Skip to content

Commit

Permalink
[test] addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wandadars committed Oct 17, 2024
1 parent 80ecdc1 commit 3a300b4
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 539 deletions.
9 changes: 3 additions & 6 deletions test/python/test_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def test_legacy_hdf_multidim(self, test_data_path):
@pytest.mark.skipif("native" not in ct.hdf_support(),
reason="Cantera compiled without HDF support")
@pytest.mark.filterwarnings("ignore:.*legacy HDF.*:UserWarning")
def test_legacy_hdf(self, test_data_path, legacy=False):
def test_legacy_hdf(self, test_data_path):
# recreate states used to create legacy HDF file (valid portion)
extra = {'foo': range(7), 'bar': range(7)}
meta = {'spam': 'eggs', 'hello': 'world'}
Expand All @@ -814,18 +814,15 @@ def test_legacy_hdf(self, test_data_path, legacy=False):
@pytest.mark.skipif("native" not in ct.hdf_support(),
reason="Cantera compiled without HDF support")
@pytest.mark.filterwarnings("ignore:.*legacy HDF.*:UserWarning")
def test_read_legacy_hdf_no_norm(self, test_data_path, legacy=False):
def test_read_legacy_hdf_no_norm(self, test_data_path):
# recreate states used to create legacy HDF file
self.gas.set_unnormalized_mole_fractions(np.full(self.gas.n_species, 0.3))
states = ct.SolutionArray(self.gas, 5)

infile = test_data_path / "solutionarray_no_norm_legacy.h5"

b = ct.SolutionArray(self.gas)
if legacy:
b.read_hdf(infile, normalize=False)
else:
b.restore(infile, "group0")
b.restore(infile, "group0")
assert states.T == approx(b.T, rel=1e-7)
assert states.P == approx(b.P, rel=1e-7)
assert states.X == approx(b.X, rel=1e-7)
Expand Down
71 changes: 36 additions & 35 deletions test/python/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def checkConversion(self, refFile, testFile):
for i in range(ref.n_species)]
compositionB = [[gas.n_atoms(i,j) for j in range(gas.n_elements)]
for i in range(gas.n_species)]
assert compositionA, compositionB
assert compositionA == compositionB

return ref, gas

Expand All @@ -70,9 +70,9 @@ def checkThermo(self, ref, gas, temperatures):
gas_s = gas.standard_entropies_R
for i in range(gas.n_species):
message = ' for species {0} at T = {1}'.format(i, T)
assert ref_cp[i] == approx(gas_cp[i], rel=1e-7)
assert ref_h[i] == approx(gas_h[i], rel=1e-7)
assert ref_s[i] == approx(gas_s[i], rel=1e-7)
assert ref_cp[i] == approx(gas_cp[i], rel=1e-7), 'cp' + message
assert ref_h[i] == approx(gas_h[i], rel=1e-7), 'h' + message
assert ref_s[i] == approx(gas_s[i], rel=1e-7), 's' + message

def checkKinetics(self, ref, gas, temperatures, pressures, tol=1e-8):
for T,P in itertools.product(temperatures, pressures):
Expand All @@ -84,8 +84,8 @@ def checkKinetics(self, ref, gas, temperatures, pressures, tol=1e-8):
gas_kr = gas.reverse_rate_constants
for i in range(gas.n_reactions):
message = ' for reaction {0} at T = {1}, P = {2}'.format(i, T, P)
assert ref_kf[i] == approx(gas_kf[i], rel=tol)
assert ref_kr[i] == approx(gas_kr[i], rel=tol)
assert ref_kf[i] == approx(gas_kf[i], rel=tol), 'kf' + message
assert ref_kr[i] == approx(gas_kr[i], rel=tol), 'kr' + message

