<commit_before>"""
module __GenericNetwork__: Abstract class to construct pore networks
==================================================================

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

"""

import sys, os
parent_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if sys.path[1] != parent_dir:
    sys.path.insert(1, parent_dir)
import OpenPNM
import numpy as np
import scipy as sp
import scipy.sparse as sprs

class GenericNetwork(OpenPNM.Utilities.Tools):
    r"""
    GenericNetwork - Base class to construct pore networks

    This class contains the interface definition for the construction of networks

    Parameters
    ----------
    name : string
        Unique name for Network object
    loglevel : int
        Level of the logger (10=Debug, 20=INFO, 30=Warning, 40=Error, 50=Critical)
    loggername : string (optional)
        Define the logger name to be used on console output. Defaults to class name.

    """

    def __init__(self, name=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericNetwork,self).__init__(**kwargs)
        self._logger.info("Construct Network")
        self.name = name
        #Initialize fluid, physics, and geometry tracking lists
        self._fluids = {}
        self._geometries = {}
        #Initialize adjacency and incidence matrix dictionaries
        self._incidence_matrix = {}
        self._adjacency_matrix = {}
        self.reset_graphs()
        self._logger.debug("Construction of Network container")

        
    def generate(self, **params):
        r"""
        Generate the network
        """
        self._logger.error('This method is not implemented')
 
    #--------------------------------------------------------------------------
    '''pore_data and throat_data interpolation methods'''
    #--------------------------------------------------------------------------
    def interpolate_pore_data(self,Tvals=None):
        r"""
        Determines a pore property as the average of it's neighboring throats

        Parameters
        ----------
        Tvals : array_like
            The array of throat information to be interpolated
        
        Returns
        -------
        Pvals : array_like
            An array of size Np contain interpolated throat data
            
        See Also
        --------
        interpolate_throat_data

        Notes
        -----
        This uses an unweighted average, without attempting to account for distances or sizes of pores and throats.
        
        Examples
        --------
        

        """
        if sp.size(Tvals)==1:
            Pvals = Tvals
        elif sp.size(Tvals) != self.num_throats():
            raise Exception('The list of throat information received was the wrong length')
        else:
            Pvals = sp.zeros((self.num_pores()))
            #Only interpolate conditions for internal pores, type=0
            Pnums = self.get_pore_indices()
            nTs = self.find_neighbor_throats(Pnums,flatten=False)
            for i in sp.r_[0:sp.shape(nTs)[0]]:
                Pvals[i] = sp.mean(Tvals[nTs[i]])
        return Pvals

    def interpolate_throat_data(self,Pvals=None):
        r"""
        Determines a throat property as the average of it's neighboring pores

        Parameters
        ----------
        Pvals : array_like
            The array of the pore condition to be interpolated
        
        Returns
        -------
        Tvals : array_like
            An array of size Nt contain interpolated pore data
            
        See Also
        --------
        interpolate_throat_data

        Notes
        -----
        This uses an unweighted average, without attempting to account for distances or sizes of pores and throats.

        Examples
        --------

        """
        if sp.size(Pvals)==1:
            Tvals = Pvals
        elif sp.size(Pvals) != self.num_pores():
            raise Exception('The list of pore information received was the wrong length')
        else:
            Tvals = sp.zeros((self.num_throats()))
            #Interpolate values for all throats, including those leading to boundary pores
            Tnums = sp.r_[0:self.num_throats()]
            nPs = self.find_connected_pores(Tnums,flatten=False)
            for i in sp.r_[0:sp.shape(nPs)[0]]:
                Tvals[i] = sp.mean(Pvals[nPs[i]])
        return Tvals

    def amalgamate_pore_data(self,fluids='all'):
        r"""
        Returns a dictionary containing ALL pore data from all fluids, physics and geometry objects
        """
        self._pore_data_amalgamate = {}
        if type(fluids)!= sp.ndarray and fluids=='all':
            fluids = self._fluids
        elif type(fluids)!= sp.ndarray: 
            fluids = sp.array(fluids,ndmin=1)
        #Add fluid data
        for item in fluids:
            if type(item)==sp.str_: item =  self.find_object_by_name(item)
            for key in item._pore_data.keys():
                if sp.amax(item._pore_data[key]) < sp.inf:
                    dict_name = item.name+'_pore_'+key
                    self._pore_data_amalgamate.update({dict_name : item._pore_data[key]})
            for key in item._pore_info.keys():
                if sp.amax(item._pore_info[key]) < sp.inf:
                    dict_name = item.name+'_pore_label_'+key
                    self._pore_data_amalgamate.update({dict_name : item._pore_info[key]})
        #Add geometry data
        for key in self._pore_data.keys():
            if sp.amax(self._pore_data[key]) < sp.inf:
                dict_name = 'pore'+'_'+key
                self._pore_data_amalgamate.update({dict_name : self._pore_data[key]})
        for key in self._pore_info.keys():
            if sp.amax(self._pore_info[key]) < sp.inf:
                dict_name = 'pore'+'_label_'+key
                self._pore_data_amalgamate.update({dict_name : self._pore_info[key]})
        return self._pore_data_amalgamate

    def amalgamate_throat_data(self,fluids='all'):
        r"""
        Returns a dictionary containing ALL throat data from all fluids, physics and geometry objects
        """
        self._throat_data_amalgamate = {}
        if type(fluids)!= sp.ndarray and fluids=='all':
            fluids = self._fluids
        elif type(fluids)!= sp.ndarray: 
            fluids = sp.array(fluids,ndmin=1)
        #Add fluid data
        for item in fluids:
            if type(item)==sp.str_: item =  self.find_object_by_name(item)
            for key in item._throat_data.keys():
                if sp.amax(item._throat_data[key]) < sp.inf:
                    dict_name = item.name+'_throat_'+key
                    self._throat_data_amalgamate.update({dict_name : item._throat_data[key]})
            for key in item._throat_info.keys():
                if sp.amax(item._throat_info[key]) < sp.inf:
                    dict_name = item.name+'_throat_label_'+key
                    self._throat_data_amalgamate.update({dict_name : item._throat_info[key]})
        #Add geometry data
        for key in self._throat_data.keys():
            if sp.amax(self._throat_data[key]) < sp.inf:
                dict_name = 'throat'+'_'+key
                self._throat_data_amalgamate.update({dict_name : self._throat_data[key]})
        for key in self._throat_info.keys():
            if sp.amax(self._throat_info[key]) < sp.inf:
                dict_name = 'throat'+'_label_'+key
                self._throat_data_amalgamate.update({dict_name : self._throat_info[key]})
        return self._throat_data_amalgamate

    #--------------------------------------------------------------------------
    '''Graph theory and topology related methods'''<commit_msg>change amalgamate data to ignore new pore and throat data used for voronoi geom<commit_after>"""
module __GenericNetwork__: Abstract class to construct pore networks
==================================================================

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

"""

