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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::Reaction
29 
30 Description
31  Simple extension of ReactionThermo to handle reaction kinetics in addition
32  to the equilibrium thermodynamics already handled.
33 
34 SourceFiles
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"
47 #include "runTimeSelectionTables.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 // Forward Declarations
55 
56 template<class ThermoType>
58 
59 template<class ReactionThermo>
60 class Reaction;
61 
62 template<class ReactionThermo>
63 inline Ostream& operator<<(Ostream&, const Reaction<ReactionThermo>&);
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class Reaction Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 template<class ReactionThermo>
71 class Reaction
72 :
73  public ReactionThermo::thermoType
74 {
75 public:
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;
90  scalar stoichCoeff;
91  scalar exponent;
92 
93  specieCoeffs()
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
120  << sc.stoichCoeff << token::SPACE
121  << sc.exponent;
122  return os;
123  }
124  };
125 
126 
127 private:
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
138  List<specieCoeffs> lhs_;
139 
140  //- Specie info for the right-hand-side of the reaction
141  List<specieCoeffs> rhs_;
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 
159 protected:
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 
178 public:
179 
180  //- Runtime type information
181  TypeName("Reaction");
182 
183 
184  // Declare run-time constructor selection tables
185 
187  (
188  autoPtr,
189  Reaction,
190  dictionary,
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
203  Reaction
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
213  Reaction
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
223  Reaction
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
233  virtual autoPtr<Reaction<ReactionThermo>> clone() const
234  {
236  }
237 
238  //- Construct and return a clone with new speciesTable
239  virtual autoPtr<Reaction<ReactionThermo>> clone
240  (
241  const speciesTable& species
242  ) const
243  {
244  return autoPtr<Reaction<ReactionThermo>>::New(*this, species);
245  }
246 
247 
248  // Selectors
249 
250  //- Return a pointer to new patchField created on freestore from dict
251  static autoPtr<Reaction<ReactionThermo>> New
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&,
294  List<specieCoeffs>& lhs,
295  List<specieCoeffs>& rhs,
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;
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
335 
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 // ************************************************************************* //
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:401
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:389
dictionary dict
virtual const List< specieCoeffs > & grhs() const
Access to gas components of the reaction.
Definition: Reaction.C:443
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void write(Ostream &os) const
Write.
Definition: Reaction.C:380
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:349
bool operator==(const specieCoeffs &sc) const noexcept
Definition: Reaction.H:106
const speciesTable & species() const noexcept
Access to specie list.
Definition: Reaction.H:313
TypeName("Reaction")
Runtime type information.
virtual autoPtr< Reaction< ReactionThermo > > clone() const
Construct and return a clone.
Definition: Reaction.H:265
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:38
Hold specie index and its coefficients in the reaction rate expression.
Definition: Reaction.H:86
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:55
void reactionStrLeft(OStringStream &reaction) const
Add string representation of the left of the reaction.
Definition: Reaction.C:64
bool operator!=(const specieCoeffs &sc) const noexcept
Definition: Reaction.H:111
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Space [isspace].
Definition: token.H:131
virtual ~Reaction()=default
Destructor.
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const ReactionTable< ReactionThermo > &thermoDatabase, bool initReactionThermo=true)
Construct from components.
Definition: Reaction.C:150
const word & name() const noexcept
Name of reaction.
Definition: Reaction.H:308
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:434
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const ReactionTable< ReactionThermo > &thermoDatabase, const dictionary &dict),(species, thermoDatabase, dict))
OBJstream os(runTime.globalPath()/outputName)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
Definition: Reaction.C:425
void reactionStrRight(OStringStream &reaction) const
Add string representation of the right of the reaction.
Definition: Reaction.C:74
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:241
CombustionModel< rhoReactionThermo > & reaction
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
const dimensionedScalar c
Speed of light in a vacuum.
const List< specieCoeffs > & rhs() const noexcept
Specie info for the right-hand-side of the reaction.
Definition: Reaction.H:323
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Macros to ease declaration of run-time selection tables.
volScalarField & p
const List< specieCoeffs > & lhs() const noexcept
Specie info for the left-hand-side of the reaction.
Definition: Reaction.H:318
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:77
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:256
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:116
Namespace for OpenFOAM.