Cantera  2.3.0
ThirdBodyCalc.h
Go to the documentation of this file.
1 /**
2  * @file ThirdBodyCalc.h
3  */
4 
5 // This file is part of Cantera. See License.txt in the top-level directory or
6 // at http://www.cantera.org/license.txt for license and copyright information.
7 
8 #ifndef CT_THIRDBODYCALC_H
9 #define CT_THIRDBODYCALC_H
10 
11 #include "cantera/base/utilities.h"
12 #include <cassert>
13 
14 namespace Cantera
15 {
16 
17 //! Calculate and apply third-body effects on reaction rates, including non-
18 //! unity third-body efficiencies.
20 {
21 public:
22  void install(size_t rxnNumber, const std::map<size_t, double>& enhanced,
23  double dflt=1.0) {
24  m_reaction_index.push_back(rxnNumber);
25  m_default.push_back(dflt);
26 
27  m_species.emplace_back();
28  m_eff.emplace_back();
29  for (const auto& eff : enhanced) {
30  assert(eff.first != npos);
31  m_species.back().push_back(eff.first);
32  m_eff.back().push_back(eff.second - dflt);
33  }
34  }
35 
36  void update(const vector_fp& conc, double ctot, double* work) {
37  for (size_t i = 0; i < m_species.size(); i++) {
38  double sum = 0.0;
39  for (size_t j = 0; j < m_species[i].size(); j++) {
40  sum += m_eff[i][j] * conc[m_species[i][j]];
41  }
42  work[i] = m_default[i] * ctot + sum;
43  }
44  }
45 
46  void multiply(double* output, const double* work) {
47  scatter_mult(work, work + m_reaction_index.size(),
48  output, m_reaction_index.begin());
49  }
50 
51  size_t workSize() {
52  return m_reaction_index.size();
53  }
54 
55 protected:
56  //! Indices of third-body reactions within the full reaction array
57  std::vector<size_t> m_reaction_index;
58 
59  //! m_species[i][j] is the index of the j-th species in reaction i.
60  std::vector<std::vector<size_t> > m_species;
61 
62  //! m_eff[i][j] is the efficiency of the j-th species in reaction i.
63  std::vector<vector_fp> m_eff;
64 
65  //! The default efficiency for each reaction
67 };
68 
69 }
70 
71 #endif
vector_fp m_default
The default efficiency for each reaction.
Definition: ThirdBodyCalc.h:66
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
Definition: ThirdBodyCalc.h:19
void scatter_mult(InputIter mult_begin, InputIter mult_end, RandAccessIter data, IndexIter index)
Multiply selected elements in an array by a contiguous sequence of multipliers.
Definition: utilities.h:367
std::vector< std::vector< size_t > > m_species
m_species[i][j] is the index of the j-th species in reaction i.
Definition: ThirdBodyCalc.h:60
std::vector< vector_fp > m_eff
m_eff[i][j] is the efficiency of the j-th species in reaction i.
Definition: ThirdBodyCalc.h:63
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
Namespace for the Cantera kernel.
Definition: application.cpp:29
std::vector< size_t > m_reaction_index
Indices of third-body reactions within the full reaction array.
Definition: ThirdBodyCalc.h:57