Skip to content

Commit

Permalink
[Kinetics] Eliminate chained function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Feb 9, 2022
1 parent 6eb1e83 commit 5b58690
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
54 changes: 21 additions & 33 deletions include/cantera/kinetics/Arrhenius.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,29 @@ class Arrhenius3 : public ArrheniusBase
}

//! Evaluate reaction rate
//! @internal Non-virtual method that should not be overloaded
double evalRate(double logT, double recipT) const {
return m_A * std::exp(m_b * logT - m_Ea_R * recipT);
}

//! Evaluate natural logarithm of the rate constant.
//! @internal Non-virtual method that should not be overloaded
double evalLog(double logT, double recipT) const {
return m_logA + m_b * logT - m_Ea_R * recipT;
}

//! Evaluate reaction rate
double evalRate(const ArrheniusData& shared_data) const {
/*!
* @param shared_data data shared by all reactions of a given type
*/
double evalFromStruct(const ArrheniusData& shared_data) const {
return m_A * std::exp(m_b * shared_data.logT - m_Ea_R * shared_data.recipT);
}

//! Evaluate derivative of reaction rate with respect to temperature
//! divided by reaction rate
double ddTScaled(const ArrheniusData& shared_data) const {
/*!
* @param shared_data data shared by all reactions of a given type
*/
double ddTScaledFromStruct(const ArrheniusData& shared_data) const {
return (m_Ea_R * shared_data.recipT + m_b) * shared_data.recipT;
}
};
Expand Down Expand Up @@ -228,12 +232,13 @@ class TwoTempPlasma : public ArrheniusBase
return "two-temperature-plasma";
}

//! Context
virtual void setContext(const Reaction& rxn, const Kinetics& kin) override;

//! Evaluate reaction rate
//! @internal Non-virtual method that should not be overloaded
double evalRate(const TwoTempPlasmaData& shared_data) const {
/*!
* @param shared_data data shared by all reactions of a given type
*/
double evalFromStruct(const TwoTempPlasmaData& shared_data) const {
// m_E4_R is the electron activation (in temperature units)
return m_A * std::exp(m_b * shared_data.logTe -
m_Ea_R * shared_data.recipT +
Expand All @@ -246,9 +251,9 @@ class TwoTempPlasma : public ArrheniusBase
/*!
* This method does not consider changes of electron temperature.
* A corresponding warning is raised.
* @internal Non-virtual method that should not be overloaded
* @param shared_data data shared by all reactions of a given type
*/
double ddTScaled(const TwoTempPlasmaData& shared_data) const;
double ddTScaledFromStruct(const TwoTempPlasmaData& shared_data) const;

//! Return the electron activation energy *Ea* [J/kmol]
double activationElectronEnergy() const {
Expand Down Expand Up @@ -313,7 +318,6 @@ class BlowersMasel : public ArrheniusBase
return "Blowers-Masel";
}

//! Set context
virtual void setContext(const Reaction& rxn, const Kinetics& kin) override;

//! Update information specific to reaction
Expand All @@ -330,20 +334,21 @@ class BlowersMasel : public ArrheniusBase
}

//! Evaluate reaction rate
//! @internal Non-virtual method that should not be overloaded
double evalRate(const BlowersMaselData& shared_data) const {
/*!
* @param shared_data data shared by all reactions of a given type
*/
double evalFromStruct(const BlowersMaselData& shared_data) const {
double Ea_R = effectiveActivationEnergy_R(m_deltaH_R);
return m_A * std::exp(m_b * shared_data.logT - Ea_R * shared_data.recipT);
}

//! Evaluate derivative of reaction rate with respect to temperature
//! divided by reaction rate
/*!
* This method does not consider potential changes due to a changed reaction
* enthalpy. A corresponding warning is raised.
* @internal Non-virtual method that should not be overloaded
* @param shared_data data shared by all reactions of a given type
*/
double ddTScaled(const BlowersMaselData& shared_data) const;
double ddTScaledFromStruct(const BlowersMaselData& shared_data) const;

//! Return the effective activation energy (a function of the delta H of reaction)
//! divided by the gas constant (i.e. the activation temperature) [K]
Expand Down Expand Up @@ -384,7 +389,7 @@ class BlowersMasel : public ArrheniusBase

//! A class template for bulk phase reaction rate specifications
template <class RateType, class DataType>
class BulkRate final : public RateType
class BulkRate : public RateType
{
public:
BulkRate() = default;
Expand Down Expand Up @@ -425,23 +430,6 @@ class BulkRate final : public RateType
node["type"] = RateType::type();
}
}

//! Evaluate reaction rate
/*!
* @param shared_data data shared by all reactions of a given type
*/
double evalFromStruct(const DataType& shared_data) const {
return RateType::evalRate(shared_data);
}

//! Evaluate derivative of reaction rate with respect to temperature
//! divided by reaction rate
/*!
* @param shared_data data shared by all reactions of a given type
*/
double ddTScaledFromStruct(const DataType& shared_data) const {
return RateType::ddTScaled(shared_data);
}
};

typedef BulkRate<Arrhenius3, ArrheniusData> ArrheniusRate;
Expand Down
8 changes: 4 additions & 4 deletions src/kinetics/Arrhenius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ TwoTempPlasma::TwoTempPlasma(double A, double b, double Ea, double EE)
m_E4_R = EE / GasConstant;
}

double TwoTempPlasma::ddTScaled(const TwoTempPlasmaData& shared_data) const
double TwoTempPlasma::ddTScaledFromStruct(const TwoTempPlasmaData& shared_data) const
{
warn_user("TwoTempPlasma::ddTScaled",
warn_user("TwoTempPlasma::ddTScaledFromStruct",
"Temperature derivative does not consider changes of electron temperature.");
return (m_Ea_R - m_E4_R) * shared_data.recipT * shared_data.recipT;
}

void TwoTempPlasma::setContext(const Reaction& rxn, const Kinetics& kin)
{
// TwoTempPlasmaReaction is for a non-equilirium plasma, and the reverse rate
// TwoTempPlasmaReaction is for a non-equilibrium plasma, and the reverse rate
// cannot be calculated from the conventional thermochemistry.
// @todo implement the reversible rate for non-equilibrium plasma
if (rxn.reversible) {
Expand All @@ -175,7 +175,7 @@ BlowersMasel::BlowersMasel(double A, double b, double Ea0, double w)
m_E4_R = w / GasConstant;
}

double BlowersMasel::ddTScaled(const BlowersMaselData& shared_data) const
double BlowersMasel::ddTScaledFromStruct(const BlowersMaselData& shared_data) const
{
warn_user("BlowersMasel::ddTScaledFromStruct",
"Temperature derivative does not consider changes of reaction enthalpy.");
Expand Down

0 comments on commit 5b58690

Please sign in to comment.