Cantera  2.0
FlowDevice.h
Go to the documentation of this file.
1 /**
2  * @file FlowDevice.h
3  */
4 
5 // Copyright 2001 California Institute of Technology
6 
7 #ifndef CT_FLOWDEVICE_H
8 #define CT_FLOWDEVICE_H
9 
10 #include "cantera/base/ct_defs.h"
11 #include "cantera/base/global.h"
13 
14 namespace Cantera
15 {
16 class Func1;
17 class ReactorBase; // forward reference
18 
19 const int MFC_Type = 1;
20 const int PressureController_Type = 2;
21 const int Valve_Type = 3;
22 
23 /**
24  * Base class for 'flow devices' (valves, pressure regulators,
25  * etc.) connecting reactors. Allowance is made for devices that
26  * are closed-loop controllers. Several methods for these are
27  * defined here that do nothing but may be overloaded to set or
28  * get the setpoint, gains, etc. The behavior of overloaded
29  * methods should be consistent with the behavior described
30  * here. The base-class versions of these methods print a warning
31  * if called.
32  * @ingroup reactor0
33  */
35 {
36 
37 public:
38 
39  /// Constructor
40  FlowDevice() : m_mdot(0.0), m_func(0), m_type(0),
41  m_nspin(0), m_nspout(0),
42  m_in(0), m_out(0) {}
43 
44  /// Destructor (does nothing)
45  virtual ~FlowDevice() {}
46 
47  // /// Copy constructor.
48  // FlowDevice(const FlowDevice& a) : m_in(a.m_in), m_out(a.m_out) {}
49 
50  // /// Assignment operator
51  // FlowDevice& operator=(const FlowDevice& a) {
52  // if (this == &a) return *this;
53  // m_in = a.m_in;
54  // m_out = a.m_out;
55  // return *this;
56  // }
57 
58  int type() {
59  return m_type;
60  }
61 
62  /**
63  * Mass flow rate (kg/s).
64  */
65  doublereal massFlowRate(double time = -999.0) {
66  if (time != -999.0) {
67  updateMassFlowRate(time);
68  }
69  return m_mdot;
70  }
71 
72  // Update the mass flow rate at time 'time'. This must be
73  // overloaded in subclassess to update m_mdot.
74  virtual void updateMassFlowRate(doublereal time) {}
75 
76  // mass flow rate of outlet species k
77  doublereal outletSpeciesMassFlowRate(size_t k);
78 
79  // specific enthalpy
80  doublereal enthalpy_mass();
81 
82  // /**
83  // * Setpoint. Default = 0.0.
84  // */
85  // virtual doublereal setpoint() { warn("setpoint"); return 0.0; }
86 
87 
88  // /* Update the internal state, if necessary. By default this method
89  // * does nothing, but may be overloaded for devices that have a
90  // * state.
91  // */
92  // virtual void update() {warn("update");}
93 
94 
95  // /* Reset the device. By default this method does nothing, but
96  // * may be overloaded for devices that have a state that depends on
97  // * past history.
98  // */
99  // virtual void reset() {warn("reset");}
100 
101  // /**
102  // * Set the setpoint. May be changed at any time. By default,
103  // * this does nothing.
104  // */
105  // virtual void setSetpoint(doublereal value) {warn("setSetpoint");}
106 
107  // /**
108  // * Set the controller gains. Returns false if the number of
109  // * gains is too small, or if an illegal value is specified.
110  // */
111  // virtual bool setGains(int n, const doublereal* gains) {
112  // warn("setGains");
113  // return true;
114  // }
115 
116  // /**
117  // * Get the controller gains. Returns false if the 'gains'
118  // * array is too small.
119  // */
120  // virtual bool getGains(int n, doublereal* gains) {
121  // warn("getGains");
122  // return true;
123  // }
124 
125  // /**
126  // * Maximum difference between input and setpoint since
127  // * last call to 'reset'.
128  // */
129  // virtual doublereal maxError() {warn("maxError"); return 0.0;}
130 
131  /**
132  * Install a flow device between two reactors.
133  * @param in Upstream reactor.
134  * @param out Downstream reactor.
135  */
136  bool install(ReactorBase& in, ReactorBase& out);
137 
138  virtual bool ready() {
139  return (m_in != 0 && m_out != 0);
140  }
141 
142  /// Return a reference to the upstream reactor.
143  ReactorBase& in() const {
144  return *m_in;
145  }
146 
147  /// Return a const reference to the downstream reactor.
148  const ReactorBase& out() const {
149  return *m_out;
150  }
151 
152  /// set parameters
153  virtual void setParameters(int n, doublereal* coeffs) {
154  m_coeffs.resize(n);
155  std::copy(coeffs, coeffs + n, m_coeffs.begin());
156  }
157 
158  void setFunction(Cantera::Func1* f);
159  void setMassFlowRate(doublereal mdot) {
160  m_mdot = mdot;
161  }
162 
163 
164 protected:
165 
166  doublereal m_mdot;
167  Cantera::Func1* m_func;
168  vector_fp m_coeffs;
169  int m_type;
170 
171 private:
172 
173  size_t m_nspin, m_nspout;
174  ReactorBase* m_in;
175  ReactorBase* m_out;
176  std::vector<size_t> m_in2out, m_out2in;
177 
178  void warn(std::string meth) {
179  writelog(std::string("Warning: method ") + meth + " of base class "
180  + " FlowDevice called. Nothing done.\n");
181  }
182 };
183 
184 }
185 
186 #endif