Cantera  3.1.0a1
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"
12 
13 namespace Cantera
14 {
15 class Func1;
16 class ReactorBase;
17 
18 /**
19  * Base class for 'flow devices' (valves, pressure regulators, etc.)
20  * connecting reactors.
21  * @ingroup flowDeviceGroup
22  */
24 {
25 public:
26  FlowDevice() = default;
27 
28  virtual ~FlowDevice() = default;
29  FlowDevice(const FlowDevice&) = delete;
30  FlowDevice& operator=(const FlowDevice&) = delete;
31 
32  //! String indicating the flow device implemented. Usually
33  //! corresponds to the name of the derived class.
34  virtual string type() const {
35  return "FlowDevice";
36  }
37 
38  //! Mass flow rate (kg/s).
39  double massFlowRate() {
40  if (m_mdot == Undef) {
41  throw CanteraError("FlowDevice::massFlowRate",
42  "Flow device is not ready. Try initializing the reactor network.");
43  } else {
44  return m_mdot;
45  }
46  }
47 
48  //! Update the mass flow rate at time 'time'. This must be overloaded in
49  //! subclasses to update m_mdot.
50  virtual void updateMassFlowRate(double time) {}
51 
52  //! Mass flow rate (kg/s) of outlet species k. Returns zero if this species
53  //! is not present in the upstream mixture.
54  double outletSpeciesMassFlowRate(size_t k);
55 
56  //! specific enthalpy
57  double enthalpy_mass();
58 
59  //! Install a flow device between two reactors.
60  /*!
61  * @param in Upstream reactor.
62  * @param out Downstream reactor.
63  */
65 
66  virtual bool ready() {
67  return (m_in != 0 && m_out != 0);
68  }
69 
70  //! Return a reference to the upstream reactor.
71  ReactorBase& in() const {
72  return *m_in;
73  }
74 
75  //! Return a const reference to the downstream reactor.
76  const ReactorBase& out() const {
77  return *m_out;
78  }
79 
80  //! Return current value of the pressure function.
81  /*!
82  * The mass flow rate [kg/s] is calculated given the pressure drop [Pa] and a
83  * coefficient set by a flow device specific function; unless a user-defined
84  * pressure function is set, this is the pressure difference across the device.
85  * The calculation of mass flow rate depends to the flow device.
86  * @since New in %Cantera 3.0.
87  */
88  double evalPressureFunction();
89 
90  //! Set a function of pressure that is used in determining the
91  //! mass flow rate through the device. The evaluation of mass flow
92  //! depends on the derived flow device class.
93  virtual void setPressureFunction(Func1* f);
94 
95  //! Return current value of the time function.
96  /*!
97  * The mass flow rate [kg/s] is calculated for a Flow device, and multiplied by a
98  * function of time, which returns 1.0 unless a user-defined function is provided.
99  * The calculation of mass flow rate depends on the flow device.
100  * @since New in %Cantera 3.0.
101  */
102  double evalTimeFunction();
103 
104  //! Set a function of time that is used in determining
105  //! the mass flow rate through the device. The evaluation of mass flow
106  //! depends on the derived flow device class.
107  virtual void setTimeFunction(Func1* g);
108 
109  //! Set current reactor network time
110  /*!
111  * @since New in %Cantera 3.0.
112  */
113  void setSimTime(double time) {
114  m_time = time;
115  }
116 
117 protected:
118  double m_mdot = Undef;
119 
120  //! Function set by setPressureFunction; used by updateMassFlowRate
121  Func1* m_pfunc = nullptr;
122 
123  //! Function set by setTimeFunction; used by updateMassFlowRate
124  Func1* m_tfunc = nullptr;
125 
126  //! Coefficient set by derived classes; used by updateMassFlowRate
127  double m_coeff = 1.0;
128 
129  //! Current reactor network time
130  double m_time = 0.;
131 
132 private:
133  size_t m_nspin = 0;
134  size_t m_nspout = 0;
135  ReactorBase* m_in = nullptr;
136  ReactorBase* m_out = nullptr;
137  vector<size_t> m_in2out, m_out2in;
138 };
139 
140 }
141 
142 #endif
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:66
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition: FlowDevice.cpp:72
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:14
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:124
virtual string type() const
String indicating the flow device implemented.
Definition: FlowDevice.h:34
double m_time
Current reactor network time.
Definition: FlowDevice.h:130
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition: FlowDevice.h:127
void setSimTime(double time)
Set current reactor network time.
Definition: FlowDevice.h:113
double enthalpy_mass()
specific enthalpy
Definition: FlowDevice.cpp:84
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:45
double massFlowRate()
Mass flow rate (kg/s).
Definition: FlowDevice.h:39
double evalTimeFunction()
Return current value of the time function.
Definition: FlowDevice.cpp:64
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:59
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: FlowDevice.h:50
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:71
double evalPressureFunction()
Return current value of the pressure function.
Definition: FlowDevice.cpp:50
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:76
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:121
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:75
Base class for stirred reactors.
Definition: ReactorBase.h:50
This file contains definitions of constants, types and terms that are used in internal routines and a...
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 and logging,...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:164