Cantera  2.0
RateCoeffMgr.h
Go to the documentation of this file.
1 /**
2  * @file RateCoeffMgr.h
3  */
4 // Copyright 2001 California Institute of Technology
5 
6 
7 #ifndef CT_RATECOEFF_MGR_H
8 #define CT_RATECOEFF_MGR_H
9 
10 #include "cantera/base/utilities.h"
11 #include "RxnRates.h"
12 
13 #include "cantera/base/ct_defs.h"
16 
17 namespace Cantera
18 {
19 
20 /**
21  * This rate coefficient manager supports one parameterization of
22  * the rate constant of any type.
23  */
24 template<class R>
25 class Rate1
26 {
27 
28 public:
29 
30  Rate1() {}
31  virtual ~Rate1() {}
32 
33  /**
34  * Install a rate coefficient calculator.
35  * @param rxnNumber the reaction number
36  * @param rdata rate coefficient specification for the reaction
37  */
38  size_t install(size_t rxnNumber, const ReactionData& rdata) {
39  /*
40  * Check to see if the current reaction rate type is the same as the
41  * type of this class. If not, throw an error condition.
42  */
43  if (rdata.rateCoeffType != R::type())
44  throw CanteraError("Rate1::install",
45  "incorrect rate coefficient type: "+int2str(rdata.rateCoeffType) + ". Was Expecting type: "+ int2str(R::type()));
46 
47  // Install a rate calculator and return the index of the calculator.
48  m_rxn.push_back(rxnNumber);
49  m_rates.push_back(R(rdata));
50  return m_rates.size() - 1;
51  }
52 
53  /**
54  * Return a reference to the nth rate coefficient calculator.
55  * Note that this is not the same as the calculator for
56  * reaction n, since reactions with constant rate coefficients
57  * do not have a calculator.
58  */
59  const R& rateCoeff(int loc) const {
60  return m_rates[loc];
61  }
62 
63  /**
64  * Update the concentration-dependent parts of the rate
65  * coefficient, if any. Used by class SurfaceArrhenius to
66  * compute coverage-dependent * modifications to the Arrhenius
67  * parameters. The array c should contain whatever data the
68  * particular rate coefficient class needs to update its
69  * rates. Note that this method does not return anything. To
70  * get the updated rates, method update must be called after
71  * the call to update_C.
72  */
73  void update_C(const doublereal* c) {
74  typename std::vector<R>::iterator b = m_rates.begin();
75  typename std::vector<R>::iterator e = m_rates.end();
76  int i = 0;
77  for (; b != e; ++b, ++i) {
78  b->update_C(c);
79  }
80  }
81 
82  /**
83  * Write the rate coefficients into array values. Each
84  * calculator writes one entry in values, at the location
85  * specified by the reaction number when it was
86  * installed. Note that nothing will be done for reactions
87  * that have constant rates. The array values should be
88  * preloaded with the constant rate coefficients.
89  */
90  void update(doublereal T, doublereal logT, doublereal* values) {
91  typename std::vector<R>::const_iterator b = m_rates.begin();
92  typename std::vector<R>::const_iterator e = m_rates.end();
93  doublereal recipT = 1.0/T;
94  int i = 0;
95  for (; b != e; ++b, ++i) {
96  // values[m_rxn[i]] = exp(b->update(logT, recipT));
97  values[m_rxn[i]] = b->updateRC(logT, recipT);
98  }
99  }
100 
101  void writeUpdate(std::ostream& output1, std::string key) {
102  output1 << key;
103  }
104 
105  size_t nReactions() const {
106  return m_rates.size();
107  }
108 
109 protected:
110  std::vector<R> m_rates;
111  std::vector<size_t> m_rxn;
112  vector_fp m_const; //!< @deprecated not used
113 };
114 
115 
116 
117 /**
118  * This rate coefficient manager supports two parameterizations of
119  * any type.
120  */
121 template<class R1, class R2>
122 class Rate2
123 {
124 public:
125 
126  Rate2() {}
127  virtual ~Rate2() {}
128 
129  int install(size_t rxnNumber, int rateType, size_t m,
130  const doublereal* c) {
131  if (rateType == R1::type()) {
132  return m_r1.install(rxnNumber, rateType, m, c);
133  } else if (rateType == R2::type()) {
134  return m_r2.install(rxnNumber, rateType, m, c);
135  } else
136  throw CanteraError("Rate2::install",
137  "unknown rate coefficient type");
138  return -1;
139  }
140 
141  void update(doublereal T, doublereal logT,
142  doublereal* values) {
143  m_r1.update(T, logT, values);
144  m_r2.update(T, logT, values);
145  }
146 
147 protected:
148 
149  Rate1<R1> m_r1;
150  Rate1<R2> m_r2;
151 };
152 
153 }
154 
155 #endif