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
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() = default;
26
27 void update(double T) override;
28
29 void update(double T, double P) override {
31 pressure = P;
32 log10P = std::log10(P);
33 }
34
35 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 void restore() override;
47
48 void invalidateCache() override {
50 pressure = NAN;
51 }
52
53 double pressure = NAN; //!< pressure
54 double log10P = 0.0; //!< base 10 logarithm of pressure
55
56protected:
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 */
91class ChebyshevRate final : public ReactionRate
92{
93public:
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
228protected:
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
Header file for class Cantera::Array2D.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition Array.h:32
size_t nRows() const
Number of rows.
Definition Array.h:192
size_t nColumns() const
Number of columns.
Definition Array.h:197
Pressure-dependent rate expression where the rate coefficient is expressed as a bivariate Chebyshev p...
void getParameters(AnyMap &rateNode) const override
Get parameters.
const Array2D & data() const
Access Chebyshev coefficients as 2-dimensional array with temperature and pressure dimensions corresp...
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
double Tmax_
valid temperature range
void setParameters(const AnyMap &node, const UnitStack &rate_units) override
Perform object setup based on AnyMap node information.
double TrDen_
terms appearing in the reduced temperature
void getParameters(AnyMap &rateNode, const Units &rate_units) const
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 validate(const string &equation, const Kinetics &kin) override
Validate the reaction rate expression.
vector< double > dotProd_
dot product of coeffs with the reduced pressure polynomial
void setData(const Array2D &coeffs)
Set the Chebyshev coefficients as 2-dimensional array.
double Tmax() const
Maximum valid temperature [K].
ChebyshevRate()=default
Default constructor.
Array2D m_coeffs
< coefficient array
double Pmax_
valid pressure range
size_t nPressure() const
Number of points in the pressure direction.
double evalFromStruct(const ChebyshevData &shared_data)
Evaluate reaction rate.
double Pmax() const
Maximum valid pressure [Pa].
double PrDen_
terms appearing in the reduced pressure
const string type() const override
String identifying reaction rate specialization.
double m_log10P
value detecting updates
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.
Public interface for kinetics managers.
Definition Kinetics.h:126
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Base class for a phase with thermodynamic properties.
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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
Data container holding shared data specific to ChebyshevRate.
void perturbPressure(double deltaP)
Perturb pressure of data container.
double m_pressure_buf
buffered pressure
double log10P
base 10 logarithm of pressure
void update(double T) override
Update data container based on temperature T
void restore() override
Restore data container after a perturbation.
void invalidateCache() override
Force shared data and reaction rates to be updated next time.
void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
double pressure
pressure
Data container holding shared data used for ReactionRate calculation.
double recipT
inverse of temperature
virtual void update(double T)
Update data container based on temperature T
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Unit aggregation utility.
Definition Units.h:105