Cantera  4.0.0a1
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 m_tfunc.reset();
16 m_coeff = mdot;
17}
18
20{
21 if (!ready()) {
22 throw CanteraError("MassFlowController::updateMassFlowRate",
23 "Device is not ready; some parameters have not been set.");
24 }
25 double mdot = m_coeff;
26 if (m_tfunc) {
27 mdot *= m_tfunc->eval(time);
28 }
29 m_mdot = std::max(mdot, 0.0);
30}
31
33{
34 if (!ready()) {
35 throw CanteraError("PressureController::updateMassFlowRate",
36 "Device is not ready; some parameters have not been set.");
37 }
38 double mdot = m_coeff;
39 double delta_P = in().pressure() - out().pressure();
40 if (m_pfunc) {
41 mdot *= m_pfunc->eval(delta_P);
42 } else {
43 mdot *= delta_P;
44 }
45 m_primary->updateMassFlowRate(time);
46 mdot += m_primary->massFlowRate();
47 m_mdot = std::max(mdot, 0.0);
48}
49
51{
52 if (m_mdot <= 0.0) {
53 return 0.0;
54 }
55 double delta_P = in().pressure() - out().pressure();
56 return m_coeff * pressureFunction_ddP(delta_P);
57}
58
60 SparseTriplets& trips, size_t row, double coeff, bool includePressureSpecies)
61{
62 FlowDevice::addMassFlowRateJacobian(trips, row, coeff, includePressureSpecies);
63 if (m_primary) {
64 m_primary->addMassFlowRateJacobian(trips, row, coeff, includePressureSpecies);
65 }
66}
67
68void PressureController::setPrimary(shared_ptr<ConnectorNode> primary)
69{
70 auto dev = std::dynamic_pointer_cast<FlowDevice>(primary);
71 if (!dev) {
72 throw CanteraError("PressureController::setPrimary",
73 "Invalid primary mass flow controller with type {}.",
74 primary->type());
75 }
76 m_primary = dev.get();
77}
78
80{
81 if (!ready()) {
82 throw CanteraError("Valve::updateMassFlowRate",
83 "Device is not ready; some parameters have not been set.");
84 }
85 double mdot = m_coeff;
86 if (m_tfunc) {
87 mdot *= m_tfunc->eval(time);
88 }
89 double delta_P = in().pressure() - out().pressure();
90 if (m_pfunc) {
91 mdot *= m_pfunc->eval(delta_P);
92 } else {
93 mdot *= delta_P;
94 }
95 m_mdot = std::max(mdot, 0.0);
96}
97
99{
100 if (m_mdot <= 0.0) {
101 return 0.0;
102 }
103 double alpha = m_coeff;
104 if (m_tfunc) {
105 alpha *= m_tfunc->eval(m_time);
106 }
107 double delta_P = in().pressure() - out().pressure();
108 alpha *= pressureFunction_ddP(delta_P);
109 return alpha;
110}
111
112}
Base class for exceptions thrown by Cantera classes.
virtual void addMassFlowRateJacobian(SparseTriplets &trips, size_t row, double coeff, bool includePressureSpecies=true)
Add Jacobian terms proportional to derivatives of the mass flow rate.
double m_time
Current reactor network time.
Definition FlowDevice.h:227
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition FlowDevice.h:224
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:150
double massFlowRate()
Mass flow rate (kg/s).
Definition FlowDevice.h:37
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:155
shared_ptr< Func1 > m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:221
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition FlowDevice.h:48
shared_ptr< Func1 > m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:218
double pressureFunction_ddP(double deltaP) const
Return the derivative of the pressure function at deltaP.
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 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 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.
double pressure() const
Returns the current pressure (Pa) of the reactor.
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.
Some flow devices derived from class FlowDevice.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595