[Python] Add access to p-log reactions

This commit is contained in:
Ray Speth 2015-04-24 17:33:04 -04:00
parent d3d303c4e9
commit 5fb9f95004
2 changed files with 27 additions and 2 deletions

View file

@ -1,6 +1,7 @@
from libcpp.vector cimport vector
from libcpp.string cimport string
from libcpp.map cimport map as stdmap
from libcpp.pair cimport pair
from libcpp cimport bool as cbool
from cpython cimport bool as pybool
@ -253,6 +254,12 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
CxxThirdBody third_body
shared_ptr[CxxFalloff] falloff
cdef cppclass CxxPlog "Cantera::Plog":
vector[pair[double,CxxArrhenius]] rates()
cdef cppclass CxxPlogReaction "Cantera::PlogReaction" (CxxReaction):
CxxPlog rate
cdef extern from "cantera/kinetics/Kinetics.h" namespace "Cantera":
cdef cppclass CxxKinetics "Cantera::Kinetics":

View file

@ -68,9 +68,9 @@ cdef class Reaction:
cdef class Arrhenius:
def __cinit__(self, init=True):
def __cinit__(self, A=0, b=0, E=0, init=True):
if init:
self.rate = new CxxArrhenius()
self.rate = new CxxArrhenius(A, b, E)
self.reaction = None
def __dealloc__(self):
@ -96,6 +96,11 @@ cdef wrapArrhenius(CxxArrhenius* rate, Reaction reaction):
r.reaction = reaction
return r
cdef copyArrhenius(CxxArrhenius* rate):
r = Arrhenius(rate.preExponentialFactor(), rate.temperatureExponent(),
rate.activationEnergy_R())
return r
cdef class ElementaryReaction(Reaction):
property rate:
@ -183,6 +188,17 @@ cdef class ChemicallyActivatedReaction(FalloffReaction):
pass
cdef class PlogReaction(Reaction):
property rates:
def __get__(self):
cdef CxxPlogReaction* r = <CxxPlogReaction*>self.reaction
rates = []
cdef vector[pair[double,CxxArrhenius]] cxxrates = r.rate.rates()
cdef pair[double,CxxArrhenius] p_rate
for p_rate in cxxrates:
rates.append((p_rate.first,copyArrhenius(&p_rate.second)))
return rates
cdef Reaction wrapReaction(shared_ptr[CxxReaction] reaction):
"""
Wrap a C++ Reaction object with a Python object of the correct derived type.
@ -197,6 +213,8 @@ cdef Reaction wrapReaction(shared_ptr[CxxReaction] reaction):
R = FalloffReaction(init=False)
elif reaction_type == CHEMACT_RXN:
R = ChemicallyActivatedReaction(init=False)
elif reaction_type == PLOG_RXN:
R = PlogReaction(init=False)
else:
R = Reaction(init=False)