Skip to content

Commit

Permalink
[Kinetics] Remove pre-screening for implicit three-body reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 17, 2022
1 parent 5b6c93a commit ec2578b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 72 deletions.
22 changes: 3 additions & 19 deletions src/kinetics/Kinetics.cpp
Expand Up @@ -150,25 +150,9 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
continue; // stoichiometries differ (not by a multiple)
} else if (c < 0.0 && !R.reversible && !other.reversible) {
continue; // irreversible reactions in opposite directions
} else if (R.type() == "falloff" || R.type() == "chemically-activated") {
auto tb1 = dynamic_cast<FalloffReaction&>(R).thirdBody();
auto tb2 = dynamic_cast<FalloffReaction&>(other).thirdBody();
bool thirdBodyOk = true;
for (size_t k = 0; k < nTotalSpecies(); k++) {
string s = kineticsSpeciesName(k);
if (tb1->efficiency(s) * tb2->efficiency(s) != 0.0) {
// non-zero third body efficiencies for species `s` in
// both reactions
thirdBodyOk = false;
break;
}
}
if (thirdBodyOk) {
continue; // No overlap in third body efficiencies
}
} else if (R.type() == "three-body") {
ThirdBody& tb1 = *(dynamic_cast<ThreeBodyReaction&>(R).thirdBody());
ThirdBody& tb2 = *(dynamic_cast<ThreeBodyReaction&>(other).thirdBody());
} else if (R.usesThirdBody() && other.usesThirdBody()) {
ThirdBody& tb1 = *(R.thirdBody());
ThirdBody& tb2 = *(other.thirdBody());
bool thirdBodyOk = true;
for (size_t k = 0; k < nTotalSpecies(); k++) {
string s = kineticsSpeciesName(k);
Expand Down
54 changes: 1 addition & 53 deletions src/kinetics/Reaction.cpp
Expand Up @@ -746,44 +746,6 @@ FalloffReaction::FalloffReaction(const AnyMap& node, const Kinetics& kin)
}
}

bool isThreeBody(const Reaction& R)
{
// detect explicitly specified collision partner
size_t found = 0;
for (const auto& reac : R.reactants) {
auto prod = R.products.find(reac.first);
if (prod != R.products.end() &&
trunc(reac.second) == reac.second && trunc(prod->second) == prod->second) {
// candidate species with integer stoichiometric coefficients on both sides
found += 1;
}
}
if (found != 1) {
return false;
}

// ensure that all reactants have integer stoichiometric coefficients
size_t nreac = 0;
for (const auto& reac : R.reactants) {
if (trunc(reac.second) != reac.second) {
return false;
}
nreac += static_cast<size_t>(reac.second);
}

// ensure that all products have integer stoichiometric coefficients
size_t nprod = 0;
for (const auto& prod : R.products) {
if (trunc(prod.second) != prod.second) {
return false;
}
nprod += static_cast<size_t>(prod.second);
}

// either reactant or product side involves exactly three species
return (nreac == 3) || (nprod == 3);
}

unique_ptr<Reaction> newReaction(const std::string& type)
{
AnyMap rxn_node;
Expand All @@ -794,21 +756,7 @@ unique_ptr<Reaction> newReaction(const std::string& type)

unique_ptr<Reaction> newReaction(const AnyMap& rxn_node, const Kinetics& kin)
{
std::string type = "elementary";
size_t nDim = kin.thermo(kin.reactionPhaseIndex()).nDim();
if (rxn_node.hasKey("type")) {
type = rxn_node["type"].asString();
} else if (nDim == 3) {
// Reaction type is not specified
// See if this is a three-body reaction with a specified collision partner
Reaction testReaction;
parseReactionEquation(testReaction, rxn_node["equation"].asString(),
rxn_node, &kin);
if (isThreeBody(testReaction)) {
type = "three-body";
}
}

std::string type = rxn_node.getString("type", "elementary");
if (!(ReactionFactory::factory()->exists(type))) {
throw InputFileError("ReactionFactory::newReaction", rxn_node["type"],
"Unknown reaction type '{}'", type);
Expand Down

0 comments on commit ec2578b

Please sign in to comment.