Skip to content

Commit

Permalink
[Kinetics] Remove get/setParameter specializations for Reaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jul 17, 2022
1 parent a5fb7ea commit 070e2f0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 62 deletions.
24 changes: 15 additions & 9 deletions include/cantera/kinetics/Reaction.h
Expand Up @@ -74,11 +74,11 @@ class Reaction

//! Ensure that the rate constant and other parameters for this reaction are valid.
//! @since New in Cantera 3.0.
virtual void check();
void check();

//! Ensure that the rate constant and other parameters for this reaction are valid.
//! @deprecated To be removed after Cantera 3.0. Replaceable by check.
virtual void validate() {
void validate() {
warn_deprecated("Reaction::validate",
"Deprecated in Cantera 3.0 and to be removed thereafter; replaceable "
"by Reaction::check.");
Expand All @@ -87,7 +87,7 @@ class Reaction

//! Perform validation checks that need access to a complete Kinetics objects, for
// example to retrieve information about reactant / product species.
virtual void validate(Kinetics& kin) {
void validate(Kinetics& kin) {
if (m_rate) {
m_rate->validate(equation(), kin);
}
Expand All @@ -102,7 +102,7 @@ class Reaction
AnyMap parameters(bool withInput=true) const;

//! Set up reaction based on AnyMap *node*
virtual void setParameters(const AnyMap& node, const Kinetics& kin);
void setParameters(const AnyMap& node, const Kinetics& kin);

//! Get validity flag of reaction
bool valid() const {
Expand Down Expand Up @@ -184,7 +184,7 @@ class Reaction
//! Store the parameters of a Reaction needed to reconstruct an identical
//! object using the newReaction(AnyMap&, Kinetics&) function. Does not
//! include user-defined fields available in the #input map.
virtual void getParameters(AnyMap& reactionNode) const;
void getParameters(AnyMap& reactionNode) const;

//! Flag indicating whether reaction is set up correctly
bool m_valid = true;
Expand Down Expand Up @@ -212,11 +212,21 @@ class ThirdBody
public:
explicit ThirdBody(double default_efficiency=1.0);

//! @todo Remove default kinetics after removal of setEfficiencies
ThirdBody(const AnyMap& node);

//! Set third-body efficiencies from AnyMap *node*
//! @deprecated To be removed after Cantera 3.0; renamed to setParameters
void setEfficiencies(const AnyMap& node);

//! Set third-body efficiencies from AnyMap *node*
//! @since New in Cantera 3.0
void setParameters(const AnyMap& node);

//! Get third-body efficiencies from AnyMap *node*
//! @since New in Cantera 3.0
void getParameters(AnyMap& node) const;

//! Get the third-body efficiency for species *k*
double efficiency(const std::string& k) const;

Expand Down Expand Up @@ -255,8 +265,6 @@ class ThreeBodyReaction : public Reaction

virtual void setEquation(const std::string& equation, const Kinetics* kin=0);
bool detectEfficiencies();
virtual void setParameters(const AnyMap& node, const Kinetics& kin);
virtual void getParameters(AnyMap& reactionNode) const;
};


Expand All @@ -278,8 +286,6 @@ class FalloffReaction : public Reaction
virtual std::string type() const;

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;
};


Expand Down
87 changes: 34 additions & 53 deletions src/kinetics/Reaction.cpp
Expand Up @@ -159,6 +159,10 @@ void Reaction::getParameters(AnyMap& reactionNode) const
}
}
}

if (m_third_body) {
m_third_body->getParameters(reactionNode);
}
}

void Reaction::setParameters(const AnyMap& node, const Kinetics& kin)
Expand Down Expand Up @@ -186,6 +190,10 @@ void Reaction::setParameters(const AnyMap& node, const Kinetics& kin)
duplicate = node.getBool("duplicate", false);
allow_negative_orders = node.getBool("negative-orders", false);
allow_nonreactant_orders = node.getBool("nonreactant-orders", false);

if (m_third_body) {
m_third_body->setParameters(node);
}
}

void Reaction::setRate(shared_ptr<ReactionRate> rate)
Expand Down Expand Up @@ -499,17 +507,42 @@ ThirdBody::ThirdBody(double default_eff)

ThirdBody::ThirdBody(const AnyMap& node)
{
setEfficiencies(node);
setParameters(node);
}

void ThirdBody::setEfficiencies(const AnyMap& node)
{
warn_deprecated("ThirdBody::setEfficiencies", node,
"To be removed after Cantera 3.0. Renamed to setParameters");
setParameters(node);
}

void ThirdBody::setParameters(const AnyMap& node)
{
if (specified_collision_partner) {
return;
}
default_efficiency = node.getDouble("default-efficiency", 1.0);
if (node.hasKey("efficiencies")) {
efficiencies = node["efficiencies"].asMap<double>();
}
}

void ThirdBody::getParameters(AnyMap& node) const
{
if (!specified_collision_partner) {
if (mass_action) {
// @todo remove once specialization is removed
node["type"] = "three-body";
}
node["efficiencies"] = efficiencies;
node["efficiencies"].setFlowStyle();
if (default_efficiency != 1.0) {
node["default-efficiency"] = default_efficiency;
}
}
}

double ThirdBody::efficiency(const std::string& k) const
{
return getValue(efficiencies, k, default_efficiency);
Expand Down Expand Up @@ -609,31 +642,6 @@ void ThreeBodyReaction::setEquation(const std::string& equation, const Kinetics*
products.erase("M");
}

void ThreeBodyReaction::setParameters(const AnyMap& node, const Kinetics& kin)
{
if (node.empty()) {
// empty node: used by newReaction() factory loader
return;
}
Reaction::setParameters(node, kin);
if (!m_third_body->specified_collision_partner) {
m_third_body->setEfficiencies(node);
}
}

void ThreeBodyReaction::getParameters(AnyMap& reactionNode) const
{
Reaction::getParameters(reactionNode);
if (!m_third_body->specified_collision_partner) {
reactionNode["type"] = "three-body";
reactionNode["efficiencies"] = m_third_body->efficiencies;
reactionNode["efficiencies"].setFlowStyle();
if (m_third_body->default_efficiency != 1.0) {
reactionNode["default-efficiency"] = m_third_body->default_efficiency;
}
}
}

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

void FalloffReaction::setParameters(const AnyMap& node, const Kinetics& kin)
{
if (node.empty()) {
// empty node: used by newReaction() factory loader
return;
}
Reaction::setParameters(node, kin);

if (!m_third_body->specified_collision_partner) {
m_third_body->setEfficiencies(node);
}
}

void FalloffReaction::setEquation(const std::string& equation, const Kinetics* kin)
{
Reaction::setEquation(equation, kin);
Expand Down Expand Up @@ -738,20 +733,6 @@ void FalloffReaction::setEquation(const std::string& equation, const Kinetics* k
}
}

void FalloffReaction::getParameters(AnyMap& reactionNode) const
{
Reaction::getParameters(reactionNode);
if (m_third_body->specified_collision_partner) {
// pass
} else if (m_third_body->efficiencies.size()) {
reactionNode["efficiencies"] = m_third_body->efficiencies;
reactionNode["efficiencies"].setFlowStyle();
if (m_third_body->default_efficiency != 1.0) {
reactionNode["default-efficiency"] = m_third_body->default_efficiency;
}
}
}

bool isThreeBody(const Reaction& R)
{
// detect explicitly specified collision partner
Expand Down

0 comments on commit 070e2f0

Please sign in to comment.