Skip to content

Commit

Permalink
[Kinetics] Remove reactant/productString specializations
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 17, 2022
1 parent 3c24987 commit a5fb7ea
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 69 deletions.
24 changes: 10 additions & 14 deletions include/cantera/kinetics/Reaction.h
Expand Up @@ -42,10 +42,10 @@ class Reaction
virtual ~Reaction() {}

//! The reactant side of the chemical equation for this reaction
virtual std::string reactantString() const;
std::string reactantString() const;

//! The product side of the chemical equation for this reaction
virtual std::string productString() const;
std::string productString() const;

//! The chemical equation for this reaction
std::string equation() const;
Expand Down Expand Up @@ -200,8 +200,8 @@ class Reaction
//! Reaction rate used by generic reactions
shared_ptr<ReactionRate> m_rate;

//! Relative efficiencies of third-body species in enhancing the reaction
//! rate (if applicable)
//! Relative efficiencies of third-body species in enhancing the reaction rate
//! (if applicable)
shared_ptr<ThirdBody> m_third_body;
};

Expand All @@ -220,19 +220,21 @@ class ThirdBody
//! Get the third-body efficiency for species *k*
double efficiency(const std::string& k) const;

//! Name or placeholder of third body collider, for example `+ M`
std::string collider() const;

//! Map of species to third body efficiency
Composition efficiencies;

//! The default third body efficiency for species not listed in
//! #efficiencies.
//! The default third body efficiency for species not listed in #efficiencies.
double default_efficiency;

//! Input explicitly specifies collision partner
bool specified_collision_partner;
bool specified_collision_partner = false;

//! Third body is used by law of mass action
//! (`true` for three-body reactions, `false` for falloff reactions)
bool mass_action;
bool mass_action = true;
};


Expand All @@ -255,9 +257,6 @@ class ThreeBodyReaction : public Reaction
bool detectEfficiencies();
virtual void setParameters(const AnyMap& node, const Kinetics& kin);
virtual void getParameters(AnyMap& reactionNode) const;

virtual std::string reactantString() const;
virtual std::string productString() const;
};


Expand All @@ -281,9 +280,6 @@ class FalloffReaction : public Reaction
virtual void setEquation(const std::string& equation, const Kinetics* kin);
virtual void setParameters(const AnyMap& node, const Kinetics& kin);
virtual void getParameters(AnyMap& reactionNode) const;

virtual std::string reactantString() const;
virtual std::string productString() const;
};


Expand Down
84 changes: 29 additions & 55 deletions src/kinetics/Reaction.cpp
Expand Up @@ -51,11 +51,11 @@ Reaction::Reaction(const AnyMap& node, const Kinetics& kin)
}
std::string type = rateNode["type"].asString();
if (rateNode.hasKey("rate-constant")) {
if (!boost::algorithm::starts_with(type, "interface-")) {
if (!ba::starts_with(type, "interface-")) {
rateNode["type"] = "interface-" + type;
}
} else if (node.hasKey("sticking-coefficient")) {
if (!boost::algorithm::starts_with(type, "sticking-")) {
if (!ba::starts_with(type, "sticking-")) {
rateNode["type"] = "sticking-" + type;
}
} else {
Expand Down Expand Up @@ -152,9 +152,9 @@ void Reaction::getParameters(AnyMap& reactionNode) const
// strip information not needed for reconstruction
if (reactionNode.hasKey("type")) {
std::string type = reactionNode["type"].asString();
if (boost::algorithm::starts_with(type, "Arrhenius")) {
if (ba::starts_with(type, "Arrhenius")) {
reactionNode.erase("type");
} else if (boost::algorithm::starts_with(type, "Blowers-Masel")) {
} else if (ba::starts_with(type, "Blowers-Masel")) {
reactionNode["type"] = "Blowers-Masel";
}
}
Expand Down Expand Up @@ -223,7 +223,10 @@ std::string Reaction::reactantString() const
}
result << iter->first;
}
return result.str();
if (m_third_body) {
result << m_third_body->collider();
}
return result.str();
}

std::string Reaction::productString() const
Expand All @@ -238,7 +241,10 @@ std::string Reaction::productString() const
}
result << iter->first;
}
return result.str();
if (m_third_body) {
result << m_third_body->collider();
}
return result.str();
}

