| Cantera 3.0.0

Loading...
Searching...
No Matches
PlogRate.h
Go to the documentation of this file.
1//! @file PlogRate.h
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#ifndef CT_PLOGRATE_H
7#define CT_PLOGRATE_H
8
9#include "cantera/kinetics/Arrhenius.h"
10
11 namespace Cantera
12{
13
14//! Data container holding shared data specific to PlogRate
15/**
16 * The data container `PlogData` holds precalculated data common to
17 * all `PlogRate` objects.
18 */
19 struct PlogData : public ReactionData
20{
21 PlogData() = default;
22
23 void update(double T) override;
24
25 void update(double T, double P) override {
26 ReactionData::update(T);
27 pressure = P;
28 logP = std::log(P);
29 }
30
31 bool update(const ThermoPhase& phase, const Kinetics& kin) override;
32
33 using ReactionData::update;
34
35 //! Perturb pressure of data container
36 /**
37 * The method is used for the evaluation of numerical derivatives.
38 * @param deltaP relative pressure perturbation
39 */
40 void perturbPressure(double deltaP);
41
42 void restore() override;
43
44 void invalidateCache() override {
45 ReactionData::invalidateCache();
46 pressure = NAN;
47 }
48
49 double pressure = NAN; //!< pressure
50 double logP = 0.0; //!< logarithm of pressure
51
52 protected:
53 double m_pressure_buf = -1.0; //!< buffered pressure
54};
55
56
57//! Pressure-dependent reaction rate expressed by logarithmically interpolating
58//! between Arrhenius rate expressions at various pressures.
59/*!
60 * Given two rate expressions at two specific pressures:
61 *
62 * * @f$ P_1: k_1(T) = A_1 T^{b_1} e^{-E_1 / RT} @f$
63 * * @f$ P_2: k_2(T) = A_2 T^{b_2} e^{-E_2 / RT} @f$
64 *
65 * The rate at an intermediate pressure @f$ P_1 < P < P_2 @f$ is computed as
66 * @f[
67 * \ln k(T,P) = \ln k_1(T) + \bigl(\ln k_2(T) - \ln k_1(T)\bigr)
68 * \frac{\ln P - \ln P_1}{\ln P_2 - \ln P_1}
69 * @f]
70 * Multiple rate expressions may be given at the same pressure, in which case
71 * the rate used in the interpolation formula is the sum of all the rates given
72 * at that pressure. For pressures outside the given range, the rate expression
73 * at the nearest pressure is used.
74 * @ingroup otherRateGroup
75 */
76 class PlogRate final : public ReactionRate
77{
78 public:
79 //! Default constructor.
80 PlogRate() = default;
81
82 //! Constructor from Arrhenius rate expressions at a set of pressures
83 explicit PlogRate(const std::multimap<double, ArrheniusRate>& rates);
84
85 PlogRate(const AnyMap& node, const UnitStack& rate_units={});
86
87 unique_ptr<MultiRateBase> newMultiRate() const override {
88 return make_unique<MultiRate<PlogRate, PlogData>>();
89 }
90
91 //! Identifier of reaction rate type
92 const string type() const override { return "pressure-dependent-Arrhenius"; }
93
94 //! Perform object setup based on AnyMap node information
95 /*!
96 * @param node AnyMap containing rate information
97 * @param rate_units Unit definitions specific to rate information
98 */
99 void setParameters(const AnyMap& node, const UnitStack& rate_units) override;
100
101 void getParameters(AnyMap& rateNode, const Units& rate_units) const;
102 void getParameters(AnyMap& rateNode) const override {
103 return getParameters(rateNode, Units(0));
104 }
105
106 //! Update information specific to reaction
107 /*!
108 * @param shared_data data shared by all reactions of a given type
109 */
110 void updateFromStruct(const PlogData& shared_data) {
111 if (shared_data.logP != logP_) {
112 logP_ = shared_data.logP;
113 if (logP_ > logP1_ && logP_ < logP2_) {
114 return;
115 }
116
117 auto iter = pressures_.upper_bound(logP_);
118 AssertThrowMsg(iter != pressures_.end(), "PlogRate::updateFromStruct",
119 "Pressure out of range: {}", logP_);
120 AssertThrowMsg(iter != pressures_.begin(), "PlogRate::updateFromStruct",
121 "Pressure out of range: {}", logP_);
122
123 // upper interpolation pressure
124 logP2_ = iter->first;
125 ihigh1_ = iter->second.first;
126 ihigh2_ = iter->second.second;
127
128 // lower interpolation pressure
129 logP1_ = (--iter)->first;
130 ilow1_ = iter->second.first;
131 ilow2_ = iter->second.second;
132
133 rDeltaP_ = 1.0 / (logP2_ - logP1_);
134 }
135 }
136
137 //! Evaluate reaction rate
138 /*!
139 * @param shared_data data shared by all reactions of a given type
140 */
141 double evalFromStruct(const PlogData& shared_data) {
142 double log_k1, log_k2;
143 if (ilow1_ == ilow2_) {
144 log_k1 = rates_[ilow1_].evalLog(shared_data.logT, shared_data.recipT);
145 } else {
146 double k = 1e-300; // non-zero to make log(k) finite
147 for (size_t i = ilow1_; i < ilow2_; i++) {
148 k += rates_[i].evalRate(shared_data.logT, shared_data.recipT);
149 }
150 log_k1 = std::log(k);
151 }
152
153 if (ihigh1_ == ihigh2_) {
154 log_k2 = rates_[ihigh1_].evalLog(shared_data.logT, shared_data.recipT);
155 } else {
156 double k = 1e-300; // non-zero to make log(k) finite
157 for (size_t i = ihigh1_; i < ihigh2_; i++) {
158 k += rates_[i].evalRate(shared_data.logT, shared_data.recipT);
159 }
160 log_k2 = std::log(k);
161 }
162
163 return std::exp(log_k1 + (log_k2 - log_k1) * (logP_ - logP1_) * rDeltaP_);
164 }
165
166 //! Set up Plog object
167 void setRates(const std::multimap<double, ArrheniusRate>& rates);
168
169 //! Check to make sure that the rate expression is finite over a range of
170 //! temperatures at each interpolation pressure. This is potentially an
171 //! issue when one of the Arrhenius expressions at a particular pressure
172 //! has a negative pre-exponential factor.
173 void validate(const string& equation, const Kinetics& kin) override;
174
175 //! @deprecated To be removed after %Cantera 3.0;
176 //! superseded by two-parameter version
177 void validate(const string& equation) override;
178
179 //! Return the pressures and Arrhenius expressions which comprise this
180 //! reaction.
181 std::multimap<double, ArrheniusRate> getRates() const;
182
183 protected:
184 //! log(p) to (index range) in the rates_ vector
185 map<double, pair<size_t, size_t>> pressures_;
186
187 // Rate expressions which are referenced by the indices stored in pressures_
188 vector<ArrheniusRate> rates_;
189
190 double logP_ = -1000; //!< log(p) at the current state
191 double logP1_ = 1000; //!< log(p) at the lower pressure reference
192 double logP2_ = -1000; //!< log(p) at the upper pressure reference
193
194 //! Indices to the ranges within rates_ for the lower / upper pressure, such
195 //! that rates_[ilow1_] through rates_[ilow2_] (inclusive) are the rates
196 //! expressions which are combined to form the rate at the lower reference
197 //! pressure.
198 size_t ilow1_, ilow2_, ihigh1_, ihigh2_;
199
200 double rDeltaP_ = -1.0; //!< reciprocal of (logP2 - logP1)
201};
202
203}
204#endif
Arrhenius.h
Header for reaction rates that involve Arrhenius-type kinetics.
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
Cantera::PlogRate
Pressure-dependent reaction rate expressed by logarithmically interpolating between Arrhenius rate ex...
Definition PlogRate.h:77
Cantera::PlogRate::getParameters
void getParameters(AnyMap &rateNode) const override
Get parameters.
Definition PlogRate.h:102
Cantera::PlogRate::pressures_
map< double, pair< size_t, size_t > > pressures_
log(p) to (index range) in the rates_ vector
Definition PlogRate.h:185
Cantera::PlogRate::newMultiRate
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
Definition PlogRate.h:87
Cantera::PlogRate::updateFromStruct
void updateFromStruct(const PlogData &shared_data)
Update information specific to reaction.
Definition PlogRate.h:110
Cantera::PlogRate::PlogRate
PlogRate()=default
Default constructor.
Cantera::PlogRate::getRates
std::multimap< double, ArrheniusRate > getRates() const
Return the pressures and Arrhenius expressions which comprise this reaction.
Definition PlogRate.cpp:166
Cantera::PlogRate::setParameters
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Perform object setup based on AnyMap node information.
Definition PlogRate.cpp:65
Cantera::PlogRate::setRates
void setRates(const std::multimap< double, ArrheniusRate > &rates)
Set up Plog object.
Definition PlogRate.cpp:95
Cantera::PlogRate::validate
void validate(const string &equation, const Kinetics &kin) override
Check to make sure that the rate expression is finite over a range of temperatures at each interpolat...
Definition PlogRate.cpp:128
Cantera::PlogRate::evalFromStruct
double evalFromStruct(const PlogData &shared_data)
Evaluate reaction rate.
Definition PlogRate.h:141
Cantera::PlogRate::rDeltaP_
double rDeltaP_
reciprocal of (logP2 - logP1)
Definition PlogRate.h:200
Cantera::PlogRate::logP_
double logP_
log(p) at the current state
Definition PlogRate.h:190
Cantera::PlogRate::type
const string type() const override
Identifier of reaction rate type.
Definition PlogRate.h:92
Cantera::PlogRate::logP1_
double logP1_
log(p) at the lower pressure reference
Definition PlogRate.h:191
Cantera::PlogRate::ilow1_
size_t ilow1_
Indices to the ranges within rates_ for the lower / upper pressure, such that rates_[ilow1_] through ...
Definition PlogRate.h:198
Cantera::PlogRate::logP2_
double logP2_
log(p) at the upper pressure reference
Definition PlogRate.h:192
Cantera::ReactionRate
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition ReactionRate.h:49
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
AssertThrowMsg
#define AssertThrowMsg(expr, procedure,...)
Assertion must be true or an error is thrown.
Definition ctexceptions.h:278
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::PlogData
Data container holding shared data specific to PlogRate.
Definition PlogRate.h:20
Cantera::PlogData::perturbPressure
void perturbPressure(double deltaP)
Perturb pressure of data container.
Definition PlogRate.cpp:32
Cantera::PlogData::m_pressure_buf
double m_pressure_buf
buffered pressure
Definition PlogRate.h:53
Cantera::PlogData::update
void update(double T) override
Update data container based on temperature T
Definition PlogRate.cpp:15
Cantera::PlogData::logP
double logP
logarithm of pressure
Definition PlogRate.h:50
Cantera::PlogData::restore
void restore() override
Restore data container after a perturbation.
Definition PlogRate.cpp:42
Cantera::PlogData::invalidateCache
void invalidateCache() override
Force shared data and reaction rates to be updated next time.
Definition PlogRate.h:44
Cantera::PlogData::update
void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
Definition PlogRate.h:25
Cantera::PlogData::pressure
double pressure
pressure
Definition PlogRate.h:49
Cantera::ReactionData
Data container holding shared data used for ReactionRate calculation.
Definition ReactionData.h:27
Cantera::ReactionData::recipT
double recipT
inverse of temperature
Definition ReactionData.h:112
Cantera::ReactionData::update
virtual void update(double T)
Update data container based on temperature T
Definition ReactionData.h:36
Cantera::ReactionData::logT
double logT
logarithm of temperature
Definition ReactionData.h:111
Cantera::ReactionData::invalidateCache
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Definition ReactionData.h:106
Cantera::UnitStack
Unit aggregation utility.
Definition Units.h:105