Cantera 2.6.0
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
13MassFlowController::MassFlowController() : FlowDevice() {
14}
15
16void MassFlowController::setMassFlowRate(double mdot)
17{
18 if (m_tfunc) {
19 delete m_tfunc;
20 }
21 m_coeff = mdot;
22}
23
24void MassFlowController::updateMassFlowRate(double time)
25{
26 if (!ready()) {
27 throw CanteraError("MassFlowController::updateMassFlowRate",
28 "Device is not ready; some parameters have not been set.");
29 }
30 double mdot = m_coeff;
31 if (m_tfunc) {
32 mdot *= m_tfunc->eval(time);
33 }
34 m_mdot = std::max(mdot, 0.0);
35}
36
37PressureController::PressureController() : FlowDevice(), m_master(0) {
38}
39
41{
42 if (!ready()) {
43 throw CanteraError("PressureController::updateMassFlowRate",
44 "Device is not ready; some parameters have not been set.");
45 }
46 double mdot = m_coeff;
47 double delta_P = in().pressure() - out().pressure();
48 if (m_pfunc) {
49 mdot *= m_pfunc->eval(delta_P);
50 } else {
51 mdot *= delta_P;
52 }
53 m_master->updateMassFlowRate(time);
54 mdot += m_master->massFlowRate();
55 m_mdot = std::max(mdot, 0.0);
56}
57
58Valve::Valve() : FlowDevice() {
59}
60
62{
63 if (!ready()) {
64 throw CanteraError("Valve::updateMassFlowRate",
65 "Device is not ready; some parameters have not been set.");
66 }
67 double mdot = m_coeff;
68 if (m_tfunc) {
69 mdot *= m_tfunc->eval(time);
70 }
71 double delta_P = in().pressure() - out().pressure();
72 if (m_pfunc) {
73 mdot *= m_pfunc->eval(delta_P);
74 } else {
75 mdot *= delta_P;
76 }
77 m_mdot = std::max(mdot, 0.0);
78}
79
80}
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition: FlowDevice.h:24
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:106
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition: FlowDevice.h:109
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:80
double massFlowRate()
Mass flow rate (kg/s).
Definition: FlowDevice.h:48
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:85
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: FlowDevice.h:59
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:103
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:60
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:228
virtual void updateMassFlowRate(double time)
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.h:29