Cantera  3.2.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 "Flow1D.h"
17
18namespace Cantera
19{
20
21//! Unique identifier for the left inlet.
22const int LeftInlet = 1;
23
24//! Unique identifier for the right inlet.
25const int RightInlet = -1;
26
27//! @defgroup bdryGroup Boundaries
28//! Boundaries of one-dimensional flow domains.
29//! @ingroup onedGroup
30//! @{
31
32/**
33 * The base class for boundaries between one-dimensional spatial domains. The
34 * boundary may have its own internal variables, such as surface species
35 * coverages.
36 *
37 * The boundary types are an inlet, an outlet, a symmetry plane, and a surface.
38 *
39 * The public methods are all virtual, and the base class implementations throw
40 * exceptions.
41 */
42class Boundary1D : public Domain1D
43{
44public:
45 //! Default constructor
46 Boundary1D();
47
48 void init() override {
49 _init(1);
50 }
51
52 string domainType() const override {
53 return "boundary";
54 }
55
56 bool isConnector() override {
57 return true;
58 }
59
60 //! Set the temperature.
61 virtual void setTemperature(double t) {
62 m_temp = t;
63 }
64
65 //! Temperature [K].
66 virtual double temperature() {
67 return m_temp;
68 }
69
70 //! Get the number of species
71 virtual size_t nSpecies() {
72 return 0;
73 }
74
75 //! Set the mole fractions by specifying a string.
76 virtual void setMoleFractions(const string& xin) {
77 throw NotImplementedError("Boundary1D::setMoleFractions");
78 }
79
80 //! Set the mole fractions by specifying an array.
81 virtual void setMoleFractions(const double* xin) {
82 throw NotImplementedError("Boundary1D::setMoleFractions");
83 }
84
85 //! Mass fraction of species k.
86 virtual double massFraction(size_t k) {
87 throw NotImplementedError("Boundary1D::massFraction");
88 }
89
90 //! Set the total mass flow rate [kg/m²/s].
91 virtual void setMdot(double mdot) {
92 m_mdot = mdot;
93 }
94
95 //! Set tangential velocity gradient [1/s] at this boundary.
96 virtual void setSpreadRate(double V0) {
97 throw NotImplementedError("Boundary1D::setSpreadRate");
98 }
99
100 //! Tangential velocity gradient [1/s] at this boundary.
101 virtual double spreadRate() {
102 throw NotImplementedError("Boundary1D::spreadRate");
103 }
104
105 //! The total mass flow rate [kg/m2/s].
106 virtual double mdot() {
107 return m_mdot;
108 }
109
110 void setupGrid(size_t n, const double* z) override {}
111
112 void fromArray(const shared_ptr<SolutionArray>& arr) override;
113
114protected:
115 //! Initialize member variables based on the adjacent domains.
116 //! @param n Number of state variables associated with the boundary object
117 void _init(size_t n);
118
119 Flow1D* m_flow_left = nullptr; //!< Flow domain to the left of this boundary
120 Flow1D* m_flow_right = nullptr; //! Flow domain to the right of this boundary
121 size_t m_left_nv = 0; //!< Number of state vector components in left flow domain
122 size_t m_right_nv = 0; //!< Number of state vector components in right flow domain
123 size_t m_left_nsp = 0; //!< Number of species in left flow domain
124 size_t m_right_nsp = 0; //!< Number of species in right flow domain
125 ThermoPhase* m_phase_left = nullptr; //!< Thermo object used by left flow domain
126 ThermoPhase* m_phase_right = nullptr; //!< Thermo object used by right flow domain
127
128 //! Temperature of the boundary.
129 double m_temp = 0.0;
130 //! Mass flow rate at the boundary.
131 double m_mdot = 0.0;
132};
133
134
135/**
136 * An inlet.
137 * Unstrained flows use an inlet to the left of the flow domain (left-to-right flow).
138 * Strained flow configurations may have inlets on the either side of the flow domain.
139 */
140class Inlet1D : public Boundary1D
141{
142public:
143 //! Default constructor
144 Inlet1D();
145
146 //! Constructor with contents
147 //! @param phase Solution representing contents of adjacent flow domain
148 //! @param id Name used to identify this domain
149 Inlet1D(shared_ptr<Solution> phase, const string& id="");
150
151 string domainType() const override {
152 return "inlet";
153 }
154
155 void setSpreadRate(double V0) override;
156
157 double spreadRate() override {
158 return m_V0;
159 }
160
161 void setTemperature(double T) override;
162
163 void show(const double* x) override;
164
165 size_t nSpecies() override {
166 return m_nsp;
167 }
168
169 void setMoleFractions(const string& xin) override;
170 void setMoleFractions(const double* xin) override;
171 double massFraction(size_t k) override {
172 return m_yin[k];
173 }
174
175 void updateState(size_t loc) override;
176 void init() override;
177 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
178 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
179 void fromArray(const shared_ptr<SolutionArray>& arr) override;
180
181protected:
182 //! A marker that indicates whether this is a left inlet or a right inlet.
183 int m_ilr;
184
185 //! The spread rate of the inlet [1/s]
186 double m_V0 = 0.0;
187
188 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
189 vector<double> m_yin; //!< inlet mass fractions
190 string m_xstr; //!< inlet mass fractions. Parsing deferred to init()
191 Flow1D* m_flow = nullptr; //!< the adjacent flow domain
192};
193
194
195/**
196 * A terminator that does nothing.
197 */
198class Empty1D : public Boundary1D
199{
200public:
201 //! Default constructor
202 Empty1D() = default;
203
204 //! Constructor with contents
205 //! @param phase Solution representing contents
206 //! @param id Name used to identify this domain
207 Empty1D(shared_ptr<Solution> phase, const string& id="") : Empty1D() {
209 m_solution->thermo()->addSpeciesLock();
210 m_id = id;
211 }
212
213 string domainType() const override {
214 return "empty";
215 }
216
217 void show(const double* x) override {}
218
219 void init() override;
220
221 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
222
223 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
224};
225
226
227/**
228 * A symmetry plane. The axial velocity u = 0, and all other components have
229 * zero axial gradients.
230 */
231class Symm1D : public Boundary1D
232{
233public:
234 //! Default constructor
235 Symm1D() = default;
236
237 //! Constructor with contents
238 //! @param phase Solution representing contents of adjacent flow domain
239 //! @param id Name used to identify this domain
240 Symm1D(shared_ptr<Solution> phase, const string& id="") : Symm1D() {
242 m_solution->thermo()->addSpeciesLock();
243 m_id = id;
244 }
245
246 string domainType() const override {
247 return "symmetry-plane";
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> toArray(bool normalize=false) override;
255};
256
257
258/**
259 * An outlet.
260 * Flow is assumed to be from left to right.
261 */
262class Outlet1D : public Boundary1D
263{
264public:
265 //! Default constructor
266 Outlet1D() = default;
267
268 //! Constructor with contents
269 //! @param phase Solution representing contents of adjacent flow domain
270 //! @param id Name used to identify this domain
271 Outlet1D(shared_ptr<Solution> phase, const string& id="") : Outlet1D() {
273 m_solution->thermo()->addSpeciesLock();
274 m_id = id;
275 }
276
277 string domainType() const override {
278 return "outlet";
279 }
280
281 void init() override;
282
283 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
284
285 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
286};
287
288
289/**
290 * An outlet with specified composition.
291 * Flow is assumed to be from left to right.
292 */
294{
295public:
296 //! Default constructor
297 OutletRes1D();
298
299 //! Constructor with contents
300 //! @param phase Solution representing contents of adjacent flow domain
301 //! @param id Name used to identify this domain
302 OutletRes1D(shared_ptr<Solution> phase, const string& id="");
303
304 string domainType() const override {
305 return "outlet-reservoir";
306 }
307
308 void show(const double* x) override {}
309
310 size_t nSpecies() override {
311 return m_nsp;
312 }
313
314 void setMoleFractions(const string& xin) override;
315 void setMoleFractions(const double* xin) override;
316 double massFraction(size_t k) override {
317 return m_yres[k];
318 }
319
320 void init() override;
321 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
322 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
323 void fromArray(const shared_ptr<SolutionArray>& arr) override;
324
325protected:
326 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
327 vector<double> m_yres; //!< Mass fractions in the reservoir
328 string m_xstr; //!< Mole fractions in the reservoir
329 Flow1D* m_flow = nullptr; //!< The adjacent flow domain
330};
331
332
333/**
334 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
335 * transverse velocity (no slip). The temperature is specified, and a zero flux
336 * condition is imposed for the species.
337 */
338class Surf1D : public Boundary1D
339{
340public:
341 //! Default constructor
342 Surf1D() = default;
343
344 //! Constructor with contents
345 //! @param phase Solution representing contents of adjacent flow domain
346 //! @param id Name used to identify this domain
347 Surf1D(shared_ptr<Solution> phase, const string& id="") : Surf1D() {
349 m_solution->thermo()->addSpeciesLock();
350 m_id = id;
351 }
352
353 string domainType() const override {
354 return "surface";
355 }
356
357 void init() override;
358 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
359 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
360 void fromArray(const shared_ptr<SolutionArray>& arr) override;
361 void show(const double* x) override;
362};
363
364
365/**
366 * A reacting surface.
367 */
369{
370public:
371 //! Default constructor
373
374 //! Constructor with contents
375 //! @param phase Solution representing contents of adjacent flow domain
376 //! @param id Name used to identify this domain
377 ReactingSurf1D(shared_ptr<Solution> phase, const string& id="");
378
379 string domainType() const override {
380 return "reacting-surface";
381 }
382
383 void setKinetics(shared_ptr<Kinetics> kin) override;
384
385 //! Set whether to solve the equations for the surface species coverages
386 void enableCoverageEquations(bool docov) {
387 m_enabled = docov;
388 }
389
390 //! Indicates whether the equations for the surface species coverages are being
391 //! solved
393 return m_enabled;
394 }
395
396 string componentName(size_t n) const override;
397 size_t componentIndex(const string& name, bool checkAlias=true) const override;
398
399 void init() override;
400 void resetBadValues(double* xg) override;
401
402 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
403
404 double value(const string& component) const override;
405 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
406 void fromArray(const shared_ptr<SolutionArray>& arr) override;
407
408 void _getInitialSoln(double* x) override {
410 }
411
412 void _finalize(const double* x) override {
413 std::copy(x, x+m_nsp, m_fixed_cov.begin());
414 }
415
416 void show(const double* x) override;
417
418protected:
419 InterfaceKinetics* m_kin = nullptr; //!< surface kinetics mechanism
420 SurfPhase* m_sphase = nullptr; //!< phase representing the surface species
421 size_t m_nsp = 0; //!< the number of surface phase species
422 bool m_enabled = false; //!< True if coverage equations are being solved
423
424 //! temporary vector used to store coverages and production rates. Size is total
425 //! number of species in the kinetic mechanism
426 vector<double> m_work;
427
428 //! Fixed values of the coverages used when coverage equations are not being solved.
429 //! Length is #m_nsp.
430 vector<double> m_fixed_cov;
431};
432
433//! @} End of bdryGroup
434
435}
436
437#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:43
ThermoPhase * m_phase_left
Thermo object used by left flow domain.
Definition Boundary1D.h:125
bool isConnector() override
True if the domain is a connector domain.
Definition Boundary1D.h:56
double m_mdot
Mass flow rate at the boundary.
Definition Boundary1D.h:131
double m_temp
Temperature of the boundary.
Definition Boundary1D.h:129
virtual void setMdot(double mdot)
Set the total mass flow rate [kg/m²/s].
Definition Boundary1D.h:91
virtual void setMoleFractions(const string &xin)
Set the mole fractions by specifying a string.
Definition Boundary1D.h:76
virtual double temperature()
Temperature [K].
Definition Boundary1D.h:66
void _init(size_t n)
Initialize member variables based on the adjacent domains.
Flow1D * m_flow_left
Flow domain to the left of this boundary.
Definition Boundary1D.h:119
ThermoPhase * m_phase_right
Thermo object used by right flow domain.
Definition Boundary1D.h:126
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
size_t m_right_nsp
Number of species in right flow domain.
Definition Boundary1D.h:124
virtual void setTemperature(double t)
Set the temperature.
Definition Boundary1D.h:61
virtual void setMoleFractions(const double *xin)
Set the mole fractions by specifying an array.
Definition Boundary1D.h:81
void setupGrid(size_t n, const double *z) override
called to set up initial grid, and after grid refinement
Definition Boundary1D.h:110
virtual void setSpreadRate(double V0)
Set tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:96
virtual double mdot()
The total mass flow rate [kg/m2/s].
Definition Boundary1D.h:106
virtual double massFraction(size_t k)
Mass fraction of species k.
Definition Boundary1D.h:86
void init() override
Initialize.
Definition Boundary1D.h:48
size_t m_left_nsp
Number of species in left flow domain.
Definition Boundary1D.h:123
Boundary1D()
Default constructor.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:52
size_t m_right_nv
Number of state vector components in right flow domain.
Definition Boundary1D.h:122
size_t m_left_nv
Flow domain to the right of this boundary.
Definition Boundary1D.h:121
virtual size_t nSpecies()
Get the number of species.
Definition Boundary1D.h:71
virtual double spreadRate()
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:101
Base class for one-dimensional domains.
Definition Domain1D.h:29
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:864
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:718
shared_ptr< Solution > phase() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:641
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal
Definition Domain1D.h:731
string m_id
Identity tag for the domain.
Definition Domain1D.h:857
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector.
Definition Domain1D.h:657
A terminator that does nothing.
Definition Boundary1D.h:199
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
Empty1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:207
Empty1D()=default
Default constructor.
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:213
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:217
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition Flow1D.h:47
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
vector< double > m_yin
inlet mass fractions
Definition Boundary1D.h:189
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:183
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
string m_xstr
inlet mass fractions.
Definition Boundary1D.h:190
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:171
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:165
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void updateState(size_t loc) override
Update state at given location to state of associated Solution object.
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.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:188
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
Definition Boundary1D.h:191
double spreadRate() override
Tangential velocity gradient [1/s] at this boundary.
Definition Boundary1D.h:157
void setSpreadRate(double V0) override
set spreading rate
string domainType() const override
Domain type flag.
Definition Boundary1D.h:151
void show(const double *x) override
Print the solution.
double m_V0
The spread rate of the inlet [1/s].
Definition Boundary1D.h:186
Inlet1D()
Default constructor.
A kinetics manager for heterogeneous reaction mechanisms.
An error indicating that an unimplemented function has been called.
Outlet1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:271
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to 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:277
Outlet1D()=default
Default constructor.
An outlet with specified composition.
Definition Boundary1D.h:294
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
OutletRes1D()
Default constructor.
string m_xstr
Mole fractions in the reservoir.
Definition Boundary1D.h:328
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:316
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:327
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:310
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:326
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:329
string domainType() const override
Domain type flag.
Definition Boundary1D.h:304
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:308
A reacting surface.
Definition Boundary1D.h:369
SurfPhase * m_sphase
phase representing the surface species
Definition Boundary1D.h:420
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...
size_t componentIndex(const string &name, bool checkAlias=true) const override
Index of component with name name.
InterfaceKinetics * m_kin
surface kinetics mechanism
Definition Boundary1D.h:419
bool m_enabled
True if coverage equations are being solved.
Definition Boundary1D.h:422
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
Definition Boundary1D.h:430
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
Definition Boundary1D.h:426
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
double value(const string &component) const override
Set a single component value at a boundary.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from 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:412
size_t m_nsp
the number of surface phase species
Definition Boundary1D.h:421
void enableCoverageEquations(bool docov)
Set whether to solve the equations for the surface species coverages.
Definition Boundary1D.h:386
string componentName(size_t n) const override
Name of component n. May be overloaded.
bool coverageEnabled()
Indicates whether the equations for the surface species coverages are being solved.
Definition Boundary1D.h:392
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:379
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:408
A non-reacting surface.
Definition Boundary1D.h:339
Surf1D()=default
Default constructor.
Surf1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:347
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from 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:353
void show(const double *x) override
Print the solution.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:114
void getCoverages(double *theta) const
Return a vector of surface coverages.
A symmetry plane.
Definition Boundary1D.h:232
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
Symm1D()=default
Default constructor.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:246
Symm1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:240
Base class for a phase with thermodynamic properties.
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const int LeftInlet
Unique identifier for the left inlet.
Definition Boundary1D.h:22
const int RightInlet
Unique identifier for the right inlet.
Definition Boundary1D.h:25