Cantera  4.0.0a1
Loading...
Searching...
No Matches
flowControllers.h
Go to the documentation of this file.
1//! @file flowControllers.h Some flow devices derived from class FlowDevice.
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_FLOWCONTR_H
7#define CT_FLOWCONTR_H
8
9#include "FlowDevice.h"
11
12namespace Cantera
13{
14
15/**
16 * A class for mass flow controllers. The mass flow rate is constant or
17 * specified as a function of time.
18 *
19 * The device coefficient *c* specifies the mass flow coefficient with units of kg/s.
20 * The mass flow rate is computed as:
21 * @f[\dot{m} = c g(t) @f]
22 * where *g* is a function of time that is set by `setTimeFunction`.
23 * If no function is specified, the mass flow rate defaults to:
24 * @f[\dot{m} = c @f]
25 *
26 * @ingroup connectorGroup
27 */
29{
30public:
31 using FlowDevice::FlowDevice; // inherit constructors
32
33 string type() const override {
34 return "MassFlowController";
35 }
36
37 void setMassFlowRate(double mdot) override;
38
39 //! Set the mass flow coefficient.
40 /*!
41 * *m* has units of kg/s. The mass flow rate is computed as:
42 *
43 * where *g* is a function of time that is set by `setTimeFunction`.
44 * If no function is specified, the mass flow rate defaults to:
45 * @f[\dot{m} = m @f]
46 */
47 void setMassFlowCoeff(double m) {
48 m_coeff = m;
49 }
50
51 //! Get the mass flow coefficient.
53 return m_coeff;
54 }
55
56 void setPressureFunction(shared_ptr<Func1> f) override {
57 throw NotImplementedError("MassFlowController::setPressureFunction");
58 }
59
60 //! If a function of time has been specified for mdot, then update the
61 //! stored mass flow rate. Otherwise, mdot is a constant, and does not
62 //! need updating.
63 void updateMassFlowRate(double time) override;
64
65 double massFlowRate_ddP() const override {
66 return 0.0;
67 }
68};
69
70/**
71 * A class for flow controllers where the flow rate is equal to the flow rate
72 * of a primary mass flow controller plus a correction proportional to the
73 * pressure difference between the inlet and outlet.
74 *
75 * The device coefficient *c* sets the proportionality constant between pressure drop
76 * and mass flow rate and has units of kg/s/Pa. The mass flow rate is computed as:
77 * @f[\dot{m} = \dot{m}_{primary} + c f(\Delta P) @f]
78 * where *f* is a functions of pressure drop that is set by
79 * `setPressureFunction`. If no functions is specified, the mass flow
80 * rate defaults to:
81 * @f[\dot{m} = \dot{m}_{primary} + c \Delta P @f]
82 *
83 * @ingroup connectorGroup
84 */
86{
87public:
88 using FlowDevice::FlowDevice; // inherit constructors
89
90 string type() const override {
91 return "PressureController";
92 }
93
94 bool ready() override {
95 return FlowDevice::ready() && m_primary != 0;
96 }
97
98 void setPrimary(shared_ptr<ConnectorNode> primary) override;
99
100 void setTimeFunction(shared_ptr<Func1> f) override {
101 throw NotImplementedError("PressureController::setTimeFunction");
102 }
103
104 //! Set the proportionality constant between pressure drop and mass flow rate.
105 void setPressureCoeff(double c) {
106 m_coeff = c;
107 }
108
109 //! Get the pressure coefficient.
111 return m_coeff;
112 }
113
114 void updateMassFlowRate(double time) override;
115
116 double massFlowRate_ddP() const override;
117
118 //! Add terms proportional to derivatives of this device's mass flow rate.
119 //!
120 //! Adds both the pressure-correction derivative and the primary flow device's
121 //! derivative.
122 //! @copydetails FlowDevice::addMassFlowRateJacobian
123 void addMassFlowRateJacobian(SparseTriplets& trips, size_t row, double coeff,
124 bool includePressureSpecies=true) override;
125
126protected:
127 FlowDevice* m_primary = nullptr;
128};
129
130//! Supply a mass flow rate that is a function of the pressure drop across the valve.
131/*!
132 * The default behavior is a linearly proportional to the pressure difference.
133 * Note that real valves do not have this behavior, so this class does not
134 * model real, physical valves.
135 *
136 * The device coefficient *c* sets the proportionality constant between pressure drop
137 * and mass flow rate and has units of kg/s/Pa. The mass flow rate is computed as:
138 * @f[\dot{m} = c g(t) f(\Delta P) @f]
139 * where *g* and *f* are functions of time and pressure drop that are set
140 * by `setTimeFunction` and `setPressureFunction`, respectively. If no functions are
141 * specified, the mass flow rate defaults to:
142 * @f[\dot{m} = c \Delta P @f]
143 *
144 * @ingroup connectorGroup
145 */
146class Valve : public FlowDevice
147{
148public:
149 using FlowDevice::FlowDevice; // inherit constructors
150
151 string type() const override {
152 return "Valve";
153 }
154
155 //! Set the proportionality constant between pressure drop and mass flow rate.
156 void setValveCoeff(double c) {
157 m_coeff = c;
158 }
159
160 //! Get the valve coefficient.
161 double getValveCoeff() {
162 return m_coeff;
163 }
164
165 //! Compute the current mass flow rate, based on the pressure difference.
166 void updateMassFlowRate(double time) override;
167
168 double massFlowRate_ddP() const override;
169};
170
171}
172#endif
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:26
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:224
A class for mass flow controllers.
void setMassFlowCoeff(double m)
Set the mass flow coefficient.
void setPressureFunction(shared_ptr< Func1 > f) override
Set a function of pressure to modify the pressure response.
string type() const override
String indicating the connector implemented.
double getMassFlowCoeff()
Get the mass flow coefficient.
double massFlowRate_ddP() const override
Derivative of mass flow rate with respect to pressure difference.
void updateMassFlowRate(double time) override
If a function of time has been specified for mdot, then update the stored mass flow rate.
void setMassFlowRate(double mdot) override
Set the fixed mass flow rate (kg/s) through a flow device.
An error indicating that an unimplemented function has been called.
A class for flow controllers where the flow rate is equal to the flow rate of a primary mass flow con...
string type() const override
String indicating the connector implemented.
void addMassFlowRateJacobian(SparseTriplets &trips, size_t row, double coeff, bool includePressureSpecies=true) override
Add terms proportional to derivatives of this device's mass flow rate.
double getPressureCoeff()
Get the pressure coefficient.
void setPressureCoeff(double c)
Set the proportionality constant between pressure drop and mass flow rate.
void setTimeFunction(shared_ptr< Func1 > f) override
Set a function of time to modulate the mass flow rate.
double massFlowRate_ddP() const override
Derivative of mass flow rate with respect to pressure difference.
void updateMassFlowRate(double time) override
Update the mass flow rate at time 'time'.
void setPrimary(shared_ptr< ConnectorNode > primary) override
Set the primary mass flow controller.
Supply a mass flow rate that is a function of the pressure drop across the valve.
void setValveCoeff(double c)
Set the proportionality constant between pressure drop and mass flow rate.
string type() const override
String indicating the connector implemented.
double getValveCoeff()
Get the valve coefficient.
double massFlowRate_ddP() const override
Derivative of mass flow rate with respect to pressure difference.
void updateMassFlowRate(double time) override
Compute the current mass flow rate, based on the pressure difference.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595