diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index bbbd13a56..3d86eea52 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -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() diff --git a/interfaces/cython/cantera/base.pyx b/interfaces/cython/cantera/base.pyx index a76c39af4..019d90c05 100644 --- a/interfaces/cython/cantera/base.pyx +++ b/interfaces/cython/cantera/base.pyx @@ -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 diff --git a/interfaces/cython/cantera/composite.pyx b/interfaces/cython/cantera/composite.pyx index e5d3a4e83..d375e2c0a 100644 --- a/interfaces/cython/cantera/composite.pyx +++ b/interfaces/cython/cantera/composite.pyx @@ -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 diff --git a/interfaces/cython/cantera/test/test_transport.py b/interfaces/cython/cantera/test/test_transport.py index 0f5bad665..715d8daaa 100644 --- a/interfaces/cython/cantera/test/test_transport.py +++ b/interfaces/cython/cantera/test/test_transport.py @@ -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) diff --git a/interfaces/cython/cantera/transport.pyx b/interfaces/cython/cantera/transport.pyx index 23b80d552..a44ca2ce5 100644 --- a/interfaces/cython/cantera/transport.pyx +++ b/interfaces/cython/cantera/transport.pyx @@ -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): + (self.transport).setPorosity(value)