Cantera  2.3.0
Reactor.h
Go to the documentation of this file.
1 //! @file Reactor.h
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at http://www.cantera.org/license.txt for license and copyright information.
5 
6 #ifndef CT_REACTOR_H
7 #define CT_REACTOR_H
8 
9 #include "ReactorBase.h"
11 
12 namespace Cantera
13 {
14 
15 /**
16  * Class Reactor is a general-purpose class for stirred reactors. The reactor
17  * may have an arbitrary number of inlets and outlets, each of which may be
18  * connected to a "flow device" such as a mass flow controller, a pressure
19  * regulator, etc. Additional reactors may be connected to the other end of
20  * the flow device, allowing construction of arbitrary reactor networks.
21  *
22  * The reactor class integrates the same governing equations no matter what
23  * type of reactor is simulated. The differences among reactor types are
24  * completely specified by the attached flow devices and the time-dependent
25  * user-specified boundary conditions.
26  *
27  * If an instance of class Reactor is used directly, it will simulate an
28  * adiabatic, constant volume reactor with gas-phase chemistry but no surface
29  * chemistry. Other reactor types may be simulated by deriving a class from
30  * Reactor. This method allows specifying the following in terms of the
31  * instantaneous reactor state:
32  *
33  * - rate of change of the total volume (m^3/s)
34  * - surface heat loss rate (W)
35  * - species surface production rates (kmol/s)
36  */
37 class Reactor : public ReactorBase
38 {
39 public:
40  Reactor();
41 
42  virtual int type() const {
43  return ReactorType;
44  }
45 
46  /**
47  * Insert something into the reactor. The 'something' must belong to a class
48  * that is a subclass of both ThermoPhase and Kinetics.
49  */
50  template<class G>
51  void insert(G& contents) {
53  setKineticsMgr(contents);
54  }
55 
56  void setKineticsMgr(Kinetics& kin);
57 
58  //! Disable changes in reactor composition due to chemical reactions.
59  //! @deprecated Use setChemistry instead. To be removed after Cantera 2.3
61  warn_deprecated("Reactor::disableChemistry",
62  "Use setChemistry instead. To be removed after Cantera 2.3");
63  setChemistry(false);
64  }
65 
66  //! Enable changes in reactor composition due to chemical reactions.
67  //! @deprecated Use setChemistry instead. To be removed after Cantera 2.3
68  void enableChemistry() {
69  warn_deprecated("Reactor::enableChemistry",
70  "Use setChemistry instead. To be removed after Cantera 2.3");
71  setChemistry(true);
72  }
73 
74  //! Enable or disable changes in reactor composition due to chemical reactions.
75  void setChemistry(bool cflag = true) {
76  m_chem = cflag;
77  }
78 
79  //! Returns `true` if changes in the reactor composition due to chemical reactions are enabled.
80  bool chemistryEnabled() const {
81  return m_chem;
82  }
83 
84  //! Set the energy equation on or off.
85  void setEnergy(int eflag = 1) {
86  if (eflag > 0) {
87  m_energy = true;
88  } else {
89  m_energy = false;
90  }
91  }
92 
93  //! Returns `true` if solution of the energy equation is enabled.
94  bool energyEnabled() const {
95  return m_energy;
96  }
97 
98  //! Number of equations (state variables) for this reactor
99  virtual size_t neq() {
100  if (!m_nv) {
101  initialize();
102  }
103  return m_nv;
104  }
105 
106  //! Called by ReactorNet to get the initial conditions.
107  /*!
108  * Essentially calls function getState()
109  *
110  * @param[in] t0 Time at which initial conditions are determined
111  * @param[in] leny Length of *y* (unused)
112  * @param[out] y state vector representing the initial state of the reactor
113  * @deprecated Use getState instead. To be removed after Cantera 2.3.
114  */
115  virtual void getInitialConditions(doublereal t0, size_t leny,
116  doublereal* y);
117 
118  //! Get the the current state of the reactor.
119  /*!
120  * @param[out] y state vector representing the initial state of the reactor
121  */
122  virtual void getState(doublereal* y);
123 
124  virtual void initialize(doublereal t0 = 0.0);
125 
126  /*!
127  * Evaluate the reactor governing equations. Called by ReactorNet::eval.
128  * @param[in] t time.
129  * @param[in] y solution vector, length neq()
130  * @param[out] ydot rate of change of solution vector, length neq()
131  * @param[in] params sensitivity parameter vector, length ReactorNet::nparams()
132  */
133  virtual void evalEqs(doublereal t, doublereal* y,
134  doublereal* ydot, doublereal* params);
135 
136  virtual void syncState();
137 
138  //! Set the state of the reactor to correspond to the state vector *y*.
139  virtual void updateState(doublereal* y);
140 
141  //! Number of sensitivity parameters associated with this reactor
142  //! (including walls)
143  virtual size_t nSensParams();
144 
145  //! Add a sensitivity parameter associated with the reaction number *rxn*
146  //! (in the homogeneous phase).
147  virtual void addSensitivityReaction(size_t rxn);
148 
149  //! Add a sensitivity parameter associated with the enthalpy formation of
150  //! species *k* (in the homogeneous phase)
151  virtual void addSensitivitySpeciesEnthalpy(size_t k);
152 
153  //! Return the index in the solution vector for this reactor of the
154  //! component named *nm*. Possible values for *nm* are "mass", "volume",
155  //! "int_energy", the name of a homogeneous phase species, or the name of a
156  //! surface species.
157  virtual size_t componentIndex(const std::string& nm) const;
158 
159  //! Return the name of the solution component with index *i*.
160  //! @see componentIndex()
161  virtual std::string componentName(size_t k);
162 
163 protected:
164  //! Set reaction rate multipliers based on the sensitivity variables in
165  //! *params*.
166  virtual void applySensitivity(double* params);
167  //! Reset the reaction rate multipliers
168  virtual void resetSensitivity(double* params);
169 
170  //! Return the index in the solution vector for this reactor of the species
171  //! named *nm*, in either the homogeneous phase or a surface phase, relative
172  //! to the start of the species terms. Used to implement componentIndex for
173  //! specific reactor implementations.
174  virtual size_t speciesIndex(const std::string& nm) const;
175 
176  //! Evaluate terms related to Walls. Calculates #m_vdot and #m_Q based on
177  //! wall movement and heat transfer.
178  //! @param t the current time
179  virtual void evalWalls(double t);
180 
181  //! Evaluate terms related to surface reactions. Calculates #m_sdot and rate
182  //! of change in surface species coverages.
183  //! @param t the current time
184  //! @param[out] ydot array of d(coverage)/dt for surface species
185  //! @returns Net mass flux from surfaces
186  virtual double evalSurfaces(double t, double* ydot);
187 
188  //! Update the state of SurfPhase objects attached to this reactor
189  virtual void updateSurfaceState(double* y);
190 
191  //! Get initial conditions for SurfPhase objects attached to this reactor
192  virtual void getSurfaceInitialConditions(double* y);
193 
194  //! Pointer to the homogeneous Kinetics object that handles the reactions
196 
197  doublereal m_vdot; //!< net rate of volume change from moving walls [m^3/s]
198  doublereal m_Q; //!< net heat transfer through walls [W]
199  doublereal m_mass; //!< total mass
200  vector_fp m_work;
201 
202  //! Production rates of gas phase species on surfaces [kmol/s]
204 
205  vector_fp m_wdot; //!< Species net molar production rates
206  vector_fp m_uk; //!< Species molar internal energies
207  bool m_chem;
208  bool m_energy;
209  size_t m_nv;
210 
211  // Data associated each sensitivity parameter
212  std::vector<SensitivityParameter> m_sensParams;
213 };
214 }
215 
216 #endif
void setChemistry(bool cflag=true)
Enable or disable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:75
virtual void getInitialConditions(doublereal t0, size_t leny, doublereal *y)
Called by ReactorNet to get the initial conditions.
Definition: Reactor.cpp:40
vector_fp m_sdot
Production rates of gas phase species on surfaces [kmol/s].
Definition: Reactor.h:203
doublereal m_mass
total mass
Definition: Reactor.h:199
virtual size_t nSensParams()
Number of sensitivity parameters associated with this reactor (including walls)
Definition: Reactor.cpp:118
vector_fp m_wdot
Species net molar production rates.
Definition: Reactor.h:205
void setEnergy(int eflag=1)
Set the energy equation on or off.
Definition: Reactor.h:85
virtual void addSensitivityReaction(size_t rxn)
Add a sensitivity parameter associated with the reaction number rxn (in the homogeneous phase)...
Definition: Reactor.cpp:300
virtual void evalWalls(double t)
Evaluate terms related to Walls.
Definition: Reactor.cpp:254
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual void resetSensitivity(double *params)
Reset the reaction rate multipliers.
Definition: Reactor.cpp:429
void enableChemistry()
Enable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:68
virtual size_t speciesIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the species named nm, in either the homog...
Definition: Reactor.cpp:328
virtual std::string componentName(size_t k)
Return the name of the solution component with index i.
Definition: Reactor.cpp:381
virtual void initialize(doublereal t0=0.0)
Initialize the reactor.
Definition: Reactor.cpp:82
bool chemistryEnabled() const
Returns true if changes in the reactor composition due to chemical reactions are enabled.
Definition: Reactor.h:80
virtual void updateState(doublereal *y)
Set the state of the reactor to correspond to the state vector y.
Definition: Reactor.cpp:133
Kinetics * m_kin
Pointer to the homogeneous Kinetics object that handles the reactions.
Definition: Reactor.h:195
void insert(G &contents)
Insert something into the reactor.
Definition: Reactor.h:51
virtual void applySensitivity(double *params)
Set reaction rate multipliers based on the sensitivity variables in params.
Definition: Reactor.cpp:407
doublereal m_Q
net heat transfer through walls [W]
Definition: Reactor.h:198
virtual double evalSurfaces(double t, double *ydot)
Evaluate terms related to surface reactions.
Definition: Reactor.cpp:265
Public interface for kinetics managers.
Definition: Kinetics.h:111
virtual void getState(doublereal *y)
Get the the current state of the reactor.
Definition: Reactor.cpp:47
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Base class for stirred reactors.
Definition: ReactorBase.h:44
virtual void setThermoMgr(thermo_t &thermo)
Specify the mixture contained in the reactor.
Definition: ReactorBase.cpp:26
void disableChemistry()
Disable changes in reactor composition due to chemical reactions.
Definition: Reactor.h:60
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:149
virtual void syncState()
Set the state of the reactor to correspond to the state of the associated ThermoPhase object...
Definition: Reactor.cpp:127
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
virtual size_t componentIndex(const std::string &nm) const
Return the index in the solution vector for this reactor of the component named nm.
Definition: Reactor.cpp:350
bool energyEnabled() const
Returns true if solution of the energy equation is enabled.
Definition: Reactor.h:94
virtual int type() const
Return a constant indicating the type of this Reactor.
Definition: Reactor.h:42
virtual size_t neq()
Number of equations (state variables) for this reactor.
Definition: Reactor.h:99
virtual void evalEqs(doublereal t, doublereal *y, doublereal *ydot, doublereal *params)
Definition: Reactor.cpp:188
doublereal m_vdot
net rate of volume change from moving walls [m^3/s]
Definition: Reactor.h:197
vector_fp m_uk
Species molar internal energies.
Definition: Reactor.h:206
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void addSensitivitySpeciesEnthalpy(size_t k)
Add a sensitivity parameter associated with the enthalpy formation of species k (in the homogeneous p...
Definition: Reactor.cpp:313
virtual void updateSurfaceState(double *y)
Update the state of SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:179
virtual void getSurfaceInitialConditions(double *y)
Get initial conditions for SurfPhase objects attached to this reactor.
Definition: Reactor.cpp:73
Class Reactor is a general-purpose class for stirred reactors.
Definition: Reactor.h:37