13#include "cantera/kinetics/Falloff.h"
20FalloffData::FalloffData()
23 , m_state_mf_number(-1)
26 conc_3b.resize(1, NAN);
27 m_conc_3b_buf.resize(1, NAN);
30void FalloffData::update(
double T)
33 "Missing state information: 'FalloffData' requires third-body concentration.");
36void FalloffData::update(
double T,
double M)
38 ReactionData::update(T);
48 if (T != temperature) {
49 ReactionData::update(T);
52 if (rho_m != molar_density || mf != m_state_mf_number) {
53 molar_density = rho_m;
54 m_state_mf_number = mf;
61void FalloffData::perturbThirdBodies(
double deltaM)
65 "Cannot apply another perturbation as state is already perturbed.");
67 m_conc_3b_buf = conc_3b;
68 for (
auto& c3b : conc_3b) {
74void FalloffData::restore()
76 ReactionData::restore();
81 conc_3b = m_conc_3b_buf;
97 "Detected inconsistent rate definitions;\nhigh and low "
98 "rate pre-exponential factors must have the same sign.");
100 m_lowRate = std::move(_low);
110 "Detected inconsistent rate definitions;\nhigh and low "
111 "rate pre-exponential factors must have the same sign.");
113 m_highRate = std::move(_high);
120 "Incorrect number of parameters. 0 required. Received {}.",
136 m_negativeA_ok = node.
getBool(
"negative-A",
false);
137 if (node[
"type"] ==
"chemically-activated") {
138 m_chemicallyActivated =
true;
143 if (rate_units.
size()) {
144 if (m_chemicallyActivated) {
145 low_rate_units.
join(1);
146 high_rate_units.
join(2);
148 high_rate_units.
join(1);
151 if (node.
hasKey(
"low-P-rate-constant")) {
153 node[
"low-P-rate-constant"], node.
units(), low_rate_units);
154 m_lowRate.setAllowNegativePreExponentialFactor(m_negativeA_ok);
156 if (node.
hasKey(
"high-P-rate-constant")) {
158 node[
"high-P-rate-constant"], node.
units(), high_rate_units);
159 m_highRate.setAllowNegativePreExponentialFactor(m_negativeA_ok);
163void FalloffRate::getParameters(
AnyMap& node)
const
165 if (m_chemicallyActivated) {
166 node[
"type"] =
"chemically-activated";
168 node[
"type"] =
"falloff";
170 if (m_negativeA_ok) {
171 node[
"negative-A"] =
true;
174 m_lowRate.getRateParameters(rNode);
175 if (!rNode.
empty()) {
176 node[
"low-P-rate-constant"] = std::move(rNode);
179 m_highRate.getRateParameters(rNode);
180 if (!rNode.
empty()) {
181 node[
"high-P-rate-constant"] = std::move(rNode);
185void FalloffRate::check(
const std::string& equation,
const AnyMap& node)
187 m_lowRate.check(equation, node);
188 m_highRate.check(equation, node);
190 double lowA = m_lowRate.preExponentialFactor();
191 double highA = m_highRate.preExponentialFactor();
192 if (std::isnan(lowA) || std::isnan(highA)) {
196 if (lowA * highA < 0) {
198 "Inconsistent rate definitions found in reaction '{}';\nhigh and low "
199 "rate pre-exponential factors must have the same sign.", equation);
203void FalloffRate::validate(
const std::string& equation,
const Kinetics& kin)
205 m_lowRate.validate(equation, kin);
206 m_highRate.validate(equation, kin);
211 if (c.size() != 3 && c.size() != 4) {
213 "Incorrect number of coefficients. 3 or 4 required. Received {}.",
218 m_rt3 = std::numeric_limits<double>::infinity();
224 m_rt1 = std::numeric_limits<double>::infinity();
232 "Unexpected parameter value T2=0. Omitting exp(T2/T) term from "
233 "falloff expression. To suppress this warning, remove value "
234 "for T2 from the input file. In the unlikely case that the "
235 "exp(T2/T) term should be included with T2 effectively equal "
236 "to 0, set T2 to a sufficiently small value "
237 "(for example, T2 < 1e-16).");
248 getParameters(c.data());
254void TroeRate::updateTemp(
double T,
double* work)
const
256 double Fcent = (1.0 - m_a) * exp(-T*m_rt3) + m_a * exp(-T*m_rt1);
258 Fcent += exp(- m_t2 / T);
263double TroeRate::F(
double pr,
const double* work)
const
266 double cc = -0.4 - 0.67 * (*work);
267 double nn = 0.75 - 1.27 * (*work);
268 double f1 = (lpr + cc)/ (nn - 0.14 * (lpr + cc));
269 double lgf = (*work) / (1.0 + f1 * f1);
270 return pow(10.0, lgf);
279 FalloffRate::setParameters(node, rate_units);
280 auto& f = node[
"Troe"].as<
AnyMap>();
289 if (f.hasKey(
"T2")) {
290 params.push_back(f[
"T2"].asDouble());
292 setFalloffCoeffs(params);
295void TroeRate::getParameters(
double* params)
const {
297 params[1] = 1.0/m_rt3;
298 params[2] = 1.0/m_rt1;
302void TroeRate::getParameters(
AnyMap& node)
const
304 FalloffRate::getParameters(node);
307 if (std::isnan(m_a)) {
309 }
else if (m_lowRate.rateUnits().factor() != 0.0) {
311 params[
"T3"].setQuantity(1.0 / m_rt3,
"K");
312 params[
"T1"].setQuantity(1.0 / m_rt1,
"K");
314 params[
"T2"].setQuantity(m_t2,
"K");
318 params[
"T3"] = 1.0 / m_rt3;
319 params[
"T1"] = 1.0 / m_rt1;
325 node[
"Troe"] = std::move(params);
330 if (c.size() != 3 && c.size() != 5) {
332 "Incorrect number of coefficients. 3 or 5 required. Received {}.",
338 "m_c parameter is less than zero: {}", c[2]);
347 "m_d parameter is less than zero: {}", c[3]);
360 getParameters(c.data());
366void SriRate::updateTemp(
double T,
double* work)
const
368 *work = m_a * exp(- m_b / T);
370 *work += exp(- T/m_c);
372 work[1] = m_d * pow(T,m_e);
375double SriRate::F(
double pr,
const double* work)
const
378 double xx = 1.0/(1.0 + lpr*lpr);
379 return pow(*work, xx) * work[1];
388 FalloffRate::setParameters(node, rate_units);
389 auto& f = node[
"SRI"].as<
AnyMap>();
399 params.push_back(f[
"D"].asDouble());
402 params.push_back(f[
"E"].asDouble());
404 setFalloffCoeffs(params);
407void SriRate::getParameters(
double* params)
const
416void SriRate::getParameters(
AnyMap& node)
const
418 FalloffRate::getParameters(node);
421 if (std::isnan(m_a)) {
423 }
else if (m_lowRate.rateUnits().factor() != 0.0) {
425 params[
"B"].setQuantity(m_b,
"K");
426 params[
"C"].setQuantity(m_c,
"K");
427 if (m_d != 1.0 || m_e != 0.0) {
435 if (m_d != 1.0 || m_e != 0.0) {
441 node[
"SRI"] = std::move(params);
446 if (c.size() != 1 && c.size() != 2) {
448 "Incorrect number of coefficients. 1 or 2 required. Received {}.",
464 getParameters(c.data());
470void TsangRate::updateTemp(
double T,
double* work)
const
472 double Fcent = m_a + (m_b * T);
476double TsangRate::F(
double pr,
const double* work)
const
479 double cc = -0.4 - 0.67 * (*work);
480 double nn = 0.75 - 1.27 * (*work);
481 double f1 = (lpr + cc)/ (nn - 0.14 * (lpr + cc));
482 double lgf = (*work) / (1.0 + f1 * f1);
483 return pow(10.0, lgf);
492 FalloffRate::setParameters(node, rate_units);
493 auto& f = node[
"Tsang"].as<
AnyMap>();
501 setFalloffCoeffs(params);
504void TsangRate::getParameters(
double* params)
const {
509void TsangRate::getParameters(
AnyMap& node)
const
511 FalloffRate::getParameters(node);
514 if (std::isnan(m_a)) {
522 node[
"Tsang"] = std::move(params);
Base class for kinetics managers and also contains the kineticsmgr module documentation (see 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.
const UnitSystem & units() const
Return the default units that should be used to convert stored values.
bool empty() const
Return boolean indicating whether AnyMap is empty.
bool getBool(const std::string &key, bool default_) const
If key exists, return it as a bool, otherwise return default_.
void setFlowStyle(bool flow=true)
Use "flow" style when outputting this AnyMap to YAML.
void clear()
Erase all items in the mapping.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
void setAllowNegativePreExponentialFactor(bool value)
Set flag indicating whether negative A values are permitted.
virtual void check(const std::string &equation, const AnyMap &node) override
Check rate expression.
virtual double preExponentialFactor() const
Return the pre-exponential factor A (in m, kmol, s to powers depending on the reaction order)
Arrhenius reaction rate type depends only on temperature.
Base class for exceptions thrown by Cantera classes.
Public interface for kinetics managers.
virtual const vector_fp & thirdBodyConcentrations() const
Provide direct access to current third-body concentration values.
double molarDensity() const
Molar density (kmol/m^3).
int stateMFNumber() const
Return the State Mole Fraction Number.
doublereal temperature() const
Temperature (K).
Base class for a phase with thermodynamic properties.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
const double SmallNumber
smallest number to compare to zero.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void warn_user(const std::string &method, const std::string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Contains declarations for string manipulation functions within Cantera.
Unit aggregation utility.
size_t size() const
Size of UnitStack.
void join(double exponent)
Join (update) exponent of standard units, where the updated exponent is the sum of the pre-existing e...