[Input] Implement 'skip-undeclared-third-bodies' option in YAML format

This commit is contained in:
Ray Speth 2019-06-17 12:27:49 -04:00
parent a7aa6e721a
commit 44c5094bb2
4 changed files with 42 additions and 2 deletions

View file

@ -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`.

View file

@ -96,6 +96,9 @@ unique_ptr<Kinetics> newKinetics(std::vector<ThermoPhase*>& 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<string> 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.",

View file

@ -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

View file

@ -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<ThermoPhase> thermo1 = newPhase(phaseNode1, infile);
std::vector<ThermoPhase*> 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<ThermoPhase> thermo2 = newPhase(phaseNode2, infile);
std::vector<ThermoPhase*> phases2{thermo2.get()};
auto kin = newKinetics(phases2, phaseNode2, infile);
EXPECT_EQ(kin->nReactions(), (size_t) 1);
}
TEST(Kinetics, InterfaceKineticsFromYaml)
{
shared_ptr<ThermoPhase> gas(newPhase("surface-phases.yaml", "gas"));