Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_hagen_poiseuille(self):
mod = op.models.physics.hydraulic_conductance.hagen_poiseuille
self.phys.add_model(propname='throat.conductance1',
model=mod)
assert sp.allclose(a=self.phys['throat.conductance1'][0],
b=1330.68207684)
self.phys.add_model(propname='throat.conductance2',
model=mod,
calc_pore_len=True)
assert sp.allclose(a=self.phys['throat.conductance2'][0],
b=1330.68207684)
def test_linear(self):
self.phys['pore.item1'] = 0.5e-11
self.phys['pore.item2'] = 1.5e-12
self.phys.add_model(propname='pore.source1',
model=pm.generic_source_term.linear,
A1='pore.item1',
A2='pore.item2',
quantity='pore.mole_fraction',
regen_mode='normal')
self.alg = op.algorithms.ReactiveTransport(network=self.net,
phase=self.phase)
self.alg.settings.update({'conductance': 'throat.diffusive_conductance',
'quantity': 'pore.mole_fraction'})
self.alg.set_dirichlet_BC(values=0.4, pores=self.BC_pores)
self.alg.set_source(propname='pore.source1',
pores=self.source_pores)
self.alg.run()
self.phase.update(self.alg.results())
self.phys.regenerate_models(propnames='pore.source1')
X = self.phase['pore.mole_fraction']
r1 = np.round(np.sum(0.5e-11 * X[self.source_pores] + 1.5e-12), 20)
try:
# The following properties will all be there for Voronoi
p_centroids = net['pore.centroid']
t_centroids = net['throat.centroid']
p_diam = net['pore.indiameter']
t_norms = net['throat.normal']
except:
# Chances are this isn't Voronoi so calculate or replace all
p_centroids = net['pore.coords']
temp = net['pore.coords'][net['throat.conns']]
t_centroids = np.mean(temp, axis=1)
p_diam = net['pore.diameter']
t_norms = net['throat.normal']
if capillary_model == 'purcell':
angle_model = pm.capillary_pressure.purcell_filling_angle
radius_model = pm.capillary_pressure.purcell_meniscus_radius
center_model = pm.capillary_pressure.purcell_meniscus_center
elif capillary_model == 'sinusoidal':
angle_model = pm.capillary_pressure.sinusoidal
radius_model = pm.capillary_pressure.sinusoidal
center_model = pm.capillary_pressure.sinusoidal
else:
logger.exception('capillary model '+capillary_model+' not valid')
for phys in phases_physics:
for Pc in inv_points:
# Dictionary with keys of pore id
pore_data = {}
regen_mode='normal'
if capillary_model == 'purcell':
phys.add_model(propname=tfill_angle,
model=angle_model,
# NETWORK
sp.random.seed(17)
nx, ny, nz = 20, 40, 1
pn = op.network.Cubic(shape=[nx, ny, nz], spacing=1e-4, name='pn11')
# GEOMETRIES
geom = op.geometry.StickAndBall(network=pn, pores=pn.Ps, throats=pn.Ts)
# PHASES
water = op.phases.Water(network=pn)
# PHYSICS
phys_water = op.physics.GenericPhysics(network=pn, phase=water, geometry=geom)
water['throat.viscosity'] = water['pore.viscosity'][0]
mod = op.models.physics.hydraulic_conductance.hagen_poiseuille
phys_water.add_model(propname='throat.hydraulic_conductance',
model=mod, viscosity='throat.viscosity')
geom['pore.area'] = sp.pi*(geom['pore.diameter']**2)/4.0
mod2 = op.models.physics.diffusive_conductance.bulk_diffusion
phys_water.add_model(propname='throat.diffusive_conductance',
model=mod2, diffusivity='pore.diffusivity')
phys_water.regenerate_models()
inlet = pn.pores('back') # pore inlet
outlet = pn.pores('front') # pore outlet
inlet2 = pn.pores('left') # pore inlet2
outlet2 = pn.pores('right') # pore outlet2
# %% Define phase objects
hg = op.phases.Mercury(network=net)
air = op.phases.Air(network=net)
water = op.phases.Water(network=net)
hg['throat.contact_angle'] = 140
hg['throat.surface_tension'] = 0.48
water['throat.viscosity'] = 0.0001
phys_air = op.physics.GenericPhysics(network=net, phase=air, geometry=geo)
phys_hg = op.physics.GenericPhysics(network=net, phase=hg, geometry=geo)
phys_water = op.physics.GenericPhysics(network=net, phase=water, geometry=geo)
# %%Simulate capillary pressure curve
mod = op.models.physics.capillary_pressure.washburn_slit
phys_hg.add_model(propname='throat.entry_pressure', model=mod)
mip = op.algorithms.Porosimetry(network=net)
mip.setup(phase=hg)
mip.set_inlets(net.pores(['top', 'bottom']))
mip.run(points=25)
mip.plot_intrusion_curve()
# %%Calculating permeability
mod = op.models.physics.hydraulic_conductance.hagen_poiseuille_slit
phys_water.add_model(propname='throat.hydraulic_conductance', model=mod)
alg = op.algorithms.StokesFlow(network=net, phase=water)
BC1_pores = net.pores('pore.front')
alg.set_value_BC(values=202650, pores=BC1_pores)
BC2_pores = net.pores('pore.back')
import openpnm as op
ws = op.Workspace()
proj = ws.new_project()
pn = op.network.Cubic(shape=[10, 10, 10], project=proj, spacing=1e-4)
geom = op.geometry.StickAndBall(network=pn, pores=pn.Ps, throats=pn.Ts)
geom['pore.volume'][pn.pores('left')] = 0
hg = op.phases.Mercury(network=pn)
phys = op.physics.GenericPhysics(network=pn, phase=hg, geometry=geom)
phys.add_model(propname='throat.entry_pressure',
model=op.models.physics.capillary_pressure.washburn)
phys.add_model(propname='pore.pc_star',
model=op.models.misc.from_neighbor_throats,
throat_prop='throat.entry_pressure',
mode='min')
phys.add_model(propname='pore.late_filling',
model=op.models.physics.multiphase.late_filling,
pressure='pore.pressure',
Pc_star='pore.pc_star',
eta=1, Swp_star=0.4,
regen_mode='deferred')
phys['throat.pc_star'] = phys['throat.entry_pressure']
phys.add_model(propname='throat.late_filling',
model=op.models.physics.multiphase.late_filling,
pressure='throat.pressure',
Pc_star='throat.pc_star',
eta=1, Swp_star=0.2,
air.add_model(propname='pore.diffusivity.pure_O2',
model=op.models.phases.mixtures.fuller_diffusivity)
air.add_model(propname='pore.viscosity',
model=op.models.misc.polynomial,
prop='pore.temperature',
a=[0.00000182082, 6.51815E-08, -3.48553E-11, 1.11409E-14])
air.add_model(propname='pore.molar_density',
model=op.models.phases.density.ideal_gas)
phys = op.physics.GenericPhysics(network=pn, phase=air, geometry=geo)
phys.add_model(propname='throat.diffusive_conductance',
pore_diffusivity='pore.diffusivity.pure_O2',
model=op.models.physics.diffusive_conductance.ordinary_diffusion)
phys.add_model(propname='throat.hydraulic_conductance',
pore_diffusivity='pore.viscosity',
model=op.models.physics.hydraulic_conductance.classic_hagen_poiseuille)
sf = op.algorithms.StokesFlow(network=pn, phase=air)
sf.set_value_BC(pores=pn.pores('left'), values=200000)
sf.set_value_BC(pores=pn.pores('right'), values=100000)
sf.run()
air.update(sf.results())
air.regenerate_models()
fd = op.algorithms.FickianDiffusion(network=pn, phase=air)
fd.setup(quantity='pore.concentration.pure_O2')
fd.set_value_BC(pores=pn.pores('left'), values=1)
fd.set_value_BC(pores=pn.pores('right'), values=0)
fd.run()
air.update(fd.results())
phys.add_model(propname='throat.hydraulic_conductance',
pore_viscosity='pore.viscosity',
throat_viscosity='throat.viscosity',
model=flow, regen_mode='normal')
current = op.models.physics.ionic_conductance.electroneutrality
phys.add_model(propname='throat.ionic_conductance', ions=[Na.name, Cl.name],
model=current, regen_mode='normal')
eA_dif = op.models.physics.diffusive_conductance.ordinary_diffusion
phys.add_model(propname='throat.diffusive_conductance.' + Na.name,
pore_diffusivity='pore.diffusivity.' + Na.name,
throat_diffusivity='throat.diffusivity.' + Na.name,
model=eA_dif, regen_mode='normal')
eB_dif = op.models.physics.diffusive_conductance.ordinary_diffusion
phys.add_model(propname='throat.diffusive_conductance.' + Cl.name,
pore_diffusivity='pore.diffusivity.' + Cl.name,
throat_diffusivity='throat.diffusivity.' + Cl.name,
model=eB_dif, regen_mode='normal')
# algorithms
sf = op.algorithms.StokesFlow(network=net, phase=sw)
sf.set_value_BC(pores=net.pores('back'), values=0.01)
sf.set_value_BC(pores=net.pores('front'), values=0.00)
sf.settings['rxn_tolerance'] = 1e-12
sf.run()
sw.update(sf.results())
p = op.algorithms.ChargeConservation(network=net, phase=sw)
p.set_value_BC(pores=net.pores('left'), values=0.01)
p.set_value_BC(pores=net.pores('right'), values=0.00)
self.settings.update({'prefix': 'phys'})
# Overwrite with user supplied settings, if any
self.settings.update(settings)
# Deal with network or project arguments
if network is not None:
if project is not None:
assert network is project.network
else:
project = network.project
super().__init__(project=project, phase=phase, geometry=geometry,
**kwargs)
self.add_model(propname='throat.flow_shape_factors',
model=mods.flow_shape_factors.ball_and_stick)
self.add_model(propname='throat.hydraulic_conductance',
model=mods.hydraulic_conductance.hagen_poiseuille)
self.add_model(propname='throat.poisson_shape_factors',
model=mods.poisson_shape_factors.ball_and_stick)
self.add_model(propname='throat.diffusive_conductance',
model=mods.diffusive_conductance.ordinary_diffusion)
self.add_model(propname='throat.entry_pressure',
model=mods.capillary_pressure.washburn)
self.add_model(propname='throat.thermal_conductance',
model=mods.thermal_conductance.series_resistors)
self.add_model(propname='throat.electrical_conductance',
model=mods.electrical_conductance.series_resistors)
model=mods.geometry.throat_length.ctc)
geom.add_model(propname='throat.area',
model=mods.geometry.throat_area.cylinder)
geom.add_model(propname='pore.area',
model=mods.misc.from_neighbor_throats,
throat_prop='throat.area')
geom.add_model(propname='pore.volume',
model=mods.misc.constant, value=0.0)
geom.add_model(propname='throat.volume',
model=mods.geometry.throat_volume.cylinder)
geom.regenerate_models()
# Now create a generic phase with physics models on it
phase = GenericPhase(network=net)
m = mods.physics.hydraulic_conductance.classic_hagen_poiseuille
phase.add_model(propname='throat.hydraulic_conductance',
model=m, regen_mode='deferred')
m = mods.physics.diffusive_conductance.classic_ordinary_diffusion
phase.add_model(propname='throat.diffusive_conductance',
model=m, regen_mode='deferred')
m = mods.physics.diffusive_conductance.classic_ordinary_diffusion
phase.add_model(propname='throat.entry_pressure',
model=m, regen_mode='deferred')