Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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
import openpnm as op
import scipy as sp
ws = op.core.Workspace()
ws.settings['local_data'] = True
# NETWORK
sp.random.seed(17)
nx, ny, nz = 30, 20, 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()
import openpnm as op
import scipy as sp
ws = op.core.Workspace()
ws.settings['local_data'] = True
# 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()
partitioning at the two air-water interfaces, then continues diffusing
through the water, and finally reacting at the two reacting plates at the
top and the bottom of the network.
"""
import openpnm as op
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(10)
# Define network, geometry and constituent phases
net = op.network.Cubic(shape=[100, 100, 1])
geom = op.geometry.StickAndBall(network=net)
air = op.phases.Air(network=net, name="air")
water = op.phases.Water(network=net, name="water")
water["pore.diffusivity"] = air["pore.diffusivity"] * 0.05
# Define the regions to be occupied by the two phases (air and water)
x, y, z = net["pore.coords"].T
ps_water = net.Ps[(y >= 75) + (y <= 25)]
ps_air = np.setdiff1d(net.Ps, ps_water)
ts_water = net.find_neighbor_throats(pores=ps_water, mode="xnor")
ts_air = net.find_neighbor_throats(pores=ps_air, mode="xnor")
ts_interface = net.find_neighbor_throats(pores=ps_water, mode="xor")
# Define multiphase and set phase occupancy
mphase = op.phases.MultiPhase(network=net, phases=[air, water], name="mphase")
mphase._set_automatic_throat_occupancy()
mphase.set_occupancy(air, pores=ps_air, throats=ts_air)
mphase.set_occupancy(water, pores=ps_water, throats=ts_water)
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)
perm.setup(phase=water)
perm.set_value_BC(pores=pn.pores('right'), values=0)
perm.set_value_BC(pores=pn.pores('left'), values=101325)
import openpnm as op
import scipy as sp
ws = op.core.Workspace()
ws.settings['local_data'] = True
sp.random.seed(0)
pn = op.network.Cubic(shape=[15, 15, 15], spacing=0.0001, name='pn11')
pn.add_boundary_pores()
geom = op.geometry.StickAndBall(network=pn, pores=pn.Ps, throats=pn.Ts,
settings={'test': 1})
water = op.phases.Water(network=pn)
water['throat.viscosity'] = water['pore.viscosity'][0]
phys_water = op.physics.GenericPhysics(network=pn, phase=water, geometry=geom)
mod = op.physics.models.hydraulic_conductance.hagen_poiseuille
phys_water.add_model(propname='throat.conductance',
model=mod, viscosity='throat.viscosity')
phys_water.regenerate_models()
alg = op.algorithms.FickianDiffusion(network=pn, phase=water)
alg.setup(conductance='throat.conductance', quantity='pore.mole_fraction')
alg.set_BC(pores=pn.pores('top'), bctype='dirichlet', bcvalues=0.5)
alg.set_BC(pores=pn.pores('bottom'), bctype='dirichlet', bcvalues=0.0)
alg['pore.mole_fraction'] = 0
rxn = op.algorithms.GenericReaction(network=pn, pores=[70, 71])
rxn['pore.k'] = 1e-1
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')
# algorithms
sf = op.algorithms.StokesFlow(network=net, phase=water)
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
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)
# Define physics object
phys = op.physics.Standard(network=net, phase=mphase, geometry=geom)
mdiff = op.models.physics.diffusive_conductance.multiphase_diffusion
phys.add_model(propname="throat.diffusive_conductance", model=mdiff)