Skip to content

Commit 1a47f0e

Browse files
committed
[UnitTests] Update tests (WIP)
1 parent 5e97b9b commit 1a47f0e

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

interfaces/cython/cantera/test/test_jacobian.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class TestThreeBody(HydrogenOxygen, utilities.CanteraTest):
395395
# Three body reaction with default efficiency
396396
rxn_idx = 1
397397
equation = "H + O + M <=> OH + M"
398-
rate_type = "Arrhenius"
398+
rate_type = "three-body-Arrhenius"
399399

400400
@classmethod
401401
def setUpClass(cls):
@@ -463,7 +463,7 @@ class TestThreeBodyNoDefault(EdgeCases, utilities.CanteraTest):
463463
# Three body reaction without default efficiency
464464
rxn_idx = 4
465465
equation = "H + O + M <=> OH + M"
466-
rate_type = "Arrhenius"
466+
rate_type = "three-body-Arrhenius"
467467

468468
@classmethod
469469
def setUpClass(cls):

interfaces/cython/cantera/test/test_reaction.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test_implicit_three_body(self):
2424
rate-constant: {A: 2.08e+19, b: -1.24, Ea: 0.0}
2525
"""
2626
rxn1 = ct.Reaction.from_yaml(yaml1, self.gas)
27-
self.assertEqual(rxn1.reaction_type, "three-body")
28-
self.assertEqual(rxn1.default_efficiency, 0.)
29-
self.assertEqual(rxn1.efficiencies, {"O2": 1})
27+
assert rxn1.rate.type == "three-body-Arrhenius"
28+
assert rxn1.rate.default_efficiency == 0.
29+
assert rxn1.rate.efficiencies == {"O2": 1}
3030

3131
yaml2 = """
3232
equation: H + O2 + M <=> HO2 + M
@@ -36,8 +36,9 @@ def test_implicit_three_body(self):
3636
efficiencies: {O2: 1.0}
3737
"""
3838
rxn2 = ct.Reaction.from_yaml(yaml2, self.gas)
39-
self.assertEqual(rxn1.efficiencies, rxn2.efficiencies)
40-
self.assertEqual(rxn1.default_efficiency, rxn2.default_efficiency)
39+
assert rxn2.rate.type == "three-body-Arrhenius"
40+
assert rxn1.rate.efficiencies == rxn2.rate.efficiencies
41+
assert rxn1.rate.default_efficiency == rxn2.rate.default_efficiency
4142

4243
def test_duplicate(self):
4344
# @todo simplify this test
@@ -46,25 +47,27 @@ def test_duplicate(self):
4647
species=self.gas.species(), reactions=[])
4748

4849
yaml1 = """
49-
equation: H + O2 + H2O <=> HO2 + H2O
50+
equation: H + O2 + M <=> HO2 + M
5051
rate-constant: {A: 1.126e+19, b: -0.76, Ea: 0.0}
52+
type: three-body
53+
default-efficiency: 0
54+
efficiencies: {H2O: 1}
5155
"""
5256
rxn1 = ct.Reaction.from_yaml(yaml1, gas1)
57+
print(rxn1.reaction_type, rxn1.rate.type)
58+
assert rxn1.rate.type == "three-body-Arrhenius"
5359

5460
yaml2 = """
55-
equation: H + O2 + M <=> HO2 + M
61+
equation: H + O2 + H2O <=> HO2 + H2O
5662
rate-constant: {A: 1.126e+19, b: -0.76, Ea: 0.0}
57-
type: three-body
58-
default-efficiency: 0
59-
efficiencies: {H2O: 1}
6063
"""
6164
rxn2 = ct.Reaction.from_yaml(yaml2, gas1)
65+
assert rxn2.rate.type == "three-body-Arrhenius"
6266

63-
self.assertEqual(rxn1.reaction_type, rxn2.reaction_type)
6467
self.assertEqual(rxn1.reactants, rxn2.reactants)
6568
self.assertEqual(rxn1.products, rxn2.products)
66-
self.assertEqual(rxn1.efficiencies, rxn2.efficiencies)
67-
self.assertEqual(rxn1.default_efficiency, rxn2.default_efficiency)
69+
assert rxn1.rate.efficiencies == rxn2.rate.efficiencies
70+
assert rxn1.rate.default_efficiency == rxn2.rate.default_efficiency
6871

6972
gas1.add_reaction(rxn1)
7073
gas1.add_reaction(rxn2)
@@ -1290,11 +1293,12 @@ class TestThreeBody(TestThreeBody2):
12901293
# test updated version of three-body reaction
12911294

12921295
_legacy = False
1293-
_rxn_type = "three-body"
1294-
_rate_type = "Arrhenius"
1296+
_rxn_type = "reaction"
1297+
_rate_type = "three-body-Arrhenius"
1298+
_rate_cls = ct.ThreeBodyArrheniusRate
12951299
_yaml = """
12961300
equation: 2 O + M <=> O2 + M
1297-
type: three-body
1301+
type: three-body-Arrhenius
12981302
rate-constant: {A: 1.2e+11, b: -1.0, Ea: 0.0 cal/mol}
12991303
efficiencies: {H2: 2.4, H2O: 15.4, AR: 0.83}
13001304
"""

test/kinetics/kineticsFromYaml.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ TEST(Reaction, ThreeBodyFromYaml3)
7979

8080
auto R = newReaction(rxn, *(sol->kinetics()));
8181
EXPECT_EQ(R->reactants.count("M"), (size_t) 0);
82-
EXPECT_EQ(R->type(), "three-body");
83-
EXPECT_DOUBLE_EQ(R->thirdBody()->efficiencies["H2O"], 5.0);
84-
EXPECT_DOUBLE_EQ(R->thirdBody()->default_efficiency, 1.0);
85-
86-
const auto& rate = std::dynamic_pointer_cast<ArrheniusRate>(R->rate());
82+
EXPECT_EQ(R->type(), "reaction");
83+
const auto& rate = std::dynamic_pointer_cast<ThreeBodyArrheniusRate>(R->rate());
84+
AnyMap efficiencies;
85+
rate->getEfficiencies(efficiencies);
86+
EXPECT_DOUBLE_EQ(efficiencies["H2O"].asDouble(), 5.0);
87+
EXPECT_DOUBLE_EQ(rate->defaultEfficiency(), 1.0);
8788
EXPECT_DOUBLE_EQ(rate->preExponentialFactor(), 1.2e11);
8889
}
8990

@@ -539,7 +540,7 @@ TEST_F(ReactionToYaml, threeBody)
539540
soln = newSolution("h2o2.yaml", "", "None");
540541
soln->thermo()->setState_TPY(1000, 2e5, "H2:1.0, O2:0.5, O:1e-8, OH:3e-8, H:2e-7");
541542
duplicateReaction(1);
542-
EXPECT_TRUE(std::dynamic_pointer_cast<ThreeBodyReaction3>(duplicate));
543+
EXPECT_TRUE(std::dynamic_pointer_cast<ThreeBodyArrheniusRate>(duplicate->rate()));
543544
compareReactions();
544545
}
545546

0 commit comments

Comments
 (0)