コード例 #1
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_connected_sites_with_logic_flattened(self):
     am = self.net.get_adjacency_matrix(fmt='coo')
     a = topotools.find_connected_sites(bonds=[0, 2],
                                        am=am,
                                        logic='or',
                                        flatten=True)
     assert np.all(a == [0, 1, 3])
     a = topotools.find_connected_sites(bonds=[0, 2],
                                        am=am,
                                        logic='and',
                                        flatten=True)
     assert np.all(a == [])
     a = topotools.find_connected_sites(bonds=[0, 2],
                                        am=am,
                                        logic='xor',
                                        flatten=True)
     assert np.all(a == [0, 3])
     a = topotools.find_connected_sites(bonds=[0, 2],
                                        am=am,
                                        logic='xnor',
                                        flatten=True)
     assert np.all(a == [1])
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(bonds=[0], am=am, logic='nor')
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(bonds=[0], am=am, logic='nand')
コード例 #2
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_given_am(self):
     am = self.net.create_adjacency_matrix(fmt='lil')
     Ts = topotools.find_neighbor_bonds(sites=[0], am=am)
     assert np.all(Ts == [0, 1])
     with pytest.raises(Exception):
         _ = topotools.find_neighbor_bonds(sites=[0],
                                           am=am,
                                           logic="unsupported_logic")
コード例 #3
0
ファイル: GraphToolsTest.py プロジェクト: yulilicau/OpenPNM
 def test_find_neighbor_bonds_with_am_exceptions(self):
     am = self.net.get_adjacency_matrix(fmt='coo')
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(sites=[1], am=am, flatten=True,
                                       logic='intersection')
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(sites=[1], am=am, flatten=False,
                                       logic='or')
コード例 #4
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbr_bonds_unflattened(self):
     im = self.net.create_incidence_matrix(fmt='lil')
     Ts = topotools.find_neighbor_bonds(sites=[0, 1, 5],
                                        logic="and",
                                        im=im,
                                        flatten=False)
     assert np.allclose(Ts, [np.array([], dtype="int64")] * 3)
コード例 #5
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_with_am_and_logic(self):
     am = self.net.get_adjacency_matrix(fmt='coo')
     im = self.net.get_incidence_matrix(fmt='coo')
     Ts1 = topotools.find_neighbor_bonds(sites=[1],
                                         am=am,
                                         flatten=True,
                                         logic='or')
     Ts2 = topotools.find_neighbor_bonds(sites=[1],
                                         im=im,
                                         flatten=True,
                                         logic='or')
     assert np.all(Ts1 == Ts2)
     Ts1 = topotools.find_neighbor_bonds(sites=[1],
                                         am=am,
                                         flatten=True,
                                         logic='xor')
     Ts2 = topotools.find_neighbor_bonds(sites=[1],
                                         im=im,
                                         flatten=True,
                                         logic='xor')
     assert np.all(Ts1 == Ts2)
     Ts1 = topotools.find_neighbor_bonds(sites=[1],
                                         am=am,
                                         flatten=True,
                                         logic='xnor')
     Ts2 = topotools.find_neighbor_bonds(sites=[1],
                                         im=im,
                                         flatten=True,
                                         logic='xnor')
     assert np.all(Ts1 == Ts2)
コード例 #6
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_with_logic(self):
     im = self.net.get_incidence_matrix(fmt='lil')
     a = topotools.find_neighbor_bonds(sites=[0, 2], im=im, logic='or')
     assert np.all(a == [0, 1, 3])
     a = topotools.find_neighbor_bonds(sites=[0, 2], im=im, logic='and')
     assert np.all(a == [])
     a = topotools.find_neighbor_bonds(sites=[0], im=im, logic='xor')
     assert np.all(a == [0, 1])
     a = topotools.find_neighbor_bonds(sites=[0], im=im, logic='xnor')
     assert np.all(a == [])
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(sites=[0], im=im, logic='nor')
     with pytest.raises(Exception):
         topotools.find_neighbor_bonds(sites=[0], im=im, logic='nand')
コード例 #7
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds(self):
     im = self.net.create_incidence_matrix(fmt='lil')
     Ts = topotools.find_neighbor_bonds(sites=[0], im=im)
     assert np.all(Ts == [0, 1])
     Ts = topotools.find_neighbor_bonds(sites=[1], im=im)
     assert np.all(Ts == [0, 2, 3, 5])
     Ts = topotools.find_neighbor_bonds(sites=[2], im=im)
     assert np.all(Ts == [3])
     Ts = topotools.find_neighbor_bonds(sites=[3], im=im)
     assert np.all(Ts == [1, 2, 4])
     Ts = topotools.find_neighbor_bonds(sites=[4], im=im)
     assert np.all(Ts == [4, 5, 6])
     Ts = topotools.find_neighbor_bonds(sites=[5], im=im)
     assert np.all(Ts == [6])
     Ts = topotools.find_neighbor_bonds(sites=[], im=im)
     assert Ts == []
