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


"""
module __OrdinaryPercolation__: Ordinary Percolation Algorithm
========================================================================

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

"""

import scipy as sp
import numpy as np
import scipy.sparse as sprs
import matplotlib.pyplot as plt

from .__GenericAlgorithm__ import GenericAlgorithm

class OrdinaryPercolation(GenericAlgorithm):
    r"""
    Simulates a capillary drainage experiment by looping through a list of 
    capillary pressures.  

    Parameters
    ----------
    network : OpenPNM Network Object
        The network upon which the simulation will be run
    name : string, optional
        The name to assign to the Algorithm Object

    Notes
    -----
    To run this algorithm, use 'setup()' to provide the necessary simulation 
    parameters, and then use 'run()' to execute it.  Use 'update()' to send
    the results of the simulation out of the algorithm object.
    """

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

        """
        super(OrdinaryPercolation,self).__init__(**kwargs)
        self._logger.debug("Create Drainage Percolation Algorithm Object")
        
    def setup(self,
              invading_fluid=None,
              defending_fluid=None,
              inlets=[0], 
              npts=25, 
              inv_points=[],
              capillary_pressure = 'capillary_pressure', 
              AL=True,
              **params):
        r'''
        '''
        # Parse params
        self._fluid_inv = invading_fluid
        self._fluid_def = defending_fluid
        try: self._inv_sites
        except: self._inv_sites = inlets
        self._npts = npts
        self._inv_points = inv_points
        self._AL = AL
        self._p_cap = capillary_pressure

    def run(self):
        r'''
        '''
        #See if setup has been run
        try: self._p_cap
        except: raise Exception('setup has not been run, cannot proceed')
        #Create pore and throat conditions lists to store inv_val at which each is invaded
        self._p_inv = sp.zeros((self._net.num_pores(),),dtype=float)
        self._p_seq = sp.zeros_like(self._p_inv,dtype=int)
        self._t_inv = sp.zeros((self._net.num_throats(),),dtype=float)
        self._t_seq = sp.zeros_like(self._t_inv,dtype=int)
        #Determine the invasion pressures to apply
        self._t_cap = self._fluid_inv['throat.'+self._p_cap]
        if type(self._inv_points) == list:
            min_p = sp.amin(self._t_cap)*0.98  # nudge min_p down slightly
            max_p = sp.amax(self._t_cap)*1.02  # bump max_p up slightly
            self._logger.info('Generating list of invasion pressures')
            if min_p == 0:
                min_p = sp.linspace(min_p,max_p,self._npts)[1]
            self._inv_points = sp.logspace(sp.log10(min_p),sp.log10(max_p),self._npts)
        self._do_outer_iteration_stage()

    def _do_outer_iteration_stage(self):
        #Generate curve from points
        for inv_val in self._inv_points:
            #Apply one applied pressure and determine invaded pores
            self._logger.info('Applying capillary pressure: '+str(inv_val))
            self._do_one_inner_iteration(inv_val)
        #Store results using networks' get/set method
        self['pore.inv_Pc'] = self._p_inv
        self['throat.inv_Pc'] = self._t_inv
        #Find invasion sequence values (to correspond with IP algorithm)
        self._p_seq = sp.searchsorted(sp.unique(self._p_inv),self._p_inv)
        self._t_seq = sp.searchsorted(sp.unique(self._t_inv),self._t_inv)<commit_msg>changed OrdinaryPercolation to be executed with OP.run(...) instead of OP.setup(...) and subsequent OP.run()<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Author: <NAME> (<EMAIL>)
# License: TBD
# Copyright (c) 2013


"""
module __OrdinaryPercolation__: Ordinary Percolation Algorithm
========================================================================

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

"""

import scipy as sp
import numpy as np
import scipy.sparse as sprs
import matplotlib.pyplot as plt

from .__GenericAlgorithm__ import GenericAlgorithm

class OrdinaryPercolation(GenericAlgorithm):
    r"""
    Simulates a capillary drainage experiment by looping through a list of 
    capillary pressures.  

    Parameters
    ----------
    network : OpenPNM Network Object
        The network upon which the simulation will be run
    name : string, optional
        The name to assign to the Algorithm Object

    Notes
    -----
    To run this algorithm, use 'setup()' to provide the necessary simulation 
    parameters, and then use 'run()' to execute it.  Use 'update()' to send
    the results of the simulation out of the algorithm object.
    """

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

        """
        super(OrdinaryPercolation,self).__init__(**kwargs)
        self._logger.debug("Create Drainage Percolation Algorithm Object")
        
    def run(self,
              invading_fluid=None,
              defending_fluid=None,
              inlets=[0], 
              npts=25, 
              inv_points=[],
              capillary_pressure = 'capillary_pressure', 
              AL=True,
              **params):
        r'''
        '''
        # Parse params
        self._fluid_inv = invading_fluid
        self._fluid_def = defending_fluid
        try: self._inv_sites
        except: self._inv_sites = inlets
        self._npts = npts
        self._inv_points = inv_points
        self._AL = AL
        self._p_cap = capillary_pressure
        
        #Create pore and throat conditions lists to store inv_val at which each is invaded
        self._p_inv = sp.zeros((self._net.num_pores(),),dtype=float)
        self._p_seq = sp.zeros_like(self._p_inv,dtype=int)
        self._t_inv = sp.zeros((self._net.num_throats(),),dtype=float)
        self._t_seq = sp.zeros_like(self._t_inv,dtype=int)
        #Determine the invasion pressures to apply
        self._t_cap = self._fluid_inv['throat.'+self._p_cap]
        if type(self._inv_points) == list:
            min_p = sp.amin(self._t_cap)*0.98  # nudge min_p down slightly
            max_p = sp.amax(self._t_cap)*1.02  # bump max_p up slightly
            self._logger.info('Generating list of invasion pressures')
            if min_p == 0:
                min_p = sp.linspace(min_p,max_p,self._npts)[1]
            self._inv_points = sp.logspace(sp.log10(min_p),sp.log10(max_p),self._npts)
        self._do_outer_iteration_stage()

    def _do_outer_iteration_stage(self):
        #Generate curve from points
        for inv_val in self._inv_points:
            #Apply one applied pressure and determine invaded pores
            self._logger.info('Applying capillary pressure: '+str(inv_val))
            self._do_one_inner_iteration(inv_val)
        #Store results using networks' get/set method
        self['pore.inv_Pc'] = self._p_inv
        self['throat.inv_Pc'] = self._t_inv
        #Find invasion sequence values (to correspond with IP algorithm)
        self._p_seq = sp.searchsorted(sp.unique(self._p_inv),self._p_inv)
        self._t_seq = sp.searchsorted(sp.unique(self._t_inv),self._t_inv)
{'fraction_non_alphanumeric': 0.11665542818610924, 'fraction_numerical': 0.005394470667565745, 'mean_word_length': 2.5247148288973382, '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': '1075331', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2160, 'n_words': 574}