Cantera  2.1.2
Wall.cpp
Go to the documentation of this file.
1 //! @file Wall.cpp
2 #include "cantera/zeroD/Wall.h"
8 
9 namespace Cantera
10 {
11 Wall::Wall() : m_left(0), m_right(0),
12  m_area(1.0), m_k(0.0), m_rrth(0.0), m_emiss(0.0),
13  m_vf(0), m_qf(0)
14 {
15  for (int n = 0; n < 2; n++) {
16  m_chem[n] = 0;
17  m_surf[n] = 0;
18  m_nsp[n] = 0;
19  }
20 }
21 
22 bool Wall::install(ReactorBase& rleft, ReactorBase& rright)
23 {
24  // check if wall is already installed
25  if (m_left || m_right) {
26  return false;
27  }
28  m_left = &rleft;
29  m_right = &rright;
30  m_left->addWall(*this, 0);
31  m_right->addWall(*this, 1);
32  return true;
33 }
34 
36 {
37  std::sort(m_pleft.begin(), m_pleft.end());
38  std::sort(m_pright.begin(), m_pright.end());
39 }
40 
41 void Wall::setKinetics(Kinetics* left, Kinetics* right)
42 {
43  m_chem[0] = left;
44  m_chem[1] = right;
45  size_t ileft = 0, iright = 0;
46  if (left) {
47  ileft = left->surfacePhaseIndex();
48  if (ileft != npos) {
49  m_surf[0] = (SurfPhase*)&left->thermo(ileft);
50  m_nsp[0] = m_surf[0]->nSpecies();
51  m_leftcov.resize(m_nsp[0]);
52  m_surf[0]->getCoverages(DATA_PTR(m_leftcov));
53  }
54  }
55  if (right) {
56  iright = right->surfacePhaseIndex();
57  if (iright != npos) {
58  m_surf[1] = (SurfPhase*)&right->thermo(iright);
59  m_nsp[1] = m_surf[1]->nSpecies();
60  m_rightcov.resize(m_nsp[1]);
61  m_surf[1]->getCoverages(DATA_PTR(m_rightcov));
62  }
63  }
64  if (ileft == npos || iright == npos) {
65  throw CanteraError("Wall::setKinetics",
66  "specified surface kinetics manager does not "
67  "represent a surface reaction mechanism.");
68  }
69 }
70 
71 doublereal Wall::vdot(doublereal t)
72 {
73  double rate1 = m_k * m_area *
74  (m_left->pressure() - m_right->pressure());
75  if (m_vf) {
76  rate1 += m_area * m_vf->eval(t);
77  }
78  return rate1;
79 }
80 
81 doublereal Wall::Q(doublereal t)
82 {
83  double q1 = (m_area * m_rrth) *
84  (m_left->temperature() - m_right->temperature());
85  if (m_emiss > 0.0) {
86  double tl = m_left->temperature();
87  double tr = m_right->temperature();
88  q1 += m_emiss * m_area * StefanBoltz * (tl*tl*tl*tl - tr*tr*tr*tr);
89  }
90  if (m_qf) {
91  q1 += m_area * m_qf->eval(t);
92  }
93  return q1;
94 }
95 
96 void Wall::setCoverages(int leftright, const doublereal* cov)
97 {
98  if (leftright == 0) {
99  copy(cov, cov + m_nsp[0], m_leftcov.begin());
100  } else {
101  copy(cov, cov + m_nsp[1], m_rightcov.begin());
102  }
103 }
104 
105 void Wall::getCoverages(int leftright, doublereal* cov)
106 {
107  if (leftright == 0) {
108  copy(m_leftcov.begin(), m_leftcov.end(), cov);
109  } else {
110  copy(m_rightcov.begin(), m_rightcov.end(), cov);
111  }
112 }
113 
114 void Wall::syncCoverages(int leftright)
115 {
116  if (leftright == 0) {
117  m_surf[0]->setCoverages(DATA_PTR(m_leftcov));
118  } else {
119  m_surf[1]->setCoverages(DATA_PTR(m_rightcov));
120  }
121 }
122 
123 void Wall::addSensitivityReaction(int leftright, size_t rxn)
124 {
125  if (rxn >= m_chem[leftright]->nReactions())
126  throw CanteraError("Wall::addSensitivityReaction",
127  "Reaction number out of range ("+int2str(rxn)+")");
128  if (leftright == 0) {
129  m_left->network().registerSensitivityReaction(this, rxn,
130  m_chem[0]->reactionString(rxn), leftright);
131  m_pleft.push_back(rxn);
132  m_leftmult_save.push_back(1.0);
133  } else {
134  m_right->network().registerSensitivityReaction(this, rxn,
135  m_chem[1]->reactionString(rxn), leftright);
136  m_pright.push_back(rxn);
137  m_rightmult_save.push_back(1.0);
138  }
139 }
140 
141 void Wall::setSensitivityParameters(int lr, double* params)
142 {
143  // process sensitivity parameters
144  size_t n, npar;
145  if (lr == 0) {
146  npar = m_pleft.size();
147  for (n = 0; n < npar; n++) {
148  m_leftmult_save[n] = m_chem[0]->multiplier(m_pleft[n]);
149  m_chem[0]->setMultiplier(m_pleft[n],
150  m_leftmult_save[n]*params[n]);
151  }
152  } else {
153  npar = m_pright.size();
154  for (n = 0; n < npar; n++) {
155  m_rightmult_save[n] = m_chem[1]->multiplier(m_pright[n]);
156  m_chem[1]->setMultiplier(m_pright[n],
157  m_rightmult_save[n]*params[n]);
158  }
159  }
160 }
161 
162 void Wall::resetSensitivityParameters(int lr)
163 {
164  size_t n, npar;
165  if (lr == 0) {
166  npar = m_pleft.size();
167  for (n = 0; n < npar; n++) {
168  m_chem[0]->setMultiplier(m_pleft[n], m_leftmult_save[n]);
169  }
170  } else {
171  npar = m_pright.size();
172  for (n = 0; n < npar; n++) {
173  m_chem[1]->setMultiplier(m_pright[n],
174  m_rightmult_save[n]);
175  }
176  }
177 }
178 }
const ReactorBase & right()
Return a reference to the Reactor or Reservoir to the right of the wall.
Definition: Wall.h:138
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
doublereal pressure() const
Returns the current pressure (Pa) of the reactor.
Definition: ReactorBase.h:179
Header file for class Wall.
const doublereal StefanBoltz
Stefan-Boltzmann constant.
Definition: ct_defs.h:87
thermo_t & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism...
Definition: Kinetics.h:288
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual doublereal Q(doublereal t)
Heat flow rate through the wall (W).
Definition: Wall.cpp:81
bool install(ReactorBase &leftReactor, ReactorBase &rightReactor)
Install the wall between two reactors or reservoirs.
Definition: Wall.cpp:22
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:283
ReactorNet & network()
The ReactorNet that this reactor belongs to.
Definition: ReactorBase.cpp:72
void setKinetics(Cantera::Kinetics *leftMechanism, Cantera::Kinetics *rightMechanism)
Specify the heterogeneous reaction mechanisms for each side of the wall.
Definition: Wall.cpp:41
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition: Kinetics.h:840
void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:849
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:62
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:318
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:143
size_t surfacePhaseIndex()
This returns the integer index of the phase which has ThermoPhase type cSurf.
Definition: Kinetics.h:263
void setCoverages(int leftright, const doublereal *cov)
Set the surface coverages on the left (leftright = 0) or right (leftright = 1) surface to the values ...
Definition: Wall.cpp:96
Public interface for kinetics managers.
Definition: Kinetics.h:131
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
Base class for stirred reactors.
Definition: ReactorBase.h:30
void addWall(Wall &w, int lr)
Insert a Wall between this reactor and another reactor.
Definition: ReactorBase.cpp:56
void syncCoverages(int leftright)
Set the coverages in the surface phase object to the values for this wall surface.
Definition: Wall.cpp:114
void registerSensitivityReaction(void *reactor, size_t reactionIndex, const std::string &name, int leftright=0)
Used by Reactor and Wall objects to register the addition of sensitivity reactions so that the Reacto...
Definition: ReactorNet.cpp:270
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual doublereal vdot(doublereal t)
Rate of volume change (m^3/s) for the adjacent reactors.
Definition: Wall.cpp:71
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
ReactorBase & left() const
Return a reference to the Reactor or Reservoir to the left of the wall.
Definition: Wall.h:132
void getCoverages(int leftright, doublereal *cov)
Write the coverages of the left or right surface into array cov.
Definition: Wall.cpp:105
virtual void initialize()
Called just before the start of integration.
Definition: Wall.cpp:35
doublereal temperature() const
Returns the current temperature (K) of the reactor's contents.
Definition: ReactorBase.h:164