diff --git a/doc/sphinx/yaml/phases.rst b/doc/sphinx/yaml/phases.rst index e3635c568..e3f0cb6b2 100644 --- a/doc/sphinx/yaml/phases.rst +++ b/doc/sphinx/yaml/phases.rst @@ -45,6 +45,11 @@ The fields of a ``phase`` entry are: explicitly included in the phase. The default is ``false``, where the presence of such species is considered an error. +``skip-undeclared-third-bodies`` + If set to ``true``, ignore third body efficiencies for species that are not + defined in the phase. The default is ``false``, where the presence of + such third body specifications is considered an error. + ``state`` A mapping specifying the thermodynamic state. See :ref:`sec-yaml-setting-state`. diff --git a/src/kinetics/KineticsFactory.cpp b/src/kinetics/KineticsFactory.cpp index 87c570719..02437e71f 100644 --- a/src/kinetics/KineticsFactory.cpp +++ b/src/kinetics/KineticsFactory.cpp @@ -96,6 +96,9 @@ unique_ptr newKinetics(std::vector& phases, void addReactions(Kinetics& kin, const AnyMap& phaseNode, const AnyMap& rootNode) { + kin.skipUndeclaredThirdBodies( + phaseNode.getBool("skip-undeclared-third-bodies", false)); + // Find sections containing reactions to add vector sections, rules; @@ -130,10 +133,8 @@ void addReactions(Kinetics& kin, const AnyMap& phaseNode, const AnyMap& rootNode for (size_t i = 0; i < sections.size(); i++) { if (rules[i] == "all") { kin.skipUndeclaredSpecies(false); - kin.skipUndeclaredThirdBodies(false); } else if (rules[i] == "declared-species") { kin.skipUndeclaredSpecies(true); - kin.skipUndeclaredThirdBodies(true); } else if (rules[i] != "none") { throw InputFileError("setupKinetics", phaseNode.at("reactions"), "Unknown rule '{}' for adding species from the '{}' section.", diff --git a/test/data/ideal-gas.yaml b/test/data/ideal-gas.yaml index ff8145f3a..6105935d4 100644 --- a/test/data/ideal-gas.yaml +++ b/test/data/ideal-gas.yaml @@ -54,6 +54,24 @@ phases: reactions: [reactions, test_subdir/species-elements.yaml/nox-reactions] state: {T: 300.0, P: 1 atm, X: {AR: 0.2, O2: 0.7, N2: 0.1}} +- name: efficiency-error + thermo: ideal-gas + kinetics: gas + species: + - species: [N2, O] + - test_subdir/species-elements.yaml/species: [N2O] + reactions: [test_subdir/species-elements.yaml/nox-reactions] + state: {T: 300.0, P: 1 atm, X: {N2: 1.0}} + +- name: efficiency-skip + thermo: ideal-gas + kinetics: gas + skip-undeclared-third-bodies: true + species: + - species: [N2, O] + - test_subdir/species-elements.yaml/species: [N2O] + reactions: [test_subdir/species-elements.yaml/nox-reactions] + state: {T: 300.0, P: 1 atm, X: {N2: 1.0}} elements: - symbol: Ar diff --git a/test/kinetics/kineticsFromYaml.cpp b/test/kinetics/kineticsFromYaml.cpp index dfff7bf1c..315fd4be3 100644 --- a/test/kinetics/kineticsFromYaml.cpp +++ b/test/kinetics/kineticsFromYaml.cpp @@ -197,6 +197,22 @@ TEST(Kinetics, GasKineticsFromYaml2) EXPECT_EQ(kin->nReactions(), (size_t) 3); } +TEST(Kinetics, EfficienciesFromYaml) +{ + AnyMap infile = AnyMap::fromYamlFile("ideal-gas.yaml"); + auto& phaseNode1 = infile["phases"].getMapWhere("name", "efficiency-error"); + shared_ptr thermo1 = newPhase(phaseNode1, infile); + std::vector phases1{thermo1.get()}; + // Reaction with efficiency defined for undeclared species "AR" + EXPECT_THROW(newKinetics(phases1, phaseNode1, infile), CanteraError); + + auto& phaseNode2 = infile["phases"].getMapWhere("name", "efficiency-skip"); + shared_ptr thermo2 = newPhase(phaseNode2, infile); + std::vector phases2{thermo2.get()}; + auto kin = newKinetics(phases2, phaseNode2, infile); + EXPECT_EQ(kin->nReactions(), (size_t) 1); +} + TEST(Kinetics, InterfaceKineticsFromYaml) { shared_ptr gas(newPhase("surface-phases.yaml", "gas"));