Skip to content

Commit 2558add

Browse files
committed
Tests: Reaction tests modifications
1 parent 996df3d commit 2558add

1 file changed

Lines changed: 31 additions & 8 deletions

File tree

test/rmgpy/reactionTest.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import cantera as ct
3737
import numpy
38-
import yaml
3938
from copy import deepcopy
4039

4140
import pytest
@@ -2948,34 +2947,58 @@ def test_pdep_arrhenius(self):
29482947
ct_objects = [self.ct_pdepArrhenius]
29492948
converted_ct_objects = [obj.to_cantera(self.species_list, use_chemkin_identifier=True) for obj in rmg_objects]
29502949

2950+
def assert_plog_rates_equal(rates1, rates2, rtol=1e-9, atol=0.0):
2951+
assert len(rates1) == len(rates2)
2952+
# Sort by pressure to avoid ordering differences (Plog stores a multimap internally)
2953+
rates1 = sorted(rates1, key=lambda x: x[0])
2954+
rates2 = sorted(rates2, key=lambda x: x[0])
2955+
for (p1, r1), (p2, r2) in zip(rates1, rates2):
2956+
assert math.isclose(float(p1), float(p2), rel_tol=rtol, abs_tol=atol)
2957+
A1, b1, Ea1 = r1.pre_exponential_factor, r1.temperature_exponent, r1.activation_energy
2958+
A2, b2, Ea2 = r2.pre_exponential_factor, r2.temperature_exponent, r2.activation_energy
2959+
assert math.isclose(A1, A2, rel_tol=rtol, abs_tol=atol)
2960+
assert math.isclose(b1, b2, rel_tol=rtol, abs_tol=atol)
2961+
assert math.isclose(Ea1, Ea2, rel_tol=rtol, abs_tol=atol)
2962+
29512963
for converted_obj, ct_obj in zip(converted_ct_objects, ct_objects):
29522964
# Check that the reaction class is the same
29532965
assert type(converted_obj) == type(ct_obj)
29542966
# Check that the reaction string is the same
29552967
assert repr(converted_obj) == repr(ct_obj)
29562968
# Check that the Arrhenius rates are identical
2957-
assert str(converted_obj.rates) == str(ct_obj.rates)
2969+
assert_plog_rates_equal(converted_obj.rate.rates, ct_obj.rate.rates)
29582970

29592971
def test_multi_pdep_arrhenius(self):
29602972
"""
29612973
Tests formation of cantera reactions with MultiPDepArrhenius kinetics.
29622974
"""
2963-
29642975
rmg_objects = [self.multiPdepArrhenius]
29652976
ct_objects = [self.ct_multiPdepArrhenius]
29662977
converted_ct_objects = [obj.to_cantera(self.species_list, use_chemkin_identifier=True) for obj in rmg_objects]
29672978

2979+
def assert_plog_rates_equal(rates1, rates2, rtol=1e-9, atol=0.0):
2980+
assert len(rates1) == len(rates2)
2981+
# Sort by pressure to avoid ordering differences (Plog stores a multimap internally)
2982+
rates1 = sorted(rates1, key=lambda x: x[0])
2983+
rates2 = sorted(rates2, key=lambda x: x[0])
2984+
for (p1, r1), (p2, r2) in zip(rates1, rates2):
2985+
assert math.isclose(float(p1), float(p2), rel_tol=rtol, abs_tol=atol)
2986+
A1, b1, Ea1 = r1.pre_exponential_factor, r1.temperature_exponent, r1.activation_energy
2987+
A2, b2, Ea2 = r2.pre_exponential_factor, r2.temperature_exponent, r2.activation_energy
2988+
assert math.isclose(A1, A2, rel_tol=rtol, abs_tol=atol)
2989+
assert math.isclose(b1, b2, rel_tol=rtol, abs_tol=atol)
2990+
assert math.isclose(Ea1, Ea2, rel_tol=rtol, abs_tol=atol)
2991+
29682992
for converted_obj, ct_obj in zip(converted_ct_objects, ct_objects):
29692993
# Check that the same number of reactions are produced
29702994
assert len(converted_obj) == len(ct_obj)
2971-
29722995
for converted_rxn, ct_rxn in zip(converted_obj, ct_obj):
29732996
# Check that the reaction has the same type
29742997
assert type(converted_rxn) == type(ct_rxn)
29752998
# Check that the reaction string is the same
29762999
assert repr(converted_rxn) == repr(ct_rxn)
29773000
# Check that the Arrhenius rates are identical
2978-
assert str(converted_rxn.rates) == str(ct_rxn.rates)
3001+
assert_plog_rates_equal(converted_rxn.rate.rates, ct_rxn.rate.rates)
29793002

29803003
def test_chebyshev(self):
29813004
"""
@@ -2996,18 +3019,18 @@ def test_falloff(self):
29963019
assert round(abs(ct_troe.rate.low_rate.pre_exponential_factor - self.ct_troe.rate.low_rate.pre_exponential_factor), 3) == 0
29973020
assert ct_troe.rate.low_rate.temperature_exponent == self.ct_troe.rate.low_rate.temperature_exponent
29983021
assert ct_troe.rate.low_rate.activation_energy == self.ct_troe.rate.low_rate.activation_energy
2999-
assert ct_troe.efficiencies == self.ct_troe.efficiencies
3022+
assert ct_troe.third_body.efficiencies == self.ct_troe.third_body.efficiencies
30003023

30013024
ct_third_body = self.thirdBody.to_cantera(self.species_list, use_chemkin_identifier=True)
30023025
assert type(ct_third_body.rate) == type(self.ct_thirdBody.rate)
30033026
assert round(abs(ct_third_body.rate.pre_exponential_factor - self.ct_thirdBody.rate.pre_exponential_factor), 3) == 0
30043027
assert ct_third_body.rate.temperature_exponent == self.ct_thirdBody.rate.temperature_exponent
30053028
assert ct_third_body.rate.activation_energy == self.ct_thirdBody.rate.activation_energy
3006-
assert ct_third_body.efficiencies == self.ct_thirdBody.efficiencies
3029+
assert ct_third_body.third_body.efficiencies == self.ct_thirdBody.third_body.efficiencies
30073030

30083031
ct_lindemann = self.lindemann.to_cantera(self.species_list, use_chemkin_identifier=True)
30093032
assert type(ct_lindemann.rate) == type(self.ct_lindemann.rate)
3010-
assert ct_lindemann.efficiencies == self.ct_lindemann.efficiencies
3033+
assert ct_lindemann.third_body.efficiencies == self.ct_lindemann.third_body.efficiencies
30113034
assert str(ct_lindemann.rate.low_rate) == str(self.ct_lindemann.rate.low_rate)
30123035
assert str(ct_lindemann.rate.high_rate) == str(self.ct_lindemann.rate.high_rate)
30133036

0 commit comments

Comments
 (0)