Skip to content

Commit

Permalink
[Kinetics] Simplify reaction rate unit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Oct 8, 2021
1 parent 230c367 commit 5deeade
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 143 deletions.
40 changes: 28 additions & 12 deletions include/cantera/kinetics/Arrhenius.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ArrheniusBase

//! Constructor based on AnyValue content
ArrheniusBase(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units)
const UnitSystem& units, const UnitsVector& rate_units)
{
setParameters(rate, units, rate_units);
}
Expand All @@ -56,11 +56,13 @@ class ArrheniusBase
* @param rate_units Unit definitions specific to rate information
*/
virtual void setParameters(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units);
const UnitSystem& units, const UnitsVector& rate_units);

//! Get parameters
//! Store the parameters of a ReactionRate needed to reconstruct an identical
virtual void getParameters(AnyMap& node, const Units& units) const;
//! Return parameters
/*!
* @param node AnyValue containing rate information
*/
virtual void getParameters(AnyMap& node) const;

//! Validate the reaction rate expression
virtual void validate(const std::string& equation);
Expand All @@ -87,10 +89,24 @@ class ArrheniusBase

size_t rate_index; //!< Reaction rate index within kinetics evaluator

void setRateUnits(const UnitsVector& rate_units) {
m_rate_units = Units::product(rate_units);
if (rate_units.size()>1) {
m_order = 0;
for (size_t i = 2; i < rate_units.size(); ++i) {
m_order -= rate_units[i].second;
}
} else {
m_order = NAN;
}
}

protected:
double m_A; //!< Pre-exponential factor
double m_b; //!< Temperature exponent
double m_Ea_R; //!< Activation energy (in temperature units)
double m_order; //!< Reaction order
Units m_rate_units; //!< Reaction rate units
};


Expand All @@ -115,7 +131,7 @@ class Arrhenius3 : public ArrheniusBase
using ArrheniusBase::setParameters;

