Cantera  3.2.0a5
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 void init() override;
175 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
176 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
177 void fromArray(const shared_ptr<SolutionArray>& arr) 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 phase Solution representing contents
203 //! @param id Name used to identify this domain
204 Empty1D(shared_ptr<Solution> phase, const string& id="") : Empty1D() {
206 m_solution->thermo()->addSpeciesLock();
207 m_id = id;
208 }
209
210 string domainType() const override {
211 return "empty";
212 }
213
214 void show(const double* x) override {}
215
216 void init() override;
217
218 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
219
220 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
221};
222
223/**
224 * A symmetry plane. The axial velocity u = 0, and all other components have
225 * zero axial gradients.
226 */
227class Symm1D : public Boundary1D
228{
229public:
230 //! Default constructor
231 Symm1D() = default;
232
233 //! Constructor with contents
234 //! @param phase Solution representing contents of adjacent flow domain
235 //! @param id Name used to identify this domain
236 Symm1D(shared_ptr<Solution> phase, const string& id="") : Symm1D() {
238 m_solution->thermo()->addSpeciesLock();
239 m_id = id;
240 }
241
242 string domainType() const override {
243 return "symmetry-plane";
244 }
245
246 void init() override;
247
248 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
249
250 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
251};
252
253
254/**
255 * An outlet.
256 * Flow is assumed to be from left to right.
257 */
258class Outlet1D : public Boundary1D
259{
260public:
261 //! Default constructor
262 Outlet1D() = default;
263
264 //! Constructor with contents
265 //! @param phase Solution representing contents of adjacent flow domain
266 //! @param id Name used to identify this domain
267 Outlet1D(shared_ptr<Solution> phase, const string& id="") : Outlet1D() {
269 m_solution->thermo()->addSpeciesLock();
270 m_id = id;
271 }
272
273 string domainType() const override {
274 return "outlet";
275 }
276
277 void init() override;
278
279 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
280
281 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
282};
283
284
285/**
286 * An outlet with specified composition.
287 * Flow is assumed to be from left to right.
288 */
290{
291public:
292 //! Default constructor
293 OutletRes1D();
294
295 //! Constructor with contents
296 //! @param phase Solution representing contents of adjacent flow domain
297 //! @param id Name used to identify this domain
298 OutletRes1D(shared_ptr<Solution> phase, const string& id="");
299
300 string domainType() const override {
301 return "outlet-reservoir";
302 }
303
304 void show(const double* x) override {}
305
306 size_t nSpecies() override {
307 return m_nsp;
308 }
309
310 void setMoleFractions(const string& xin) override;
311 void setMoleFractions(const double* xin) override;
312 double massFraction(size_t k) override {
313 return m_yres[k];
314 }
315
316 void init() override;
317 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
318 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
319 void fromArray(const shared_ptr<SolutionArray>& arr) override;
320
321protected:
322 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
323 vector<double> m_yres; //!< Mass fractions in the reservoir
324 string m_xstr; //!< Mole fractions in the reservoir
325 Flow1D* m_flow = nullptr; //!< The adjacent flow domain
326};
327
328/**
329 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
330 * transverse velocity (no slip). The temperature is specified, and a zero flux
331 * condition is imposed for the species.
332 */
333class Surf1D : public Boundary1D
334{
335public:
336 //! Default constructor
337 Surf1D() = default;
338
339 //! Constructor with contents
340 //! @param phase Solution representing contents of adjacent flow domain
341 //! @param id Name used to identify this domain
342 Surf1D(shared_ptr<Solution> phase, const string& id="") : Surf1D() {
344 m_solution->thermo()->addSpeciesLock();
345 m_id = id;
346 }
347
348 string domainType() const override {
349 return "surface";
350 }
351
352 void init() override;
353 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
354 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
355 void fromArray(const shared_ptr<SolutionArray>& arr) override;
356 void show(const double* x) override;
357};
358
359/**
360 * A reacting surface.
361 */
363{
364public:
365 //! Default constructor
367
368 //! Constructor with contents
369 //! @param phase Solution representing contents of adjacent flow domain
370 //! @param id Name used to identify this domain
371 ReactingSurf1D(shared_ptr<Solution> phase, const string& id="");
372
373 string domainType() const override {
374 return "reacting-surface";
375 }
376
377 void setKinetics(shared_ptr<Kinetics> kin) override;
378
379 //! Set whether to solve the equations for the surface species coverages
380 void enableCoverageEquations(bool docov) {
381 m_enabled = docov;
382 }
383
384 //! Indicates whether the equations for the surface species coverages are being
385 //! solved
387 return m_enabled;
388 }
389
390 string componentName(size_t n) const override;
391 size_t componentIndex(const string& name, bool checkAlias=true) const override;
392
393 void init() override;
394 void resetBadValues(double* xg) override;
395
396 void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
397
398 double value(const string& component) const override;
399 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
400 void fromArray(const shared_ptr<SolutionArray>& arr) 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
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:862
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:855
A terminator that does nothing.
Definition Boundary1D.h:196
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:204
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:210
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:214
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:187
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:181
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:188
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 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 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.
Outlet1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:267
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:273
Outlet1D()=default
Default constructor.
An outlet with specified composition.
Definition Boundary1D.h:290
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:324
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:312
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:323
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:306
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:322
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:325
string domainType() const override
Domain type flag.
Definition Boundary1D.h:300
void show(const double *x) override
Print the solution.
Definition Boundary1D.h:304
A reacting surface.
Definition Boundary1D.h:363
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...
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: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 > 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: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:380
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:386
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:373
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 non-reacting surface.
Definition Boundary1D.h:334
Surf1D()=default
Default constructor.
Surf1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:342
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:348
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:228
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:242
Symm1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:236
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