Cantera  2.0
Wall.cpp
1 
2 #include "cantera/zeroD/Wall.h"
7 
8 using namespace std;
9 using namespace Cantera;
10 
11 namespace Cantera
12 {
13 
14 Wall::Wall() : m_left(0), m_right(0),
15  m_area(0.0), m_k(0.0), m_rrth(0.0), m_emiss(0.0),
16  m_vf(0), m_qf(0)
17 {
18  for (int n = 0; n < 2; n++) {
19  m_chem[n] = 0;
20  m_surf[n] = 0;
21  m_nsp[n] = 0;
22  }
23 }
24 
25 bool Wall::install(ReactorBase& rleft, ReactorBase& rright)
26 {
27  // check if wall is already installed
28  if (m_left || m_right) {
29  return false;
30  }
31  m_left = &rleft;
32  m_right = &rright;
33  m_left->addWall(*this, 0);
34  m_right->addWall(*this, 1);
35  return true;
36 }
37 
38 /** Specify the kinetics managers for the surface mechanisms on
39  * the left side and right side of the wall. Enter 0 if there is
40  * no reaction mechanism.
41  */
42 void Wall::setKinetics(Kinetics* left, Kinetics* right)
43 {
44  m_chem[0] = left;
45  m_chem[1] = right;
46  size_t ileft = 0, iright = 0;
47  if (left) {
48  ileft = left->surfacePhaseIndex();
49  if (ileft != npos) {
50  m_surf[0] = (SurfPhase*)&left->thermo(ileft);
51  m_nsp[0] = m_surf[0]->nSpecies();
52  m_leftcov.resize(m_nsp[0]);
53  m_surf[0]->getCoverages(DATA_PTR(m_leftcov));
54  }
55  }
56  if (right) {
57  iright = right->surfacePhaseIndex();
58  if (iright != npos) {
59  m_surf[1] = (SurfPhase*)&right->thermo(iright);
60  m_nsp[1] = m_surf[1]->nSpecies();
61  m_rightcov.resize(m_nsp[1]);
62  m_surf[1]->getCoverages(DATA_PTR(m_rightcov));
63  }
64  }
65  if (ileft == npos || iright == npos) {
66  throw CanteraError("Wall::setKinetics",
67  "specified surface kinetics manager does not "
68  "represent a surface reaction mechanism.");
69  }
70 }
71 
72 /**
73  * The volume rate of change is given by
74  * \f[ \dot V = K A (P_{left} - P_{right}) + F(t) \f]
75  * where \f$ F(t) \f$ is a specified function of time.
76  *
77  * This method is used by class Reactor to compute the
78  * rate of volume change of the reactor.
79  */
80 doublereal Wall::vdot(doublereal t)
81 {
82  double rate1 = m_k * m_area *
83  (m_left->pressure() - m_right->pressure());
84  if (m_vf) {
85  rate1 += m_area * m_vf->eval(t);
86  }
87  return rate1;
88 }
89 
90 /**
91  * The heat flux is given by
92  * \f[ Q = h A (T_{left} - T_{right}) + A G(t) \f]
93  * where h is the heat transfer coefficient, and
94  * \f$ G(t) \f$ is a specified function of time.
95  */
96 doublereal Wall::Q(doublereal t)
97 {
98  double q1 = (m_area * m_rrth) *
99  (m_left->temperature() - m_right->temperature());
100  if (m_emiss > 0.0) {
101  double tl = m_left->temperature();
102  double tr = m_right->temperature();
103  q1 += m_emiss * m_area * StefanBoltz * (tl*tl*tl*tl - tr*tr*tr*tr);
104  }
105  if (m_qf) {
106  q1 += m_area * m_qf->eval(t);
107  }
108  return q1;
109 }
110 
111 void Wall::setCoverages(int leftright, const doublereal* cov)
112 {
113  if (leftright == 0) {
114  copy(cov, cov + m_nsp[0], m_leftcov.begin());
115  } else {
116  copy(cov, cov + m_nsp[1], m_rightcov.begin());
117  }
118 }
119 
120 void Wall::getCoverages(int leftright, doublereal* cov)
121 {
122  if (leftright == 0) {
123  copy(m_leftcov.begin(), m_leftcov.end(), cov);
124  } else {
125  copy(m_rightcov.begin(), m_rightcov.end(), cov);
126  }
127 }
128 
129 void Wall::syncCoverages(int leftright)
130 {
131  if (leftright == 0) {
132  m_surf[0]->setCoverages(DATA_PTR(m_leftcov));
133  } else {
134  m_surf[1]->setCoverages(DATA_PTR(m_rightcov));
135  }
136 }
137 
138 void Wall::addSensitivityReaction(int leftright, size_t rxn)
139 {
140  if (rxn >= m_chem[leftright]->nReactions())
141  throw CanteraError("Wall::addSensitivityReaction",
142  "Reaction number out of range ("+int2str(rxn)+")");
143  if (leftright == 0) {
144  m_pleft.push_back(rxn);
145  m_leftmult_save.push_back(1.0);
146  m_pname_left.push_back(m_chem[0]->reactionString(rxn));
147  } else {
148  m_pright.push_back(rxn);
149  m_rightmult_save.push_back(1.0);
150  m_pname_right.push_back(m_chem[1]->reactionString(rxn));
151  }
152 }
153 
154 void Wall::setSensitivityParameters(int lr, double* params)
155 {
156  // process sensitivity parameters
157  size_t n, npar;
158  if (lr == 0) {
159  npar = m_pleft.size();
160  for (n = 0; n < npar; n++) {
161  m_leftmult_save[n] = m_chem[0]->multiplier(m_pleft[n]);
162  m_chem[0]->setMultiplier(m_pleft[n],
163  m_leftmult_save[n]*params[n]);
164  }
165  } else {
166  npar = m_pright.size();
167  for (n = 0; n < npar; n++) {
168  m_rightmult_save[n] = m_chem[1]->multiplier(m_pright[n]);
169  m_chem[1]->setMultiplier(m_pright[n],
170  m_rightmult_save[n]*params[n]);
171  }
172  }
173 }
174 
175 void Wall::resetSensitivityParameters(int lr)
176 {
177  size_t n, npar;
178  if (lr == 0) {
179  npar = m_pleft.size();
180  for (n = 0; n < npar; n++) {
181  m_chem[0]->setMultiplier(m_pleft[n], m_leftmult_save[n]);
182  }
183  } else {
184  npar = m_pright.size();
185  for (n = 0; n < npar; n++) {
186  m_chem[1]->setMultiplier(m_pright[n],
187  m_rightmult_save[n]);
188  }
189  }
190 }
191 }