Cantera  3.2.0a2
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->contents();
30 const ThermoPhase& mixout = m_out->contents();
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);
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);
44 m_out2in.push_back(ki);
45 }
46}
47
48bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
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);
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);
77 m_out2in.push_back(ki);
78 }
79 return true;
80}
81
82void FlowDevice::setPressureFunction(Func1* f)
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
90double FlowDevice::evalPressureFunction()
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
99void FlowDevice::setTimeFunction(Func1* g)
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
107double FlowDevice::evalTimeFunction()
108{
109 if (m_tfunc) {
110 return m_tfunc->eval(m_time);
111 }
112 return 1.;
113}
114
115double FlowDevice::outletSpeciesMassFlowRate(size_t k)
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
127double FlowDevice::enthalpy_mass()
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 'functor' classes that evaluate a function of one variable.
Definition Func1.h:75
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:28
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:232
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:142
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:129
Base class for reactor objects.
Definition ReactorBase.h:49
virtual void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
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