test with cantera reference updated

This commit is contained in:
Nicolas Kruse 2025-06-24 10:59:16 +02:00
parent b758d78a14
commit c57a247255
1 changed files with 10 additions and 7 deletions

View File

@ -1,7 +1,8 @@
import gaspype as gp import gaspype as gp
import numpy as np import numpy as np
# import pytest # import pytest
import cantera as ct # type: ignore import cantera as ct
from gaspype.typing import NDFloat
def test_equilibrium_cantera(): def test_equilibrium_cantera():
@ -16,7 +17,7 @@ def test_equilibrium_cantera():
composition = gp.fluid({'H2': 1}, fs) +\ composition = gp.fluid({'H2': 1}, fs) +\
gp.fluid({'CH4': 1}, fs) * np.linspace(0, 0.05, 30) +\ gp.fluid({'CH4': 1}, fs) * np.linspace(0, 0.05, 30) +\
gp.fluid({'O2': 1}, fs) * np.expand_dims(np.linspace(0, 0.5, 30), axis=1) gp.fluid({'O2': 1}, fs) * np.linspace(0, 0.5, 30)[:, None]
t = 1495 + 273.15 # K t = 1495 + 273.15 # K
p = 1e5 # Pa p = 1e5 # Pa
@ -40,10 +41,12 @@ def test_equilibrium_cantera():
#if flow1.X[indeces][0] > 0.01: #if flow1.X[indeces][0] > 0.01:
# print(flow1.X[indeces]) # print(flow1.X[indeces])
ct_result_array = np.stack(ct_results) # type: ignore ct_result_array = np.stack(ct_results, dtype=NDFloat) # type: ignore
max_deviation = np.max(np.abs((gp_result_array - ct_result_array))) deviations = np.abs(gp_result_array - ct_result_array)
mean_deviation = np.mean(np.abs((gp_result_array - ct_result_array)))
assert max_deviation < 0.04 for dev, gp_comp_result, ct_comp_result in zip(deviations, gp_result_array, ct_result_array):
assert mean_deviation < 2e-4 print(f"Composition: {gp_comp_result} / {ct_comp_result}")
assert np.all(dev < 0.04), f"Deviateion: {dev}"
assert np.mean(deviations) < 2e-4