From 82d1487ec441d58fe746efd5aef47c5a8007ad45 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 12 Aug 2023 12:46:54 -0500 Subject: [PATCH] [unittests] Add test for mechanism reduction --- test/python/test_kinetics.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/python/test_kinetics.py b/test/python/test_kinetics.py index ec475ad5a0c..3a083c6a354 100644 --- a/test/python/test_kinetics.py +++ b/test/python/test_kinetics.py @@ -304,7 +304,7 @@ def test_coverage_dependence_flags(self): surf.net_rates_of_progress_ddCi def test_electrochemistry_flags(self): - # Phases + # Phases mech = "lithium_ion_battery.yaml" anode, cathode, metal, electrolyte = ct.import_phases( mech, ["anode", "cathode", "electron", "electrolyte"]) @@ -315,6 +315,29 @@ def test_electrochemistry_flags(self): anode_int.derivative_settings = {"skip-electrochemistry": True} anode_int.net_rates_of_progress_ddCi + def test_submechanism(self): + # Simplified samples/python/kinetics/extract_submechanism.py + gri30 = ct.Solution('gri30.yaml') + h2o2 = ct.Solution('h2o2.yaml') + + reactions = [] + dest_species = set(h2o2.species_names) + colliders = dest_species.union([None, "M"]) + for R in gri30.reactions(): + if all(S in dest_species for S in (R.reactants | R.products).keys()): + if R.third_body_collider in colliders: + reactions.append(R) + + gas = ct.Solution(thermo='ideal-gas', kinetics='gas', species=h2o2.species(), + reactions=reactions) + assert gas.n_reactions == len(reactions) + assert gas.n_species == len(h2o2.species_names) + + gas.write_yaml("reduced.yaml") + restored = ct.Solution("reduced.yaml") + assert gas.species_names == restored.species_names + assert gas.reaction_equations() == restored.reaction_equations() + class KineticsRepeatability(utilities.CanteraTest): """