[Python] Enable direct construction of PlogReaction

This commit is contained in:
Ray Speth 2015-04-30 19:23:44 -04:00
parent 2fff28f37c
commit 6458b0c50d
3 changed files with 54 additions and 0 deletions

View file

@ -10,6 +10,21 @@ cimport numpy as np
ctypedef stdmap[string,double] Composition
cdef extern from "<map>" namespace "std":
cdef cppclass multimap[T, U]:
cppclass iterator:
pair[T, U]& operator*() nogil
iterator operator++() nogil
iterator operator--() nogil
bint operator==(iterator) nogil
bint operator!=(iterator) nogil
multimap() nogil except +
U& operator[](T&) nogil
iterator begin() nogil
iterator end() nogil
pair[iterator, bint] insert(pair[T, U]) nogil
iterator find(T&) nogil
cdef extern from "cantera/base/xml.h" namespace "Cantera":
cdef cppclass XML_Node:
XML_Node* findByName(string)
@ -261,6 +276,7 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
CxxChemicallyActivatedReaction()
cdef cppclass CxxPlog "Cantera::Plog":
CxxPlog(multimap[double,CxxArrhenius])
vector[pair[double,CxxArrhenius]] rates()
cdef cppclass CxxPlogReaction "Cantera::PlogReaction" (CxxReaction):

View file

@ -332,6 +332,18 @@ cdef class PlogReaction(Reaction):
rates.append((p_rate.first,copyArrhenius(&p_rate.second)))
return rates
def __set__(self, rates):
cdef multimap[double,CxxArrhenius] ratemap
cdef Arrhenius rate
cdef pair[double,CxxArrhenius] item
for p,rate in rates:
item.first = p
item.second = deref(rate.rate)
ratemap.insert(item)
cdef CxxPlogReaction* r = <CxxPlogReaction*>self.reaction
r.rate = CxxPlog(ratemap)
cdef class ChebyshevReaction(Reaction):
reaction_type = CHEBYSHEV_RXN

View file

@ -692,3 +692,29 @@ class TestReaction(utilities.CanteraTest):
self.gas.forward_rate_constants[20])
self.assertNear(gas2.net_rates_of_progress[0],
self.gas.net_rates_of_progress[20])
def test_plog(self):
gas1 = ct.Solution('pdep-test.cti')
species = ct.Species.listFromFile('pdep-test.cti')
r = ct.PlogReaction()
r.reactants = {'R1A':1, 'R1B':1}
r.products = {'P1':1, 'H':1}
r.rates = [
(0.01*ct.one_atm, ct.Arrhenius(1.2124e13, -0.5779, 10872.7*4184)),
(1.0*ct.one_atm, ct.Arrhenius(4.9108e28, -4.8507, 24772.8*4184)),
(10.0*ct.one_atm, ct.Arrhenius(1.2866e44, -9.0246, 39796.5*4184)),
(100.0*ct.one_atm, ct.Arrhenius(5.9632e53, -11.529, 52599.6*4184))
]
gas2 = ct.Solution(thermo='IdealGas', kinetics='GasKinetics',
species=species, reactions=[r])
gas2.X = gas1.X = 'R1A:0.3, R1B:0.6, P1:0.1'
for P in [0.001, 0.01, 0.2, 1.0, 1.1, 9.0, 10.0, 99.0, 103.0]:
gas1.TP = gas2.TP = 900, P * ct.one_atm
self.assertNear(gas2.forward_rate_constants[0],
gas1.forward_rate_constants[0])
self.assertNear(gas2.net_rates_of_progress[0],
gas1.net_rates_of_progress[0])