Cantera  2.0
Inlet1D.h
Go to the documentation of this file.
1 /**
2  * @file Inlet1D.h
3  *
4  * Boundary objects for one-dimensional simulations.
5  */
6 
7 /*
8  * Copyright 2002-3 California Institute of Technology
9  */
10 
11 #ifndef CT_BDRY1D_H
12 #define CT_BDRY1D_H
13 
14 #include "Domain1D.h"
17 #include "StFlow.h"
18 #include "OneDim.h"
19 #include "cantera/base/ctml.h"
20 
21 namespace Cantera
22 {
23 
24 const int LeftInlet = 1;
25 const int RightInlet = -1;
26 
27 /**
28  * The base class for boundaries between one-dimensional spatial
29  * domains. The boundary may have its own internal variables, such
30  * as surface species coverages.
31  *
32  * The boundary types are an inlet, an outlet, a symmetry plane,
33  * and a surface.
34  *
35  * The public methods are all virtual, and the base class
36  * implementations throw exceptions.
37  */
38 class Bdry1D : public Domain1D
39 {
40 public:
41 
42  Bdry1D();
43 
44  virtual ~Bdry1D() {}
45 
46  /// Initialize.
47  virtual void init() {
48  _init(1);
49  }
50 
51  /// Set the temperature.
52  virtual void setTemperature(doublereal t) {
53  m_temp = t;
54  }
55 
56  /// Temperature [K].
57  virtual doublereal temperature() {
58  return m_temp;
59  }
60 
61  /// Set the mole fractions by specifying a std::string.
62  virtual void setMoleFractions(std::string xin) {
63  err("setMoleFractions");
64  }
65 
66  /// Set the mole fractions by specifying an array.
67  virtual void setMoleFractions(doublereal* xin) {
68  err("setMoleFractions");
69  }
70 
71  /// Mass fraction of species k.
72  virtual doublereal massFraction(size_t k) {
73  err("massFraction");
74  return 0.0;
75  }
76 
77  /// Set the total mass flow rate.
78  virtual void setMdot(doublereal mdot) {
79  m_mdot = mdot;
80  }
81 
82  /// The total mass flow rate [kg/m2/s].
83  virtual doublereal mdot() {
84  return m_mdot;
85  }
86 
87  virtual void _getInitialSoln(doublereal* x) {
88  writelog("Bdry1D::_getInitialSoln called!\n");
89  }
90 
91  virtual void setupGrid(size_t n, const doublereal* z) {}
92 
93 protected:
94 
95  void _init(size_t n);
96 
97  StFlow* m_flow_left, *m_flow_right;
98  size_t m_ilr, m_left_nv, m_right_nv;
99  size_t m_left_loc, m_right_loc;
100  size_t m_left_points;
101  size_t m_nv, m_left_nsp, m_right_nsp;
102  size_t m_sp_left, m_sp_right;
103  size_t m_start_left, m_start_right;
104  ThermoPhase* m_phase_left, *m_phase_right;
105  doublereal m_temp, m_mdot;
106 
107 private:
108  void err(std::string method) {
109  throw CanteraError("Bdry1D::"+method,
110  "attempt to call base class method "+method);
111  }
112 };
113 
114 
115 /**
116  * An inlet.
117  */
118 class Inlet1D : public Bdry1D
119 {
120 
121 public:
122 
123  /**
124  * Constructor. Create a new Inlet1D instance. If invoked
125  * without parameters, a left inlet (facing right) is
126  * constructed).
127  */
128  Inlet1D() : Bdry1D(), m_V0(0.0), m_nsp(0), m_flow(0) {
129  m_type = cInletType;
130  m_xstr = "";
131  }
132  virtual ~Inlet1D() {}
133 
134  /// set spreading rate
135  virtual void setSpreadRate(doublereal V0) {
136  m_V0 = V0;
137  needJacUpdate();
138  }
139 
140  /// spreading rate
141  virtual double spreadRate() {
142  return m_V0;
143  }
144 
145 
146  virtual void showSolution(const doublereal* x) {
147  char buf[80];
148  sprintf(buf, " Mass Flux: %10.4g kg/m^2/s \n", m_mdot);
149  writelog(buf);
150  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
151  writelog(buf);
152  if (m_flow) {
153  writelog(" Mass Fractions: \n");
154  for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
155  if (m_yin[k] != 0.0) {
156  sprintf(buf, " %16s %10.4g \n",
157  m_flow->phase().speciesName(k).c_str(), m_yin[k]);
158  writelog(buf);
159  }
160  }
161  }
162  writelog("\n");
163  }
164 
165  virtual void _getInitialSoln(doublereal* x) {
166  x[0] = m_mdot;
167  x[1] = m_temp;
168  }
169 
170  virtual void _finalize(const doublereal* x) {}
171 
172  virtual void setMoleFractions(std::string xin);
173  virtual void setMoleFractions(doublereal* xin);
174  virtual doublereal massFraction(size_t k) {
175  return m_yin[k];
176  }
177  virtual std::string componentName(size_t n) const;
178  virtual void init();
179  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
180  integer* diagg, doublereal rdt);
181  virtual void save(XML_Node& o, const doublereal* const soln);
182  virtual void restore(const XML_Node& dom, doublereal* soln);
183 
184 protected:
185 
186  int m_ilr;
187  doublereal m_V0;
188  size_t m_nsp;
189  vector_fp m_yin;
190  std::string m_xstr;
191  StFlow* m_flow;
192 };
193 
194 
195 /**
196  * A terminator that does nothing.
197  */
198 class Empty1D : public Domain1D
199 {
200 
201 public:
202 
203  Empty1D() : Domain1D() {
204  m_type = cEmptyType;
205  }
206  virtual ~Empty1D() {}
207 
208  virtual std::string componentName(size_t n) const;
209  virtual void showSolution(const doublereal* x) {}
210 
211  virtual void init();
212 
213  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
214  integer* diagg, doublereal rdt);
215 
216  virtual void save(XML_Node& o, const doublereal* const soln);
217  virtual void restore(const XML_Node& dom, doublereal* soln);
218  virtual void _finalize(const doublereal* x) {}
219  virtual void _getInitialSoln(doublereal* x) {
220  x[0] = 0.0;
221  }
222 
223 protected:
224 
225 };
226 
227 /**
228  * A symmetry plane. The axial velocity u = 0, and all other
229  * components have zero axial gradients.
230  */
231 class Symm1D : public Bdry1D
232 {
233 
234 public:
235 
236  Symm1D() : Bdry1D() {
237  m_type = cSymmType;
238  }
239  virtual ~Symm1D() {}
240 
241  virtual std::string componentName(size_t n) const;
242 
243  virtual void init();
244 
245  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
246  integer* diagg, doublereal rdt);
247 
248  virtual void save(XML_Node& o, const doublereal* const soln);
249  virtual void restore(const XML_Node& dom, doublereal* soln);
250  virtual void _finalize(const doublereal* x) {
251  ; //m_temp = x[0];
252  }
253  virtual void _getInitialSoln(doublereal* x) {
254  x[0] = m_temp;
255  }
256 
257 protected:
258 
259 };
260 
261 
262 /**
263  */
264 class Outlet1D : public Bdry1D
265 {
266 
267 public:
268 
269  Outlet1D() : Bdry1D() {
270  m_type = cOutletType;
271  }
272  virtual ~Outlet1D() {}
273 
274  virtual std::string componentName(size_t n) const;
275 
276  virtual void init();
277 
278  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
279  integer* diagg, doublereal rdt);
280 
281  virtual void save(XML_Node& o, const doublereal* const soln);
282  virtual void restore(const XML_Node& dom, doublereal* soln);
283  virtual void _finalize(const doublereal* x) {
284  ; //m_temp = x[0];
285  }
286  virtual void _getInitialSoln(doublereal* x) {
287  x[0] = m_temp;
288  }
289 protected:
290 
291 };
292 
293 
294 
295 /**
296  * An outlet with specified composition.
297  */
298 class OutletRes1D : public Bdry1D
299 {
300 
301 public:
302 
303  /**
304  * Constructor.
305  */
306  OutletRes1D() : Bdry1D(), m_nsp(0), m_flow(0) {
307  m_type = cOutletResType;
308  m_xstr = "";
309  }
310  virtual ~OutletRes1D() {}
311 
312  virtual void showSolution(const doublereal* x) {}
313 
314  virtual void _getInitialSoln(doublereal* x) {
315  x[0] = m_temp;
316  }
317 
318  virtual void _finalize(const doublereal* x) {
319  ;
320  }
321 
322  virtual void setMoleFractions(std::string xin);
323  virtual void setMoleFractions(doublereal* xin);
324  virtual doublereal massFraction(size_t k) {
325  return m_yres[k];
326  }
327  virtual std::string componentName(size_t n) const;
328  virtual void init();
329  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
330  integer* diagg, doublereal rdt);
331  virtual void save(XML_Node& o, const doublereal* const soln);
332  virtual void restore(const XML_Node& dom, doublereal* soln);
333 
334 protected:
335 
336  size_t m_nsp;
337  vector_fp m_yres;
338  std::string m_xstr;
339  StFlow* m_flow;
340 };
341 
342 
343 /**
344  * A non-reacting surface. The axial velocity is zero
345  * (impermeable), as is the transverse velocity (no slip). The
346  * temperature is specified, and a zero flux condition is imposed
347  * for the species.
348  */
349 class Surf1D : public Bdry1D
350 {
351 
352 public:
353 
354  Surf1D() : Bdry1D() {
355  m_type = cSurfType;
356  }
357  virtual ~Surf1D() {}
358 
359  virtual std::string componentName(size_t n) const;
360 
361  virtual void init();
362 
363  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
364  integer* diagg, doublereal rdt);
365 
366  virtual void save(XML_Node& o, const doublereal* const soln);
367  virtual void restore(const XML_Node& dom, doublereal* soln);
368 
369  virtual void _getInitialSoln(doublereal* x) {
370  x[0] = m_temp;
371  }
372 
373  virtual void _finalize(const doublereal* x) {
374  ; //m_temp = x[0];
375  }
376 
377  virtual void showSolution_s(std::ostream& s, const doublereal* x) {
378  s << "------------------- Surface " << domainIndex() << " ------------------- " << std::endl;
379  s << " temperature: " << m_temp << " K" << " " << x[0] << std::endl;
380  }
381 
382  virtual void showSolution(const doublereal* x) {
383  char buf[80];
384  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
385  writelog(buf);
386  writelog("\n");
387  }
388 
389 protected:
390 
391 };
392 
393 
394 /**
395  * A reacting surface.
396  *
397  */
398 class ReactingSurf1D : public Bdry1D
399 {
400 
401 public:
402 
403  ReactingSurf1D() : Bdry1D(),
404  m_kin(0), m_surfindex(0), m_nsp(0) {
405  m_type = cSurfType;
406  }
407 
408  void setKineticsMgr(InterfaceKinetics* kin) {
409  m_kin = kin;
410  m_surfindex = kin->surfacePhaseIndex();
411  m_sphase = (SurfPhase*)&kin->thermo(m_surfindex);
412  m_nsp = m_sphase->nSpecies();
413  m_enabled = true;
414  }
415 
416  void enableCoverageEquations(bool docov) {
417  m_enabled = docov;
418  }
419 
420  virtual ~ReactingSurf1D() {}
421 
422  virtual std::string componentName(size_t n) const;
423 
424  virtual void init();
425 
426  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
427  integer* diagg, doublereal rdt);
428 
429  virtual void save(XML_Node& o, const doublereal* const soln);
430  virtual void restore(const XML_Node& dom, doublereal* soln);
431 
432  virtual void _getInitialSoln(doublereal* x) {
433  x[0] = m_temp;
434  //m_kin->advanceCoverages(1.0);
435  m_sphase->getCoverages(x+1);
436  }
437 
438  virtual void _finalize(const doublereal* x) {
439  std::copy(x+1,x+1+m_nsp,m_fixed_cov.begin());
440  }
441 
442  virtual void showSolution(const doublereal* x) {
443  char buf[80];
444  sprintf(buf, " Temperature: %10.4g K \n", x[0]);
445  writelog(buf);
446  writelog(" Coverages: \n");
447  for (size_t k = 0; k < m_nsp; k++) {
448  sprintf(buf, " %20s %10.4g \n", m_sphase->speciesName(k).c_str(),
449  x[k+1]);
450  writelog(buf);
451  }
452  writelog("\n");
453  }
454 
455 protected:
456 
457  InterfaceKinetics* m_kin;
458  SurfPhase* m_sphase;
459  size_t m_surfindex, m_nsp;
460  bool m_enabled;
461  vector_fp m_work;
462  vector_fp m_fixed_cov;
463  int dum;
464 };
465 
466 }
467 
468 #endif