From 1437aade8cb397a609e6aad28e2652cc863ddc27 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Tue, 10 Jun 2014 16:22:46 +0000 Subject: [PATCH] [Reactor] Refactor updateState and getInitialConditions implementations Extract common parts related to surface species --- include/cantera/zeroD/Reactor.h | 6 ++++ src/zeroD/ConstPressureReactor.cpp | 24 ++-------------- src/zeroD/IdealGasConstPressureReactor.cpp | 24 ++-------------- src/zeroD/IdealGasReactor.cpp | 24 ++-------------- src/zeroD/Reactor.cpp | 32 ++++++++++++++-------- 5 files changed, 32 insertions(+), 78 deletions(-) diff --git a/include/cantera/zeroD/Reactor.h b/include/cantera/zeroD/Reactor.h index 287f15e04..94dde02c5 100644 --- a/include/cantera/zeroD/Reactor.h +++ b/include/cantera/zeroD/Reactor.h @@ -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; diff --git a/src/zeroD/ConstPressureReactor.cpp b/src/zeroD/ConstPressureReactor.cpp index 341284237..9e427b284 100644 --- a/src/zeroD/ConstPressureReactor.cpp +++ b/src/zeroD/ConstPressureReactor.cpp @@ -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(); diff --git a/src/zeroD/IdealGasConstPressureReactor.cpp b/src/zeroD/IdealGasConstPressureReactor.cpp index 753b752b7..527f717ff 100644 --- a/src/zeroD/IdealGasConstPressureReactor.cpp +++ b/src/zeroD/IdealGasConstPressureReactor.cpp @@ -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(); diff --git a/src/zeroD/IdealGasReactor.cpp b/src/zeroD/IdealGasReactor.cpp index 8fa0d6fbc..50a79f27f 100644 --- a/src/zeroD/IdealGasReactor.cpp +++ b/src/zeroD/IdealGasReactor.cpp @@ -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 @@ -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(); diff --git a/src/zeroD/Reactor.cpp b/src/zeroD/Reactor.cpp index 6190f1674..ef1a4357f 100644 --- a/src/zeroD/Reactor.cpp +++ b/src/zeroD/Reactor.cpp @@ -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) {