Skip to content

Commit

Permalink
cantera 3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonBurns committed Jan 25, 2025
1 parent 6d03db1 commit 558e48e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 deletions.
5 changes: 2 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
name: rmg_env
channels:
- conda-forge
- cantera
- rmg
dependencies:
# System-level dependencies - we could install these at the OS level
Expand All @@ -46,7 +45,7 @@ dependencies:

# external software tools for chemistry
- conda-forge::coolprop
- cantera::cantera =2.6
- conda-forge::cantera >= 3
- conda-forge::mopac
# see https://github.com/ReactionMechanismGenerator/RMG-Py/pull/2639#issuecomment-2050292972
- conda-forge::cclib >=1.6.3,<1.9
Expand All @@ -59,7 +58,7 @@ dependencies:
- conda-forge::cython >=0.25.2
- conda-forge::scikit-learn
- conda-forge::scipy >=1.9
- conda-forge::numpy >=1.10.0
- conda-forge::numpy >=1.10.0,<2
- conda-forge::pydot
- conda-forge::jinja2
- conda-forge::jupyter
Expand Down
16 changes: 8 additions & 8 deletions rmgpy/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,35 +348,35 @@ def to_cantera(self, species_list=None, use_chemkin_identifier=False):

elif isinstance(self.kinetics, ThirdBody):
if ct_collider is not None:
ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider)
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products, third_body=ct_collider)
else:
ct_reaction = ct.ThreeBodyReaction(reactants=ct_reactants, products=ct_products)
ct_reaction = ct.Reaction(reactants=ct_reactants, products=ct_products)

elif isinstance(self.kinetics, Troe):
if ct_collider is not None:
ct_reaction = ct.FalloffReaction(
ct_reaction = ct.Reaction(
reactants=ct_reactants,
products=ct_products,
tbody=ct_collider,
third_body=ct_collider,
rate=ct.TroeRate()
)
else:
ct_reaction = ct.FalloffReaction(
ct_reaction = ct.Reaction(
reactants=ct_reactants,
products=ct_products,
rate=ct.TroeRate()
)

elif isinstance(self.kinetics, Lindemann):
if ct_collider is not None:
ct_reaction = ct.FalloffReaction(
ct_reaction = ct.Reaction(
reactants=ct_reactants,
products=ct_products,
tbody=ct_collider,
third_body=ct_collider,
rate=ct.LindemannRate()
)
else:
ct_reaction = ct.FalloffReaction(
ct_reaction = ct.Reaction(
reactants=ct_reactants,
products=ct_products,
rate=ct.LindemannRate()
Expand Down
23 changes: 9 additions & 14 deletions rmgpy/tools/canteramodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,20 +840,15 @@ def check_equivalent_falloff(fall1, fall2):
for j in range(ct_rxn1.rate.data.shape[1]):
assert check_nearly_equal(ct_rxn1.rate.data[i, j], ct_rxn2.rate.data[i, j], dE), \
"Similar Chebyshev coefficients"

elif isinstance(ct_rxn1, ct.ThreeBodyReaction):
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"

elif isinstance(ct_rxn1, ct.FalloffReaction):
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"
if ct_rxn1.falloff or ct_rxn2.falloff:
check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff)
if ct_rxn1.high_rate or ct_rxn2.high_rate:
check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate)
if ct_rxn1.low_rate or ct_rxn2.low_rate:
check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate)
else:
assert ct_rxn1.default_efficiency == ct_rxn2.default_efficiency, "Same default efficiency"
assert ct_rxn1.efficiencies == ct_rxn2.efficiencies, "Same efficiencies"
if ct_rxn1.falloff or ct_rxn2.falloff:
check_equivalent_falloff(ct_rxn1.falloff, ct_rxn2.falloff)
if ct_rxn1.high_rate or ct_rxn2.high_rate:
check_equivalent_arrhenius(ct_rxn1.high_rate, ct_rxn2.high_rate)
if ct_rxn1.low_rate or ct_rxn2.low_rate:
check_equivalent_arrhenius(ct_rxn1.low_rate, ct_rxn2.low_rate)

except Exception as e:
print("Cantera reaction {0} failed equivalency check on: {1}".format(ct_rxn1, e))
Expand Down
4 changes: 2 additions & 2 deletions test/rmgpy/reactionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ def test_pdep_arrhenius(self):
# Check that the reaction string is the same
assert repr(converted_obj) == repr(ct_obj)
# Check that the Arrhenius rates are identical
assert str(converted_obj.rates) == str(ct_obj.rates)
assert converted_obj.rate.rates == ct_obj.rate.rates

def test_multi_pdep_arrhenius(self):
"""
Expand All @@ -2975,7 +2975,7 @@ def test_multi_pdep_arrhenius(self):
# Check that the reaction string is the same
assert repr(converted_rxn) == repr(ct_rxn)
# Check that the Arrhenius rates are identical
assert str(converted_rxn.rates) == str(ct_rxn.rates)
assert converted_rxn.rate.rates == ct_rxn.rate.rates

def test_chebyshev(self):
"""
Expand Down
36 changes: 18 additions & 18 deletions test/rmgpy/speciesTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,24 +458,24 @@ def test_cantera(self):

rmg_ct_species = rmg_species.to_cantera(use_chemkin_identifier=True)

ct_species = ct.Species.fromCti(
"""species(name=u'Ar',
atoms='Ar:1',
thermo=(NASA([200.00, 1000.00],
[ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00,
0.00000000E+00, 0.00000000E+00, -7.45375000E+02,
4.37967000E+00]),
NASA([1000.00, 6000.00],
[ 2.50000000E+00, 0.00000000E+00, 0.00000000E+00,
0.00000000E+00, 0.00000000E+00, -7.45375000E+02,
4.37967000E+00])),
transport=gas_transport(geom='atom',
diam=3.33,
well_depth=136.501,
dipole=2.0,
polar=1.0,
rot_relax=15.0))"""
)
ct_species = ct.Species.from_yaml("""
name: Ar
composition: {Ar: 1}
thermo:
model: NASA7
temperature-ranges: [200.0, 1000.0, 6000.0]
data:
- [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967]
- [2.5, 0.0, 0.0, 0.0, 0.0, -745.375, 4.37967]
transport:
model: gas
geometry: atom
diameter: 3.33
well-depth: 136.501
dipole: 2.0
polarizability: 1.0
rotational-relaxation: 15.0
""")
assert type(rmg_ct_species) == type(ct_species)
assert rmg_ct_species.name == ct_species.name
assert rmg_ct_species.composition == ct_species.composition
Expand Down
24 changes: 14 additions & 10 deletions test/rmgpy/transportDataTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,20 @@ def test_to_cantera(self):
rmg_ct_transport = transport.to_cantera()
import cantera as ct

ct_species = ct.Species.fromCti(
"""species(name=u'Ar',
atoms='Ar:1',
transport=gas_transport(geom='atom',
diam=3.33,
well_depth=136.501,
dipole=2.0,
polar=1.0,
rot_relax=15.0))"""
)
ct_species = ct.Species.from_yaml("""
name: Ar
composition: {Ar: 1}
thermo:
model: constant-cp
transport:
model: gas
geometry: atom
diameter: 3.33
well-depth: 136.501
dipole: 2.0
polarizability: 1.0
rotational-relaxation: 15.0
""")

ct_transport = ct_species.transport

Expand Down

0 comments on commit 558e48e

Please sign in to comment.