Cantera  3.1.0a1
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 //! @defgroup bdryGroup Boundaries
25 //! Boundaries of one-dimensional flow domains.
26 //! @ingroup onedGroup
27 //! @{
28 
29 /**
30  * The base class for boundaries between one-dimensional spatial domains. The
31  * boundary may have its own internal variables, such as surface species
32  * coverages.
33  *
34  * The boundary types are an inlet, an outlet, a symmetry plane, and a surface.
35  *
36  * The public methods are all virtual, and the base class implementations throw
37  * exceptions.
38  */
39 class Boundary1D : public Domain1D
40 {
41 public:
42  Boundary1D();
43 
44  void init() override {
45  _init(1);
46  }
47 
48  string domainType() const override {
49  return "boundary";
50  }
51 
52  bool isConnector() override {
53  return true;
54  }
55 
56  //! Set the temperature.
57  virtual void setTemperature(double t) {
58  m_temp = t;
59  }
60 
61  //! Temperature [K].
62  virtual double temperature() {
63  return m_temp;
64  }
65 
66  virtual size_t nSpecies() {
67  return 0;
68  }
69 
70  //! Set the mole fractions by specifying a string.
71  virtual void setMoleFractions(const string& xin) {
72  throw NotImplementedError("Boundary1D::setMoleFractions");
73  }
74 
75  //! Set the mole fractions by specifying an array.
76  virtual void setMoleFractions(const double* xin) {
77  throw NotImplementedError("Boundary1D::setMoleFractions");
78  }
79 
80  //! Mass fraction of species k.
81  virtual double massFraction(size_t k) {
82  throw NotImplementedError("Boundary1D::massFraction");
83  }
84 
85  //! Set the total mass flow rate.
86  virtual void setMdot(double mdot) {
87  m_mdot = mdot;
88  }
89 
90  //! Set tangential velocity gradient [1/s] at this boundary.
91  virtual void setSpreadRate(double V0) {
92  throw NotImplementedError("Boundary1D::setSpreadRate");
93  }
94 
95  //! Tangential velocity gradient [1/s] at this boundary.
96  virtual double spreadRate() {
97  throw NotImplementedError("Boundary1D::spreadRate");
98  }
99 
100  //! The total mass flow rate [kg/m2/s].
101  virtual double mdot() {
102  return m_mdot;
103  }
104 
105  void setupGrid(size_t n, const double* z) override {}
106 
107  void fromArray(SolutionArray& arr, double* soln) override;
108 
109 protected:
110  void _init(size_t n);
111 
112  StFlow* m_flow_left = nullptr;
113  StFlow* m_flow_right = nullptr;
114  size_t m_ilr = 0;
115  size_t m_left_nv = 0;
116  size_t m_right_nv = 0;
117  size_t m_left_loc = 0;
118  size_t m_right_loc = 0;
119  size_t m_left_points = 0;
120  size_t m_left_nsp = 0;
121  size_t m_right_nsp = 0;
122  size_t m_sp_left = 0;
123  size_t m_sp_right = 0;
124  size_t m_start_left = 0;
125  size_t m_start_right = 0;
126  ThermoPhase* m_phase_left = nullptr;
127  ThermoPhase* m_phase_right = nullptr;
128  double m_temp = 0.0;
129  double m_mdot = 0.0;
130 };
131 
132 
133 /**
134  * An inlet.
135  * Unstrained flows use an inlet to the left of the flow domain (left-to-right flow).
136  * Strained flow configurations may have inlets on the either side of the flow domain.
137  */
138 class Inlet1D : public Boundary1D
139 {
140 public:
141  Inlet1D();
142 
143  Inlet1D(shared_ptr<Solution> solution, const string& id="");
144 
145  string domainType() const override {
146  return "inlet";
147  }
148 
149  void setSpreadRate(double V0) override;
150 
151  double spreadRate() override {
152  return m_V0;
153  }
154 
155  void show(const double* x) override;
156 
157  size_t nSpecies() override {
158  return m_nsp;
159  }
160 
161  void setMoleFractions(const string& xin) override;
162  void setMoleFractions(const double* xin) override;
163  double massFraction(size_t k) override {
164  return m_yin[k];
165  }
166  void init() override;
167  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
168  shared_ptr<SolutionArray> asArray(const double* soln) const override;
169  void fromArray(SolutionArray& arr, double* soln) override;
170 
171 protected:
172  int m_ilr;
173  double m_V0 = 0.0;
174  size_t m_nsp = 0;
175  vector<double> m_yin;
176  string m_xstr;
177  StFlow* m_flow = nullptr;
178 };
179 
180 /**
181  * A terminator that does nothing.
182  */
183 class Empty1D : public Boundary1D
184 {
185 public:
186  Empty1D() = default;
187 
188  Empty1D(shared_ptr<Solution> solution, const string& id="") : Empty1D() {
190  m_id = id;
191  }
192 
193  string domainType() const override {
194  return "empty";
195  }
196 
197  void show(const double* x) override {}
198 
199  void init() override;
200 
201  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
202 
203  shared_ptr<SolutionArray> asArray(const double* soln) const override;
204 };
205 
206 /**
207  * A symmetry plane. The axial velocity u = 0, and all other components have
208  * zero axial gradients.
209  */
210 class Symm1D : public Boundary1D
211 {
212 public:
213  Symm1D() = default;
214 
215  Symm1D(shared_ptr<Solution> solution, const string& id="") : Symm1D() {
217  m_id = id;
218  }
219 
220  string domainType() const override {
221  return "symmetry-plane";
222  }
223 
224  void init() override;
225 
226  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
227 
228  shared_ptr<SolutionArray> asArray(const double* soln) const override;
229 };
230 
231 
232 /**
233  * An outlet.
234  * Flow is assumed to be from left to right.
235  */
236 class Outlet1D : public Boundary1D
237 {
238 public:
239  Outlet1D() = default;
240 
241  Outlet1D(shared_ptr<Solution> solution, const string& id="") : Outlet1D() {
243  m_id = id;
244  }
245 
246  string domainType() const override {
247  return "outlet";
248  }
249 
250  void init() override;
251 
252  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
253 
254  shared_ptr<SolutionArray> asArray(const double* soln) const override;
255 };
256 
257 
258 /**
259  * An outlet with specified composition.
260  * Flow is assumed to be from left to right.
261  */
262 class OutletRes1D : public Boundary1D
263 {
264 public:
265  OutletRes1D();
266 
267  OutletRes1D(shared_ptr<Solution> solution, const string& id="");
268 
269  string domainType() const override {
270  return "outlet-reservoir";
271  }
272 
273  void show(const double* x) override {}
274 
275  size_t nSpecies() override {
276  return m_nsp;
277  }
278 
279  void setMoleFractions(const string& xin) override;
280  void setMoleFractions(const double* xin) override;
281  double massFraction(size_t k) override {
282  return m_yres[k];
283  }
284 
285  void init() override;
286  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
287  shared_ptr<SolutionArray> asArray(const double* soln) const override;
288  void fromArray(SolutionArray& arr, double* soln) override;
289 
290 protected:
291  size_t m_nsp = 0;
292  vector<double> m_yres;
293  string m_xstr;
294  StFlow* m_flow = nullptr;
295 };
296 
297 /**
298  * A non-reacting surface. The axial velocity is zero (impermeable), as is the
299  * transverse velocity (no slip). The temperature is specified, and a zero flux
300  * condition is imposed for the species.
301  */
302 class Surf1D : public Boundary1D
303 {
304 public:
305  Surf1D() = default;
306 
307  Surf1D(shared_ptr<Solution> solution, const string& id="") : Surf1D() {
309  m_id = id;
310  }
311 
312  string domainType() const override {
313  return "surface";
314  }
315 
316  void init() override;
317 
318  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
319 
320  shared_ptr<SolutionArray> asArray(const double* soln) const override;
321  void fromArray(SolutionArray& arr, double* soln) override;
322 
323  void show(std::ostream& s, const double* x) override;
324 
325  void show(const double* x) override;
326 };
327 
328 /**
329  * A reacting surface.
330  */
332 {
333 public:
334  ReactingSurf1D();
335  ReactingSurf1D(shared_ptr<Solution> solution, const string& id="");
336 
337  string domainType() const override {
338  return "reacting-surface";
339  }
340 
341  void setKinetics(shared_ptr<Kinetics> kin) override;
342 
343  void enableCoverageEquations(bool docov) {
344  m_enabled = docov;
345  }
346 
347  bool coverageEnabled() {
348  return m_enabled;
349  }
350 
351  string componentName(size_t n) const override;
352 
353  void init() override;
354  void resetBadValues(double* xg) override;
355 
356  void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
357 
358  shared_ptr<SolutionArray> asArray(const double* soln) const override;
359  void fromArray(SolutionArray& arr, double* soln) override;
360 
361  void _getInitialSoln(double* x) override {
362  m_sphase->getCoverages(x);
363  }
364 
365  void _finalize(const double* x) override {
366  std::copy(x, x+m_nsp, m_fixed_cov.begin());
367  }
368 
369  void show(const double* x) override;
370 
371 protected:
372  InterfaceKinetics* m_kin = nullptr;
373  SurfPhase* m_sphase = nullptr;
374  size_t m_nsp = 0;
375  bool m_enabled = false;
376  vector<double> m_work;
377  vector<double> m_fixed_cov;
378 };
379 
380 //! @} End of bdryGroup
381 
382 }
383 
384 #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:40
bool isConnector() override
True if the domain is a connector domain.
Definition: Boundary1D.h:52
virtual void setMdot(double mdot)
Set the total mass flow rate.
Definition: Boundary1D.h:86
virtual void setMoleFractions(const string &xin)
Set the mole fractions by specifying a string.
Definition: Boundary1D.h:71
virtual double temperature()
Temperature [K].
Definition: Boundary1D.h:62
virtual void setTemperature(double t)
Set the temperature.
Definition: Boundary1D.h:57
virtual void setMoleFractions(const double *xin)
Set the mole fractions by specifying an array.
Definition: Boundary1D.h:76
void setupGrid(size_t n, const double *z) override
called to set up initial grid, and after grid refinement
Definition: Boundary1D.h:105
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition: Boundary1D.cpp:79
virtual void setSpreadRate(double V0)
Set tangential velocity gradient [1/s] at this boundary.
Definition: Boundary1D.h:91
virtual double mdot()
The total mass flow rate [kg/m2/s].
Definition: Boundary1D.h:101
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition: Boundary1D.h:81
void init() override
Initialize.
Definition: Boundary1D.h:44
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:48
virtual double spreadRate()
Tangential velocity gradient [1/s] at this boundary.
Definition: Boundary1D.h:96
Base class for one-dimensional domains.
Definition: Domain1D.h:28
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition: Domain1D.h:567
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition: Domain1D.h:366
string m_id
Identity tag for the domain.
Definition: Domain1D.h:560
A terminator that does nothing.
Definition: Boundary1D.h:184
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:287
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:282
void init() override
Initialize.
Definition: Boundary1D.cpp:277
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:193
void show(const double *x) override
Print the solution.
Definition: Boundary1D.h:197
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
Definition: Boundary1D.cpp:122
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:241
double massFraction(size_t k) override
Mass fraction of species k.
Definition: Boundary1D.h:163
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:173
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition: Boundary1D.cpp:258
void init() override
Initialize.
Definition: Boundary1D.cpp:141
double spreadRate() override
Tangential velocity gradient [1/s] at this boundary.
Definition: Boundary1D.h:151
void setSpreadRate(double V0) override
set spreading rate
Definition: Boundary1D.cpp:99
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:145
void show(const double *x) override
Print the solution.
Definition: Boundary1D.cpp:106
A kinetics manager for heterogeneous reaction mechanisms.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:195
An outlet.
Definition: Boundary1D.h:237
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:406
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:373
void init() override
Initialize.
Definition: Boundary1D.cpp:358
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:246
An outlet with specified composition.
Definition: Boundary1D.h:263
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
Definition: Boundary1D.cpp:414
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:488
double massFraction(size_t k) override
Mass fraction of species k.
Definition: Boundary1D.h:281
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:456
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition: Boundary1D.cpp:505
void init() override
Initialize.
Definition: Boundary1D.cpp:433
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:269
void show(const double *x) override
Print the solution.
Definition: Boundary1D.h:273
A reacting surface.
Definition: Boundary1D.h:332
void setKinetics(shared_ptr< Kinetics > kin) override
Set the kinetics manager.
Definition: Boundary1D.cpp:602
void resetBadValues(double *xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
Definition: Boundary1D.cpp:637
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:726
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:643
void _finalize(const double *x) override
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition: Boundary1D.h:365
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition: Boundary1D.cpp:745
string componentName(size_t n) const override
Name of the nth component. May be overloaded.
Definition: Boundary1D.cpp:614
void init() override
Initialize.
Definition: Boundary1D.cpp:623
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:337
void show(const double *x) override
Print the solution.
Definition: Boundary1D.cpp:758
void _getInitialSoln(double *x) override
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition: Boundary1D.h:361
A container class holding arrays of state information.
Definition: SolutionArray.h:33
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition: StFlow.h:45
A non-reacting surface.
Definition: Boundary1D.h:303
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:547
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:522
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition: Boundary1D.cpp:554
void init() override
Initialize.
Definition: Boundary1D.cpp:517
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:312
void show(std::ostream &s, const double *x) override
Print the solution.
Definition: Boundary1D.cpp:562
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:98
void getCoverages(double *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:249
A symmetry plane.
Definition: Boundary1D.h:211
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition: Boundary1D.cpp:339
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition: Boundary1D.cpp:300
void init() override
Initialize.
Definition: Boundary1D.cpp:295
string domainType() const override
Domain type flag.
Definition: Boundary1D.h:220
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:390
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564