diff --git a/OpenPNM/Physics/models/hydraulic_conductance.py b/OpenPNM/Physics/models/hydraulic_conductance.py index f4a16c12f6..2db2e8b3cc 100644 --- a/OpenPNM/Physics/models/hydraulic_conductance.py +++ b/OpenPNM/Physics/models/hydraulic_conductance.py @@ -9,10 +9,13 @@ import OpenPNM.Utilities.misc as misc -def hagen_poiseuille(physics, phase, network, pore_diameter='pore.diameter', - pore_viscosity='pore.viscosity', throat_length='throat.length', - throat_diameter='throat.diameter', calc_pore_len=True, +def hagen_poiseuille(physics, phase, network, + pore_diameter='pore.diameter', + pore_viscosity='pore.viscosity', + throat_length='throat.length', + throat_diameter='throat.diameter', shape_factor='throat.shape_factor', + calc_pore_len=False, **kwargs): r""" Calculates the hydraulic conductivity of throat assuming cylindrical @@ -26,11 +29,8 @@ def hagen_poiseuille(physics, phase, network, pore_diameter='pore.diameter', Notes ----- - (1) This function requires that all the necessary phase properties already - be calculated. - - (2) This function calculates the specified property for the *entire* - network then extracts the values for the appropriate throats at the end. + This function calculates the specified property for the *entire* network + then extracts the values for the appropriate throats at the end. """ # Get Nt-by-2 list of pores connected to each throat diff --git a/OpenPNM/Utilities/misc.py b/OpenPNM/Utilities/misc.py index 179df9ea0a..9c75ba1e53 100644 --- a/OpenPNM/Utilities/misc.py +++ b/OpenPNM/Utilities/misc.py @@ -271,13 +271,13 @@ def conduit_lengths(network, throats=None, mode='pore'): # Find the pore-to-pore distance, minus the throat length lengths = _sp.sqrt(_sp.sum(_sp.square(pcoords[Ps[:, 0]] - pcoords[Ps[:, 1]]), 1)) - network['throat.length'] - lengths[lengths <= 0.0] = 2e-9 + lengths[lengths < 0.0] = 2e-9 # Calculate the fraction of that distance from the first pore try: fractions = pdia[Ps[:, 0]]/(pdia[Ps[:, 0]] + pdia[Ps[:, 1]]) # Don't allow zero lengths - fractions[fractions == 0.0] = 0.5 - fractions[fractions == 1.0] = 0.5 +# fractions[fractions == 0.0] = 0.5 +# fractions[fractions == 1.0] = 0.5 except: fractions = 0.5 plen1 = lengths*fractions diff --git a/run_script.py b/run_script.py index dc4c993ed8..ee702186ab 100644 --- a/run_script.py +++ b/run_script.py @@ -5,7 +5,7 @@ #============================================================================== '''Build Topological Network''' #============================================================================== -pn = op.Network.Cubic(shape=[5,6,7],spacing=0.0001,name='net') +pn = op.Network.Cubic(shape=[5,5,5],spacing=1,name='net') pn.add_boundaries() #============================================================================== @@ -13,8 +13,12 @@ #============================================================================== Ps = pn.pores('boundary',mode='not') Ts = pn.find_neighbor_throats(pores=Ps,mode='intersection',flatten=True) -geom = op.Geometry.Toray090(network=pn,pores=Ps,throats=Ts) -geom.models.add(propname='throat.length',model=gm.throat_length.straight) +geom = op.Geometry.GenericGeometry(network=pn,pores=Ps,throats=Ts) +geom['throat.length'] = 0 +geom['throat.diameter'] = 1 +geom['pore.diameter'] = 1 +geom['pore.area'] = 1 +geom['throat.area'] = 1 Ps = pn.pores('boundary') Ts = pn.find_neighbor_throats(pores=Ps,mode='not_intersection') boun = op.Geometry.Boundary(network=pn,pores=Ps,throats=Ts) @@ -67,27 +71,18 @@ BC2_pores = pn.pores('left_boundary') alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=0.4, pores=BC2_pores) #Add new model to air's physics that accounts for water occupancy -phys_air.models.add(model=op.Physics.models.multiphase.conduit_conductance, - propname='throat.conduit_diffusive_conductance', - throat_conductance='throat.diffusive_conductance', - throat_occupancy='throat.occupancy', - pore_occupancy='pore.occupancy', - mode='strict', - factor=0) +#phys_air.models.add(model=op.Physics.models.multiphase.conduit_conductance, +# propname='throat.conduit_diffusive_conductance', +# throat_conductance='throat.diffusive_conductance', +# throat_occupancy='throat.occupancy', +# pore_occupancy='pore.occupancy', +# mode='strict', +# factor=0) #Use desired diffusive_conductance in the diffusion calculation (conductance for the dry network or water-filled network) alg.run(conductance='throat.diffusive_conductance') alg.return_results() Deff = alg.calc_eff_diffusivity() - -try: - # this creates a time step x num_pores, which is what the animated object needs - inv_seq = water['pore.IP_inv_seq'].squeeze() - history = [] - for i in sorted(set(inv_seq)): - history.append( (inv_seq != 0) & (inv_seq < i) ) - -except Exception as e: - pass +print(Deff/air['pore.diffusivity'][0]) #------------------------------------------------------------------------------ '''Export to VTK''' diff --git a/test/unit/Physics/GenericPhysicsTest.py b/test/unit/Physics/GenericPhysicsTest.py index c31c543812..3e2dd9553a 100644 --- a/test/unit/Physics/GenericPhysicsTest.py +++ b/test/unit/Physics/GenericPhysicsTest.py @@ -1,5 +1,6 @@ import OpenPNM import scipy as sp +import pytest class GenericPhysicsTest: @@ -23,35 +24,23 @@ def setup_class(self): geometry=self.geo1) def test_specify_pores_and_geometry(self): - flag = False - try: + with pytest.raises(Exception): OpenPNM.Physics.GenericPhysics(network=self.net, phase=self.phase1, geometry=self.geo1, pores=[0]) - except: - flag = True - assert flag def test_specify_overlapping_pores(self): - flag = False - try: + with pytest.raises(Exception): OpenPNM.Physics.GenericPhysics(network=self.net, phase=self.phase1, pores=[0]) - except: - flag = True - assert flag def test_specify_overlapping_geometry(self): - flag = False - try: + with pytest.raises(Exception): OpenPNM.Physics.GenericPhysics(network=self.net, phase=self.phase1, geometry=self.geo1) - except: - flag = True - assert flag def test_get_item_self_name(self): a = self.phys1.get('pore.'+self.phys1.name) @@ -119,8 +108,15 @@ def test_reassign_phase_regenerate_models(self): geometry=geo1) phys.models.add(propname='throat.hydraulic_conductance', model=physmods.hydraulic_conductance.hagen_poiseuille) - assert sp.allclose(phys['throat.hydraulic_conductance'], 0.02454369) + # Get value of hydraulic_conductance in current phys + a = phys['throat.hydraulic_conductance'][0] + # Make sure they're all the same + assert sp.allclose(phys['throat.hydraulic_conductance'], a) + # Assign phys to a different phase with 10x higher viscoity phys.parent_phase = phase2 - assert sp.allclose(phys['throat.hydraulic_conductance'], 0.02454369) + # Verify that hydraulic_conductance has NOT yet changed + assert sp.allclose(phys['throat.hydraulic_conductance'], a) + # Re-run models phys.models.regenerate() - assert sp.allclose(phys['throat.hydraulic_conductance'], 0.00245437) + # Confirm hydraulic_conductance is 10x lower + assert sp.allclose(phys['throat.hydraulic_conductance'], a/10) diff --git a/test/unit/Physics/models/DiffusiveConductanceTest.py b/test/unit/Physics/models/DiffusiveConductanceTest.py index 93620f1bbd..f6ab53053c 100644 --- a/test/unit/Physics/models/DiffusiveConductanceTest.py +++ b/test/unit/Physics/models/DiffusiveConductanceTest.py @@ -1,3 +1,33 @@ +import OpenPNM +import pytest +import scipy as sp + + class DiffusiveConductanceTest: + def setup_class(self): + self.net = OpenPNM.Network.Cubic(shape=[5, 5, 5], spacing=1.0) + self.geo = OpenPNM.Geometry.GenericGeometry(network=self.net, + pores=self.net.Ps, + throats=self.net.Ts) + self.geo['pore.diameter'] = 1.0 + self.geo['pore.area'] = 1.0 + self.geo['throat.diameter'] = 1.0 + self.geo['throat.length'] = 1e-9 + self.geo['throat.area'] = 1 + self.air = OpenPNM.Phases.Air(network=self.net) + self.phys = OpenPNM.Physics.GenericPhysics(network=self.net, + phase=self.air, + geometry=self.geo) + def test_bulk_diffusion(self): - pass + mod = OpenPNM.Physics.models.diffusive_conductance.bulk_diffusion + self.phys.models.add(propname='throat.conductance1', + model=mod) + assert sp.allclose(a=self.phys['throat.conductance1'][0], + b=0.00084552) + + self.phys.models.add(propname='throat.conductance2', + model=mod, + calc_pore_len=True) + assert sp.allclose(a=self.phys['throat.conductance2'][0], + b=0.00084552) diff --git a/test/unit/Physics/models/HydraulicConductance.py b/test/unit/Physics/models/HydraulicConductance.py new file mode 100644 index 0000000000..45aaba1a83 --- /dev/null +++ b/test/unit/Physics/models/HydraulicConductance.py @@ -0,0 +1,31 @@ +import OpenPNM +import pytest +import scipy as sp + + +class HydraulicConductanceTest: + def setup_class(self): + self.net = OpenPNM.Network.Cubic(shape=[5, 5, 5], spacing=1.0) + self.geo = OpenPNM.Geometry.GenericGeometry(network=self.net, + pores=self.net.Ps, + throats=self.net.Ts) + self.geo['pore.diameter'] = 1.0 + self.geo['throat.diameter'] = 1.0 + self.geo['throat.length'] = 1.0e-9 + self.air = OpenPNM.Phases.Air(network=self.net) + self.phys = OpenPNM.Physics.GenericPhysics(network=self.net, + phase=self.air, + geometry=self.geo) + + def test_hagen_poiseuille(self): + mod = OpenPNM.Physics.models.hydraulic_conductance.hagen_poiseuille + self.phys.models.add(propname='throat.conductance1', + model=mod) + assert sp.allclose(a=self.phys['throat.conductance1'][0], + b=1330.68207684) + + self.phys.models.add(propname='throat.conductance2', + model=mod, + calc_pore_len=True) + assert sp.allclose(a=self.phys['throat.conductance2'][0], + b=1330.68207684)