[Cython] Improve support for building derived Cython modules

The .pxd file now contains declarations for all of the cdef classes,
and is installed with the module.
This commit is contained in:
Ray Speth 2013-09-25 22:57:36 +00:00
parent 55ece82319
commit 7520170f30
7 changed files with 100 additions and 35 deletions

View file

@ -564,6 +564,8 @@ cdef extern from "wrappers.h":
cdef string stringify(x)
ctypedef void (*thermoMethod1d)(CxxThermoPhase*, double*) except +
cdef class _SolutionBase:
cdef CxxThermoPhase* thermo
cdef CxxKinetics* kinetics
@ -572,9 +574,28 @@ cdef class _SolutionBase:
cdef np.ndarray _selected_species
cdef object parent
cdef class ThermoPhase(_SolutionBase):
cdef double _mass_factor(self)
cdef double _mole_factor(self)
cpdef int element_index(self, element) except *
cpdef int species_index(self, species) except *
cdef np.ndarray _getArray1(self, thermoMethod1d method)
cdef void _setArray1(self, thermoMethod1d method, values) except *
cdef class InterfacePhase(ThermoPhase):
cdef CxxSurfPhase* surf
cdef class Kinetics(_SolutionBase):
pass
cdef class InterfaceKinetics(Kinetics):
pass
cdef class Mixture:
cdef CxxMultiPhase* mix
cdef list _phases
cpdef int element_index(self, element) except *
cdef class Func1:
cdef CxxFunc1* func
cdef object callable
@ -591,6 +612,21 @@ cdef class Reactor(ReactorBase):
cdef CxxReactor* reactor
cdef object _kinetics
cdef class Reservoir(ReactorBase):
pass
cdef class ConstPressureReactor(Reactor):
pass
cdef class IdealGasReactor(Reactor):
pass
cdef class IdealGasConstPressureReactor(Reactor):
pass
cdef class FlowReactor(Reactor):
pass
cdef class WallSurface:
cdef CxxWall* cxxwall
cdef object wall
@ -613,3 +649,65 @@ cdef class FlowDevice:
cdef str name
cdef ReactorBase _upstream
cdef ReactorBase _downstream
cdef class MassFlowController(FlowDevice):
pass
cdef class Valve(FlowDevice):
pass
cdef class PressureController(FlowDevice):
pass
cdef class ReactorNet:
cdef CxxReactorNet net
cdef list _reactors
cdef class Domain1D:
cdef CxxDomain1D* domain
cdef class Boundary1D(Domain1D):
cdef CxxBdry1D* boundary
cdef _SolutionBase phase
cdef class Inlet1D(Boundary1D):
cdef CxxInlet1D* inlet
cdef class Outlet1D(Boundary1D):
cdef CxxOutlet1D* outlet
cdef class OutletReservoir1D(Boundary1D):
cdef CxxOutletRes1D* outlet
cdef class SymmetryPlane1D(Boundary1D):
cdef CxxSymm1D* symm
cdef class Surface1D(Boundary1D):
cdef CxxSurf1D* surf
cdef class ReactingSurface1D(Boundary1D):
cdef CxxReactingSurf1D* surf
cdef class _FlowBase(Domain1D):
cdef CxxStFlow* flow
cdef _SolutionBase gas
cdef class FreeFlow(_FlowBase):
pass
cdef class AxisymmetricStagnationFlow(_FlowBase):
pass
cdef class Sim1D:
cdef CxxSim1D* sim
cdef readonly object domains
cdef object _initialized
cdef Func1 interrupt
cdef class ReactionPathDiagram:
cdef CxxReactionPathDiagram diagram
cdef CxxReactionPathBuilder builder
cdef Kinetics kinetics
cdef str element
cdef pybool built
cdef CxxStringStream _log

View file

