| 217 | } |
| 218 | |
| 219 | void Reactor::eval(double time, double* LHS, double* RHS) |
| 220 | { |
| 221 | double& dmdt = RHS[0]; |
| 222 | double* mdYdt = RHS + 3; // mass * dY/dt |
| 223 | |
| 224 | evalWalls(time); |
| 225 | m_thermo->restoreState(m_state); |
| 226 | const vector<double>& mw = m_thermo->molecularWeights(); |
| 227 | const double* Y = m_thermo->massFractions(); |
| 228 | |
| 229 | evalSurfaces(LHS + m_nsp + 3, RHS + m_nsp + 3, m_sdot.data()); |
| 230 | // mass added to gas phase from surface reactions |
| 231 | double mdot_surf = dot(m_sdot.begin(), m_sdot.end(), mw.begin()); |
| 232 | dmdt = mdot_surf; |
| 233 | |
| 234 | // volume equation |
| 235 | RHS[1] = m_vdot; |
| 236 | |
| 237 | if (m_chem) { |
| 238 | m_kin->getNetProductionRates(&m_wdot[0]); // "omega dot" |
| 239 | } |
| 240 | |
| 241 | for (size_t k = 0; k < m_nsp; k++) { |
| 242 | // production in gas phase and from surfaces |
| 243 | mdYdt[k] = (m_wdot[k] * m_vol + m_sdot[k]) * mw[k]; |
| 244 | // dilution by net surface mass flux |
| 245 | mdYdt[k] -= Y[k] * mdot_surf; |
| 246 | LHS[k+3] = m_mass; |
| 247 | } |
| 248 | |
| 249 | // Energy equation. |
| 250 | // @f[ |
| 251 | // \dot U = -P\dot V + A \dot q + \dot m_{in} h_{in} - \dot m_{out} h. |
| 252 | // @f] |
| 253 | if (m_energy) { |
| 254 | RHS[2] = - m_thermo->pressure() * m_vdot + m_Qdot; |
| 255 | } else { |
| 256 | RHS[2] = 0.0; |
| 257 | } |
| 258 | |
| 259 | // add terms for outlets |
| 260 | for (auto outlet : m_outlet) { |
| 261 | double mdot = outlet->massFlowRate(); |
| 262 | dmdt -= mdot; // mass flow out of system |
| 263 | if (m_energy) { |
| 264 | RHS[2] -= mdot * m_enthalpy; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // add terms for inlets |
| 269 | for (auto inlet : m_inlet) { |
| 270 | double mdot = inlet->massFlowRate(); |
| 271 | dmdt += mdot; // mass flow into system |
| 272 | for (size_t n = 0; n < m_nsp; n++) { |
| 273 | double mdot_spec = inlet->outletSpeciesMassFlowRate(n); |
| 274 | // flow of species into system and dilution by other species |
| 275 | mdYdt[n] += (mdot_spec - mdot * Y[n]); |
| 276 | } |
no test coverage detected