Cantera  2.0
Reactor.h
Go to the documentation of this file.
1 /**
2  * @file Reactor.h
3  */
4 
5 // Copyright 2001 California Institute of Technology
6 
7 #ifndef CT_REACTOR_H
8 #define CT_REACTOR_H
9 
10 #include "ReactorBase.h"
12 
13 namespace Cantera
14 {
15 
16 /**
17  * Class Reactor is a general-purpose class for stirred
18  * reactors. The reactor may have an arbitrary number of inlets
19  * and outlets, each of which may be connected to a "flow device"
20  * such as a mass flow controller, a pressure regulator,
21  * etc. Additional reactors may be connected to the other end of
22  * the flow device, allowing construction of arbitrary reactor
23  * networks.
24  *
25  * The reactor class integrates the same governing equations no
26  * matter what type of reactor is simulated. The differences
27  * among reactor types are completely specified by the attached
28  * flow devices and the time-dependent user-specified boundary
29  * conditions.
30  *
31  * If an instance of class Reactor is used directly, it will
32  * simulate an adiabatic, constant volume reactor with gas-phase
33  * chemistry but no surface chemistry. Other reactor types may be
34  * simulated by deriving a class from Reactor and overloading
35  * method getParams. This method allows specifying the following
36  * in terms of the instantaneous reactor state:
37  *
38  * - rate of change of the total volume (m^3/s)
39  * - surface heat loss rate (W)
40  * - species surface production rates (kmol/s)
41  *
42  * class Reactor inherits from both ReactorBase and
43  * FuncEval. ReactorBase provides the basic reactor-like methods
44  * that FlowDevice instances can access to determine their mass
45  * flow rate. Class FuncEval is the class used to define a system
46  * of ODE's to be integrated.
47  */
48 
49 class Reactor : public ReactorBase
50 {
51 
52 public:
53 
54  //! Default constructor.
55  Reactor();
56 
57  /**
58  * Destructor. Deletes the integrator.
59  */
60  virtual ~Reactor() {}
61 
62  virtual int type() const {
63  return ReactorType;
64  }
65 
66  /**
67  * Insert something into the reactor. The 'something' must
68  * belong to a class that is a subclass of both ThermoPhase
69  * and Kinetics.
70  */
71  template<class G>
72  void insert(G& contents) {
73  setThermoMgr(contents);
74  setKineticsMgr(contents);
75  }
76 
77  void setKineticsMgr(Kinetics& kin) {
78  m_kin = &kin;
79  if (m_kin->nReactions() == 0) {
80  disableChemistry();
81  }
82  }
83 
84  void disableChemistry() {
85  m_chem = false;
86  }
87  void enableChemistry() {
88  m_chem = true;
89  }
90 
91  /// Set the energy equation on or off.
92  void setEnergy(int eflag = 1) {
93  if (eflag > 0) {
94  m_energy = true;
95  } else {
96  m_energy = false;
97  }
98  }
99 
100  // overloaded methods of class FuncEval
101  virtual size_t neq() {
102  return m_nv;
103  }
104 
105  virtual void getInitialConditions(doublereal t0, size_t leny,
106  doublereal* y);
107 
108  virtual void initialize(doublereal t0 = 0.0);
109  virtual void evalEqs(doublereal t, doublereal* y,
110  doublereal* ydot, doublereal* params);
111 
112  /**
113  * Set the mixture to a state consistent with solution
114  * vector y.
115  */
116  virtual void updateState(doublereal* y);
117 
118  virtual size_t nSensParams();
119  virtual void addSensitivityReaction(size_t rxn);
120 
121  virtual std::string sensParamID(int p) {
122  return m_pname[p];
123  }
124 
125  // virtual std::string component(int k) const;
126  virtual size_t componentIndex(std::string nm) const;
127 
128 protected:
129  //! Pointer to the homogeneous Kinetics object that handles the reactions
131 
132  //! Tolerance on the temperature
133  doublereal m_temp_atol;
134  doublereal m_maxstep; // max step size
135  doublereal m_vdot, m_Q;
136  vector_fp m_atol;
137  doublereal m_rtol;
138  vector_fp m_work;
139  vector_fp m_sdot; // surface production rates
140  bool m_chem;
141  bool m_energy;
142  size_t m_nv;
143 
144  size_t m_nsens;
145  std::vector<size_t> m_pnum;
146  std::vector<std::string> m_pname;
147  std::vector<size_t> m_nsens_wall;
148  vector_fp m_mult_save;
149 
150 private:
151 };
152 }
153 
154 #endif
155