Cantera  3.2.0a2
Loading...
Searching...
No Matches
flowControllers.cpp
Go to the documentation of this file.
1//! @file flowControllers.cpp
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
9
10namespace Cantera
11{
12
14{
15 if (m_tfunc) {
16 delete m_tfunc;
17 }
18 m_coeff = mdot;
19}
20
22{
23 if (!ready()) {
24 throw CanteraError("MassFlowController::updateMassFlowRate",
25 "Device is not ready; some parameters have not been set.");
26 }
27 double mdot = m_coeff;
28 if (m_tfunc) {
29 mdot *= m_tfunc->eval(time);
30 }
31 m_mdot = std::max(mdot, 0.0);
32}
33
35{
36 if (!ready()) {
37 throw CanteraError("PressureController::updateMassFlowRate",
38 "Device is not ready; some parameters have not been set.");
39 }
40 double mdot = m_coeff;
41 double delta_P = in().pressure() - out().pressure();
42 if (m_pfunc) {
43 mdot *= m_pfunc->eval(delta_P);
44 } else {
45 mdot *= delta_P;
46 }
47 m_primary->updateMassFlowRate(time);
48 mdot += m_primary->massFlowRate();
49 m_mdot = std::max(mdot, 0.0);
50}
51
52void PressureController::setPrimary(shared_ptr<ConnectorNode> primary)
53{
54 auto dev = std::dynamic_pointer_cast<FlowDevice>(primary);
55 if (!dev) {
56 throw CanteraError("PressureController::setPrimary",
57 "Invalid primary mass flow controller with type {}.",
58 primary->type());
59 }
60 m_primary = dev.get();
61}
62
64{
65 if (!ready()) {
66 throw CanteraError("Valve::updateMassFlowRate",
67 "Device is not ready; some parameters have not been set.");
68 }
69 double mdot = m_coeff;
70 if (m_tfunc) {
71 mdot *= m_tfunc->eval(time);
72 }
73 double delta_P = in().pressure() - out().pressure();
74 if (m_pfunc) {
75 mdot *= m_pfunc->eval(delta_P);
76 } else {
77 mdot *= delta_P;
78 }
79 m_mdot = std::max(mdot, 0.0);
80}
81
82}
Base class for exceptions thrown by Cantera classes.
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:173
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:176
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:93
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:36
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:98
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition FlowDevice.h:47
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:170
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:28
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.
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.
double pressure() const
Returns the current pressure (Pa) of the reactor.
void updateMassFlowRate(double time) override
Compute the current mass flow rate, based on the pressure difference.
Some flow devices derived from class FlowDevice.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595