<commit_before>"""
module __EffectiveProperty__: Base class to estimate transport properties
===============================================================================

"""
import OpenPNM
import scipy as sp
import scipy.signal as spsg
import scipy.spatial as sptl

from .__GenericAlgorithm__ import GenericAlgorithm

class EffectiveProperty(GenericAlgorithm):
    r'''
    '''
    def __init__(self,**kwargs):
        r'''
        '''
        super(EffectiveProperty,self).__init__(**kwargs)
        self._logger.info("Construct Algorithm")
        
    def calculate(self,algorithm,clean=False):
        r'''
        '''
        self._alg = algorithm
        self._fluid = algorithm._fluid
        conductance = algorithm._conductance
        self._conductance = algorithm._conductance
        self._quantity =  algorithm._quantity
        self._clean = clean
        
        self._execute()
#        if self._clean:
#            self._calc_eff_prop_tensor(fluid=fluid,alg=algorithm,...)
#        else:
#            if 'pore.Dirichlet' in algorithm.labels():
#                #code that calls _execute for the algorithms preset boundaries.
#                _execute(self)
#            else:
#                self._calc_eff_prop_tensor(fluid=fluid,alg=algorithm,...)
#            
                
        
        
    def _execute(self):
        #Determine boundary conditions by analyzing algorithm object
        Ps = self._alg.pores(labels='pore.Dirichlet')
        BCs = sp.unique(self._alg['pore.bcval_Dirichlet'][Ps])
        if sp.shape(BCs)[0] != 2:
            raise Exception('The supplied algorithm did not have appropriate BCs')
        inlets = sp.where(self._alg['pore.bcval_Dirichlet']==sp.amax(BCs))[0]
        outlets = sp.where(self._alg['pore.bcval_Dirichlet']==sp.amin(BCs))[0]
        
        #Fetch area and length of domain
        A = self._net.domain_area(face=inlets)
        L = self._net.domain_length(face_1=inlets,face_2=outlets)
    
        x = self._alg.get_data(self._quantity)
        #Find flow through inlet face
        Pin = []
        Pn = []
        for pore in inlets:
            pore_concentration = x[pore]
            neighbors = self._net.find_neighbor_pores(pore, excl_self = True)
            for neighbor in neighbors:
                neighbor_concentration = x[neighbor]
                if(sp.absolute(neighbor_concentration - pore_concentration) > .000001):
                    Pin.append(pore)
                    Pn.append(neighbor)
        
        Ts = self._net.find_connecting_throat(Pin,Pn)
        g = self._fluid[self._conductance][Ts]
        s = self._fluid['throat.occupancy'][Ts]
        xin = self._alg[self._quantity][Pin]
        xout = self._alg[self._quantity][Pn]
        flow = g*s*(sp.log(1-xin) - sp.log(1-xout))
        D = sp.sum(flow)*L/A/sp.absolute(BCs[0]-BCs[1])
        return D
        
    def _calc_eff_prop_tensor(self,                            
                       fluid,
                       alg,<commit_msg>cleaning up way of attaining mole fractions for pores<commit_after>"""
module __EffectiveProperty__: Base class to estimate transport properties
===============================================================================

"""
import OpenPNM
import scipy as sp
import scipy.signal as spsg
import scipy.spatial as sptl

from .__GenericAlgorithm__ import GenericAlgorithm

class EffectiveProperty(GenericAlgorithm):
    r'''
    '''
    def __init__(self,**kwargs):
        r'''
        '''
        super(EffectiveProperty,self).__init__(**kwargs)
        self._logger.info("Construct Algorithm")
        
    def calculate(self,algorithm,clean=False):
        r'''
        '''
        self._alg = algorithm
        self._fluid = algorithm._fluid
        conductance = algorithm._conductance
        self._conductance = algorithm._conductance
        self._quantity =  algorithm._quantity
        self._clean = clean
        
        self._execute()
#        if self._clean:
#            self._calc_eff_prop_tensor(fluid=fluid,alg=algorithm,...)
#        else:
#            if 'pore.Dirichlet' in algorithm.labels():
#                #code that calls _execute for the algorithms preset boundaries.
#                _execute(self)
#            else:
#                self._calc_eff_prop_tensor(fluid=fluid,alg=algorithm,...)
#            
                
        
        
    def _execute(self):
        #Determine boundary conditions by analyzing algorithm object
        Ps = self._alg.pores(labels='pore.Dirichlet')
        BCs = sp.unique(self._alg['pore.bcval_Dirichlet'][Ps])
        if sp.shape(BCs)[0] != 2:
            raise Exception('The supplied algorithm did not have appropriate BCs')
        inlets = sp.where(self._alg['pore.bcval_Dirichlet']==sp.amax(BCs))[0]
        outlets = sp.where(self._alg['pore.bcval_Dirichlet']==sp.amin(BCs))[0]
        
        #Fetch area and length of domain
        A = self._net.domain_area(face=inlets)
        L = self._net.domain_length(face_1=inlets,face_2=outlets)
        x = self._alg[self._quantity]
        #Find flow through inlet face
        Pin = []
        Pn = []
        for pore in inlets:
            pore_concentration = x[pore]
            neighbors = self._net.find_neighbor_pores(pore, excl_self = True)
            for neighbor in neighbors:
                neighbor_concentration = x[neighbor]
                if(sp.absolute(neighbor_concentration - pore_concentration) > .000001):
                    Pin.append(pore)
                    Pn.append(neighbor)
        
        Ts = self._net.find_connecting_throat(Pin,Pn)
        g = self._fluid[self._conductance][Ts]
        s = self._fluid['throat.occupancy'][Ts]
        xin = x[Pin]
        xout = x[Pn]
        flow = g*s*(sp.log(1-xin) - sp.log(1-xout))
        D = sp.sum(flow)*L/A/sp.absolute(BCs[0]-BCs[1])
        return D
        
    def _calc_eff_prop_tensor(self,                            
                       fluid,
                       alg,
{'fraction_non_alphanumeric': 0.1315, 'fraction_numerical': 0.005333333333333333, 'mean_word_length': 2.0790148794253462, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '966211', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1712, 'n_words': 331}