[Python] Add functions for evaluating rate constants
This commit is contained in:
parent
af3e34ccb0
commit
0f6f9c8f5a
3 changed files with 45 additions and 0 deletions
|
|
@ -292,6 +292,8 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
|
|||
cdef cppclass CxxPlog "Cantera::Plog":
|
||||
CxxPlog(multimap[double,CxxArrhenius])
|
||||
vector[pair[double,CxxArrhenius]] rates()
|
||||
void update_C(double*)
|
||||
double updateRC(double, double)
|
||||
|
||||
cdef cppclass CxxPlogReaction "Cantera::PlogReaction" (CxxReaction):
|
||||
CxxPlog rate
|
||||
|
|
@ -305,6 +307,8 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
|
|||
size_t nPressure()
|
||||
size_t nTemperature()
|
||||
vector[double]& coeffs()
|
||||
void update_C(double*)
|
||||
double updateRC(double, double)
|
||||
|
||||
cdef cppclass CxxChebyshevReaction "Cantera::ChebyshevReaction" (CxxReaction):
|
||||
CxxChebyshevRate rate
|
||||
|
|
|
|||
|
|
@ -279,6 +279,11 @@ cdef class Arrhenius:
|
|||
self.pre_exponential_factor, self.temperature_exponent,
|
||||
self.activation_energy)
|
||||
|
||||
def __call__(self, float T):
|
||||
cdef double logT = np.log(T)
|
||||
cdef double recipT = 1/T
|
||||
return self.rate.updateRC(logT, recipT)
|
||||
|
||||
|
||||
cdef wrapArrhenius(CxxArrhenius* rate, Reaction reaction):
|
||||
r = Arrhenius(init=False)
|
||||
|
|
@ -564,6 +569,15 @@ cdef class PlogReaction(Reaction):
|
|||
cdef CxxPlogReaction* r = <CxxPlogReaction*>self.reaction
|
||||
r.rate = CxxPlog(ratemap)
|
||||
|
||||
def __call__(self, float T, float P):
|
||||
cdef CxxPlogReaction* r = <CxxPlogReaction*>self.reaction
|
||||
cdef double logT = np.log(T)
|
||||
cdef double recipT = 1/T
|
||||
cdef double logP = np.log(P)
|
||||
|
||||
r.rate.update_C(&logP)
|
||||
return r.rate.updateRC(logT, recipT)
|
||||
|
||||
|
||||
cdef class ChebyshevReaction(Reaction):
|
||||
"""
|
||||
|
|
@ -635,6 +649,15 @@ cdef class ChebyshevReaction(Reaction):
|
|||
|
||||
r.rate = CxxChebyshevRate(Tmin, Tmax, Pmin, Pmax, data)
|
||||
|
||||
def __call__(self, float T, float P):
|
||||
cdef CxxChebyshevReaction* r = <CxxChebyshevReaction*>self.reaction
|
||||
cdef double logT = np.log(T)
|
||||
cdef double recipT = 1/T
|
||||
cdef double logP = np.log10(P)
|
||||
|
||||
r.rate.update_C(&logP)
|
||||
return r.rate.updateRC(logT, recipT)
|
||||
|
||||
|
||||
cdef class InterfaceReaction(ElementaryReaction):
|
||||
""" A reaction occurring on an `Interface` (i.e. a surface or an edge) """
|
||||
|
|
|
|||
|
|
@ -657,6 +657,10 @@ class TestReaction(utilities.CanteraTest):
|
|||
self.assertNear(gas2.net_rates_of_progress[0],
|
||||
self.gas.net_rates_of_progress[2])
|
||||
|
||||
def test_arrhenius_rate(self):
|
||||
R = self.gas.reaction(2)
|
||||
self.assertNear(R.rate(self.gas.T), self.gas.forward_rate_constants[2])
|
||||
|
||||
def test_negative_A(self):
|
||||
species = ct.Species.listFromFile('gri30.cti')
|
||||
r = ct.ElementaryReaction('NH:1, NO:1', 'N2O:1, H:1')
|
||||
|
|
@ -731,6 +735,13 @@ class TestReaction(utilities.CanteraTest):
|
|||
self.assertNear(gas2.net_rates_of_progress[0],
|
||||
gas1.net_rates_of_progress[0])
|
||||
|
||||
def test_plog_rate(self):
|
||||
gas1 = ct.Solution('pdep-test.cti')
|
||||
gas1.TP = 800, 2*ct.one_atm
|
||||
for i in range(4):
|
||||
self.assertNear(gas1.reaction(i)(gas1.T, gas1.P),
|
||||
gas1.forward_rate_constants[i])
|
||||
|
||||
def test_chebyshev(self):
|
||||
gas1 = ct.Solution('pdep-test.cti')
|
||||
species = ct.Species.listFromFile('pdep-test.cti')
|
||||
|
|
@ -756,6 +767,13 @@ class TestReaction(utilities.CanteraTest):
|
|||
self.assertNear(gas2.net_rates_of_progress[0],
|
||||
gas1.net_rates_of_progress[4])
|
||||
|
||||
def test_chebyshev_rate(self):
|
||||
gas1 = ct.Solution('pdep-test.cti')
|
||||
gas1.TP = 800, 2*ct.one_atm
|
||||
for i in range(4,6):
|
||||
self.assertNear(gas1.reaction(i)(gas1.T, gas1.P),
|
||||
gas1.forward_rate_constants[i])
|
||||
|
||||
def test_interface(self):
|
||||
surf_species = ct.Species.listFromFile('ptcombust.xml')
|
||||
gas = ct.Solution('ptcombust.xml', 'gas')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue