| 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
6#include "cantera/kinetics/Arrhenius.h"
7#include "cantera/thermo/ThermoPhase.h"
8
9 namespace Cantera
10{
11
12 ArrheniusBase::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
23 ArrheniusBase::ArrheniusBase(const AnyValue& rate, const UnitSystem& units,
24 const UnitStack& rate_units)
25{
26 setRateUnits(rate_units);
27 setRateParameters(rate, units, rate_units);
28}
29
30 ArrheniusBase::ArrheniusBase(const AnyMap& node, const UnitStack& rate_units)
31{
32 setParameters(node, rate_units);
33}
34
35 void ArrheniusBase::setRateParameters(
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;
44 setRateUnits(Units(0.));
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
76 void ArrheniusBase::getRateParameters(AnyMap& node) const
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
100 void 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
111 void ArrheniusBase::getParameters(AnyMap& node) const {
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
123 void 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
138 void 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
146 bool 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}
Arrhenius.h
Header for reaction rates that involve Arrhenius-type kinetics.
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::AnyMap::hasKey
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
Cantera::AnyMap::units
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
Definition AnyMap.h:630
Cantera::AnyMap::empty
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition AnyMap.cpp:1418
Cantera::AnyMap::setFlowStyle
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
Definition AnyMap.cpp:1726
Cantera::AnyMap::getBool
bool getBool(const string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
Definition AnyMap.cpp:1515
Cantera::AnyValue
A wrapper for a variable whose type is determined at runtime.
Definition AnyMap.h:86
Cantera::AnyValue::empty
bool empty() const
Return boolean indicating whether AnyValue is empty.
Definition AnyMap.cpp:647
Cantera::AnyValue::is
bool is() const
Returns true if the held value is of the specified type.
Definition AnyMap.inl.h:68
Cantera::AnyValue::asVector
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
Cantera::AnyValue::as
const T & as() const
Get the value of this key as the specified type.
Definition AnyMap.inl.h:16
Cantera::ArrheniusBase::setParameters
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Set parameters.
Definition Arrhenius.cpp:100
Cantera::ArrheniusBase::m_b_str
string m_b_str
The string for temperature exponent.
Definition Arrhenius.h:154
Cantera::ArrheniusBase::m_E4_str
string m_E4_str
The string for an optional 4th parameter.
Definition Arrhenius.h:156
Cantera::ArrheniusBase::m_E4_R
double m_E4_R
Optional 4th energy parameter (in temperature units)
Definition Arrhenius.h:150
Cantera::ArrheniusBase::getRateParameters
void getRateParameters(AnyMap &node) const
Get Arrhenius parameters used to populate the rate-coefficient or equivalent field.
Definition Arrhenius.cpp:76
Cantera::ArrheniusBase::validate
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
Definition Arrhenius.cpp:138
Cantera::ArrheniusBase::m_Ea_str
string m_Ea_str
The string for activation energy.
Definition Arrhenius.h:155
Cantera::ArrheniusBase::getParameters
void getParameters(AnyMap &node) const override
Get parameters.
Definition Arrhenius.cpp:111
Cantera::ArrheniusBase::m_A
double m_A
Pre-exponential factor.
Definition Arrhenius.h:147
Cantera::ArrheniusBase::setRateParameters
void setRateParameters(const AnyValue &rate, const UnitSystem &units, const UnitStack &rate_units)
Perform object setup based on AnyValue node information.
Definition Arrhenius.cpp:35
Cantera::ArrheniusBase::m_negativeA_ok
bool m_negativeA_ok
Permissible negative A values.
Definition Arrhenius.h:146
Cantera::ArrheniusBase::m_A_str
string m_A_str
The string for the pre-exponential factor.
Definition Arrhenius.h:153
Cantera::ArrheniusBase::m_b
double m_b
Temperature exponent.
Definition Arrhenius.h:148
Cantera::ArrheniusBase::check
void check(const string &equation) override
Check rate expression.
Definition Arrhenius.cpp:123
Cantera::ArrheniusBase::setRateUnits
void setRateUnits(const UnitStack &rate_units) override
Set units of the reaction rate expression.
Definition Arrhenius.h:126
Cantera::ArrheniusBase::ArrheniusBase
ArrheniusBase()
Default constructor.
Definition Arrhenius.h:47
Cantera::ArrheniusBase::m_logA
double m_logA
Logarithm of pre-exponential factor.
Definition Arrhenius.h:151
Cantera::ArrheniusBase::m_Ea_R
double m_Ea_R
Activation energy (in temperature units)
Definition Arrhenius.h:149
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::InputFileError
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:738
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
Cantera::Phase::temperature
double temperature() const
Temperature (K).
Definition Phase.h:662
Cantera::ReactionRate::setParameters
virtual void setParameters(const AnyMap &node, const UnitStack &units)
Set parameters.
Definition ReactionRate.h:101
Cantera::ReactionRate::conversionUnits
const Units & conversionUnits() const
Get the units for converting the leading term in the reaction rate expression.
Definition ReactionRate.h:121
Cantera::ReactionRate::valid
bool valid() const
Get flag indicating whether reaction rate is set up correctly.
Definition ReactionRate.h:220
Cantera::ReactionRate::m_valid
bool m_valid
Flag indicating whether reaction rate is set up correctly.
Definition ReactionRate.h:253
Cantera::ReactionRate::m_input
AnyMap m_input
Input data used for specific models.
Definition ReactionRate.h:247
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::UnitSystem
Unit conversion utility.
Definition Units.h:169
Cantera::UnitSystem::convertRateCoeff
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
Cantera::UnitSystem::convertActivationEnergy
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
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::ArrheniusData::update
bool update(const ThermoPhase &phase, const Kinetics &kin) override
Update data container based on thermodynamic phase state.
Definition Arrhenius.cpp:146
Cantera::ReactionData::temperature
double temperature
temperature
Definition ReactionData.h:110
Cantera::UnitStack
Unit aggregation utility.
Definition Units.h:105