Cantera  2.5.1
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 https://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/ct_defs.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  for (size_t i = 0; i < m_reaction_index.size(); i++) {
48  output[m_reaction_index[i]] *= work[i];
49  }
50  }
51 
52  size_t workSize() {
53  return m_reaction_index.size();
54  }
55 
56 protected:
57  //! Indices of third-body reactions within the full reaction array
58  std::vector<size_t> m_reaction_index;
59 
60  //! m_species[i][j] is the index of the j-th species in reaction i.
61  std::vector<std::vector<size_t> > m_species;
62 
63  //! m_eff[i][j] is the efficiency of the j-th species in reaction i.
64  std::vector<vector_fp> m_eff;
65 
66  //! The default efficiency for each reaction
68 };
69 
70 }
71 
72 #endif
Calculate and apply third-body effects on reaction rates, including non- unity third-body efficiencie...
Definition: ThirdBodyCalc.h:20
std::vector< size_t > m_reaction_index
Indices of third-body reactions within the full reaction array.
Definition: ThirdBodyCalc.h:58
vector_fp m_default
The default efficiency for each reaction.
Definition: ThirdBodyCalc.h:67
std::vector< vector_fp > m_eff
m_eff[i][j] is the efficiency of the j-th species in reaction i.
Definition: ThirdBodyCalc.h:64
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:61
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
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:180
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264