Skip to content

Commit da66acb

Browse files
committed
Add unit test for coverage dependent thermodynamics in RMG thermo classes
1 parent 4c98a7a commit da66acb

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

test/rmgpy/thermo/convertTest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def setup_class(self):
5757
S0=(-118.46 * constants.R, "J/(mol*K)"),
5858
Tmin=(10, "K"),
5959
Tmax=(3000, "K"),
60+
thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}},
6061
comment="C2H6",
6162
)
6263
self.nasa = NASA(
@@ -93,6 +94,7 @@ def setup_class(self):
9394
E0=(-93.6077, "kJ/mol"),
9495
Cp0=(4.0 * constants.R, "J/(mol*K)"),
9596
CpInf=(21.5 * constants.R, "J/(mol*K)"),
97+
thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}},
9698
comment="C2H6",
9799
)
98100
self.thermodata = ThermoData(
@@ -108,6 +110,7 @@ def setup_class(self):
108110
Tmin=(10, "K"),
109111
Tmax=(3000, "K"),
110112
E0=(-93.6077, "kJ/mol"),
113+
thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}},
111114
comment="C2H6",
112115
)
113116

@@ -129,6 +132,7 @@ def test_convert_wilhoit_to_nasa(self):
129132
s_nasa = nasa.get_entropy(T)
130133
assert abs(s_nasa - s_wilhoit) < 1e0
131134
assert abs(wilhoit.E0.value_si - nasa.E0.value_si) < 1e1
135+
assert repr(nasa.thermo_coverage_dependence) == repr(wilhoit.thermo_coverage_dependence)
132136

133137
def test_convert_wilhoit_to_thermo_data(self):
134138
"""
@@ -149,6 +153,7 @@ def test_convert_wilhoit_to_thermo_data(self):
149153
s_thermodata = thermodata.get_entropy(T)
150154
assert round(abs(s_thermodata - s_wilhoit), 4) == 0
151155
assert abs(wilhoit.E0.value_si - thermodata.E0.value_si) < 1e1
156+
assert repr(thermodata.thermo_coverage_dependence) == repr(wilhoit.thermo_coverage_dependence)
152157

153158
def test_convert_nasa_to_wilhoit(self):
154159
"""
@@ -168,6 +173,7 @@ def test_convert_nasa_to_wilhoit(self):
168173
s_nasa = nasa.get_entropy(T)
169174
assert abs(s_nasa - s_wilhoit) < 1e0
170175
assert abs(nasa.E0.value_si - wilhoit.E0.value_si) < 2e1
176+
assert repr(wilhoit.thermo_coverage_dependence) == repr(nasa.thermo_coverage_dependence)
171177

172178
def test_convert_nasa_to_thermo_data(self):
173179
"""
@@ -188,6 +194,7 @@ def test_convert_nasa_to_thermo_data(self):
188194
s_nasa = nasa.get_entropy(T)
189195
assert round(abs(s_nasa - s_thermodata), 4) == 0
190196
assert abs(nasa.E0.value_si - thermodata.E0.value_si) < 1e1
197+
assert repr(thermodata.thermo_coverage_dependence) == repr(nasa.thermo_coverage_dependence)
191198

192199
def test_convert_thermo_data_to_wilhoit(self):
193200
"""
@@ -208,6 +215,7 @@ def test_convert_thermo_data_to_wilhoit(self):
208215
s_thermodata = thermodata.get_entropy(T)
209216
assert round(abs(s_thermodata - s_wilhoit), 3) == 0
210217
assert abs(thermodata.E0.value_si - wilhoit.E0.value_si) < 1e1
218+
assert repr(wilhoit.thermo_coverage_dependence) == repr(thermodata.thermo_coverage_dependence)
211219

