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
12#include "cantera/base/Array.h"
13#include "cantera/base/global.h"
14
15namespace 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 */
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 {
31 pressure = P;
32 log10P = std::log10(P);
33 }
34
35 virtual bool update(const ThermoPhase& phase, const Kinetics& kin) override;
36
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 {
50 pressure = NAN;
51 }
52
53 double pressure; //!< pressure
54 double log10P; //!< base 10 logarithm of pressure
55
56protected:
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 */
89class ChebyshevRate final : public ReactionRate
90{
91public:
92 //! Default constructor.
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>(
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
267protected:
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
Header file for class Cantera::Array2D.
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:30
size_t nRows() const
Number of rows.
Definition: Array.h:188
size_t nColumns() const
Number of columns.
Definition: Array.h:193
Pressure-dependent rate expression where the rate coefficient is expressed as a bivariate Chebyshev p...
Definition: ChebyshevRate.h:90
const Array2D & data() const
Access Chebyshev coefficients as 2-dimensional array with temperature and pressure dimensions corresp...
void setParameters(const AnyMap &node, const UnitStack &units)
Perform object setup based on AnyMap node information.
double Tmax_
valid temperature range
ChebyshevRate()
Default constructor.
Definition: ChebyshevRate.h:93
unique_ptr< MultiRateBase > newMultiRate() const
Create a rate evaluator for reactions of a particular derived type.
double TrDen_
terms appearing in the reduced temperature
Units m_rate_units
Reaction rate units.
void updateFromStruct(const ChebyshevData &shared_data)
Update information specific to reaction.
double Pmin() const
Minimum valid pressure [Pa].
double Tmin() const
Minimum valid temperature [K].
void setData(const Array2D &coeffs)
Set the Chebyshev coefficients as 2-dimensional array.
double Tmax() const
Maximum valid temperature [K].
double updateRC(double logT, double recipT) const
Update the value the rate constant.
const std::string type() const
String identifying reaction rate specialization.
Array2D m_coeffs
< coefficient array
double Pmax_
valid pressure range
vector_fp dotProd_
dot product of chebCoeffs with the reduced pressure polynomial
size_t nPressure() const
Number of points in the pressure direction.
double evalFromStruct(const ChebyshevData &shared_data)
Evaluate reaction rate.
void setup(double Tmin, double Tmax, double Pmin, double Pmax, const Array2D &coeffs)
Set up ChebyshevRate object.
double Pmax() const
Maximum valid pressure [Pa].
double PrDen_
terms appearing in the reduced pressure
vector_fp chebCoeffs_
Chebyshev coefficients, length nP * nT.
double m_log10P
value detecting updates
const vector_fp & coeffs() const
Access the ChebyshevRate coefficients.
void update_C(const double *c)
Update concentration-dependent parts of the rate coefficient.
void setLimits(double Tmin, double Tmax, double Pmin, double Pmax)
Set limits for ChebyshevRate object.
size_t nTemperature() const
Number of points in the temperature direction.
virtual void validate(const std::string &equation, const Kinetics &kin)
Validate the reaction rate expression.
Public interface for kinetics managers.
Definition: Kinetics.h:114
A class template handling ReactionRate specializations.
Definition: MultiRate.h:21
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition: ReactionRate.h:45
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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
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
Data container holding shared data specific to ChebyshevRate.
Definition: ChebyshevRate.h:24
void perturbPressure(double deltaP)
Perturb pressure of data container.
double m_pressure_buf
buffered pressure
Definition: ChebyshevRate.h:57
double log10P
base 10 logarithm of pressure
Definition: ChebyshevRate.h:54
virtual void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
Definition: ChebyshevRate.h:29
virtual void update(double T) override
Update data container based on temperature T
virtual void invalidateCache() override
Force shared data and reaction rates to be updated next time.
Definition: ChebyshevRate.h:48
virtual void restore() override
Restore data container after a perturbation.
double pressure
pressure
Definition: ChebyshevRate.h:53
Data container holding shared data used for ReactionRate calculation.
Definition: ReactionData.h:26
double recipT
inverse of temperature
Definition: ReactionData.h:111
virtual void update(double T)
Update data container based on temperature T
Definition: ReactionData.h:35
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Definition: ReactionData.h:105
Unit aggregation utility.
Definition: Units.h:99