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
6#include "cantera/zeroD/flowControllers.h"
7#include "cantera/zeroD/ReactorBase.h"
8#include "cantera/numerics/Func1.h"
9
10 namespace Cantera
11{
12
13MassFlowController::MassFlowController() : FlowDevice() {
14}
15
16 void MassFlowController::setMassFlowRate(double mdot)
17{
18 if (m_tfunc) {
19 delete m_tfunc;
20 }
21 m_coeff = mdot;
22}
23
24 void 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
40 void PressureController::updateMassFlowRate(double time)
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
61 void Valve::updateMassFlowRate(double time)
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}
Func1.h
ReactorBase.h
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
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:106
Cantera::FlowDevice::m_coeff
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition: FlowDevice.h:109
Cantera::FlowDevice::in
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:80
Cantera::FlowDevice::massFlowRate
double massFlowRate()
Mass flow rate (kg/s).
Definition: FlowDevice.h:48
Cantera::FlowDevice::out
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:85
Cantera::FlowDevice::updateMassFlowRate
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: FlowDevice.h:59
Cantera::FlowDevice::m_pfunc
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:103
Cantera::Func1::eval
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:60
Cantera::PressureController::updateMassFlowRate
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: flowControllers.cpp:40
Cantera::ReactorBase::pressure
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:228
Cantera::Valve::updateMassFlowRate
virtual void updateMassFlowRate(double time)
Compute the current mass flow rate, based on the pressure difference.
Definition: flowControllers.cpp:61
flowControllers.h
Some flow devices derived from class FlowDevice.
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557