コード例 #8
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_fmt_not_lil(self):
     # Make sure results are correct even if converting to lil internally
     im = self.net.create_incidence_matrix(fmt='coo')
     Ts = topotools.find_neighbor_bonds(sites=[0], im=im)
     assert np.all(Ts == [0, 1])
     Ts = topotools.find_neighbor_bonds(sites=[1], im=im)
     assert np.all(Ts == [0, 2, 3, 5])
     Ts = topotools.find_neighbor_bonds(sites=[2], im=im)
     assert np.all(Ts == [3])
     Ts = topotools.find_neighbor_bonds(sites=[3], im=im)
     assert np.all(Ts == [1, 2, 4])
     Ts = topotools.find_neighbor_bonds(sites=[4], im=im)
     assert np.all(Ts == [4, 5, 6])
     Ts = topotools.find_neighbor_bonds(sites=[5], im=im)
     assert np.all(Ts == [6])
コード例 #9
0
    def find_neighbor_throats(self, pores, mode='union', flatten=True):
        r"""
        Returns a list of throats neighboring the given pore(s)

        Parameters
        ----------
        pores : array_like
            Indices of pores whose neighbors are sought

        flatten : boolean, optional
            If ``True`` (default) a 1D array of unique throat indices is
            returned. If ``False`` the returned array contains arrays of
            neighboring throat indices for each input pore, in the order
            they were sent.

        mode : string
            Specifies logic to filter the resulting list.  Options are:

            **'or'** : (default) All neighbors of the input pores.  This is
            also known as the 'union' in set theory or 'any' in boolean logic.
            Both keywords are accepted and treated as 'or'.

            **'xor'** : Only neighbors of one and only one input pore.  This
            is useful for finding the thraots that are not shared by any of the
            input pores.

            **'xnor'** : Neighbors that are shared by two or more input pores.
            This is equivalent to finding all neighbors with 'or', minus those
            found with 'xor', and is useful for finding neighbors that the
            inputs have in common.

            **'and'** : Only neighbors shared by all input pores.  This is also
            known as 'intersection' in set theory and (somtimes) as 'all' in
            boolean logic.  Both keywords are accepted and treated as 'and'.

        Returns
        -------
        If ``flatten`` is ``True``, returns a 1D array of throat indices
        filtered according to the specified mode.  If ``flatten`` is ``False``,
        returns a list of lists, where each list contains the neighbors of the
        corresponding input pores.

        Notes
        -----
        The ``logic`` options are applied to neighboring bonds only, thus it
        is not possible to obtain bonds that are part of the global set but
        not neighbors. This is because (a) the list of global bonds might be
        very large, and (b) it is not possible to return a list of neighbors
        for each input site if global sites are considered.

        Examples
        --------
        >>> import openpnm as op
        >>> pn = op.network.Cubic(shape=[5, 5, 5])
        >>> Ts = pn.find_neighbor_throats(pores=[0, 1])
        >>> print(Ts)
        [  0   1 100 101 200 201]
        >>> Ts = pn.find_neighbor_throats(pores=[0, 1], flatten=False)
        >>> print(Ts)
        [array([  0, 100, 200]), array([  0,   1, 101, 201])]

        """
        pores = self._parse_indices(pores)
        if sp.size(pores) == 0:
            return sp.array([], ndmin=1, dtype=int)
        if 'lil' not in self._im.keys():
            self.get_incidence_matrix(fmt='lil')
        neighbors = topotools.find_neighbor_bonds(sites=pores,
                                                  logic=mode,
                                                  im=self._im['lil'],
                                                  flatten=flatten)
        return neighbors
コード例 #10
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_single(self):
     im = self.net.create_incidence_matrix(fmt='lil')
     Ts = topotools.find_neighbor_bonds(sites=0, im=im)
     assert np.all(Ts == [0, 1])
コード例 #11
0
ファイル: GraphToolsTest.py プロジェクト: ma-sadeghi/OpenPNM
 def test_find_neighbor_bonds_missing_both_am_and_im(self):
     with pytest.raises(Exception):
         _ = topotools.find_neighbor_bonds(sites=[0])