Cantera 2.6.0

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() : pressure(NAN), log10P(0.), m_pressure_buf(-1.) {}
26
27 virtual void update(double T) override;
28
29 virtual void update(double T, double P) override {
30 ReactionData::update(T);
31 pressure = P;
32 log10P = std::log10(P);
33 }
34
35 virtual 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 virtual void restore() override;
47
48 virtual void invalidateCache() override {
49 ReactionData::invalidateCache();
50 pressure = NAN;
51 }
52
53 double pressure; //!< pressure
54 double log10P; //!< base 10 logarithm of pressure
55
56 protected:
57 double m_pressure_buf; //!< 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 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 P - \log P_\mathrm{min} - \log P_\mathrm{max}}
77 * {\log P_\mathrm{max} - \log 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 class ChebyshevRate final : public ReactionRate
90{
91 public:
92 //! Default constructor.
93 ChebyshevRate() : m_log10P(NAN), m_rate_units(Units(0.)) {}
94
95 //! Constructor directly from coefficient array
96 /*!
97 * @param Tmin Minimum temperature [K]
98 * @param Tmax Maximum temperature [K]
99 * @param Pmin Minimum pressure [Pa]
100 * @param Pmax Maximum pressure [Pa]
101 * @param coeffs Coefficient array dimensioned `nT` by `nP` where `nT` and
102 * `nP` are the number of temperatures and pressures used in the fit,
103 * respectively.
104 */
105 ChebyshevRate(double Tmin, double Tmax, double Pmin, double Pmax,
106 const Array2D& coeffs);
107
108 ChebyshevRate(const AnyMap& node, const UnitStack& rate_units={})
109 : ChebyshevRate()
110 {
111 setParameters(node, rate_units);
112 }
113
114 unique_ptr<MultiRateBase> newMultiRate() const {
115 return unique_ptr<MultiRateBase>(
116 new MultiRate<ChebyshevRate, ChebyshevData>);
117 }
118
119 const std::string type() const { return "Chebyshev"; }
120
121 //! Perform object setup based on AnyMap node information
122 /*!
123 * @param node AnyMap containing rate information
124 * @param units Unit definitions specific to rate information
125 */
126 void setParameters(const AnyMap& node, const UnitStack& units);
127 void getParameters(AnyMap& rateNode, const Units& rate_units) const {
128 // @todo: deprecate, as second argument is no longer needed
129 return getParameters(rateNode);
130 }
131 void getParameters(AnyMap& rateNode) const;
132
133 virtual void validate(const std::string& equation, const Kinetics& kin);
134
135 //! Update information specific to reaction
136 /*!
137 * @param shared_data data shared by all reactions of a given type
138 */
139 void updateFromStruct(const ChebyshevData& shared_data) {
140 if (shared_data.log10P != m_log10P) {
141 update_C(&shared_data.log10P);
142 }
143 }
144
145 //! Evaluate reaction rate
146 /*!
147 * @param shared_data data shared by all reactions of a given type
148 */
149 double evalFromStruct(const ChebyshevData& shared_data) {
150 return updateRC(0., shared_data.recipT);
151 }
152
153 //! Set up ChebyshevRate object
154 /*!
155 * @deprecated Deprecated in Cantera 2.6. Replaceable with
156 * @see setLimits() and @see setCoeffs().
157 */
158 void setup(double Tmin, double Tmax, double Pmin, double Pmax,
159 const Array2D& coeffs);
160
161 //! Set limits for ChebyshevRate object
162 /*!
163 * @param Tmin Minimum temperature [K]
164 * @param Tmax Maximum temperature [K]
165 * @param Pmin Minimum pressure [Pa]
166 * @param Pmax Maximum pressure [Pa]
167 */
168 void setLimits(double Tmin, double Tmax, double Pmin, double Pmax);
169
170 //! Update concentration-dependent parts of the rate coefficient.
171 //! @param c base-10 logarithm of the pressure in Pa
172 //! @deprecated To be removed after Cantera 2.6. Implementation will be moved to
173 //! the updateFromStruct() method.
174 void update_C(const double* c) {
175 m_log10P = c[0];
176 double Pr = (2 * c[0] + PrNum_) * PrDen_;
177 double Cnm1 = Pr;
178 double Cn = 1;
179 double Cnp1;
180 for (size_t i = 0; i < m_coeffs.nRows(); i++) {
181 dotProd_[i] = m_coeffs(i, 0);
182 }
183 for (size_t j = 1; j < m_coeffs.nColumns(); j++) {
184 Cnp1 = 2 * Pr * Cn - Cnm1;
185 for (size_t i = 0; i < m_coeffs.nRows(); i++) {
186 dotProd_[i] += Cnp1 * m_coeffs(i, j);
187 }
188 Cnm1 = Cn;
189 Cn = Cnp1;
190 }
191 }
192
193 /**
194 * Update the value the rate constant.
195 *
196 * This function returns the actual value of the rate constant.
197 * @deprecated To be removed after Cantera 2.6. Implementation will be moved to
198 * the evalFromStruct() method.
199 */
200 double updateRC(double logT, double recipT) const {
201 double Tr = (2 * recipT + TrNum_) * TrDen_;
202 double Cnm1 = Tr;
203 double Cn = 1;
204 double Cnp1;
205 double logk = dotProd_[0];
206 for (size_t i = 1; i < m_coeffs.nRows(); i++) {
207 Cnp1 = 2 * Tr * Cn - Cnm1;
208 logk += Cnp1 * dotProd_[i];
209 Cnm1 = Cn;
210 Cn = Cnp1;
211 }
212 return std::pow(10, logk);
213 }
214
215 //! Minimum valid temperature [K]
216 double Tmin() const {
217 return Tmin_;
218 }
219
220 //! Maximum valid temperature [K]
221 double Tmax() const {
222 return Tmax_;
223 }
224
225 //! Minimum valid pressure [Pa]
226 double Pmin() const {
227 return Pmin_;
228 }
229
230 //! Maximum valid pressure [Pa]
231 double Pmax() const {
232 return Pmax_;
233 }
234
235 //! Number of points in the pressure direction
236 size_t nPressure() const {
237 return m_coeffs.nColumns();
238 }
239
240 //! Number of points in the temperature direction
241 size_t nTemperature() const {
242 return m_coeffs.nRows();
243 }
244
245 //! Access the ChebyshevRate coefficients.
246 /*!
247 * \f$ \alpha_{t,p} = \mathrm{coeffs}[N_P*t + p] \f$ where
248 * \f$ 0 <= t < N_T \f$ and \f$ 0 <= p < N_P \f$.
249 *
250 * @deprecated To be removed after Cantera 2.6. Replaceable by @see data().
251 */
252 const vector_fp& coeffs() const {
253 warn_deprecated("ChebyshevRate::coeffs", "Deprecated in Cantera 2.6 "
254 "and to be removed thereafter; replaceable by data().");
255 return chebCoeffs_;
256 }
257
258 //! Access Chebyshev coefficients as 2-dimensional array with temperature and
259 //! pressure dimensions corresponding to rows and columns, respectively.
260 const Array2D& data() const {
261 return m_coeffs;
262 }
263
264 //! Set the Chebyshev coefficients as 2-dimensional array.
265 void setData(const Array2D& coeffs);
266
267 protected:
268 double m_log10P; //!< value detecting updates
269 double Tmin_, Tmax_; //!< valid temperature range
270 double Pmin_, Pmax_; //!< valid pressure range
271 double TrNum_, TrDen_; //!< terms appearing in the reduced temperature
272 double PrNum_, PrDen_; //!< terms appearing in the reduced pressure
273
274 Array2D m_coeffs; //!<< coefficient array
275 vector_fp chebCoeffs_; //!< Chebyshev coefficients, length nP * nT
276 vector_fp dotProd_; //!< dot product of chebCoeffs with the reduced pressure polynomial
277
278 Units m_rate_units; //!< Reaction rate units
279};
280
281}
282
283#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:399
Cantera::Array2D
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
Cantera::Array2D::nRows
size_t nRows() const
Number of rows.
Definition: Array.h:188
Cantera::Array2D::nColumns
size_t nColumns() const
Number of columns.
Definition: Array.h:193
Cantera::ChebyshevRate
Pressure-dependent rate expression where the rate coefficient is expressed as a bivariate Chebyshev p...
Definition: ChebyshevRate.h:90
Cantera::ChebyshevRate::data
const Array2D & data() const
Access Chebyshev coefficients as 2-dimensional array with temperature and pressure dimensions corresp...
Definition: ChebyshevRate.h:260
Cantera::ChebyshevRate::setParameters
void setParameters(const AnyMap &node, const UnitStack &units)
Perform object setup based on AnyMap node information.
Definition: ChebyshevRate.cpp:57
Cantera::ChebyshevRate::Tmax_
double Tmax_
valid temperature range
Definition: ChebyshevRate.h:269
Cantera::ChebyshevRate::ChebyshevRate
ChebyshevRate()
Default constructor.
Definition: ChebyshevRate.h:93
Cantera::ChebyshevRate::newMultiRate
unique_ptr< MultiRateBase > newMultiRate() const
Create a rate evaluator for reactions of a particular derived type.
Definition: ChebyshevRate.h:114
Cantera::ChebyshevRate::TrDen_
double TrDen_
terms appearing in the reduced temperature
Definition: ChebyshevRate.h:271
Cantera::ChebyshevRate::m_rate_units
Units m_rate_units
Reaction rate units.
Definition: ChebyshevRate.h:278
Cantera::ChebyshevRate::updateFromStruct
void updateFromStruct(const ChebyshevData &shared_data)
Update information specific to reaction.
Definition: ChebyshevRate.h:139
Cantera::ChebyshevRate::Pmin
double Pmin() const
Minimum valid pressure [Pa].
Definition: ChebyshevRate.h:226
Cantera::ChebyshevRate::Tmin
double Tmin() const
Minimum valid temperature [K].
Definition: ChebyshevRate.h:216
Cantera::ChebyshevRate::setData
void setData(const Array2D &coeffs)
Set the Chebyshev coefficients as 2-dimensional array.
Definition: ChebyshevRate.cpp:122
Cantera::ChebyshevRate::Tmax
double Tmax() const
Maximum valid temperature [K].
Definition: ChebyshevRate.h:221
Cantera::ChebyshevRate::updateRC
double updateRC(double logT, double recipT) const
Update the value the rate constant.
Definition: ChebyshevRate.h:200
Cantera::ChebyshevRate::type
const std::string type() const
String identifying reaction rate specialization.
Definition: ChebyshevRate.h:119
Cantera::ChebyshevRate::m_coeffs
Array2D m_coeffs
< coefficient array
Definition: ChebyshevRate.h:274
Cantera::ChebyshevRate::Pmax_
double Pmax_
valid pressure range
Definition: ChebyshevRate.h:270
Cantera::ChebyshevRate::dotProd_
vector_fp dotProd_
dot product of chebCoeffs with the reduced pressure polynomial
Definition: ChebyshevRate.h:276
Cantera::ChebyshevRate::nPressure
size_t nPressure() const
Number of points in the pressure direction.
Definition: ChebyshevRate.h:236
Cantera::ChebyshevRate::evalFromStruct
double evalFromStruct(const ChebyshevData &shared_data)
Evaluate reaction rate.
Definition: ChebyshevRate.h:149
Cantera::ChebyshevRate::setup
void setup(double Tmin, double Tmax, double Pmin, double Pmax, const Array2D &coeffs)
Set up ChebyshevRate object.
Definition: ChebyshevRate.cpp:95
Cantera::ChebyshevRate::Pmax
double Pmax() const
Maximum valid pressure [Pa].
Definition: ChebyshevRate.h:231
Cantera::ChebyshevRate::PrDen_
double PrDen_
terms appearing in the reduced pressure
Definition: ChebyshevRate.h:272
Cantera::ChebyshevRate::chebCoeffs_
vector_fp chebCoeffs_
Chebyshev coefficients, length nP * nT.
Definition: ChebyshevRate.h:275
Cantera::ChebyshevRate::m_log10P
double m_log10P
value detecting updates
Definition: ChebyshevRate.h:268
Cantera::ChebyshevRate::coeffs
const vector_fp & coeffs() const
Access the ChebyshevRate coefficients.
Definition: ChebyshevRate.h:252
Cantera::ChebyshevRate::update_C
void update_C(const double *c)
Update concentration-dependent parts of the rate coefficient.
Definition: ChebyshevRate.h:174
Cantera::ChebyshevRate::setLimits
void setLimits(double Tmin, double Tmax, double Pmin, double Pmax)
Set limits for ChebyshevRate object.
Definition: ChebyshevRate.cpp:104
Cantera::ChebyshevRate::nTemperature
size_t nTemperature() const
Number of points in the temperature direction.
Definition: ChebyshevRate.h:241
Cantera::ChebyshevRate::validate
virtual void validate(const std::string &equation, const Kinetics &kin)
Validate the reaction rate expression.
Definition: ChebyshevRate.cpp:174
Cantera::Kinetics
Public interface for kinetics managers.
Definition: Kinetics.h:114
Cantera::MultiRate
A class template handling ReactionRate specializations.
Definition: MultiRate.h:21
Cantera::ReactionRate
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition: ReactionRate.h:45
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
global.h
This file contains definitions for utility functions and text for modules, inputfiles,...
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::warn_deprecated
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
Cantera::vector_fp
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184
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
virtual void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
Definition: ChebyshevRate.h:29
Cantera::ChebyshevData::update
virtual void update(double T) override
Update data container based on temperature T
Definition: ChebyshevRate.cpp:12
Cantera::ChebyshevData::invalidateCache
virtual void invalidateCache() override
Force shared data and reaction rates to be updated next time.
Definition: ChebyshevRate.h:48
Cantera::ChebyshevData::restore
virtual void restore() override
Restore data container after a perturbation.
Definition: ChebyshevRate.cpp:39
Cantera::ChebyshevData::pressure
double pressure
pressure
Definition: ChebyshevRate.h:53
Cantera::ReactionData
Data container holding shared data used for ReactionRate calculation.
Definition: ReactionData.h:26
Cantera::ReactionData::recipT
double recipT
inverse of temperature
Definition: ReactionData.h:111
Cantera::ReactionData::update
virtual void update(double T)
Update data container based on temperature T
Definition: ReactionData.h:35
Cantera::ReactionData::invalidateCache
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Definition: ReactionData.h:105
Cantera::UnitStack
Unit aggregation utility.
Definition: Units.h:99