Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
flowControllers.h
Go to the documentation of this file.
1 /**
2  * @file flowControllers.h
3  *
4  * Some flow devices derived from class FlowDevice.
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 
9 #ifndef CT_FLOWCONTR_H
10 #define CT_FLOWCONTR_H
11 
12 #include "FlowDevice.h"
13 #include "ReactorBase.h"
14 #include "cantera/numerics/Func1.h"
15 
16 namespace Cantera
17 {
18 /**
19  * A class for mass flow controllers. The mass flow rate is constant or
20  * specified as a function of time..
21  */
23 {
24 public:
26  m_type = MFC_Type;
27  }
28 
29  virtual bool ready() {
30  return FlowDevice::ready() && m_mdot >= 0.0;
31  }
32 
33  /// If a function of time has been specified for mdot, then update the
34  /// stored mass flow rate. Otherwise, mdot is a constant, and does not
35  /// need updating.
36  virtual void updateMassFlowRate(doublereal time) {
37  if (m_func) {
38  m_mdot = m_func->eval(time);
39  }
40  m_mdot = std::max(m_mdot, 0.0);
41  }
42 };
43 
44 /**
45  * A class for flow controllers where the flow rate is equal to the flow rate
46  * of a "master" mass flow controller plus a correction proportional to the
47  * pressure difference between the inlet and outlet.
48  */
50 {
51 public:
52  PressureController() : FlowDevice(), m_master(0) {
53  m_type = PressureController_Type;
54  }
55 
56  virtual bool ready() {
57  return FlowDevice::ready() && m_master != 0 && m_coeffs.size() == 1;
58  }
59 
60  void setMaster(FlowDevice* master) {
61  m_master = master;
62  }
63 
64  virtual void updateMassFlowRate(doublereal time) {
65  if (!ready()) {
66  throw CanteraError("PressureController::updateMassFlowRate",
67  "Device is not ready; some parameters have not been set.");
68  }
69  doublereal master_mdot = m_master->massFlowRate(time);
70  m_mdot = master_mdot + m_coeffs[0]*(in().pressure() -
71  out().pressure());
72  m_mdot = std::max(m_mdot, 0.0);
73  }
74 
75 protected:
76  FlowDevice* m_master;
77 };
78 
79 //! Supply a mass flow rate that is a function of the pressure drop across the
80 //! valve.
81 /*!
82  * The default behavior is a linearly proportional to the pressure difference.
83  * Note that real valves do not have this behavior, so this class does not
84  * model real, physical valves.
85  */
86 class Valve : public FlowDevice
87 {
88 public:
89  Valve() : FlowDevice() {
90  m_type = Valve_Type;
91  }
92 
93  virtual bool ready() {
94  return FlowDevice::ready() && (m_coeffs.size() == 1 || m_func);
95  }
96 
97  /// Compute the currrent mass flow rate, based on the pressure difference.
98  virtual void updateMassFlowRate(doublereal time) {
99  if (!ready()) {
100  throw CanteraError("Valve::updateMassFlowRate",
101  "Device is not ready; some parameters have not been set.");
102  }
103  double delta_P = in().pressure() - out().pressure();
104  if (m_func) {
105  m_mdot = m_func->eval(delta_P);
106  } else {
107  m_mdot = m_coeffs[0]*delta_P;
108  }
109  m_mdot = std::max(m_mdot, 0.0);
110  }
111 };
112 
113 }
114 #endif
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:188
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:28
Supply a mass flow rate that is a function of the pressure drop across the valve. ...
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:82
A class for flow controllers where the flow rate is equal to the flow rate of a "master" mass flow co...
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:56
virtual void updateMassFlowRate(doublereal time)
Update the mass flow rate at time 'time'.
virtual void updateMassFlowRate(doublereal time)
Compute the currrent mass flow rate, based on the pressure difference.
A class for mass flow controllers.
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:77
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
doublereal massFlowRate(double time=-999.0)
Definition: FlowDevice.h:45
virtual void updateMassFlowRate(doublereal time)
If a function of time has been specified for mdot, then update the stored mass flow rate...