8 #include "cantera/zeroD/IdealGasConstPressureReactor.h"
19 void IdealGasConstPressureReactor::setThermoMgr(
ThermoPhase& thermo)
25 "Incompatible phase type provided");
27 Reactor::setThermoMgr(thermo);
31 void IdealGasConstPressureReactor::
32 getInitialConditions(
double t0,
size_t leny,
double* y)
37 "Error: reactor is empty.");
39 m_thermo->restoreState(m_state);
42 y[0] = m_thermo->density() * m_vol;
45 y[1] = m_thermo->temperature();
48 m_thermo->getMassFractions(y+2);
52 size_t loc = m_nsp + 2;
54 for (
size_t m = 0; m < m_nwalls; m++) {
55 surf = m_wall[m]->surface(m_lr[m]);
63 void IdealGasConstPressureReactor::initialize(doublereal t0)
65 m_thermo->restoreState(m_state);
66 m_sdot.resize(m_nsp, 0.0);
67 m_wdot.resize(m_nsp, 0.0);
68 m_hk.resize(m_nsp, 0.0);
70 for (
size_t w = 0; w < m_nwalls; w++)
71 if (m_wall[w]->surface(m_lr[w])) {
72 m_nv += m_wall[w]->surface(m_lr[w])->nSpecies();
75 m_enthalpy = m_thermo->enthalpy_mass();
76 m_pressure = m_thermo->pressure();
77 m_intEnergy = m_thermo->intEnergy_mass();
79 size_t nt = 0, maxnt = 0;
80 for (
size_t m = 0; m < m_nwalls; m++) {
81 if (m_wall[m]->kinetics(m_lr[m])) {
82 nt = m_wall[m]->kinetics(m_lr[m])->nTotalSpecies();
86 if (m_wall[m]->kinetics(m_lr[m])) {
87 if (&m_kin->thermo(0) !=
88 &m_wall[m]->kinetics(m_lr[m])->thermo(0)) {
89 throw CanteraError(
"IdealGasConstPressureReactor::initialize",
90 "First phase of all kinetics managers must be"
97 std::sort(m_pnum.begin(), m_pnum.end());
101 void IdealGasConstPressureReactor::updateState(doublereal* y)
107 m_thermo->setMassFractions_NoNorm(y+2);
108 m_thermo->setState_TP(y[1], m_pressure);
109 m_vol = m_mass / m_thermo->density();
111 size_t loc = m_nsp + 2;
113 for (
size_t m = 0; m < m_nwalls; m++) {
114 surf = m_wall[m]->surface(m_lr[m]);
122 m_enthalpy = m_thermo->enthalpy_mass();
123 m_intEnergy = m_thermo->intEnergy_mass();
124 m_thermo->saveState(m_state);
127 void IdealGasConstPressureReactor::evalEqs(doublereal time, doublereal* y,
128 doublereal* ydot, doublereal* params)
131 m_thermo->restoreState(m_state);
140 npar = m_pnum.size();
141 for (
size_t n = 0; n < npar; n++) {
143 m_kin->setMultiplier(m_pnum[n], mult*params[n]);
146 for (
size_t m = 0; m < m_nwalls; m++) {
147 if (m_nsens_wall[m] > 0) {
148 m_wall[m]->setSensitivityParameters(m_lr[m], params + ploc);
149 ploc += m_nsens_wall[m];
157 doublereal rs0, sum, wallarea;
158 double mcpdTdt = 0.0;
160 double* dYdt = ydot + 2;
161 m_thermo->getPartialMolarEnthalpies(&m_hk[0]);
164 size_t lr, ns, loc = m_nsp+2, surfloc;
165 fill(m_sdot.begin(), m_sdot.end(), 0.0);
166 for (
size_t i = 0; i < m_nwalls; i++) {
168 m_Q += lr*m_wall[i]->Q(time);
169 kin = m_wall[i]->kinetics(m_lr[i]);
170 surf = m_wall[i]->surface(m_lr[i]);
176 m_wall[i]->syncCoverages(m_lr[i]);
180 for (
size_t k = 1; k < nk; k++) {
181 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->
size(k);
182 sum -= ydot[loc + k];
187 wallarea = m_wall[i]->area();
188 for (
size_t k = 0; k < m_nsp; k++) {
189 m_sdot[k] += m_work[k]*wallarea;
194 const vector_fp& mw = m_thermo->molecularWeights();
195 const doublereal* Y = m_thermo->massFractions();
198 m_kin->getNetProductionRates(&m_wdot[0]);
201 double mdot_surf = 0.0;
202 for (
size_t k = 0; k < m_nsp; k++) {
204 dYdt[k] = (m_wdot[k] * m_vol + m_sdot[k]) * mw[k] / m_mass;
205 mdot_surf += m_sdot[k] * mw[k];
212 for (
size_t n = 0; n < m_nsp; n++) {
214 mcpdTdt -= m_wdot[n] * m_hk[n] * m_vol;
215 mcpdTdt -= m_sdot[n] * m_hk[n];
217 dYdt[n] -= Y[n] * mdot_surf / m_mass;
223 for (
size_t i = 0; i < m_nOutlets; i++) {
224 dmdt -= m_outlet[i]->massFlowRate(time);
228 for (
size_t i = 0; i < m_nInlets; i++) {
229 double mdot_in = m_inlet[i]->massFlowRate(time);
231 mcpdTdt += m_inlet[i]->enthalpy_mass() * mdot_in;
232 for (
size_t n = 0; n < m_nsp; n++) {
233 double mdot_spec = m_inlet[i]->outletSpeciesMassFlowRate(n);
235 dYdt[n] += (mdot_spec - mdot_in * Y[n]) / m_mass;
236 mcpdTdt -= m_hk[n] / mw[n] * mdot_spec;
243 ydot[1] = mcpdTdt / (m_mass * m_thermo->cp_mass());
250 npar = m_pnum.size();
251 for (
size_t n = 0; n < npar; n++) {
252 mult = m_kin->multiplier(m_pnum[n]);
253 m_kin->setMultiplier(m_pnum[n], mult/params[n]);
256 for (
size_t m = 0; m < m_nwalls; m++) {
257 if (m_nsens_wall[m] > 0) {
258 m_wall[m]->resetSensitivityParameters(m_lr[m]);
259 ploc += m_nsens_wall[m];
265 size_t IdealGasConstPressureReactor::componentIndex(
const string& nm)
const
270 return ConstPressureReactor::componentIndex(nm);
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.
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
doublereal size(size_t k) const
This routine returns the size of species k.
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Base class for a phase with thermodynamic properties.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
Public interface for kinetics managers.
Base class for exceptions thrown by Cantera classes.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
size_t nSpecies() const
Returns the number of species in the phase.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual int eosType() const
Equation of state type flag.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
const int cIdealGas
Equation of state types:
doublereal siteDensity()
Returns the site density.