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);
58 updateConnected(
false);
61 void ConstPressureReactor::evalEqs(doublereal time, doublereal* y,
62 doublereal* ydot, doublereal* params)
65 double* dYdt = ydot + 2;
68 applySensitivity(params);
70 m_thermo->restoreState(m_state);
71 double mdot_surf = evalSurfaces(time, ydot + m_nsp + 2);
74 const vector_fp& mw = m_thermo->molecularWeights();
75 const doublereal* Y = m_thermo->massFractions();
78 m_kin->getNetProductionRates(&m_wdot[0]);
81 for (
size_t k = 0; k < m_nsp; k++) {
83 dYdt[k] = (m_wdot[k] * m_vol + m_sdot[k]) * mw[k] / m_mass;
85 dYdt[k] -= Y[k] * mdot_surf / m_mass;
92 for (
auto outlet : m_outlet) {
93 double mdot = outlet->massFlowRate();
95 dHdt -= mdot * m_enthalpy;
99 for (
auto inlet : m_inlet) {
100 double mdot = inlet->massFlowRate();
102 for (
size_t n = 0; n < m_nsp; n++) {
103 double mdot_spec = inlet->outletSpeciesMassFlowRate(n);
105 dYdt[n] += (mdot_spec - mdot * Y[n]) / m_mass;
107 dHdt += mdot * inlet->enthalpy_mass();
118 resetSensitivity(params);
121 size_t ConstPressureReactor::componentIndex(
const string& nm)
const
123 size_t k = speciesIndex(nm);
126 }
else if (nm ==
"mass") {
128 }
else if (nm ==
"enthalpy") {
135 std::string ConstPressureReactor::componentName(
size_t k) {
140 }
else if (k >= 2 && k < neq()) {
142 if (k < m_thermo->nSpecies()) {
143 return m_thermo->speciesName(k);
145 k -= m_thermo->nSpecies();
147 for (
auto& S : m_surfaces) {
149 if (k < th->nSpecies()) {
156 throw CanteraError(
"ConstPressureReactor::componentName",
157 "Index is out of bounds.");
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Header file for base class WallBase.
Base class for exceptions thrown by Cantera classes.
size_t nSpecies() const
Returns the number of species in the phase.
std::string speciesName(size_t k) const
Name of the species with index k.
Base class for a phase with thermodynamic properties.
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.