15FlowDevice::FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
16 const string& name) : ConnectorNode(r0, r1, name)
18 if (!m_nodes.first || !m_nodes.second) {
19 throw CanteraError(
"FlowDevice::FlowDevice",
20 "Reactors must be provided to FlowDevice constructor.");
24 m_in->addOutlet(*
this);
25 m_out->addInlet(*
this);
28 const ThermoPhase& mixin = *m_in->phase()->thermo();
29 const ThermoPhase& mixout = *m_out->phase()->thermo();
31 m_nspin = mixin.nSpecies();
32 m_nspout = mixout.nSpecies();
35 for (ki = 0; ki < m_nspin; ki++) {
36 nm = mixin.speciesName(ki);
37 ko = mixout.speciesIndex(nm,
false);
38 m_in2out.push_back(ko);
40 for (ko = 0; ko < m_nspout; ko++) {
41 nm = mixout.speciesName(ko);
42 ki = mixin.speciesIndex(nm,
false);
43 m_out2in.push_back(ki);
47double FlowDevice::evalPressureFunction()
49 double delta_P = in().pressure() - out().pressure();
51 return m_pfunc->eval(delta_P);
56double FlowDevice::evalTimeFunction()
59 return m_tfunc->eval(m_time);
64double FlowDevice::outletSpeciesMassFlowRate(
size_t k)
69 size_t ki = m_out2in[k];
73 return m_mdot * m_in->massFraction(ki);
76void FlowDevice::addMassFlowRateJacobian(SparseTriplets& trips,
size_t row,
77 double coeff,
bool includePressureSpecies)
79 double alpha = massFlowRate_ddP();
85 m_in->addPressureJacobian(trips, row, coeff * alpha, includePressureSpecies);
86 m_out->addPressureJacobian(trips, row, -coeff * alpha, includePressureSpecies);
89void FlowDevice::addOutletSpeciesMassFlowRateJacobian(
90 SparseTriplets& trips,
size_t row,
size_t k,
double coeff,
91 bool includeComposition,
bool includePressureSpecies)
96 size_t ki = m_out2in[k];
100 double Yin = m_in->massFraction(ki);
103 addMassFlowRateJacobian(trips, row, coeff * Yin, includePressureSpecies);
104 if (includeComposition && m_mdot != 0.0) {
105 m_in->addSpeciesMassFractionJacobian(trips, row, ki, coeff * m_mdot);
109double FlowDevice::enthalpy_mass()
111 return m_in->enthalpy_mass();
114double FlowDevice::pressureFunction_ddP(
double deltaP)
const
120 return m_pfunc->derivative()->eval(deltaP);
125 double eps = std::sqrt(std::numeric_limits<double>::epsilon())
126 * std::max(1.0, std::abs(deltaP));
127 return (m_pfunc->eval(deltaP + eps) - m_pfunc->eval(deltaP - eps))
132void FlowDevice::addInletEnthalpyJacobian(SparseTriplets& trips,
size_t row,
133 double coeff,
bool includeComposition)
136 m_in->addEnthalpyJacobian(trips, row, coeff * m_mdot, includeComposition);
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Base class for exceptions thrown by Cantera classes.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"