Cantera  2.4.0
FalloffMgr.h
Go to the documentation of this file.
1 /**
2  * @file FalloffMgr.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_FALLOFFMGR_H
9 #define CT_FALLOFFMGR_H
10 
11 #include "reaction_defs.h"
12 #include "FalloffFactory.h"
13 #include "cantera/base/global.h"
14 
15 namespace Cantera
16 {
17 
18 /**
19  * A falloff manager that implements any set of falloff functions.
20  * @ingroup falloffGroup
21  */
23 {
24 public:
25  //! Constructor.
27  m_worksize(0) {
28  m_factory = FalloffFactory::factory(); // RFB:TODO This raw pointer should be encapsulated
29  // because accessing a 'Singleton Factory'
30  }
31 
32  //! Install a new falloff function calculator.
33  /*
34  * @param rxn Index of the falloff reaction. This will be used to
35  * determine which array entry is modified in method pr_to_falloff.
36  * @param reactionType Either `FALLOFF_RXN` or `CHEMACT_RXN`
37  * @param f The falloff function.
38  */
39  void install(size_t rxn, int reactionType, shared_ptr<Falloff> f) {
40  m_rxn.push_back(rxn);
41  m_offset.push_back(m_worksize);
42  m_worksize += f->workSize();
43  m_falloff.push_back(f);
44  m_reactionType.push_back(reactionType);
45  m_indices[rxn] = m_falloff.size()-1;
46  }
47 
48  /*!
49  * Replace an existing falloff function calculator
50  *
51  * @param rxn External reaction index
52  * @param f New falloff function, of the same kind as the existing one
53  */
54  void replace(size_t rxn, shared_ptr<Falloff> f) {
55  m_falloff[m_indices[rxn]] = f;
56  }
57 
58  //! Size of the work array required to store intermediate results.
59  size_t workSize() {
60  return m_worksize;
61  }
62 
63  /**
64  * Update the cached temperature-dependent intermediate
65  * results for all installed falloff functions.
66  * @param t Temperature [K].
67  * @param work Work array. Must be dimensioned at least workSize().
68  */
69  void updateTemp(doublereal t, doublereal* work) {
70  for (size_t i = 0; i < m_rxn.size(); i++) {
71  m_falloff[i]->updateTemp(t, work + m_offset[i]);
72  }
73  }
74 
75  /**
76  * Given a vector of reduced pressures for each falloff reaction,
77  * replace each entry by the value of the falloff function.
78  */
79  void pr_to_falloff(doublereal* values, const doublereal* work) {
80  for (size_t i = 0; i < m_rxn.size(); i++) {
81  double pr = values[m_rxn[i]];
82  if (m_reactionType[i] == FALLOFF_RXN) {
83  // Pr / (1 + Pr) * F
84  values[m_rxn[i]] *=
85  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
86  } else {
87  // 1 / (1 + Pr) * F
88  values[m_rxn[i]] =
89  m_falloff[i]->F(pr, work + m_offset[i]) /(1.0 + pr);
90  }
91  }
92  }
93 
94 protected:
95  std::vector<size_t> m_rxn;
96  std::vector<shared_ptr<Falloff> > m_falloff;
97  FalloffFactory* m_factory;
98  vector_int m_loc;
99  std::vector<vector_fp::difference_type> m_offset;
100  size_t m_worksize;
101 
102  //! Distinguish between falloff and chemically activated reactions
104 
105  //! map of external reaction index to local index
106  std::map<size_t, size_t> m_indices;
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:79
A falloff manager that implements any set of falloff functions.
Definition: FalloffMgr.h:22
void replace(size_t rxn, shared_ptr< Falloff > f)
Definition: FalloffMgr.h:54
void install(size_t rxn, int reactionType, shared_ptr< Falloff > f)
Install a new falloff function calculator.
Definition: FalloffMgr.h:39
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:69
size_t workSize()
Size of the work array required to store intermediate results.
Definition: FalloffMgr.h:59
const int FALLOFF_RXN
The general form for a gas-phase association or dissociation reaction, with a pressure-dependent rate...
Definition: reaction_defs.h:43
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:26
vector_int m_reactionType
Distinguish between falloff and chemically activated reactions.
Definition: FalloffMgr.h:103
Factory class to construct falloff function calculators.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
std::map< size_t, size_t > m_indices
map of external reaction index to local index
Definition: FalloffMgr.h:106