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)
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 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)
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()
inlet = pn.pores('back') # pore inlet
outlet = pn.pores('front') # pore outlet
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 cantera as ct
from openpnm.utils.misc import tic, toc
ws = op.core.Workspace()
net = op.network.Cubic(shape=[10, 10, 10], spacing=1e-6, name='test_net')
proj = net.project
geom = op.geometry.GenericGeometry(network=net, pores=net.Ps, throats=net.Ts)
air = op.phases.Air(network=net)
phys_air = op.physics.GenericPhysics(network=net, phase=air, geometry=geom)
cantera = op.models.phase.thermal_conductivity.cantera
print('Calculating thermal conductivity with Cantera')
tic()
air.add_model(propname='pore.thermal_conductivity',
model=cantera,
cantera_phase_obj=ct.Solution('air.xml'))
air.regenerate_models(propnames='pore.thermal_conductivity')
toc()
print('Calculating thermal conductivity directly')
tic()
water_conductivity = op.models.phase.thermal_conductivity.water
air.add_model(propname='pore.thermal_conductivity', model=water_conductivity)
# 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)
# Define algorithm: Fickian diffusion
fd = op.algorithms.FickianDiffusion(network=net, phase=mphase)
fd.set_value_BC(pores=0, values=1.0)
fd.set_value_BC(pores=9, values=0.1)
fd.run()
# Post-processing
c = fd["pore.concentration"]
plt.figure()
plt.plot(c, "ko:")
plt.xlabel("x (m)")
plt.ylabel("c (mol/m3)")
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')
phys.regenerate_models()
eA_dif = op.models.physics.diffusive_conductance.ordinary_diffusion
phys.add_model(propname='throat.diffusive_conductance.Na',
pore_diffusivity='pore.diffusivity.Na',
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')
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']))