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-2021 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 Reaction_H
41 #define 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>
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  bool operator==(const specieCoeffs& sc) const
103  {
104  return index == sc.index;
105  }
106 
107  bool operator!=(const specieCoeffs& sc) const
108  {
109  return index != sc.index;
110  }
111 
112  friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
113  {
114  os << sc.index << token::SPACE
115  << sc.stoichCoeff << token::SPACE
116  << sc.exponent;
117  return os;
118  }
119  };
120 
121 
122 private:
123 
124  // Private Data
125 
126  //- Name of reaction
127  const word name_;
128 
129  //- List of specie names present in reaction system
130  const speciesTable& species_;
131 
132  //- Specie info for the left-hand-side of the reaction
133  List<specieCoeffs> lhs_;
134 
135  //- Specie info for the right-hand-side of the reaction
136  List<specieCoeffs> rhs_;
137 
138 
139  // Private Member Functions
140 
141  //- Return string representation of reaction
142  string reactionStr(OStringStream& reaction) const;
143 
144  //- Construct reaction thermo
145  void setThermo(const ReactionTable<ReactionThermo>& thermoDatabase);
146 
147  //- Return new reaction ID for un-named reactions
148  label getNewReactionID();
149 
150  //- No copy assignment
151  void operator=(const Reaction<ReactionThermo>&) = delete;
152 
153 
154 protected:
155 
156  // Protected Member Functions
157 
158  //- Return string representation of the left of the reaction
160 
161  //- Return string representation of the right of the reaction
163 
164 
165 public:
166 
167  //- Runtime type information
168  TypeName("Reaction");
169 
170 
171  // Declare run-time constructor selection tables
172 
174  (
175  autoPtr,
176  Reaction,
177  dictionary,
178  (
179  const speciesTable& species,
180  const ReactionTable<ReactionThermo>& thermoDatabase,
181  const dictionary& dict
182  ),
183  (species, thermoDatabase, dict)
184  );
185 
186 
187  // Constructors
188 
189  //- Construct from components
190  Reaction
191  (
192  const speciesTable& species,
193  const List<specieCoeffs>& lhs,
194  const List<specieCoeffs>& rhs,
195  const ReactionTable<ReactionThermo>& thermoDatabase,
196  bool initReactionThermo = true
197  );
198 
199  //- Construct as copy given new speciesTable
200  Reaction
201  (
203  const speciesTable& species
204  );
205 
206  //- Construct from dictionary
207  // NOTE: initReactionThermo is used by solidReaction where there is no
208  // need of setting a lhs - rhs thermo type for each reaction. This is
209  // needed for mechanism with reversible reactions
210  Reaction
211  (
212  const speciesTable& species,
213  const ReactionTable<ReactionThermo>& thermoDatabase,
214  const dictionary& dict,
215  bool initReactionThermo = true
216  );
217 
218  //- Construct and return a clone
219  virtual autoPtr<Reaction<ReactionThermo>> clone() const
220  {
222  }
223 
224  //- Construct and return a clone with new speciesTable
226  (
227  const speciesTable& species
228  ) const
229  {
231  }
232 
233 
234  // Selectors
235 
236  //- Return a pointer to new patchField created on freestore from dict
238  (
239  const speciesTable& species,
240  const ReactionTable<ReactionThermo>& thermoDatabase,
241  const dictionary& dict
242  );
243 
244 
245  //- Destructor
246  virtual ~Reaction() = default;
247 
248 
249  // Member Functions
250 
251  // Access
252 
253  //- Name of reaction
254  const word& name() const noexcept { return name_; }
255 
256  //- Access to specie list
257  const speciesTable& species() const noexcept { return species_; }
258 
259  //- Specie info for the left-hand-side of the reaction
260  const List<specieCoeffs>& lhs() const noexcept { return lhs_; }
261 
262  //- Specie info for the right-hand-side of the reaction
263  const List<specieCoeffs>& rhs() const noexcept { return rhs_; }
264 
265  //- Access to gas specie list
266  virtual const speciesTable& gasSpecies() const;
267 
268  //- Access to gas components of the reaction
269  virtual const List<specieCoeffs>& grhs() const;
270  virtual const List<specieCoeffs>& glhs() const;
271 
272 
273  // Manipulation
274 
275  //- Construct the left- and right-hand-side reaction coefficients
276  void setLRhs
277  (
278  Istream&,
279  const speciesTable&,
282  );
283 
284 
285  // Reaction rate coefficients
286 
287  //- Forward rate constant
288  virtual scalar kf
289  (
290  const scalar p,
291  const scalar T,
292  const scalarField& c
293  ) const;
294 
295  //- Reverse rate constant from the given forward rate constant
296  virtual scalar kr
297  (
298  const scalar kfwd,
299  const scalar p,
300  const scalar T,
301  const scalarField& c
302  ) const;
303 
304  //- Reverse rate constant.
305  // Note this evaluates the forward rate constant and divides by the
306  // equilibrium constant
307  virtual scalar kr
308  (
309  const scalar p,
310  const scalar T,
311  const scalarField& c
312  ) const;
313 
314 
315  //- Write
316  virtual void write(Ostream& os) const;
317 
318 
319  // Ostream Operator
320 
321  friend Ostream& operator<< <ReactionThermo>
322  (
323  Ostream&,
325  );
326 };
327 
328 
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 
331 } // End namespace Foam
332 
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
334 
335 #include "ReactionI.H"
336 
337 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 
339 #ifdef NoRepository
340  #include "Reaction.C"
341 #endif
342 
343 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 
345 #endif
346 
347 // ************************************************************************* //
Foam::Reaction::specieCoeffs::index
label index
Definition: Reaction.H:88
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::Reaction::setLRhs
void setLRhs(Istream &, const speciesTable &, List< specieCoeffs > &lhs, List< specieCoeffs > &rhs)
Construct the left- and right-hand-side reaction coefficients.
Definition: Reaction.C:240
typeInfo.H
scalarField.H
Foam::Reaction::rhs
const List< specieCoeffs > & rhs() const noexcept
Specie info for the right-hand-side of the reaction.
Definition: Reaction.H:262
Foam::Reaction::reactionStrLeft
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:42
Foam::Reaction::specieCoeffs
Definition: Reaction.H:86
speciesTable.H
Foam::Reaction::name
const word & name() const noexcept
Name of reaction.
Definition: Reaction.H:253
Foam::Reaction::specieCoeffs::exponent
scalar exponent
Definition: Reaction.H:90
Foam::Reaction::~Reaction
virtual ~Reaction()=default
Destructor.
Foam::Reaction::lhs
const List< specieCoeffs > & lhs() const noexcept
Specie info for the left-hand-side of the reaction.
Definition: Reaction.H:259
Foam::Reaction::gasSpecies
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
Definition: Reaction.C:430
Foam::Reaction::glhs
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:439
Foam::Reaction::specieCoeffs::operator!=
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:106
Foam::Reaction::kf
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:394
Foam::Reaction::reactionStrRight
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:67
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::Reaction::kr
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:406
Foam::Field< scalar >
Foam::hashedWordList
A wordList with hashed named lookup, which can be faster in some situations than using the normal lis...
Definition: hashedWordList.H:54
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Reaction::write
virtual void write(Ostream &os) const
Write.
Definition: Reaction.C:385
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::Reaction::TypeName
TypeName("Reaction")
Runtime type information.
Foam::Reaction::clone
virtual autoPtr< Reaction< ReactionThermo > > clone() const
Construct and return a clone.
Definition: Reaction.H:218
Foam::Reaction::nUnNamedReactions
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:79
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Reaction::species
const speciesTable & species() const noexcept
Access to specie list.
Definition: Reaction.H:256
reaction
CombustionModel< rhoReactionThermo > & reaction
Definition: setRegionFluidFields.H:3
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::Reaction::specieCoeffs::specieCoeffs
specieCoeffs()
Definition: Reaction.H:92
Foam::HashPtrTable< ThermoType >
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Reaction::specieCoeffs::stoichCoeff
scalar stoichCoeff
Definition: Reaction.H:89
Foam::Reaction::specieCoeffs::operator==
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:101
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
HashPtrTable.H
ReactionI.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Reaction::grhs
virtual const List< specieCoeffs > & grhs() const
Access to gas components of the reaction.
Definition: Reaction.C:448
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Reaction::Reaction
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:158
Foam::Reaction
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:59
Foam::Reaction::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const ReactionTable< ReactionThermo > &thermoDatabase, const dictionary &dict),(species, thermoDatabase, dict))
Foam::Reaction::New
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:354
Foam::Reaction::specieCoeffs::operator<<
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:111
Reaction.C