Cantera  3.0.0
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 "StFlow.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 type() 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 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 */
138class Inlet1D : public Boundary1D
139{
140public:
141 Inlet1D();
142
143 Inlet1D(shared_ptr<Solution> solution, const string& id="");
144
145 string type() 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
171protected:
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 */
183class Empty1D : public Boundary1D
184{
185public:
186 Empty1D() {
187 m_type = cEmptyType;
188 }
189
190 Empty1D(shared_ptr<Solution> solution, const string& id="") : Empty1D() {
192 m_id = id;
193 }
194
195 string type() 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() {
216 m_type = cSymmType;
217 }
218
219 Symm1D(shared_ptr<Solution> solution, const string& id="") : Symm1D() {
221 m_id = id;
222 }
223
224 string type() const override {
225 return "symmetry-plane";
226 }
227
228 void init() override;
229
230 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
231
232 shared_ptr<SolutionArray> asArray(const double* soln) const override;
233};
234
235
236/**
237 * An outlet.
238 * Flow is assumed to be from left to right.
239 */
240class Outlet1D : public Boundary1D
241{
242public:
243 Outlet1D() {
244 m_type = cOutletType;
245 }
246
247 Outlet1D(shared_ptr<Solution> solution, const string& id="") : Outlet1D() {
249 m_id = id;
250 }
251
252 string type() const override {
253 return "outlet";
254 }
255
256 void init() override;
257
258 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
259
260 shared_ptr<SolutionArray> asArray(const double* soln) const override;
261};
262
263
264/**
265 * An outlet with specified composition.
266 * Flow is assumed to be from left to right.
267 */
269{
270public:
271 OutletRes1D();
272
273 OutletRes1D(shared_ptr<Solution> solution, const string& id="");
274
275 string type() const override {
276 return "outlet-reservoir";
277 }
278
279 void show(const double* x) override {}
280
281 size_t nSpecies() override {
282 return m_nsp;
283 }
284
285 void setMoleFractions(const string& xin) override;
286 void setMoleFractions(const double* xin) override;
287 double massFraction(size_t k) override {
288 return m_yres[k];
289 }
290
291 void init() override;
292 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
293 shared_ptr<SolutionArray> asArray(const double* soln) const override;
294 void fromArray(SolutionArray& arr, double* soln) override;
295
296protected:
297 size_t m_nsp = 0;
298 vector<double> m_yres;
299 string m_xstr;
300 StFlow* m_flow = nullptr;
301};
302
303/**
304 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
305 * transverse velocity (no slip). The temperature is specified, and a zero flux
306 * condition is imposed for the species.
307 */
308class Surf1D : public Boundary1D
309{
310public:
311 Surf1D() {
312 m_type = cSurfType;
313 }
314
315 Surf1D(shared_ptr<Solution> solution, const string& id="") : Surf1D() {
317 m_id = id;
318 }
319
320 string type() const override {
321 return "surface";
322 }
323
324 void init() override;
325
326 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
327
328 shared_ptr<SolutionArray> asArray(const double* soln) const override;
329 void fromArray(SolutionArray& arr, double* soln) override;
330
331 void show(std::ostream& s, const double* x) override;
332
333 void show(const double* x) override;
334};
335
336/**
337 * A reacting surface.
338 */
340{
341public:
343 ReactingSurf1D(shared_ptr<Solution> solution, const string& id="");
344
345 string type() const override {
346 return "reacting-surface";
347 }
348
349 void setKinetics(shared_ptr<Kinetics> kin) override;
350
351 //! @deprecated To be removed after %Cantera 3.0; replaced by setKinetics()
353
354 void enableCoverageEquations(bool docov) {
355 m_enabled = docov;
356 }
357
358 bool coverageEnabled() {
359 return m_enabled;
360 }
361
362 string componentName(size_t n) const override;
363
364 void init() override;
365 void resetBadValues(double* xg) override;
366
367 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
368
369 shared_ptr<SolutionArray> asArray(const double* soln) const override;
370 void fromArray(SolutionArray& arr, double* soln) override;
371
372 void _getInitialSoln(double* x) override {
373 m_sphase->getCoverages(x);
374 }
375
376 void _finalize(const double* x) override {
377 std::copy(x, x+m_nsp, m_fixed_cov.begin());
378 }
379
380 void show(const double* x) override;
381
382protected:
383 InterfaceKinetics* m_kin = nullptr;
384 SurfPhase* m_sphase = nullptr;
385 size_t m_surfindex = 0;
386 size_t m_nsp = 0;
387 bool m_enabled = false;
388 vector<double> m_work;
389 vector<double> m_fixed_cov;
390};
391
392//! @} End of bdryGroup
393
394}
395
396#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
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:48
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
virtual double spreadRate()
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:96
Base class for one-dimensional domains.
Definition Domain1D.h:41
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:609
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:400
string m_id
Identity tag for the domain.
Definition Domain1D.h:602
A terminator that does nothing.
Definition Boundary1D.h:184
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:195
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.
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:199
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:145
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:163
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
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.
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:252
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.
An outlet with specified composition.
Definition Boundary1D.h:269
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:275
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:287
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.
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:279
A reacting surface.
Definition Boundary1D.h:340
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...
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:345
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void setKineticsMgr(InterfaceKinetics *kin)
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:376
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.
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:372
A container class holding arrays of state information.
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:309
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:320
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.
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
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:224
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.
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564