Cantera  2.5.1
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 
10 namespace Cantera
11 {
12 
13 MassFlowController::MassFlowController() : FlowDevice() {
14  m_type = MFC_Type;
15 }
16 
17 void MassFlowController::setMassFlowRate(double mdot)
18 {
19  if (m_tfunc) {
20  delete m_tfunc;
21  }
22  m_coeff = mdot;
23 }
24 
25 void MassFlowController::updateMassFlowRate(double time)
26 {
27  if (!ready()) {
28  throw CanteraError("MassFlowController::updateMassFlowRate",
29  "Device is not ready; some parameters have not been set.");
30  }
31  double mdot = m_coeff;
32  if (m_tfunc) {
33  mdot *= m_tfunc->eval(time);
34  }
35  m_mdot = std::max(mdot, 0.0);
36 }
37 
38 PressureController::PressureController() : FlowDevice(), m_master(0) {
39  m_type = PressureController_Type;
40 }
41 
43 {
44  if (!ready()) {
45  throw CanteraError("PressureController::updateMassFlowRate",
46  "Device is not ready; some parameters have not been set.");
47  }
48  double mdot = m_coeff;
49  double delta_P = in().pressure() - out().pressure();
50  if (m_pfunc) {
51  mdot *= m_pfunc->eval(delta_P);
52  } else {
53  mdot *= delta_P;
54  }
55  m_master->updateMassFlowRate(time);
56  mdot += m_master->massFlowRate();
57  m_mdot = std::max(mdot, 0.0);
58 }
59 
60 Valve::Valve() : FlowDevice() {
61  m_type = Valve_Type;
62 }
63 
64 void Valve::updateMassFlowRate(double time)
65 {
66  if (!ready()) {
67  throw CanteraError("Valve::updateMassFlowRate",
68  "Device is not ready; some parameters have not been set.");
69  }
70  double mdot = m_coeff;
71  if (m_tfunc) {
72  mdot *= m_tfunc->eval(time);
73  }
74  double delta_P = in().pressure() - out().pressure();
75  if (m_pfunc) {
76  mdot *= m_pfunc->eval(delta_P);
77  } else {
78  mdot *= delta_P;
79  }
80  m_mdot = std::max(mdot, 0.0);
81 }
82 
83 }
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:31
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:162
double m_coeff
Coefficient set by derived classes; used by updateMassFlowRate.
Definition: FlowDevice.h:165
double massFlowRate(double time=-999.0)
Mass flow rate (kg/s).
Definition: FlowDevice.h:61
virtual void updateMassFlowRate(double time)
Update the mass flow rate at time 'time'.
Definition: FlowDevice.h:78
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:99
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:104
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:159
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:233
virtual void updateMassFlowRate(double time)
Compute the currrent mass flow rate, based on the pressure difference.
Some flow devices derived from class FlowDevice.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
const int MFC_Type
Magic numbers.
Definition: FlowDevice.h:21