Skip to content

Commit 24205ac

Browse files
committed
Tests: Update canteramodel and transportData tests
1 parent 20799d4 commit 24205ac

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

test/rmgpy/tools/canteramodelTest.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
###############################################################################
2929

3030
import os
31-
32-
3331
import numpy as np
32+
import tempfile
3433

3534
import rmgpy
3635
from rmgpy.quantity import Quantity
@@ -42,7 +41,6 @@ def test_ignition_delay(self):
4241
"""
4342
Test that find_ignition_delay() works.
4443
"""
45-
4644
t = np.arange(0, 5, 0.5)
4745
P = np.array([0, 0.33, 0.5, 0.9, 2, 4, 15, 16, 16.1, 16.2])
4846
OH = np.array([0, 0.33, 0.5, 0.9, 2, 4, 15, 16, 7, 2])
@@ -82,7 +80,6 @@ class RMGToCanteraTest:
8280

8381
def setup_class(self):
8482
from rmgpy.chemkin import load_chemkin_file
85-
8683
folder = os.path.join(os.path.dirname(rmgpy.__file__), "tools/data/various_kinetics")
8784

8885
chemkin_path = os.path.join(folder, "chem_annotated.inp")
@@ -118,19 +115,32 @@ def setup_class(self):
118115
self.rmg_surface_ct_reactions.extend(converted_reactions)
119116
else:
120117
self.rmg_surface_ct_reactions.append(converted_reactions)
118+
119+
with open(chemkin_surface_path, 'r') as f:
120+
surface_content = f.read()
121+
if "SITE SDEN" in surface_content:
122+
# Inject a dummy phase name 'SURF'
123+
surface_content = surface_content.replace("SITE SDEN", "SITE SURF SDEN")
124+
125+
# Write to a temporary file to avoid modifying the repo's test data
126+
tf = tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.inp')
127+
tf.write(surface_content)
128+
tf.close()
129+
# Use the temp file for Cantera loading
130+
chemkin_surface_path = tf.name
131+
132+
121133
job = Cantera()
122134
job.surface = True
123-
job.load_chemkin_model(chemkin_path, surface_file=chemkin_surface_path, quiet=True)
135+
job.load_chemkin_model(chemkin_path, surface_file=chemkin_surface_path, quiet=True, permissive=True)
124136
self.ct_surface_species = job.surface.species()
125137
self.ct_surface_reactions = job.surface.reactions()
126138

127-
128139
def test_species_conversion(self):
129140
"""
130141
Test that species objects convert properly
131142
"""
132143
from rmgpy.tools.canteramodel import check_equivalent_cantera_species
133-
134144
for i in range(len(self.ctSpecies)):
135145
assert check_equivalent_cantera_species(self.ctSpecies[i], self.rmg_ctSpecies[i])
136146

@@ -139,7 +149,6 @@ def test_reaction_conversion(self):
139149
Test that reaction objects convert properly
140150
"""
141151
from rmgpy.tools.canteramodel import check_equivalent_cantera_reaction
142-
143152
for i in range(len(self.ctReactions)):
144153
assert check_equivalent_cantera_reaction(self.ctReactions[i], self.rmg_ctReactions[i])
145154

@@ -148,7 +157,6 @@ def test_surface_species_conversion(self):
148157
Test that surface species objects convert properly
149158
"""
150159
from rmgpy.tools.canteramodel import check_equivalent_cantera_species
151-
152160
for i in range(len(self.ct_surface_species)):
153161
#print("Chemkin-to-Cantera:", self.ct_surfaceSpecies[i].input_data)
154162
#print("Chemkin-to-RMG-to-Cantera:", self.rmg_surface_ctSpecies[i].input_data)
@@ -159,8 +167,7 @@ def test_surface_reaction_conversion(self):
159167
Test that surface reaction objects convert properly
160168
"""
161169
from rmgpy.tools.canteramodel import check_equivalent_cantera_reaction
162-
163170
for i in range(len(self.ct_surface_reactions)):
164171
#print("Chemkin-to-Cantera:", self.ct_surfaceReactions[i].input_data)
165172
#print("Chemkin-to-RMG-to-Cantera:", self.rmg_surface_ctReactions[i].input_data)
166-
assert check_equivalent_cantera_reaction(self.ct_surface_reactions[i], self.rmg_surface_ct_reactions[i])
173+
assert check_equivalent_cantera_reaction(self.ct_surface_reactions[i], self.rmg_surface_ct_reactions[i])

test/rmgpy/transportDataTest.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,19 @@ 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))"""
164+
ct_species = ct.Species.from_yaml(
165+
"""
166+
name: Ar
167+
composition: {Ar: 1}
168+
transport:
169+
model: gas
170+
geometry: atom
171+
diameter: 3.33
172+
well-depth: 136.501
173+
dipole: 2.0
174+
polarizability: 1.0
175+
rotational-relaxation: 15.0
176+
"""
173177
)
174178

175179
ct_transport = ct_species.transport

0 commit comments

Comments
 (0)