212220
def test_convert_thermo_data_to_nasa(self):
213221
"""
@@ -228,6 +236,7 @@ def test_convert_thermo_data_to_nasa(self):
228236
s_nasa = nasa.get_entropy(T)
229237
assert abs(s_nasa - s_thermodata) < 1e0
230238
assert abs(thermodata.E0.value_si - nasa.E0.value_si) < 1e1
239+
assert repr(nasa.thermo_coverage_dependence) == repr(thermodata.thermo_coverage_dependence)
231240

232241
def test_wilhoit_nasa_wilhoit(self):
233242
"""
@@ -248,6 +257,7 @@ def test_wilhoit_nasa_wilhoit(self):
248257
s_2 = wilhoit2.get_entropy(T)
249258
assert abs(s_1 - s_2) < 1e0
250259
assert abs(wilhoit1.E0.value_si - wilhoit2.E0.value_si) < 1e1
260+
assert repr(wilhoit1.thermo_coverage_dependence) == repr(wilhoit2.thermo_coverage_dependence)
251261

252262
def test_wilhoit_thermo_data_wilhoit(self):
253263
"""
@@ -268,3 +278,4 @@ def test_wilhoit_thermo_data_wilhoit(self):
268278
s_2 = wilhoit2.get_entropy(T)
269279
assert abs(s_1 - s_2) < 1e0
270280
assert abs(wilhoit1.E0.value_si - wilhoit2.E0.value_si) < 1e1
281+
assert repr(wilhoit1.thermo_coverage_dependence) == repr(wilhoit2.thermo_coverage_dependence)

test/rmgpy/thermo/nasaTest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import rmgpy.constants as constants
4040
from rmgpy.quantity import ScalarQuantity
4141
from rmgpy.thermo.nasa import NASA, NASAPolynomial
42+
from rmgpy.quantity import Dimensionless
4243

4344

4445
class TestNASA:
@@ -69,6 +70,7 @@ def setup_class(self):
6970
self.Tmax = 3000.0
7071
self.Tint = 650.73
7172
self.E0 = -782292.0 # J/mol.
73+
self.thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}}
7274
self.comment = "C2H6"
7375
self.nasa = NASA(
7476
polynomials=[
@@ -82,6 +84,7 @@ def setup_class(self):
8284
Tmin=(self.Tmin, "K"),
8385
Tmax=(self.Tmax, "K"),
8486
E0=(self.E0, "J/mol"),
87+
thermo_coverage_dependence=self.thermo_coverage_dependence,
8588
comment=self.comment,
8689
)
8790

@@ -136,6 +139,12 @@ def test_comment(self):
136139
Test that the NASA comment property was properly set.
137140
"""
138141
assert self.nasa.comment == self.comment
142+
143+
def test_thermo_coverage_dependence(self):
144+
"""
145+
Test that the thermo_coverage_dependence property was properly set.
146+
"""
147+
assert repr(self.nasa.thermo_coverage_dependence) == repr(self.thermo_coverage_dependence)
139148

