diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index 5e00130cc..a2ef26092 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -235,6 +235,25 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera": CxxThirdBodyReaction() CxxThirdBody third_body + cdef cppclass CxxFalloff "Cantera::Falloff": + CxxFalloff() + void updateTemp(double, double*) + double F(double, double*) + size_t workSize() + + size_t nParameters() + int getType() + void getParameters(double*) + + cdef cppclass CxxFalloffReaction "Cantera::FalloffReaction" (CxxReaction): + CxxFalloffReaction() + + CxxArrhenius low_rate + CxxArrhenius high_rate + CxxThirdBody third_body + shared_ptr[CxxFalloff] falloff + + cdef extern from "cantera/kinetics/Kinetics.h" namespace "Cantera": cdef cppclass CxxKinetics "Cantera::Kinetics": CxxKinetics() @@ -712,6 +731,10 @@ cdef class Arrhenius: cdef CxxArrhenius* rate cdef Reaction reaction # parent reaction, to prevent garbage collection +cdef class Falloff: + cdef shared_ptr[CxxFalloff] _falloff + cdef CxxFalloff* falloff + cdef class Kinetics(_SolutionBase): pass diff --git a/interfaces/cython/cantera/reaction.pyx b/interfaces/cython/cantera/reaction.pyx index e2a9481cc..947397a18 100644 --- a/interfaces/cython/cantera/reaction.pyx +++ b/interfaces/cython/cantera/reaction.pyx @@ -7,6 +7,9 @@ cdef extern from "cantera/kinetics/reaction_defs.h" namespace "Cantera": cdef int CHEMACT_RXN cdef int INTERFACE_RXN + cdef int SIMPLE_FALLOFF + cdef int TROE_FALLOFF + cdef int SRI_FALLOFF cdef class Reaction: @@ -117,6 +120,69 @@ cdef class ThirdBodyReaction(ElementaryReaction): return self.tbr().third_body.efficiency(stringify(species)) +cdef class Falloff: + def __cinit__(self, init=True): + if init: + self._falloff.reset(new CxxFalloff()) + self.falloff = self._falloff.get() + + property type: + def __get__(self): + cdef int falloff_type = self.falloff.getType() + if falloff_type == SIMPLE_FALLOFF: + return "Simple" + elif falloff_type == TROE_FALLOFF: + return "Troe" + elif falloff_type == SRI_FALLOFF: + return "SRI" + else: + return "unknown" + + property parameters: + def __get__(self): + N = self.falloff.nParameters() + if N == 0: + return np.empty(0) + + cdef np.ndarray[np.double_t, ndim=1] data = np.empty(N) + self.falloff.getParameters(&data[0]) + return data + + def __call__(self, float T, float Pr): + N = max(self.falloff.workSize(), 1) + cdef np.ndarray[np.double_t, ndim=1] work = np.empty(N) + self.falloff.updateTemp(T, &work[0]) + return self.falloff.F(Pr, &work[0]) + + +cdef wrapFalloff(shared_ptr[CxxFalloff] falloff): + f = Falloff(init=False) + f._falloff = falloff + f.falloff = f._falloff.get() + return f + + +cdef class FalloffReaction(Reaction): + property low_rate: + def __get__(self): + cdef CxxFalloffReaction* r = self.reaction + return wrapArrhenius(&(r.low_rate), self) + + property high_rate: + def __get__(self): + cdef CxxFalloffReaction* r = self.reaction + return wrapArrhenius(&(r.high_rate), self) + + property falloff: + def __get__(self): + cdef CxxFalloffReaction* r = self.reaction + return wrapFalloff(r.falloff) + + +cdef class ChemicallyActivatedReaction(FalloffReaction): + pass + + cdef Reaction wrapReaction(shared_ptr[CxxReaction] reaction): """ Wrap a C++ Reaction object with a Python object of the correct derived type. @@ -127,6 +193,10 @@ cdef Reaction wrapReaction(shared_ptr[CxxReaction] reaction): R = ElementaryReaction(init=False) elif reaction_type == THREE_BODY_RXN: R = ThirdBodyReaction(init=False) + elif reaction_type == FALLOFF_RXN: + R = FalloffReaction(init=False) + elif reaction_type == CHEMACT_RXN: + R = ChemicallyActivatedReaction(init=False) else: R = Reaction(init=False)