From f8fdb8e50862430b80bac90e6b8df549e4d09828 Mon Sep 17 00:00:00 2001 From: Cory Kinney Date: Thu, 16 May 2024 13:31:07 -0400 Subject: [PATCH] yaml2ck: Check if third body is in species list Does not write the third body efficiencies for species that are not in the solution's species list Fixed #1683 --- interfaces/cython/cantera/yaml2ck.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interfaces/cython/cantera/yaml2ck.py b/interfaces/cython/cantera/yaml2ck.py index 03ba8b66a..daa2f7fc4 100644 --- a/interfaces/cython/cantera/yaml2ck.py +++ b/interfaces/cython/cantera/yaml2ck.py @@ -336,7 +336,7 @@ def build_thermodynamics_text( ) -def build_reactions_text(reactions: Iterable[ct.Reaction]): +def build_reactions_text(reactions: Iterable[ct.Reaction], species: Iterable[ct.Species]): """ Create the reaction definition section of this file. @@ -346,6 +346,8 @@ def build_reactions_text(reactions: Iterable[ct.Reaction]): .. versionadded:: 3.0 """ + species_names = [spec.name for spec in species] + # Note: Cantera converts explicit reverse rate coefficients given by the ``REV`` # keyword into two independent irreversible reactions. Therefore, there's no need to # handle the ``REV`` keyword in this function. @@ -478,6 +480,7 @@ def build_reactions_text(reactions: Iterable[ct.Reaction]): " ".join( f"{spec}/{value:.3E}/" for spec, value in reac.third_body.efficiencies.items() + if spec in species_names ) ) @@ -701,7 +704,7 @@ def convert( # TODO: Handle phases without reactions all_reactions = solution.reactions() - mechanism_text.append(build_reactions_text(all_reactions)) + mechanism_text.append(build_reactions_text(all_reactions, all_species)) if transport_path is None and transport_exists: mechanism_text.append(build_transport_text(all_species, separate_file=False))