Cantera 2.6.0
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() : m_mdot(Undef), m_pfunc(0), m_tfunc(0),
15 m_coeff(1.0), m_nspin(0), m_nspout(0),
16 m_in(0), m_out(0) {}
17
18bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
19{
20 if (m_in || m_out) {
21 throw CanteraError("FlowDevice::install", "Already installed");
22 }
23 m_in = ∈
24 m_out = &out;
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 std::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 return true;
47}
48
49void FlowDevice::setPressureFunction(Func1* f)
50{
51 m_pfunc = f;
52}
53
54void FlowDevice::setTimeFunction(Func1* g)
55{
56 m_tfunc = g;
57}
58
59double FlowDevice::outletSpeciesMassFlowRate(size_t k)
60{
61 if (k >= m_nspout) {
62 return 0.0;
63 }
64 size_t ki = m_out2in[k];
65 if (ki == npos) {
66 return 0.0;
67 }
68 return m_mdot * m_in->massFraction(ki);
69}
70
71double FlowDevice::enthalpy_mass()
72{
73 return m_in->enthalpy_mass();
74}
75
76}
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:44
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:273
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:200
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:187
Base class for stirred reactors.
Definition: ReactorBase.h:49
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:53
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:161