140149
def test_is_temperature_valid(self):
141150
"""
@@ -263,6 +272,7 @@ def test_pickle(self):
263272
assert self.nasa.Tmax.units == nasa.Tmax.units
264273
assert self.nasa.E0.value == nasa.E0.value
265274
assert self.nasa.E0.units == nasa.E0.units
275+
assert repr(self.nasa.thermo_coverage_dependence) == repr(nasa.thermo_coverage_dependence)
266276
assert self.nasa.comment == nasa.comment
267277

268278
def test_repr(self):
@@ -296,6 +306,7 @@ def test_repr(self):
296306
assert self.nasa.Tmax.units == nasa.Tmax.units
297307
assert self.nasa.E0.value == nasa.E0.value
298308
assert self.nasa.E0.units == nasa.E0.units
309+
assert repr(self.nasa.thermo_coverage_dependence) == repr(nasa.thermo_coverage_dependence)
299310
assert self.nasa.comment == nasa.comment
300311

301312
def test_to_cantera(self):
@@ -326,6 +337,7 @@ def test_to_nasa(self):
326337

327338
spc = Species().from_smiles("CC")
328339
spc.get_thermo_data()
340+
spc.thermo.thermo_coverage_dependence = self.thermo_coverage_dependence
329341

330342
T = 1350.0 # not 298K!
331343

@@ -353,6 +365,7 @@ def test_to_nasa(self):
353365

354366
assert round(abs(s_nasa - s_td), -1) == 0
355367
assert wilhoit.comment == nasa.comment
368+
assert repr(wilhoit.thermo_coverage_dependence) == repr(nasa.thermo_coverage_dependence)
356369

357370
# nasa to wilhoi performed in wilhoitTest
358371

@@ -364,6 +377,7 @@ def test_nasa_as_dict_full(self):
364377
assert nasa_dict["E0"]["value"] == self.E0
365378
assert nasa_dict["Tmin"]["value"] == self.Tmin
366379
assert nasa_dict["Tmax"]["value"] == self.Tmax
380+
assert repr(nasa_dict["thermo_coverage_dependence"]) == "{'OX': {'model': 'polynomial', 'enthalpy-coefficients': [{'class': 'ScalarQuantity', 'value': 1.0}, {'class': 'ScalarQuantity', 'value': 2.0}, {'class': 'ScalarQuantity', 'value': 3.0}], 'entropy-coefficients': [{'class': 'ScalarQuantity', 'value': 1.0}, {'class': 'ScalarQuantity', 'value': 2.0}, {'class': 'ScalarQuantity', 'value': 3.0}]}}"
367381
assert nasa_dict["comment"] == self.comment
368382
assert tuple(nasa_dict["polynomials"]["polynomial1"]["coeffs"]["object"]) == tuple(self.coeffs_low)
369383
assert tuple(nasa_dict["polynomials"]["polynomial2"]["coeffs"]["object"]) == tuple(self.coeffs_high)

test/rmgpy/thermo/thermodataTest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def setup_class(self):
5353
self.Tmin = 100.0
5454
self.Tmax = 3000.0
5555
self.E0 = -782292.0
56+
self.thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}}
5657
self.comment = "C2H6"
5758
self.thermodata = ThermoData(
5859
Tdata=(self.Tdata, "K"),
@@ -64,6 +65,7 @@ def setup_class(self):
6465
Tmin=(self.Tmin, "K"),
6566
Tmax=(self.Tmax, "K"),
6667
E0=(self.E0, "J/mol"),
68+
thermo_coverage_dependence=self.thermo_coverage_dependence,
6769
comment=self.comment,
6870
)
6971

@@ -130,6 +132,12 @@ def test_comment(self):
130132
Test that the ThermoData comment property was properly set.
131133
"""
132134
assert self.thermodata.comment == self.comment
135+
136+
def test_thermo_coverage_dependence(self):
137+
"""
138+
Test that the ThermoData thermo_coverage_dependence property was properly set.
139+
"""
140+
assert repr(self.thermodata.thermo_coverage_dependence) == repr(self.thermo_coverage_dependence)
133141

