Problem getting start #2029
-
Greetings Dr. Jeff, I am a PhD student interested in flow in porous media and I want to implement OpenPNM in my research. But I am struggling at the very beginning. I am trying to run the getting started tutorial and failed. Here is the code and issue: import openpnm as op
# Define geometrical parameters
Lc = 1e-4
Nx, Ny, Nz = (10, 10, 10)
# Generate network, geometry, phase, and physics
pn = op.network.Cubic(shape=[Nx, Ny, Nz], spacing=Lc)
geo = op.geometry.StickAndBall(network=pn, pores=pn.Ps, throats=pn.Ts)
Hg = op.phases.Mercury(network=pn)
phys = op.physics.Standard(network=pn, phase=Hg, geometry=geo)
# Create algorithm and run simulation
mip = op.algorithms.Porosimetry(network=pn, phase=Hg)
mip.set_inlets(pores=pn.pores(['left', 'right', 'top', 'bottom']))
mip.run()
# Generate phase and physics
water = op.phases.Water(network=pn)
phys = op.physics.Standard(network=pn, phase=water, geometry=geo)
# Create algorithm, set boundary conditions and run simulation
sf = op.algorithms.StokesFlow(network=pn, phase=water)
Pin, Pout = (200_000, 101_325)
sf.set_value_BC(pores=pn.pores('left'), values=Pin)
sf.set_value_BC(pores=pn.pores('right'), values=Pout)
op.algorithms.StokesFlow(network=pn, phase=water).run()
Q = sf.rate(pores=pn.pores('left'))
A = Ny*Nz*Lc**2
L = Nx*Lc
mu = water['pore.viscosity'].mean()
K = Q*mu*L/(A*(Pin-Pout)) ---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-77-99eb7690f599> in <module>
25 sf.set_value_BC(pores=pn.pores('right'), values=Pout)
26 op.algorithms.StokesFlow(network=pn, phase=water).run()
---> 27 Q = sf.rate(pores=pn.pores('left'))
28 A = Ny*Nz*Lc**2
29 L = Nx*Lc
~\anaconda3\lib\site-packages\openpnm\algorithms\GenericTransport.py in rate(self, pores, throats, mode)
887 phase = self.project.phases()[self.settings['phase']]
888 g = phase[self.settings['conductance']]
--> 889 quantity = self[self.settings['quantity']]
890
891 P12 = network['throat.conns']
~\anaconda3\lib\site-packages\openpnm\core\Base.py in __getitem__(self, key)
275 vals = super().__getitem__(key)
276 else:
--> 277 raise KeyError(key)
278 return vals
279
KeyError: 'pore.pressure' I have tried to change code |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is an easy one to fix :-) You have create a 'StokesFlow' object (sf) and added boundary conditions, BUT then when you attempt to run it, you are actually creating a second StokesFlow algorithm object: |
Beta Was this translation helpful? Give feedback.
This is an easy one to fix :-) You have create a 'StokesFlow' object (sf) and added boundary conditions, BUT then when you attempt to run it, you are actually creating a second StokesFlow algorithm object:
op.algorithms.StokesFlow(network=pn, phase=water).run()
should just besf.run()
.