Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_class(self):
self.net = op.network.Cubic(shape=[5, 5, 5], spacing=1.0)
self.geo = op.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 = op.phases.Air(network=self.net)
self.phys = op.physics.GenericPhysics(network=self.net,
phase=self.air,
geometry=self.geo)
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
def setup_class(self):
self.net = op.network.Cubic(shape=[5, 5, 5])
Ps = self.net.Ps
Ts = self.net.Ts
self.geo = op.geometry.GenericGeometry(network=self.net, pores=Ps,
throats=Ts)
self.phase = op.phases.GenericPhase(network=self.net)
self.phys = op.physics.GenericPhysics(network=self.net,
phase=self.phase,
geometry=self.geo)
self.phys['throat.diffusive_conductance'] = 5e-8
self.phase['pore.mole_fraction'] = 0.0
self.BC_pores = np.arange(20, 30)
self.source_pores = np.arange(55, 85)
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)
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)
# 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
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)
def setup_class(self):
self.net = op.network.Cubic(shape=[5, 5, 5])
Ps = self.net.Ps
Ts = self.net.Ts
self.geo = op.geometry.GenericGeometry(network=self.net, pores=Ps,
throats=Ts)
self.phase = op.phases.GenericPhase(network=self.net)
self.phys = op.physics.GenericPhysics(network=self.net,
phase=self.phase,
geometry=self.geo)
self.phys['throat.diffusive_conductance'] = 5e-8
self.phase['pore.mole_fraction'] = 0.0
self.BC_pores = np.arange(20, 30)
self.source_pores = np.arange(55, 85)
def setup_class(self):
self.net = op.network.Cubic(shape=[5, 5, 5], spacing=1.0)
self.geo = op.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 = op.phases.Air(network=self.net)
self.phys = op.physics.GenericPhysics(network=self.net,
phase=self.air,
geometry=self.geo)
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