Added basic implementation of surface and edge phases in the Python module

This commit is contained in:
Ray Speth 2012-09-06 19:56:30 +00:00
parent 341648aa23
commit 514abaa0da
4 changed files with 32 additions and 1 deletions

View file

@ -11,9 +11,14 @@ cdef extern from "cantera/base/xml.h" namespace "Cantera":
cdef extern from "cantera/base/ctml.h" namespace "ctml":
XML_Node getCtmlTree(string) except +
cdef extern from "cantera/thermo/mix_defs.h":
cdef int thermo_type_surf "Cantera::cSurf"
cdef int thermo_type_edge "Cantera::cEdge"
cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
cdef cppclass CxxThermoPhase "Cantera::ThermoPhase":
CxxThermoPhase()
int eosType()
double pressure() except +
double temperature() except +
void setMoleFractions(double*) except +
@ -21,6 +26,12 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera":
int nSpecies()
XML_Node& xml()
cdef extern from "cantera/thermo/SurfPhase.h":
cdef cppclass CxxSurfPhase "Cantera::SurfPhase":
CxxSurfPhase()
double siteDensity()
void setSiteDensity(double)
cdef extern from "cantera/kinetics/Kinetics.h" namespace "Cantera":
cdef cppclass CxxKinetics "Cantera::Kinetics":
CxxKinetics()

View file

@ -1,5 +1,5 @@
cdef class _SolutionBase:
def __cinit__(self, infile, phaseid=''):
def __cinit__(self, infile, phaseid='', phases=()):
rootNode = getCtmlTree(stringify(infile))
# Get XML data
@ -19,9 +19,13 @@ cdef class _SolutionBase:
# Kinetics
cdef vector[CxxThermoPhase*] v
cdef _SolutionBase phase
if isinstance(self, Kinetics):
v.push_back(self.thermo)
for phase in phases:
# adjacent bulk phases for a surface phase
v.push_back(phase.thermo)
self.kinetics = newKineticsMgr(deref(phaseNode), v)
else:
self.kinetics = NULL

View file

@ -2,3 +2,5 @@ class Solution(ThermoPhase, Kinetics, Transport):
def __init__(self, *args, **kwars):
pass
class Interface(InterfacePhase, Kinetics):
pass

View file

@ -22,3 +22,17 @@ cdef class ThermoPhase(_SolutionBase):
cdef np.ndarray[np.double_t, ndim=1] X_c = np.empty(self.nSpecies)
self.thermo.getMassFractions(&X_c[0])
return X_c
cdef class InterfacePhase(ThermoPhase):
cdef CxxSurfPhase* surf
def __cinit__(self, *args, **kwargs):
if self.thermo.eosType() not in (thermo_type_surf, thermo_type_edge):
raise TypeError('Underlying ThermoPhase object is of the wrong type.')
self.surf = <CxxSurfPhase*>(self.thermo)
property siteDensity:
def __get__(self):
return self.surf.siteDensity()
def __set__(self, double value):
self.surf.setSiteDensity(value)