@pytest.mark.slow_test
def test_gri30(self):
Expand Down Expand Up @@ -228,15 +228,15 @@ def test_pathologicalSpeciesNames(self):
assert list(nu[:,1]) == [-2, 3, 0, -1, 0, 0, 0, 0, 0, 0]
assert list(nu[:,2]) == [-1, 0, 0, 0, 1, 0, 0, 0, 0, 0]
assert list(nu[:,3]) == [3, 0, 0, 0, -2, -1, 0, 0, 0, 0]
assert list(nu[:,4])== [2, 0, 0, 0, -1, 0, -1, 0, 0, 0]
assert list(nu[:,5])== [1, 0, 0, 0, 1, -1, -1, 0, 0, 0]
assert list(nu[:,6])== [2, 0, -1, 0, 0, -1, 0, 0, 0, 0]
assert list(nu[:,7])== [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,8])== [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,9])== [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,10])== [0, 0, -1, 0, 2, 0, 0, -1, 0, 0]
assert list(nu[:,11])== [0, 0, -1, 0, 2, 0, 0, 0, -1, 0]
assert list(nu[:,12])== [0, 0, 0, 0, 1, 0, 0, 0, 0, -1]
assert list(nu[:,4]) == [2, 0, 0, 0, -1, 0, -1, 0, 0, 0]
assert list(nu[:,5]) == [1, 0, 0, 0, 1, -1, -1, 0, 0, 0]
assert list(nu[:,6]) == [2, 0, -1, 0, 0, -1, 0, 0, 0, 0]
assert list(nu[:,7]) == [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,8]) == [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,9]) == [0, 0, 0, 0, -1, 1, 0, 0, 0, 0]
assert list(nu[:,10]) == [0, 0, -1, 0, 2, 0, 0, -1, 0, 0]
assert list(nu[:,11]) == [0, 0, -1, 0, 2, 0, 0, 0, -1, 0]
assert list(nu[:,12]) == [0, 0, 0, 0, 1, 0, 0, 0, 0, -1]

def test_unterminatedSections(self):
output = self.convert('unterminated-sections.inp', quiet=False)
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_explicit_reverse_rate(self):
# two irreversible reactions with reactants and products swapped, unless
# the explicit reverse rate is zero so only the forward reaction is used.
Rr = gas.reverse_rate_constants
assert Rr[0] == 0.0
assert Rr[0] == 0.0
assert Rr[1] == 0.0
assert Rr[2] == 0.0
assert Rr[3] == 0.0
Expand Down Expand Up @@ -891,9 +891,9 @@ def check_thermo(self, ck_phase, yaml_phase, temperatures, tol=1e-7):
assert ck_phase.density == approx(yaml_phase.density)
for i in range(ck_phase.n_species):
message = ' for species {0} at T = {1}'.format(i, T)
assert cp_ck[i] == approx(cp_yaml[yaml_idx[i]], rel=tol)
assert h_ck[i] == approx(h_yaml[yaml_idx[i]], rel=tol)
assert s_ck[i] == approx(s_yaml[yaml_idx[i]], rel=tol)
assert cp_ck[i] == approx(cp_yaml[yaml_idx[i]], rel=tol), 'cp' + message
assert h_ck[i] == approx(h_yaml[yaml_idx[i]], rel=tol), 'h' + message
assert s_ck[i] == approx(s_yaml[yaml_idx[i]], rel=tol), 's' + message

