Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Wall.cpp
Go to the documentation of this file.
1 //! @file Wall.cpp
2 #include "cantera/zeroD/Wall.h"
7 
8 namespace Cantera
9 {
10 Wall::Wall() : m_left(0), m_right(0),
11  m_area(1.0), m_k(0.0), m_rrth(0.0), m_emiss(0.0),
12  m_vf(0), m_qf(0)
13 {
14  for (int n = 0; n < 2; n++) {
15  m_chem[n] = 0;
16  m_surf[n] = 0;
17  m_nsp[n] = 0;
18  }
19 }
20 
21 bool Wall::install(ReactorBase& rleft, ReactorBase& rright)
22 {
23  // check if wall is already installed
24  if (m_left || m_right) {
25  return false;
26  }
27  m_left = &rleft;
28  m_right = &rright;
29  m_left->addWall(*this, 0);
30  m_right->addWall(*this, 1);
31  return true;
32 }
33 
35 {
36  std::sort(m_pleft.begin(), m_pleft.end());
37  std::sort(m_pright.begin(), m_pright.end());
38 }
39 
40 void Wall::setKinetics(Kinetics* left, Kinetics* right)
41 {
42  m_chem[0] = left;
43  m_chem[1] = right;
44  size_t ileft = 0, iright = 0;
45  if (left) {
46  ileft = left->surfacePhaseIndex();
47  if (ileft != npos) {
48  m_surf[0] = (SurfPhase*)&left->thermo(ileft);
49  m_nsp[0] = m_surf[0]->nSpecies();
50  m_leftcov.resize(m_nsp[0]);
51  m_surf[0]->getCoverages(DATA_PTR(m_leftcov));
52  }
53  }
54  if (right) {
55  iright = right->surfacePhaseIndex();
56  if (iright != npos) {
57  m_surf[1] = (SurfPhase*)&right->thermo(iright);
58  m_nsp[1] = m_surf[1]->nSpecies();
59  m_rightcov.resize(m_nsp[1]);
60  m_surf[1]->getCoverages(DATA_PTR(m_rightcov));
61  }
62  }
63  if (ileft == npos || iright == npos) {
64  throw CanteraError("Wall::setKinetics",
65  "specified surface kinetics manager does not "
66  "represent a surface reaction mechanism.");
67  }
68 }
69 
70 doublereal Wall::vdot(doublereal t)
71 {
72  double rate1 = m_k * m_area *
73  (m_left->pressure() - m_right->pressure());
74  if (m_vf) {
75  rate1 += m_area * m_vf->eval(t);
76  }
77  return rate1;
78 }
79 
80 doublereal Wall::Q(doublereal t)
81 {
82  double q1 = (m_area * m_rrth) *
83  (m_left->temperature() - m_right->temperature());
84  if (m_emiss > 0.0) {
85  double tl = m_left->temperature();
86  double tr = m_right->temperature();
87  q1 += m_emiss * m_area * StefanBoltz * (tl*tl*tl*tl - tr*tr*tr*tr);
88  }
89  if (m_qf) {
90  q1 += m_area * m_qf->eval(t);
91  }
92  return q1;
93 }
94 
95 void Wall::setCoverages(int leftright, const doublereal* cov)
96 {
97  if (leftright == 0) {
98  copy(cov, cov + m_nsp[0], m_leftcov.begin());
99  } else {
100  copy(cov, cov + m_nsp[1], m_rightcov.begin());
101  }
102 }
103 
104 void Wall::setCoverages(int leftright, const compositionMap& cov)
105 {
106  m_surf[leftright]->setCoveragesByName(cov);
107  if (leftright == 0) {
108  m_surf[0]->getCoverages(&m_leftcov[0]);
109  } else {
110  m_surf[1]->getCoverages(&m_rightcov[0]);
111  }
112 }
113 
114 void Wall::setCoverages(int leftright, const std::string& cov)
115 {
116  m_surf[leftright]->setCoveragesByName(cov);
117  if (leftright == 0) {
118  m_surf[0]->getCoverages(&m_leftcov[0]);
119  } else {
120  m_surf[1]->getCoverages(&m_rightcov[0]);
121  }
122 }
123 
124 void Wall::getCoverages(int leftright, doublereal* cov)
125 {
126  if (leftright == 0) {
127  copy(m_leftcov.begin(), m_leftcov.end(), cov);
128  } else {
129  copy(m_rightcov.begin(), m_rightcov.end(), cov);
130  }
131 }
132 
133 void Wall::syncCoverages(int leftright)
134 {
135  if (leftright == 0) {
136  m_surf[0]->setCoverages(DATA_PTR(m_leftcov));
137  } else {
138  m_surf[1]->setCoverages(DATA_PTR(m_rightcov));
139  }
140 }
141 
142 void Wall::addSensitivityReaction(int leftright, size_t rxn)
143 {
144  if (rxn >= m_chem[leftright]->nReactions())
145  throw CanteraError("Wall::addSensitivityReaction",
146  "Reaction number out of range ("+int2str(rxn)+")");
147  if (leftright == 0) {
148  m_left->network().registerSensitivityReaction(this, rxn,
149  m_chem[0]->reactionString(rxn), leftright);
150  m_pleft.push_back(rxn);
151  m_leftmult_save.push_back(1.0);
152  } else {
153  m_right->network().registerSensitivityReaction(this, rxn,
154  m_chem[1]->reactionString(rxn), leftright);
155  m_pright.push_back(rxn);
156  m_rightmult_save.push_back(1.0);
157  }
158 }
159 
160 void Wall::setSensitivityParameters(int lr, double* params)
161 {
162  // process sensitivity parameters
163  size_t n, npar;
164  if (lr == 0) {
165  npar = m_pleft.size();
166  for (n = 0; n < npar; n++) {
167  m_leftmult_save[n] = m_chem[0]->multiplier(m_pleft[n]);
168  m_chem[0]->setMultiplier(m_pleft[n],
169  m_leftmult_save[n]*params[n]);
170  }
171  } else {
172  npar = m_pright.size();
173  for (n = 0; n < npar; n++) {
174  m_rightmult_save[n] = m_chem[1]->multiplier(m_pright[n]);
175  m_chem[1]->setMultiplier(m_pright[n],
176  m_rightmult_save[n]*params[n]);
177  }
178  }
179 }
180 
181 void Wall::resetSensitivityParameters(int lr)
182 {
183  size_t n, npar;
184  if (lr == 0) {
185  npar = m_pleft.size();
186  for (n = 0; n < npar; n++) {
187  m_chem[0]->setMultiplier(m_pleft[n], m_leftmult_save[n]);
188  }
189  } else {
190  npar = m_pright.size();
191  for (n = 0; n < npar; n++) {
192  m_chem[1]->setMultiplier(m_pright[n],
193  m_rightmult_save[n]);
194  }
195  }
196 }
197 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:149
const ReactorBase & right()
Return a reference to the Reactor or Reservoir to the right of the wall.
Definition: Wall.h:136
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
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:188
Header file for class Wall.
const doublereal StefanBoltz
Stefan-Boltzmann constant.
Definition: ct_defs.h:85
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:285
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
virtual doublereal Q(doublereal t)
Heat flow rate through the wall (W).
Definition: Wall.cpp:80
bool install(ReactorBase &leftReactor, ReactorBase &rightReactor)
Install the wall between two reactors or reservoirs.
Definition: Wall.cpp:21
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:327
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:284
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:40
doublereal multiplier(size_t i) const
The current value of the multiplier for reaction i.
Definition: Kinetics.h:875
virtual doublereal eval(doublereal t) const
Evaluate the function.
Definition: Func1.cpp:56
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:319
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:260
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:95
Public interface for kinetics managers.
Definition: Kinetics.h:128
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
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:57
void syncCoverages(int leftright)
Set the coverages in the surface phase object to the values for this wall surface.
Definition: Wall.cpp:133
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:234
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
virtual doublereal vdot(doublereal t)
Rate of volume change (m^3/s) for the adjacent reactors.
Definition: Wall.cpp:70
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
virtual void setMultiplier(size_t i, doublereal f)
Set the multiplier for reaction i to f.
Definition: Kinetics.h:884
ReactorBase & left() const
Return a reference to the Reactor or Reservoir to the left of the wall.
Definition: Wall.h:130
void getCoverages(int leftright, doublereal *cov)
Write the coverages of the left or right surface into array cov.
Definition: Wall.cpp:124
virtual void initialize()
Called just before the start of integration.
Definition: Wall.cpp:34
doublereal temperature() const
Returns the current temperature (K) of the reactor's contents.
Definition: ReactorBase.h:173