| 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"
14#include "cantera/thermo/SurfPhase.h"
15#include "cantera/kinetics/InterfaceKinetics.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 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
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 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
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() {
187 m_type = cEmptyType;
188 }
189
190 Empty1D(shared_ptr<Solution> solution, const string& id="") : Empty1D() {
191 m_solution = solution;
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 */
212 class Symm1D : public Boundary1D
213{
214 public:
215 Symm1D() {
216 m_type = cSymmType;
217 }
218
219 Symm1D(shared_ptr<Solution> solution, const string& id="") : Symm1D() {
220 m_solution = solution;
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 */
240 class Outlet1D : public Boundary1D
241{
242 public:
243 Outlet1D() {
244 m_type = cOutletType;
245 }
246
247 Outlet1D(shared_ptr<Solution> solution, const string& id="") : Outlet1D() {
248 m_solution = solution;
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 */
268 class OutletRes1D : public Boundary1D
269{
270 public:
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
296 protected:
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 */
308 class Surf1D : public Boundary1D
309{
310 public:
311 Surf1D() {
312 m_type = cSurfType;
313 }
314
315 Surf1D(shared_ptr<Solution> solution, const string& id="") : Surf1D() {
316 m_solution = solution;
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 */
339 class ReactingSurf1D : public Boundary1D
340{
341 public:
342 ReactingSurf1D();
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()
352 void setKineticsMgr(InterfaceKinetics* kin);
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
382 protected:
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
Domain1D.h
InterfaceKinetics.h
StFlow.h
SurfPhase.h
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Cantera::Boundary1D
The base class for boundaries between one-dimensional spatial domains.
Definition Boundary1D.h:40
Cantera::Boundary1D::isConnector
bool isConnector() override
True if the domain is a connector domain.
Definition Boundary1D.h:52
Cantera::Boundary1D::setMdot
virtual void setMdot(double mdot)
Set the total mass flow rate.
Definition Boundary1D.h:86
Cantera::Boundary1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:48
Cantera::Boundary1D::setMoleFractions
virtual void setMoleFractions(const string &xin)
Set the mole fractions by specifying a string.
Definition Boundary1D.h:71
Cantera::Boundary1D::temperature
virtual double temperature()
Temperature [K].
Definition Boundary1D.h:62
Cantera::Boundary1D::setTemperature
virtual void setTemperature(double t)
Set the temperature.
Definition Boundary1D.h:57
Cantera::Boundary1D::setMoleFractions
virtual void setMoleFractions(const double *xin)
Set the mole fractions by specifying an array.
Definition Boundary1D.h:76
Cantera::Boundary1D::setupGrid
void setupGrid(size_t n, const double *z) override
called to set up initial grid, and after grid refinement
Definition Boundary1D.h:105
Cantera::Boundary1D::fromArray
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Boundary1D.cpp:80
Cantera::Boundary1D::setSpreadRate
virtual void setSpreadRate(double V0)
Set tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:91
Cantera::Boundary1D::mdot
virtual double mdot()
The total mass flow rate [kg/m2/s].
Definition Boundary1D.h:101
Cantera::Boundary1D::massFraction
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition Boundary1D.h:81
Cantera::Boundary1D::init
void init() override
Initialize.
Definition Boundary1D.h:44
Cantera::Boundary1D::spreadRate
virtual double spreadRate()
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:96
Cantera::Domain1D
Base class for one-dimensional domains.
Definition Domain1D.h:41
Cantera::Domain1D::m_solution
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:609
Cantera::Domain1D::solution
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:400
Cantera::Domain1D::m_type
int m_type
Definition Domain1D.h:587
Cantera::Domain1D::m_id
string m_id
Identity tag for the domain.
Definition Domain1D.h:602
Cantera::Empty1D
A terminator that does nothing.
Definition Boundary1D.h:184
Cantera::Empty1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:195
Cantera::Empty1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:289
Cantera::Empty1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:284
Cantera::Empty1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:279
Cantera::Empty1D::show
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:199
Cantera::Inlet1D
An inlet.
Definition Boundary1D.h:139
Cantera::Inlet1D::setMoleFractions
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
Definition Boundary1D.cpp:124
Cantera::Inlet1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:145
Cantera::Inlet1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:243
Cantera::Inlet1D::massFraction
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:163
Cantera::Inlet1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:175
Cantera::Inlet1D::fromArray
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Boundary1D.cpp:260
Cantera::Inlet1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:143
Cantera::Inlet1D::spreadRate
double spreadRate() override
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:151
Cantera::Inlet1D::setSpreadRate
void setSpreadRate(double V0) override
set spreading rate
Definition Boundary1D.cpp:101
Cantera::Inlet1D::show
void show(const double *x) override
Print the solution.
Definition Boundary1D.cpp:108
Cantera::InterfaceKinetics
A kinetics manager for heterogeneous reaction mechanisms.
Definition InterfaceKinetics.h:56
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
Cantera::Outlet1D
An outlet.
Definition Boundary1D.h:241
Cantera::Outlet1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:252
Cantera::Outlet1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:409
Cantera::Outlet1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:376
Cantera::Outlet1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:361
Cantera::OutletRes1D
An outlet with specified composition.
Definition Boundary1D.h:269
Cantera::OutletRes1D::setMoleFractions
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
Definition Boundary1D.cpp:417
Cantera::OutletRes1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:275
Cantera::OutletRes1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:491
Cantera::OutletRes1D::massFraction
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:287
Cantera::OutletRes1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:459
Cantera::OutletRes1D::fromArray
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Boundary1D.cpp:508
Cantera::OutletRes1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:436
Cantera::OutletRes1D::show
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:279
Cantera::ReactingSurf1D
A reacting surface.
Definition Boundary1D.h:340
Cantera::ReactingSurf1D::setKinetics
void setKinetics(shared_ptr< Kinetics > kin) override
Set the kinetics manager.
Definition Boundary1D.cpp:609
Cantera::ReactingSurf1D::resetBadValues
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:656
Cantera::ReactingSurf1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:345
Cantera::ReactingSurf1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:746
Cantera::ReactingSurf1D::setKineticsMgr
void setKineticsMgr(InterfaceKinetics *kin)
Definition Boundary1D.cpp:622
Cantera::ReactingSurf1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:662
Cantera::ReactingSurf1D::_finalize
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
Cantera::ReactingSurf1D::fromArray
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Boundary1D.cpp:765
Cantera::ReactingSurf1D::componentName
string componentName(size_t n) const override
Name of the nth component. May be overloaded.
Definition Boundary1D.cpp:633
Cantera::ReactingSurf1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:642
Cantera::ReactingSurf1D::show
void show(const double *x) override
Print the solution.
Definition Boundary1D.cpp:778
Cantera::ReactingSurf1D::_getInitialSoln
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
Cantera::SolutionArray
A container class holding arrays of state information.
Definition SolutionArray.h:33
Cantera::StFlow
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition StFlow.h:45
Cantera::Surf1D
A non-reacting surface.
Definition Boundary1D.h:309
Cantera::Surf1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:320
Cantera::Surf1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:550
Cantera::Surf1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:525
Cantera::Surf1D::fromArray
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Boundary1D.cpp:557
Cantera::Surf1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:520
Cantera::Surf1D::show
void show(std::ostream &s, const double *x) override
Print the solution.
Definition Boundary1D.cpp:565
Cantera::SurfPhase
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:98
Cantera::SurfPhase::getCoverages
void getCoverages(double *theta) const
Return a vector of surface coverages.
Definition SurfPhase.cpp:257
Cantera::Symm1D
A symmetry plane.
Definition Boundary1D.h:213
Cantera::Symm1D::type
string type() const override
String indicating the domain implemented.
Definition Boundary1D.h:224
Cantera::Symm1D::asArray
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Boundary1D.cpp:341
Cantera::Symm1D::eval
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Definition Boundary1D.cpp:302
Cantera::Symm1D::init
void init() override
Initialize.
Definition Boundary1D.cpp:297
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564