Skip to content

Commit 33bd6f2

Browse files
committed
cantera 3 updates
1 parent ace1123 commit 33bd6f2

File tree

7 files changed

+62
-63
lines changed

7 files changed

+62
-63
lines changed

environment.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
name: rmg_env
2626
channels:
2727
- conda-forge
28-
- cantera
2928
- rmg
3029
dependencies:
3130
# System-level dependencies - we could install these at the OS level
@@ -46,7 +45,7 @@ dependencies:
4645

4746
# external software tools for chemistry
4847
- conda-forge::coolprop
49-
- cantera::cantera =2.6
48+
- conda-forge::cantera >= 3
5049
- conda-forge::mopac
5150
# see https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2639#issuecomment-2050292972
5251
- conda-forge::cclib >=1.6.3,<1.9
@@ -59,7 +58,7 @@ dependencies:
5958
- conda-forge::cython >=0.25.2
6059
- conda-forge::scikit-learn
6160
- conda-forge::scipy >=1.9
62-
- conda-forge::numpy >=1.10.0
61+
- conda-forge::numpy >=1.10.0,<2
6362
- conda-forge::pydot
6463
- conda-forge::jinja2
6564
- conda-forge::jupyter

rmgpy/kinetics/falloff.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ cdef class ThirdBody(PDepKineticsModel):
122122

123123
def set_cantera_kinetics(self, ct_reaction, species_list):
124124
"""
125-
Sets the kinetics and efficiencies for a cantera `ThreeBodyReaction` object
125+
Sets the kinetics and efficiencies for a cantera Reaction representing a Three Body Rate
126126
"""
127127
import cantera as ct
128-
assert isinstance(ct_reaction, ct.ThreeBodyReaction), "Must be a Cantera ThreeBodyReaction object"
129-
ct_reaction.efficiencies = PDepKineticsModel.get_cantera_efficiencies(self, species_list)
128+
# assert ct_reaction.third_body is not None, "Cantera Reaction must have third_body attribute"
129+
ct_reaction.third_body.efficiencies = PDepKineticsModel.get_cantera_efficiencies(self, species_list)
130130
self.arrheniusLow.set_cantera_kinetics(ct_reaction, species_list)
131131

