Cantera  3.2.0
Loading...
Searching...
No Matches
FlowDevice.cpp
Go to the documentation of this file.
1//! @file FlowDevice.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
10
11namespace Cantera
12{
13
14FlowDevice::FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
15 const string& name) : ConnectorNode(r0, r1, name)
16{
17 if (!m_nodes.first || !m_nodes.second) {
18 warn_deprecated("FlowDevice::FlowDevice",
19 "After Cantera 3.2, Reactors must be provided to a FlowDevice "
20 "constructor.");
21 return;
22 }
23 m_in = r0.get();
24 m_out = r1.get();
25 m_in->addOutlet(*this);
26 m_out->addInlet(*this);
27
28 // construct adapters between inlet and outlet species
29 const ThermoPhase& mixin = *m_in->phase()->thermo();
30 const ThermoPhase& mixout = *m_out->phase()->thermo();
31
32 m_nspin = mixin.nSpecies();
33 m_nspout = mixout.nSpecies();
34 string nm;
35 size_t ki, ko;
36 for (ki = 0; ki < m_nspin; ki++) {
37 nm = mixin.speciesName(ki);
38 ko = mixout.speciesIndex(nm, false);
39 m_in2out.push_back(ko);
40 }
41 for (ko = 0; ko < m_nspout; ko++) {
42 nm = mixout.speciesName(ko);
43 ki = mixin.speciesIndex(nm, false);
44 m_out2in.push_back(ki);
45 }
46}
47
49{
50 warn_deprecated("FlowDevice::install",
51 "To be removed after Cantera 3.2. Reactors should be provided to constructor "
52 "instead.");
53 if (m_in || m_out) {
54 throw CanteraError("FlowDevice::install", "Already installed");
55 }
56 m_in = &in;
57 m_out = &out;
58 m_in->addOutlet(*this);
59 m_out->addInlet(*this);
60
61 // construct adapters between inlet and outlet species
62 const ThermoPhase& mixin = m_in->contents();
63 const ThermoPhase& mixout = m_out->contents();
64
65 m_nspin = mixin.nSpecies();
66 m_nspout = mixout.nSpecies();
67 string nm;
68 size_t ki, ko;
69 for (ki = 0; ki < m_nspin; ki++) {
70 nm = mixin.speciesName(ki);
71 ko = mixout.speciesIndex(nm, false);
72 m_in2out.push_back(ko);
73 }
74 for (ko = 0; ko < m_nspout; ko++) {
75 nm = mixout.speciesName(ko);
76 ki = mixin.speciesIndex(nm, false);
77 m_out2in.push_back(ki);
78 }
79 return true;
80}
81
83{
84 warn_deprecated("FlowDevice::setPressureFunction",
85 "To be removed after Cantera 3.2. Replaceable by version using "
86 "shared pointer.");
87 m_pfunc = f;
88}
89
91{
92 double delta_P = in().pressure() - out().pressure();
93 if (m_pfunc) {
94 return m_pfunc->eval(delta_P);
95 }
96 return delta_P;
97}
98
100{
101 warn_deprecated("FlowDevice::setTimeFunction",
102 "To be removed after Cantera 3.2. Replaceable by version using "
103 "shared pointer.");
104 m_tfunc = g;
105}
106
108{
109 if (m_tfunc) {
110 return m_tfunc->eval(m_time);
111 }
112 return 1.;
113}
114
116{
117 if (k >= m_nspout) {
118 return 0.0;
119 }
120 size_t ki = m_out2in[k];
121 if (ki == npos) {
122 return 0.0;
123 }
124 return m_mdot * m_in->massFraction(ki);
125}
126
128{
129 return m_in->enthalpy_mass();
130}
131
132}
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Base class for walls and flow devices connecting reactors.
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:173
double m_time
Current reactor network time.
Definition FlowDevice.h:179
double enthalpy_mass()
specific enthalpy
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:93
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:98
double evalTimeFunction()
Return current value of the time function.
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
double evalPressureFunction()
Return current value of the pressure function.
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:170
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:270
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:174
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:147
Base class for reactor objects.
Definition ReactorBase.h:49
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997