Cantera  3.1.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(SolutionArray& arr, double* soln) 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 solution Solution representing contents of adjacent flow domain
148 //! @param id Name used to identify this domain
149 Inlet1D(shared_ptr<Solution> solution, 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 void init() override;
175 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
176 shared_ptr<SolutionArray> asArray(const double* soln) const override;
177 void fromArray(SolutionArray& arr, double* soln) override;
178
179protected:
180 //! A marker that indicates whether this is a left inlet or a right inlet.
181 int m_ilr;
182
183 //! The spread rate of the inlet [1/s]
184 double m_V0 = 0.0;
185
186 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
187 vector<double> m_yin; //!< inlet mass fractions
188 string m_xstr; //!< inlet mass fractions. Parsing deferred to init()
189 Flow1D* m_flow = nullptr; //!< the adjacent flow domain
190};
191
192/**
193 * A terminator that does nothing.
194 */
195class Empty1D : public Boundary1D
196{
197public:
198 //! Default constructor
199 Empty1D() = default;
200
201 //! Constructor with contents
202 //! @param solution Solution representing contents
203 //! @param id Name used to identify this domain
204 Empty1D(shared_ptr<Solution> solution, const string& id="") : Empty1D() {
206 m_id = id;
207 }
208
209 string domainType() const override {
210 return "empty";
211 }
212
213 void show(const double* x) override {}
214
215 void init() override;
216
217 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
218
219 shared_ptr<SolutionArray> asArray(const double* soln) const override;
220};
221
222/**
223 * A symmetry plane. The axial velocity u = 0, and all other components have
224 * zero axial gradients.
225 */
226class Symm1D : public Boundary1D
227{
228public:
229 //! Default constructor
230 Symm1D() = default;
231
232 //! Constructor with contents
233 //! @param solution Solution representing contents of adjacent flow domain
234 //! @param id Name used to identify this domain
235 Symm1D(shared_ptr<Solution> solution, const string& id="") : Symm1D() {
237 m_id = id;
238 }
239
240 string domainType() const override {
241 return "symmetry-plane";
242 }
243
244 void init() override;
245
246 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
247
248 shared_ptr<SolutionArray> asArray(const double* soln) const override;
249};
250
251
252/**
253 * An outlet.
254 * Flow is assumed to be from left to right.
255 */
256class Outlet1D : public Boundary1D
257{
258public:
259 //! Default constructor
260 Outlet1D() = default;
261
262 //! Constructor with contents
263 //! @param solution Solution representing contents of adjacent flow domain
264 //! @param id Name used to identify this domain
265 Outlet1D(shared_ptr<Solution> solution, const string& id="") : Outlet1D() {
267 m_id = id;
268 }
269
270 string domainType() const override {
271 return "outlet";
272 }
273
274 void init() override;
275
276 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
277
278 shared_ptr<SolutionArray> asArray(const double* soln) const override;
279};
280
281
282/**
283 * An outlet with specified composition.
284 * Flow is assumed to be from left to right.
285 */
287{
288public:
289 //! Default constructor
290 OutletRes1D();
291
292 //! Constructor with contents
293 //! @param solution Solution representing contents of adjacent flow domain
294 //! @param id Name used to identify this domain
295 OutletRes1D(shared_ptr<Solution> solution, const string& id="");
296
297 string domainType() const override {
298 return "outlet-reservoir";
299 }
300
301 void show(const double* x) override {}
302
303 size_t nSpecies() override {
304 return m_nsp;
305 }
306
307 void setMoleFractions(const string& xin) override;
308 void setMoleFractions(const double* xin) override;
309 double massFraction(size_t k) override {
310 return m_yres[k];
311 }
312
313 void init() override;
314 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
315 shared_ptr<SolutionArray> asArray(const double* soln) const override;
316 void fromArray(SolutionArray& arr, double* soln) override;
317
318protected:
319 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
320 vector<double> m_yres; //!< Mass fractions in the reservoir
321 string m_xstr; //!< Mole fractions in the reservoir
322 Flow1D* m_flow = nullptr; //!< The adjacent flow domain
323};
324
325/**
326 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
327 * transverse velocity (no slip). The temperature is specified, and a zero flux
328 * condition is imposed for the species.
329 */
330class Surf1D : public Boundary1D
331{
332public:
333 //! Default constructor
334 Surf1D() = default;
335
336 //! Constructor with contents
337 //! @param solution Solution representing contents of adjacent flow domain
338 //! @param id Name used to identify this domain
339 Surf1D(shared_ptr<Solution> solution, const string& id="") : Surf1D() {
341 m_id = id;
342 }
343
344 string domainType() const override {
345 return "surface";
346 }
347
348 void init() override;
349
350 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
351
352 shared_ptr<SolutionArray> asArray(const double* soln) const override;
353 void fromArray(SolutionArray& arr, double* soln) override;
354
355 //! @deprecated To be removed after Cantera 3.1.
356 void show(std::ostream& s, const double* x) override;
357
358 void show(const double* x) override;
359};
360
361/**
362 * A reacting surface.
363 */
365{
366public:
367 //! Default constructor
369
370 //! Constructor with contents
371 //! @param solution Solution representing contents of adjacent flow domain
372 //! @param id Name used to identify this domain
373 ReactingSurf1D(shared_ptr<Solution> solution, const string& id="");
374
375 string domainType() const override {
376 return "reacting-surface";
377 }
378
379 void setKinetics(shared_ptr<Kinetics> kin) override;
380
381 //! Set whether to solve the equations for the surface species coverages
382 void enableCoverageEquations(bool docov) {
383 m_enabled = docov;
384 }
385
386 //! Indicates whether the equations for the surface species coverages are being
387 //! solved
389 return m_enabled;
390 }
391
392 string componentName(size_t n) const override;
393
394 void init() override;
395 void resetBadValues(double* xg) override;
396
397 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
398
399 shared_ptr<SolutionArray> asArray(const double* soln) const override;
400 void fromArray(SolutionArray& arr, double* soln) override;
401
402 void _getInitialSoln(double* x) override {
404 }
405
406 void _finalize(const double* x) override {
407 std::copy(x, x+m_nsp, m_fixed_cov.begin());
408 }
409
410 void show(const double* x) override;
411
412protected:
413 InterfaceKinetics* m_kin = nullptr; //!< surface kinetics mechanism
414 SurfPhase* m_sphase = nullptr; //!< phase representing the surface species
415 size_t m_nsp = 0; //!< the number of surface phase species
416 bool m_enabled = false; //!< True if coverage equations are being solved
417
418 //! temporary vector used to store coverages and production rates. Size is total
419 //! number of species in the kinetic mechanism
420 vector<double> m_work;
421
422 //! Fixed values of the coverages used when coverage equations are not being solved.
423 //! Length is #m_nsp.
424 vector<double> m_fixed_cov;
425};
426
427//! @} End of bdryGroup
428
429}
430
431#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
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
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: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 > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:402
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:479
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal
Definition Domain1D.h:499
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:617
A terminator that does nothing.
Definition Boundary1D.h:196
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
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.
Empty1D(shared_ptr< Solution > solution, const string &id="")
Constructor with contents.
Definition Boundary1D.h:204
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:209
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:213
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.
vector< double > m_yin
inlet mass fractions
Definition Boundary1D.h:187
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:181
string m_xstr
inlet mass fractions. Parsing deferred to init()
Definition Boundary1D.h:188
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:171
size_t nSpecies() override
Get the number of species.
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.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:186
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
Definition Boundary1D.h:189
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:184
Inlet1D()
Default constructor.
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.
Outlet1D(shared_ptr< Solution > solution, const string &id="")
Constructor with contents.
Definition Boundary1D.h:265
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:270
Outlet1D()=default
Default constructor.
An outlet with specified composition.
Definition Boundary1D.h:287
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
OutletRes1D()
Default constructor.
string m_xstr
Mole fractions in the reservoir.
Definition Boundary1D.h:321
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:309
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:320
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:303
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:319
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:322
string domainType() const override
Domain type flag.
Definition Boundary1D.h:297
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:301
A reacting surface.
Definition Boundary1D.h:365
SurfPhase * m_sphase
phase representing the surface species
Definition Boundary1D.h:414
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...
InterfaceKinetics * m_kin
surface kinetics mechanism
Definition Boundary1D.h:413
bool m_enabled
True if coverage equations are being solved.
Definition Boundary1D.h:416
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
Definition Boundary1D.h:424
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
Definition Boundary1D.h:420
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:406
size_t m_nsp
the number of surface phase species
Definition Boundary1D.h:415
void enableCoverageEquations(bool docov)
Set whether to solve the equations for the surface species coverages.
Definition Boundary1D.h:382
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 component n. May be overloaded.
bool coverageEnabled()
Indicates whether the equations for the surface species coverages are being solved.
Definition Boundary1D.h:388
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:375
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:402
A container class holding arrays of state information.
A non-reacting surface.
Definition Boundary1D.h:331
Surf1D()=default
Default constructor.
Surf1D(shared_ptr< Solution > solution, const string &id="")
Constructor with contents.
Definition Boundary1D.h:339
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:344
void show(std::ostream &s, const double *x) override
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:227
Symm1D(shared_ptr< Solution > solution, const string &id="")
Constructor with contents.
Definition Boundary1D.h:235
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.
Symm1D()=default
Default constructor.
void init() override
Initialize.
string domainType() const override
Domain type flag.
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