Cantera  2.5.1
Boundary1D.h
Go to the documentation of this file.
1 /**
2  * @file Boundary1D.h
3  *
4  * Boundary objects for one-dimensional simulations.
5  */
6 
7 // This file is part of Cantera. See License.txt in the top-level directory or
8 // at https://cantera.org/license.txt for license and copyright information.
9 
10 #ifndef CT_BOUNDARY1D_H
11 #define CT_BOUNDARY1D_H
12 
13 #include "Domain1D.h"
16 #include "StFlow.h"
17 
18 namespace Cantera
19 {
20 
21 const int LeftInlet = 1;
22 const int RightInlet = -1;
23 
24 /**
25  * The base class for boundaries between one-dimensional spatial domains. The
26  * boundary may have its own internal variables, such as surface species
27  * coverages.
28  *
29  * The boundary types are an inlet, an outlet, a symmetry plane, and a surface.
30  *
31  * The public methods are all virtual, and the base class implementations throw
32  * exceptions.
33  * @ingroup onedim
34  */
35 class Boundary1D : public Domain1D
36 {
37 public:
38  Boundary1D();
39 
40  virtual void init() {
41  _init(1);
42  }
43 
44  /// Set the temperature.
45  virtual void setTemperature(double t) {
46  m_temp = t;
47  }
48 
49  /// Temperature [K].
50  virtual double temperature() {
51  return m_temp;
52  }
53 
54  virtual size_t nSpecies() {
55  return 0;
56  }
57 
58  /// Set the mole fractions by specifying a std::string.
59  virtual void setMoleFractions(const std::string& xin) {
60  throw NotImplementedError("Boundary1D::setMoleFractions");
61  }
62 
63  /// Set the mole fractions by specifying an array.
64  virtual void setMoleFractions(const double* xin) {
65  throw NotImplementedError("Boundary1D::setMoleFractions");
66  }
67 
68  /// Mass fraction of species k.
69  virtual double massFraction(size_t k) {
70  throw NotImplementedError("Boundary1D::massFraction");
71  }
72 
73  /// Set the total mass flow rate.
74  virtual void setMdot(double mdot) {
75  m_mdot = mdot;
76  }
77 
78  /// The total mass flow rate [kg/m2/s].
79  virtual double mdot() {
80  return m_mdot;
81  }
82 
83  virtual void setupGrid(size_t n, const double* z) {}
84 
85 protected:
86  void _init(size_t n);
87 
88  StFlow* m_flow_left, *m_flow_right;
89  size_t m_ilr, m_left_nv, m_right_nv;
90  size_t m_left_loc, m_right_loc;
91  size_t m_left_points;
92  size_t m_left_nsp, m_right_nsp;
93  size_t m_sp_left, m_sp_right;
94  size_t m_start_left, m_start_right;
95  ThermoPhase* m_phase_left, *m_phase_right;
96  double m_temp, m_mdot;
97 };
98 
99 
100 /*!
101  * Renamed base class for boundaries between one-dimensional spatial domains.
102  * @deprecated To be removed after Cantera 2.5.
103  */
104 class Bdry1D : public Boundary1D
105 {
106 public:
107  Bdry1D() : Boundary1D() {
108  warn_deprecated("Bdry1D::Bdry1D()",
109  "To be removed after Cantera 2.5. "
110  "Class renamed to Boundary1D.");
111  }
112 };
113 
114 
115 /**
116  * An inlet.
117  * @ingroup onedim
118  */
119 class Inlet1D : public Boundary1D
120 {
121 public:
122  Inlet1D();
123 
124  /// set spreading rate
125  virtual void setSpreadRate(double V0) {
126  m_V0 = V0;
127  needJacUpdate();
128  }
129 
130  /// spreading rate
131  virtual double spreadRate() {
132  return m_V0;
133  }
134 
135  virtual void showSolution(const double* x);
136 
137  virtual size_t nSpecies() {
138  return m_nsp;
139  }
140 
141  virtual void setMoleFractions(const std::string& xin);
142  virtual void setMoleFractions(const double* xin);
143  virtual double massFraction(size_t k) {
144  return m_yin[k];
145  }
146  virtual void init();
147  virtual void eval(size_t jg, double* xg, double* rg,
148  integer* diagg, double rdt);
149  virtual XML_Node& save(XML_Node& o, const double* const soln);
150  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
151 
152 protected:
153  int m_ilr;
154  double m_V0;
155  size_t m_nsp;
156  vector_fp m_yin;
157  std::string m_xstr;
158  StFlow* m_flow;
159 };
160 
161 /**
162  * A terminator that does nothing.
163  * @ingroup onedim
164  */
165 class Empty1D : public Boundary1D
166 {
167 public:
168  Empty1D() : Boundary1D() {
169  m_type = cEmptyType;
170  }
171 
172  virtual void showSolution(const double* x) {}
173 
174  virtual void init();
175 
176  virtual void eval(size_t jg, double* xg, double* rg,
177  integer* diagg, double rdt);
178 
179  virtual XML_Node& save(XML_Node& o, const double* const soln);
180  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
181 };
182 
183 /**
184  * A symmetry plane. The axial velocity u = 0, and all other components have
185  * zero axial gradients.
186  * @ingroup onedim
187  */
188 class Symm1D : public Boundary1D
189 {
190 public:
191  Symm1D() : Boundary1D() {
192  m_type = cSymmType;
193  }
194 
195  virtual void init();
196 
197  virtual void eval(size_t jg, double* xg, double* rg,
198  integer* diagg, double rdt);
199 
200  virtual XML_Node& save(XML_Node& o, const double* const soln);
201  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
202 };
203 
204 
205 /**
206  * An outlet.
207  * @ingroup onedim
208  */
209 class Outlet1D : public Boundary1D
210 {
211 public:
212  Outlet1D() : Boundary1D() {
213  m_type = cOutletType;
214  }
215 
216  virtual void init();
217 
218  virtual void eval(size_t jg, double* xg, double* rg,
219  integer* diagg, double rdt);
220 
221  virtual XML_Node& save(XML_Node& o, const double* const soln);
222  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
223 };
224 
225 
226 /**
227  * An outlet with specified composition.
228  * @ingroup onedim
229  */
230 class OutletRes1D : public Boundary1D
231 {
232 public:
233  OutletRes1D();
234 
235  virtual void showSolution(const double* x) {}
236 
237  virtual size_t nSpecies() {
238  return m_nsp;
239  }
240 
241  virtual void setMoleFractions(const std::string& xin);
242  virtual void setMoleFractions(const double* xin);
243  virtual double massFraction(size_t k) {
244  return m_yres[k];
245  }
246  virtual void init();
247  virtual void eval(size_t jg, double* xg, double* rg,
248  integer* diagg, double rdt);
249  virtual XML_Node& save(XML_Node& o, const double* const soln);
250  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
251 
252 protected:
253  size_t m_nsp;
254  vector_fp m_yres;
255  std::string m_xstr;
256  StFlow* m_flow;
257 };
258 
259 /**
260  * A non-reacting surface. The axial velocity is zero (impermeable), as is the
261  * transverse velocity (no slip). The temperature is specified, and a zero flux
262  * condition is imposed for the species.
263  * @ingroup onedim
264  */
265 class Surf1D : public Boundary1D
266 {
267 public:
268  Surf1D() : Boundary1D() {
269  m_type = cSurfType;
270  }
271 
272  virtual void init();
273 
274  virtual void eval(size_t jg, double* xg, double* rg,
275  integer* diagg, double rdt);
276 
277  virtual XML_Node& save(XML_Node& o, const double* const soln);
278  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
279 
280  virtual void showSolution_s(std::ostream& s, const double* x);
281 
282  virtual void showSolution(const double* x) {
283  writelog(" Temperature: {:10.4g} K \n\n", m_temp);
284  }
285 };
286 
287 /**
288  * A reacting surface.
289  * @ingroup onedim
290  */
292 {
293 public:
294  ReactingSurf1D();
295 
296  void setKineticsMgr(InterfaceKinetics* kin);
297 
298  void enableCoverageEquations(bool docov) {
299  m_enabled = docov;
300  }
301 
302  bool coverageEnabled() {
303  return m_enabled;
304  }
305 
306  virtual std::string componentName(size_t n) const;
307 
308  virtual void init();
309  virtual void resetBadValues(double* xg);
310 
311  virtual void eval(size_t jg, double* xg, double* rg,
312  integer* diagg, double rdt);
313 
314  virtual XML_Node& save(XML_Node& o, const double* const soln);
315  virtual void restore(const XML_Node& dom, double* soln, int loglevel);
316 
317  virtual void _getInitialSoln(double* x) {
318  m_sphase->getCoverages(x);
319  }
320 
321  virtual void _finalize(const double* x) {
322  std::copy(x, x+m_nsp, m_fixed_cov.begin());
323  }
324 
325  virtual void showSolution(const double* x);
326 
327 protected:
328  InterfaceKinetics* m_kin;
329  SurfPhase* m_sphase;
330  size_t m_surfindex, m_nsp;
331  bool m_enabled;
332  vector_fp m_work;
333  vector_fp m_fixed_cov;
334 };
335 
336 }
337 
338 #endif
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
The base class for boundaries between one-dimensional spatial domains.
Definition: Boundary1D.h:36
virtual void setMdot(double mdot)
Set the total mass flow rate.
Definition: Boundary1D.h:74
virtual void setupGrid(size_t n, const double *z)
called to set up initial grid, and after grid refinement
Definition: Boundary1D.h:83
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
Definition: Boundary1D.h:59
virtual double temperature()
Temperature [K].
Definition: Boundary1D.h:50
virtual void init()
Definition: Boundary1D.h:40
virtual void setTemperature(double t)
Set the temperature.
Definition: Boundary1D.h:45
virtual void setMoleFractions(const double *xin)
Set the mole fractions by specifying an array.
Definition: Boundary1D.h:64
virtual double mdot()
The total mass flow rate [kg/m2/s].
Definition: Boundary1D.h:79
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition: Boundary1D.h:69
Base class for one-dimensional domains.
Definition: Domain1D.h:39
void needJacUpdate()
Definition: Domain1D.cpp:102
A terminator that does nothing.
Definition: Boundary1D.h:166
virtual void init()
Definition: Boundary1D.cpp:245
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:255
virtual void showSolution(const double *x)
Print the solution.
Definition: Boundary1D.h:172
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:250
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:262
virtual void init()
Definition: Boundary1D.cpp:122
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
Definition: Boundary1D.cpp:103
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:210
virtual void showSolution(const double *x)
Print the solution.
Definition: Boundary1D.cpp:87
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:149
virtual void setSpreadRate(double V0)
set spreading rate
Definition: Boundary1D.h:125
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition: Boundary1D.h:143
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:223
virtual double spreadRate()
spreading rate
Definition: Boundary1D.h:131
A kinetics manager for heterogeneous reaction mechanisms.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:187
An outlet.
Definition: Boundary1D.h:210
virtual void init()
Definition: Boundary1D.cpp:337
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:398
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:349
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:405
An outlet with specified composition.
Definition: Boundary1D.h:231
virtual void init()
Definition: Boundary1D.cpp:432
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
Definition: Boundary1D.cpp:413
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:509
virtual void showSolution(const double *x)
Print the solution.
Definition: Boundary1D.h:235
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:453
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition: Boundary1D.h:243
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:521
A reacting surface.
Definition: Boundary1D.h:292
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:724
virtual void _finalize(const double *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition: Boundary1D.h:321
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
Definition: Boundary1D.cpp:612
virtual void showSolution(const double *x)
Print the solution.
Definition: Boundary1D.cpp:757
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:640
virtual void resetBadValues(double *xg)
Definition: Boundary1D.cpp:634
virtual void _getInitialSoln(double *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Boundary1D.h:317
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:736
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition: StFlow.h:37
A non-reacting surface.
Definition: Boundary1D.h:266
virtual void init()
Definition: Boundary1D.cpp:542
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:572
virtual void showSolution(const double *x)
Print the solution.
Definition: Boundary1D.h:282
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:547
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:580
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:143
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:261
A symmetry plane.
Definition: Boundary1D.h:189
virtual void init()
Definition: Boundary1D.cpp:270
virtual XML_Node & save(XML_Node &o, const double *const soln)
Save the current solution for this domain into an XML_Node.
Definition: Boundary1D.cpp:314
virtual void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt)
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:275
virtual void restore(const XML_Node &dom, double *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: Boundary1D.cpp:321
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:180
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
Definition: global.h:158
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264