Cantera  3.2.0a2
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#include "ConnectorNode.h"
13
14namespace Cantera
15{
16class Func1;
17class ReactorBase;
18
19/**
20 * Base class for 'flow devices' (valves, pressure regulators, etc.)
21 * connecting reactors.
22 * @ingroup connectorGroup
23 */
25{
26public:
27 FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
28 const string& name="(none)");
29 using ConnectorNode::ConnectorNode; // inherit constructors
30
31 string type() const override {
32 return "FlowDevice";
33 }
34
35 //! Mass flow rate (kg/s).
36 double massFlowRate() {
37 if (m_mdot == Undef) {
38 throw CanteraError("FlowDevice::massFlowRate",
39 "Flow device is not ready. Try initializing the reactor network.");
40 } else {
41 return m_mdot;
42 }
43 }
44
45 //! Update the mass flow rate at time 'time'.
46 //! This must be overloaded in derived classes to update m_mdot.
47 virtual void updateMassFlowRate(double time) {}
48
49 //! Set the fixed mass flow rate (kg/s) through a flow device.
50 virtual void setMassFlowRate(double mdot) {
51 throw NotImplementedError("FlowDevice::setMassFlowRate");
52 }
53
54 //! Get the device coefficient (defined by derived class).
55 //! @since New in %Cantera 3.2.
56 double deviceCoefficient() const {
57 return m_coeff;
58 }
59
60 //! Set the device coefficient (defined by derived class).
61 //! @since New in %Cantera 3.2.
62 void setDeviceCoefficient(double c) {
63 m_coeff = c;
64 }
65
66 //! Set the primary mass flow controller.
67 //! @since New in %Cantera 3.2.
68 virtual void setPrimary(shared_ptr<ConnectorNode> primary) {
69 throw NotImplementedError("FlowDevice::setPrimary");
70 }
71
72 //! Mass flow rate (kg/s) of outlet species k. Returns zero if this species
73 //! is not present in the upstream mixture.
74 double outletSpeciesMassFlowRate(size_t k);
75
76 //! specific enthalpy
77 double enthalpy_mass();
78
79 //! Install a flow device between two reactors.
80 /*!
81 * @param in Upstream reactor.
82 * @param out Downstream reactor.
83 * @deprecated To be removed after %Cantera 3.2. Reactors should be provided to
84 * constructor instead.
85 */
87
88 virtual bool ready() {
89 return (m_in != 0 && m_out != 0);
90 }
91
92 //! Return a reference to the upstream reactor.
93 ReactorBase& in() const {
94 return *m_in;
95 }
96
97 //! Return a const reference to the downstream reactor.
98 const ReactorBase& out() const {
99 return *m_out;
100 }
101
102 //! Return a mutable reference to the downstream reactor.
104 return *m_out;
105 }
106
107 //! Return current value of the pressure function.
108 /*!
109 * The mass flow rate [kg/s] is calculated given the pressure drop [Pa] and a
110 * coefficient set by a flow device specific function; unless a user-defined
111 * pressure function is set, this is the pressure difference across the device.
112 * The calculation of mass flow rate depends to the flow device.
113 * @since New in %Cantera 3.0.
114 */
115 double evalPressureFunction();
116
117 //! Set a function of pressure that is used in determining the
118 //! mass flow rate through the device. The evaluation of mass flow
119 //! depends on the derived flow device class.
120 //! @deprecated To be removed after %Cantera 3.2. Replaceable by version using
121 //! shared pointer.
122 virtual void setPressureFunction(Func1* f);
123
124 //! Set a function of pressure to modify the pressure response.
125 //! Set a function of pressure that is used in determining the
126 //! mass flow rate through the device. The evaluation of mass flow
127 //! depends on the derived flow device class.
128 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
129 virtual void setPressureFunction(shared_ptr<Func1> f) {
130 m_pfunc = f.get();
131 }
132
133 //! Return current value of the time function.
134 /*!
135 * The mass flow rate [kg/s] is calculated for a Flow device, and multiplied by a
136 * function of time, which returns 1.0 unless a user-defined function is provided.
137 * The calculation of mass flow rate depends on the flow device.
138 * @since New in %Cantera 3.0.
139 */
140 double evalTimeFunction();
141
142 //! Set a function of time that is used in determining
143 //! the mass flow rate through the device. The evaluation of mass flow
144 //! depends on the derived flow device class.
145 //! @deprecated To be removed after %Cantera 3.2. Replaceable by version using
146 //! shared pointer.
147 virtual void setTimeFunction(Func1* g);
148
149 //! Set a function of time to modulate the mass flow rate.
150 //! Set a function of time that is used in determining
151 //! the mass flow rate through the device. The evaluation of mass flow
152 //! depends on the derived flow device class.
153 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
154 virtual void setTimeFunction(shared_ptr<Func1> g) {
155 m_tfunc = g.get();
156 }
157
158 //! Set current reactor network time
159 /*!
160 * @since New in %Cantera 3.0.
161 */
162 void setSimTime(double time) {
163 m_time = time;
164 }
165
166protected:
167 double m_mdot = Undef;
168
169 //! Function set by setPressureFunction; used by updateMassFlowRate
170 Func1* m_pfunc = nullptr;
171
172 //! Function set by setTimeFunction; used by updateMassFlowRate
173 Func1* m_tfunc = nullptr;
174
175 //! Coefficient set by derived classes; used by updateMassFlowRate
176 double m_coeff = 1.0;
177
178 //! Current reactor network time
179 double m_time = 0.;
180
181private:
182 size_t m_nspin = 0;
183 size_t m_nspout = 0;
184 ReactorBase* m_in = nullptr;
185 ReactorBase* m_out = nullptr;
186 vector<size_t> m_in2out, m_out2in;
187};
188
189}
190
191#endif
Base class for exceptions thrown by Cantera classes.
Base class for walls and flow devices connecting reactors.
string name() const
Retrieve connector name.
ConnectorNode(const string &name="(none)")
Transitional constructor.
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:25
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
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:173
double m_time
Current reactor network time.
Definition FlowDevice.h:179
virtual void setMassFlowRate(double mdot)
Set the fixed mass flow rate (kg/s) through a flow device.
Definition FlowDevice.h:50
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:176
void setSimTime(double time)
Set current reactor network time.
Definition FlowDevice.h:162
string type() const override
String indicating the connector implemented.
Definition FlowDevice.h:31
double enthalpy_mass()
specific enthalpy
double deviceCoefficient() const
Get the device coefficient (defined by derived class).
Definition FlowDevice.h:56
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:93
virtual void setTimeFunction(shared_ptr< Func1 > g)
Set a function of time to modulate the mass flow rate.
Definition FlowDevice.h:154
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:36
void setDeviceCoefficient(double c)
Set the device coefficient (defined by derived class).
Definition FlowDevice.h:62
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:98
double evalTimeFunction()
Return current value of the time function.
ReactorBase & out()
Return a mutable reference to the downstream reactor.
Definition FlowDevice.h:103
virtual void setPressureFunction(shared_ptr< Func1 > f)
Set a function of pressure to modify the pressure response.
Definition FlowDevice.h:129
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:47
double evalPressureFunction()
Return current value of the pressure function.
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:170
virtual void setPrimary(shared_ptr< ConnectorNode > primary)
Set the primary mass flow controller.
Definition FlowDevice.h:68
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
An error indicating that an unimplemented function has been called.
Base class for reactor objects.
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