Skip to content

Commit

Permalink
[Kinetics] mark unused reaction type magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Mar 19, 2021
1 parent 20be280 commit fe29554
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
7 changes: 7 additions & 0 deletions include/cantera/kinetics/Kinetics.h
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ class Kinetics
*/
virtual int reactionType(size_t i) const;

/**
* String specifying the type of reaction.
*
* @param i reaction index
*/
virtual std::string reactionTypeStr(size_t i) const;

/**
* True if reaction i has been declared to be reversible. If isReversible(i)
* is false, then the reverse rate of progress for reaction i is always
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/test/test_kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_multiplier(self):

def test_reaction_type(self):
self.assertNear(self.phase.reaction_type(0), 2) # 3rd body
self.assertNear(self.phase.reaction_type(2), 1) # elementary
#self.assertNear(self.phase.reaction_type(2), 1) # elementary
self.assertNear(self.phase.reaction_type(20), 4) # falloff

with self.assertRaisesRegex(ValueError, 'out of range'):
Expand Down
3 changes: 3 additions & 0 deletions src/kinetics/Kinetics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ int Kinetics::reactionType(size_t i) const {
return m_reactions[i]->reaction_type;
}

std::string Kinetics::reactionTypeStr(size_t i) const {
return m_reactions[i]->type();
}

std::string Kinetics::reactionString(size_t i) const
{
Expand Down
26 changes: 12 additions & 14 deletions src/kinetics/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ std::string Reaction::equation() const
ElementaryReaction::ElementaryReaction(const Composition& reactants_,
const Composition products_,
const Arrhenius& rate_)
: Reaction(ELEMENTARY_RXN, reactants_, products_)
: Reaction(UNUSED_MAGIC_NUMBER, reactants_, products_)
, rate(rate_)
, allow_negative_pre_exponential_factor(false)
{
}

ElementaryReaction::ElementaryReaction()
: Reaction(ELEMENTARY_RXN)
: Reaction()
, allow_negative_pre_exponential_factor(false)
{
}
Expand Down Expand Up @@ -233,7 +233,7 @@ void FalloffReaction::validate() {

ChemicallyActivatedReaction::ChemicallyActivatedReaction()
{
reaction_type = CHEMACT_RXN;
reaction_type = UNUSED_MAGIC_NUMBER;
}

ChemicallyActivatedReaction::ChemicallyActivatedReaction(
Expand All @@ -242,43 +242,43 @@ ChemicallyActivatedReaction::ChemicallyActivatedReaction(
const ThirdBody& tbody)
: FalloffReaction(reactants_, products_, low_rate_, high_rate_, tbody)
{
reaction_type = CHEMACT_RXN;
reaction_type = UNUSED_MAGIC_NUMBER;
}

PlogReaction::PlogReaction()
: Reaction(PLOG_RXN)
: Reaction()
{
}

PlogReaction::PlogReaction(const Composition& reactants_,
const Composition& products_, const Plog& rate_)
: Reaction(PLOG_RXN, reactants_, products_)
: Reaction(UNUSED_MAGIC_NUMBER, reactants_, products_)
, rate(rate_)
{
}

ChebyshevReaction::ChebyshevReaction()
: Reaction(CHEBYSHEV_RXN)
: Reaction()
{
}

ChebyshevReaction::ChebyshevReaction(const Composition& reactants_,
const Composition& products_,
const ChebyshevRate& rate_)
: Reaction(CHEBYSHEV_RXN, reactants_, products_)
: Reaction(UNUSED_MAGIC_NUMBER, reactants_, products_)
, rate(rate_)
{
}

CustomPyReaction::CustomPyReaction()
: Reaction(CUSTOMPY_RXN)
: Reaction()
{
}

CustomPyReaction::CustomPyReaction(const Composition& reactants_,
const Composition& products_,
const CustomPyRate& rate_)
: Reaction(CUSTOMPY_RXN, reactants_, products_)
: Reaction(UNUSED_MAGIC_NUMBER, reactants_, products_)
, rate(rate_)
{
}
Expand All @@ -287,7 +287,7 @@ InterfaceReaction::InterfaceReaction()
: is_sticking_coefficient(false)
, use_motz_wise_correction(false)
{
reaction_type = INTERFACE_RXN;
reaction_type = UNUSED_MAGIC_NUMBER;
}

InterfaceReaction::InterfaceReaction(const Composition& reactants_,
Expand All @@ -298,7 +298,7 @@ InterfaceReaction::InterfaceReaction(const Composition& reactants_,
, is_sticking_coefficient(isStick)
, use_motz_wise_correction(false)
{
reaction_type = INTERFACE_RXN;
reaction_type = UNUSED_MAGIC_NUMBER;
}

ElectrochemicalReaction::ElectrochemicalReaction()
Expand Down Expand Up @@ -534,7 +534,6 @@ void parseReactionEquation(Reaction& R, const AnyValue& equation,
}
if (kin.kineticsSpeciesIndex(species) == npos
&& stoich != -1 && species != "M") {
R.reaction_type = INVALID_RXN;
R.set_valid(false);
}

Expand Down Expand Up @@ -567,7 +566,6 @@ void setupReaction(Reaction& R, const AnyMap& node, const Kinetics& kin)
for (const auto& order : node["orders"].asMap<double>()) {
R.orders[order.first] = order.second;
if (kin.kineticsSpeciesIndex(order.first) == npos) {
R.reaction_type = INVALID_RXN;
R.set_valid(false);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/kinetics/ReactionPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,9 +680,9 @@ string reactionLabel(size_t i, size_t kr, size_t nr,
label += " + "+ s.kineticsSpeciesName(slist[j]);
}
}
if (s.reactionType(i) == THREE_BODY_RXN) {
if (s.reactionTypeStr(i) == "three-body") {
label += " + M ";
} else if (s.reactionType(i) == FALLOFF_RXN) {
} else if (s.reactionTypeStr(i) == "falloff") {
label += " (+ M)";
}
return label;
Expand Down Expand Up @@ -735,9 +735,9 @@ int ReactionPathBuilder::build(Kinetics& s, const string& element,
revlabel += " + "+ s.kineticsSpeciesName(m_prod[i][j]);
}
}
if (s.reactionType(i) == THREE_BODY_RXN) {
if (s.reactionTypeStr(i) == "three-body") {
revlabel += " + M ";
} else if (s.reactionType(i) == FALLOFF_RXN) {
} else if (s.reactionTypeStr(i) == "falloff") {
revlabel += " (+ M)";
}

Expand Down
3 changes: 2 additions & 1 deletion test/kinetics/kineticsFromYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST(Reaction, ElementaryFromYaml)
auto R = newReaction(rxn, *(sol->kinetics()));
EXPECT_EQ(R->reactants.at("NO"), 1);
EXPECT_EQ(R->products.at("N2"), 1);
EXPECT_EQ(R->reaction_type, ELEMENTARY_RXN);
EXPECT_EQ(R->type(), "elementary");

auto ER = dynamic_cast<ElementaryReaction&>(*R);
EXPECT_DOUBLE_EQ(ER.rate.preExponentialFactor(), -2.7e10);
Expand All @@ -40,6 +40,7 @@ TEST(Reaction, ThreeBodyFromYaml1)

auto R = newReaction(rxn, *(sol->kinetics()));
EXPECT_EQ(R->reactants.count("M"), (size_t) 0);
EXPECT_EQ(R->type(), "three-body");

auto TBR = dynamic_cast<ThreeBodyReaction&>(*R);
EXPECT_DOUBLE_EQ(TBR.rate.preExponentialFactor(), 1.2e11);
Expand Down

0 comments on commit fe29554

Please sign in to comment.