Cantera  3.3.0a1
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
10
11namespace Cantera
12{
13
14FlowDevice::FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
15 const string& name) : ConnectorNode(r0, r1, name)
16{
17 if (!m_nodes.first || !m_nodes.second) {
18 throw CanteraError("FlowDevice::FlowDevice",
19 "Reactors must be provided to FlowDevice constructor.");
20 }
21 m_in = r0.get();
22 m_out = r1.get();
23 m_in->addOutlet(*this);
24 m_out->addInlet(*this);
25
26 // construct adapters between inlet and outlet species
27 const ThermoPhase& mixin = *m_in->phase()->thermo();
28 const ThermoPhase& mixout = *m_out->phase()->thermo();
29
30 m_nspin = mixin.nSpecies();
31 m_nspout = mixout.nSpecies();
32 string nm;
33 size_t ki, ko;
34 for (ki = 0; ki < m_nspin; ki++) {
35 nm = mixin.speciesName(ki);
36 ko = mixout.speciesIndex(nm, false);
37 m_in2out.push_back(ko);
38 }
39 for (ko = 0; ko < m_nspout; ko++) {
40 nm = mixout.speciesName(ko);
41 ki = mixin.speciesIndex(nm, false);
42 m_out2in.push_back(ki);
43 }
44}
45
46double FlowDevice::evalPressureFunction()
47{
48 double delta_P = in().pressure() - out().pressure();
49 if (m_pfunc) {
50 return m_pfunc->eval(delta_P);
51 }
52 return delta_P;
53}
54
55double FlowDevice::evalTimeFunction()
56{
57 if (m_tfunc) {
58 return m_tfunc->eval(m_time);
59 }
60 return 1.;
61}
62
63double FlowDevice::outletSpeciesMassFlowRate(size_t k)
64{
65 if (k >= m_nspout) {
66 return 0.0;
67 }
68 size_t ki = m_out2in[k];
69 if (ki == npos) {
70 return 0.0;
71 }
72 return m_mdot * m_in->massFraction(ki);
73}
74
75double FlowDevice::enthalpy_mass()
76{
77 return m_in->enthalpy_mass();
78}
79
80}
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180