Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Kinetics cleanup #1225

Merged
merged 7 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/cantera/base/ct_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const double ElectronMass = 9.1093837015e-31;
//! @{

//! Reduced Planck constant \f$ \hbar \f$ [m2-kg/s]
//! @deprecated Unused. To be removed after Cantera 2.6.
const double Planck_bar = Planck / (2 * Pi);

//! Universal Gas Constant \f$ R_u \f$ [J/kmol/K]
Expand All @@ -117,10 +118,11 @@ const double logGasConstant = std::log(GasConstant);
const double GasConst_cal_mol_K = GasConstant / 4184.0;

//! log(k_b/h)
//! @deprecated Unused. To be removed after Cantera 2.6.
const double logBoltz_Planck = std::log(Boltzmann / Planck);

//! Stefan-Boltzmann constant \f$ \sigma \f$ [W/m2/K4]
const double StefanBoltz = Pi * Pi * std::pow(Boltzmann, 4.0) / (60.0 * std::pow(Planck_bar, 3.0) * lightSpeed * lightSpeed); // 5.670374419e-8
const double StefanBoltz = 2.0 * std::pow(Pi, 5) * std::pow(Boltzmann, 4) / (15.0 * std::pow(Planck, 3) * lightSpeed * lightSpeed); // 5.670374419e-8

//! Faraday constant \f$ F \f$ [C/kmol]
const double Faraday = ElectronCharge * Avogadro;
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/base/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void suppress_thermo_warnings(bool suppress=true);
//! @copydoc Application::thermo_warnings_suppressed
bool thermo_warnings_suppressed();

//! @copydoc Application::suppress_user_warnings
//! @copydoc Application::suppress_warnings
void suppress_warnings();

//! @copydoc Application::warnings_suppressed
Expand Down
93 changes: 31 additions & 62 deletions include/cantera/kinetics/Arrhenius.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ namespace Cantera
class AnyValue;
class AnyMap;

//! Data container holding shared data specific to ArrheniusRate
/**
* The data container `ArrheniusData` holds precalculated data common to
* all `ArrheniusRate` objects.
*/
struct ArrheniusData : public ReactionData
{
virtual bool update(const ThermoPhase& phase, const Kinetics& kin);
using ReactionData::update;
};


/**
* @defgroup arrheniusGroup Arrhenius-type Parameterizations
*
Expand Down Expand Up @@ -58,6 +70,12 @@ class ArrheniusBase : public ReactionRate
setRateParameters(rate, units, rate_units);
}

explicit ArrheniusBase(const AnyMap& node, const UnitStack& rate_units={})
: ArrheniusBase()
{
setParameters(node, rate_units);
}

//! Perform object setup based on AnyValue node information
/*!
* @param rate AnyValue containing rate information
Expand All @@ -71,9 +89,16 @@ class ArrheniusBase : public ReactionRate
//! Return parameters
void getRateParameters(AnyMap& node) const;

virtual void setParameters(
const AnyMap& node, const UnitStack& rate_units) override;

virtual void getParameters(AnyMap& node) const override;

//! Check rate expression
virtual void check(const std::string& equation, const AnyMap& node) override;

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

//! Return the pre-exponential factor *A* (in m, kmol, s to powers depending
//! on the reaction order)
/*!
Expand Down Expand Up @@ -149,17 +174,6 @@ class ArrheniusBase : public ReactionRate
Units m_rate_units; //!< Reaction rate units
};

//! Data container holding shared data specific to ArrheniusRate
/**
* The data container `ArrheniusData` holds precalculated data common to
* all `ArrheniusRate` objects.
*/
struct ArrheniusData : public ReactionData
{
virtual bool update(const ThermoPhase& phase, const Kinetics& kin);
using ReactionData::update;
};

//! Arrhenius reaction rate type depends only on temperature
/*!
* A reaction rate coefficient of the following form.
Expand All @@ -170,16 +184,19 @@ struct ArrheniusData : public ReactionData
*
* @ingroup arrheniusGroup
*
* @todo supersedes Arrhenius2 and will replace Arrhenius(2) after Cantera 2.6,
* The class should be renamed to Arrhenius after removal of Arrhenius2. The new
* @todo supersedes Arrhenius2 and will replace Arrhenius after Cantera 2.6. The new
* behavior can be forced in self-compiled Cantera installations by defining
* CT_NO_LEGACY_REACTIONS_26 via the 'no_legacy_reactions' option in SCons.
*/
class Arrhenius3 : public ArrheniusBase
class ArrheniusRate : public ArrheniusBase
{
public:
using ArrheniusBase::ArrheniusBase; // inherit constructors

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<ArrheniusRate, ArrheniusData>);
}

virtual const std::string type() const override {
return "Arrhenius";
}
Expand Down Expand Up @@ -212,54 +229,6 @@ class Arrhenius3 : public ArrheniusBase
}
};


//! A class template for bulk phase reaction rate specifications
template <class RateType, class DataType>
class BulkRate : public RateType
{
public:
BulkRate() = default;
using RateType::RateType; // inherit constructors

//! Constructor based on AnyMap content
BulkRate(const AnyMap& node, const UnitStack& rate_units={}) {
setParameters(node, rate_units);
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(
new MultiRate<BulkRate<RateType, DataType>, DataType>);
}

virtual void setParameters(
const AnyMap& node, const UnitStack& rate_units) override
{
RateType::m_negativeA_ok = node.getBool("negative-A", false);
if (!node.hasKey("rate-constant")) {
RateType::setRateParameters(AnyValue(), node.units(), rate_units);
return;
}
RateType::setRateParameters(node["rate-constant"], node.units(), rate_units);
}

virtual void getParameters(AnyMap& node) const override {
if (RateType::m_negativeA_ok) {
node["negative-A"] = true;
}
AnyMap rateNode;
RateType::getRateParameters(rateNode);
if (!rateNode.empty()) {
// RateType object is configured
node["rate-constant"] = std::move(rateNode);
}
if (RateType::type() != "Arrhenius") {
node["type"] = RateType::type();
}
}
};

