Cantera  2.1.2
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  //! Constructor.
24  FalloffMgr(/*FalloffFactory* f = 0*/) :
25  m_worksize(0) {
26  //if (f == 0)
27  m_factory = FalloffFactory::factory(); // RFB:TODO This raw pointer should be encapsulated
28  // because accessing a 'Singleton Factory'
29  //else m_factory = f;
30  }
31 
32  //! Destructor. Deletes all installed falloff function calculators.
33  virtual ~FalloffMgr() {
34  for (size_t i = 0; i < m_falloff.size(); i++) {
35  delete m_falloff[i];
36  }
37  //if (m_factory) {
38  //FalloffFactory::deleteFalloffFactory();
39  //m_factory = 0;
40  //}
41  }
42 
43  //! Install a new falloff function calculator.
44  /*
45  * @param rxn Index of the falloff reaction. This will be used to
46  * determine which array entry is modified in method pr_to_falloff.
47  * @param falloffType of falloff function to install.
48  * @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
49  * @param c vector of coefficients for the falloff function.
50  */
51  void install(size_t rxn, int falloffType, int reactionType,
52  const vector_fp& c) {
53  m_rxn.push_back(rxn);
54  Falloff* f = m_factory->newFalloff(falloffType,c);
55  m_offset.push_back(m_worksize);
56  m_worksize += f->workSize();
57  m_falloff.push_back(f);
58  m_reactionType.push_back(reactionType);
59  }
60 
61  //! Size of the work array required to store intermediate results.
62  size_t workSize() {
63  return m_worksize;
64  }
65 
66  /**
67  * Update the cached temperature-dependent intermediate
68  * results for all installed falloff functions.
69  * @param t Temperature [K].
70  * @param work Work array. Must be dimensioned at least workSize().
71  */
72  void updateTemp(doublereal t, doublereal* work) {
73  for (size_t i = 0; i < m_rxn.size(); i++) {
74  m_falloff[i]->updateTemp(t, work + m_offset[i]);
75  }
76  }
77 
78  /**
79  * Given a vector of reduced pressures for each falloff reaction,
80  * replace each entry by the value of the falloff function.
81  */
82  void pr_to_falloff(doublereal* values, const doublereal* work) {
83  for (size_t i = 0; i < m_rxn.size(); i++) {
84  double pr = values[m_rxn[i]];
85  if (m_reactionType[i] == FALLOFF_RXN) {
86  // Pr / (1 + Pr) * F
87  values[m_rxn[i]] *=
88  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
89  } else {
90  // 1 / (1 + Pr) * F
91  values[m_rxn[i]] =
92  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
93  }
94  }
95  }
96 
97 protected:
98  std::vector<size_t> m_rxn;
99  std::vector<Falloff*> m_falloff;
100  FalloffFactory* m_factory;
101  vector_int m_loc;
102  std::vector<vector_fp::difference_type> m_offset;
103  size_t m_worksize;
104 
105  //! Distinguish between falloff and chemically activated reactions
107 };
108 }
109 
110 #endif
void pr_to_falloff(doublereal *values, const doublereal *work)
Given a vector of reduced pressures for each falloff reaction, replace each entry by the value of the...
Definition: FalloffMgr.h:82
A falloff manager that implements any set of falloff functions.
Definition: FalloffMgr.h:20
virtual Falloff * newFalloff(int type, const vector_fp &c)
Return a pointer to a new falloff function calculator.
void install(size_t rxn, int falloffType, int reactionType, const vector_fp &c)
Install a new falloff function calculator.
Definition: FalloffMgr.h:51
Parameterizations for reaction falloff functions.
void updateTemp(doublereal t, doublereal *work)
Update the cached temperature-dependent intermediate results for all installed falloff functions...
Definition: FalloffMgr.h:72
size_t workSize()
Size of the work array required to store intermediate results.
Definition: FalloffMgr.h:62
const int FALLOFF_RXN
The general form for an association or dissociation reaction, with a pressure-dependent rate...
Definition: reaction_defs.h:38
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:167
static FalloffFactory * factory()
Return a pointer to the factory.
virtual size_t workSize()
The size of the work array required.
This file defines some constants used to specify reaction types.
FalloffMgr()
Constructor.
Definition: FalloffMgr.h:24
vector_int m_reactionType
Distinguish between falloff and chemically activated reactions.
Definition: FalloffMgr.h:106
Base class for falloff function calculators.
virtual ~FalloffMgr()
Destructor. Deletes all installed falloff function calculators.
Definition: FalloffMgr.h:33
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:165
Factory class to construct falloff function calculators.