9 #include "cantera/zeroD/ConstPressureReactor.h"
20 ConstPressureReactor::ConstPressureReactor() :
Reactor() {}
22 void ConstPressureReactor::
23 getInitialConditions(
double t0,
size_t leny,
double* y)
28 "Error: reactor is empty.");
34 doublereal mass = m_thermo->
density() * m_vol;
49 size_t loc =
m_nsp + 2;
51 for (
size_t m = 0; m < m_nwalls; m++) {
52 surf = m_wall[m]->surface(m_lr[m]);
54 m_wall[m]->getCoverages(m_lr[m], y + loc);
55 loc += surf->nSpecies();
63 m_sdot.resize(
m_nsp, 0.0);
65 for (
size_t w = 0; w < m_nwalls; w++)
66 if (m_wall[w]->surface(m_lr[w])) {
67 m_nv += m_wall[w]->surface(m_lr[w])->nSpecies();
73 size_t nt = 0, maxnt = 0;
74 for (
size_t m = 0; m < m_nwalls; m++) {
75 if (m_wall[m]->kinetics(m_lr[m])) {
76 nt = m_wall[m]->kinetics(m_lr[m])->nTotalSpecies();
80 if (m_wall[m]->kinetics(m_lr[m])) {
82 &m_wall[m]->kinetics(m_lr[m])->thermo(0)) {
84 "First phase of all kinetics managers must be"
100 doublereal* mss = y + 2;
101 doublereal mass = accumulate(y+2, y+2+
m_nsp, 0.0);
109 m_vol = 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]);
116 m_wall[m]->setCoverages(m_lr[m], y+loc);
131 void ConstPressureReactor::evalEqs(doublereal time, doublereal* y,
132 doublereal* ydot, doublereal* params)
145 npar = m_pnum.size();
146 for (
size_t n = 0; n < npar; n++) {
151 for (
size_t m = 0; m < m_nwalls; m++) {
152 if (m_nsens_wall[m] > 0) {
153 m_wall[m]->setSensitivityParameters(m_lr[m], params + ploc);
154 ploc += m_nsens_wall[m];
163 doublereal rs0, sum, wallarea;
166 size_t lr, ns, loc =
m_nsp+2, surfloc;
167 fill(m_sdot.begin(), m_sdot.end(), 0.0);
168 for (
size_t i = 0; i < m_nwalls; i++) {
170 m_Q += lr*m_wall[i]->Q(time);
171 kin = m_wall[i]->kinetics(m_lr[i]);
172 surf = m_wall[i]->surface(m_lr[i]);
174 rs0 = 1.0/surf->siteDensity();
175 nk = surf->nSpecies();
177 surf->setTemperature(m_state[0]);
178 m_wall[i]->syncCoverages(m_lr[i]);
182 for (
size_t k = 1; k < nk; k++) {
183 ydot[loc + k] = m_work[surfloc+k]*rs0*surf->size(k);
184 sum -= ydot[loc + k];
189 wallarea = m_wall[i]->area();
190 for (
size_t k = 0; k <
m_nsp; k++) {
191 m_sdot[k] += m_work[k]*wallarea;
208 fill(ydot + 2, ydot + 2 +
m_nsp, 0.0);
210 for (
size_t n = 0; n <
m_nsp; n++) {
212 ydot[n+2] += m_sdot[n];
239 for (
size_t i = 0; i < m_nOutlets; i++) {
240 mdot_out = m_outlet[i]->massFlowRate(time);
241 for (
size_t n = 0; n <
m_nsp; n++) {
242 ydot[2+n] -= mdot_out * mf[n];
253 for (
size_t i = 0; i < m_nInlets; i++) {
254 mdot_in = m_inlet[i]->massFlowRate(time);
255 for (
size_t n = 0; n <
m_nsp; n++) {
256 ydot[2+n] += m_inlet[i]->outletSpeciesMassFlowRate(n);
259 ydot[0] += mdot_in * m_inlet[i]->enthalpy_mass();
266 npar = m_pnum.size();
267 for (
size_t n = 0; n < npar; n++) {
272 for (
size_t m = 0; m < m_nwalls; m++) {
273 if (m_nsens_wall[m] > 0) {
274 m_wall[m]->resetSensitivityParameters(m_lr[m]);
275 ploc += m_nsens_wall[m];
281 size_t ConstPressureReactor::componentIndex(
string nm)
const
296 size_t walloffset = 0, kp = 0;
298 for (
size_t m = 0; m < m_nwalls; m++) {
299 if (m_wall[m]->kinetics(m_lr[m])) {
300 kp = m_wall[m]->kinetics(m_lr[m])->reactionPhaseIndex();
301 th = &m_wall[m]->kinetics(m_lr[m])->thermo(kp);
302 k = th->speciesIndex(nm);
304 return k + 2 + m_nsp + walloffset;
306 walloffset += th->nSpecies();