| Cantera 3.0.0

Loading...
Searching...
No Matches
ChebyshevRate.h
Go to the documentation of this file.
1//! @file ChebyshevRate.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_CHEBYSHEV_H
7#define CT_CHEBYSHEV_H
8
9#include "cantera/kinetics/ReactionRate.h"
10#include "cantera/kinetics/ReactionData.h"
11#include "cantera/kinetics/MultiRate.h"
12#include "cantera/base/Array.h"
13#include "cantera/base/global.h"
14
15 namespace Cantera
16{
17
18//! Data container holding shared data specific to ChebyshevRate
19/**
20 * The data container `ChebyshevData` holds precalculated data common to
21 * all `ChebyshevRate` objects.
22 */
23 struct ChebyshevData : public ReactionData
24{
25 ChebyshevData() = default;
26
27 void update(double T) override;
28
29 void update(double T, double P) override {
30 ReactionData::update(T);
31 pressure = P;
32 log10P = std::log10(P);
33 }
34
35 bool update(const ThermoPhase& phase, const Kinetics& kin) override;
36
37 using ReactionData::update;
38
39 //! Perturb pressure of data container
40 /**
41 * The method is used for the evaluation of numerical derivatives.
42 * @param deltaP relative pressure perturbation
43 */
44 void perturbPressure(double deltaP);
45
46 void restore() override;
47
48 void invalidateCache() override {
49 ReactionData::invalidateCache();
50 pressure = NAN;
51 }
52
53 double pressure = NAN; //!< pressure
54 double log10P = 0.0; //!< base 10 logarithm of pressure
55
56 protected:
57 double m_pressure_buf = -1.0; //!< buffered pressure
58};
59
60//! Pressure-dependent rate expression where the rate coefficient is expressed
61//! as a bivariate Chebyshev polynomial in temperature and pressure.
62/*!
63 * The rate constant can be written as:
64 * @f[
65 * \log_{10} k(T,P) = \sum_{t=1}^{N_T} \sum_{p=1}^{N_P} \alpha_{tp}
66 * \phi_t(\tilde{T}) \phi_p(\tilde{P})
67 * @f]
68 * where @f$ \alpha_{tp} @f$ are the constants defining the rate, @f$ \phi_n(x) @f$
69 * is the Chebyshev polynomial of the first kind of degree *n* evaluated at
70 * *x*, and
71 * @f[
72 * \tilde{T} \equiv \frac{2T^{-1} - T_\mathrm{min}^{-1} - T_\mathrm{max}^{-1}}
73 * {T_\mathrm{max}^{-1} - T_\mathrm{min}^{-1}}
74 * @f]
75 * @f[
76 * \tilde{P} \equiv \frac{2 \log_{10} P - \log_{10} P_\mathrm{min} - \log_{10} P_\mathrm{max}}
77 * {\log_{10} P_\mathrm{max} - \log_{10} P_\mathrm{min}}
78 * @f]
79 * are reduced temperature and reduced pressures which map the ranges
80 * @f$ (T_\mathrm{min}, T_\mathrm{max}) @f$ and
81 * @f$ (P_\mathrm{min}, P_\mathrm{max}) @f$ to (-1, 1).
82 *
83 * A ChebyshevRate rate expression is specified in terms of the coefficient matrix
84 * @f$ \alpha @f$ and the temperature and pressure ranges. Note that the
85 * Chebyshev polynomials are not defined outside the interval (-1,1), and
86 * therefore extrapolation of rates outside the range of temperatures and
87 * pressures for which they are defined is strongly discouraged.
88 *
89 * @ingroup otherRateGroup
90 */
91 class ChebyshevRate final : public ReactionRate
92{
93 public:
94 //! Default constructor.
95 ChebyshevRate() = default;
96
97 //! Constructor directly from coefficient array
98 /*!
99 * @param Tmin Minimum temperature [K]
100 * @param Tmax Maximum temperature [K]
101 * @param Pmin Minimum pressure [Pa]
102 * @param Pmax Maximum pressure [Pa]
103 * @param coeffs Coefficient array dimensioned `nT` by `nP` where `nT` and
104 * `nP` are the number of temperatures and pressures used in the fit,
105 * respectively.
106 */
107 ChebyshevRate(double Tmin, double Tmax, double Pmin, double Pmax,
108 const Array2D& coeffs);
109
110 ChebyshevRate(const AnyMap& node, const UnitStack& rate_units={});
111
112 unique_ptr<MultiRateBase> newMultiRate() const override {
113 return make_unique<MultiRate<ChebyshevRate, ChebyshevData>>();
114 }
115
116 const string type() const override { return "Chebyshev"; }
117
118 //! Perform object setup based on AnyMap node information
119 /*!
120 * @param node AnyMap containing rate information
121 * @param rate_units Unit definitions specific to rate information
122 */
123 void setParameters(const AnyMap& node, const UnitStack& rate_units) override;
124
125 void getParameters(AnyMap& rateNode) const override;
126
127 //! @deprecated To be removed after %Cantera 3.0.
128 void getParameters(AnyMap& rateNode, const Units& rate_units) const {
129 warn_deprecated("ChebyshevRate:getParameters",
130 "To be removed after Cantera 3.0. Second argument is no longer needed.");
131 return getParameters(rateNode);
132 }
133
134 void validate(const string& equation, const Kinetics& kin) override;
135
136 //! Update information specific to reaction
137 /*!
138 * @param shared_data data shared by all reactions of a given type
139 */
140 void updateFromStruct(const ChebyshevData& shared_data) {
141 if (shared_data.log10P != m_log10P) {
142 m_log10P = shared_data.log10P;
143 double Pr = (2 * shared_data.log10P + PrNum_) * PrDen_;
144 double Cnm1 = Pr;
145 double Cn = 1;
146 double Cnp1;
147 for (size_t i = 0; i < m_coeffs.nRows(); i++) {
148 dotProd_[i] = m_coeffs(i, 0);
149 }
150 for (size_t j = 1; j < m_coeffs.nColumns(); j++) {
151 Cnp1 = 2 * Pr * Cn - Cnm1;
152 for (size_t i = 0; i < m_coeffs.nRows(); i++) {
153 dotProd_[i] += Cnp1 * m_coeffs(i, j);
154 }
155 Cnm1 = Cn;
156 Cn = Cnp1;
157 }
158 }
159 }
160
161 //! Evaluate reaction rate
162 /*!
163 * @param shared_data data shared by all reactions of a given type
164 */
165 double evalFromStruct(const ChebyshevData& shared_data) {
166 double Tr = (2 * shared_data.recipT + TrNum_) * TrDen_;
167 double Cnm1 = Tr;
168 double Cn = 1;
169 double Cnp1;
170 double logk = dotProd_[0];
171 for (size_t i = 1; i < m_coeffs.nRows(); i++) {
172 Cnp1 = 2 * Tr * Cn - Cnm1;
173 logk += Cnp1 * dotProd_[i];
174 Cnm1 = Cn;
175 Cn = Cnp1;
176 }
177 return std::pow(10, logk);
178 }
179
180 //! Set limits for ChebyshevRate object
181 /*!
182 * @param Tmin Minimum temperature [K]
183 * @param Tmax Maximum temperature [K]
184 * @param Pmin Minimum pressure [Pa]
185 * @param Pmax Maximum pressure [Pa]
186 */
187 void setLimits(double Tmin, double Tmax, double Pmin, double Pmax);
188
189 //! Minimum valid temperature [K]
190 double Tmin() const {
191 return Tmin_;
192 }
193
194 //! Maximum valid temperature [K]
195 double Tmax() const {
196 return Tmax_;
197 }
198
199 //! Minimum valid pressure [Pa]
200 double Pmin() const {
201 return Pmin_;
202 }
203
204 //! Maximum valid pressure [Pa]
205 double Pmax() const {
206 return Pmax_;
207 }
208
209 //! Number of points in the pressure direction
210 size_t nPressure() const {
211 return m_coeffs.nColumns();
212 }
213
214 //! Number of points in the temperature direction
215 size_t nTemperature() const {
216 return m_coeffs.nRows();
217 }
218
219 //! Access Chebyshev coefficients as 2-dimensional array with temperature and
220 //! pressure dimensions corresponding to rows and columns, respectively.
221 const Array2D& data() const {
222 return m_coeffs;
223 }
224
225 //! Set the Chebyshev coefficients as 2-dimensional array.
226 void setData(const Array2D& coeffs);
227
228 protected:
229 double m_log10P = NAN; //!< value detecting updates
230 double Tmin_, Tmax_; //!< valid temperature range
231 double Pmin_, Pmax_; //!< valid pressure range
232 double TrNum_, TrDen_; //!< terms appearing in the reduced temperature
233 double PrNum_, PrDen_; //!< terms appearing in the reduced pressure
234
235 Array2D m_coeffs; //!<< coefficient array
236 vector<double> dotProd_; //!< dot product of coeffs with the reduced pressure polynomial
237};
238
239}
240
241#endif
Array.h
Header file for class Cantera::Array2D.
MultiRate.h
ReactionData.h
ReactionRate.h
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::Array2D
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
Cantera::Array2D::nRows
size_t nRows() const
Number of rows.
Definition Array.h:192
Cantera::Array2D::nColumns
size_t nColumns() const
Number of columns.
Definition Array.h:197
Cantera::ChebyshevRate
Pressure-dependent rate expression where the rate coefficient is expressed as a bivariate Chebyshev p...
Definition ChebyshevRate.h:92
Cantera::ChebyshevRate::getParameters
void getParameters(AnyMap &rateNode) const override
Get parameters.
Definition ChebyshevRate.cpp:126
Cantera::ChebyshevRate::data
const Array2D & data() const
Access Chebyshev coefficients as 2-dimensional array with temperature and pressure dimensions corresp...
Definition ChebyshevRate.h:221
Cantera::ChebyshevRate::newMultiRate
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
Definition ChebyshevRate.h:112
Cantera::ChebyshevRate::Tmax_
double Tmax_
valid temperature range
Definition ChebyshevRate.h:230
Cantera::ChebyshevRate::setParameters
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Perform object setup based on AnyMap node information.
Definition ChebyshevRate.cpp:63
Cantera::ChebyshevRate::TrDen_
double TrDen_
terms appearing in the reduced temperature
Definition ChebyshevRate.h:232
Cantera::ChebyshevRate::getParameters
void getParameters(AnyMap &rateNode, const Units &rate_units) const
Definition ChebyshevRate.h:128
Cantera::ChebyshevRate::updateFromStruct
void updateFromStruct(const ChebyshevData &shared_data)
Update information specific to reaction.
Definition ChebyshevRate.h:140
Cantera::ChebyshevRate::Pmin
double Pmin() const
Minimum valid pressure [Pa].
Definition ChebyshevRate.h:200
Cantera::ChebyshevRate::Tmin
double Tmin() const
Minimum valid temperature [K].
Definition ChebyshevRate.h:190
Cantera::ChebyshevRate::validate
void validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
Definition ChebyshevRate.cpp:160
Cantera::ChebyshevRate::dotProd_
vector< double > dotProd_
dot product of coeffs with the reduced pressure polynomial
Definition ChebyshevRate.h:236
Cantera::ChebyshevRate::setData
void setData(const Array2D &coeffs)
Set the Chebyshev coefficients as 2-dimensional array.
Definition ChebyshevRate.cpp:114
Cantera::ChebyshevRate::Tmax
double Tmax() const
Maximum valid temperature [K].
Definition ChebyshevRate.h:195
Cantera::ChebyshevRate::ChebyshevRate
ChebyshevRate()=default
Default constructor.
Cantera::ChebyshevRate::m_coeffs
Array2D m_coeffs
< coefficient array
Definition ChebyshevRate.h:235
Cantera::ChebyshevRate::Pmax_
double Pmax_
valid pressure range
Definition ChebyshevRate.h:231
Cantera::ChebyshevRate::nPressure
size_t nPressure() const
Number of points in the pressure direction.
Definition ChebyshevRate.h:210
Cantera::ChebyshevRate::evalFromStruct
double evalFromStruct(const ChebyshevData &shared_data)
Evaluate reaction rate.
Definition ChebyshevRate.h:165
Cantera::ChebyshevRate::Pmax
double Pmax() const
Maximum valid pressure [Pa].
Definition ChebyshevRate.h:205
Cantera::ChebyshevRate::PrDen_
double PrDen_
terms appearing in the reduced pressure
Definition ChebyshevRate.h:233
Cantera::ChebyshevRate::type
const string type() const override
String identifying reaction rate specialization.
Definition ChebyshevRate.h:116
Cantera::ChebyshevRate::m_log10P
double m_log10P
value detecting updates
Definition ChebyshevRate.h:229
Cantera::ChebyshevRate::setLimits
void setLimits(double Tmin, double Tmax, double Pmin, double Pmax)
Set limits for ChebyshevRate object.
Definition ChebyshevRate.cpp:96
Cantera::ChebyshevRate::nTemperature
size_t nTemperature() const
Number of points in the temperature direction.
Definition ChebyshevRate.h:215
Cantera::Kinetics
Public interface for kinetics managers.
Definition Kinetics.h:126
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
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926
Cantera::ChebyshevData
Data container holding shared data specific to ChebyshevRate.
Definition ChebyshevRate.h:24
Cantera::ChebyshevData::perturbPressure
void perturbPressure(double deltaP)
Perturb pressure of data container.
Definition ChebyshevRate.cpp:29
Cantera::ChebyshevData::m_pressure_buf
double m_pressure_buf
buffered pressure
Definition ChebyshevRate.h:57
Cantera::ChebyshevData::log10P
double log10P
base 10 logarithm of pressure
Definition ChebyshevRate.h:54
Cantera::ChebyshevData::update
void update(double T) override
Update data container based on temperature T
Definition ChebyshevRate.cpp:12
Cantera::ChebyshevData::restore
void restore() override
Restore data container after a perturbation.
Definition ChebyshevRate.cpp:39
Cantera::ChebyshevData::invalidateCache
void invalidateCache() override
Force shared data and reaction rates to be updated next time.
Definition ChebyshevRate.h:48
Cantera::ChebyshevData::update
void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
Definition ChebyshevRate.h:29
Cantera::ChebyshevData::pressure
double pressure
pressure
Definition ChebyshevRate.h:53
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::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