From 96f9b05f8c45259b0d57ad976da6a2ce6f28d70b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 6 Sep 2012 19:55:50 +0000 Subject: [PATCH] Added skeletal implementation of multiphase mixtures to new Python module --- interfaces/cython/cantera/__init__.py | 1 + interfaces/cython/cantera/mixture.pxd | 16 +++++++++++ interfaces/cython/cantera/mixture.pyx | 38 +++++++++++++++++++++++++ interfaces/cython/cantera/substance.pxd | 1 + interfaces/cython/cantera/substance.pyx | 4 +++ interfaces/cython/setup.py.in | 1 + 6 files changed, 61 insertions(+) create mode 100644 interfaces/cython/cantera/mixture.pxd create mode 100644 interfaces/cython/cantera/mixture.pyx diff --git a/interfaces/cython/cantera/__init__.py b/interfaces/cython/cantera/__init__.py index aeb237c7f..656ebae40 100644 --- a/interfaces/cython/cantera/__init__.py +++ b/interfaces/cython/cantera/__init__.py @@ -1,2 +1,3 @@ from .solution import * from .constants import * +from .mixture import * diff --git a/interfaces/cython/cantera/mixture.pxd b/interfaces/cython/cantera/mixture.pxd new file mode 100644 index 000000000..ace3dfa1a --- /dev/null +++ b/interfaces/cython/cantera/mixture.pxd @@ -0,0 +1,16 @@ +from solution cimport * + +cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera": + cdef cppclass CxxMultiPhase "Cantera::MultiPhase": + CxxMultiPhase() + void addPhase(CxxThermoPhase*, double) except + + void init() except + + double nSpecies() + void setTemperature(double) + double temperature() + void setPressure(double) + double pressure() + +cdef class Mixture: + cdef CxxMultiPhase* mix + cdef list _phases diff --git a/interfaces/cython/cantera/mixture.pyx b/interfaces/cython/cantera/mixture.pyx new file mode 100644 index 000000000..6cab45f08 --- /dev/null +++ b/interfaces/cython/cantera/mixture.pyx @@ -0,0 +1,38 @@ +from mixture cimport * + +cdef class Mixture: + def __cinit__(self, phases): + self.mix = new CxxMultiPhase() + self._phases = [] + + cdef _SolutionBase phase + for phase,moles in phases: + self.mix.addPhase(phase.thermo, moles) + self._phases.append(phase) + + self.mix.init() + if self._phases: + self.pressure = self._phases[0].pressure + self.temperature = self._phases[0].temperature + + def __dealloc__(self): + del self.mix + + def phase(self, n): + return self._phases[n] + + property nSpecies: + def __get__(self): + return self.mix.nSpecies() + + property temperature: + def __get__(self): + return self.mix.temperature() + def __set__(self, T): + self.mix.setTemperature(T) + + property pressure: + def __get__(self): + return self.mix.pressure() + def __set__(self, P): + self.mix.setPressure(P) diff --git a/interfaces/cython/cantera/substance.pxd b/interfaces/cython/cantera/substance.pxd index 0270e9bf4..e92bbe904 100644 --- a/interfaces/cython/cantera/substance.pxd +++ b/interfaces/cython/cantera/substance.pxd @@ -5,6 +5,7 @@ cdef extern from "cantera/thermo/ThermoPhase.h" namespace "Cantera": cdef cppclass CxxThermoPhase "Cantera::ThermoPhase": CxxThermoPhase() double pressure() except + + double temperature() except + void setMoleFractions(double*) except + void getMassFractions(double*) except + int nSpecies() diff --git a/interfaces/cython/cantera/substance.pyx b/interfaces/cython/cantera/substance.pyx index 69baf0f4b..eb5a5ef99 100644 --- a/interfaces/cython/cantera/substance.pyx +++ b/interfaces/cython/cantera/substance.pyx @@ -54,6 +54,10 @@ cdef class ThermoPhase(_SolutionBase): def __get__(self): return self.thermo.pressure() + property temperature: + def __get__(self): + return self.thermo.temperature() + def setMoleFractions(self, X): if len(X) != self.nSpecies: raise ValueError("Mole fraction array has incorrect length") diff --git a/interfaces/cython/setup.py.in b/interfaces/cython/setup.py.in index 15c843c8b..954b844f5 100644 --- a/interfaces/cython/setup.py.in +++ b/interfaces/cython/setup.py.in @@ -21,6 +21,7 @@ def addExtension(name): extra_link_args=@py_extra_link_args@)) addExtension('solution') +addExtension('mixture') addExtension('utils') addExtension('constants')