Skip to content

Commit

Permalink
Fix YAML interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 9, 2022
1 parent cdd15ca commit d618e63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
28 changes: 18 additions & 10 deletions interfaces/cython/cantera/reaction.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,16 @@ cdef class TwoTempPlasmaRate(ReactionRate):
.. math::
k_f = A T_e^b \exp{-\tfrac{E_a}{RT}} \exp{-\tfrac{E_{a,e}}{RT_e}}
k_f = A T_e^b \exp{-\tfrac{E_{a,g}}{RT}} \exp{-\tfrac{E_{a,e}}{RT_e}}
where ``A`` is the `pre_exponential_factor`, ``b`` is the `temperature_exponent`,
``E_a`` is the `activation_energy`, and ``E_{a,e}`` is the `activation_electron_energy`.
where :math:`A` is the `pre_exponential_factor`, :math:`b` is the
`temperature_exponent`, :math:`E_{a,g}` is the `activation_energy`, and
:math:`E_{a,e}` is the `activation_electron_energy`.
"""
_reaction_rate_type = "two-temperature-plasma"

def __cinit__(self, A=None, b=None, Ea_gas=None, Ea_electron=None, input_data=None, init=True):
def __cinit__(self, A=None, b=None, Ea_gas=None, Ea_electron=None,
input_data=None, init=True):
if init:
if isinstance(input_data, dict):
self._rate.reset(new CxxTwoTempPlasmaRate(dict_to_anymap(input_data)))
Expand All @@ -292,7 +294,8 @@ cdef class TwoTempPlasmaRate(ReactionRate):
elif input_data:
raise TypeError("Invalid parameter 'input_data'")
else:
raise TypeError("Invalid parameters 'A', 'b', 'Ea-gas' or 'Ea-electron'")
raise TypeError(
"Invalid parameters 'A', 'b', 'Ea_gas' or 'Ea_electron'")
self.set_cxx_object()

def __call__(self, double temperature, double elec_temp):
Expand Down Expand Up @@ -321,14 +324,14 @@ cdef class TwoTempPlasmaRate(ReactionRate):

property activation_energy:
"""
The activation energy ``E_a`` [J/kmol].
The activation energy :math:`E_{a,g}` [J/kmol].
"""
def __get__(self):
return self.cxx_object().activationEnergy()

property activation_electron_energy:
"""
The activation electron energy ``E_{a,e}`` [J/kmol].
The activation electron energy :math:`E_{a,e}` [J/kmol].
"""
def __get__(self):
return self.cxx_object().activationElectronEnergy()
Expand Down Expand Up @@ -2278,11 +2281,14 @@ cdef class BlowersMaselReaction(Reaction):
reaction rate.
An example for the definition of an `BlowersMaselReaction` object is given as::
rxn = BlowersMaselReaction(
equation="O + H2 <=> H + OH",
rate={"A": 38.7, "b": 2.7, "Ea0": 1.0958665856e8, "w": 1.7505856e13},
kinetics=gas)
The YAML description corresponding to this reaction is::
equation: O + H2 <=> H + OH
type: Blowers-Masel
rate-constant: {A: 38700 cm^3/mol/s, b: 2.7, Ea0: 2.619184e4 cal/mol, w: 4.184e9 cal/mol}
Expand Down Expand Up @@ -2326,14 +2332,17 @@ cdef class TwoTempPlasmaReaction(Reaction):
A reaction which rate coefficient depends on both gas and electron temperature
An example for the definition of an `TwoTempPlasmaReaction` object is given as::
rxn = TwoTempPlasmaReaction(
equation="O2 + E <=> O2-",
rate={"A": 17283, "b": -3.1, "Ea": -5820088, "EE": 10808733},
rate={"A": 17283, "b": -3.1, "Ea-gas": -5820088, "Ea-electron": 10808733},
kinetics=gas)
The YAML description corresponding to this reaction is::
equation: O2 + E <=> O2-
type: two-temperature-plasma
rate-constant: {A: 17283, b: -3.1, Ea: -700 K, EE: 1300 K}
rate-constant: {A: 17283, b: -3.1, Ea-gas: -700 K, Ea-electron: 1300 K}
"""
_reaction_type = "two-temperature-plasma"

Expand All @@ -2359,7 +2368,6 @@ cdef class TwoTempPlasmaReaction(Reaction):
self.reaction = self._reaction.get()

if isinstance(rate, TwoTempPlasmaRate):
print("is TwoTempPlasmaRate")
self.rate = rate

property rate:
Expand Down
15 changes: 4 additions & 11 deletions interfaces/cython/cantera/test/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,7 @@ class TestTwoTempPlasmaRate(ReactionRateTests, utilities.CanteraTest):
@classmethod
def setUpClass(cls):
ReactionRateTests.setUpClass()
cls._parts = cls._input["rate-constant"]

def from_parts(self):
# create reaction rate object from parts
replaced_parts = {}
for key, value in self._parts.items():
replaced_parts[key.replace("-", "_")] = value
return self._cls(**replaced_parts)
cls._parts = {key.replace("-", "_"): value for key, value in cls._input["rate-constant"].items()}

def eval(self, rate):
# check evaluation as a function of temperature and electron temperature
Expand All @@ -318,8 +311,8 @@ def test_from_parts(self):
rate = self.from_parts()
self.assertEqual(self._parts["A"], rate.pre_exponential_factor)
self.assertEqual(self._parts["b"], rate.temperature_exponent)
self.assertAlmostEqual(self._parts["Ea-gas"], rate.activation_energy)
self.assertAlmostEqual(self._parts["Ea-electron"], rate.activation_electron_energy)
self.assertAlmostEqual(self._parts["Ea_gas"], rate.activation_energy)
self.assertAlmostEqual(self._parts["Ea_electron"], rate.activation_electron_energy)
self.check_rate(rate)

def test_negative_A(self):
Expand Down Expand Up @@ -937,7 +930,7 @@ class TestTwoTempPlasma(ReactionTests, utilities.CanteraTest):
_cls = ct.TwoTempPlasmaReaction
_type = "two-temperature-plasma"
_equation = "O + H <=> O + H"
_rate = {"A": 17283, "b": -3.1, "Ea-gas": -5820000, "Ea-electron": 1081000}
_rate = {"A": 17283, "b": -3.1, "Ea_gas": -5820000, "Ea_electron": 1081000}
_index = 11
_yaml = """
equation: O + H <=> O + H
Expand Down

0 comments on commit d618e63

Please sign in to comment.