mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Python] Add access to input data for Reaction objects
This commit is contained in:
committed by
Ingmar Schoegl
parent
148e3d9abf
commit
0f0a02056f
@@ -358,6 +358,8 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
|
||||
string equation()
|
||||
string type()
|
||||
void validate() except +translate_exception
|
||||
void getParameters(CxxAnyMap&) except +translate_exception
|
||||
int reaction_type
|
||||
Composition reactants
|
||||
Composition products
|
||||
Composition orders
|
||||
@@ -366,6 +368,7 @@ cdef extern from "cantera/kinetics/Reaction.h" namespace "Cantera":
|
||||
cbool duplicate
|
||||
cbool allow_nonreactant_orders
|
||||
cbool allow_negative_orders
|
||||
CxxAnyMap input
|
||||
|
||||
cdef cppclass CxxReaction2 "Cantera::Reaction2" (CxxReaction):
|
||||
CxxReaction2()
|
||||
|
||||
@@ -320,6 +320,17 @@ cdef class Reaction:
|
||||
def __set__(self, allow):
|
||||
self.reaction.allow_negative_orders = allow
|
||||
|
||||
property input_data:
|
||||
"""
|
||||
Get input data for this reaction with its current parameter values,
|
||||
along with any user-specified data provided with its input (YAML)
|
||||
definition.
|
||||
"""
|
||||
def __get__(self):
|
||||
cdef CxxAnyMap params
|
||||
self.reaction.getParameters(params)
|
||||
return mergeAnyMap(params, self.reaction.input)
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}: {}>'.format(self.__class__.__name__, self.equation)
|
||||
|
||||
|
||||
@@ -842,6 +842,24 @@ class TestReaction(utilities.CanteraTest):
|
||||
self.assertIn('HO2', R[2].products)
|
||||
self.assertEqual(R[0].rate.temperature_exponent, 2.7)
|
||||
|
||||
def test_input_data_from_file(self):
|
||||
R = self.gas.reaction(0)
|
||||
data = R.input_data
|
||||
self.assertEqual(data['type'], 'three-body')
|
||||
self.assertEqual(data['efficiencies'],
|
||||
{'H2': 2.4, 'H2O': 15.4, 'AR': 0.83})
|
||||
self.assertEqual(data['equation'], R.equation)
|
||||
|
||||
def test_input_data_from_scratch(self):
|
||||
r = ct.ElementaryReaction({'O':1, 'H2':1}, {'H':1, 'OH':1})
|
||||
r.rate = ct.Arrhenius(3.87e1, 2.7, 2.6e7)
|
||||
data = r.input_data
|
||||
self.assertEqual(data['rate-constant'],
|
||||
{'A': 3.87e1, 'b': 2.7, 'Ea': 2.6e7})
|
||||
terms = data['equation'].split()
|
||||
self.assertIn('O', terms)
|
||||
self.assertIn('OH', terms)
|
||||
|
||||
def test_elementary(self):
|
||||
r = ct.ElementaryReaction({'O':1, 'H2':1}, {'H':1, 'OH':1})
|
||||
r.rate = ct.Arrhenius(3.87e1, 2.7, 6260*1000*4.184)
|
||||
|
||||
Reference in New Issue
Block a user