16 void ConstPressureReactor::getState(
double* y)
20 "Error: reactor is empty.");
22 m_thermo->restoreState(m_state);
25 y[0] = m_thermo->density() * m_vol;
28 y[1] = m_thermo->enthalpy_mass() * m_thermo->density() * m_vol;
31 m_thermo->getMassFractions(y+2);
35 getSurfaceInitialConditions(y + m_nsp + 2);
38 void ConstPressureReactor::initialize(doublereal t0)
40 Reactor::initialize(t0);
44 void ConstPressureReactor::updateState(doublereal* y)
50 m_thermo->setMassFractions_NoNorm(y+2);
52 m_thermo->setState_HP(y[1]/m_mass, m_pressure);
54 m_thermo->setPressure(m_pressure);
56 m_vol = m_mass / m_thermo->density();
57 updateSurfaceState(y + m_nsp + 2);
60 m_enthalpy = m_thermo->enthalpy_mass();
61 m_intEnergy = m_thermo->intEnergy_mass();
62 m_thermo->saveState(m_state);
65 void ConstPressureReactor::evalEqs(doublereal time, doublereal* y,
66 doublereal* ydot, doublereal* params)
69 double* dYdt = ydot + 2;
70 m_thermo->restoreState(m_state);
71 applySensitivity(params);
73 double mdot_surf = evalSurfaces(time, ydot + m_nsp + 2);
76 const vector_fp& mw = m_thermo->molecularWeights();
77 const doublereal* Y = m_thermo->massFractions();
80 m_kin->getNetProductionRates(&m_wdot[0]);
83 for (
size_t k = 0; k < m_nsp; k++) {
85 dYdt[k] = (m_wdot[k] * m_vol + m_sdot[k]) * mw[k] / m_mass;
87 dYdt[k] -= Y[k] * mdot_surf / m_mass;
94 for (
size_t i = 0; i < m_outlet.size(); i++) {
95 double mdot_out = m_outlet[i]->massFlowRate(time);
97 dHdt -= mdot_out * m_enthalpy;
101 for (
size_t i = 0; i < m_inlet.size(); i++) {
102 double mdot_in = m_inlet[i]->massFlowRate(time);
104 for (
size_t n = 0; n < m_nsp; n++) {
105 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
107 dYdt[n] += (mdot_spec - mdot_in * Y[n]) / m_mass;
109 dHdt += mdot_in * m_inlet[i]->enthalpy_mass();
120 resetSensitivity(params);
123 size_t ConstPressureReactor::componentIndex(
const string& nm)
const 125 size_t k = speciesIndex(nm);
128 }
else if (nm ==
"mass") {
130 }
else if (nm ==
"enthalpy") {
137 std::string ConstPressureReactor::componentName(
size_t k) {
142 }
else if (k >= 2 && k < neq()) {
144 if (k < m_thermo->nSpecies()) {
145 return m_thermo->speciesName(k);
147 k -= m_thermo->nSpecies();
149 for (
auto& S : m_surfaces) {
151 if (k < th->nSpecies()) {
158 throw CanteraError(
"ConstPressureReactor::componentName",
159 "Index is out of bounds.");
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
Header file for class Wall.
const size_t npos
index returned by functions to indicate "no position"
size_t nSpecies() const
Returns the number of species in the phase.
Base class for a phase with thermodynamic properties.
std::string speciesName(size_t k) const
Name of the species with index k.
Base class for exceptions thrown by Cantera classes.
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.