def test_find_connecting_bonds_multiple_sites_fmt_not_dok(self): am = self.net.create_adjacency_matrix(weights=self.net.Ts, fmt='csr') T = topotools.find_connecting_bonds(sites=[[0, 1], [0, 3]], am=am) assert np.all(T == [0, 1]) T = topotools.find_connecting_bonds(sites=[[0, 1], [0, 3], [4, 5]], am=am) assert np.all(T == [0, 1, 6])
def find_connecting_throat(self, P1, P2): r""" Return the throat index connecting pairs of pores Parameters ---------- P1 , P2 : array_like The indices of the pores whose throats are sought. These can be vectors of indices, but must be the same length Returns ------- Returns a list the same length as P1 (and P2) with the each element containing the throat index that connects the corresponding pores, or `None`` if pores are not connected. Notes ----- The returned list can be converted to an ND-array, which will convert the ``None`` values to ``nan``. These can then be found using ``scipy.isnan``. Examples -------- >>> import openpnm as op >>> pn = op.network.Cubic(shape=[5, 5, 5]) >>> Ts = pn.find_connecting_throat([0, 1, 2], [2, 2, 2]) >>> print(Ts) [None, 1, None] """ am = self.create_adjacency_matrix(weights=self.Ts, fmt='coo') sites = sp.vstack((P1, P2)).T Ts = topotools.find_connecting_bonds(sites=sites, am=am) return Ts
def test_find_connecting_bonds_fmt_not_dok(self): am = self.net.create_adjacency_matrix(weights=self.net.Ts, fmt='csr') T = topotools.find_connecting_bonds(sites=[0, 1], am=am) assert np.all(T == [0]) T = topotools.find_connecting_bonds(sites=[0, 3], am=am) assert np.all(T == [1]) T = topotools.find_connecting_bonds(sites=[1, 3], am=am) assert np.all(T == [2]) T = topotools.find_connecting_bonds(sites=[1, 2], am=am) assert np.all(T == [3]) T = topotools.find_connecting_bonds(sites=[3, 4], am=am) assert np.all(T == [4]) T = topotools.find_connecting_bonds(sites=[1, 4], am=am) assert np.all(T == [5]) T = topotools.find_connecting_bonds(sites=[4, 5], am=am) assert np.all(T == [6])
def test_find_connecting_bonds_nonexistant_connections(self): am = self.net.create_adjacency_matrix(weights=self.net.Ts, fmt='dok') T = topotools.find_connecting_bonds(sites=[0, 5], am=am) assert np.all(T == [None]) T = topotools.find_connecting_bonds(sites=[[0, 1], [0, 5]], am=am) assert np.all(T == [0, None])
def test_find_connecting_bonds_no_sites(self): am = self.net.create_adjacency_matrix(weights=self.net.Ts, fmt='dok') T = topotools.find_connecting_bonds(sites=[], am=am) assert T == [] T = topotools.find_connecting_bonds(sites=[[], []], am=am) assert T == []