[Reactor] Refactor updateState and getInitialConditions implementations

Extract common parts related to surface species
This commit is contained in:
Ray Speth 2014-06-10 16:22:46 +00:00
parent 67de2fa793
commit 1437aade8c
5 changed files with 32 additions and 78 deletions

View file

@ -169,6 +169,12 @@ protected:
//! @returns Net mass flux from surfaces
virtual double evalSurfaces(double t, double* ydot);
//! Update the state of SurfPhase objects attached to this reactor
virtual void updateSurfaceState(double* y);
//! Get initial conditions for SurfPhase objects attached to this reactor
virtual void getSurfaceInitialConditions(double* y);
//! Pointer to the homogeneous Kinetics object that handles the reactions
Kinetics* m_kin;

View file

@ -7,9 +7,6 @@
#include "cantera/zeroD/ConstPressureReactor.h"
#include "cantera/zeroD/FlowDevice.h"
#include "cantera/zeroD/Wall.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/thermo/SurfPhase.h"
using namespace std;
@ -38,15 +35,7 @@ void ConstPressureReactor::getInitialConditions(double t0, size_t leny, double*
// set the remaining components to the surface species
// coverages on the walls
size_t loc = m_nsp + 2;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->getCoverages(m_lr[m], y + loc);
loc += surf->nSpecies();
}
}
getSurfaceInitialConditions(y + m_nsp + 2);
}
void ConstPressureReactor::initialize(doublereal t0)
@ -68,16 +57,7 @@ void ConstPressureReactor::updateState(doublereal* y)
m_thermo->setPressure(m_pressure);
}
m_vol = m_mass / m_thermo->density();
size_t loc = m_nsp + 2;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->setCoverages(m_lr[m], y+loc);
loc += surf->nSpecies();
}
}
updateSurfaceState(y + m_nsp + 2);
// save parameters needed by other connected reactors
m_enthalpy = m_thermo->enthalpy_mass();

View file

@ -7,9 +7,6 @@
#include "cantera/zeroD/IdealGasConstPressureReactor.h"
#include "cantera/zeroD/FlowDevice.h"
#include "cantera/zeroD/Wall.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/thermo/SurfPhase.h"
using namespace std;
@ -49,15 +46,7 @@ void IdealGasConstPressureReactor::getInitialConditions(double t0, size_t leny,
// set the remaining components to the surface species
// coverages on the walls
size_t loc = m_nsp + 2;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->getCoverages(m_lr[m], y + loc);
loc += surf->nSpecies();
}
}
getSurfaceInitialConditions(y + m_nsp + 2);
}
void IdealGasConstPressureReactor::initialize(doublereal t0)
@ -75,16 +64,7 @@ void IdealGasConstPressureReactor::updateState(doublereal* y)
m_thermo->setMassFractions_NoNorm(y+2);
m_thermo->setState_TP(y[1], m_pressure);
m_vol = m_mass / m_thermo->density();
size_t loc = m_nsp + 2;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->setCoverages(m_lr[m], y+loc);
loc += surf->nSpecies();
}
}
updateSurfaceState(y + m_nsp + 2);
// save parameters needed by other connected reactors
m_enthalpy = m_thermo->enthalpy_mass();

View file

@ -5,8 +5,6 @@
#include "cantera/zeroD/IdealGasReactor.h"
#include "cantera/zeroD/FlowDevice.h"
#include "cantera/zeroD/Wall.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/thermo/SurfPhase.h"
#include "cantera/zeroD/ReactorNet.h"
#include <cfloat>
@ -51,15 +49,7 @@ void IdealGasReactor::getInitialConditions(double t0, size_t leny, double* y)
// set the remaining components to the surface species
// coverages on the walls
size_t loc = m_nsp + 3;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->getCoverages(m_lr[m], y + loc);
loc += surf->nSpecies();
}
}
getSurfaceInitialConditions(y + m_nsp + 3);
}
void IdealGasReactor::initialize(doublereal t0)
@ -80,19 +70,9 @@ void IdealGasReactor::updateState(doublereal* y)
// and [K+3...] are the coverages of surface species on each wall.
m_mass = y[0];
m_vol = y[1];
m_thermo->setMassFractions_NoNorm(y+3);
m_thermo->setState_TR(y[2], m_mass / m_vol);
size_t loc = m_nsp + 3;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->setCoverages(m_lr[m], y+loc);
loc += surf->nSpecies();
}
}
updateSurfaceState(y + m_nsp + 3);
// save parameters needed by other connected reactors
m_enthalpy = m_thermo->enthalpy_mass();

View file

@ -50,10 +50,14 @@ void Reactor::getInitialConditions(double t0, size_t leny, double* y)
// set the remaining components to the surface species
// coverages on the walls
size_t loc = m_nsp + 3;
SurfPhase* surf;
getSurfaceInitialConditions(y + m_nsp + 3);
}
void Reactor::getSurfaceInitialConditions(double* y)
{
size_t loc = 0;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
SurfPhase* surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->getCoverages(m_lr[m], y + loc);
loc += surf->nSpecies();
@ -157,15 +161,7 @@ void Reactor::updateState(doublereal* y)
m_thermo->setDensity(m_mass/m_vol);
}
size_t loc = m_nsp + 3;
SurfPhase* surf;
for (size_t m = 0; m < m_nwalls; m++) {
surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->setCoverages(m_lr[m], y+loc);
loc += surf->nSpecies();
}
}
updateSurfaceState(y + m_nsp + 3);
// save parameters needed by other connected reactors
m_enthalpy = m_thermo->enthalpy_mass();
@ -174,6 +170,18 @@ void Reactor::updateState(doublereal* y)
m_thermo->saveState(m_state);
}
void Reactor::updateSurfaceState(double* y)
{
size_t loc = 0;
for (size_t m = 0; m < m_nwalls; m++) {
SurfPhase* surf = m_wall[m]->surface(m_lr[m]);
if (surf) {
m_wall[m]->setCoverages(m_lr[m], y+loc);
loc += surf->nSpecies();
}
}
}
void Reactor::evalEqs(doublereal time, doublereal* y,
doublereal* ydot, doublereal* params)
{