Cantera  2.5.1
RxnRates.cpp
Go to the documentation of this file.
1 //! @file RxnRates.cpp
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 
7 #include "cantera/base/Array.h"
8 
9 namespace Cantera
10 {
12  : m_logA(-1.0E300)
13  , m_b(0.0)
14  , m_E(0.0)
15  , m_A(0.0)
16 {
17 }
18 
19 Arrhenius::Arrhenius(doublereal A, doublereal b, doublereal E)
20  : m_b(b)
21  , m_E(E)
22  , m_A(A)
23 {
24  if (m_A <= 0.0) {
25  m_logA = -1.0E300;
26  } else {
27  m_logA = std::log(m_A);
28  }
29 }
30 
31 SurfaceArrhenius::SurfaceArrhenius()
32  : m_b(0.0)
33  , m_E(0.0)
34  , m_A(0.0)
35  , m_acov(0.0)
36  , m_ecov(0.0)
37  , m_mcov(0.0)
38 {
39 }
40 
41 SurfaceArrhenius::SurfaceArrhenius(double A, double b, double Ta)
42  : m_b(b)
43  , m_E(Ta)
44  , m_A(A)
45  , m_acov(0.0)
46  , m_ecov(0.0)
47  , m_mcov(0.0)
48 {
49 }
50 
51 void SurfaceArrhenius::addCoverageDependence(size_t k, doublereal a,
52  doublereal m, doublereal e)
53 {
54  m_sp.push_back(k);
55  m_ac.push_back(a);
56  m_ec.push_back(e);
57  if (m != 0.0) {
58  m_msp.push_back(k);
59  m_mc.push_back(m);
60  }
61 }
62 
63 Plog::Plog(const std::multimap<double, Arrhenius>& rates)
64  : logP_(-1000)
65  , logP1_(1000)
66  , logP2_(-1000)
67  , rDeltaP_(-1.0)
68 {
69  size_t j = 0;
70  rates_.reserve(rates.size());
71  // Insert intermediate pressures
72  for (const auto& rate : rates) {
73  double logp = std::log(rate.first);
74  if (pressures_.empty() || pressures_.rbegin()->first != logp) {
75  // starting a new group
76  pressures_[logp] = {j, j+1};
77  } else {
78  // another rate expression at the same pressure
79  pressures_[logp].second = j+1;
80  }
81 
82  j++;
83  rates_.push_back(rate.second);
84  }
85 
86  // Duplicate the first and last groups to handle P < P_0 and P > P_N
87  pressures_.insert({-1000.0, pressures_.begin()->second});
88  pressures_.insert({1000.0, pressures_.rbegin()->second});
89 }
90 
91 void Plog::validate(const std::string& equation)
92 {
93  fmt::memory_buffer err_reactions;
94  double T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0};
95 
96  for (auto iter = ++pressures_.begin(); iter->first < 1000; iter++) {
97  update_C(&iter->first);
98  for (size_t i=0; i < 6; i++) {
99  double k = 0;
100  for (size_t p = ilow1_; p < ilow2_; p++) {
101  k += rates_[p].updateRC(log(T[i]), 1.0/T[i]);
102  }
103  if (k < 0) {
104  format_to(err_reactions,
105  "\nInvalid rate coefficient for reaction '{}'\n"
106  "at P = {:.5g}, T = {:.1f}\n",
107  equation, std::exp(iter->first), T[i]);
108  }
109  }
110  }
111  if (err_reactions.size()) {
112  throw CanteraError("Plog::validate", to_string(err_reactions));
113  }
114 }
115 
116 std::vector<std::pair<double, Arrhenius> > Plog::rates() const
117 {
118  std::vector<std::pair<double, Arrhenius> > R;
119  // initial preincrement to skip rate for P --> 0
120  for (auto iter = ++pressures_.begin();
121  iter->first < 1000; // skip rates for (P --> infinity)
122  ++iter) {
123  for (size_t i = iter->second.first;
124  i < iter->second.second;
125  i++) {
126  R.emplace_back(std::exp(iter->first), rates_[i]);
127  }
128  }
129  return R;
130 }
131 
132 
133 ChebyshevRate::ChebyshevRate(double Tmin, double Tmax, double Pmin, double Pmax,
134  const Array2D& coeffs)
135  : Tmin_(Tmin)
136  , Tmax_(Tmax)
137  , Pmin_(Pmin)
138  , Pmax_(Pmax)
139  , nP_(coeffs.nColumns())
140  , nT_(coeffs.nRows())
141  , chebCoeffs_(coeffs.nColumns() * coeffs.nRows(), 0.0)
142  , dotProd_(coeffs.nRows())
143 {
144  double logPmin = std::log10(Pmin);
145  double logPmax = std::log10(Pmax);
146  double TminInv = 1.0 / Tmin;
147  double TmaxInv = 1.0 / Tmax;
148 
149  TrNum_ = - TminInv - TmaxInv;
150  TrDen_ = 1.0 / (TmaxInv - TminInv);
151  PrNum_ = - logPmin - logPmax;
152  PrDen_ = 1.0 / (logPmax - logPmin);
153 
154  for (size_t t = 0; t < nT_; t++) {
155  for (size_t p = 0; p < nP_; p++) {
156  chebCoeffs_[nP_*t + p] = coeffs(t,p);
157  }
158  }
159 }
160 
161 }
Header file for class Cantera::Array2D.
A class for 2D arrays stored in column-major (Fortran-compatible) form.
Definition: Array.h:32
Arrhenius()
Default constructor.
Definition: RxnRates.cpp:11
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
ChebyshevRate()
Default constructor.
Definition: RxnRates.h:369
double TrDen_
terms appearing in the reduced temperature
Definition: RxnRates.h:466
double Pmin() const
Minimum valid pressure [Pa].
Definition: RxnRates.h:435
double Tmin() const
Minimum valid temperature [K].
Definition: RxnRates.h:425
double Tmax() const
Maximum valid temperature [K].
Definition: RxnRates.h:430
size_t nP_
number of points in the pressure direction
Definition: RxnRates.h:469
const vector_fp & coeffs() const
Access the Chebyshev coefficients.
Definition: RxnRates.h:459
size_t nT_
number of points in the temperature direction
Definition: RxnRates.h:470
double Pmax() const
Maximum valid pressure [Pa].
Definition: RxnRates.h:440
double PrDen_
terms appearing in the reduced pressure
Definition: RxnRates.h:467
vector_fp chebCoeffs_
Chebyshev coefficients, length nP * nT.
Definition: RxnRates.h:471
void update_C(const doublereal *c)
Update concentration-dependent parts of the rate coefficient.
Definition: RxnRates.h:242
std::vector< std::pair< double, Arrhenius > > rates() const
Return the pressures and Arrhenius expressions which comprise this reaction.
Definition: RxnRates.cpp:116
std::map< double, std::pair< size_t, size_t > > pressures_
log(p) to (index range) in the rates_ vector
Definition: RxnRates.h:309
Plog()
Default constructor.
Definition: RxnRates.h:235
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:91
size_t ilow1_
Indices to the ranges within rates_ for the lower / upper pressure, such that rates_[ilow1_] through ...
Definition: RxnRates.h:321
void addCoverageDependence(size_t k, doublereal a, doublereal m, doublereal e)
Add a coverage dependency for species k, with exponential dependence a, power-law exponent m,...
Definition: RxnRates.cpp:51
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264