Cantera  3.1.0a2
Loading...
Searching...
No Matches
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 "Flow1D.h"
17
18namespace Cantera
19{
20
21const int LeftInlet = 1;
22const 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 */
39class Boundary1D : public Domain1D
40{
41public:
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
109protected:
110 void _init(size_t n);
111
112 Flow1D* m_flow_left = nullptr;
113 Flow1D* 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 */
138class Inlet1D : public Boundary1D
139{
140public:
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 setTemperature(double T) override;
156
157 void show(const double* x) override;
158
159 size_t nSpecies() override {
160 return m_nsp;
161 }
162
163 void setMoleFractions(const string& xin) override;
164 void setMoleFractions(const double* xin) override;
165 double massFraction(size_t k) override {
166 return m_yin[k];
167 }
168 void init() override;
169 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
170 shared_ptr<SolutionArray> asArray(const double* soln) const override;
171 void fromArray(SolutionArray& arr, double* soln) override;
172
173protected:
174 int m_ilr;
175 double m_V0 = 0.0;
176 size_t m_nsp = 0;
177 vector<double> m_yin;
178 string m_xstr;
179 Flow1D* m_flow = nullptr;
180};
181
182/**
183 * A terminator that does nothing.
184 */
185class Empty1D : public Boundary1D
186{
187public:
188 Empty1D() = default;
189
190 Empty1D(shared_ptr<Solution> solution, const string& id="") : Empty1D() {
192 m_id = id;
193 }
194
195 string domainType() const override {
196 return "empty";
197 }
198
199 void show(const double* x) override {}
200
201 void init() override;
202
203 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
204
205 shared_ptr<SolutionArray> asArray(const double* soln) const override;
206};
207
208/**
209 * A symmetry plane. The axial velocity u = 0, and all other components have
210 * zero axial gradients.
211 */
212class Symm1D : public Boundary1D
213{
214public:
215 Symm1D() = default;
216
217 Symm1D(shared_ptr<Solution> solution, const string& id="") : Symm1D() {
219 m_id = id;
220 }
221
222 string domainType() const override {
223 return "symmetry-plane";
224 }
225
226 void init() override;
227
228 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
229
230 shared_ptr<SolutionArray> asArray(const double* soln) const override;
231};
232
233
234/**
235 * An outlet.
236 * Flow is assumed to be from left to right.
237 */
238class Outlet1D : public Boundary1D
239{
240public:
241 Outlet1D() = default;
242
243 Outlet1D(shared_ptr<Solution> solution, const string& id="") : Outlet1D() {
245 m_id = id;
246 }
247
248 string domainType() const override {
249 return "outlet";
250 }
251
252 void init() override;
253
254 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
255
256 shared_ptr<SolutionArray> asArray(const double* soln) const override;
257};
258
259
260/**
261 * An outlet with specified composition.
262 * Flow is assumed to be from left to right.
263 */
265{
266public:
267 OutletRes1D();
268
269 OutletRes1D(shared_ptr<Solution> solution, const string& id="");
270
271 string domainType() const override {
272 return "outlet-reservoir";
273 }
274
275 void show(const double* x) override {}
276
277 size_t nSpecies() override {
278 return m_nsp;
279 }
280
281 void setMoleFractions(const string& xin) override;
282 void setMoleFractions(const double* xin) override;
283 double massFraction(size_t k) override {
284 return m_yres[k];
285 }
286
287 void init() override;
288 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
289 shared_ptr<SolutionArray> asArray(const double* soln) const override;
290 void fromArray(SolutionArray& arr, double* soln) override;
291
292protected:
293 size_t m_nsp = 0;
294 vector<double> m_yres;
295 string m_xstr;
296 Flow1D* m_flow = nullptr;
297};
298
299/**
300 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
301 * transverse velocity (no slip). The temperature is specified, and a zero flux
302 * condition is imposed for the species.
303 */
304class Surf1D : public Boundary1D
305{
306public:
307 Surf1D() = default;
308
309 Surf1D(shared_ptr<Solution> solution, const string& id="") : Surf1D() {
311 m_id = id;
312 }
313
314 string domainType() const override {
315 return "surface";
316 }
317
318 void init() override;
319
320 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
321
322 shared_ptr<SolutionArray> asArray(const double* soln) const override;
323 void fromArray(SolutionArray& arr, double* soln) override;
324
325 void show(std::ostream& s, const double* x) override;
326
327 void show(const double* x) override;
328};
329
330/**
331 * A reacting surface.
332 */
334{
335public:
337 ReactingSurf1D(shared_ptr<Solution> solution, const string& id="");
338
339 string domainType() const override {
340 return "reacting-surface";
341 }
342
343 void setKinetics(shared_ptr<Kinetics> kin) override;
344
345 void enableCoverageEquations(bool docov) {
346 m_enabled = docov;
347 }
348
349 bool coverageEnabled() {
350 return m_enabled;
351 }
352
353 string componentName(size_t n) const override;
354
355 void init() override;
356 void resetBadValues(double* xg) override;
357
358 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
359
360 shared_ptr<SolutionArray> asArray(const double* soln) const override;
361 void fromArray(SolutionArray& arr, double* soln) override;
362
363 void _getInitialSoln(double* x) override {
364 m_sphase->getCoverages(x);
365 }
366
367 void _finalize(const double* x) override {
368 std::copy(x, x+m_nsp, m_fixed_cov.begin());
369 }
370
371 void show(const double* x) override;
372
373protected:
374 InterfaceKinetics* m_kin = nullptr;
375 SurfPhase* m_sphase = nullptr;
376 size_t m_nsp = 0;
377 bool m_enabled = false;
378 vector<double> m_work;
379 vector<double> m_fixed_cov;
380};
381
382//! @} End of bdryGroup
383
384}
385
386#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.
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 > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:364
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
Definition Domain1D.cpp:31
string m_id
Identity tag for the domain.
Definition Domain1D.h:558
A terminator that does nothing.
Definition Boundary1D.h:186
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:195
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:199
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition Flow1D.h:46
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:165
void setTemperature(double T) override
Set the temperature.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
double spreadRate() override
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:151
void setSpreadRate(double V0) override
set spreading rate
string domainType() const override
Domain type flag.
Definition Boundary1D.h:145
void show(const double *x) override
Print the solution.
A kinetics manager for heterogeneous reaction mechanisms.
An error indicating that an unimplemented function has been called.
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:248
An outlet with specified composition.
Definition Boundary1D.h:265
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:283
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:271
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:275
A reacting surface.
Definition Boundary1D.h:334
void setKinetics(shared_ptr< Kinetics > kin) override
Set the kinetics manager.
void resetBadValues(double *xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
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:367
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
string componentName(size_t n) const override
Name of the nth component. May be overloaded.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:339
void show(const double *x) override
Print the solution.
void _getInitialSoln(double *x) override
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition Boundary1D.h:363
A container class holding arrays of state information.
A non-reacting surface.
Definition Boundary1D.h:305
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:314
void show(std::ostream &s, const double *x) override
Print the solution.
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.
A symmetry plane.
Definition Boundary1D.h:213
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:222
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564