std::string Reaction::equation() const
Expand Down Expand Up @@ -406,7 +412,7 @@ bool Reaction::checkSpecies(const Kinetics& kin) const
} else {
throw InputFileError("Reaction::checkSpecies", input, "Reaction '{}'\n"
"contains undeclared species: '{}'",
equation(), boost::algorithm::join(undeclared, "', '"));
equation(), ba::join(undeclared, "', '"));
}
}

Expand All @@ -420,12 +426,12 @@ bool Reaction::checkSpecies(const Kinetics& kin) const
throw InputFileError("Reaction::checkSpecies", input["orders"],
"Reaction '{}'\n"
"defines reaction orders for undeclared species: '{}'",
equation(), boost::algorithm::join(undeclared, "', '"));
equation(), ba::join(undeclared, "', '"));
}
// Error for empty input AnyMap (that is, XML)
throw InputFileError("Reaction::checkSpecies", input, "Reaction '{}'\n"
"defines reaction orders for undeclared species: '{}'",
equation(), boost::algorithm::join(undeclared, "', '"));
equation(), ba::join(undeclared, "', '"));
}
}

Expand All @@ -439,12 +445,12 @@ bool Reaction::checkSpecies(const Kinetics& kin) const
throw InputFileError("Reaction::checkSpecies", input["efficiencies"],
"Reaction '{}'\n"
"defines third-body efficiencies for undeclared species: '{}'",
equation(), boost::algorithm::join(undeclared, "', '"));
equation(), ba::join(undeclared, "', '"));
}
// Error for specified ThirdBody or empty input AnyMap
throw InputFileError("Reaction::checkSpecies", input, "Reaction '{}'\n"
"is a three-body reaction with undeclared species: '{}'",
equation(), boost::algorithm::join(undeclared, "', '"));
equation(), ba::join(undeclared, "', '"));
} else if (kin.skipUndeclaredSpecies() && specified_collision_partner_) {
return false;
}
Expand Down Expand Up @@ -488,14 +494,10 @@ bool Reaction::usesElectrochemistry(const Kinetics& kin) const

ThirdBody::ThirdBody(double default_eff)
: default_efficiency(default_eff)
, specified_collision_partner(false)
, mass_action(true)
{
}

ThirdBody::ThirdBody(const AnyMap& node)
: specified_collision_partner(false)
, mass_action(true)
{
setEfficiencies(node);
}
Expand All @@ -513,6 +515,18 @@ double ThirdBody::efficiency(const std::string& k) const
return getValue(efficiencies, k, default_efficiency);
}

std::string ThirdBody::collider() const
{
std::string name = "M";
if (specified_collision_partner && efficiencies.size()) {
name = efficiencies.begin()->first;
}
if (mass_action) {
return " + " + name;
}
return " (+" + name + ")";
}

ThreeBodyReaction::ThreeBodyReaction()
{
m_third_body.reset(new ThirdBody);
Expand Down Expand Up @@ -620,26 +634,6 @@ void ThreeBodyReaction::getParameters(AnyMap& reactionNode) const
}
}

std::string ThreeBodyReaction::reactantString() const
{
if (m_third_body->specified_collision_partner) {
return Reaction::reactantString() + " + "
+ m_third_body->efficiencies.begin()->first;
} else {
return Reaction::reactantString() + " + M";
}
}

std::string ThreeBodyReaction::productString() const
{
if (m_third_body->specified_collision_partner) {
return Reaction::productString() + " + "
+ m_third_body->efficiencies.begin()->first;
} else {
return Reaction::productString() + " + M";
}
}

FalloffReaction::FalloffReaction()
{
m_third_body.reset(new ThirdBody);
Expand Down Expand Up @@ -688,26 +682,6 @@ std::string FalloffReaction::type() const
return "falloff";
}

std::string FalloffReaction::reactantString() const
{
if (m_third_body->specified_collision_partner) {
return Reaction::reactantString() + " (+" +
m_third_body->efficiencies.begin()->first + ")";
} else {
return Reaction::reactantString() + " (+M)";
}
}

std::string FalloffReaction::productString() const
{
if (m_third_body->specified_collision_partner) {
return Reaction::productString() + " (+" +
m_third_body->efficiencies.begin()->first + ")";
} else {
return Reaction::productString() + " (+M)";
}
}

void FalloffReaction::setParameters(const AnyMap& node, const Kinetics& kin)
{
if (node.empty()) {
Expand Down

0 comments on commit a5fb7ea

Please sign in to comment.