132132
################################################################################
@@ -398,7 +398,7 @@ cdef class Troe(PDepKineticsModel):
398398
"""
399399
import cantera as ct
400400
assert isinstance(ct_reaction.rate, ct.TroeRate), "Must have a Cantera TroeRate attribute"
401-
ct_reaction.efficiencies = PDepKineticsModel.get_cantera_efficiencies(self, species_list)
401+
ct_reaction.third_body.efficiencies = PDepKineticsModel.get_cantera_efficiencies(self, species_list)
402402
ct_reaction.rate = self.to_cantera_kinetics()
403403

404404
def to_cantera_kinetics(self):

rmgpy/reaction.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,36 +347,37 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):
347347
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, rate=ct.ChebyshevRate())
348348

349349
elif isinstance(self.kinetics, ThirdBody):
350+
# Cantera 3 doesn't have a ThirdBody class, only third body attribute in the normal class
350351
if ct_collider is not None:
351-
ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider)
352-
else:
353-
ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products)
352+
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider, rate=ct.ArrheniusRate())
353+
else: # provide the default collider (if we don't have one) to establish this as a ThirdBody reaction
354+
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, third_body=ct.ThirdBody(), rate=ct.ArrheniusRate())
354355

355356
elif isinstance(self.kinetics, Troe):
356357
if ct_collider is not None:
357-
ct_reaction = ct.FalloffReaction(
358+
ct_reaction = ct.Reaction(
358359
reactants=ct_reactants,
359360
products=ct_products,
360-
tbody=ct_collider,
361+
third_body=ct_collider,
361362
rate=ct.TroeRate()
362363
)
363364
else:
364-
ct_reaction = ct.FalloffReaction(
365+
ct_reaction = ct.Reaction(
365366
reactants=ct_reactants,
366367
products=ct_products,
367368
rate=ct.TroeRate()
368369
)
369370

370371
elif isinstance(self.kinetics, Lindemann):
371372
if ct_collider is not None:
372-
ct_reaction = ct.FalloffReaction(
373+
ct_reaction = ct.Reaction(
373374
reactants=ct_reactants,
374375
products=ct_products,
375-
tbody=ct_collider,
376+
third_body=ct_collider,
376377
rate=ct.LindemannRate()
377378
)
378379
else:
379-
ct_reaction = ct.FalloffReaction(
380+
ct_reaction = ct.Reaction(
380381
reactants=ct_reactants,
381382
products=ct_products,
382383
rate=ct.LindemannRate()

rmgpy/tools/canteramodel.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -840,20 +840,15 @@ def check_equivalent_falloff(fall1, fall2):
840840
for j in range(ct_rxn1.rate.data.shape[1]):
841841
assert check_nearly_equal(ct_rxn1.rate.data[i, j], ct_rxn2.rate.data[i, j], dE), \
842842
"Similar Chebyshev coefficients"
843-
844-
elif isinstance(ct_rxn1, ct.ThreeBodyReaction):
845-
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
846-
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"
847-
848-
elif isinstance(ct_rxn1, ct.FalloffReaction):
849-
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
850-
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"
851-
if ct_rxn1.falloff or ct_rxn2.falloff:
852-
check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff)
853-
if ct_rxn1.high_rate or ct_rxn2.high_rate:
854-
check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate)
855-
if ct_rxn1.low_rate or ct_rxn2.low_rate:
856-
check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate)
843+
else:
844+
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
845+
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"
846+
if ct_rxn1.falloff or ct_rxn2.falloff:
847+
check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff)
848+
if ct_rxn1.high_rate or ct_rxn2.high_rate:
849+
check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate)
850+
if ct_rxn1.low_rate or ct_rxn2.low_rate:
851+
check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate)
857852

858853
except Exception as e:
859854
print("Cantera reaction {0} failed equivalency check on: {1}".format(ct_rxn1, e))

test/rmgpy/reactionTest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,7 @@ def test_pdep_arrhenius(self):
29542954
# Check that the reaction string is the same
29552955
assert repr(converted_obj) == repr(ct_obj)
29562956
# Check that the Arrhenius rates are identical
2957-
assert str(converted_obj.rates) == str(ct_obj.rates)
2957+
assert str(converted_obj.rate.rates) == str(ct_obj.rate.rates)
29582958

29592959
def test_multi_pdep_arrhenius(self):
29602960
"""
@@ -2975,7 +2975,7 @@ def test_multi_pdep_arrhenius(self):
29752975
# Check that the reaction string is the same
29762976
assert repr(converted_rxn) == repr(ct_rxn)
29772977
# Check that the Arrhenius rates are identical
2978-
assert str(converted_rxn.rates) == str(ct_rxn.rates)
2978+
assert str(converted_rxn.rate.rates) == str(ct_rxn.rate.rates)
29792979

