Cantera  2.1.2
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 #include <cstdio>
22 
23 namespace Cantera
24 {
25 
26 const int LeftInlet = 1;
27 const int RightInlet = -1;
28 
29 /**
30  * The base class for boundaries between one-dimensional spatial
31  * domains. The boundary may have its own internal variables, such
32  * as surface species coverages.
33  *
34  * The boundary types are an inlet, an outlet, a symmetry plane,
35  * and a surface.
36  *
37  * The public methods are all virtual, and the base class
38  * implementations throw exceptions.
39  * @ingroup onedim
40  */
41 class Bdry1D : public Domain1D
42 {
43 public:
44  Bdry1D();
45 
46  virtual void init() {
47  _init(1);
48  }
49 
50  /// Set the temperature.
51  virtual void setTemperature(doublereal t) {
52  m_temp = t;
53  }
54 
55  /// Temperature [K].
56  virtual doublereal temperature() {
57  return m_temp;
58  }
59 
60  virtual size_t nSpecies() {
61  return 0;
62  }
63 
64  /// Set the mole fractions by specifying a std::string.
65  virtual void setMoleFractions(const std::string& xin) {
66  err("setMoleFractions");
67  }
68 
69  /// Set the mole fractions by specifying an array.
70  virtual void setMoleFractions(doublereal* xin) {
71  err("setMoleFractions");
72  }
73 
74  /// Mass fraction of species k.
75  virtual doublereal massFraction(size_t k) {
76  err("massFraction");
77  return 0.0;
78  }
79 
80  /// Set the total mass flow rate.
81  virtual void setMdot(doublereal mdot) {
82  m_mdot = mdot;
83  }
84 
85  /// The total mass flow rate [kg/m2/s].
86  virtual doublereal mdot() {
87  return m_mdot;
88  }
89 
90  virtual void _getInitialSoln(doublereal* x) {
91  writelog("Bdry1D::_getInitialSoln called!\n");
92  }
93 
94  virtual void setupGrid(size_t n, const doublereal* z) {}
95 
96 protected:
97  void _init(size_t n);
98 
99  StFlow* m_flow_left, *m_flow_right;
100  size_t m_ilr, m_left_nv, m_right_nv;
101  size_t m_left_loc, m_right_loc;
102  size_t m_left_points;
103  size_t m_nv, m_left_nsp, m_right_nsp;
104  size_t m_sp_left, m_sp_right;
105  size_t m_start_left, m_start_right;
106  ThermoPhase* m_phase_left, *m_phase_right;
107  doublereal m_temp, m_mdot;
108 
109 private:
110  void err(const std::string& method) {
111  throw CanteraError("Bdry1D::"+method,
112  "attempt to call base class method "+method);
113  }
114 };
115 
116 
117 /**
118  * An inlet.
119  * @ingroup onedim
120  */
121 class Inlet1D : public Bdry1D
122 {
123 public:
124  Inlet1D() : Bdry1D(), m_V0(0.0), m_nsp(0), m_flow(0) {
125  m_type = cInletType;
126  m_xstr = "";
127  }
128 
129  /// set spreading rate
130  virtual void setSpreadRate(doublereal V0) {
131  m_V0 = V0;
132  needJacUpdate();
133  }
134 
135  /// spreading rate
136  virtual double spreadRate() {
137  return m_V0;
138  }
139 
140  virtual void showSolution(const doublereal* x) {
141  char buf[80];
142  sprintf(buf, " Mass Flux: %10.4g kg/m^2/s \n", m_mdot);
143  writelog(buf);
144  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
145  writelog(buf);
146  if (m_flow) {
147  writelog(" Mass Fractions: \n");
148  for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
149  if (m_yin[k] != 0.0) {
150  sprintf(buf, " %16s %10.4g \n",
151  m_flow->phase().speciesName(k).c_str(), m_yin[k]);
152  writelog(buf);
153  }
154  }
155  }
156  writelog("\n");
157  }
158 
159  virtual void _getInitialSoln(doublereal* x) {
160  x[0] = m_mdot;
161  x[1] = m_temp;
162  }
163 
164  virtual void _finalize(const doublereal* x) {}
165 
166  virtual size_t nSpecies() {
167  return m_nsp;
168  }
169 
170  virtual void setMoleFractions(const std::string& xin);
171  virtual void setMoleFractions(doublereal* xin);
172  virtual doublereal massFraction(size_t k) {
173  return m_yin[k];
174  }
175  virtual std::string componentName(size_t n) const;
176  virtual void init();
177  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
178  integer* diagg, doublereal rdt);
179  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
180  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
181 
182 protected:
183  int m_ilr;
184  doublereal m_V0;
185  size_t m_nsp;
186  vector_fp m_yin;
187  std::string m_xstr;
188  StFlow* m_flow;
189 };
190 
191 /**
192  * A terminator that does nothing.
193  * @ingroup onedim
194  */
195 class Empty1D : public Domain1D
196 {
197 public:
198  Empty1D() : Domain1D() {
199  m_type = cEmptyType;
200  }
201 
202  virtual std::string componentName(size_t n) const;
203  virtual void showSolution(const doublereal* x) {}
204 
205  virtual void init();
206 
207  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
208  integer* diagg, doublereal rdt);
209 
210  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
211  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
212  virtual void _finalize(const doublereal* x) {}
213  virtual void _getInitialSoln(doublereal* x) {
214  x[0] = 0.0;
215  }
216 };
217 
218 /**
219  * A symmetry plane. The axial velocity u = 0, and all other
220  * components have zero axial gradients.
221  * @ingroup onedim
222  */
223 class Symm1D : public Bdry1D
224 {
225 public:
226 
227  Symm1D() : Bdry1D() {
228  m_type = cSymmType;
229  }
230 
231  virtual std::string componentName(size_t n) const;
232 
233  virtual void init();
234 
235  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
236  integer* diagg, doublereal rdt);
237 
238  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
239  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
240  virtual void _finalize(const doublereal* x) {
241  ; //m_temp = x[0];
242  }
243  virtual void _getInitialSoln(doublereal* x) {
244  x[0] = m_temp;
245  }
246 };
247 
248 
249 /**
250  * An outlet.
251  */
252 class Outlet1D : public Bdry1D
253 {
254 public:
255  Outlet1D() : Bdry1D() {
256  m_type = cOutletType;
257  }
258 
259  virtual std::string componentName(size_t n) const;
260 
261  virtual void init();
262 
263  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
264  integer* diagg, doublereal rdt);
265 
266  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
267  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
268  virtual void _finalize(const doublereal* x) {
269  ; //m_temp = x[0];
270  }
271  virtual void _getInitialSoln(doublereal* x) {
272  x[0] = m_temp;
273  }
274 };
275 
276 
277 /**
278  * An outlet with specified composition.
279  * @ingroup onedim
280  */
281 class OutletRes1D : public Bdry1D
282 {
283 public:
284  OutletRes1D() : Bdry1D(), m_nsp(0), m_flow(0) {
285  m_type = cOutletResType;
286  m_xstr = "";
287  }
288 
289  virtual void showSolution(const doublereal* x) {}
290 
291  virtual void _getInitialSoln(doublereal* x) {
292  x[0] = m_temp;
293  }
294 
295  virtual void _finalize(const doublereal* x) {
296  ;
297  }
298 
299  virtual size_t nSpecies() {
300  return m_nsp;
301  }
302 
303  virtual void setMoleFractions(const std::string& xin);
304  virtual void setMoleFractions(doublereal* xin);
305  virtual doublereal massFraction(size_t k) {
306  return m_yres[k];
307  }
308  virtual std::string componentName(size_t n) const;
309  virtual void init();
310  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
311  integer* diagg, doublereal rdt);
312  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
313  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
314 
315 protected:
316  size_t m_nsp;
317  vector_fp m_yres;
318  std::string m_xstr;
319  StFlow* m_flow;
320 };
321 
322 /**
323  * A non-reacting surface. The axial velocity is zero
324  * (impermeable), as is the transverse velocity (no slip). The
325  * temperature is specified, and a zero flux condition is imposed
326  * for the species.
327  */
328 class Surf1D : public Bdry1D
329 {
330 public:
331  Surf1D() : Bdry1D() {
332  m_type = cSurfType;
333  }
334 
335  virtual std::string componentName(size_t n) const;
336 
337  virtual void init();
338 
339  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
340  integer* diagg, doublereal rdt);
341 
342  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
343  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
344 
345  virtual void _getInitialSoln(doublereal* x) {
346  x[0] = m_temp;
347  }
348 
349  virtual void _finalize(const doublereal* x) {
350  ; //m_temp = x[0];
351  }
352 
353  virtual void showSolution_s(std::ostream& s, const doublereal* x) {
354  s << "------------------- Surface " << domainIndex() << " ------------------- " << std::endl;
355  s << " temperature: " << m_temp << " K" << " " << x[0] << std::endl;
356  }
357 
358  virtual void showSolution(const doublereal* x) {
359  char buf[80];
360  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
361  writelog(buf);
362  writelog("\n");
363  }
364 };
365 
366 /**
367  * A reacting surface.
368  * @ingroup onedim
369  */
370 class ReactingSurf1D : public Bdry1D
371 {
372 public:
373  ReactingSurf1D() : Bdry1D(),
374  m_kin(0), m_surfindex(0), m_nsp(0) {
375  m_type = cSurfType;
376  }
377 
378  void setKineticsMgr(InterfaceKinetics* kin) {
379  m_kin = kin;
380  m_surfindex = kin->surfacePhaseIndex();
381  m_sphase = (SurfPhase*)&kin->thermo(m_surfindex);
382  m_nsp = m_sphase->nSpecies();
383  m_enabled = true;
384  }
385 
386  void enableCoverageEquations(bool docov) {
387  m_enabled = docov;
388  }
389 
390  virtual std::string componentName(size_t n) const;
391 
392  virtual void init();
393 
394  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
395  integer* diagg, doublereal rdt);
396 
397  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
398  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
399 
400  virtual void _getInitialSoln(doublereal* x) {
401  x[0] = m_temp;
402  //m_kin->advanceCoverages(1.0);
403  m_sphase->getCoverages(x+1);
404  }
405 
406  virtual void _finalize(const doublereal* x) {
407  std::copy(x+1,x+1+m_nsp,m_fixed_cov.begin());
408  }
409 
410  virtual void showSolution(const doublereal* x) {
411  char buf[80];
412  sprintf(buf, " Temperature: %10.4g K \n", x[0]);
413  writelog(buf);
414  writelog(" Coverages: \n");
415  for (size_t k = 0; k < m_nsp; k++) {
416  sprintf(buf, " %20s %10.4g \n", m_sphase->speciesName(k).c_str(),
417  x[k+1]);
418  writelog(buf);
419  }
420  writelog("\n");
421  }
422 
423 protected:
424  InterfaceKinetics* m_kin;
425  SurfPhase* m_sphase;
426  size_t m_surfindex, m_nsp;
427  bool m_enabled;
428  vector_fp m_work;
429  vector_fp m_fixed_cov;
430  int dum;
431 };
432 
433 }
434 
435 #endif
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual void setMoleFractions(doublereal *xin)
Set the mole fractions by specifying an array.
Definition: Inlet1D.h:70
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:295
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:410
virtual doublereal mdot()
The total mass flow rate [kg/m2/s].
Definition: Inlet1D.h:86
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition: StFlow.h:41
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
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
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:213
A symmetry plane.
Definition: Inlet1D.h:223
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:358
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:140
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
A reacting surface.
Definition: Inlet1D.h:370
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:271
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
Definition: Inlet1D.h:65
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
virtual void init()
virtual void setTemperature(doublereal t)
Set the temperature.
Definition: Inlet1D.h:51
virtual doublereal massFraction(size_t k)
Mass fraction of species k.
Definition: Inlet1D.h:305
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:289
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual void init()
Definition: Inlet1D.h:46
A terminator that does nothing.
Definition: Inlet1D.h:195
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual doublereal massFraction(size_t k)
Mass fraction of species k.
Definition: Inlet1D.h:75
virtual doublereal temperature()
Temperature [K].
Definition: Inlet1D.h:56
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
virtual void init()
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:345
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:90
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:318
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
An inlet.
Definition: Inlet1D.h:121
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:400
Base class for one-dimensional domains.
Definition: Domain1D.h:37
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
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
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:243
virtual void init()
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
A kinetics manager for heterogeneous reaction mechanisms.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
An outlet.
Definition: Inlet1D.h:252
virtual void setMdot(doublereal mdot)
Set the total mass flow rate.
Definition: Inlet1D.h:81
virtual void setSpreadRate(doublereal V0)
set spreading rate
Definition: Inlet1D.h:130
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
Definition: Inlet1D.h:94
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
An outlet with specified composition.
Definition: Inlet1D.h:281
virtual double spreadRate()
spreading rate
Definition: Inlet1D.h:136
The base class for boundaries between one-dimensional spatial domains.
Definition: Inlet1D.h:41
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
A non-reacting surface.
Definition: Inlet1D.h:328
size_t domainIndex()
The left-to-right location of this domain.
Definition: Domain1D.h:73
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual void init()
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:203
Domain1D(size_t nv=1, size_t points=1, doublereal time=0.0)
Constructor.
Definition: Domain1D.h:46
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:240
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:212
virtual void init()
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:159
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:291
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:164
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:406
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:43
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
void needJacUpdate()
Definition: OneDim.cpp:323
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
virtual doublereal massFraction(size_t k)
Mass fraction of species k.
Definition: Inlet1D.h:172
virtual void init()
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:246
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:268
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: Inlet1D.h:349
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.