Cantera  2.3.0
flowControllers.h
Go to the documentation of this file.
1 //! @file flowControllers.h Some flow devices derived from class FlowDevice.
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_FLOWCONTR_H
7 #define CT_FLOWCONTR_H
8 
9 #include "FlowDevice.h"
10 #include "ReactorBase.h"
11 #include "cantera/numerics/Func1.h"
12 
13 namespace Cantera
14 {
15 /**
16  * A class for mass flow controllers. The mass flow rate is constant or
17  * specified as a function of time..
18  */
20 {
21 public:
23  m_type = MFC_Type;
24  }
25 
26  virtual bool ready() {
27  return FlowDevice::ready() && m_mdot >= 0.0;
28  }
29 
30  /// If a function of time has been specified for mdot, then update the
31  /// stored mass flow rate. Otherwise, mdot is a constant, and does not
32  /// need updating.
33  virtual void updateMassFlowRate(doublereal time) {
34  if (m_func) {
35  m_mdot = m_func->eval(time);
36  }
37  m_mdot = std::max(m_mdot, 0.0);
38  }
39 };
40 
41 /**
42  * A class for flow controllers where the flow rate is equal to the flow rate
43  * of a "master" mass flow controller plus a correction proportional to the
44  * pressure difference between the inlet and outlet.
45  */
47 {
48 public:
49  PressureController() : FlowDevice(), m_master(0) {
50  m_type = PressureController_Type;
51  }
52 
53  virtual bool ready() {
54  return FlowDevice::ready() && m_master != 0 && m_coeffs.size() == 1;
55  }
56 
57  void setMaster(FlowDevice* master) {
58  m_master = master;
59  }
60 
61  //! Set the proportionality constant between pressure drop and mass flow
62  //! rate
63  /*!
64  * *c* has units of kg/s/Pa. The mass flow rate is computed as:
65  * \f[\dot{m} = \dot{m}_{master} + c \Delta P \f]
66  */
67  void setPressureCoeff(double c) {
68  m_coeffs = {c};
69  }
70 
71  virtual void updateMassFlowRate(doublereal time) {
72  if (!ready()) {
73  throw CanteraError("PressureController::updateMassFlowRate",
74  "Device is not ready; some parameters have not been set.");
75  }
76  m_mdot = m_master->massFlowRate(time)
77  + m_coeffs[0]*(in().pressure() - out().pressure());
78  m_mdot = std::max(m_mdot, 0.0);
79  }
80 
81 protected:
82  FlowDevice* m_master;
83 };
84 
85 //! Supply a mass flow rate that is a function of the pressure drop across the
86 //! valve.
87 /*!
88  * The default behavior is a linearly proportional to the pressure difference.
89  * Note that real valves do not have this behavior, so this class does not
90  * model real, physical valves.
91  */
92 class Valve : public FlowDevice
93 {
94 public:
95  Valve() : FlowDevice() {
96  m_type = Valve_Type;
97  }
98 
99  virtual bool ready() {
100  return FlowDevice::ready() && (m_coeffs.size() == 1 || m_func);
101  }
102 
103  //! Set the proportionality constant between pressure drop and mass flow
104  //! rate
105  /*!
106  * *c* has units of kg/s/Pa. The mass flow rate is computed as:
107  * \f[\dot{m} = c \Delta P \f]
108  */
109  void setPressureCoeff(double c) {
110  m_coeffs = {c};
111  }
112 
113  /// Compute the currrent mass flow rate, based on the pressure difference.
114  virtual void updateMassFlowRate(doublereal time) {
115  if (!ready()) {
116  throw CanteraError("Valve::updateMassFlowRate",
117  "Device is not ready; some parameters have not been set.");
118  }
119  double delta_P = in().pressure() - out().pressure();
120  if (m_func) {
121  m_mdot = m_func->eval(delta_P);
122  } else {
123  m_mdot = m_coeffs[0]*delta_P;
124  }
125  m_mdot = std::max(m_mdot, 0.0);
126  }
127 };
128 
129 }
130 #endif
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:27
Supply a mass flow rate that is a function of the pressure drop across the valve. ...
A class for flow controllers where the flow rate is equal to the flow rate of a "master" mass flow co...
void setPressureCoeff(double c)
Set the proportionality constant between pressure drop and mass flow rate.
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:77
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:60
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.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
void setPressureCoeff(double c)
Set the proportionality constant between pressure drop and mass flow rate.
doublereal massFlowRate(double time=-999.0)
Mass flow rate (kg/s).
Definition: FlowDevice.h:42
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:202
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:72
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void updateMassFlowRate(doublereal time)
If a function of time has been specified for mdot, then update the stored mass flow rate...