Cantera  3.3.0a1
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 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 to modify the pressure response.
109 //! Set a function of pressure that is used in determining the
110 //! mass flow rate through the device. The evaluation of mass flow
111 //! depends on the derived flow device class.
112 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
113 virtual void setPressureFunction(shared_ptr<Func1> f) {
114 m_pfunc = f.get();
115 }
116
117 //! Return current value of the time function.
118 /*!
119 * The mass flow rate [kg/s] is calculated for a Flow device, and multiplied by a
120 * function of time, which returns 1.0 unless a user-defined function is provided.
121 * The calculation of mass flow rate depends on the flow device.
122 * @since New in %Cantera 3.0.
123 */
124 double evalTimeFunction();
125
126 //! Set a function of time to modulate the mass flow rate.
127 //! Set a function of time that is used in determining
128 //! the mass flow rate through the device. The evaluation of mass flow
129 //! depends on the derived flow device class.
130 //! @since Changed in %Cantera 3.2. Previous version used a raw pointer.
131 virtual void setTimeFunction(shared_ptr<Func1> g) {
132 m_tfunc = g.get();
133 }
134
135 //! Set current reactor network time
136 /*!
137 * @since New in %Cantera 3.0.
138 */
139 void setSimTime(double time) {
140 m_time = time;
141 }
142
143protected:
144 double m_mdot = Undef;
145
146 //! Function set by setPressureFunction; used by updateMassFlowRate
147 Func1* m_pfunc = nullptr;
148
149 //! Function set by setTimeFunction; used by updateMassFlowRate
150 Func1* m_tfunc = nullptr;
151
152 //! Coefficient set by derived classes; used by updateMassFlowRate
153 double m_coeff = 1.0;
154
155 //! Current reactor network time
156 double m_time = 0.;
157
158private:
159 size_t m_nspin = 0;
160 size_t m_nspout = 0;
161 ReactorBase* m_in = nullptr;
162 ReactorBase* m_out = nullptr;
163 vector<size_t> m_in2out, m_out2in;
164};
165
166}
167
168#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.
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:150
double m_time
Current reactor network time.
Definition FlowDevice.h:156
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:153
void setSimTime(double time)
Set current reactor network time.
Definition FlowDevice.h:139
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:84
virtual void setTimeFunction(shared_ptr< Func1 > g)
Set a function of time to modulate the mass flow rate.
Definition FlowDevice.h:131
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:89
double evalTimeFunction()
Return current value of the time function.
ReactorBase & out()
Return a mutable reference to the downstream reactor.
Definition FlowDevice.h:94
virtual void setPressureFunction(shared_ptr< Func1 > f)
Set a function of pressure to modify the pressure response.
Definition FlowDevice.h:113
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:147
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