Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "cantera/base/global.h"
13 
14 namespace Cantera
15 {
16 
17 /**
18  * A falloff manager that implements any set of falloff functions.
19  * @ingroup falloffGroup
20  */
22 {
23 public:
24  //! Constructor.
25  FalloffMgr(/*FalloffFactory* f = 0*/) :
26  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  //! Install a new falloff function calculator.
34  /*
35  * @param rxn Index of the falloff reaction. This will be used to
36  * determine which array entry is modified in method pr_to_falloff.
37  * @param falloffType of falloff function to install.
38  * @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
39  * @param c vector of coefficients for the falloff function.
40  * @deprecated Use install(size_t, int, shared_ptr<Falloff>). To be removed
41  * after Cantera 2.2.
42  */
43  void install(size_t rxn, int falloffType, int reactionType,
44  const vector_fp& c) {
45  warn_deprecated("FalloffMgr::install(size_t, int, int, const vector_fp&)",
46  "Use install(size_t, int, shared_ptr<Falloff>). To be removed after Cantera 2.2.");
47  shared_ptr<Falloff> f(m_factory->newFalloff(falloffType,c));
48  install(rxn, reactionType, f);
49  }
50 
51  //! Install a new falloff function calculator.
52  /*
53  * @param rxn Index of the falloff reaction. This will be used to
54  * determine which array entry is modified in method pr_to_falloff.
55  * @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
56  * @param f The falloff function.
57  */
58  void install(size_t rxn, int reactionType, shared_ptr<Falloff> f) {
59  m_rxn.push_back(rxn);
60  m_offset.push_back(m_worksize);
61  m_worksize += f->workSize();
62  m_falloff.push_back(f);
63  m_reactionType.push_back(reactionType);
64  m_indices[rxn] = m_falloff.size()-1;
65  }
66 
67  /*!
68  * Replace an existing falloff function calculator
69  *
70  * @param rxn External reaction index
71  * @param f New falloff function, of the same kind as the existing one
72  */
73  void replace(size_t rxn, shared_ptr<Falloff> f) {
74  m_falloff[m_indices[rxn]] = f;
75  }
76 
77  //! Size of the work array required to store intermediate results.
78  size_t workSize() {
79  return m_worksize;
80  }
81 
82  /**
83  * Update the cached temperature-dependent intermediate
84  * results for all installed falloff functions.
85  * @param t Temperature [K].
86  * @param work Work array. Must be dimensioned at least workSize().
87  */
88  void updateTemp(doublereal t, doublereal* work) {
89  for (size_t i = 0; i < m_rxn.size(); i++) {
90  m_falloff[i]->updateTemp(t, work + m_offset[i]);
91  }
92  }
93 
94  /**
95  * Given a vector of reduced pressures for each falloff reaction,
96  * replace each entry by the value of the falloff function.
97  */
98  void pr_to_falloff(doublereal* values, const doublereal* work) {
99  for (size_t i = 0; i < m_rxn.size(); i++) {
100  double pr = values[m_rxn[i]];
101  if (m_reactionType[i] == FALLOFF_RXN) {
102  // Pr / (1 + Pr) * F
103  values[m_rxn[i]] *=
104  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
105  } else {
106  // 1 / (1 + Pr) * F
107  values[m_rxn[i]] =
108  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
109  }
110  }
111  }
112 
113 protected:
114  std::vector<size_t> m_rxn;
115  std::vector<shared_ptr<Falloff> > m_falloff;
116  FalloffFactory* m_factory;
117  vector_int m_loc;
118  std::vector<vector_fp::difference_type> m_offset;
119  size_t m_worksize;
120 
121  //! Distinguish between falloff and chemically activated reactions
123 
124  //! map of external reaction index to local index
125  std::map<size_t, size_t> m_indices;
126 };
127 }
128 
129 #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:98
A falloff manager that implements any set of falloff functions.
Definition: FalloffMgr.h:21
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:43
void replace(size_t rxn, shared_ptr< Falloff > f)
Definition: FalloffMgr.h:73
void install(size_t rxn, int reactionType, shared_ptr< Falloff > f)
Install a new falloff function calculator.
Definition: FalloffMgr.h:58
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
Parameterizations for reaction falloff functions.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
void updateTemp(doublereal t, doublereal *work)
Update the cached temperature-dependent intermediate results for all installed falloff functions...
Definition: FalloffMgr.h:88
size_t workSize()
Size of the work array required to store intermediate results.
Definition: FalloffMgr.h:78
const int FALLOFF_RXN
The general form for a gas-phase association or dissociation reaction, with a pressure-dependent rate...
Definition: reaction_defs.h:42
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:159
static FalloffFactory * factory()
Return a pointer to the factory.
This file defines some constants used to specify reaction types.
FalloffMgr()
Constructor.
Definition: FalloffMgr.h:25
vector_int m_reactionType
Distinguish between falloff and chemically activated reactions.
Definition: FalloffMgr.h:122
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
Factory class to construct falloff function calculators.
std::map< size_t, size_t > m_indices
map of external reaction index to local index
Definition: FalloffMgr.h:125