Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, num_points=None, shape=None, points=None,
trim_domain=False, **kwargs):
super().__init__(num_points=num_points, shape=shape, points=points,
trim_domain=trim_domain, **kwargs)
topotools.trim(self, pores=self.pores('delaunay'))
del self['throat.interconnect']
del self['throat.delaunay']
del self['pore.delaunay']
del self['pore.voronoi']
del self['throat.voronoi']
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], flatten=False)
>>> print(Ps)
[array([ 1, 5, 25]), array([ 1, 3, 7, 27])]
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xnor')
>>> print(Ps)
[1]
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xor')
>>> print(Ps)
[ 3 5 7 25 27]
"""
pores = self._parse_indices(pores)
if sp.size(pores) == 0:
return sp.array([], ndmin=1, dtype=int)
if 'lil' not in self._am.keys():
self.get_adjacency_matrix(fmt='lil')
neighbors = topotools.find_neighbor_sites(sites=pores, logic=mode,
am=self._am['lil'],
flatten=flatten,
include_input=include_input)
return neighbors
def __init__(self, network=None, project=None, settings={}, name=None,
**kwargs):
if project is None:
project = network.project
hg = Mercury(network=network)
super().__init__(network=network, project=project, **kwargs)
op = Porosimetry(project=project, phase=hg)
self.settings['mip'] = op.name
mod = models.physics.capillary_pressure.washburn
for geom in project.geometries().values():
phys = GenericPhysics(network=network, phase=hg, geometry=geom)
phys.add_model(propname='throat.entry_pressure', model=mod)
if not project.geometries():
hg.add_model(propname='throat.entry_pressure', model=mod)
topotools.find_surface_pores(network=network)
op.set_inlets(pores=network.pores('surface'))
logger.info('Running MIP simulation')
op.run()
self.update(op)
import openpnm as op
pn = op.network.Cubic(shape=[10, 10, 10], spacing=0.0001)
fig = op.topotools.plot_connections(network=pn, throats=pn.Ts,
color='b', alpha=0.5)
fig = op.topotools.plot_coordinates(network=pn, pores=pn.Ps, fig=fig,
c='r', s=100)
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=[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
p_coords = np.array([network['pore.coords'][list(p)] for p in vertices],
dtype=object)
self['pore.vertices'] = p_coords
vertices = network.find_throat_facets()
t_coords = np.array([network['pore.coords'][list(t)] for t in vertices],
dtype=object)
self['throat.vertices'] = t_coords
self.in_hull_volume()
self['throat.normal'] = self._t_normals()
self['throat.centroid'] = self._centroids(verts=t_coords)
self['pore.centroid'] = self._centroids(verts=p_coords)
(self['pore.indiameter'],
self['pore.incenter']) = self._indiameter_from_fibers()
self._throat_props()
topotools.trim_occluded_throats(network=network, mask=self.name)
self['throat.volume'] = sp.zeros(1, dtype=float)
self['throat.length'] = sp.ones(1, dtype=float)
self['throat.length'] *= self.network.fiber_rad*2
cen_lens = self._throat_c2c()
self['throat.c2c'] = np.sum(cen_lens, axis=1)
cen_lens[cen_lens <= 0.0] = 1e-12
self['throat.conduit_lengths.pore1'] = cen_lens[:, 0]
self['throat.conduit_lengths.throat'] = cen_lens[:, 1]
self['throat.conduit_lengths.pore2'] = cen_lens[:, 2]
# Configurable Models
self.add_model(propname='throat.shape_factor',
model=gm.throat_shape_factor.compactness)
self.add_model(propname='pore.diameter',
model=gm.pore_size.equivalent_diameter)
self.add_model(propname='pore.area',
model=gm.pore_area.sphere,
Examples
--------
>>> import openpnm as op
>>> pn = op.network.Cubic(shape=[5, 5, 5])
>>> Ps = pn.find_connected_pores(throats=[0, 1])
>>> print(Ps)
[[0 1]
[1 2]]
>>> Ps = pn.find_connected_pores(throats=[0, 1], flatten=True)
>>> print(Ps)
[0 1 2]
"""
Ts = self._parse_indices(throats)
am = self.get_adjacency_matrix(fmt='coo')
pores = topotools.find_connected_sites(bonds=Ts, am=am,
flatten=flatten, logic=mode)
return pores
import openpnm as op
pn = op.network.Cubic(shape=[10, 10, 3])
pn.add_boundary_pores()
Ps = pn.pores('internal')
# Create figure showing internal pores
fig = op.topotools.plot_coordinates(network=pn, pores=Ps, c='b')
Ps = pn.pores('*boundary')
# Pass existing fig back into function to plot boundary pores
fig = op.topotools.plot_coordinates(network=pn, pores=Ps, fig=fig, c='r')
def _label_surface_pores(self):
r"""
"""
hits = sp.zeros_like(self.Ps, dtype=bool)
dims = topotools.dimensionality(self)
mn = sp.amin(self['pore.coords'], axis=0)
mx = sp.amax(self['pore.coords'], axis=0)
for ax in [0, 1, 2]:
if dims[ax]:
hits += self['pore.coords'][:, ax] <= mn[ax]
hits += self['pore.coords'][:, ax] >= mx[ax]
self['pore.surface'] = hits
# Label Voronoi pores on surface
Ps = self.find_neighbor_pores(pores=self.pores('surface'))
Ps = self['pore.voronoi']*self.tomask(pores=Ps)
self['pore.surface'][Ps] = True
# Label Voronoi and interconnect throats on surface
self['throat.surface'] = False
Ps = self.pores('surface')
Ts = self.find_neighbor_throats(pores=Ps, mode='intersection')
self['throat.surface'][Ts] = True
# Trim throats between Delaunay surface pores
Ps = self.pores(labels=['surface', 'delaunay'], mode='intersection')
Ts = self.find_neighbor_throats(pores=Ps, mode='intersection')
topotools.trim(network=self, throats=Ts)
# Move Delaunay surface pores to centroid of Voronoi facet
Ps = self.pores(labels=['surface', 'delaunay'], mode='intersection')
for P in Ps:
Ns = self.find_neighbor_pores(pores=P)
Ns = Ps = self['pore.voronoi']*self.tomask(pores=Ns)
coords = sp.mean(self['pore.coords'][Ns], axis=0)
self['pore.coords'][P] = coords
self['pore.internal'] = ~self['pore.surface']
Ps = self.pores('internal')
Ts = self.find_neighbor_throats(pores=Ps, mode='intersection')
self['throat.internal'] = False
self['throat.internal'][Ts] = True
# Clean-up