Cantera  3.0.0
Loading...
Searching...
No Matches
Arrhenius.cpp
Go to the documentation of this file.
1//! @file Arrhenius.cpp
2
3// This file is part of Cantera. See License.txt in the top-level directory or
4// at https://cantera.org/license.txt for license and copyright information.
5
8
9namespace Cantera
10{
11
12ArrheniusBase::ArrheniusBase(double A, double b, double Ea)
13 : m_A(A)
14 , m_b(b)
15 , m_Ea_R(Ea / GasConstant)
16{
17 if (m_A > 0.0) {
18 m_logA = std::log(m_A);
19 }
20 m_valid = true;
21}
22
24 const UnitStack& rate_units)
25{
26 setRateUnits(rate_units);
27 setRateParameters(rate, units, rate_units);
28}
29
30ArrheniusBase::ArrheniusBase(const AnyMap& node, const UnitStack& rate_units)
31{
32 setParameters(node, rate_units);
33}
34
36 const AnyValue& rate, const UnitSystem& units, const UnitStack& rate_units)
37{
38 m_Ea_R = 0.; // assume zero if not provided
39 m_E4_R = 0.; // assume zero if not provided
40 if (rate.empty()) {
41 m_A = NAN;
42 m_b = NAN;
43 m_logA = NAN;
45 return;
46 }
47
48 if (rate.is<AnyMap>()) {
49
50 auto& rate_map = rate.as<AnyMap>();
51 m_A = units.convertRateCoeff(rate_map[m_A_str], conversionUnits());
52 m_b = rate_map[m_b_str].asDouble();
53 if (rate_map.hasKey(m_Ea_str)) {
54 m_Ea_R = units.convertActivationEnergy(rate_map[m_Ea_str], "K");
55 }
56 if (rate_map.hasKey(m_E4_str)) {
57 m_E4_R = units.convertActivationEnergy(rate_map[m_E4_str], "K");
58 }
59 } else {
60 auto& rate_vec = rate.asVector<AnyValue>(2, 4);
61 m_A = units.convertRateCoeff(rate_vec[0], conversionUnits());
62 m_b = rate_vec[1].asDouble();
63 if (rate_vec.size() > 2) {
64 m_Ea_R = units.convertActivationEnergy(rate_vec[2], "K");
65 }
66 if (rate_vec.size() > 3) {
67 m_E4_R = units.convertActivationEnergy(rate_vec[3], "K");
68 }
69 }
70 if (m_A > 0.0) {
71 m_logA = std::log(m_A);
72 }
73 m_valid = true;
74}
75
77{
78 if (!valid()) {
79 // Return empty/unmodified AnyMap
80 return;
81 }
82
83 if (conversionUnits().factor() != 0.0) {
84 node[m_A_str].setQuantity(m_A, conversionUnits());
85 } else {
86 node[m_A_str] = m_A;
87 // This can't be converted to a different unit system because the dimensions of
88 // the rate constant were not set. Can occur if the reaction was created outside
89 // the context of a Kinetics object and never added to a Kinetics object.
90 node["__unconvertible__"] = true;
91 }
92 node[m_b_str] = m_b;
93 node[m_Ea_str].setQuantity(m_Ea_R, "K", true);
94 if (m_E4_str != "") {
95 node[m_E4_str].setQuantity(m_E4_R, "K", true);
96 }
97 node.setFlowStyle();
98}
99
100void ArrheniusBase::setParameters(const AnyMap& node, const UnitStack& rate_units)
101{
102 ReactionRate::setParameters(node, rate_units);
103 m_negativeA_ok = node.getBool("negative-A", false);
104 if (!node.hasKey("rate-constant")) {
105 setRateParameters(AnyValue(), node.units(), rate_units);
106 return;
107 }
108 setRateParameters(node["rate-constant"], node.units(), rate_units);
109}
110
112 if (m_negativeA_ok) {
113 node["negative-A"] = true;
114 }
115 AnyMap rateNode;
116 getRateParameters(rateNode);
117 if (!rateNode.empty()) {
118 // RateType object is configured
119 node["rate-constant"] = std::move(rateNode);
120 }
121}
122
123void ArrheniusBase::check(const string& equation)
124{
125 if (!m_negativeA_ok && m_A < 0) {
126 if (equation == "") {
127 throw CanteraError("ArrheniusBase::check",
128 "Detected negative pre-exponential factor (A={}).\n"
129 "Enable 'allowNegativePreExponentialFactor' to suppress "
130 "this message.", m_A);
131 }
132 throw InputFileError("ArrheniusBase::check", m_input,
133 "Undeclared negative pre-exponential factor found in reaction '{}'",
134 equation);
135 }
136}
137
138void ArrheniusBase::validate(const string& equation, const Kinetics& kin)
139{
140 if (!valid()) {
141 throw InputFileError("ArrheniusBase::validate", m_input,
142 "Rate object for reaction '{}' is not configured.", equation);
143 }
144}
145
146bool ArrheniusData::update(const ThermoPhase& phase, const Kinetics& kin)
147{
148 double T = phase.temperature();
149 if (T == temperature) {
150 return false;
151 }
152 update(T);
153 return true;
154}
155
156}
Header for reaction rates that involve Arrhenius-type kinetics.
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
Definition AnyMap.h:630
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition AnyMap.cpp:1418
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
Definition AnyMap.cpp:1726
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition AnyMap.cpp:1515
A wrapper for a variable whose type is determined at runtime.
Definition AnyMap.h:86
bool empty() const
Return boolean indicating whether AnyValue is empty.
Definition AnyMap.cpp:647
bool is() const
Returns true if the held value is of the specified type.
Definition AnyMap.inl.h:68
const vector< T > & asVector(size_t nMin=npos, size_t nMax=npos) const
Return the held value, if it is a vector of type T.
Definition AnyMap.inl.h:109
const T & as() const
Get the value of this key as the specified type.
Definition AnyMap.inl.h:16
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Set parameters.
string m_b_str
The string for temperature exponent.
Definition Arrhenius.h:154
string m_E4_str
The string for an optional 4th parameter.
Definition Arrhenius.h:156
double m_E4_R
Optional 4th energy parameter (in temperature units)
Definition Arrhenius.h:150
void getRateParameters(AnyMap &node) const
Get Arrhenius parameters used to populate the rate-coefficient or equivalent field.
Definition Arrhenius.cpp:76
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
string m_Ea_str
The string for activation energy.
Definition Arrhenius.h:155
void getParameters(AnyMap &node) const override
Get parameters.
double m_A
Pre-exponential factor.
Definition Arrhenius.h:147
void setRateParameters(const AnyValue &rate, const UnitSystem &units, const UnitStack &rate_units)
Perform object setup based on AnyValue node information.
Definition Arrhenius.cpp:35
bool m_negativeA_ok
Permissible negative A values.
Definition Arrhenius.h:146
string m_A_str
The string for the pre-exponential factor.
Definition Arrhenius.h:153
double m_b
Temperature exponent.
Definition Arrhenius.h:148
void check(const string &equation) override
Check rate expression.
void setRateUnits(const UnitStack &rate_units) override
Set units of the reaction rate expression.
Definition Arrhenius.h:126
ArrheniusBase()
Default constructor.
Definition Arrhenius.h:47
double m_logA
Logarithm of pre-exponential factor.
Definition Arrhenius.h:151
double m_Ea_R
Activation energy (in temperature units)
Definition Arrhenius.h:149
Base class for exceptions thrown by Cantera classes.
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:738
Public interface for kinetics managers.
Definition Kinetics.h:126
double temperature() const
Temperature (K).
Definition Phase.h:662
virtual void setParameters(const AnyMap &node, const UnitStack &units)
Set parameters.
const Units & conversionUnits() const
Get the units for converting the leading term in the reaction rate expression.
bool valid() const
Get flag indicating whether reaction rate is set up correctly.
bool m_valid
Flag indicating whether reaction rate is set up correctly.
AnyMap m_input
Input data used for specific models.
Base class for a phase with thermodynamic properties.
Unit conversion utility.
Definition Units.h:169
double convertRateCoeff(const AnyValue &val, const Units &dest) const
Convert a generic AnyValue node representing a reaction rate coefficient to the units specified in de...
Definition Units.cpp:631
double convertActivationEnergy(double value, const string &src, const string &dest) const
Convert value from the units of src to the units of dest, allowing for the different dimensions that ...
Definition Units.cpp:673
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
bool update(const ThermoPhase &phase, const Kinetics &kin) override
Update data container based on thermodynamic phase state.
double temperature
temperature
Unit aggregation utility.
Definition Units.h:105