From d618e634f8541e23fc83da3fca9c9e2234d21ba4 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 8 Jan 2022 09:15:10 -0600 Subject: [PATCH] Fix YAML interface --- interfaces/cython/cantera/reaction.pyx | 28 ++++++++++++------- .../cython/cantera/test/test_reaction.py | 15 +++------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/interfaces/cython/cantera/reaction.pyx b/interfaces/cython/cantera/reaction.pyx index 0d9a153ee3d..435b000129e 100644 --- a/interfaces/cython/cantera/reaction.pyx +++ b/interfaces/cython/cantera/reaction.pyx @@ -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))) @@ -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): @@ -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() @@ -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} @@ -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" @@ -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: diff --git a/interfaces/cython/cantera/test/test_reaction.py b/interfaces/cython/cantera/test/test_reaction.py index b12372af359..a0208a68429 100644 --- a/interfaces/cython/cantera/test/test_reaction.py +++ b/interfaces/cython/cantera/test/test_reaction.py @@ -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 @@ -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): @@ -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