Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlowDevice.cpp
Go to the documentation of this file.
1 //! @file FlowDevice.cpp
5 
6 namespace Cantera
7 {
8 
10 {
11  if (m_in || m_out) {
12  throw CanteraError("FlowDevice::install", "Already installed");
13  }
14  m_in = ∈
15  m_out = &out;
16  m_in->addOutlet(*this);
17  m_out->addInlet(*this);
18 
19  // construct adapters between inlet and outlet species
20  ThermoPhase* mixin = &m_in->contents();
21  ThermoPhase* mixout = &m_out->contents();
22 
23  m_nspin = mixin->nSpecies();
24  m_nspout = mixout->nSpecies();
25  std::string nm;
26  size_t ki, ko;
27  for (ki = 0; ki < m_nspin; ki++) {
28  nm = mixin->speciesName(ki);
29  ko = mixout->speciesIndex(nm);
30  m_in2out.push_back(ko);
31  }
32  for (ko = 0; ko < m_nspout; ko++) {
33  nm = mixout->speciesName(ko);
34  ki = mixin->speciesIndex(nm);
35  m_out2in.push_back(ki);
36  }
37  return true;
38 }
39 
41 {
42  m_func = f;
43 }
44 
46 {
47  if (k >= m_nspout) {
48  return 0.0;
49  }
50  size_t ki = m_out2in[k];
51  if (ki == npos) {
52  return 0.0;
53  }
54  return m_mdot * m_in->massFraction(ki);
55 }
56 
58 {
59  return m_in->enthalpy_mass();
60 }
61 
62 }
doublereal enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:178
void setFunction(Cantera::Func1 *f)
Set a function of a single variable that is used in determining the mass flow rate through the device...
Definition: FlowDevice.cpp:40
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:82
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:57
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:97
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:257
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:41
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:77
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
Base class for stirred reactors.
Definition: ReactorBase.h:30
doublereal outletSpeciesMassFlowRate(size_t k)
Definition: FlowDevice.cpp:45
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:9
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:135
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
doublereal massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:203
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272