Cantera  2.0
FalloffMgr.h
Go to the documentation of this file.
1 /**
2  * @file FalloffMgr.h
3  */
4 
5 // Copyright 2001 California Institute of Technology
6 
7 #ifndef CT_FALLOFFMGR_H
8 #define CT_FALLOFFMGR_H
9 
10 #include "reaction_defs.h"
11 #include "FalloffFactory.h"
12 
13 namespace Cantera
14 {
15 
16 /**
17  * A falloff manager that implements any set of falloff functions.
18  * @ingroup falloffGroup
19  */
21 {
22 public:
23 
24  //! Constructor.
25  FalloffMgr(/*FalloffFactory* f = 0*/) :
26  m_n(0), m_n0(0), m_worksize(0) {
27  //if (f == 0)
28  m_factory = FalloffFactory::factory(); // RFB:TODO This raw pointer should be encapsulated
29  // because accessing a 'Singleton Factory'
30  //else m_factory = f;
31  }
32 
33  /**
34  * Destructor. Deletes all installed falloff function
35  * calculators.
36  */
37  virtual ~FalloffMgr() {
38  int i;
39  for (i = 0; i < m_n; i++) {
40  delete m_falloff[i];
41  }
42  //if (m_factory) {
43  //FalloffFactory::deleteFalloffFactory();
44  //m_factory = 0;
45  //}
46  }
47 
48  /**
49  * Install a new falloff function calculator. @param rxn
50  * Index of the falloff reaction. This will be used to determine
51  * which array entry is modified in method pr_to_falloff.
52  *
53  * @param type of falloff function to install.
54  * @param c vector of coefficients for the falloff function.
55  */
56  void install(size_t rxn, int type,
57  const vector_fp& c) {
58  if (type != SIMPLE_FALLOFF) {
59  m_rxn.push_back(rxn);
60  Falloff* f = m_factory->newFalloff(type,c);
61  m_offset.push_back(m_worksize);
62  m_worksize += f->workSize();
63  m_falloff.push_back(f);
64  m_n++;
65  } else {
66  m_rxn0.push_back(rxn);
67  m_n0++;
68  }
69  }
70 
71  /**
72  * Size of the work array required to store intermediate results.
73  */
74  size_t workSize() {
75  return m_worksize;
76  }
77 
78  /**
79  * Update the cached temperature-dependent intermediate
80  * results for all installed falloff functions.
81  * @param t Temperature [K].
82  * @param work Work array. Must be dimensioned at least workSize().
83  */
84  void updateTemp(doublereal t, doublereal* work) {
85  int i;
86  for (i = 0; i < m_n; i++) {
87  m_falloff[i]->updateTemp(t,
88  work + m_offset[i]);
89  }
90  }
91 
92  /**
93  * Given a vector of reduced pressures for each falloff reaction,
94  * replace each entry by the value of the falloff function.
95  */
96  void pr_to_falloff(doublereal* values, const doublereal* work) {
97  doublereal pr;
98  int i;
99  for (i = 0; i < m_n0; i++) {
100  values[m_rxn0[i]] /= (1.0 + values[m_rxn0[i]]);
101  }
102  for (i = 0; i < m_n; i++) {
103  pr = values[m_rxn[i]];
104  values[m_rxn[i]] *=
105  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
106  }
107  }
108 
109 protected:
110  std::vector<size_t> m_rxn, m_rxn0;
111  std::vector<Falloff*> m_falloff;
112  FalloffFactory* m_factory;
113  vector_int m_loc;
114  int m_n, m_n0;
115  std::vector<vector_fp::difference_type> m_offset;
116  size_t m_worksize;
117 };
118 }
119 
120 #endif
121