<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: <NAME> (<EMAIL>)
# License: TBD
# Copyright (c) 2013


"""
module __Tortuosity__: Network Tortuosity Algorithm
========================================================================

.. warning:: The classes of this module should be loaded through the 'Algorithms.__init__.py' file.

"""

import scipy as sp
import scipy.sparse.csgraph as spgr
import OpenPNM

from .__GenericAlgorithm__ import GenericAlgorithm

class Tortuosity(GenericAlgorithm):
    r"""
    Determines the tortuosity of the network using a shortest path search algorithm.

    Parameters
    ----------

    loglevel : integer, optional
        Level of the logger (10=Debug, 20=INFO, 30=Warning, 40=Error, 50=Critical)
    loggername : string, optional
        Set the name of the logger to be output on the console. Defaults to class name.

    Note
    ----
    n/a
    
    """

    def __init__(self, **kwargs):
        r"""

        """
        super(Tortuosity,self).__init__(**kwargs)
        self._logger.debug("Create Tortuosity Object")
        
    def estimate_time(self):
        r'''
        '''
        pn_temp = OpenPNM.Network.TestNet()
        graph = pn_temp.create_adjacency_matrix(sprsfmt='csr')
        self._net.tic()
        path = spgr.shortest_path(csgraph = graph, method='D', directed = False)
        t = self._net.toc(quiet=True)
        N = 125
        k = 6
        O = t/(N*(N*k + N*sp.log(N)))
        N = self._net.num_pores()
        k = sp.median(self._net.num_neighbors(pores=self._net.pores()))
        t_est = O*(N*(N*k + N*sp.log(N)))
        return t_est

    def run(self,fluid):
        r'''
        '''
        self._fluid = fluid
        self._logger.warning("This algorithm can take some time...")
        if 'throat.occupancy' in self._fluid.props():
            graph = self._net.create_adjacency_matrix(prop=self._fluid['throat.occupancy'],sprsfmt='csr')
        elif 'conns' in self._net._adjacency_matrix['csr'].keys():
            graph = self._net._adjacency_matrix['csr']['conns']
        else:
            self._net.create_adjacency_matrix()
            graph = self._net._adjacency_matrix['csr']['conns']
        self._net.tic()
        path = spgr.shortest_path(csgraph = graph, method='D', directed = False)
        self._net.toc()
        path = path*self._net._Lc
        
        Px = sp.array(self._net['pore.coords'][:,0],ndmin=2)
        Py = sp.array(self._net['pore.coords'][:,1],ndmin=2)
        Pz = sp.array(self._net['pore.coords'][:,2],ndmin=2)
        
        Cx = sp.square(Px.T - Px)
        Cy = sp.square(Py.T - Py)
        Cz = sp.square(Pz.T - Pz)
        Ds = sp.sqrt(Cx + Cy + Cz)
        
        temp = path/Ds
        
        temp[sp.isnan(temp)] = 0
        
        return temp
        
        
        




if __name__ == '__main__':
    print('no tests yet')
<commit_msg>Added final touches to Tortuosity - If no fluid is sent, it get dry tortuosity between every pair of pores - If a fluid IS sent, it will apply the 'throat.occupancy' to the connectivity matrix, to get the tortuosity in that phase. - This method returns as a 2D Nt x Nt matrix that can be nicely visualized with plt.imshow<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: <NAME> (<EMAIL>)
# License: TBD
# Copyright (c) 2013


"""
module __Tortuosity__: Network Tortuosity Algorithm
========================================================================

.. warning:: The classes of this module should be loaded through the 'Algorithms.__init__.py' file.

"""

import scipy as sp
import scipy.sparse.csgraph as spgr
import OpenPNM

from .__GenericAlgorithm__ import GenericAlgorithm

class Tortuosity(GenericAlgorithm):
    r"""
    Determines the tortuosity of the network using a shortest path search algorithm.

    Parameters
    ----------

    loglevel : integer, optional
        Level of the logger (10=Debug, 20=INFO, 30=Warning, 40=Error, 50=Critical)
    loggername : string, optional
        Set the name of the logger to be output on the console. Defaults to class name.

    Note
    ----
    n/a
    
    """

    def __init__(self, **kwargs):
        r"""

        """
        super(Tortuosity,self).__init__(**kwargs)
        self._logger.debug("Create Tortuosity Object")
        
    def estimate_time(self):
        r'''
        '''
        pn_temp = OpenPNM.Network.TestNet()
        graph = pn_temp.create_adjacency_matrix(sprsfmt='csr')
        self._net.tic()
        path = spgr.shortest_path(csgraph = graph, method='D', directed = False)
        t = self._net.toc(quiet=True)
        N = 125
        k = 6
        O = t/(N*(N*k + N*sp.log(N)))
        N = self._net.num_pores()
        k = sp.median(self._net.num_neighbors(pores=self._net.pores()))
        t_est = O*(N*(N*k + N*sp.log(N)))
        print("Based on the network size and PC performance, this algorithm will require: ",t_est,' seconds')
        return 

    def run(self,fluid=None):
        r'''
        '''
        self._logger.warning("This algorithm can take some time. \
        Use the estimate_time method to check time requirements for present network.")
        graph = self._net.create_adjacency_matrix(data=self._net['throat.length'],sprsfmt='csr')
        
        if fluid != None:
            self._fluid = fluid
            if 'throat.occupancy' in self._fluid.props():
                temp = self._net['throat.length']*(self._fluid['throat.occupancy']==1)
                graph = self._net.create_adjacency_matrix(data=temp,sprsfmt='csr',prop='temp')
        
        self._net.tic()
        path = spgr.shortest_path(csgraph = graph, method='D', directed = False)
        self._net.toc()
        
        Px = sp.array(self._net['pore.coords'][:,0],ndmin=2)
        Py = sp.array(self._net['pore.coords'][:,1],ndmin=2)
        Pz = sp.array(self._net['pore.coords'][:,2],ndmin=2)
        
        Cx = sp.square(Px.T - Px)
        Cy = sp.square(Py.T - Py)
        Cz = sp.square(Pz.T - Pz)
        Ds = sp.sqrt(Cx + Cy + Cz)
        
        temp = path/Ds
        
        temp[sp.isnan(temp)] = 0
        temp[sp.isinf(temp)] = 0
        
        return temp
        
        
        




if __name__ == '__main__':
    print('no tests yet')

{'fraction_non_alphanumeric': 0.15372374283895607, 'fraction_numerical': 0.008752387014640357, 'mean_word_length': 2.2974816369359914, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4023621', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1975, 'n_words': 481}