| Cantera 3.0.0

Loading...
Searching...
No Matches
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
6#include "cantera/zeroD/FlowDevice.h"
7#include "cantera/zeroD/ReactorBase.h"
8#include "cantera/thermo/ThermoPhase.h"
9#include "cantera/numerics/Func1.h"
10
11 namespace Cantera
12{
13
14 bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
15{
16 if (m_in || m_out) {
17 throw CanteraError("FlowDevice::install", "Already installed");
18 }
19 m_in = &in;
20 m_out = &out;
21 m_in->addOutlet(*this);
22 m_out->addInlet(*this);
23
24 // construct adapters between inlet and outlet species
25 const ThermoPhase& mixin = m_in->contents();
26 const ThermoPhase& mixout = m_out->contents();
27
28 m_nspin = mixin.nSpecies();
29 m_nspout = mixout.nSpecies();
30 string nm;
31 size_t ki, ko;
32 for (ki = 0; ki < m_nspin; ki++) {
33 nm = mixin.speciesName(ki);
34 ko = mixout.speciesIndex(nm);
35 m_in2out.push_back(ko);
36 }
37 for (ko = 0; ko < m_nspout; ko++) {
38 nm = mixout.speciesName(ko);
39 ki = mixin.speciesIndex(nm);
40 m_out2in.push_back(ki);
41 }
42 return true;
43}
44
45 void FlowDevice::setPressureFunction(Func1* f)
46{
47 m_pfunc = f;
48}
49
50 double FlowDevice::evalPressureFunction()
51{
52 double delta_P = in().pressure() - out().pressure();
53 if (m_pfunc) {
54 return m_pfunc->eval(delta_P);
55 }
56 return delta_P;
57}
58
59 void FlowDevice::setTimeFunction(Func1* g)
60{
61 m_tfunc = g;
62}
63
64 double FlowDevice::evalTimeFunction()
65{
66 if (m_tfunc) {
67 return m_tfunc->eval(m_time);
68 }
69 return 1.;
70}
71
72 double FlowDevice::outletSpeciesMassFlowRate(size_t k)
73{
74 if (k >= m_nspout) {
75 return 0.0;
76 }
77 size_t ki = m_out2in[k];
78 if (ki == npos) {
79 return 0.0;
80 }
81 return m_mdot * m_in->massFraction(ki);
82}
83
84 double FlowDevice::enthalpy_mass()
85{
86 return m_in->enthalpy_mass();
87}
88
89}
FlowDevice.h
Func1.h
ReactorBase.h
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::FlowDevice::outletSpeciesMassFlowRate
double outletSpeciesMassFlowRate(size_t k)
Mass flow rate (kg/s) of outlet species k.
Definition FlowDevice.cpp:72
Cantera::FlowDevice::install
bool install(ReactorBase &in, ReactorBase &out)
Install a flow device between two reactors.
Definition FlowDevice.cpp:14
Cantera::FlowDevice::m_tfunc
Func1 * m_tfunc
Function set by setTimeFunction; used by updateMassFlowRate.
Definition FlowDevice.h:124
Cantera::FlowDevice::m_time
double m_time
Current reactor network time.
Definition FlowDevice.h:130
Cantera::FlowDevice::enthalpy_mass
double enthalpy_mass()
specific enthalpy
Definition FlowDevice.cpp:84
Cantera::FlowDevice::in
ReactorBase & in() const
Return a reference to the upstream reactor.
Definition FlowDevice.h:71
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:45
Cantera::FlowDevice::out
const ReactorBase & out() const
Return a const reference to the downstream reactor.
Definition FlowDevice.h:76
Cantera::FlowDevice::evalTimeFunction
double evalTimeFunction()
Return current value of the time function.
Definition FlowDevice.cpp:64
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:59
Cantera::FlowDevice::evalPressureFunction
double evalPressureFunction()
Return current value of the pressure function.
Definition FlowDevice.cpp:50
Cantera::FlowDevice::m_pfunc
Func1 * m_pfunc
Function set by setPressureFunction; used by updateMassFlowRate.
Definition FlowDevice.h:121
Cantera::Func1
Base class for 'functor' classes that evaluate a function of one variable.
Definition Func1.h:96
Cantera::Func1::eval
virtual double eval(double t) const
Evaluate the function.
Definition Func1.cpp:61
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
Cantera::Phase::speciesName
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
Cantera::Phase::speciesIndex
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:138
Cantera::ReactorBase
Base class for stirred reactors.
Definition ReactorBase.h:50
Cantera::ReactorBase::massFraction
double massFraction(size_t k) const
Return the mass fraction of the k-th species.
Definition ReactorBase.h:239
Cantera::ReactorBase::pressure
double pressure() const
Returns the current pressure (Pa) of the reactor.
Definition ReactorBase.h:224
Cantera::ReactorBase::addOutlet
void addOutlet(FlowDevice &outlet)
Connect an outlet FlowDevice to this reactor.
Definition ReactorBase.cpp:46
Cantera::ReactorBase::addInlet
void addInlet(FlowDevice &inlet)
Connect an inlet FlowDevice to this reactor.
Definition ReactorBase.cpp:41
Cantera::ReactorBase::contents
ThermoPhase & contents()
return a reference to the contents.
Definition ReactorBase.h:172
Cantera::ReactorBase::enthalpy_mass
double enthalpy_mass() const
Returns the current enthalpy (J/kg) of the reactor's contents.
Definition ReactorBase.h:214
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::npos
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:195