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 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 declaration of friend functions and operators
55 
56 template<class ReactionThermo>
57 class Reaction;
58 
59 template<class ReactionThermo>
61 
62 
63 /*---------------------------------------------------------------------------*\
64  Class Reaction Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class ReactionThermo>
68 class Reaction
69 :
70  public ReactionThermo::thermoType
71 {
72 protected:
73 
74  // Protected member functions
75 
76  //- Return string representation of the left of the reaction
78 
79  //- Return string representation of the right of the reaction
81 
82 
83 public:
84 
85  // Static data
86 
87  //- Number of un-named reactions
88  static label nUnNamedReactions;
89 
90 
91  // Public data types
92 
93  //- Class to hold the specie index and its coefficients in the
94  // reaction rate expression
95  struct specieCoeffs
96  {
97  label index;
98  scalar stoichCoeff;
99  scalar exponent;
100 
101  specieCoeffs()
102  :
103  index(-1),
104  stoichCoeff(0),
105  exponent(1)
106  {}
107 
109 
110  bool operator==(const specieCoeffs& sc) const
111  {
112  return index == sc.index;
113  }
114 
115  bool operator!=(const specieCoeffs& sc) const
116  {
117  return index != sc.index;
118  }
119 
120  friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
121  {
122  os << sc.index << token::SPACE
123  << sc.stoichCoeff << token::SPACE
124  << sc.exponent;
125  return os;
126  }
127  };
128 
129 
130 private:
131 
132  // Private data
133 
134  //- Name of reaction
135  const word name_;
136 
137  //- List of specie names present in reaction system
138  const speciesTable& species_;
139 
140  //- Specie info for the left-hand-side of the reaction
141  List<specieCoeffs> lhs_;
142 
143  //- Specie info for the right-hand-side of the reaction
144  List<specieCoeffs> rhs_;
145 
146 
147  // Private Member Functions
148 
149  //- Return string representation of reaction
150  string reactionStr(OStringStream& reaction) const;
151 
152  //- Construct reaction thermo
153  void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
154 
155  //- No copy assignment
156  void operator=(const Reaction<ReactionThermo>&) = delete;
157 
158  //- Return new reaction ID for un-named reactions
159  label getNewReactionID();
160 
161 
162 public:
163 
164  //- Runtime type information
165  TypeName("Reaction");
166 
167 
168  // Declare run-time constructor selection tables
169 
171  (
172  autoPtr,
173  Reaction,
174  dictionary,
175  (
176  const speciesTable& species,
177  const HashPtrTable<ReactionThermo>& thermoDatabase,
178  const dictionary& dict
179  ),
180  (species, thermoDatabase, dict)
181  );
182 
183 
184  // Constructors
185 
186  //- Construct from components
187  Reaction
188  (
189  const speciesTable& species,
190  const List<specieCoeffs>& lhs,
191  const List<specieCoeffs>& rhs,
192  const HashPtrTable<ReactionThermo>& thermoDatabase,
193  bool initReactionThermo = true
194  );
195 
196  //- Construct as copy given new speciesTable
197  Reaction
198  (
200  const speciesTable& species
201  );
202 
203  //- Construct from dictionary
204  // NOTE: initReactionThermo is used by solidReaction where there is no
205  // need of setting a lhs - rhs thermo type for each reaction. This is
206  // needed for mechanism with reversible reactions
207  Reaction
208  (
209  const speciesTable& species,
210  const HashPtrTable<ReactionThermo>& thermoDatabase,
211  const dictionary& dict,
212  bool initReactionThermo = true
213  );
214 
215  //- Construct and return a clone
216  virtual autoPtr<Reaction<ReactionThermo>> clone() const //
217  {
219  }
220 
221  //- Construct and return a clone with new speciesTable
223  (
224  const speciesTable& species
225  ) const
226  {
228  }
229 
230 
231  // Selectors
232 
233  //- Return a pointer to new patchField created on freestore from dict
235  (
236  const speciesTable& species,
237  const HashPtrTable<ReactionThermo>& thermoDatabase,
238  const dictionary& dict
239  );
240 
241 
242  //- Destructor
243  virtual ~Reaction() = default;
244 
245 
246  // Member Functions
247 
248  // Access
249 
250  inline const word& name() const;
251 
252  // - Access to basic components of the reaction
253  inline const List<specieCoeffs>& lhs() const;
254  inline const List<specieCoeffs>& rhs() const;
255 
256  // - Access to gas components of the reaction
257  virtual const List<specieCoeffs>& grhs() const;
258  virtual const List<specieCoeffs>& glhs() const;
259 
260  //- Access to specie list
261  const speciesTable& species() const;
262 
263  //- Access to gas specie list
264  virtual const speciesTable& gasSpecies() const;
265 
266  //- Construct the left- and right-hand-side reaction coefficients
267  void setLRhs
268  (
269  Istream&,
270  const speciesTable&,
273  );
274 
275 
276  // Reaction rate coefficients
277 
278  //- Forward rate constant
279  virtual scalar kf
280  (
281  const scalar p,
282  const scalar T,
283  const scalarField& c
284  ) const;
285 
286  //- Reverse rate constant from the given forward rate constant
287  virtual scalar kr
288  (
289  const scalar kfwd,
290  const scalar p,
291  const scalar T,
292  const scalarField& c
293  ) const;
294 
295  //- Reverse rate constant.
296  // Note this evaluates the forward rate constant and divides by the
297  // equilibrium constant
298  virtual scalar kr
299  (
300  const scalar p,
301  const scalar T,
302  const scalarField& c
303  ) const;
304 
305 
306  //- Write
307  virtual void write(Ostream&) const;
308 
309 
310  // Ostream Operator
311 
312  friend Ostream& operator<< <ReactionThermo>
313  (
314  Ostream&,
316  );
317 };
318 
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 } // End namespace Foam
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 #include "ReactionI.H"
327 
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
329 
330 #ifdef NoRepository
331  #include "Reaction.C"
332 #endif
333 
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335 
336 #endif
337 
338 // ************************************************************************* //
Foam::Reaction::specieCoeffs::index
label index
Definition: Reaction.H:96
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:239
typeInfo.H
scalarField.H
Foam::Reaction::species
const speciesTable & species() const
Access to specie list.
Definition: Reaction.C:429
Foam::Reaction::reactionStrLeft
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:41
Foam::Reaction::specieCoeffs
Class to hold the specie index and its coefficients in the.
Definition: Reaction.H:94
speciesTable.H
Foam::Reaction::specieCoeffs::exponent
scalar exponent
Definition: Reaction.H:98
Foam::Reaction::~Reaction
virtual ~Reaction()=default
Destructor.
Foam::Reaction::gasSpecies
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
Definition: Reaction.C:436
Foam::Reaction::glhs
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:445
Foam::Reaction::specieCoeffs::operator!=
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:114
Foam::Reaction::lhs
const List< specieCoeffs > & lhs() const
Definition: ReactionI.H:46
Foam::Reaction::kf
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:393
Foam::Reaction::reactionStrRight
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:66
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:405
Foam::Reaction::New
static autoPtr< Reaction< ReactionThermo > > New(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, const dictionary &dict)
Return a pointer to new patchField created on freestore from dict.
Definition: Reaction.C:353
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::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, const dictionary &dict),(species, thermoDatabase, dict))
Foam::Reaction::write
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:384
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:215
Foam::Reaction::nUnNamedReactions
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:87
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:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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:100
Foam::Reaction::rhs
const List< specieCoeffs > & rhs() const
Definition: ReactionI.H:54
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:54
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Reaction::specieCoeffs::stoichCoeff
scalar stoichCoeff
Definition: Reaction.H:97
Foam::Reaction::specieCoeffs::operator==
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:109
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.
Definition: StringStream.H:196
Foam::token::SPACE
Space [isspace].
Definition: token.H:117
HashPtrTable.H
ReactionI.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Reaction::name
const word & name() const
Definition: ReactionI.H:38
Foam::Reaction::grhs
virtual const List< specieCoeffs > & grhs() const
Definition: Reaction.C:454
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Reaction
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:56
Foam::Reaction::specieCoeffs::operator<<
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:119
Reaction.C
Foam::Reaction::Reaction
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase, bool initReactionThermo=true)
Construct from components.
Definition: Reaction.C:157