Skip to content

Commit

Permalink
[Reactor] Add ReactorSurface to simplify use of surface reactions
Browse files Browse the repository at this point in the history
This separates the handling of interactions between reactors (mediated by
Wall objects) and surfaces on which surface reactions occur (handled by
ReactorSurface). This simplifies the implementation within reactor, and
reduces the complexity of user code involving surface reactions by
eliminating the need to set up a Reservoir object for the opposite side
of a Wall object that is only being used for surface reactions.
  • Loading branch information
speth committed Jun 28, 2016
1 parent a8c6fe0 commit 3f76637
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 195 deletions.
8 changes: 8 additions & 0 deletions include/cantera/zeroD/ReactorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Cantera
class FlowDevice;
class Wall;
class ReactorNet;
class ReactorSurface;

const int ReservoirType = 1;
const int ReactorType = 2;
Expand Down Expand Up @@ -114,6 +115,12 @@ class ReactorBase
//! Return a reference to the *n*-th Wall connected to this reactor.
Wall& wall(size_t n);

void addSurface(ReactorSurface* surf);

//! Return a reference to the *n*-th ReactorSurface connected to this
//! reactor
ReactorSurface* surface(size_t n);

/**
* Initialize the reactor. Called automatically by ReactorNet::initialize.
*/
Expand Down Expand Up @@ -230,6 +237,7 @@ class ReactorBase
vector_fp m_state;
std::vector<FlowDevice*> m_inlet, m_outlet;
std::vector<Wall*> m_wall;
std::vector<ReactorSurface*> m_surfaces;
vector_int m_lr;
std::string m_name;

Expand Down
91 changes: 91 additions & 0 deletions include/cantera/zeroD/ReactorSurface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//! @file ReactorSurface.h Header file for class ReactorSurface

#ifndef CT_REACTOR_SURFACE_H
#define CT_REACTOR_SURFACE_H

#include "cantera/zeroD/ReactorBase.h"

namespace Cantera
{

class Kinetics;
class SurfPhase;

class ReactorSurface
{
public:
ReactorSurface();

//! Returns the surface area [m^2]
double area() const;

//! Set the surface area [m^2]
void setArea(double a);

//! Accessor for the SurfPhase object
SurfPhase* thermo() {
return m_thermo;
}

//! Accessor for the InterfaceKinetics object
Kinetics* kinetics() {
return m_kinetics;
}

//! Set the InterfaceKinetics object for this surface
void setKinetics(Kinetics* kin);

//! Set the reactor that this Surface interacts with
void setReactor(ReactorBase* reactor);

//! Number of sensitivity parameters associated with reactions on this
//! surface
size_t nSensParams() const {
return m_params.size();
}

//! Set the surface coverages. Array `cov` has length equal to the number of
//! surface species.
void setCoverages(const double* cov);

//! Set the surface coverages by name
void setCoverages(const Composition& cov);

//! Set the surface coverages by name
void setCoverages(const std::string& cov);

//! Get the surface coverages. Array `cov` should have length equal to the
//! number of surface species.
void getCoverages(double* cov) const;

//! Set the coverages in the surface phase object to the values for this
//! surface.
void syncCoverages();

//! Enable calculation of sensitivities with respect to the rate constant
//! for reaction `i`.
void addSensitivityReaction(size_t i);

//! Set reaction rate multipliers. `params` is the global vector of
//! sensitivity parameters. This function is called within
//! ReactorNet::eval() before the reaction rates are evaluated.
void setSensitivityParameters(const double* params);

//! Set reaction rate multipliers back to their initial values. This
//! function is called within ReactorNet::eval() after all rates have been
//! evaluated.
void resetSensitivityParameters();

protected:
double m_area;

SurfPhase* m_thermo;
Kinetics* m_kinetics;
ReactorBase* m_reactor;
vector_fp m_cov;
std::vector<SensitivityParameter> m_params;
};

}

#endif
27 changes: 13 additions & 14 deletions include/cantera/zeroD/Wall.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cantera/base/ctexceptions.h"
#include "cantera/numerics/Func1.h"
#include "cantera/zeroD/ReactorBase.h"
#include "cantera/zeroD/ReactorSurface.h"

namespace Cantera
{
Expand Down Expand Up @@ -61,6 +62,8 @@ class Wall
//! Set the area [m^2].
void setArea(doublereal a) {
m_area = a;
m_surf[0].setArea(a);
m_surf[1].setArea(a);
}

//! Get the area [m^2]
Expand Down Expand Up @@ -147,13 +150,17 @@ class Wall
//! Return a pointer to the surface phase object for the left
//! (`leftright=0`) or right (`leftright=1`) wall surface.
SurfPhase* surface(int leftright) {
return m_surf[leftright];
return m_surf[leftright].thermo();
}

ReactorSurface* reactorSurface(int leftright) {
return &m_surf[leftright];
}

//! Return a pointer to the surface kinetics object for the left
//! (`leftright=0`) or right (`leftright=1`) wall surface.
Kinetics* kinetics(int leftright) {
return m_chem[leftright];
return m_surf[leftright].kinetics();
}

//! Set the surface coverages on the left (`leftright = 0`) or right
Expand All @@ -178,11 +185,7 @@ class Wall
//! Number of sensitivity parameters associated with reactions on the left
//! (`lr = 0`) or right (`lr = 1`) side of the wall.
size_t nSensParams(int lr) const {
if (lr == 0) {
return m_pleft.size();
} else {
return m_pright.size();
}
return m_surf[lr].nSensParams();
}
void addSensitivityReaction(int leftright, size_t rxn);
void setSensitivityParameters(double* params);
Expand All @@ -191,17 +194,13 @@ class Wall
protected:
ReactorBase* m_left;
ReactorBase* m_right;
Kinetics* m_chem[2];
SurfPhase* m_surf[2];
size_t m_nsp[2];

std::vector<ReactorSurface> m_surf;

doublereal m_area, m_k, m_rrth;
doublereal m_emiss;
Func1* m_vf;
Func1* m_qf;
vector_fp m_leftcov, m_rightcov;

std::vector<SensitivityParameter> m_pleft, m_pright;
vector_fp m_leftmult_save, m_rightmult_save;
};

}
Expand Down
17 changes: 7 additions & 10 deletions src/zeroD/ConstPressureReactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "cantera/zeroD/ConstPressureReactor.h"
#include "cantera/zeroD/FlowDevice.h"
#include "cantera/zeroD/Wall.h"
#include "cantera/thermo/SurfPhase.h"

using namespace std;

Expand Down Expand Up @@ -162,16 +163,12 @@ std::string ConstPressureReactor::componentName(size_t k) {
} else {
k -= m_thermo->nSpecies();
}
for (size_t m = 0; m < m_wall.size(); m++) {
Wall& w = *m_wall[m];
if (w.kinetics(m_lr[m])) {
size_t kp = w.kinetics(m_lr[m])->reactionPhaseIndex();
ThermoPhase& th = w.kinetics(m_lr[m])->thermo(kp);
if (k < th.nSpecies()) {
return th.speciesName(k);
} else {
k -= th.nSpecies();
}
for (auto& S : m_surfaces) {
ThermoPhase* th = S->thermo();
if (k < th->nSpecies()) {
return th->speciesName(k);
} else {
k -= th->nSpecies();
}
}
}
Expand Down
Loading

0 comments on commit 3f76637

Please sign in to comment.