diff --git a/include/cantera/kinetics/Reaction.h b/include/cantera/kinetics/Reaction.h index 9ee2b381e9..f19b3cf69d 100644 --- a/include/cantera/kinetics/Reaction.h +++ b/include/cantera/kinetics/Reaction.h @@ -122,7 +122,7 @@ class Reaction2 : public Reaction } //! Set up reaction based on AnyMap node - virtual void setup(const AnyMap& node, const Kinetics& kin); + virtual void setParameters(const AnyMap& node, const Kinetics& kin); protected: //! Reaction rate used by generic reactions @@ -281,7 +281,7 @@ class CustomFunc1Reaction : public Reaction2 public: CustomFunc1Reaction(); - virtual void setup(const AnyMap& node, const Kinetics& kin); + virtual void setParameters(const AnyMap& node, const Kinetics& kin); virtual std::string type() const { return "custom-rate-function"; @@ -306,7 +306,7 @@ class TestReaction : public Reaction2 return "elementary-new"; } - virtual void setup(const AnyMap& node, const Kinetics& kin); + virtual void setParameters(const AnyMap& node, const Kinetics& kin); bool allow_negative_pre_exponential_factor; }; diff --git a/include/cantera/kinetics/ReactionRate.h b/include/cantera/kinetics/ReactionRate.h index 927986f45b..52635465b8 100644 --- a/include/cantera/kinetics/ReactionRate.h +++ b/include/cantera/kinetics/ReactionRate.h @@ -86,11 +86,6 @@ class ReactionRate : public ReactionRateBase public: ReactionRate() = default; - ReactionRate(const AnyMap& node, const Units& rc_units) { - throw CanteraError("ReactionRate::ReactionRate", - "Constructor needs to be implemented by derived classes."); - } - //! Update information specific to reaction //! @param shared_data data shared by all reactions of a given type virtual void update(const DataType& shared_data, const ThermoPhase& bulk) {} @@ -148,8 +143,8 @@ class ArrheniusRate final : public ReactionRate, public Arrhenius //! Constructor //! @param node AnyMap object containing reaction rate specification - //! @param rc_units Description of units used for rate parameters - ArrheniusRate(const AnyMap& node, const Units& rc_units); + //! @param rate_units Description of units used for rate parameters + ArrheniusRate(const AnyMap& node, const Units& rate_units); virtual std::string type() const override { return "ArrheniusRate"; } @@ -182,8 +177,8 @@ class CustomFunc1Rate final : public ReactionRate //! Constructor does nothing, as there is no formalized parameterization //! @param node AnyMap object containing reaction rate specification - //! @param rc_units Description of units used for rate parameters - CustomFunc1Rate(const AnyMap& rate, const Units& rc_units) {} + //! @param rate_units Description of units used for rate parameters + CustomFunc1Rate(const AnyMap& rate, const Units& rate_units) {} virtual std::string type() const override { return "custom-function"; } diff --git a/include/cantera/kinetics/RxnRates.h b/include/cantera/kinetics/RxnRates.h index 1e0fbfcdae..7205eb6226 100644 --- a/include/cantera/kinetics/RxnRates.h +++ b/include/cantera/kinetics/RxnRates.h @@ -42,8 +42,8 @@ class Arrhenius Arrhenius(doublereal A, doublereal b, doublereal E); //! Run object setup based on AnyMap node information - void setup(const AnyValue& rate, - const UnitSystem& units, const Units& rc_units); + void setParameters(const AnyValue& rate, + const UnitSystem& units, const Units& rate_units); //! Update concentration-dependent parts of the rate coefficient. /*! diff --git a/src/kinetics/Reaction.cpp b/src/kinetics/Reaction.cpp index 7447250399..23b5047ba7 100644 --- a/src/kinetics/Reaction.cpp +++ b/src/kinetics/Reaction.cpp @@ -98,29 +98,6 @@ void Reaction::validate() } } -void Reaction2::setup(const AnyMap& node, const Kinetics& kin) -{ - parseReactionEquation(*this, node["equation"], kin); - // Non-stoichiometric reaction orders - std::map orders; - if (node.hasKey("orders")) { - for (const auto& order : node["orders"].asMap()) { - orders[order.first] = order.second; - if (kin.kineticsSpeciesIndex(order.first) == npos) { - setValid(false); - } - } - } - - // Flags - id = node.getString("id", ""); - duplicate = node.getBool("duplicate", false); - allow_negative_orders = node.getBool("negative-orders", false); - allow_nonreactant_orders = node.getBool("nonreactant-orders", false); - - input = node; -} - std::string Reaction::reactantString() const { std::ostringstream result; @@ -320,18 +297,41 @@ ChebyshevReaction::ChebyshevReaction(const Composition& reactants_, reaction_type = CHEBYSHEV_RXN; } +void Reaction2::setParameters(const AnyMap& node, const Kinetics& kin) +{ + parseReactionEquation(*this, node["equation"], kin); + // Non-stoichiometric reaction orders + std::map orders; + if (node.hasKey("orders")) { + for (const auto& order : node["orders"].asMap()) { + orders[order.first] = order.second; + if (kin.kineticsSpeciesIndex(order.first) == npos) { + setValid(false); + } + } + } + + // Flags + id = node.getString("id", ""); + duplicate = node.getBool("duplicate", false); + allow_negative_orders = node.getBool("negative-orders", false); + allow_nonreactant_orders = node.getBool("nonreactant-orders", false); + + input = node; +} + CustomFunc1Reaction::CustomFunc1Reaction() : Reaction2() { reaction_type = CUSTOMPY_RXN; } -void CustomFunc1Reaction::setup(const AnyMap& node, const Kinetics& kin) +void CustomFunc1Reaction::setParameters(const AnyMap& node, const Kinetics& kin) { - Reaction2::setup(node, kin); - Units rc_units; // @todo Not needed once `rate_units` is implemented. + Reaction2::setParameters(node, kin); + Units rate_units; // @todo Not needed once `rate_units` is implemented. setRate( - std::shared_ptr(new CustomFunc1Rate(node, rc_units))); + std::shared_ptr(new CustomFunc1Rate(node, rate_units))); } TestReaction::TestReaction() @@ -340,15 +340,15 @@ TestReaction::TestReaction() { } -void TestReaction::setup(const AnyMap& node, const Kinetics& kin) +void TestReaction::setParameters(const AnyMap& node, const Kinetics& kin) { - Reaction2::setup(node, kin); + Reaction2::setParameters(node, kin); // @todo Rate units will become available as `rate_units` after // serialization is fully implemented. - Units rc_units = rateCoeffUnits(*this, kin); + Units rate_units = rateCoeffUnits(*this, kin); setRate( - std::shared_ptr(new ArrheniusRate(node, rc_units))); + std::shared_ptr(new ArrheniusRate(node, rate_units))); allow_negative_pre_exponential_factor = node.getBool("negative-A", false); } @@ -434,9 +434,9 @@ Arrhenius readArrhenius(const Reaction& R, const AnyValue& rate, const Kinetics& kin, const UnitSystem& units, int pressure_dependence=0) { - Units rc_units = rateCoeffUnits(R, kin, pressure_dependence); + Units rate_units = rateCoeffUnits(R, kin, pressure_dependence); Arrhenius arr; - arr.setup(rate, units, rc_units); + arr.setParameters(rate, units, rate_units); return arr; } diff --git a/src/kinetics/ReactionFactory.cpp b/src/kinetics/ReactionFactory.cpp index 50861187f5..fa741741f6 100644 --- a/src/kinetics/ReactionFactory.cpp +++ b/src/kinetics/ReactionFactory.cpp @@ -105,7 +105,7 @@ ReactionFactory::ReactionFactory() }); reg_AnyMap("custom-rate-function", [](Reaction* R, const AnyMap& node, const Kinetics& kin) { - ((Reaction2*)R)->setup(node, kin); + ((Reaction2*)R)->setParameters(node, kin); }); // register custom Python reactions @@ -117,7 +117,7 @@ ReactionFactory::ReactionFactory() }); reg_AnyMap("elementary-new", [](Reaction* R, const AnyMap& node, const Kinetics& kin) { - (dynamic_cast(R))->setup(node, kin); + (dynamic_cast(R))->setParameters(node, kin); }); // register interface reactions diff --git a/src/kinetics/ReactionRate.cpp b/src/kinetics/ReactionRate.cpp index 38e897600d..29485704c9 100644 --- a/src/kinetics/ReactionRate.cpp +++ b/src/kinetics/ReactionRate.cpp @@ -14,8 +14,8 @@ ArrheniusRate::ArrheniusRate(double A, double b, double E) : Arrhenius(A, b, E) { } -ArrheniusRate::ArrheniusRate(const AnyMap& node, const Units& rc_units) { - setup(node["rate-constant"], node.units(), rc_units); +ArrheniusRate::ArrheniusRate(const AnyMap& node, const Units& rate_units) { + setParameters(node["rate-constant"], node.units(), rate_units); } CustomFunc1Rate::CustomFunc1Rate() : m_ratefunc(0) {} diff --git a/src/kinetics/RxnRates.cpp b/src/kinetics/RxnRates.cpp index 959ad86a1d..0b72288158 100644 --- a/src/kinetics/RxnRates.cpp +++ b/src/kinetics/RxnRates.cpp @@ -29,17 +29,17 @@ Arrhenius::Arrhenius(doublereal A, doublereal b, doublereal E) } } -void Arrhenius::setup(const AnyValue& rate, - const UnitSystem& units, const Units& rc_units) +void Arrhenius::setParameters(const AnyValue& rate, + const UnitSystem& units, const Units& rate_units) { if (rate.is()) { auto& rate_map = rate.as(); - m_A = units.convert(rate_map["A"], rc_units); + m_A = units.convert(rate_map["A"], rate_units); m_b = rate_map["b"].asDouble(); m_E = units.convertActivationEnergy(rate_map["Ea"], "K"); } else { auto& rate_vec = rate.asVector(3); - m_A = units.convert(rate_vec[0], rc_units); + m_A = units.convert(rate_vec[0], rate_units); m_b = rate_vec[1].asDouble(); m_E = units.convertActivationEnergy(rate_vec[2], "K"); }