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_openpnm_to_im(self):
net = op.network.Cubic(shape=[5, 5, 5])
geom = op.geometry.StickAndBall(network=net,
pores=net.Ps, throats=net.Ts)
geom.add_model(propname="pore.volume",
model=op.models.geometry.pore_volume.cube)
geom.add_model(propname="throat.volume",
model=op.models.geometry.throat_volume.cylinder)
geom.regenerate_models()
im = ps.io.openpnm_to_im(network=net, pore_shape="cube",
throat_shape="cylinder", rtol=0.01)
porosity_actual = im.astype(bool).sum() / np.prod(im.shape)
volume_void = net["pore.volume"].sum() + net["throat.volume"].sum()
volume_total = np.prod(net.spacing * net.shape)
porosity_desired = volume_void / volume_total
assert_allclose(actual=porosity_actual, desired=porosity_desired,
rtol=0.05)
# Generate Ps as boolean mask
Ps = pn['pore.coords'][:, 2] <= 20
Ts = pn.find_neighbor_throats(pores=Ps, mode='intersection', flatten=True)
geom1 = op.geometry.GenericGeometry(network=pn, pores=Ps, throats=Ts)
# Convert Ps to indices
Ps = pn.toindices(pn['pore.coords'][:, 2] > 20)
Ts = pn.find_neighbor_throats(pores=Ps, mode='union')
geom2 = op.geometry.GenericGeometry(network=pn, pores=Ps, throats=Ts)
water = op.phases.Water(network=pn)
phys1 = op.physics.GenericPhysics(network=pn, phase=water, geometry=geom1)
phys1.add_model(propname='pore.test',
model=op.models.geometry.pore_misc.constant,
value=1.0)
phys1.regenerate_models()
phys2 = op.physics.GenericPhysics(network=pn, phase=water, geometry=geom2)
# Copy models from phys1 to phys2 directly
phys2.models = phys1.models
# Ensure the models dicts are equal
assert phys1.models == phys2.models
# But they are actually distinct objects
assert phys1.models is not phys2.models
self['pore.critical_pressure'] = 3.786E6
self['pore.critical_temperature'] = 132.5
self['pore.critical_volume'] = 0.002917
self['pore.contact_angle'] = 110.0
self.add_model(propname='pore.molar_density',
model=mods.phases.molar_density.ideal_gas)
self.add_model(propname='pore.diffusivity',
model=mods.phases.diffusivity.fuller,
MA=0.032, MB=0.028,
vA=16.6, vB=17.9)
self.add_model(propname='pore.thermal_conductivity',
model=mods.misc.polynomial,
prop='pore.temperature',
a=[0.00422791, 0.0000789606, -1.56383E-08])
self.add_model(propname='pore.viscosity',
model=mods.misc.polynomial,
prop='pore.temperature',
a=[0.00000182082, 6.51815E-08, -3.48553E-11,
1.11409E-14])
# ws.settings['loglevel'] = 20
# network, geometry, phase
np.random.seed(0)
net = op.network.Cubic(shape=[8, 8, 1], spacing=9e-4, project=proj)
prs = (net['pore.back'] * net['pore.right'] + net['pore.back'] *
net['pore.left'] + net['pore.front'] * net['pore.right'] +
net['pore.front'] * net['pore.left'])
thrts = net['throat.surface']
op.topotools.trim(network=net, pores=net.Ps[prs], throats=net.Ts[thrts])
geo = op.geometry.StickAndBall(network=net, pores=net.Ps, throats=net.Ts)
pore_d = op.models.misc.constant
throat_d = op.models.misc.constant
geo.add_model(propname='pore.diameter', model=pore_d, value=1.5e-4)
geo.add_model(propname='throat.diameter', model=throat_d, value=1e-4)
geo.regenerate_models()
water = op.phases.Water(network=net)
# physics
phys = op.physics.GenericPhysics(network=net, phase=water, geometry=geo)
flow = op.models.physics.hydraulic_conductance.hagen_poiseuille
phys.add_model(propname='throat.hydraulic_conductance',
pore_viscosity='pore.viscosity',
throat_viscosity='throat.viscosity',
model=flow, regen_mode='normal')
self['pore.electrical_conductivity'] = 1e-15
self['pore.permittivity'] = 78.303
self['pore.diffusivity.Na'] = 1.33e-09
self['pore.diffusivity.Cl'] = 2.03e-09
self['pore.valence.Na'] = 1
self['pore.valence.Cl'] = -1
self['throat.permittivity'] = 78.303
self['throat.diffusivity.Na'] = 1.33e-09
self['throat.diffusivity.Cl'] = 2.03e-09
self['throat.valence.Na'] = 1
self['throat.valence.Cl'] = -1
self.add_model(propname='pore.density',
model=mods.phases.density.water)
self.add_model(propname='pore.molar_density',
model=mods.phases.molar_density.standard)
self.add_model(propname='pore.surface_tension',
model=mods.phases.surface_tension.water)
self.add_model(propname='pore.thermal_conductivity',
model=mods.phases.thermal_conductivity.water)
self.add_model(propname='pore.vapor_pressure',
model=mods.phases.vapor_pressure.antoine,
A=8.088, B=1750.71, C=236.191)
self.add_model(propname='pore.viscosity',
model=mods.phases.viscosity.water)
self.regenerate_models()
def __init__(self, name=None, **kwargs):
super().__init__(name=name, **kwargs)
self['pore.molecular_weight'] = 0.2006
self['pore.critical_pressure'] = 1.662E8
self['pore.critical_temperature'] = 1733
self['pore.critical_volume'] = 0.000189
self['pore.contact_angle'] = 140
self.add_model(propname='pore.vapor_pressure',
model=mods.phases.vapor_pressure.antoine,
A=9.85767, B=3007.129, C=-10.001)
self.add_model(propname='pore.density',
model=mods.misc.linear,
prop='pore.temperature',
b=14280.9, m=-2.47004)
self.add_model(propname='pore.molar_density',
model=mods.phases.molar_density.standard)
self.add_model(propname='pore.surface_tension',
model=mods.misc.linear,
prop='pore.temperature',
b=0.56254, m=-0.00028)
self.add_model(propname='pore.thermal_conductivity',
model=mods.misc.polynomial,
prop='pore.temperature',
a=[3.98691, 0.0170967, -0.0000063862])
self.add_model(propname='pore.viscosity',
model=mods.misc.polynomial,
prop='pore.temperature',
a=[0.00355837, -0.0000100131, 1.23684E-08, -5.1684E-12])
self.regenerate_models()
import numpy as np
import openpnm as op
pn = op.network.Cubic(shape=[10, 10, 10], spacing=0.0001)
Ps = pn.pores('all')
Ts = pn.throats('all')
geo = op.geometry.StickAndBall(network=pn, pores=Ps, throats=Ts)
hg = op.phases.Mercury(network=pn)
h2o = op.phases.Water(network=pn)
phys1 = op.physics.GenericPhysics(network=pn, phase=hg, geometry=geo)
phys2 = op.physics.GenericPhysics(network=pn, phase=h2o, geometry=geo)
model = op.models.physics.capillary_pressure.washburn
hg.add_model(propname='throat.entry_pressure',
model=model,
contact_angle='pore.contact_angle',
surface_tension='pore.surface_tension')
model = op.models.physics.hydraulic_conductance.hagen_poiseuille
h2o.add_model(propname='throat.hydraulic_conductance',
model=model,
throat_viscosity='throat.viscosity',
pore_diameter='pore.diameter',
throat_length='throat.length',
throat_diameter='throat.area')
mip = op.algorithms.Drainage(network=pn)
mip.setup(invading_phase=hg, entry_pressure='throat.entry_pressure')
mip.set_inlets(pn.pores(['left', 'right', 'top', 'bottom', 'front', 'back']))
mip.run(inv_pressures=np.logspace(5, 6.5, num=15))
def __init__(self, network, **kwargs):
super().__init__(network=network, components=[], **kwargs)
N2 = species.gases.N2(network=network, name='N2_'+self.name)
O2 = species.gases.O2(network=network, name='O2_'+self.name)
self.settings['components'] = [O2.name, N2.name]
self.set_mole_fraction(component=N2, values=0.791)
self.set_mole_fraction(component=O2, values=0.209)
self.add_model(propname='pore.diffusivity.N2',
model=mods.phases.mixtures.fuller_diffusivity)
self.add_model(propname='pore.diffusivity.O2',
model=mods.phases.mixtures.fuller_diffusivity)
self.add_model(propname='pore.molar_mass',
model=mole_weighted_average,
prop='pore.molecular_weight')