29802980
def test_chebyshev(self):
29812981
"""
@@ -2996,18 +2996,18 @@ def test_falloff(self):
29962996
assert round(abs(ct_troe.rate.low_rate.pre_exponential_factor - self.ct_troe.rate.low_rate.pre_exponential_factor), 3) == 0
29972997
assert ct_troe.rate.low_rate.temperature_exponent == self.ct_troe.rate.low_rate.temperature_exponent
29982998
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
2999+
assert ct_troe.third_body.efficiencies == self.ct_troe.third_body.efficiencies
30003000

30013001
ct_third_body = self.thirdBody.to_cantera(self.species_list, use_chemkin_identifier=True)
30023002
assert type(ct_third_body.rate) == type(self.ct_thirdBody.rate)
30033003
assert round(abs(ct_third_body.rate.pre_exponential_factor - self.ct_thirdBody.rate.pre_exponential_factor), 3) == 0
30043004
assert ct_third_body.rate.temperature_exponent == self.ct_thirdBody.rate.temperature_exponent
30053005
assert ct_third_body.rate.activation_energy == self.ct_thirdBody.rate.activation_energy
3006-
assert ct_third_body.efficiencies == self.ct_thirdBody.efficiencies
3006+
assert ct_third_body.third_body.efficiencies == self.ct_thirdBody.third_body.efficiencies
30073007

30083008
ct_lindemann = self.lindemann.to_cantera(self.species_list, use_chemkin_identifier=True)
30093009
assert type(ct_lindemann.rate) == type(self.ct_lindemann.rate)
3010-
assert ct_lindemann.efficiencies == self.ct_lindemann.efficiencies
3010+
assert ct_lindemann.third_body.efficiencies == self.ct_lindemann.third_body.efficiencies
30113011
assert str(ct_lindemann.rate.low_rate) == str(self.ct_lindemann.rate.low_rate)
30123012
assert str(ct_lindemann.rate.high_rate) == str(self.ct_lindemann.rate.high_rate)
30133013

test/rmgpy/speciesTest.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -458,24 +458,24 @@ def test_cantera(self):
458458

459459
rmg_ct_species = rmg_species.to_cantera(use_chemkin_identifier=True)
460460

461-
ct_species = ct.Species.fromCti(
462-
"""species(name=u'Ar',
463-
atoms='Ar:1',
464-
thermo=(NASA([200.00, 1000.00],
465-
[ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00,
466-
0.00000000E+00, 0.00000000E+00, -7.45375000E+02,
467-
4.37967000E+00]),
468-
NASA([1000.00, 6000.00],
469-
[ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00,
470-
0.00000000E+00, 0.00000000E+00, -7.45375000E+02,
471-
4.37967000E+00])),
472-
transport=gas_transport(geom='atom',
473-
diam=3.33,
474-
well_depth=136.501,
475-
dipole=2.0,
476-
polar=1.0,
477-
rot_relax=15.0))"""
478-
)
461+
ct_species = ct.Species.from_yaml("""
462+
name: Ar
463+
composition: {Ar: 1}
464+
thermo:
465+
model: NASA7
466+
temperature-ranges: [200.0, 1000.0, 6000.0]
467+
data:
468+
- [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967]
469+
- [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967]
470+
transport:
471+
model: gas
472+
geometry: atom
473+
diameter: 3.33
474+
well-depth: 136.501
475+
dipole: 2.0
476+
polarizability: 1.0
477+
rotational-relaxation: 15.0
478+
""")
479479
assert type(rmg_ct_species) == type(ct_species)
480480
assert rmg_ct_species.name == ct_species.name
481481
assert rmg_ct_species.composition == ct_species.composition

test/rmgpy/transportDataTest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,20 @@ def test_to_cantera(self):
161161
rmg_ct_transport = transport.to_cantera()
162162
import cantera as ct
163163

164-
ct_species = ct.Species.fromCti(
165-
"""species(name=u'Ar',
166-
atoms='Ar:1',
167-
transport=gas_transport(geom='atom',
168-
diam=3.33,
169-
well_depth=136.501,
170-
dipole=2.0,
171-
polar=1.0,
172-
rot_relax=15.0))"""
173-
)
164+
ct_species = ct.Species.from_yaml("""
165+
name: Ar
166+
composition: {Ar: 1}
167+
thermo:
168+
model: constant-cp
169+
transport:
170+
model: gas
171+
geometry: atom
172+
diameter: 3.33
173+
well-depth: 136.501
174+
dipole: 2.0
175+
polarizability: 1.0
176+
rotational-relaxation: 15.0
177+
""")
174178

175179
ct_transport = ct_species.transport
176180

0 commit comments

Comments
 (0)