import sys, os
parent_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if sys.path[1] != parent_dir:
    sys.path.insert(1, parent_dir)
import OpenPNM
import numpy as np
import scipy as sp
import scipy.sparse as sprs

class GenericNetwork(OpenPNM.Utilities.Tools):
    r"""
    GenericNetwork - Base class to construct pore networks

    This class contains the interface definition for the construction of networks

    Parameters
    ----------
    name : string
        Unique name for Network object
    loglevel : int
        Level of the logger (10=Debug, 20=INFO, 30=Warning, 40=Error, 50=Critical)
    loggername : string (optional)
        Define the logger name to be used on console output. Defaults to class name.

    """

    def __init__(self, name=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericNetwork,self).__init__(**kwargs)
        self._logger.info("Construct Network")
        self.name = name
        #Initialize fluid, physics, and geometry tracking lists
        self._fluids = {}
        self._geometries = {}
        #Initialize adjacency and incidence matrix dictionaries
        self._incidence_matrix = {}
        self._adjacency_matrix = {}
        self.reset_graphs()
        self._logger.debug("Construction of Network container")

        
    def generate(self, **params):
        r"""
        Generate the network
        """
        self._logger.error('This method is not implemented')
 
    #--------------------------------------------------------------------------
    '''pore_data and throat_data interpolation methods'''
    #--------------------------------------------------------------------------
    def interpolate_pore_data(self,Tvals=None):
        r"""
        Determines a pore property as the average of it's neighboring throats

        Parameters
        ----------
        Tvals : array_like
            The array of throat information to be interpolated
        
        Returns
        -------
        Pvals : array_like
            An array of size Np contain interpolated throat data
            
        See Also
        --------
        interpolate_throat_data

        Notes
        -----
        This uses an unweighted average, without attempting to account for distances or sizes of pores and throats.
        
        Examples
        --------
        

        """
        if sp.size(Tvals)==1:
            Pvals = Tvals
        elif sp.size(Tvals) != self.num_throats():
            raise Exception('The list of throat information received was the wrong length')
        else:
            Pvals = sp.zeros((self.num_pores()))
            #Only interpolate conditions for internal pores, type=0
            Pnums = self.get_pore_indices()
            nTs = self.find_neighbor_throats(Pnums,flatten=False)
            for i in sp.r_[0:sp.shape(nTs)[0]]:
                Pvals[i] = sp.mean(Tvals[nTs[i]])
        return Pvals

    def interpolate_throat_data(self,Pvals=None):
        r"""
        Determines a throat property as the average of it's neighboring pores

        Parameters
        ----------
        Pvals : array_like
            The array of the pore condition to be interpolated
        
        Returns
        -------
        Tvals : array_like
            An array of size Nt contain interpolated pore data
            
        See Also
        --------
        interpolate_throat_data

        Notes
        -----
        This uses an unweighted average, without attempting to account for distances or sizes of pores and throats.

        Examples
        --------

        """
        if sp.size(Pvals)==1:
            Tvals = Pvals
        elif sp.size(Pvals) != self.num_pores():
            raise Exception('The list of pore information received was the wrong length')
        else:
            Tvals = sp.zeros((self.num_throats()))
            #Interpolate values for all throats, including those leading to boundary pores
            Tnums = sp.r_[0:self.num_throats()]
            nPs = self.find_connected_pores(Tnums,flatten=False)
            for i in sp.r_[0:sp.shape(nPs)[0]]:
                Tvals[i] = sp.mean(Pvals[nPs[i]])
        return Tvals

    def amalgamate_pore_data(self,fluids='all'):
        r"""
        Returns a dictionary containing ALL pore data from all fluids, physics and geometry objects
        """
        self._pore_data_amalgamate = {}
        if type(fluids)!= sp.ndarray and fluids=='all':
            fluids = self._fluids
        elif type(fluids)!= sp.ndarray: 
            fluids = sp.array(fluids,ndmin=1)
        #Add fluid data
        for item in fluids:
            if type(item)==sp.str_: item =  self.find_object_by_name(item)
            for key in item._pore_data.keys():
                if (sp.amax(item._pore_data[key]) < sp.inf) and (key != 'vertices') and (key != 'centroid'):
                    dict_name = item.name+'_pore_'+key
                    self._pore_data_amalgamate.update({dict_name : item._pore_data[key]})
            for key in item._pore_info.keys():
                if sp.amax(item._pore_info[key]) < sp.inf:
                    dict_name = item.name+'_pore_label_'+key
                    self._pore_data_amalgamate.update({dict_name : item._pore_info[key]})
        #Add geometry data
        for key in self._pore_data.keys():
            if (key != 'vertices') and (key != 'centroid'):
                if sp.amax(self._pore_data[key]) < sp.inf:
                    dict_name = 'pore'+'_'+key
                    self._pore_data_amalgamate.update({dict_name : self._pore_data[key]})
        for key in self._pore_info.keys():
            if sp.amax(self._pore_info[key]) < sp.inf:
                dict_name = 'pore'+'_label_'+key
                self._pore_data_amalgamate.update({dict_name : self._pore_info[key]})
        return self._pore_data_amalgamate

    def amalgamate_throat_data(self,fluids='all'):
        r"""
        Returns a dictionary containing ALL throat data from all fluids, physics and geometry objects
        """
        self._throat_data_amalgamate = {}
        if type(fluids)!= sp.ndarray and fluids=='all':
            fluids = self._fluids
        elif type(fluids)!= sp.ndarray: 
            fluids = sp.array(fluids,ndmin=1)
        #Add fluid data
        for item in fluids:
            if type(item)==sp.str_: item =  self.find_object_by_name(item)
            for key in item._throat_data.keys():
                if key != 'offset_verts':
                    if sp.amax(item._throat_data[key]) < sp.inf:
                        dict_name = item.name+'_throat_'+key
                        self._throat_data_amalgamate.update({dict_name : item._throat_data[key]})
            for key in item._throat_info.keys():
                if sp.amax(item._throat_info[key]) < sp.inf:
                    dict_name = item.name+'_throat_label_'+key
                    self._throat_data_amalgamate.update({dict_name : item._throat_info[key]})
        #Add geometry data
        for key in self._throat_data.keys():
                if key != 'offset_verts':
                    if sp.amax(self._throat_data[key]) < sp.inf:
                        dict_name = 'throat'+'_'+key
                        self._throat_data_amalgamate.update({dict_name : self._throat_data[key]})
        for key in self._throat_info.keys():
            if sp.amax(self._throat_info[key]) < sp.inf:
                dict_name = 'throat'+'_label_'+key
                self._throat_data_amalgamate.update({dict_name : self._throat_info[key]})
        return self._throat_data_amalgamate

    #--------------------------------------------------------------------------
    '''Graph theory and topology related methods'''
{'fraction_non_alphanumeric': 0.13618603478699268, 'fraction_numerical': 0.0027728762288883285, 'mean_word_length': 1.8449264969523127, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, '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': '2748166', 'n_tokens_mistral': 4644, 'n_tokens_neox': 4345, 'n_words': 1112}