typedef BulkRate<Arrhenius3, ArrheniusData> ArrheniusRate;

}

#endif
18 changes: 13 additions & 5 deletions include/cantera/kinetics/BlowersMaselRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ struct BlowersMaselData : public ReactionData
*
* @ingroup arrheniusGroup
*/
class BlowersMasel : public ArrheniusBase
class BlowersMaselRate : public ArrheniusBase
{
public:
//! Default constructor.
BlowersMasel();
BlowersMaselRate();

//! Constructor.
/*!
Expand All @@ -82,7 +82,17 @@ class BlowersMasel : public ArrheniusBase
* @param w Average bond dissociation energy of the bond being formed and
* broken in the reaction, in energy units [J/kmol]
*/
BlowersMasel(double A, double b, double Ea0, double w);
BlowersMaselRate(double A, double b, double Ea0, double w);

explicit BlowersMaselRate(const AnyMap& node, const UnitStack& rate_units={})
: BlowersMaselRate()
{
setParameters(node, rate_units);
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<BlowersMaselRate, BlowersMaselData>);
}

virtual const std::string type() const override {
return "Blowers-Masel";
Expand Down Expand Up @@ -177,8 +187,6 @@ class BlowersMasel : public ArrheniusBase
double m_deltaH_R; //!< enthalpy change of reaction (in temperature units)
};

typedef BulkRate<BlowersMasel, BlowersMaselData> BlowersMaselRate;

}

#endif
2 changes: 2 additions & 0 deletions include/cantera/kinetics/ChebyshevRate.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class ChebyshevRate final : public ReactionRate
}
void getParameters(AnyMap& rateNode) const;

virtual void validate(const std::string& equation, const Kinetics& kin);

//! Update information specific to reaction
/*!
* @param shared_data data shared by all reactions of a given type
Expand Down
2 changes: 2 additions & 0 deletions include/cantera/kinetics/Custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CustomFunc1Rate final : public ReactionRate
void getParameters(AnyMap& rateNode, const Units& rate_units=Units(0.)) const;
using ReactionRate::getParameters;

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

//! Update information specific to reaction
/*!
* @param shared_data data shared by all reactions of a given type
Expand Down
21 changes: 11 additions & 10 deletions include/cantera/kinetics/Falloff.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class FalloffRate : public ReactionRate
}

void check(const std::string& equation, const AnyMap& node);
virtual void validate(const std::string& equation, const Kinetics& kin);

//! Get flag indicating whether negative A values are permitted
bool allowNegativePreExponentialFactor() const {
Expand All @@ -237,24 +238,24 @@ class FalloffRate : public ReactionRate
}

//! Get reaction rate in the low-pressure limit
Arrhenius3& lowRate() {
ArrheniusRate& lowRate() {
return m_lowRate;
}

//! Set reaction rate in the low-pressure limit
void setLowRate(const Arrhenius3& low);
void setLowRate(const ArrheniusRate& low);

//! Get reaction rate in the high-pressure limit
Arrhenius3& highRate() {
ArrheniusRate& highRate() {
return m_highRate;
}

//! Set reaction rate in the high-pressure limit
void setHighRate(const Arrhenius3& high);
void setHighRate(const ArrheniusRate& high);

protected:
Arrhenius3 m_lowRate; //!< The reaction rate in the low-pressure limit
Arrhenius3 m_highRate; //!< The reaction rate in the high-pressure limit
ArrheniusRate m_lowRate; //!< The reaction rate in the low-pressure limit
ArrheniusRate m_highRate; //!< The reaction rate in the high-pressure limit

bool m_chemicallyActivated; //!< Flag labeling reaction as chemically activated
bool m_negativeA_ok; //!< Flag indicating whether negative A values are permitted
Expand Down Expand Up @@ -283,7 +284,7 @@ class LindemannRate final : public FalloffRate
}

LindemannRate(
const Arrhenius3& low, const Arrhenius3& high, const vector_fp& c)
const ArrheniusRate& low, const ArrheniusRate& high, const vector_fp& c)
: LindemannRate()
{
m_lowRate = low;
Expand Down Expand Up @@ -344,7 +345,7 @@ class TroeRate final : public FalloffRate
setParameters(node, rate_units);
}

TroeRate(const Arrhenius3& low, const Arrhenius3& high, const vector_fp& c)
TroeRate(const ArrheniusRate& low, const ArrheniusRate& high, const vector_fp& c)
: TroeRate()
{
m_lowRate = low;
Expand Down Expand Up @@ -446,7 +447,7 @@ class SriRate final : public FalloffRate
setParameters(node, rate_units);
}

SriRate(const Arrhenius3& low, const Arrhenius3& high, const vector_fp& c)
SriRate(const ArrheniusRate& low, const ArrheniusRate& high, const vector_fp& c)
: SriRate()
{
m_lowRate = low;
Expand Down Expand Up @@ -556,7 +557,7 @@ class TsangRate final : public FalloffRate
setParameters(node, rate_units);
}

TsangRate(const Arrhenius3& low, const Arrhenius3& high, const vector_fp& c)
TsangRate(const ArrheniusRate& low, const ArrheniusRate& high, const vector_fp& c)
: TsangRate()
{
m_lowRate = low;
Expand Down
Loading