134142
def test_is_temperature_valid(self):
135143
"""
@@ -261,6 +269,7 @@ def test_pickle(self):
261269
assert round(abs(self.thermodata.E0.value - thermodata.E0.value), 4) == 0
262270
assert self.thermodata.E0.units == thermodata.E0.units
263271
assert self.thermodata.label == thermodata.label
272+
assert repr(self.thermodata.thermo_coverage_dependence) == repr(thermodata.thermo_coverage_dependence)
264273
assert self.thermodata.comment == thermodata.comment
265274

266275
def test_repr(self):
@@ -295,6 +304,7 @@ def test_repr(self):
295304
assert round(abs(self.thermodata.E0.value - thermodata.E0.value), 4) == 0
296305
assert self.thermodata.E0.units == thermodata.E0.units
297306
assert self.thermodata.label == thermodata.label
307+
assert repr(self.thermodata.thermo_coverage_dependence) == repr(thermodata.thermo_coverage_dependence)
298308
assert self.thermodata.comment == thermodata.comment
299309

300310
def test_is_all_zeros(self):

test/rmgpy/thermo/wilhoitTest.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class TestWilhoit:
4545
"""
4646
Contains unit tests of the :class:`Wilhoit` class.
4747
"""
48-
4948
def setup_class(self):
5049
self.Cp0 = 4.0
5150
self.CpInf = 21.5
@@ -59,6 +58,7 @@ def setup_class(self):
5958
self.Tmin = 300.0
6059
self.Tmax = 3000.0
6160
self.comment = "C2H6"
61+
self.thermo_coverage_dependence = {'OX':{'model':'polynomial', 'enthalpy-coefficients':[1,2,3], "entropy-coefficients":[1,2,3]}}
6262
self.wilhoit = Wilhoit(
6363
Cp0=(self.Cp0 * constants.R, "J/(mol*K)"),
6464
CpInf=(self.CpInf * constants.R, "J/(mol*K)"),
@@ -71,6 +71,7 @@ def setup_class(self):
7171
S0=(self.S0 * constants.R, "J/(mol*K)"),
7272
Tmin=(self.Tmin, "K"),
7373
Tmax=(self.Tmax, "K"),
74+
thermo_coverage_dependence=self.thermo_coverage_dependence,
7475
comment=self.comment,
7576
)
7677

@@ -159,6 +160,12 @@ def test_comment(self):
159160
Test that the Wilhoit comment property was properly set.
160161
"""
161162
assert self.wilhoit.comment == self.comment
163+
164+
def test_thermo_coverage_dependence(self):
165+
"""
166+
Test that the Wilhoit thermo_coverage_dependence property was properly set.
167+
"""
168+
assert repr(self.wilhoit.thermo_coverage_dependence) == repr(self.thermo_coverage_dependence)
162169

163170
def test_is_temperature_valid(self):
164171
"""
@@ -287,6 +294,7 @@ def test_pickle(self):
287294
assert self.wilhoit.Tmax.units == wilhoit.Tmax.units
288295
assert round(abs(self.wilhoit.E0.value - wilhoit.E0.value), 4) == 0
289296
assert self.wilhoit.E0.units == wilhoit.E0.units
297+
assert repr(self.wilhoit.thermo_coverage_dependence) == repr(wilhoit.thermo_coverage_dependence)
290298
assert self.wilhoit.comment == wilhoit.comment
291299

292300
def test_repr(self):
@@ -318,6 +326,7 @@ def test_repr(self):
318326
assert self.wilhoit.Tmax.units == wilhoit.Tmax.units
319327
assert round(abs(self.wilhoit.E0.value - wilhoit.E0.value), 1) == 0
320328
assert self.wilhoit.E0.units == wilhoit.E0.units
329+
assert repr(self.wilhoit.thermo_coverage_dependence) == repr(wilhoit.thermo_coverage_dependence)
321330
assert self.wilhoit.comment == wilhoit.comment
322331

323332
def test_fit_to_data(self):
@@ -381,6 +390,7 @@ def test_to_wilhoit(self):
381390

382391
spc = Species().from_smiles("CC")
383392
spc.get_thermo_data()
393+
spc.thermo.thermo_coverage_dependence = self.thermo_coverage_dependence
384394

385395
T = 1350.0 # not 298K!
386396

@@ -448,6 +458,16 @@ def test_wilhoit_as_dict(self):
448458
"value": 178.76114800000002,
449459
},
450460
"class": "Wilhoit",
461+
'thermo_coverage_dependence': {'OX': {
462+
'model': 'polynomial',
463+
'enthalpy-coefficients': [{'class': 'ScalarQuantity', 'value': 1.0},
464+
{'class': 'ScalarQuantity', 'value': 2.0},
465+
{'class': 'ScalarQuantity', 'value': 3.0}
466+
],
467+
'entropy-coefficients': [{'class': 'ScalarQuantity', 'value': 1.0},
468+
{'class': 'ScalarQuantity', 'value': 2.0},
469+
{'class': 'ScalarQuantity', 'value': 3.0}
470+
]}}
451471
}
452472

453473
def test_make_wilhoit(self):

0 commit comments

Comments
 (0)