Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
19 #include <cstdio>
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  * @ingroup onedim
38  */
39 class Bdry1D : public Domain1D
40 {
41 public:
42  Bdry1D();
43 
44  virtual void init() {
45  _init(1);
46  }
47 
48  /// Set the temperature.
49  virtual void setTemperature(doublereal t) {
50  m_temp = t;
51  }
52 
53  /// Temperature [K].
54  virtual doublereal temperature() {
55  return m_temp;
56  }
57 
58  virtual size_t nSpecies() {
59  return 0;
60  }
61 
62  /// Set the mole fractions by specifying a std::string.
63  virtual void setMoleFractions(const std::string& xin) {
64  throw NotImplementedError("Bdry1D::setMoleFractions");
65  }
66 
67  /// Set the mole fractions by specifying an array.
68  virtual void setMoleFractions(const doublereal* xin) {
69  throw NotImplementedError("Bdry1D::setMoleFractions");
70  }
71 
72  /// Mass fraction of species k.
73  virtual doublereal massFraction(size_t k) {
74  throw NotImplementedError("Bdry1D::massFraction");
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  void _init(size_t n);
95 
96  StFlow* m_flow_left, *m_flow_right;
97  size_t m_ilr, m_left_nv, m_right_nv;
98  size_t m_left_loc, m_right_loc;
99  size_t m_left_points;
100  size_t m_nv, m_left_nsp, m_right_nsp;
101  size_t m_sp_left, m_sp_right;
102  size_t m_start_left, m_start_right;
103  ThermoPhase* m_phase_left, *m_phase_right;
104  doublereal m_temp, m_mdot;
105 };
106 
107 
108 /**
109  * An inlet.
110  * @ingroup onedim
111  */
112 class Inlet1D : public Bdry1D
113 {
114 public:
115  Inlet1D() : Bdry1D(), m_V0(0.0), m_nsp(0), m_flow(0) {
116  m_type = cInletType;
117  m_xstr = "";
118  }
119 
120  /// set spreading rate
121  virtual void setSpreadRate(doublereal V0) {
122  m_V0 = V0;
123  needJacUpdate();
124  }
125 
126  /// spreading rate
127  virtual double spreadRate() {
128  return m_V0;
129  }
130 
131  virtual void showSolution(const doublereal* x) {
132  char buf[80];
133  sprintf(buf, " Mass Flux: %10.4g kg/m^2/s \n", m_mdot);
134  writelog(buf);
135  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
136  writelog(buf);
137  if (m_flow) {
138  writelog(" Mass Fractions: \n");
139  for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
140  if (m_yin[k] != 0.0) {
141  sprintf(buf, " %16s %10.4g \n",
142  m_flow->phase().speciesName(k).c_str(), m_yin[k]);
143  writelog(buf);
144  }
145  }
146  }
147  writelog("\n");
148  }
149 
150  virtual void _getInitialSoln(doublereal* x) {
151  x[0] = m_mdot;
152  x[1] = m_temp;
153  }
154 
155  virtual size_t nSpecies() {
156  return m_nsp;
157  }
158 
159  virtual void setMoleFractions(const std::string& xin);
160  virtual void setMoleFractions(const doublereal* xin);
161  virtual doublereal massFraction(size_t k) {
162  return m_yin[k];
163  }
164  virtual std::string componentName(size_t n) const;
165  virtual void init();
166  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
167  integer* diagg, doublereal rdt);
168  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
169  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
170 
171 protected:
172  int m_ilr;
173  doublereal m_V0;
174  size_t m_nsp;
175  vector_fp m_yin;
176  std::string m_xstr;
177  StFlow* m_flow;
178 };
179 
180 /**
181  * A terminator that does nothing.
182  * @ingroup onedim
183  */
184 class Empty1D : public Domain1D
185 {
186 public:
187  Empty1D() : Domain1D() {
188  m_type = cEmptyType;
189  }
190 
191  virtual std::string componentName(size_t n) const;
192  virtual void showSolution(const doublereal* x) {}
193 
194  virtual void init();
195 
196  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
197  integer* diagg, doublereal rdt);
198 
199  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
200  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
201  virtual void _getInitialSoln(doublereal* x) {
202  x[0] = 0.0;
203  }
204 };
205 
206 /**
207  * A symmetry plane. The axial velocity u = 0, and all other
208  * components have zero axial gradients.
209  * @ingroup onedim
210  */
211 class Symm1D : public Bdry1D
212 {
213 public:
214 
215  Symm1D() : Bdry1D() {
216  m_type = cSymmType;
217  }
218 
219  virtual std::string componentName(size_t n) const;
220 
221  virtual void init();
222 
223  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
224  integer* diagg, doublereal rdt);
225 
226  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
227  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
228  virtual void _getInitialSoln(doublereal* x) {
229  x[0] = m_temp;
230  }
231 };
232 
233 
234 /**
235  * An outlet.
236  */
237 class Outlet1D : public Bdry1D
238 {
239 public:
240  Outlet1D() : Bdry1D() {
241  m_type = cOutletType;
242  }
243 
244  virtual std::string componentName(size_t n) const;
245 
246  virtual void init();
247 
248  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
249  integer* diagg, doublereal rdt);
250 
251  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
252  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
253  virtual void _getInitialSoln(doublereal* x) {
254  x[0] = m_temp;
255  }
256 };
257 
258 
259 /**
260  * An outlet with specified composition.
261  * @ingroup onedim
262  */
263 class OutletRes1D : public Bdry1D
264 {
265 public:
266  OutletRes1D() : Bdry1D(), m_nsp(0), m_flow(0) {
267  m_type = cOutletResType;
268  m_xstr = "";
269  }
270 
271  virtual void showSolution(const doublereal* x) {}
272 
273  virtual void _getInitialSoln(doublereal* x) {
274  x[0] = m_temp;
275  }
276 
277  virtual size_t nSpecies() {
278  return m_nsp;
279  }
280 
281  virtual void setMoleFractions(const std::string& xin);
282  virtual void setMoleFractions(const doublereal* xin);
283  virtual doublereal massFraction(size_t k) {
284  return m_yres[k];
285  }
286  virtual std::string componentName(size_t n) const;
287  virtual void init();
288  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
289  integer* diagg, doublereal rdt);
290  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
291  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
292 
293 protected:
294  size_t m_nsp;
295  vector_fp m_yres;
296  std::string m_xstr;
297  StFlow* m_flow;
298 };
299 
300 /**
301  * A non-reacting surface. The axial velocity is zero
302  * (impermeable), as is the transverse velocity (no slip). The
303  * temperature is specified, and a zero flux condition is imposed
304  * for the species.
305  */
306 class Surf1D : public Bdry1D
307 {
308 public:
309  Surf1D() : Bdry1D() {
310  m_type = cSurfType;
311  }
312 
313  virtual std::string componentName(size_t n) const;
314 
315  virtual void init();
316 
317  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
318  integer* diagg, doublereal rdt);
319 
320  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
321  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
322 
323  virtual void _getInitialSoln(doublereal* x) {
324  x[0] = m_temp;
325  }
326 
327  virtual void showSolution_s(std::ostream& s, const doublereal* x) {
328  s << "------------------- Surface " << domainIndex() << " ------------------- " << std::endl;
329  s << " temperature: " << m_temp << " K" << " " << x[0] << std::endl;
330  }
331 
332  virtual void showSolution(const doublereal* x) {
333  char buf[80];
334  sprintf(buf, " Temperature: %10.4g K \n", m_temp);
335  writelog(buf);
336  writelog("\n");
337  }
338 };
339 
340 /**
341  * A reacting surface.
342  * @ingroup onedim
343  */
344 class ReactingSurf1D : public Bdry1D
345 {
346 public:
347  ReactingSurf1D() : Bdry1D(),
348  m_kin(0), m_surfindex(0), m_nsp(0) {
349  m_type = cSurfType;
350  }
351 
352  void setKineticsMgr(InterfaceKinetics* kin) {
353  m_kin = kin;
354  m_surfindex = kin->surfacePhaseIndex();
355  m_sphase = (SurfPhase*)&kin->thermo(m_surfindex);
356  m_nsp = m_sphase->nSpecies();
357  m_enabled = true;
358  }
359 
360  void enableCoverageEquations(bool docov) {
361  m_enabled = docov;
362  }
363 
364  virtual std::string componentName(size_t n) const;
365 
366  virtual void init();
367 
368  virtual void eval(size_t jg, doublereal* xg, doublereal* rg,
369  integer* diagg, doublereal rdt);
370 
371  virtual XML_Node& save(XML_Node& o, const doublereal* const soln);
372  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
373 
374  virtual void _getInitialSoln(doublereal* x) {
375  x[0] = m_temp;
376  //m_kin->advanceCoverages(1.0);
377  m_sphase->getCoverages(x+1);
378  }
379 
380  virtual void _finalize(const doublereal* x) {
381  std::copy(x+1,x+1+m_nsp,m_fixed_cov.begin());
382  }
383 
384  virtual void showSolution(const doublereal* x) {
385  char buf[80];
386  sprintf(buf, " Temperature: %10.4g K \n", x[0]);
387  writelog(buf);
388  writelog(" Coverages: \n");
389  for (size_t k = 0; k < m_nsp; k++) {
390  sprintf(buf, " %20s %10.4g \n", m_sphase->speciesName(k).c_str(),
391  x[k+1]);
392  writelog(buf);
393  }
394  writelog("\n");
395  }
396 
397 protected:
398  InterfaceKinetics* m_kin;
399  SurfPhase* m_sphase;
400  size_t m_surfindex, m_nsp;
401  bool m_enabled;
402  vector_fp m_work;
403  vector_fp m_fixed_cov;
404  int dum;
405 };
406 
407 }
408 
409 #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 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.
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:384
virtual doublereal mdot()
The total mass flow rate [kg/m2/s].
Definition: Inlet1D.h:83
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:39
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
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
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:201
A symmetry plane.
Definition: Inlet1D.h:211
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:332
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:131
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:344
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:253
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
Definition: Inlet1D.h:63
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:49
virtual doublereal massFraction(size_t k)
Mass fraction of species k.
Definition: Inlet1D.h:283
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:271
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:44
A terminator that does nothing.
Definition: Inlet1D.h:184
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:73
virtual doublereal temperature()
Temperature [K].
Definition: Inlet1D.h:54
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:323
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:87
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:319
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
An inlet.
Definition: Inlet1D.h:112
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:374
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:260
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:228
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:237
virtual void setMdot(doublereal mdot)
Set the total mass flow rate.
Definition: Inlet1D.h:78
virtual void setSpreadRate(doublereal V0)
set spreading rate
Definition: Inlet1D.h:121
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
Definition: Inlet1D.h:91
An outlet with specified composition.
Definition: Inlet1D.h:263
virtual double spreadRate()
spreading rate
Definition: Inlet1D.h:127
The base class for boundaries between one-dimensional spatial domains.
Definition: Inlet1D.h:39
virtual void setMoleFractions(const doublereal *xin)
Set the mole fractions by specifying an array.
Definition: Inlet1D.h:68
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:306
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:265
virtual void init()
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: Inlet1D.h:192
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:157
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from 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:150
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Inlet1D.h:273
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:380
void writelog(const std::string &msg)
Write a message to the screen.
Definition: global.cpp:33
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
void needJacUpdate()
Definition: Domain1D.cpp:42
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:161
virtual void init()
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.