[Python] Implemented more ThermoPhase properties

This commit is contained in:
Ray Speth 2012-09-06 19:57:48 +00:00
parent aa032c1996
commit 370ba39a8c
2 changed files with 61 additions and 1 deletions

View file

@ -26,9 +26,16 @@ cdef extern from "cantera/thermo/mix_defs.h":
cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
cdef cppclass CxxThermoPhase "Cantera::ThermoPhase":
CxxThermoPhase()
# miscellaneous
int eosType()
XML_Node& xml()
string report(cbool) except +
string name()
void setName(string)
double minTemp() except +
double maxTemp() except +
double refPressure() except +
cbool getElementPotentials(double*) except +
# basic thermodynamic properties
double temperature() except +
@ -38,6 +45,8 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
double molarVolume() except +
double isothermalCompressibility() except +
double thermalExpansionCoeff() except +
double electricPotential() except +
void setElectricPotential(double) except +
# element properties
size_t nElements()

View file

@ -15,6 +15,12 @@ cdef class ThermoPhase(_SolutionBase):
def __call__(self):
print(self.report())
property name:
def __get__(self):
return pystr(self.thermo.name())
def __set__(self, name):
self.thermo.setName(stringify(name))
property basis:
def __get__(self):
if self.thermoBasis == massBasis:
@ -66,6 +72,10 @@ cdef class ThermoPhase(_SolutionBase):
def elementName(self, m):
return pystr(self.thermo.elementName(m))
property elementNames:
def __get__(self):
return [self.elementName(m) for m in range(self.nElements)]
property nSpecies:
def __get__(self):
return self.thermo.nSpecies()
@ -73,6 +83,10 @@ cdef class ThermoPhase(_SolutionBase):
def speciesName(self, k):
return pystr(self.thermo.speciesName(k))
property speciesNames:
def __get__(self):
return [self.speciesName(k) for k in range(self.nSpecies)]
cpdef int speciesIndex(self, species) except *:
if isinstance(species, str):
index = self.thermo.speciesIndex(stringify(species))
@ -110,6 +124,10 @@ cdef class ThermoPhase(_SolutionBase):
def molecularWeight(self, species):
return self.thermo.molecularWeight(self.speciesIndex(species))
property meanMolecularWeight:
def __get__(self):
return self.thermo.meanMolecularWeight()
property Y:
def __get__(self):
return self._getArray1(thermo_getMassFractions)
@ -386,6 +404,39 @@ cdef class ThermoPhase(_SolutionBase):
def __get__(self):
return self._getArray1(thermo_getCp_R)
######## Miscellaneous properties ########
property isothermalCompressibility:
def __get__(self):
return self.thermo.isothermalCompressibility()
property thermalExpansionCoeff:
def __get__(self):
return self.thermo.thermalExpansionCoeff()
property minTemp:
def __get__(self):
return self.thermo.minTemp()
property maxTemp:
def __get__(self):
return self.thermo.maxTemp()
property refPressure:
def __get__(self):
return self.thermo.refPressure()
property electricPotential:
def __get__(self):
return self.thermo.electricPotential()
def __set__(self, double value):
self.thermo.setElectricPotential(value)
property elementPotentials:
def __get__(self):
cdef np.ndarray[np.double_t, ndim=1] data = np.zeros(self.nElements)
self.thermo.getElementPotentials(&data[0])
return data
cdef class InterfacePhase(ThermoPhase):
cdef CxxSurfPhase* surf