Cantera  2.4.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 http://www.cantera.org/license.txt for license and copyright information.
5 
9 
10 namespace Cantera
11 {
12 
14 {
15  if (m_in || m_out) {
16  throw CanteraError("FlowDevice::install", "Already installed");
17  }
18  m_in = ∈
19  m_out = &out;
20  m_in->addOutlet(*this);
21  m_out->addInlet(*this);
22 
23  // construct adapters between inlet and outlet species
24  const ThermoPhase& mixin = m_in->contents();
25  const ThermoPhase& mixout = m_out->contents();
26 
27  m_nspin = mixin.nSpecies();
28  m_nspout = mixout.nSpecies();
29  std::string nm;
30  size_t ki, ko;
31  for (ki = 0; ki < m_nspin; ki++) {
32  nm = mixin.speciesName(ki);
33  ko = mixout.speciesIndex(nm);
34  m_in2out.push_back(ko);
35  }
36  for (ko = 0; ko < m_nspout; ko++) {
37  nm = mixout.speciesName(ko);
38  ki = mixin.speciesIndex(nm);
39  m_out2in.push_back(ki);
40  }
41  return true;
42 }
43 
45 {
46  m_func = f;
47 }
48 
50 {
51  if (k >= m_nspout) {
52  return 0.0;
53  }
54  size_t ki = m_out2in[k];
55  if (ki == npos) {
56  return 0.0;
57  }
58  return m_mdot * m_in->massFraction(ki);
59 }
60 
62 {
63  return m_in->enthalpy_mass();
64 }
65 
66 }
size_t speciesIndex(const std::string &name) const
Returns the index of a species named &#39;name&#39; within the Phase object.
Definition: Phase.cpp:175
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
doublereal enthalpy_mass()
specific enthalpy
Definition: FlowDevice.cpp:61
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:266
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:79
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:52
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:47
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:191
Base class for &#39;functor&#39; classes that evaluate a function of one variable.
Definition: Func1.h:41
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
Base class for stirred reactors.
Definition: ReactorBase.h:44
doublereal outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition: FlowDevice.cpp:49
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:13
doublereal massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:219
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:151
void setFunction(Func1 *f)
Set a function of a single variable that is used in determining the mass flow rate through the device...
Definition: FlowDevice.cpp:44
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:74
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
doublereal enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor&#39;s contents.
Definition: ReactorBase.h:194