Skip to content

Commit

Permalink
[kinetics] make Arrhenius easy to implement and fix ETempRate
Browse files Browse the repository at this point in the history
  • Loading branch information
BangShiuh committed Dec 12, 2021
1 parent 197f787 commit 480bc06
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
3 changes: 3 additions & 0 deletions include/cantera/kinetics/Arrhenius.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ class ArrheniusBase : public ReactionRate
double m_b; //!< Temperature exponent
double m_Ea_R; //!< Activation energy (in temperature units)
double m_order; //!< Reaction order
std::string m_A_str = "A"; //!< The string for temperature exponent
std::string m_b_str = "b"; //!< The string for temperature exponent
std::string m_Ea_str = "Ea"; //!< The string for activation energy
Units m_rate_units; //!< Reaction rate units
};

Expand Down
35 changes: 18 additions & 17 deletions src/kinetics/Arrhenius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ void ArrheniusBase::setRateParameters(
if (m_rate_units.factor() == 0) {
// A zero rate units factor is used as a sentinel to detect
// stand-alone reaction rate objects
if (rate_map["A"].is<std::string>()) {
if (rate_map[m_A_str].is<std::string>()) {
throw InputFileError("Arrhenius::setRateParameters", rate_map,
"Specification of units is not supported for pre-exponential "
"factor when\ncreating a standalone 'ReactionRate' object.");
}
m_A = rate_map["A"].asDouble();
m_A = rate_map[m_A_str].asDouble();
} else {
m_A = units.convert(rate_map["A"], m_rate_units);
m_A = units.convert(rate_map[m_A_str], m_rate_units);
}
m_b = rate_map["b"].asDouble();
if (rate_map.hasKey("Ea")) {
m_Ea_R = units.convertActivationEnergy(rate_map["Ea"], "K");
m_b = rate_map[m_b_str].asDouble();
if (rate_map.hasKey(m_Ea_str)) {
m_Ea_R = units.convertActivationEnergy(rate_map[m_Ea_str], "K");
} else {
m_Ea_R = NAN;
}
Expand All @@ -82,16 +82,16 @@ void ArrheniusBase::getParameters(AnyMap& node, const Units& rate_units) const
// Return empty/unmodified AnyMap
return;
} else if (rate_units.factor() != 0.0) {
node["A"].setQuantity(m_A, rate_units);
node[m_A_str].setQuantity(m_A, rate_units);
} else {
node["A"] = m_A;
node[m_A_str] = m_A;
// This can't be converted to a different unit system because the dimensions of
// the rate constant were not set. Can occur if the reaction was created outside
// the context of a Kinetics object and never added to a Kinetics object.
node["__unconvertible__"] = true;
}
node["b"] = m_b;
node["Ea"].setQuantity(m_Ea_R, "K", true);
node[m_b_str] = m_b;
node[m_Ea_str].setQuantity(m_Ea_R, "K", true);

node.setFlowStyle();
}
Expand Down Expand Up @@ -137,15 +137,17 @@ void ArrheniusRate::getParameters(AnyMap& rateNode) const
}

ETempRate::ETempRate()
: m_EE_R(NAN)
: ArrheniusBase()
, m_EE_R(NAN)
{
m_Ea_str = "Ea_T";
}

ETempRate::ETempRate(double A, double b, double Ea, double EE)
: ArrheniusBase(A, b, Ea)
, m_EE_R(EE / GasConstant)
{

m_Ea_str = "Ea_T";
}

void ETempRate::setRateParameters(
Expand All @@ -164,7 +166,6 @@ void ETempRate::setRateParameters(
if (rate.is<AnyMap>()) {
ArrheniusBase::setRateParameters(rate, units, rate_units);
auto& rate_map = rate.as<AnyMap>();
m_Ea_R = units.convertActivationEnergy(rate_map["Ea_T"], "K");
m_EE_R = units.convertActivationEnergy(rate_map["Ea_Te"], "K");
} else {
setRateUnits(rate_units);
Expand Down Expand Up @@ -202,16 +203,19 @@ void ETempRate::getParameters(AnyMap& rateNode) const
}

BlowersMaselRate::BlowersMaselRate()
: m_w_R(NAN)
: ArrheniusBase()
, m_w_R(NAN)
, m_deltaH_R(NAN)
{
m_Ea_str = "Ea0";
}

BlowersMaselRate::BlowersMaselRate(double A, double b, double Ea0, double w)
: ArrheniusBase(A, b, Ea0)
, m_w_R(w / GasConstant)
, m_deltaH_R(NAN)
{
m_Ea_str = "Ea0";
}

void BlowersMaselRate::setRateParameters(
Expand All @@ -230,7 +234,6 @@ void BlowersMaselRate::setRateParameters(
if (rate.is<AnyMap>()) {
ArrheniusBase::setRateParameters(rate, units, rate_units);
auto& rate_map = rate.as<AnyMap>();
m_Ea_R = units.convertActivationEnergy(rate_map["Ea0"], "K");
m_w_R = units.convertActivationEnergy(rate_map["w"], "K");
} else {
setRateUnits(rate_units);
Expand Down Expand Up @@ -261,8 +264,6 @@ void BlowersMaselRate::getParameters(AnyMap& rateNode) const
ArrheniusBase::getParameters(node);
if (!node.empty()) {
// object is configured
node.erase("Ea");
node["Ea0"].setQuantity(m_Ea_R, "K", true);
node["w"].setQuantity(m_w_R, "K", true);
rateNode["rate-constant"] = std::move(node);
}
Expand Down

0 comments on commit 480bc06

Please sign in to comment.