Skip to content

Commit

Permalink
Merge pull request #578 from PMEAL/fix_issue_566
Browse files Browse the repository at this point in the history
Fix issue #566
  • Loading branch information
jgostick committed Jun 2, 2016
2 parents 259964f + 5474c62 commit ae0d562
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 50 deletions.
16 changes: 8 additions & 8 deletions OpenPNM/Physics/models/hydraulic_conductance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions OpenPNM/Utilities/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 15 additions & 20 deletions run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
#==============================================================================
'''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()

#==============================================================================
'''Build Geometry'''
#==============================================================================
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)
Expand Down Expand Up @@ -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'''
Expand Down
32 changes: 14 additions & 18 deletions test/unit/Physics/GenericPhysicsTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import OpenPNM
import scipy as sp
import pytest


class GenericPhysicsTest:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
32 changes: 31 additions & 1 deletion test/unit/Physics/models/DiffusiveConductanceTest.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions test/unit/Physics/models/HydraulicConductance.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ae0d562

Please sign in to comment.