6 #include "cantera/zeroD/IdealGasConstPressureReactor.h" 14 void IdealGasConstPressureReactor::setThermoMgr(
ThermoPhase& thermo)
18 if (thermo.
type() !=
"IdealGas") {
20 "Incompatible phase type provided");
22 Reactor::setThermoMgr(thermo);
25 void IdealGasConstPressureReactor::getState(
double* y)
29 "Error: reactor is empty.");
31 m_thermo->restoreState(m_state);
34 y[0] = m_thermo->density() * m_vol;
37 y[1] = m_thermo->temperature();
40 m_thermo->getMassFractions(y+2);
44 getSurfaceInitialConditions(y + m_nsp + 2);
47 void IdealGasConstPressureReactor::initialize(doublereal t0)
49 ConstPressureReactor::initialize(t0);
50 m_hk.resize(m_nsp, 0.0);
53 void IdealGasConstPressureReactor::updateState(doublereal* y)
59 m_thermo->setMassFractions_NoNorm(y+2);
60 m_thermo->setState_TP(y[1], m_pressure);
61 m_vol = m_mass / m_thermo->density();
62 updateSurfaceState(y + m_nsp + 2);
65 m_enthalpy = m_thermo->enthalpy_mass();
66 m_intEnergy = m_thermo->intEnergy_mass();
67 m_thermo->saveState(m_state);
70 void IdealGasConstPressureReactor::evalEqs(doublereal time, doublereal* y,
71 doublereal* ydot, doublereal* params)
75 double* dYdt = ydot + 2;
77 m_thermo->restoreState(m_state);
78 applySensitivity(params);
80 double mdot_surf = evalSurfaces(time, ydot + m_nsp + 2);
83 m_thermo->getPartialMolarEnthalpies(&m_hk[0]);
84 const vector_fp& mw = m_thermo->molecularWeights();
85 const doublereal* Y = m_thermo->massFractions();
88 m_kin->getNetProductionRates(&m_wdot[0]);
94 for (
size_t n = 0; n < m_nsp; n++) {
96 mcpdTdt -= m_wdot[n] * m_hk[n] * m_vol;
97 mcpdTdt -= m_sdot[n] * m_hk[n];
99 dYdt[n] = (m_wdot[n] * m_vol + m_sdot[n]) * mw[n] / m_mass;
101 dYdt[n] -= Y[n] * mdot_surf / m_mass;
105 for (
size_t i = 0; i < m_outlet.size(); i++) {
106 dmdt -= m_outlet[i]->massFlowRate(time);
110 for (
size_t i = 0; i < m_inlet.size(); i++) {
111 double mdot_in = m_inlet[i]->massFlowRate(time);
113 mcpdTdt += m_inlet[i]->enthalpy_mass() * mdot_in;
114 for (
size_t n = 0; n < m_nsp; n++) {
115 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
117 dYdt[n] += (mdot_spec - mdot_in * Y[n]) / m_mass;
118 mcpdTdt -= m_hk[n] / mw[n] * mdot_spec;
124 ydot[1] = mcpdTdt / (m_mass * m_thermo->cp_mass());
129 resetSensitivity(params);
132 size_t IdealGasConstPressureReactor::componentIndex(
const string& nm)
const 134 size_t k = speciesIndex(nm);
137 }
else if (nm ==
"mass") {
139 }
else if (nm ==
"temperature") {
146 std::string IdealGasConstPressureReactor::componentName(
size_t k) {
148 return "temperature";
150 return ConstPressureReactor::componentName(k);
const size_t npos
index returned by functions to indicate "no position"
Base class for a phase with thermodynamic properties.
Base class for exceptions thrown by Cantera classes.
virtual std::string type() const
String indicating the thermodynamic model implemented.
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.