| Cantera 3.0.0

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
6#include "cantera/zeroD/flowControllers.h"
7#include "cantera/zeroD/ReactorBase.h"
8#include "cantera/numerics/Func1.h"
9
10 namespace Cantera
11{
12
13 void MassFlowController::setMassFlowRate(double mdot)
14{
15 if (m_tfunc) {
16 delete m_tfunc;
17 }
18 m_coeff = mdot;
19}
20
21 void MassFlowController::updateMassFlowRate(double time)
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
34 void PressureController::setMaster(FlowDevice* master)
35{
36 warn_deprecated("PressureController::setMaster",
37 "To be removed after Cantera 3.0; replaced by setPrimary.");
38 m_primary = master;
39}
40
41 void PressureController::updateMassFlowRate(double time)
42{
43 if (!ready()) {
44 throw CanteraError("PressureController::updateMassFlowRate",
45 "Device is not ready; some parameters have not been set.");
46 }
47 double mdot = m_coeff;
48 double delta_P = in().pressure() - out().pressure();
49 if (m_pfunc) {
50 mdot *= m_pfunc->eval(delta_P);
51 } else {
52 mdot *= delta_P;
53 }
54 m_primary->updateMassFlowRate(time);
55 mdot += m_primary->massFlowRate();
56 m_mdot = std::max(mdot, 0.0);
57}
58
59 void Valve::updateMassFlowRate(double time)
60{
61 if (!ready()) {
62 throw CanteraError("Valve::updateMassFlowRate",
63 "Device is not ready; some parameters have not been set.");
64 }
65 double mdot = m_coeff;
66 if (m_tfunc) {
67 mdot *= m_tfunc->eval(time);
68 }
69 double delta_P = in().pressure() - out().pressure();
70 if (m_pfunc) {
71 mdot *= m_pfunc->eval(delta_P);
72 } else {
73 mdot *= delta_P;
74 }
75 m_mdot = std::max(mdot, 0.0);
76}
77
78}
Func1.h
ReactorBase.h
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::FlowDevice
Base class for 'flow devices' (valves, pressure regulators, etc.) connecting reactors.
Definition FlowDevice.h:24
Cantera::FlowDevice::m_tfunc
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:124
Cantera::FlowDevice::m_coeff
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:127
Cantera::FlowDevice::in
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:71
Cantera::FlowDevice::massFlowRate
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:39
Cantera::FlowDevice::out
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:76
Cantera::FlowDevice::updateMassFlowRate
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition FlowDevice.h:50
Cantera::FlowDevice::m_pfunc
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:121
Cantera::Func1::eval
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:61
Cantera::MassFlowController::setMassFlowRate
void setMassFlowRate(double mdot)
Set the fixed mass flow rate (kg/s) through the mass flow controller.
Definition flowControllers.cpp:13
Cantera::MassFlowController::updateMassFlowRate
void updateMassFlowRate(double time) override
If a function of time has been specified for mdot, then update the stored mass flow rate.
Definition flowControllers.cpp:21
Cantera::PressureController::setMaster
void setMaster(FlowDevice *master)
Definition flowControllers.cpp:34
Cantera::PressureController::updateMassFlowRate
void updateMassFlowRate(double time) override
Update the mass flow rate at time 'time'.
Definition flowControllers.cpp:41
Cantera::ReactorBase::pressure
double pressure() const
Returns the current pressure (Pa) of the reactor.
Definition ReactorBase.h:224
Cantera::Valve::updateMassFlowRate
void updateMassFlowRate(double time) override
Compute the current mass flow rate, based on the pressure difference.
Definition flowControllers.cpp:59
flowControllers.h
Some flow devices derived from class FlowDevice.
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926