6 #include "cantera/zeroD/IdealGasConstPressureReactor.h"
15 void IdealGasConstPressureReactor::setThermoMgr(
ThermoPhase& thermo)
19 if (thermo.
type() !=
"IdealGas") {
20 throw CanteraError(
"IdealGasConstPressureReactor::setThermoMgr",
21 "Incompatible phase type provided");
23 Reactor::setThermoMgr(thermo);
26 void IdealGasConstPressureReactor::getState(
double* y)
29 throw CanteraError(
"IdealGasConstPressureReactor::getState",
30 "Error: reactor is empty.");
32 m_thermo->restoreState(m_state);
35 y[0] = m_thermo->density() * m_vol;
38 y[1] = m_thermo->temperature();
41 m_thermo->getMassFractions(y+2);
45 getSurfaceInitialConditions(y + m_nsp + 2);
48 void IdealGasConstPressureReactor::initialize(doublereal t0)
50 ConstPressureReactor::initialize(t0);
51 m_hk.resize(m_nsp, 0.0);
54 void IdealGasConstPressureReactor::updateState(doublereal* y)
60 m_thermo->setMassFractions_NoNorm(y+2);
61 m_thermo->setState_TP(y[1], m_pressure);
62 m_vol = m_mass / m_thermo->density();
63 updateSurfaceState(y + m_nsp + 2);
64 updateConnected(
false);
67 void IdealGasConstPressureReactor::evalEqs(doublereal time, doublereal* y,
68 doublereal* ydot, doublereal* params)
72 double* dYdt = ydot + 2;
74 applySensitivity(params);
77 m_thermo->restoreState(m_state);
78 double mdot_surf = evalSurfaces(time, ydot + m_nsp + 2);
81 m_thermo->getPartialMolarEnthalpies(&m_hk[0]);
82 const vector_fp& mw = m_thermo->molecularWeights();
83 const doublereal* Y = m_thermo->massFractions();
86 m_kin->getNetProductionRates(&m_wdot[0]);
92 for (
size_t n = 0; n < m_nsp; n++) {
94 mcpdTdt -= m_wdot[n] * m_hk[n] * m_vol;
95 mcpdTdt -= m_sdot[n] * m_hk[n];
97 dYdt[n] = (m_wdot[n] * m_vol + m_sdot[n]) * mw[n] / m_mass;
99 dYdt[n] -= Y[n] * mdot_surf / m_mass;
103 for (
auto outlet : m_outlet) {
104 dmdt -= outlet->massFlowRate();
108 for (
auto inlet : m_inlet) {
109 double mdot = inlet->massFlowRate();
111 mcpdTdt += inlet->enthalpy_mass() * mdot;
112 for (
size_t n = 0; n < m_nsp; n++) {
113 double mdot_spec = inlet->outletSpeciesMassFlowRate(n);
115 dYdt[n] += (mdot_spec - mdot * Y[n]) / m_mass;
116 mcpdTdt -= m_hk[n] / mw[n] * mdot_spec;
122 ydot[1] = mcpdTdt / (m_mass * m_thermo->cp_mass());
127 resetSensitivity(params);
130 size_t IdealGasConstPressureReactor::componentIndex(
const string& nm)
const
132 size_t k = speciesIndex(nm);
135 }
else if (nm ==
"mass") {
137 }
else if (nm ==
"temperature") {
144 std::string IdealGasConstPressureReactor::componentName(
size_t k) {
146 return "temperature";
148 return ConstPressureReactor::componentName(k);
Base class for exceptions thrown by Cantera classes.
Base class for a phase with thermodynamic properties.
virtual std::string type() const
String indicating the thermodynamic model implemented.
const size_t npos
index returned by functions to indicate "no position"
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Namespace for the Cantera kernel.