Cantera  3.1.0a1
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 
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 {
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 
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  void validate(const string& equation, const Kinetics& kin) override;
128 
129  //! Update information specific to reaction
130  /*!
131  * @param shared_data data shared by all reactions of a given type
132  */
133  void updateFromStruct(const ChebyshevData& shared_data) {
134  if (shared_data.log10P != m_log10P) {
135  m_log10P = shared_data.log10P;
136  double Pr = (2 * shared_data.log10P + PrNum_) * PrDen_;
137  double Cnm1 = Pr;
138  double Cn = 1;
139  double Cnp1;
140  for (size_t i = 0; i < m_coeffs.nRows(); i++) {
141  dotProd_[i] = m_coeffs(i, 0);
142  }
143  for (size_t j = 1; j < m_coeffs.nColumns(); j++) {
144  Cnp1 = 2 * Pr * Cn - Cnm1;
145  for (size_t i = 0; i < m_coeffs.nRows(); i++) {
146  dotProd_[i] += Cnp1 * m_coeffs(i, j);
147  }
148  Cnm1 = Cn;
149  Cn = Cnp1;
150  }
151  }
152  }
153 
154  //! Evaluate reaction rate
155  /*!
156  * @param shared_data data shared by all reactions of a given type
157  */
158  double evalFromStruct(const ChebyshevData& shared_data) {
159  double Tr = (2 * shared_data.recipT + TrNum_) * TrDen_;
160  double Cnm1 = Tr;
161  double Cn = 1;
162  double Cnp1;
163  double logk = dotProd_[0];
164  for (size_t i = 1; i < m_coeffs.nRows(); i++) {
165  Cnp1 = 2 * Tr * Cn - Cnm1;
166  logk += Cnp1 * dotProd_[i];
167  Cnm1 = Cn;
168  Cn = Cnp1;
169  }
170  return std::pow(10, logk);
171  }
172 
173  //! Set limits for ChebyshevRate object
174  /*!
175  * @param Tmin Minimum temperature [K]
176  * @param Tmax Maximum temperature [K]
177  * @param Pmin Minimum pressure [Pa]
178  * @param Pmax Maximum pressure [Pa]
179  */
180  void setLimits(double Tmin, double Tmax, double Pmin, double Pmax);
181 
182  //! Minimum valid temperature [K]
183  double Tmin() const {
184  return Tmin_;
185  }
186 
187  //! Maximum valid temperature [K]
188  double Tmax() const {
189  return Tmax_;
190  }
191 
192  //! Minimum valid pressure [Pa]
193  double Pmin() const {
194  return Pmin_;
195  }
196 
197  //! Maximum valid pressure [Pa]
198  double Pmax() const {
199  return Pmax_;
200  }
201 
202  //! Number of points in the pressure direction
203  size_t nPressure() const {
204  return m_coeffs.nColumns();
205  }
206 
207  //! Number of points in the temperature direction
208  size_t nTemperature() const {
209  return m_coeffs.nRows();
210  }
211 
212  //! Access Chebyshev coefficients as 2-dimensional array with temperature and
213  //! pressure dimensions corresponding to rows and columns, respectively.
214  const Array2D& data() const {
215  return m_coeffs;
216  }
217 
218  //! Set the Chebyshev coefficients as 2-dimensional array.
219  void setData(const Array2D& coeffs);
220 
221 protected:
222  double m_log10P = NAN; //!< value detecting updates
223  double Tmin_, Tmax_; //!< valid temperature range
224  double Pmin_, Pmax_; //!< valid pressure range
225  double TrNum_, TrDen_; //!< terms appearing in the reduced temperature
226  double PrNum_, PrDen_; //!< terms appearing in the reduced pressure
227 
228  Array2D m_coeffs; //!<< coefficient array
229  vector<double> dotProd_; //!< dot product of coeffs with the reduced pressure polynomial
230 };
231 
232 }
233 
234 #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:176
size_t nColumns() const
Number of columns.
Definition: Array.h:181
Pressure-dependent rate expression where the rate coefficient is expressed as a bivariate Chebyshev p...
Definition: ChebyshevRate.h:92
void getParameters(AnyMap &rateNode) const override
Get parameters.
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 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.
unique_ptr< MultiRateBase > newMultiRate() const override
Create a rate evaluator for reactions of a particular derived type.
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.
const Array2D & data() const
Access Chebyshev coefficients as 2-dimensional array with temperature and pressure dimensions corresp...
Public interface for kinetics managers.
Definition: Kinetics.h:125
Abstract base class for reaction rate definitions; this base class is used by user-facing APIs to acc...
Definition: ReactionRate.h:49
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564
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)
Update data container based on temperature T
Definition: ReactionData.h:36
void restore() override
Restore data container after a perturbation.
void invalidateCache() override
Force shared data and reaction rates to be updated next time.
Definition: ChebyshevRate.h:48
void update(double T, double P) override
Update data container based on temperature T and an extra parameter.
Definition: ChebyshevRate.h:29
double pressure
pressure
Definition: ChebyshevRate.h:53
Data container holding shared data used for ReactionRate calculation.
Definition: ReactionData.h:27
double recipT
inverse of temperature
Definition: ReactionData.h:112
virtual void update(double T)
Update data container based on temperature T
Definition: ReactionData.h:36
virtual void invalidateCache()
Force shared data and reaction rates to be updated next time.
Definition: ReactionData.h:106
Unit aggregation utility.
Definition: Units.h:105