Cantera  3.1.0
Loading...
Searching...
No Matches
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
10#include "cantera/base/global.h"
12
13namespace Cantera
14{
15class Func1;
16class ReactorBase;
17
18/**
19 * Base class for 'flow devices' (valves, pressure regulators, etc.)
20 * connecting reactors.
21 * @ingroup flowDeviceGroup
22 */
24{
25public:
26 FlowDevice(const string& name="(none)") : m_name(name) {}
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 //! Retrieve flow device name.
39 string name() const {
40 return m_name;
41 }
42
43 //! Set flow device name.
44 void setName(const string& name) {
45 m_name = name;
46 }
47
48 //! Set the default name of a flow device. Returns `false` if it was previously set.
49 bool setDefaultName(map<string, int>& counts);
50
51 //! Mass flow rate (kg/s).
52 double massFlowRate() {
53 if (m_mdot == Undef) {
54 throw CanteraError("FlowDevice::massFlowRate",
55 "Flow device is not ready. Try initializing the reactor network.");
56 } else {
57 return m_mdot;
58 }
59 }
60
61 //! Update the mass flow rate at time 'time'. This must be overloaded in
62 //! subclasses to update m_mdot.
63 virtual void updateMassFlowRate(double time) {}
64
65 //! Mass flow rate (kg/s) of outlet species k. Returns zero if this species
66 //! is not present in the upstream mixture.
67 double outletSpeciesMassFlowRate(size_t k);
68
69 //! specific enthalpy
70 double enthalpy_mass();
71
72 //! Install a flow device between two reactors.
73 /*!
74 * @param in Upstream reactor.
75 * @param out Downstream reactor.
76 */
78
79 virtual bool ready() {
80 return (m_in != 0 && m_out != 0);
81 }
82
83 //! Return a reference to the upstream reactor.
84 ReactorBase& in() const {
85 return *m_in;
86 }
87
88 //! Return a const reference to the downstream reactor.
89 const ReactorBase& out() const {
90 return *m_out;
91 }
92
93 //! Return a mutable reference to the downstream reactor.
95 return *m_out;
96 }
97
98 //! Return current value of the pressure function.
99 /*!
100 * The mass flow rate [kg/s] is calculated given the pressure drop [Pa] and a
101 * coefficient set by a flow device specific function; unless a user-defined
102 * pressure function is set, this is the pressure difference across the device.
103 * The calculation of mass flow rate depends to the flow device.
104 * @since New in %Cantera 3.0.
105 */
106 double evalPressureFunction();
107
108 //! Set a function of pressure that is used in determining the
109 //! mass flow rate through the device. The evaluation of mass flow
110 //! depends on the derived flow device class.
111 virtual void setPressureFunction(Func1* f);
112
113 //! Return current value of the time function.
114 /*!
115 * The mass flow rate [kg/s] is calculated for a Flow device, and multiplied by a
116 * function of time, which returns 1.0 unless a user-defined function is provided.
117 * The calculation of mass flow rate depends on the flow device.
118 * @since New in %Cantera 3.0.
119 */
120 double evalTimeFunction();
121
122 //! Set a function of time that is used in determining
123 //! the mass flow rate through the device. The evaluation of mass flow
124 //! depends on the derived flow device class.
125 virtual void setTimeFunction(Func1* g);
126
127 //! Set current reactor network time
128 /*!
129 * @since New in %Cantera 3.0.
130 */
131 void setSimTime(double time) {
132 m_time = time;
133 }
134
135protected:
136 string m_name; //!< Flow device name.
137 bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
138
139 double m_mdot = Undef;
140
141 //! Function set by setPressureFunction; used by updateMassFlowRate
142 Func1* m_pfunc = nullptr;
143
144 //! Function set by setTimeFunction; used by updateMassFlowRate
145 Func1* m_tfunc = nullptr;
146
147 //! Coefficient set by derived classes; used by updateMassFlowRate
148 double m_coeff = 1.0;
149
150 //! Current reactor network time
151 double m_time = 0.;
152
153private:
154 size_t m_nspin = 0;
155 size_t m_nspout = 0;
156 ReactorBase* m_in = nullptr;
157 ReactorBase* m_out = nullptr;
158 vector<size_t> m_in2out, m_out2in;
159};
160
161}
162
163#endif
Base class for exceptions thrown by Cantera classes.
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.
bool m_defaultNameSet
true if default name has been previously set.
Definition FlowDevice.h:137
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:145
virtual string type() const
String indicating the flow device implemented.
Definition FlowDevice.h:34
double m_time
Current reactor network time.
Definition FlowDevice.h:151
bool setDefaultName(map< string, int > &counts)
Set the default name of a flow device. Returns false if it was previously set.
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:148
void setSimTime(double time)
Set current reactor network time.
Definition FlowDevice.h:131
double enthalpy_mass()
specific enthalpy
void setName(const string &name)
Set flow device name.
Definition FlowDevice.h:44
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:84
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:52
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:89
double evalTimeFunction()
Return current value of the time function.
ReactorBase & out()
Return a mutable reference to the downstream reactor.
Definition FlowDevice.h:94
string m_name
Flow device name.
Definition FlowDevice.h:136
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition FlowDevice.h:63
double evalPressureFunction()
Return current value of the pressure function.
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:142
string name() const
Retrieve flow device name.
Definition FlowDevice.h:39
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
Base class for stirred reactors.
Definition ReactorBase.h:49
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:595
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