Cantera  2.5.1
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 
9 
10 namespace Cantera
11 {
12 
13 FlowDevice::FlowDevice() : m_mdot(Undef), m_pfunc(0), m_tfunc(0),
14  m_coeff(1.0), m_type(0),
15  m_nspin(0), m_nspout(0),
16  m_in(0), m_out(0) {}
17 
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 
50 {
51  m_pfunc = f;
52 }
53 
55 {
56  m_tfunc = g;
57 }
58 
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 
72 {
73  return m_in->enthalpy_mass();
74 }
75 
76 }
Cantera::FlowDevice::outletSpeciesMassFlowRate
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition: FlowDevice.cpp:59
Cantera::ReactorBase::addOutlet
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:52
Cantera::ReactorBase
Base class for stirred reactors.
Definition: ReactorBase.h:47
Cantera::FlowDevice::m_tfunc
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:162
FlowDevice.h
ReactorBase.h
Cantera::FlowDevice::install
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition: FlowDevice.cpp:18
Cantera::ReactorBase::enthalpy_mass
doublereal enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition: ReactorBase.h:223
Cantera::ReactorBase::massFraction
doublereal massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition: ReactorBase.h:248
Cantera::FlowDevice::setTimeFunction
virtual void setTimeFunction(Func1 *g)
Set a function of time that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:54
Cantera::FlowDevice::in
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition: FlowDevice.h:99
Cantera::ReactorBase::contents
thermo_t & contents()
return a reference to the contents.
Definition: ReactorBase.h:180
Cantera::Undef
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition: ct_defs.h:157
Cantera::Phase::speciesIndex
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:201
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:285
Cantera::Func1
Base class for 'functor' classes that evaluate a function of one variable.
Definition: Func1.h:43
Func1.h
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::FlowDevice::m_pfunc
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition: FlowDevice.h:159
Cantera::FlowDevice::setPressureFunction
virtual void setPressureFunction(Func1 *f)
Set a function of pressure that is used in determining the mass flow rate through the device.
Definition: FlowDevice.cpp:49
Cantera::npos
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:188
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::FlowDevice::out
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition: FlowDevice.h:104
Cantera::Phase::speciesName
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:229
Cantera::FlowDevice::enthalpy_mass
double enthalpy_mass()
specific enthalpy
Definition: FlowDevice.cpp:71
Cantera::ReactorBase::addInlet
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition: ReactorBase.cpp:47