Cantera  4.0.0a1
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(span<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(span<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(span<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(span<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, span<const double> xg, span<double> rg, span<int> diagg,
178 double rdt) override;
179 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
180 void fromArray(const shared_ptr<SolutionArray>& arr) override;
181
182protected:
183 //! A marker that indicates whether this is a left inlet or a right inlet.
184 int m_ilr;
185
186 //! The spread rate of the inlet [1/s]
187 double m_V0 = 0.0;
188
189 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
190 vector<double> m_yin; //!< inlet mass fractions
191 string m_xstr; //!< inlet mass fractions. Parsing deferred to init()
192 Flow1D* m_flow = nullptr; //!< the adjacent flow domain
193};
194
195
196/**
197 * A terminator that does nothing.
198 */
199class Empty1D : public Boundary1D
200{
201public:
202 //! Default constructor
203 Empty1D() = default;
204
205 //! Constructor with contents
206 //! @param phase Solution representing contents
207 //! @param id Name used to identify this domain
208 Empty1D(shared_ptr<Solution> phase, const string& id="") : Empty1D() {
210 m_solution->thermo()->addSpeciesLock();
211 m_id = id;
212 }
213
214 string domainType() const override {
215 return "empty";
216 }
217
218 void show(span<const double> x) override {}
219
220 void init() override;
221
222 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
223 double rdt) override;
224
225 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
226};
227
228
229/**
230 * A symmetry plane. The axial velocity u = 0, and all other components have
231 * zero axial gradients.
232 */
233class Symm1D : public Boundary1D
234{
235public:
236 //! Default constructor
237 Symm1D() = default;
238
239 //! Constructor with contents
240 //! @param phase Solution representing contents of adjacent flow domain
241 //! @param id Name used to identify this domain
242 Symm1D(shared_ptr<Solution> phase, const string& id="") : Symm1D() {
244 m_solution->thermo()->addSpeciesLock();
245 m_id = id;
246 }
247
248 string domainType() const override {
249 return "symmetry-plane";
250 }
251
252 void init() override;
253
254 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
255 double rdt) override;
256
257 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
258};
259
260
261/**
262 * An outlet.
263 * Flow is assumed to be from left to right.
264 */
265class Outlet1D : public Boundary1D
266{
267public:
268 //! Default constructor
269 Outlet1D() = default;
270
271 //! Constructor with contents
272 //! @param phase Solution representing contents of adjacent flow domain
273 //! @param id Name used to identify this domain
274 Outlet1D(shared_ptr<Solution> phase, const string& id="") : Outlet1D() {
276 m_solution->thermo()->addSpeciesLock();
277 m_id = id;
278 }
279
280 string domainType() const override {
281 return "outlet";
282 }
283
284 void init() override;
285
286 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
287 double rdt) override;
288
289 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
290};
291
292
293/**
294 * An outlet with specified composition.
295 * Flow is assumed to be from left to right.
296 */
298{
299public:
300 //! Default constructor
301 OutletRes1D();
302
303 //! Constructor with contents
304 //! @param phase Solution representing contents of adjacent flow domain
305 //! @param id Name used to identify this domain
306 OutletRes1D(shared_ptr<Solution> phase, const string& id="");
307
308 string domainType() const override {
309 return "outlet-reservoir";
310 }
311
312 void show(span<const double> x) override {}
313
314 size_t nSpecies() override {
315 return m_nsp;
316 }
317
318 void setMoleFractions(const string& xin) override;
319 void setMoleFractions(span<const double> xin) override;
320 double massFraction(size_t k) override {
321 return m_yres[k];
322 }
323
324 void init() override;
325 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
326 double rdt) override;
327 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
328 void fromArray(const shared_ptr<SolutionArray>& arr) override;
329
330protected:
331 size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
332 vector<double> m_yres; //!< Mass fractions in the reservoir
333 string m_xstr; //!< Mole fractions in the reservoir
334 Flow1D* m_flow = nullptr; //!< The adjacent flow domain
335};
336
337
338/**
339 * A non-reacting surface. The axial velocity is zero (impermeable), as is the
340 * transverse velocity (no slip). The temperature is specified, and a zero flux
341 * condition is imposed for the species.
342 */
343class Surf1D : public Boundary1D
344{
345public:
346 //! Default constructor
347 Surf1D() = default;
348
349 //! Constructor with contents
350 //! @param phase Solution representing contents of adjacent flow domain
351 //! @param id Name used to identify this domain
352 Surf1D(shared_ptr<Solution> phase, const string& id="") : Surf1D() {
354 m_solution->thermo()->addSpeciesLock();
355 m_id = id;
356 }
357
358 string domainType() const override {
359 return "surface";
360 }
361
362 void init() override;
363 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
364 double rdt) override;
365 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
366 void fromArray(const shared_ptr<SolutionArray>& arr) override;
367 void show(span<const double> x) override;
368};
369
370
371/**
372 * A reacting surface.
373 */
375{
376public:
377 //! Default constructor
379
380 //! Constructor with contents
381 //! @param phase Solution representing contents of adjacent flow domain
382 //! @param id Name used to identify this domain
383 ReactingSurf1D(shared_ptr<Solution> phase, const string& id="");
384
385 string domainType() const override {
386 return "reacting-surface";
387 }
388
389 //! Set whether to solve the equations for the surface species coverages
390 void enableCoverageEquations(bool docov) {
391 m_enabled = docov;
392 }
393
394 //! Indicates whether the equations for the surface species coverages are being
395 //! solved
397 return m_enabled;
398 }
399
400 string componentName(size_t n) const override;
401 size_t componentIndex(const string& name, bool checkAlias=true) const override;
402
403 void init() override;
404 void resetBadValues(span<double> xg) override;
405
406 void eval(size_t jg, span<const double> xg, span<double> rg, span<int> diagg,
407 double rdt) override;
408
409 double value(const string& component) const override;
410 shared_ptr<SolutionArray> toArray(bool normalize=false) override;
411 void fromArray(const shared_ptr<SolutionArray>& arr) override;
412
413 void _getInitialSoln(span<double> x) override {
415 }
416
417 void _finalize(span<const double> x) override {
418 std::copy(x.begin(), x.end(), m_fixed_cov.begin());
419 }
420
421 void show(span<const double> x) override;
422
423protected:
424 InterfaceKinetics* m_kin = nullptr; //!< surface kinetics mechanism
425 SurfPhase* m_sphase = nullptr; //!< phase representing the surface species
426 size_t m_nsp = 0; //!< the number of surface phase species
427 bool m_enabled = false; //!< True if coverage equations are being solved
428
429 //! temporary vector used to store coverages and production rates. Size is total
430 //! number of species in the kinetic mechanism
431 vector<double> m_work;
432
433 //! Fixed values of the coverages used when coverage equations are not being solved.
434 //! Length is #m_nsp.
435 vector<double> m_fixed_cov;
436};
437
438//! @} End of bdryGroup
439
440}
441
442#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
void setupGrid(span< const double > z) override
Set up initial grid.
Definition Boundary1D.h:110
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 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
virtual void setMoleFractions(span< const double > xin)
Set the mole fractions by specifying an array.
Definition Boundary1D.h:81
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:713
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:577
shared_ptr< Solution > phase() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:506
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal
Definition Domain1D.h:590
string m_id
Identity tag for the domain.
Definition Domain1D.h:706
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:522
A terminator that does nothing.
Definition Boundary1D.h:200
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:208
Empty1D()=default
Default constructor.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
Definition Boundary1D.h:218
void init() override
Initialize.
string domainType() const override
Domain type flag.
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:190
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:184
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:191
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, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:189
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
Definition Boundary1D.h:192
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
double m_V0
The spread rate of the inlet [1/s].
Definition Boundary1D.h:187
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:274
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > 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:280
Outlet1D()=default
Default constructor.
An outlet with specified composition.
Definition Boundary1D.h:298
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:333
double massFraction(size_t k) override
Mass fraction of species k.
Definition Boundary1D.h:320
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:332
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:314
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
Definition Boundary1D.h:312
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:331
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:334
string domainType() const override
Domain type flag.
Definition Boundary1D.h:308
A reacting surface.
Definition Boundary1D.h:375
SurfPhase * m_sphase
phase representing the surface species
Definition Boundary1D.h:425
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:424
bool m_enabled
True if coverage equations are being solved.
Definition Boundary1D.h:427
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
Definition Boundary1D.h:435
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
Definition Boundary1D.h:431
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, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
size_t m_nsp
the number of surface phase species
Definition Boundary1D.h:426
void enableCoverageEquations(bool docov)
Set whether to solve the equations for the surface species coverages.
Definition Boundary1D.h:390
void _finalize(span< const double > x) override
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition Boundary1D.h:417
void resetBadValues(span< double > xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
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:396
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:385
void _getInitialSoln(span< double > x) override
Writes some or all initial solution values into the global solution array, beginning at the location ...
Definition Boundary1D.h:413
A non-reacting surface.
Definition Boundary1D.h:344
Surf1D()=default
Default constructor.
Surf1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:352
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, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
void init() override
Initialize.
string domainType() const override
Domain type flag.
Definition Boundary1D.h:358
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition SurfPhase.h:114
void getCoverages(span< double > theta) const
Return a vector of surface coverages.
A symmetry plane.
Definition Boundary1D.h:234
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > 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:248
Symm1D(shared_ptr< Solution > phase, const string &id="")
Constructor with contents.
Definition Boundary1D.h:242
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