Cantera  2.5.1
FlowDevice.h
Go to the documentation of this file.
1 //! @file FlowDevice.h
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at https://cantera.org/license.txt for license and copyright information.
5 
6 #ifndef CT_FLOWDEVICE_H
7 #define CT_FLOWDEVICE_H
8 
9 #include "cantera/base/ct_defs.h"
10 #include "cantera/base/global.h"
13 
14 namespace Cantera
15 {
16 class Func1;
17 class ReactorBase;
18 
19 //! Magic numbers
20 //! @deprecated To be removed after Cantera 2.5.
21 const int MFC_Type = 1;
22 const int PressureController_Type = 2;
23 const int Valve_Type = 3;
24 
25 /**
26  * Base class for 'flow devices' (valves, pressure regulators, etc.)
27  * connecting reactors.
28  * @ingroup reactor0
29  */
31 {
32 public:
33  FlowDevice();
34 
35  virtual ~FlowDevice() {}
36  FlowDevice(const FlowDevice&) = delete;
37  FlowDevice& operator=(const FlowDevice&) = delete;
38 
39  //! String indicating the flow device implemented. Usually
40  //! corresponds to the name of the derived class.
41  virtual std::string typeStr() const {
42  return "FlowDevice";
43  }
44 
45  //! Return an integer indicating the type of flow device
46  /*!
47  * @deprecated To be changed after Cantera 2.5.
48  */
49  virtual int type() const {
50  warn_deprecated("FlowDevice::type",
51  "To be changed after Cantera 2.5. "
52  "Return string instead of magic number; use "
53  "FlowDevice::typeStr during transition.");
54  return m_type;
55  }
56 
57  //! Mass flow rate (kg/s).
58  //! @deprecated The 'time' argument will be removed after Cantera 2.5.
59  //! Evaluating the mass flow rate at times other than the current time
60  //! for the reactor network may lead to subtly incorrect results.
61  double massFlowRate(double time = -999.0) {
62  if (time != -999.0) {
63  warn_deprecated("FlowDevice::massFlowRate", "The 'time' argument"
64  " is deprecated and will be removed after Cantera 2.5.");
65  updateMassFlowRate(time);
66  }
67 
68  if (m_mdot == Undef) {
69  throw CanteraError("FlowDevice::massFlowRate",
70  "Flow device is not ready. Try initializing the reactor network.");
71  } else {
72  return m_mdot;
73  }
74  }
75 
76  //! Update the mass flow rate at time 'time'. This must be overloaded in
77  //! subclassess to update m_mdot.
78  virtual void updateMassFlowRate(double time) {}
79 
80  //! Mass flow rate (kg/s) of outlet species k. Returns zero if this species
81  //! is not present in the upstream mixture.
82  double outletSpeciesMassFlowRate(size_t k);
83 
84  //! specific enthalpy
85  double enthalpy_mass();
86 
87  //! Install a flow device between two reactors.
88  /*!
89  * @param in Upstream reactor.
90  * @param out Downstream reactor.
91  */
93 
94  virtual bool ready() {
95  return (m_in != 0 && m_out != 0);
96  }
97 
98  //! Return a reference to the upstream reactor.
99  ReactorBase& in() const {
100  return *m_in;
101  }
102 
103  //! Return a const reference to the downstream reactor.
104  const ReactorBase& out() const {
105  return *m_out;
106  }
107 
108  //! Set parameters. Generic function formerly used in the Matlab interface.
109  //! @deprecated To be removed after Cantera 2.5.
110  virtual void setParameters(int n, const double* coeffs) {
111  warn_deprecated("FlowDevice::setParameters",
112  "To be removed after Cantera 2.5. "
113  "Use device-specific functions (e.g. "
114  "Valve::setValveCoeff) instead.");
115  m_coeff = coeffs[0]; // vectorized coefficients are not used
116  }
117 
118  //! Set a function of a single variable that is used in determining the
119  //! mass flow rate through the device. The meaning of this function
120  //! depends on the parameterization of the derived type.
121  //! @deprecated To be removed after Cantera 2.5.
122  void setFunction(Func1* f) {
123  warn_deprecated("FlowDevice::setFunction",
124  "To be removed after Cantera 2.5. "
125  "Use FlowDevice::setTimeFunction or "
126  "FlowDevice::setPressureFunction instead.");
127  if (typeStr()=="MassFlowController") {
128  setTimeFunction(f);
129  } else if (typeStr()=="Valve") {
131  }
132  }
133 
134  //! Set a function of pressure that is used in determining the
135  //! mass flow rate through the device. The evaluation of mass flow
136  //! depends on the derived flow device class.
137  virtual void setPressureFunction(Func1* f);
138 
139  //! Set a function of time that is used in determining
140  //! the mass flow rate through the device. The evaluation of mass flow
141  //! depends on the derived flow device class.
142  virtual void setTimeFunction(Func1* g);
143 
144  //! Set the fixed mass flow rate (kg/s) through the flow device.
145  //! @deprecated To be removed after Cantera 2.5.
146  void setMassFlowRate(double mdot) {
147  warn_deprecated("FlowDevice::setMassFlowRate",
148  "To be removed after Cantera 2.5. "
149  "Use device-specific functions (e.g. "
150  "MassFlowController::setMassFlowRate or "
151  "Valve::setValveCoeff) instead.");
152  m_mdot = mdot;
153  }
154 
155 protected:
156  double m_mdot;
157 
158  //! Function set by setPressureFunction; used by updateMassFlowRate
160 
161  //! Function set by setTimeFunction; used by updateMassFlowRate
163 
164  //! Coefficient set by derived classes; used by updateMassFlowRate
165  double m_coeff;
166 
167  int m_type; //!< @deprecated To be removed after Cantera 2.5.
168 
169 private:
170  size_t m_nspin, m_nspout;
171  ReactorBase* m_in;
172  ReactorBase* m_out;
173  std::vector<size_t> m_in2out, m_out2in;
174 };
175 
176 }
177 
178 #endif
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:31
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition: FlowDevice.cpp:59
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:18
void setMassFlowRate(double mdot)
Set the fixed mass flow rate (kg/s) through the flow device.
Definition: FlowDevice.h:146
virtual std::string typeStr() const
String indicating the flow device implemented.
Definition: FlowDevice.h:41
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:162
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition: FlowDevice.h:165
double enthalpy_mass()
specific enthalpy
Definition: FlowDevice.cpp:71
void setFunction(Func1 *f)
Set a function of a single variable that is used in determining the mass flow rate through the device...
Definition: FlowDevice.h:122
virtual int type() const
Return an integer indicating the type of flow device.
Definition: FlowDevice.h:49
virtual void setParameters(int n, const double *coeffs)
Set parameters.
Definition: FlowDevice.h:110
double massFlowRate(double time=-999.0)
Mass flow rate (kg/s).
Definition: FlowDevice.h:61
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:49
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:54
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: FlowDevice.h:78
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:99
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:104
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:159
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:44
Base class for stirred reactors.
Definition: ReactorBase.h:48
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:157
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
const int MFC_Type
Magic numbers.
Definition: FlowDevice.h:21
Contains declarations for string manipulation functions within Cantera.