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
import openpnm as op
pn = op.network.Cubic(shape=[10, 10, 40], spacing=1)
# 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,
r"""
Example: How to use OpenPNNM to simulating multiphase Fickian diffusion
1D network, the first half of the network is occupied by air and the next
half by water. A partition coefficient of 0.5 is assumed, meaning that the
concentration of the diffusing species in water "at the interface" is half
of that in air.
"""
import openpnm as op
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(10)
# Define network and geometry
net = op.network.Cubic(shape=[10, 1, 1])
geom = op.geometry.StickAndBall(network=net)
# Define constituent phases
air = op.phases.Air(network=net, name="air")
water = op.phases.Water(network=net, name="water")
water["pore.diffusivity"] = air["pore.diffusivity"] * 0.2
# Define MultiPhase object
mphase = op.phases.MultiPhase(network=net, phases=[air, water])
mphase._set_automatic_throat_occupancy()
mphase.set_occupancy(phase=air, pores=[0, 1, 2, 3, 4])
mphase.set_occupancy(phase=water, pores=[5, 6, 7, 8, 9])
const = op.models.misc.constant
mphase.set_binary_partition_coef(propname="throat.partition_coef",
phases=[water, air], model=const, value=0.5)
import openpnm as op
import numpy as np
# work space and project
ws = op.Workspace()
ws.settings["loglevel"] = 30
proj = ws.new_project()
# network
np.random.seed(7)
net = op.network.Cubic(shape=[51, 19, 1], spacing=1e-4, project=proj)
# geometry
geo = op.geometry.StickAndBall(network=net, pores=net.Ps, throats=net.Ts)
# phase
phase = op.phases.Water(network=net)
# physics
phys = op.physics.GenericPhysics(network=net, phase=phase, geometry=geo)
phase['pore.diffusivity'] = 2e-09
phase['throat.diffusivity'] = 2e-09
mod = op.models.physics.diffusive_conductance.ordinary_diffusion
phys.add_model(propname='throat.diffusive_conductance',
model=mod, regen_mode='normal')
import openpnm as op
from openpnm.phases import mixtures
import numpy as np
ws = op.Workspace()
proj = ws.new_project()
# 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()
sw = mixtures.SalineWater(network=net)
# Retrieve handles to each species for use below
net['throat.diameter'] = sp.array(t_dia_inscribed)*voxel_size
net['throat.inscribed_diameter'] = sp.array(t_dia_inscribed)*voxel_size
net['throat.area'] = sp.array(t_area)*(voxel_size**2)
net['throat.perimeter'] = sp.array(t_perimeter)*voxel_size
net['throat.equivalent_diameter'] = (sp.array(t_area) * (voxel_size**2))**0.5
P12 = net['throat.conns']
PT1 = sp.sqrt(sp.sum(((p_coords[P12[:, 0]]-t_coords) * voxel_size)**2, axis=1))
PT2 = sp.sqrt(sp.sum(((p_coords[P12[:, 1]]-t_coords) * voxel_size)**2, axis=1))
net['throat.total_length'] = PT1 + PT2
PT1 = PT1-p_dia_local[P12[:, 0]]/2*voxel_size
PT2 = PT2-p_dia_local[P12[:, 1]]/2*voxel_size
net['throat.length'] = PT1 + PT2
dist = (p_coords[P12[:, 0]]-p_coords[P12[:, 1]])*voxel_size
net['throat.direct_length'] = sp.sqrt(sp.sum(dist**2, axis=1))
# Make a dummy openpnm network to get the conduit lengths
pn = op.network.GenericNetwork()
pn.update(net)
pn.add_model(propname='throat.endpoints',
model=op_gm.throat_endpoints.spherical_pores,
pore_diameter='pore.inscribed_diameter',
throat_diameter='throat.inscribed_diameter')
pn.add_model(propname='throat.conduit_lengths',
model=op_gm.throat_length.conduit_lengths)
pn.add_model(propname='pore.area',
model=op_gm.pore_area.sphere)
net['throat.endpoints.head'] = pn['throat.endpoints.head']
net['throat.endpoints.tail'] = pn['throat.endpoints.tail']
net['throat.conduit_lengths.pore1'] = pn['throat.conduit_lengths.pore1']
net['throat.conduit_lengths.pore2'] = pn['throat.conduit_lengths.pore2']
net['throat.conduit_lengths.throat'] = pn['throat.conduit_lengths.throat']
net['pore.area'] = pn['pore.area']
prj = pn.project
import openpnm as op
ws = op.Workspace()
proj = ws.new_project()
pn = op.network.Cubic(shape=[10, 10, 10], spacing=1e-4, project=proj)
geo = op.geometry.StickAndBall(network=pn, pores=pn.Ps, throats=pn.Ts)
air = op.phases.Air(network=pn, name='air')
water = op.phases.Water(network=pn, name='h2o')
hg = op.phases.Mercury(network=pn, name='hg')
phys_air = op.physics.Standard(network=pn, phase=air, geometry=geo)
phys_water = op.physics.Standard(network=pn, phase=water, geometry=geo)
phys_hg = op.physics.Standard(network=pn, phase=hg, geometry=geo)
mip = op.algorithms.Porosimetry(network=pn)
mip.setup(phase=hg)
mip.set_inlets(pores=pn.pores(['top', 'bottom']))
mip.run()
hg.update(mip.results(Pc=70000))
# mip.plot_intrusion_curve()
perm = op.algorithms.StokesFlow(network=pn)
def _new_object(self, objtype, name=None):
r"""
"""
if objtype.startswith('net'):
obj = openpnm.network.GenericNetwork(project=self, name=name)
elif objtype.startswith('geo'):
obj = openpnm.geometry.GenericGeometry(project=self, name=name,
pores=[], throats=[])
elif objtype.startswith('pha'):
obj = openpnm.phases.GenericPhase(project=self, name=name)
elif objtype.startswith('phy'):
obj = openpnm.physics.GenericPhysics(project=self, name=name)
elif objtype.startswith('alg'):
obj = openpnm.algorithm.GenericAlgorithm(project=self, name=name)
else:
obj = openpnm.core.Base(project=self, name=name)
return obj
import openpnm as op
import numpy as np
ws = op.Workspace()
proj = ws.new_project()
# ws.settings['loglevel'] = 20
# network, geometry, phase
np.random.seed(0)
net = op.network.Cubic(shape=[33, 33, 1], spacing=1e-5)
geo = op.geometry.StickAndBall(network=net, pores=net.Ps, throats=net.Ts)
sw = op.phases.Mixtures.SalineWater(network=net)
# physics
phys = op.physics.GenericPhysics(network=net, phase=sw, geometry=geo)
flow = op.models.physics.hydraulic_conductance.hagen_poiseuille
phys.add_model(propname='throat.hydraulic_conductance.solvent',
pore_viscosity='pore.viscosity.solvent',
throat_viscosity='throat.viscosity.solvent',
model=flow, regen_mode='normal')
phys.regenerate_models()
current = op.models.physics.ionic_conductance.ordinary
phys.add_model(propname='throat.electrical_conductance.solvent',
model=current, regen_mode='normal')
import openpnm as op
import numpy as np
import matplotlib.pyplot as plt
# Get Deff w/o including Knudsen effect
spacing = 1.0
net = op.network.Cubic(shape=[10, 10, 10], spacing=spacing)
geom = op.geometry.StickAndBall(network=net)
air = op.phases.Air(network=net)
phys = op.physics.Standard(network=net, geometry=geom, phase=air)
odiff = op.models.physics.diffusive_conductance.ordinary_diffusion
phys.add_model(propname="throat.diffusive_conductance", model=odiff)
fd = op.algorithms.FickianDiffusion(network=net, phase=air)
fd.set_value_BC(pores=net.pores("left"), values=1.0)
fd.set_value_BC(pores=net.pores("right"), values=0.0)
fd.run()
L = (net.shape * net.spacing)[1]
A = (net.shape * net.spacing)[[0, 2]].prod()
Mdot = fd.rate(pores=net.pores("left")).squeeze()
Deff0 = Mdot * L / A
# Get Deff w/ including Knudsen effect
mdiff = op.models.physics.diffusive_conductance.mixed_diffusion