importloggingimportnumpyasnpfromopenpnm.coreimportDomainfromopenpnm.utilsimportWorkspace,Docoratordocstr=Docorator()logger=logging.getLogger(__name__)ws=Workspace()__all__=['Phase',]@docstr.get_sections(base='PhaseSettings',sections=['Parameters'])@docstr.dedentclassPhaseSettings:r""" Parameters ---------- %(BaseSettings.parameters)s auto_interpolate : boolean If ``True`` then calls to a missing 'throat.<prop>' will automatically interpolate 'pore.<prop>', if present, and vice versa. If ``False`` a normal ``KeyError`` is raised. """auto_interpolate=Truedefault_domain='all'
[docs]@docstr.get_sections(base='Phase',sections=['Parameters'])@docstr.dedentclassPhase(Domain):r""" This class produces an empty object with no pore-scale models for calculating any thermophysical properties. Users must add models and specify parameters for all the properties they require. Parameters ---------- %(Base.parameters)s """def__init__(self,network,name='phase_?',**kwargs):super().__init__(network=network,name=name,**kwargs)self.settings._update(PhaseSettings())# Set standard conditions on the phaseself['pore.all']=np.ones([network.Np,],dtype=bool)self['throat.all']=np.ones([network.Nt,],dtype=bool)self['pore.temperature']=298.0self['pore.pressure']=101325.0def__setitem__(self,key,value):if'@'notinkey:super().__setitem__(key,value)else:# Deal with the fact that the label might only exist on the networkpropname,domain=key.split('@')element,prop=propname.split('.',1)try:# Fetch array from self if presenttemp=self[element+'.'+prop]exceptKeyError:# Otherwise create ittemp=self._initialize_empty_array_like(value,element)self[element+'.'+prop]=temp# Insert values into masked locationsmask=self.project._get_locations(element+'.'+domain)temp[mask]=valuedef__getitem__(self,key):try:# If key exists, just get itreturnsuper().__getitem__(key)exceptKeyError:passtry:# Allow look-up from network mostly for label/domain inforeturnself.network[key]except(KeyError,AttributeError):pass# Parse the keyelement,prop=key.split('.',1)if'@'inprop:prop,domain=prop.split('@')else:domain='all'# Get params directly if appropriateifelement=='param':returnself.params[prop]# Next get the data arrays, this is the case if @ notation was usedifelement+'.'+propinself.keys():vals=super().__getitem__(element+'.'+prop)else:# If above are not triggered then try to interpolatetry:ifself.settings['auto_interpolate']:if(element=='pore')and('throat.'+propnotinself.keys()):raiseKeyError(key)elif(element=='throat')and('pore.'+propnotinself.keys()):raiseKeyError(key)vals=self.interpolate_data(element+'.'+prop)else:raiseKeyError(key)exceptAttributeError:raiseKeyError(key)# Finally get locsifdomain=='all':locs=np.ones(self._count(element),dtype=bool)else:locs=self.project._get_locations(element+'.'+domain)returnvals[locs]