def check_kinetics(self, ck_phase, yaml_phase, temperatures, pressures, tol=1e-7):
for T, P in itertools.product(temperatures, pressures):
Expand All @@ -905,8 +905,8 @@ def check_kinetics(self, ck_phase, yaml_phase, temperatures, pressures, tol=1e-7
kr_yaml = yaml_phase.reverse_rate_constants
for i in range(yaml_phase.n_reactions):
message = f"for reaction {i+1}: {yaml_phase.reaction(i)} at T = {T}, P = {P}"
assert kf_ck[i] == approx(kf_yaml[i], rel=tol)
assert kr_ck[i] == approx(kr_yaml[i], rel=tol)
assert kf_ck[i] == approx(kf_yaml[i], rel=tol), 'kf ' + message
assert kr_ck[i] == approx(kr_yaml[i], rel=tol), 'kr ' + message

def check_transport(self, ck_phase, yaml_phase, temperatures, model="mixture-averaged"):
yaml_idx = {ck_phase.species_index(s): yaml_phase.species_index(s) for s in ck_phase.species_names}
Expand All @@ -921,7 +921,7 @@ def check_transport(self, ck_phase, yaml_phase, temperatures, model="mixture-ave
Dkm_yaml = yaml_phase.mix_diff_coeffs
for i in range(ck_phase.n_species):
message = 'dkm for species {0} at T = {1}'.format(i, T)
assert Dkm_ck[i] == approx(Dkm_yaml[yaml_idx[i]])
assert Dkm_ck[i] == approx(Dkm_yaml[yaml_idx[i]]), message

@pytest.mark.slow_test
def test_gri30(self, cantera_data_path):
Expand Down Expand Up @@ -1139,9 +1139,9 @@ def checkThermo(self, ctiPhase, yamlPhase, temperatures, tol=1e-7, check_cp=True
for i in range(ctiPhase.n_species):
message = ' for species {0} at T = {1}'.format(i, T)
if check_cp:
cp_cti[i] == approx(cp_yaml[i], rel=tol)
assert h_cti[i] == approx(h_yaml[i], rel=tol)
assert s_cti[i] == approx(s_yaml[i], rel=tol)
cp_cti[i] == approx(cp_yaml[i], rel=tol), 'cp' + message
assert h_cti[i] == approx(h_yaml[i], rel=tol), 'h' + message
assert s_cti[i] == approx(s_yaml[i], rel=tol), 's' + message

def checkKinetics(self, ctiPhase, yamlPhase, temperatures, pressures, tol=1e-7):
for T,P in itertools.product(temperatures, pressures):
Expand All @@ -1153,8 +1153,8 @@ def checkKinetics(self, ctiPhase, yamlPhase, temperatures, pressures, tol=1e-7):
kr_yaml = yamlPhase.reverse_rate_constants
for i in range(yamlPhase.n_reactions):
message = ' for reaction {0} at T = {1}, P = {2}'.format(i, T, P)
assert kf_cti[i] == approx(kf_yaml[i], rel=tol)
assert kr_cti[i] == approx(kr_yaml[i], rel=tol)
assert kf_cti[i] == approx(kf_yaml[i], rel=tol), 'kf ' + message
assert kr_cti[i] == approx(kr_yaml[i], rel=tol), 'kr ' + message

def checkTransport(self, ctiPhase, yamlPhase, temperatures,
model='mixture-averaged'):
Expand All @@ -1169,7 +1169,7 @@ def checkTransport(self, ctiPhase, yamlPhase, temperatures,
Dkm_yaml = yamlPhase.mix_diff_coeffs
for i in range(ctiPhase.n_species):
message = 'dkm for species {0} at T = {1}'.format(i, T)
assert Dkm_cti[i] == approx(Dkm_yaml[i])
assert Dkm_cti[i] == approx(Dkm_yaml[i]), message

@pytest.mark.slow_test
def test_gri30(self):
Expand Down Expand Up @@ -1343,7 +1343,8 @@ def checkConversion(self, basename, cls=ct.Solution, ctmlphases=(),
assert C.duplicate == Y.duplicate

for i, sp in zip(range(ctmlPhase.n_reactions), ctmlPhase.kinetics_species_names):
assert ctmlPhase.reactant_stoich_coeff(sp, i) == yamlPhase.reactant_stoich_coeff(sp, i)
assert (ctmlPhase.reactant_stoich_coeff(sp, i)
== yamlPhase.reactant_stoich_coeff(sp, i))

return ctmlPhase, yamlPhase

Expand All @@ -1366,9 +1367,9 @@ def checkThermo(self, ctmlPhase, yamlPhase, temperatures, pressure=ct.one_atm,
for i in range(ctmlPhase.n_species):
message = ' for species {0} at T = {1}'.format(ctmlPhase.species_names[i], T)
if check_cp:
assert cp_ctml[i] == approx(cp_yaml[i], rel=tol)
assert h_ctml[i] == approx(h_yaml[i], rel=tol)
assert s_ctml[i] == approx(s_yaml[i], rel=tol)
assert cp_ctml[i] == approx(cp_yaml[i], rel=tol), 'cp' + message
assert h_ctml[i] == approx(h_yaml[i], rel=tol), 'h' + message
assert s_ctml[i] == approx(s_yaml[i], rel=tol), 's' + message

def checkKinetics(self, ctmlPhase, yamlPhase, temperatures, pressures, tol=1e-7):
for T,P in itertools.product(temperatures, pressures):
Expand All @@ -1380,8 +1381,8 @@ def checkKinetics(self, ctmlPhase, yamlPhase, temperatures, pressures, tol=1e-7)
kr_yaml = yamlPhase.reverse_rate_constants
for i in range(yamlPhase.n_reactions):
message = ' for reaction {0} at T = {1}, P = {2}'.format(i, T, P)
assert kf_ctml[i] == approx(kf_yaml[i], rel=tol)
assert kr_ctml[i] == approx(kr_yaml[i], rel=tol)
assert kf_ctml[i] == approx(kf_yaml[i], rel=tol), 'kf ' + message
assert kr_ctml[i] == approx(kr_yaml[i], rel=tol), 'kr ' + message

def checkTransport(self, ctmlPhase, yamlPhase, temperatures,
model='mixture-averaged'):
Expand All @@ -1396,7 +1397,7 @@ def checkTransport(self, ctmlPhase, yamlPhase, temperatures,
Dkm_yaml = yamlPhase.mix_diff_coeffs
for i in range(ctmlPhase.n_species):
message = 'dkm for species {0} at T = {1}'.format(i, T)
assert Dkm_ctml[i] == approx(Dkm_yaml[i])
assert Dkm_ctml[i] == approx(Dkm_yaml[i]), message

@pytest.mark.slow_test
def test_gri30(self):
Expand Down
Loading

0 comments on commit 3a300b4

Please sign in to comment.