Loading [MathJax]/extensions/tex2jax.js
Cantera  3.2.0a1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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.1, 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.1. 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 m_pfunc = f;
85}
86
87double FlowDevice::evalPressureFunction()
88{
89 double delta_P = in().pressure() - out().pressure();
90 if (m_pfunc) {
91 return m_pfunc->eval(delta_P);
92 }
93 return delta_P;
94}
95
96void FlowDevice::setTimeFunction(Func1* g)
97{
98 m_tfunc = g;
99}
100
101double FlowDevice::evalTimeFunction()
102{
103 if (m_tfunc) {
104 return m_tfunc->eval(m_time);
105 }
106 return 1.;
107}
108
109double FlowDevice::outletSpeciesMassFlowRate(size_t k)
110{
111 if (k >= m_nspout) {
112 return 0.0;
113 }
114 size_t ki = m_out2in[k];
115 if (ki == npos) {
116 return 0.0;
117 }
118 return m_mdot * m_in->massFraction(ki);
119}
120
121double FlowDevice::enthalpy_mass()
122{
123 return m_in->enthalpy_mass();
124}
125
126}
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 stirred reactors.
Definition ReactorBase.h:49
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