From 317bdf73851fdb63e2e5d0f75dac834b00a4ad46 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 10 Jul 2026 09:59:12 +0200 Subject: [PATCH] Equilibrium benchmark updated: NASA CEA added --- .gitignore | 3 ++- tests/benchmark_equalibrium.py | 38 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 98fb789..6a9551c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ venv/ .venv/ thermo_data/combined_data.yaml src/gaspype/data/therm_data.bin -*/*/build/ \ No newline at end of file +*/*/build/ +examples/*.ipynb diff --git a/tests/benchmark_equalibrium.py b/tests/benchmark_equalibrium.py index 4c0fe3a..8378b1f 100644 --- a/tests/benchmark_equalibrium.py +++ b/tests/benchmark_equalibrium.py @@ -4,9 +4,16 @@ import numpy as np import time from gaspype import fluid_system +try: + import cea + CEA_AVAILABLE = True +except ImportError: + CEA_AVAILABLE = False + # ----------------------- # Settings # ----------------------- + n_temps = 1000 temps_C = np.linspace(300, 1000, n_temps) # °C temperatures = temps_C + 273.15 # K @@ -48,11 +55,40 @@ print(f"Gaspype: {elapsed_gaspype:.4f} s") el_err = np.sum((gp.elements(eq_gaspype) - gp.elements(fluid)).get_n()**2) assert np.all(el_err < 1e-20) +if CEA_AVAILABLE: + reac_names = ["CH4", "H2O"] + prod_names = ["CH4", "H2O", "CO", "CO2", "H2", "O2", "H", "O", "OH"] + + reac = cea.Mixture(reac_names) + prod = cea.Mixture(prod_names) + + solver = cea.EqSolver(prod, reactants=reac) + solution = cea.EqSolution(solver) + + input_moles = np.array([8.0, 2.0]) + input_weights = reac.moles_to_weights(input_moles) + + p_bar = pressure * 1e-5 # Convert to bar + + eq_cea = np.zeros((n_temps, len(species_to_track))) + + time.sleep(0.5) + t0 = time.perf_counter() + for i, T in enumerate(temperatures): + solver.solve(solution, cea.TP, T, p_bar, input_weights) + if solution.converged: + for j, s in enumerate(species_to_track): + eq_cea[i, j] = solution.mole_fractions.get(s, 0.0) + elapsed_cea = time.perf_counter() - t0 + print(f"CEA: {elapsed_cea:.4f} s") + # ----------------------- # Compare first 5 results # ----------------------- -print("First 5 equilibrium compositions (mole fractions):") +print("\nFirst 5 equilibrium compositions:") for i in range(5): print(f"T = {temperatures[i]:.1f} K") print(" Cantera:", eq_cantera[i]) print(" Gaspype :", eq_gaspype.array_composition[i]) + if CEA_AVAILABLE: + print(" CEA :", eq_cea[i])