Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RxnRates.cpp
Go to the documentation of this file.
1 //! @file RxnRates.cpp
2 
4 #include "cantera/base/Array.h"
5 
6 namespace Cantera
7 {
9  : m_logA(-1.0E300)
10  , m_b(0.0)
11  , m_E(0.0)
12  , m_A(0.0)
13 {
14 }
15 
17  : m_b(rdata.rateCoeffParameters[1])
18  , m_E(rdata.rateCoeffParameters[2])
19  , m_A(rdata.rateCoeffParameters[0])
20 {
21  if (m_A <= 0.0) {
22  m_logA = -1.0E300;
23  } else {
24  m_logA = std::log(m_A);
25  }
26 }
27 
28 Arrhenius::Arrhenius(doublereal A, doublereal b, doublereal E)
29  : m_b(b)
30  , m_E(E)
31  , m_A(A)
32 {
33  if (m_A <= 0.0) {
34  m_logA = -1.0E300;
35  } else {
36  m_logA = log(m_A);
37  }
38 }
39 
40 SurfaceArrhenius::SurfaceArrhenius()
41  : m_logA(-1.0E300)
42  , m_b(0.0)
43  , m_E(0.0)
44  , m_A(0.0)
45  , m_acov(0.0)
46  , m_ecov(0.0)
47  , m_mcov(0.0)
48  , m_ncov(0)
49  , m_nmcov(0)
50 {
51 }
52 
53 SurfaceArrhenius::SurfaceArrhenius(double A, double b, double Ta)
54  : m_logA(std::log(A))
55  , m_b(b)
56  , m_E(Ta)
57  , m_A(A)
58  , m_acov(0.0)
59  , m_ecov(0.0)
60  , m_mcov(0.0)
61  , m_ncov(0)
62  , m_nmcov(0)
63 {
64 }
65 
66 SurfaceArrhenius::SurfaceArrhenius(const ReactionData& rdata)
67  : m_b(rdata.rateCoeffParameters[1])
68  , m_E(rdata.rateCoeffParameters[2])
69  , m_A(rdata.rateCoeffParameters[0])
70  , m_acov(0.0)
71  , m_ecov(0.0)
72  , m_mcov(0.0)
73  , m_ncov(0)
74  , m_nmcov(0)
75 {
76  if (m_A <= 0.0) {
77  m_logA = -1.0E300;
78  } else {
79  m_logA = std::log(m_A);
80  }
81 
82  const vector_fp& data = rdata.rateCoeffParameters;
83  if (data.size() >= 7) {
84  for (size_t n = 3; n < data.size()-3; n += 4) {
85  addCoverageDependence(size_t(data[n]), data[n+1],
86  data[n+2], data[n+3]);
87  }
88  }
89 }
90 
91 void SurfaceArrhenius::addCoverageDependence(size_t k, doublereal a,
92  doublereal m, doublereal e) {
93  m_ncov++;
94  m_sp.push_back(k);
95  m_ac.push_back(a);
96  m_ec.push_back(e);
97  if (m != 0.0) {
98  m_msp.push_back(k);
99  m_mc.push_back(m);
100  m_nmcov++;
101  }
102  }
103 
105  : m_logA(-1.0E300)
106  , m_b(0.0)
107  , m_E(0.0)
108  , m_A(0.0)
109 {
110  warn_deprecated("class ExchangeCurrent", "Duplicate of class Arrhenius."
111  " To be removed after Cantera 2.2.");
112 }
113 
115  : m_b(rdata.rateCoeffParameters[1])
116  , m_E(rdata.rateCoeffParameters[2])
117  , m_A(rdata.rateCoeffParameters[0])
118 {
119  warn_deprecated("class ExchangeCurrent", "Duplicate of class Arrhenius."
120  " To be removed after Cantera 2.2.");
121  if (m_A <= 0.0) {
122  m_logA = -1.0E300;
123  } else {
124  m_logA = std::log(m_A);
125  }
126 }
127 
128 ExchangeCurrent::ExchangeCurrent(doublereal A, doublereal b, doublereal E)
129  : m_b(b)
130  , m_E(E)
131  , m_A(A)
132 {
133  warn_deprecated("class ExchangeCurrent", "Duplicate of class Arrhenius."
134  " To be removed after Cantera 2.2.");
135  if (m_A <= 0.0) {
136  m_logA = -1.0E300;
137  } else {
138  m_logA = std::log(m_A);
139  }
140 }
141 
143  : logP_(-1000)
144  , logP1_(1000)
145  , logP2_(-1000)
146  , rDeltaP_(-1.0)
147 {
148  typedef std::multimap<double, vector_fp>::const_iterator iter_t;
149 
150  size_t j = 0;
151  // Insert intermediate pressures
152  rates_.reserve(rdata.plogParameters.size());
153  for (iter_t iter = rdata.plogParameters.begin();
154  iter != rdata.plogParameters.end();
155  iter++) {
156  double logp = std::log(iter->first);
157  if (pressures_.empty() || pressures_.rbegin()->first != logp) {
158  // starting a new group
159  pressures_[logp] = std::make_pair(j, j+1);
160  } else {
161  // another rate expression at the same pressure
162  pressures_[logp].second = j+1;
163  }
164 
165  j++;
166  rates_.push_back(Arrhenius(iter->second[0], iter->second[1],
167  iter->second[2]));
168  }
169 
170  // Duplicate the first and last groups to handle P < P_0 and P > P_N
171  pressures_.insert(std::make_pair(-1000.0, pressures_.begin()->second));
172  pressures_.insert(std::make_pair(1000.0, pressures_.rbegin()->second));
173 
174  if (rdata.validate) {
175  validate(rdata.equation);
176  }
177 }
178 
179 Plog::Plog(const std::multimap<double, Arrhenius>& rates)
180  : logP_(-1000)
181  , logP1_(1000)
182  , logP2_(-1000)
183  , rDeltaP_(-1.0)
184 {
185  size_t j = 0;
186  rates_.reserve(rates.size());
187  // Insert intermediate pressures
188  for (std::multimap<double, Arrhenius>::const_iterator iter = rates.begin();
189  iter != rates.end();
190  iter++) {
191  double logp = std::log(iter->first);
192  if (pressures_.empty() || pressures_.rbegin()->first != logp) {
193  // starting a new group
194  pressures_[logp] = std::make_pair(j, j+1);
195  } else {
196  // another rate expression at the same pressure
197  pressures_[logp].second = j+1;
198  }
199 
200  j++;
201  rates_.push_back(iter->second);
202  }
203 
204  // Duplicate the first and last groups to handle P < P_0 and P > P_N
205  pressures_.insert(std::make_pair(-1000.0, pressures_.begin()->second));
206  pressures_.insert(std::make_pair(1000.0, pressures_.rbegin()->second));
207 }
208 
209 void Plog::validate(const std::string& equation)
210 {
211  double T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0};
212  for (pressureIter iter = pressures_.begin();
213  iter->first < 1000;
214  iter++) {
215  update_C(&iter->first);
216  for (size_t i=0; i < 6; i++) {
217  double k = updateRC(log(T[i]), 1.0/T[i]);
218  if (!(k >= 0)) {
219  // k is NaN. Increment the iterator so that the error
220  // message will correctly indicate that the problematic rate
221  // expression is at the higher of the adjacent pressures.
222  throw CanteraError("Plog::validate",
223  "Invalid rate coefficient for reaction '" + equation +
224  "'\nat P = " + fp2str(std::exp((++iter)->first)) +
225  ", T = " + fp2str(T[i]));
226  }
227  }
228  }
229 }
230 
231 std::vector<std::pair<double, Arrhenius> > Plog::rates() const
232 {
233  std::vector<std::pair<double, Arrhenius> > R;
234  // initial preincrement to skip rate for P --> 0
235  for (std::map<double, std::pair<size_t, size_t> >::const_iterator iter = ++pressures_.begin();
236  iter->first < 1000; // skip rates for (P --> infinity)
237  ++iter) {
238  for (size_t i = iter->second.first;
239  i < iter->second.second;
240  i++) {
241  R.push_back(std::make_pair(std::exp(iter->first), rates_[i]));
242  }
243  }
244  return R;
245 }
246 
248  : Tmin_(rdata.chebTmin)
249  , Tmax_(rdata.chebTmax)
250  , Pmin_(rdata.chebPmin)
251  , Pmax_(rdata.chebPmax)
252  , nP_(rdata.chebDegreeP)
253  , nT_(rdata.chebDegreeT)
254  , chebCoeffs_(rdata.chebCoeffs)
255  , dotProd_(rdata.chebDegreeT)
256 {
257  double logPmin = std::log10(rdata.chebPmin);
258  double logPmax = std::log10(rdata.chebPmax);
259  double TminInv = 1.0 / rdata.chebTmin;
260  double TmaxInv = 1.0 / rdata.chebTmax;
261 
262  TrNum_ = - TminInv - TmaxInv;
263  TrDen_ = 1.0 / (TmaxInv - TminInv);
264  PrNum_ = - logPmin - logPmax;
265  PrDen_ = 1.0 / (logPmax - logPmin);
266 }
267 
268 ChebyshevRate::ChebyshevRate(double Tmin, double Tmax, double Pmin, double Pmax,
269  const Array2D& coeffs)
270  : Tmin_(Tmin)
271  , Tmax_(Tmax)
272  , Pmin_(Pmin)
273  , Pmax_(Pmax)
274  , nP_(coeffs.nColumns())
275  , nT_(coeffs.nRows())
276  , chebCoeffs_(coeffs.nColumns() * coeffs.nRows(), 0.0)
277  , dotProd_(coeffs.nRows())
278 {
279  double logPmin = std::log10(Pmin);
280  double logPmax = std::log10(Pmax);
281  double TminInv = 1.0 / Tmin;
282  double TmaxInv = 1.0 / Tmax;
283 
284  TrNum_ = - TminInv - TmaxInv;
285  TrDen_ = 1.0 / (TmaxInv - TminInv);
286  PrNum_ = - logPmin - logPmax;
287  PrDen_ = 1.0 / (logPmax - logPmin);
288 
289  for (size_t t = 0; t < nT_; t++) {
290  for (size_t p = 0; p < nP_; p++) {
291  chebCoeffs_[nP_*t + p] = coeffs(t,p);
292  }
293  }
294 }
295 
296 }
Plog()
Default constructor.
Definition: RxnRates.h:328
const vector_fp & coeffs() const
Access the Chebyshev coefficients.
Definition: RxnRates.h:563
void addCoverageDependence(size_t k, doublereal a, doublereal m, doublereal e)
Add a coverage dependency for species k, with pre-exponential dependence a, temperature exponent depe...
Definition: RxnRates.cpp:91
size_t nP_
number of points in the pressure direction
Definition: RxnRates.h:573
std::multimap< double, vector_fp > plogParameters
Arrhenius parameters for P-log reactions.
Definition: ReactionData.h:207
double chebPmin
Minimum pressure for Chebyshev fit.
Definition: ReactionData.h:211
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
bool validate
Perform validation of the rate coefficient data.
Definition: ReactionData.h:60
Arrhenius()
Default constructor.
Definition: RxnRates.cpp:8
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:29
std::vector< std::pair< double, Arrhenius > > rates() const
Return the pressures and Arrhenius expressions which comprise this reaction.
Definition: RxnRates.cpp:231
Header file for class Cantera::Array2D.
std::string equation
The reaction equation. Used only for display purposes.
Definition: ReactionData.h:170
double chebPmax
Maximum pressure for Chebyshev fit.
Definition: ReactionData.h:212
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
Intermediate class which stores data about a reaction and its rate parameterization before adding the...
Definition: ReactionData.h:22
double TrDen_
terms appearing in the reduced temperature
Definition: RxnRates.h:570
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
void validate(const std::string &equation)
Check to make sure that the rate expression is finite over a range of temperatures at each interpolat...
Definition: RxnRates.cpp:209
void update_C(const doublereal *c)
Update concentration-dependent parts of the rate coefficient.
Definition: RxnRates.h:338
Arrhenius reaction rate type depends only on temperature.
Definition: RxnRates.h:31
double Tmax() const
Maximum valid temperature [K].
Definition: RxnRates.h:534
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:157
size_t nT_
number of points in the temperature direction
Definition: RxnRates.h:574
std::map< double, std::pair< size_t, size_t > > pressures_
log(p) to (index range) in the rates_ vector
Definition: RxnRates.h:423
ChebyshevRate()
Default constructor.
Definition: RxnRates.h:452
doublereal updateRC(doublereal logT, doublereal recipT) const
Update the value the rate constant.
Definition: RxnRates.h:376
ExchangeCurrent()
Default constructor.
Definition: RxnRates.cpp:104
double PrDen_
terms appearing in the reduced pressure
Definition: RxnRates.h:571
double chebTmax
Maximum temperature for Chebyshev fit.
Definition: ReactionData.h:210
vector_fp chebCoeffs_
Chebyshev coefficients, length nP * nT.
Definition: RxnRates.h:575
double Tmin() const
Minimum valid temperature [K].
Definition: RxnRates.h:529
double chebTmin
Minimum temperature for Chebyshev fit.
Definition: ReactionData.h:209