Reaction.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::Reaction
29
30Description
31 Simple extension of ReactionThermo to handle reaction kinetics in addition
32 to the equilibrium thermodynamics already handled.
33
34SourceFiles
35 ReactionI.H
36 Reaction.C
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_Reaction_H
41#define Foam_Reaction_H
42
43#include "speciesTable.H"
44#include "HashPtrTable.H"
45#include "scalarField.H"
46#include "typeInfo.H"
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50
51namespace Foam
52{
53
54// Forward Declarations
55
56template<class ThermoType>
58
59template<class ReactionThermo>
60class Reaction;
61
62template<class ReactionThermo>
64
65
66/*---------------------------------------------------------------------------*\
67 Class Reaction Declaration
68\*---------------------------------------------------------------------------*/
69
70template<class ReactionThermo>
71class Reaction
72:
73 public ReactionThermo::thermoType
74{
75public:
76
77 // Static Data
78
79 //- Number of un-named reactions
80 static label nUnNamedReactions;
81
82
83 // Public Classes
84
85 //- Hold specie index and its coefficients in the
86 //- reaction rate expression
87 struct specieCoeffs
88 {
89 label index;
91 scalar exponent;
94 :
95 index(-1),
96 stoichCoeff(0),
97 exponent(1)
98 {}
99
101 (
102 const speciesTable& species,
103 Istream& is,
104 bool failUnknownSpecie = true
105 );
107 bool operator==(const specieCoeffs& sc) const noexcept
108 {
109 return index == sc.index;
110 }
112 bool operator!=(const specieCoeffs& sc) const noexcept
113 {
114 return index != sc.index;
115 }
117 friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
118 {
119 os << sc.index << token::SPACE
121 << sc.exponent;
122 return os;
123 }
124 };
125
126
127private:
128
129 // Private Data
130
131 //- Name of reaction
132 const word name_;
133
134 //- List of specie names present in reaction system
135 const speciesTable& species_;
136
137 //- Specie info for the left-hand-side of the reaction
139
140 //- Specie info for the right-hand-side of the reaction
142
143
144 // Private Member Functions
145
146 //- Return string representation of reaction
147 string reactionStr(OStringStream& reaction) const;
148
149 //- Construct reaction thermo
150 void setThermo(const ReactionTable<ReactionThermo>& thermoDatabase);
151
152 //- Return new reaction ID for un-named reactions
153 label getNewReactionID();
154
155 //- No copy assignment
156 void operator=(const Reaction<ReactionThermo>&) = delete;
157
158
159protected:
160
161 // Protected Member Functions
162
163 //- Add string representation for given species reaction coeffs
164 static void reactionStr
165 (
167 const speciesTable& species,
168 const List<specieCoeffs>& reactCoeffs
169 );
170
171 //- Add string representation of the left of the reaction
173
174 //- Add string representation of the right of the reaction
176
177
178public:
179
180 //- Runtime type information
181 TypeName("Reaction");
182
183
184 // Declare run-time constructor selection tables
187 (
188 autoPtr,
189 Reaction,
191 (
192 const speciesTable& species,
193 const ReactionTable<ReactionThermo>& thermoDatabase,
194 const dictionary& dict
195 ),
196 (species, thermoDatabase, dict)
197 );
198
199
200 // Constructors
201
202 //- Construct from components
204 (
205 const speciesTable& species,
206 const List<specieCoeffs>& lhs,
207 const List<specieCoeffs>& rhs,
208 const ReactionTable<ReactionThermo>& thermoDatabase,
209 bool initReactionThermo = true
210 );
211
212 //- Construct as copy given new speciesTable
214 (
216 const speciesTable& species
217 );
218
219 //- Construct from dictionary
220 // NOTE: initReactionThermo is used by solidReaction where there is no
221 // need of setting a lhs - rhs thermo type for each reaction. This is
222 // needed for mechanism with reversible reactions
224 (
225 const speciesTable& species,
226 const ReactionTable<ReactionThermo>& thermoDatabase,
227 const dictionary& dict,
228 bool initReactionThermo = true,
229 bool failUnknownSpecie = true
230 );
231
232 //- Construct and return a clone
234 {
236 }
237
238 //- Construct and return a clone with new speciesTable
240 (
241 const speciesTable& species
242 ) const
243 {
245 }
246
247
248 // Selectors
249
250 //- Return a pointer to new patchField created on freestore from dict
252 (
253 const speciesTable& species,
254 const ReactionTable<ReactionThermo>& thermoDatabase,
255 const dictionary& dict
256 );
257
258
259 //- Destructor
260 virtual ~Reaction() = default;
261
262
263 // Member Functions
264
265 // Access
266
267 //- Name of reaction
268 const word& name() const noexcept { return name_; }
269
270 //- Access to specie list
271 const speciesTable& species() const noexcept { return species_; }
272
273 //- Specie info for the left-hand-side of the reaction
274 const List<specieCoeffs>& lhs() const noexcept { return lhs_; }
275
276 //- Specie info for the right-hand-side of the reaction
277 const List<specieCoeffs>& rhs() const noexcept { return rhs_; }
278
279 //- Access to gas specie list
280 virtual const speciesTable& gasSpecies() const;
281
282 //- Access to gas components of the reaction
283 virtual const List<specieCoeffs>& grhs() const;
284 virtual const List<specieCoeffs>& glhs() const;
285
286
287 // Manipulation
288
289 //- Construct the left- and right-hand-side reaction coefficients
290 void setLRhs
291 (
292 Istream&,
293 const speciesTable&,
296 bool failUnknownSpecie = true
297 );
298
299
300 // Reaction rate coefficients
301
302 //- Forward rate constant
303 virtual scalar kf
304 (
305 const scalar p,
306 const scalar T,
307 const scalarField& c
308 ) const;
309
310 //- Reverse rate constant from the given forward rate constant
311 virtual scalar kr
312 (
313 const scalar kfwd,
314 const scalar p,
315 const scalar T,
316 const scalarField& c
317 ) const;
318
319 //- Reverse rate constant.
320 // Note this evaluates the forward rate constant and divides by the
321 // equilibrium constant
322 virtual scalar kr
323 (
324 const scalar p,
325 const scalar T,
326 const scalarField& c
327 ) const;
328
329
330 //- Write
331 virtual void write(Ostream& os) const;
332
333
334 // Ostream Operator
336 friend Ostream& operator<< <ReactionThermo>
337 (
338 Ostream&,
340 );
341};
342
343
344// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
345
346} // End namespace Foam
347
348// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
349
350#include "ReactionI.H"
351
352// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
353
354#ifdef NoRepository
355 #include "Reaction.C"
356#endif
357
358// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
359
360#endif
361
362// ************************************************************************* //
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:73
virtual scalar kr(const scalar kfwd, const scalar p, const scalar T, const scalarField &c) const
Reverse rate constant from the given forward rate constant.
Definition: Reaction.C:408
void setLRhs(Istream &, const speciesTable &, List< specieCoeffs > &lhs, List< specieCoeffs > &rhs, bool failUnknownSpecie=true)
Construct the left- and right-hand-side reaction coefficients.
Definition: Reaction.C:248
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:79
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:441
static autoPtr< Reaction< ReactionThermo > > New(const speciesTable &species, const ReactionTable< ReactionThermo > &thermoDatabase, const dictionary &dict)
Return a pointer to new patchField created on freestore from dict.
Definition: Reaction.C:356
TypeName("Reaction")
Runtime type information.
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const ReactionTable< ReactionThermo > &thermoDatabase, const dictionary &dict),(species, thermoDatabase, dict))
const word & name() const noexcept
Name of reaction.
Definition: Reaction.H:267
const List< specieCoeffs > & lhs() const noexcept
Specie info for the left-hand-side of the reaction.
Definition: Reaction.H:273
virtual ~Reaction()=default
Destructor.
virtual autoPtr< Reaction< ReactionThermo > > clone(const speciesTable &species) const
Construct and return a clone with new speciesTable.
Definition: Reaction.H:239
virtual autoPtr< Reaction< ReactionThermo > > clone() const
Construct and return a clone.
Definition: Reaction.H:232
void reactionStrLeft(OStringStream &reaction) const
Add string representation of the left of the reaction.
Definition: Reaction.C:71
const speciesTable & species() const noexcept
Access to specie list.
Definition: Reaction.H:270
virtual const List< specieCoeffs > & grhs() const
Access to gas components of the reaction.
Definition: Reaction.C:450
const List< specieCoeffs > & rhs() const noexcept
Specie info for the right-hand-side of the reaction.
Definition: Reaction.H:276
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:396
void reactionStrRight(OStringStream &reaction) const
Add string representation of the right of the reaction.
Definition: Reaction.C:81
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
Definition: Reaction.C:432
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
@ SPACE
Space [isspace].
Definition: token.H:125
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
CombustionModel< rhoReactionThermo > & reaction
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
const direction noexcept
Definition: Scalar.H:223
runTime write()
Macros to ease declaration of run-time selection tables.
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
dictionary dict
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:116
bool operator==(const specieCoeffs &sc) const noexcept
Definition: Reaction.H:106
bool operator!=(const specieCoeffs &sc) const noexcept
Definition: Reaction.H:111
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73