From 6f8eb2914c1956d70a2079fb16d514cd50a34d12 Mon Sep 17 00:00:00 2001 From: Nicolas Kruse Date: Mon, 17 Nov 2025 13:49:13 +0100 Subject: [PATCH] extended the test_results_cantera --- tests/test_results_cantera.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/test_results_cantera.py b/tests/test_results_cantera.py index fb397f2..39ffee6 100644 --- a/tests/test_results_cantera.py +++ b/tests/test_results_cantera.py @@ -28,14 +28,14 @@ def test_equilibrium_cantera(): flow1 = ct.Solution('gri30.yaml') # type: ignore ct_results = [] - comp = (composition.array_fractions[i, j] for i in range(composition.shape[0]) for j in range(composition.shape[1])) + comp = [composition.array_fractions[i, j] for i in range(composition.shape[0]) for j in range(composition.shape[1])] for c in comp: comp_dict = {s: v for s, v in zip(fs.species, c)} flow1.TP = t, p flow1.X = comp_dict flow1.equilibrate('TP') # type: ignore - indeces = [i for flsn in fs.active_species for i, sn in enumerate(flow1.species_names) if flsn == sn] # type: ignore + indeces = [i for flsn in fs.species for i, sn in enumerate(flow1.species_names) if flsn == sn] # type: ignore ct_results.append(flow1.X[indeces]) # type: ignore #if flow1.X[indeces][0] > 0.01: @@ -45,8 +45,33 @@ def test_equilibrium_cantera(): deviations = np.abs(gp_result_array - ct_result_array) - for dev, gp_comp_result, ct_comp_result in zip(deviations, gp_result_array, ct_result_array): - print(f"Composition: {gp_comp_result} / {ct_comp_result}") + for dev, gp_comp_result, ct_comp_result, c in zip(deviations, gp_result_array, ct_result_array, comp): + comp_dict = {s: v for s, v in zip(fs.species, c)} + print(f"Inp. Composition: {comp_dict}") + print(f"Res. Composition: {gp_comp_result}") + print(f"Ref. Composition: {ct_comp_result}") + print(f"---") assert np.all(dev < 0.04), f"Deviateion: {dev}" assert np.mean(deviations) < 2e-4 + + +def test_cantera(): + + t = 1495 + 273.15 # K + p = 1e5 # Pa + + flow1 = ct.Solution('gri30.yaml') # type: ignore + flow1.TP = t, p + inp_comp = {'CH4': 0.0, 'H2O': 0.0, 'H2': 0.9508196721311476, 'CO2': 0.0, 'CO': 0.0, 'O2': 0.04918032786885246} + flow1.X = inp_comp + flow1.equilibrate('TP') # type: ignore + + results: dict[str, float] = {sn: float(flow1.X[i]) for flsn in inp_comp for i, sn in enumerate(flow1.species_names) if flsn == sn} # type: ignore + + print(inp_comp) + print(results) + + +if __name__ == "__main__": + test_cantera() \ No newline at end of file