<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 setup(self,algorithm,inlets,outlets,conductance=str,quantity=str):
        r'''
        '''
        self._alg = algorithm
        self._conductance = 'throat.'+conductance.split('.')[-1]
        self._quantity = 'pore.'+quantity.split('.')[-1]
        
        #Analyze input and output pores
        #Check for coplanarity
        if self._net.iscoplanar(inlets) == False:
            raise Exception('The specified inlet pores do not define a plane')
        if self._net.iscoplanar(outlets) == False:
            raise Exception('The specified outlet pores do not define a plane')
        #Ensure pores are on a face of domain (only 1 non-self neighbor)
        PnI = self._net.find_neighbor_pores(pores=inlets,mode='not_intersection',excl_self=True)
        if sp.shape(PnI) != sp.shape(inlets):
            raise Exception('The supplied inlet pores have too many neighbors')
            return
        PnO = self._net.find_neighbor_pores(pores=outlets,mode='not_intersection',excl_self=True)
        if sp.shape(PnO) != sp.shape(outlets):
            raise Exception('The supplied outlet pores have too many neighbors')
            return
        
        self._Pin = inlets
        self._Pout = outlets
        
    def run(self):
        r'''
        '''
        Pn = pn.find_neighbor_pores(pores=Pin,excl_self=True)
        Ts = pn.find_connecting_throat(Pin,Pn)
        flow = air['throat.diffusive_conductance'][Ts]*(air['pore.mole_fraction'][Pin] - air['pore.mole_fraction'][Pout])
        
        
        #Fetch area and length of domain
        A = self._net.domain_area(face=self._Pin)
        L = self._net.domain_length(face_1=self._Pin,face_2=self._Pout)
        
        if self._alg.__class__.__name__ == 'FickianDiffusion':
            d1 = self._alg['pore.'+self._quantity][self._Pin][0]
            d2 = self._alg['pore.'+self._quantity][self._Pout][1]
            delta = d1 - d2
#            c = 
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        <commit_msg>This roughly works for diffusion<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 setup(self,algorithm,fluid,conductance=str,quantity=str):
        r'''
        '''
        self._alg = algorithm
        self._fluid = fluid
        self._conductance = 'throat.'+conductance.split('.')[-1]
        self._quantity = 'pore.'+quantity.split('.')[-1]
        
    def run(self):
        r'''
        '''
        #Determine boundary conditions by analyzing algorithm object
        Ps = self._alg.pores(labels='pore.Dirichlet')
        BCs = sp.unique(self._alg['pore.mole_fraction'][Ps])
        if sp.shape(BCs)[0] != 2:
            raise Exception('The supplied algorithm did not have appropriate BCs')
        inlets = sp.where(self._alg['pore.mole_fraction']==sp.amax(BCs))[0]
        outlets = sp.where(self._alg['pore.mole_fraction']==sp.amin(BCs))[0]

        #Analyze input and output pores
        #Check for coplanarity
        if self._net.iscoplanar(inlets) == False:
            raise Exception('The inlet pores do not define a plane')
        if self._net.iscoplanar(outlets) == False:
            raise Exception('The outlet pores do not define a plane')
        #Ensure pores are on a face of domain (only 1 non-self neighbor each)
        PnI = self._net.find_neighbor_pores(pores=inlets,mode='not_intersection',excl_self=True)
        if sp.shape(PnI) != sp.shape(inlets):
            raise Exception('The inlet pores have too many neighbors')
        PnO = self._net.find_neighbor_pores(pores=outlets,mode='not_intersection',excl_self=True)
        if sp.shape(PnO) != sp.shape(outlets):
            raise Exception('The outlet pores have too many neighbors')
        Pin = inlets
        Pout = outlets
        
        #Fetch area and length of domain
        A = self._net.domain_area(face=Pin)
        L = self._net.domain_length(face_1=Pin,face_2=Pout)
        
        #Find flow through inlet face
        Pn = self._net.find_neighbor_pores(pores=Pin,excl_self=True)
        Ts = self._net.find_connecting_throat(Pin,Pn)
        flow = self._fluid['throat.diffusive_conductance'][Ts]*(self._alg['pore.mole_fraction'][Pin] - self._alg['pore.mole_fraction'][Pn])
        
        #Calculate effective property for given algorithm
        if self._alg.__class__.__name__ == 'FickianDiffusion':
            if 'pore.molar_density' in self._fluid.props(mode='scalars'):
                D = sp.sum(flow)*L/A/self._fluid['pore.molar_density']/sp.absolute(BCs[0]-BCs[1])
                return D
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
{'fraction_non_alphanumeric': 0.13567410942560082, 'fraction_numerical': 0.003749786943923641, 'mean_word_length': 2.243781094527363, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7139282', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1723, 'n_words': 351}