//! Constructor based on AnyMap content
Arrhenius3(const AnyMap& node, const Units& rate_units) {
Arrhenius3(const AnyMap& node, const UnitsVector& rate_units) {
setParameters(node, rate_units);
}

Expand All @@ -129,9 +145,9 @@ class Arrhenius3 : public ArrheniusBase
* @param node AnyMap containing rate information
* @param rate_units Unit definitions specific to rate information
*/
virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

virtual void getParameters(AnyMap& node, const Units& units) const;
virtual void getParameters(AnyMap& node) const;

//! Update information specific to reaction
const static bool usesUpdate() {
Expand Down Expand Up @@ -219,7 +235,7 @@ class BlowersMasel3 : public ArrheniusBase
BlowersMasel3(double A, double b, double Ea0, double w);

//! Constructor based on AnyMap content
BlowersMasel3(const AnyMap& node, const Units& rate_units) {
BlowersMasel3(const AnyMap& node, const UnitsVector& rate_units) {
setParameters(node, rate_units);
}

Expand All @@ -229,16 +245,16 @@ class BlowersMasel3 : public ArrheniusBase
}

virtual void setParameters(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units);
const UnitSystem& units, const UnitsVector& rate_units);

//! Perform object setup based on AnyMap node information
/*!
* @param node AnyMap containing rate information
* @param rate_units Unit definitions specific to rate information
*/
virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

virtual void getParameters(AnyMap& node, const Units& units) const;
virtual void getParameters(AnyMap& node) const;

//! Update information specific to reaction
const static bool usesUpdate() {
Expand Down
21 changes: 5 additions & 16 deletions include/cantera/kinetics/Falloff.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Falloff
//! Perform object setup based on AnyMap node information
//! @param node AnyMap containing rate information
//! @param rate_units unit definitions specific to rate information
virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

//! Get the values of the parameters for this object. *params* must be an
//! array of at least nParameters() elements.
Expand All @@ -141,14 +141,9 @@ class Falloff
*/
virtual void getParameters(double* params) const {}

/**
* @todo deprecate; only used by legacy framework
*/
virtual void getParameters(AnyMap& reactionNode) const {}

//! Store the falloff-related parameters needed to reconstruct an identical
//! Reaction using the newReaction(AnyMap&, Kinetics&) function.
virtual void getParameters(AnyMap& rateNode, const Units& rate_units) const;
virtual void getParameters(AnyMap& reactionNode) const;

//! Flag indicating that information specific to reaction rate is required
const static bool usesUpdate() {
Expand Down Expand Up @@ -315,7 +310,7 @@ class Troe : public Falloff
return 4;
}

virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

//! Sets params to contain, in order, \f[ (A, T_3, T_1, T_2) \f]
/**
Expand All @@ -325,8 +320,6 @@ class Troe : public Falloff

virtual void getParameters(AnyMap& reactionNode) const;

virtual void getParameters(AnyMap& rateNode, const Units& rate_units) const;

protected:
//! parameter a in the 4-parameter Troe falloff function. Dimensionless
double m_a;
Expand Down Expand Up @@ -402,7 +395,7 @@ class SRI : public Falloff
return 5;
}

virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

//! Sets params to contain, in order, \f[ (a, b, c, d, e) \f]
/**
Expand All @@ -412,8 +405,6 @@ class SRI : public Falloff

virtual void getParameters(AnyMap& reactionNode) const;

virtual void getParameters(AnyMap& rateNode, const Units& rate_units) const;

protected:
//! parameter a in the 5-parameter SRI falloff function. Dimensionless.
double m_a;
Expand Down Expand Up @@ -495,7 +486,7 @@ class Tsang : public Falloff
return 2;
}

virtual void setParameters(const AnyMap& node, const Units& rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& rate_units);

//! Sets params to contain, in order, \f[ (A, B) \f]
/**
Expand All @@ -505,8 +496,6 @@ class Tsang : public Falloff

virtual void getParameters(AnyMap& reactionNode) const;

virtual void getParameters(AnyMap& rateNode, const Units& rate_units) const;

protected:
//! parameter a in the Tsang F_cent formulation. Dimensionless
double m_a;
Expand Down
43 changes: 22 additions & 21 deletions include/cantera/kinetics/ReactionRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,22 @@ class RateTemplate : public ReactionRate<DataType>, public RateType
//! Constructor using AnyMap content
//! @param node AnyMap containing rate information
//! @param rate_units unit definitions used for rate information
RateTemplate(const AnyMap& node, const Units& rate_units=Units(0.)) {
setParameters(node, rate_units);
RateTemplate(const AnyMap& node, const UnitsVector& units={}) {
setParameters(node, units);
}

virtual const std::string type() const override {
// need to be explicitly included due to multiple inheritance
return RateType::type();
}

virtual void setParameters(const AnyMap& node, const Units& rate_units) override {
ReactionRateBase::setParameters(node, rate_units);
RateType::setParameters(node, rate_units);
virtual void setParameters(const AnyMap& node, const UnitsVector& units) override {
ReactionRateBase::setParameters(node, units);
RateType::setParameters(node, units);
}

virtual void getParameters(AnyMap& node, const Units& rate_units) const override {
RateType::getParameters(node, rate_units);
virtual void getParameters(AnyMap& node) const override {
RateType::getParameters(node);
}

virtual unique_ptr<MultiRateBase> newMultiRate() const override {
Expand Down Expand Up @@ -240,18 +240,17 @@ class PlogRate final : public ReactionRate<PlogData>, public Plog

//! Constructor using AnyMap content
//! @param node AnyMap containing rate information
//! @param rate_units unit definitions used for rate information
PlogRate(const AnyMap& node, const Units& rate_units=Units(0.));
//! @param units Description of units used for rate parameters
PlogRate(const AnyMap& node, const UnitsVector& units={});

virtual const std::string type() const override {
return "pressure-dependent-Arrhenius";
}

virtual unique_ptr<MultiRateBase> newMultiRate() const override;

virtual void setParameters(const AnyMap& node, const Units& rate_units) override;
virtual void getParameters(AnyMap& rateNode,
const Units& rate_units) const override;
virtual void setParameters(const AnyMap& node, const UnitsVector& units) override;
virtual void getParameters(AnyMap& rateNode) const override;

//! Update information specific to reaction
static bool usesUpdate() { return true; }
Expand Down Expand Up @@ -324,16 +323,15 @@ class ChebyshevRate3 final : public ReactionRate<ChebyshevData>, public Chebyshe

//! Constructor using AnyMap content
//! @param node AnyMap containing rate information
//! @param rate_units unit definitions used for rate information
ChebyshevRate3(const AnyMap& node, const Units& rate_units=Units(0.));
//! @param units Description of units used for rate parameters
ChebyshevRate3(const AnyMap& node, const UnitsVector& rate_units={});

virtual const std::string type() const override { return "Chebyshev"; }

virtual unique_ptr<MultiRateBase> newMultiRate() const override;

virtual void setParameters(const AnyMap& node, const Units& rate_units) override;
virtual void getParameters(AnyMap& rateNode,
const Units& rate_units) const override;
virtual void setParameters(const AnyMap& node, const UnitsVector& units) override;
virtual void getParameters(AnyMap& rateNode) const override;

//! Update information specific to reaction
static bool usesUpdate() { return true; }
Expand All @@ -347,6 +345,9 @@ class ChebyshevRate3 final : public ReactionRate<ChebyshevData>, public Chebyshe
}

virtual void validate(const std::string& equation) override;

protected:
Units m_rate_units; //!< Reaction rate units
};


Expand All @@ -366,15 +367,15 @@ class CustomFunc1Rate final : public ReactionRate<CustomFunc1Data>

//! Constructor does nothing, as there is no formalized parameterization
//! @param node AnyMap object containing reaction rate specification
//! @param rate_units Description of units used for rate parameters
CustomFunc1Rate(const AnyMap& rate, const Units& rate_units) {}
//! @param units Description of units used for rate parameters
CustomFunc1Rate(const AnyMap& rate, const UnitsVector& units) {}

virtual const std::string type() const override { return "custom-rate-function"; }

virtual unique_ptr<MultiRateBase> newMultiRate() const override;

virtual void setParameters(const AnyMap& node, const Units& rate_units) override {
units = rate_units;
virtual void setParameters(const AnyMap& node, const UnitsVector& units) override {
ReactionRateBase::setParameters(node, units);
}

//! Update information specific to reaction
Expand Down
29 changes: 5 additions & 24 deletions include/cantera/kinetics/ReactionRateBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Kinetics;
class ReactionRateBase
{
public:
ReactionRateBase() : units(0.), m_idx(npos) {}
ReactionRateBase() : m_idx(npos) {}
virtual ~ReactionRateBase() {}

public:
Expand Down Expand Up @@ -94,32 +94,18 @@ class ReactionRateBase
//! Return the parameters such that an identical Reaction could be reconstructed
//! using the newReaction() function. Behavior specific to derived classes is
//! handled by the getParameters() method.
//! @param rate_units units used for rate parameters
AnyMap parameters(const Units& rate_units) const {
AnyMap parameters() const {
AnyMap out;
getParameters(out, rate_units);
getParameters(out);
return out;
}

//! Return parameters using original unit system
AnyMap parameters() const {
return parameters(units);
}

//! Set parameters
//! @param node AnyMap object containing reaction rate specification
//! @param rate_units Description of units used for rate parameters
virtual void setParameters(const AnyMap& node, const Units& rate_units) {
units = rate_units;
virtual void setParameters(const AnyMap& node, const UnitsVector& units) {
input = node;
}

//! Set rate units
//! @param rate_units Description of units used for rate parameters
virtual void setUnits(const Units& rate_units) {
units = rate_units;
}

//! Reaction rate index within kinetics evaluator
size_t rateIndex() const {
return m_idx;
Expand All @@ -134,19 +120,14 @@ class ReactionRateBase
//! Get parameters
//! Store the parameters of a ReactionRate needed to reconstruct an identical
//! object. Does not include user-defined fields available in the #input map.
virtual void getParameters(AnyMap& rateNode, const Units& rate_units) const {
virtual void getParameters(AnyMap& rateNode) const {
throw NotImplementedError("ReactionRate::getParameters",
"Not implemented by '{}' object.", type());
}

//! Input data used for specific models
AnyMap input;

//! The units of the rate constant. These are determined by the units of the
//! standard concentration of the reactant species' phases of the phase
//! where the reaction occurs.
Units units;

size_t m_idx; //!< Index of reaction rate within kinetics evaluator
};

Expand Down
7 changes: 5 additions & 2 deletions include/cantera/kinetics/RxnRates.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Units;
* k_f = A T^b \exp (-E/RT)
* \f]
*/
class Arrhenius2 : public ArrheniusBase
class Arrhenius2 final : public ArrheniusBase
{
public:
//! Default constructor.
Expand All @@ -55,6 +55,9 @@ class Arrhenius2 : public ArrheniusBase
void setParameters(const AnyValue& rate,
const UnitSystem& units, const Units& rate_units);

using ArrheniusBase::getParameters;
void getParameters(AnyMap& node, const Units& rate_units) const;

//! Update concentration-dependent parts of the rate coefficient.
/*!
* For this class, there are no concentration-dependent parts, so this
Expand Down Expand Up @@ -335,7 +338,7 @@ class Plog
void setParameters(const std::vector<AnyMap>& rates,
const UnitSystem& units, const Units& rate_units);

void getParameters(AnyMap& rateNode, const Units& rate_units) const;
void getParameters(AnyMap& rateNode, const Units& rate_units=Units(0.)) const;

//! Set up Plog object
/*!
Expand Down
Loading

0 comments on commit 5deeade

Please sign in to comment.