@ -27,10 +27,6 @@ cdef class Mixture:
Each one stores its own state information locally, and synchronizes the
phases objects whenever it requires phase properties.
"""
cdef CxxMultiPhase* mix
cdef list _phases
def __cinit__(self, phases):
self.mix = new CxxMultiPhase()
self._phases = []

View file

@ -8,7 +8,6 @@ except ImportError:
from scipy.special import erf
cdef class Domain1D:
cdef CxxDomain1D* domain
def __cinit__(self, *args, **kwargs):
self.domain = NULL
@ -169,9 +168,6 @@ cdef class Boundary1D(Domain1D):
:param phase:
The (gas) phase corresponding to the adjacent flow domain
"""
cdef CxxBdry1D* boundary
cdef _SolutionBase phase
def __cinit__(self, *args, **kwargs):
self.boundary = NULL
@ -238,7 +234,6 @@ cdef class Inlet1D(Boundary1D):
domain - it must be either the leftmost or rightmost domain in a
stack.
"""
cdef CxxInlet1D* inlet
def __cinit__(self, *args, **kwargs):
self.inlet = new CxxInlet1D()
self.boundary = <CxxBdry1D*>(self.inlet)
@ -258,7 +253,6 @@ cdef class Outlet1D(Boundary1D):
A one-dimensional outlet. An outlet imposes a zero-gradient boundary
condition on the flow.
"""
cdef CxxOutlet1D* outlet
def __cinit__(self, *args, **kwargs):
self.outlet = new CxxOutlet1D()
self.boundary = <CxxBdry1D*>(self.outlet)
@ -271,7 +265,6 @@ cdef class OutletReservoir1D(Boundary1D):
"""
A one-dimensional outlet into a reservoir.
"""
cdef CxxOutletRes1D* outlet
def __cinit__(self, *args, **kwargs):
self.outlet = new CxxOutletRes1D()
self.boundary = <CxxBdry1D*>(self.outlet)
@ -282,7 +275,6 @@ cdef class OutletReservoir1D(Boundary1D):
cdef class SymmetryPlane1D(Boundary1D):
"""A symmetry plane."""
cdef CxxSymm1D* symm
def __cinit__(self, *args, **kwargs):
self.symm = new CxxSymm1D()
self.boundary = <CxxBdry1D*>(self.symm)
@ -293,7 +285,6 @@ cdef class SymmetryPlane1D(Boundary1D):
cdef class Surface1D(Boundary1D):
"""A solid surface."""
cdef CxxSurf1D* surf
def __cinit__(self, *args, **kwargs):
self.surf = new CxxSurf1D()
self.boundary = <CxxBdry1D*>(self.surf)
@ -304,7 +295,6 @@ cdef class Surface1D(Boundary1D):
cdef class ReactingSurface1D(Boundary1D):
"""A reacting solid surface."""
cdef CxxReactingSurf1D* surf
def __cinit__(self, *args, **kwargs):
self.surf = new CxxReactingSurf1D()
self.boundary = <CxxBdry1D*>(self.surf)
@ -328,8 +318,6 @@ cdef class ReactingSurface1D(Boundary1D):
cdef class _FlowBase(Domain1D):
""" Base class for 1D flow domains """
cdef CxxStFlow* flow
cdef _SolutionBase gas
def __cinit__(self, *args, **kwargs):
self.flow = NULL
@ -451,11 +439,6 @@ cdef class Sim1D:
Domains are ordered left-to-right, with domain number 0 at the left.
"""
cdef CxxSim1D* sim
cdef readonly object domains
cdef object _initialized
cdef Func1 interrupt
def __cinit__(self, *args, **kwargs):
self.sim = NULL

View file

@ -1,11 +1,4 @@
cdef class ReactionPathDiagram:
cdef CxxReactionPathDiagram diagram
cdef CxxReactionPathBuilder builder
cdef Kinetics kinetics
cdef str element
cdef pybool built
cdef CxxStringStream _log
def __init__(self, Kinetics kin, str element):
"""
Create a reaction path diagram for the fluxes of the element *element*

View file

@ -712,9 +712,6 @@ cdef class ReactorNet:
>>> reactor_network = ReactorNet([r1, r2])
>>> reactor_network.advance(time)
"""
cdef CxxReactorNet net
cdef list _reactors
def __init__(self, reactors=()):
self._reactors = [] # prevents premature garbage collection
for R in reactors:

View file

@ -2,8 +2,6 @@ cdef enum Thermasis:
mass_basis = 0
molar_basis = 1
ctypedef void (*thermoMethod1d)(CxxThermoPhase*, double*) except +
cdef class ThermoPhase(_SolutionBase):
"""
A phase with an equation of state.
@ -814,7 +812,6 @@ cdef class ThermoPhase(_SolutionBase):
cdef class InterfacePhase(ThermoPhase):
""" A class representing a surface or edge phase"""
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.')

View file

@ -61,4 +61,5 @@ setup(name="Cantera",
ext_modules = exts,
package_data = {'cantera.data': ['*.*'],
'cantera.test.data': ['*.*'],
'cantera.examples': ['*/*.*']})
'cantera.examples': ['*/*.*'],
'cantera': ['*.pxd']})