<s> """<STR_LIT>""" <EOL> from OpenPNM . Base import logging , Tools <EOL> from OpenPNM . Network import GenericNetwork <EOL> from OpenPNM . Phases import GenericPhase <EOL> import OpenPNM . Physics . models <EOL> import scipy as sp <EOL> logger = logging . getLogger ( __name__ ) <EOL> class GenericPhysics ( OpenPNM . Base . Core ) : <EOL> r"""<STR_LIT>""" <EOL> def __init__ ( self , network = None , phase = None , geometry = None , pores = [ ] , <EOL> throats = [ ] , ** kwargs ) : <EOL> super ( ) . __init__ ( ** kwargs ) <EOL> logger . name = self . name <EOL> if network is None : <EOL> network = GenericNetwork ( ) <EOL> self . network . update ( { network . name : network } ) <EOL> self . _net . physics . update ( { self . name : self } ) <EOL> if phase is None : <EOL> phase = GenericPhase ( network = self . _net ) <EOL> phase . physics . update ( { self . name : self } ) <EOL> self . phases . update ( { phase . name : phase } ) <EOL> if geometry is not None : <EOL> if ( sp . size ( pores ) > <NUM_LIT:0> ) or ( sp . size ( throats ) > <NUM_LIT:0> ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> pores = self . _net . toindices ( self . _net [ '<STR_LIT>' + geometry . name ] ) <EOL> throats = self . _net . toindices ( self . _net [ '<STR_LIT>' + geometry . name ] ) <EOL> self . _phases [ <NUM_LIT:0> ] [ '<STR_LIT>' + self . name ] = False <EOL> self . _phases [ <NUM_LIT:0> ] [ '<STR_LIT>' + self . name ] = False <EOL> self . _net [ '<STR_LIT>' + self . name ] = False <EOL> self . _net [ '<STR_LIT>' + self . name ] = False <EOL> try : <EOL> self . set_locations ( pores = pores , throats = throats ) <EOL> except : <EOL> self . controller . purge_object ( self ) <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def __getitem__ ( self , key ) : <EOL> element = key . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> if key . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] == self . name : <EOL> key = element + '<STR_LIT>' <EOL> if key in self . keys ( ) : <EOL> return super ( GenericPhysics , self ) . __getitem__ ( key ) <EOL> else : <EOL> return self . _phases [ <NUM_LIT:0> ] [ key ] [ self . _phases [ <NUM_LIT:0> ] [ element + '<STR_LIT:.>' + self . name ] ] <EOL> def _set_phase ( self , phase ) : <EOL> current_phase = self . _phases [ <NUM_LIT:0> ] <EOL> pore_label = current_phase . pop ( '<STR_LIT>' + self . name ) <EOL> throat_label = current_phase . pop ( '<STR_LIT>' + self . name ) <EOL> phase [ '<STR_LIT>' + self . name ] = pore_label <EOL> phase [ '<STR_LIT>' + self . name ] = throat_label <EOL> self . phases . clear ( ) <EOL> self . phases . update ( { phase . name : phase } ) <EOL> current_phase . physics . pop ( self . name ) <EOL> phase . physics . update ( { self . name : self } ) <EOL> def _get_phase ( self ) : <EOL> return self . _phases [ <NUM_LIT:0> ] <EOL> parent_phase = property ( fget = _get_phase , fset = _set_phase ) <EOL> def set_locations ( self , pores = [ ] , throats = [ ] , mode = '<STR_LIT>' ) : <EOL> r"""<STR_LIT>""" <EOL> if mode == '<STR_LIT>' : <EOL> for item in self . props ( ) : <EOL> if ( item not in self . models . keys ( ) ) or ( self . models [ item ] [ '<STR_LIT>' ] == '<STR_LIT>' ) : <EOL> raise Exception ( '<STR_LIT>' + <EOL> '<STR_LIT>' ) <EOL> if sp . size ( pores ) > <NUM_LIT:0> : <EOL> Tools . SetLocations . add ( obj = self , element = '<STR_LIT>' , <EOL> locations = pores ) <EOL> if sp . size ( throats ) > <NUM_LIT:0> : <EOL> Tools . SetLocations . add ( obj = self , element = '<STR_LIT>' , <EOL> locations = throats ) <EOL> if mode == '<STR_LIT>' : <EOL> if sp . size ( pores ) > <NUM_LIT:0> : <EOL> Tools . SetLocations . drop ( obj = self , element = '<STR_LIT>' , <EOL> locations = pores ) <EOL> if throats is not None : <EOL> Tools . SetLocations . drop ( obj = self , element = '<STR_LIT>' , <EOL> locations = throats ) <EOL> self . models . regenerate ( ) </s>
