[Python] Outline of a strategy for wrapping classes which extend Transport

This commit is contained in:
Ray Speth
2012-09-06 19:56:58 +00:00
parent 95b75409be
commit c7570dc6c9
5 changed files with 28 additions and 7 deletions

View File

@@ -61,7 +61,6 @@ cdef extern from "cantera/transport/DustyGasTransport.h" namespace "Cantera":
cdef cppclass CxxDustyGasTransport "Cantera::DustyGasTransport":
void setPorosity(double) except +
cdef extern from "cantera/equil/MultiPhase.h" namespace "Cantera":
cdef cppclass CxxMultiPhase "Cantera::MultiPhase":
CxxMultiPhase()

View File

@@ -30,11 +30,12 @@ cdef class _SolutionBase:
else:
self.kinetics = NULL
# Transport
# Initialization of transport is deferred to Transport.__init__
self.transport = NULL
def __init__(self, *args, **kwargs):
if isinstance(self, Transport):
self.transport = newDefaultTransportMgr(self.thermo)
else:
self.transport = NULL
assert self.transport is not NULL
def __dealloc__(self):
del self.thermo

View File

@@ -1,6 +1,8 @@
class Solution(ThermoPhase, Kinetics, Transport):
def __init__(self, *args, **kwars):
pass
pass
class Interface(InterfacePhase, Kinetics):
pass
class DustyGas(ThermoPhase, Kinetics, DustyGasTransport):
pass

View File

@@ -9,3 +9,9 @@ class TestTransport(utilities.CanteraTest):
def test_viscosity(self):
self.assertTrue(self.phase.viscosity > 0.0)
class TestDustyGas(utilities.CanteraTest):
def test_methods(self):
self.phase = ct.DustyGas('h2o2.xml')
self.phase.setPorosity(0.2)

View File

@@ -1,4 +1,17 @@
cdef class Transport(_SolutionBase):
def __init__(self, *args, **kwargs):
if self.transport == NULL:
self.transport = newDefaultTransportMgr(self.thermo)
super().__init__(*args, **kwargs)
property viscosity:
def __get__(self):
return self.transport.viscosity()
cdef class DustyGasTransport(Transport):
def __init__(self, *args, **kwargs):
self.transport = newTransportMgr(stringify("DustyGas"), self.thermo)
super().__init__(*args, **kwargs)
def setPorosity(self, value):
(<CxxDustyGasTransport*>self.transport).setPorosity(value)