Closed ma-sadeghi closed 3 years ago
You'd have to do it in reverse order:
z = pn.num_neighbors(pores=pn.Ps)
orphans = np.where(z == 1)[0]
hits = set(pn.find_neighbor_pores(pores=i)).intersection(set(orphans))
Do you think this is relevant enough to make it a function? Probably not on the network class, but maybe in topotools? It could be generalized by changing the second line to np.where(z == X)
, with X being a value supplied by the user.
actually, the last line should be: np.intersect1d(pn.find_neighbor_pores(pores=i), orphans)
to keep everything in numpy
def find_neighbor_z(network, pore, z=1):
Nz = network.num_neighbors(pores=network.Ps)
orphans = np.where(Nz == z)[0]
hits = np.intersect1d(network.find_neighbor_pores(pores=pore), orphans)
return hits
Thanks @jgostick. It might be handy to have it under topotools
.
Did it work for you?
Did it work for you?
Yep, worked like a charm! Here's a sample script:
import numpy as np
import openpnm as op
import matplotlib.pyplot as plt
net = op.network.Cubic([4, 4])
Ts1 = net.find_neighbor_throats(pores=1)
op.topotools.trim(net, throats=Ts1[[1, 2]])
Ts2 = net.find_neighbor_throats(pores=4)
op.topotools.trim(net, throats=Ts2[[2]])
fig, ax = plt.subplots()
op.topotools.plot_coordinates(net, fig=fig, markersize=100)
op.topotools.plot_connections(net, fig=fig)
def find_neighbor_z(network, pore, z=1):
Nz = network.num_neighbors(pores=network.Ps)
orphans = np.where(Nz == z)[0]
hits = np.intersect1d(network.find_neighbor_pores(pores=pore), orphans)
return hits
Ps1 = find_neighbor_z(net, pore=0, z=1)
op.topotools.plot_coordinates(net, fig=fig, pores=Ps1, color="g", markersize=100)
Ps2 = find_neighbor_z(net, pore=0, z=2)
op.topotools.plot_coordinates(net, fig=fig, pores=Ps2, color="k", markersize=100)
Here's what I'm looking for:
I use it to find "orphan" pores in my problem. I'm not sure if it's worth implementing it in
OpenPNM
.