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 | Copyright (C) 2011-2017 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Reaction
26 
27 Description
28  Simple extension of ReactionThermo to handle reaction kinetics in addition
29  to the equilibrium thermodynamics already handled.
30 
31 SourceFiles
32  ReactionI.H
33  Reaction.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Reaction_H
38 #define Reaction_H
39 
40 #include "speciesTable.H"
41 #include "HashPtrTable.H"
42 #include "scalarField.H"
43 #include "typeInfo.H"
44 #include "runTimeSelectionTables.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 // Forward declaration of friend functions and operators
52 
53 template<class ReactionThermo>
54 class Reaction;
55 
56 template<class ReactionThermo>
57 inline Ostream& operator<<(Ostream&, const Reaction<ReactionThermo>&);
58 
59 
60 /*---------------------------------------------------------------------------*\
61  Class Reaction Declaration
62 \*---------------------------------------------------------------------------*/
63 
64 template<class ReactionThermo>
65 class Reaction
66 :
67  public ReactionThermo::thermoType
68 {
69 protected:
70 
71  // Protected member functions
72 
73  //- Return string representation of the left of the reaction
75 
76  //- Return string representation of the right of the reaction
78 
79 
80 public:
81 
82  // Static data
83 
84  //- Number of un-named reactions
85  static label nUnNamedReactions;
86 
87 
88  // Public data types
89 
90  //- Class to hold the specie index and its coefficients in the
91  // reaction rate expression
92  struct specieCoeffs
93  {
95  scalar stoichCoeff;
96  scalar exponent;
97 
98  specieCoeffs()
99  :
100  index(-1),
101  stoichCoeff(0),
102  exponent(1)
103  {}
104 
107  bool operator==(const specieCoeffs& sc) const
108  {
109  return index == sc.index;
110  }
112  bool operator!=(const specieCoeffs& sc) const
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 HashPtrTable<ReactionThermo>& thermoDatabase);
151 
152  //- Disallow default bitwise assignment
153  void operator=(const Reaction<ReactionThermo>&);
154 
155  //- Return new reaction ID for un-named reactions
156  label getNewReactionID();
157 
158 
159 public:
160 
161  //- Runtime type information
162  TypeName("Reaction");
163 
164 
165  // Declare run-time constructor selection tables
166 
168  (
169  autoPtr,
170  Reaction,
171  dictionary,
172  (
173  const speciesTable& species,
174  const HashPtrTable<ReactionThermo>& thermoDatabase,
175  const dictionary& dict
176  ),
177  (species, thermoDatabase, dict)
178  );
179 
180 
181  // Constructors
182 
183  //- Construct from components
184  Reaction
185  (
186  const speciesTable& species,
187  const List<specieCoeffs>& lhs,
188  const List<specieCoeffs>& rhs,
189  const HashPtrTable<ReactionThermo>& thermoDatabase
190  );
191 
192  //- Construct as copy given new speciesTable
193  Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
194 
195  //- Construct from dictionary
196  Reaction
197  (
198  const speciesTable& species,
199  const HashPtrTable<ReactionThermo>& thermoDatabase,
200  const dictionary& dict
201  );
202 
203  //- Construct and return a clone
204  virtual autoPtr<Reaction<ReactionThermo>> clone() const //
205  {
207  (
208  new Reaction<ReactionThermo>(*this)
209  );
210  }
211 
212  //- Construct and return a clone with new speciesTable
214  (
215  const speciesTable& species
216  ) const
217  {
219  (
221  );
222  }
223 
224 
225  // Selectors
226 
227  //- Return a pointer to new patchField created on freestore from dict
229  (
230  const speciesTable& species,
231  const HashPtrTable<ReactionThermo>& thermoDatabase,
232  const dictionary& dict
233  );
234 
235 
236  //- Destructor
237  virtual ~Reaction()
238  {}
239 
240 
241  // Member Functions
242 
243  // Access
244 
245  inline word& name();
246  inline const word& name() const;
247 
248  // - Access to basic components of the reaction
249  inline const List<specieCoeffs>& lhs() const;
250  inline const List<specieCoeffs>& rhs() const;
251 
252  // - Access to gas components of the reaction
253  virtual const List<specieCoeffs>& grhs() const;
254  virtual const List<specieCoeffs>& glhs() const;
255 
256  //- Access to specie list
257  const speciesTable& species() const;
258 
259  //- Access to gas specie list
260  virtual const speciesTable& gasSpecies() const;
261 
262  //- Construct the left- and right-hand-side reaction coefficients
263  void setLRhs
264  (
265  Istream&,
266  const speciesTable&,
267  List<specieCoeffs>& lhs,
268  List<specieCoeffs>& rhs
269  );
270 
271 
272  // Reaction rate coefficients
273 
274  //- Forward rate constant
275  virtual scalar kf
276  (
277  const scalar p,
278  const scalar T,
279  const scalarField& c
280  ) const;
281 
282  //- Reverse rate constant from the given forward rate constant
283  virtual scalar kr
284  (
285  const scalar kfwd,
286  const scalar p,
287  const scalar T,
288  const scalarField& c
289  ) const;
290 
291  //- Reverse rate constant.
292  // Note this evaluates the forward rate constant and divides by the
293  // equilibrium constant
294  virtual scalar kr
295  (
296  const scalar p,
297  const scalar T,
298  const scalarField& c
299  ) const;
300 
301 
302  //- Write
303  virtual void write(Ostream&) const;
304 
305 
306  // Ostream Operator
307 
308  friend Ostream& operator<< <ReactionThermo>
309  (
310  Ostream&,
312  );
313 };
314 
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 } // End namespace Foam
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #include "ReactionI.H"
323 
324 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
325 
326 #ifdef NoRepository
327  #include "Reaction.C"
328 #endif
329 
330 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 
332 #endif
333 
334 // ************************************************************************* //
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:404
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:392
dictionary dict
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
const List< specieCoeffs > & lhs() const
Definition: ReactionI.H:51
virtual ~Reaction()
Destructor.
Definition: Reaction.H:236
word & name()
Definition: ReactionI.H:36
virtual const List< specieCoeffs > & grhs() const
Definition: Reaction.C:453
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:382
TypeName("Reaction")
Runtime type information.
virtual autoPtr< Reaction< ReactionThermo > > clone() const
Construct and return a clone.
Definition: Reaction.H:203
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
Class to hold the specie index and its coefficients in the.
Definition: Reaction.H:91
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:53
const speciesTable & species() const
Access to specie list.
Definition: Reaction.C:428
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:38
A class for handling words, derived from string.
Definition: word.H:59
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:111
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:444
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual const speciesTable & gasSpecies() const
Access to gas specie list.
Definition: Reaction.C:435
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:63
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct from components.
Definition: Reaction.C:153
void setLRhs(Istream &, const speciesTable &, List< specieCoeffs > &lhs, List< specieCoeffs > &rhs)
Construct the left- and right-hand-side reaction coefficients.
Definition: Reaction.C:242
A wordList with hashed indices for faster lookup by name.
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:351
Info<< "Creating reaction model\"<< endl;autoPtr< combustionModels::psiCombustionModel > reaction(combustionModels::psiCombustionModel::New(mesh))
const dimensionedScalar c
Speed of light in a vacuum.
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, const dictionary &dict),(species, thermoDatabase, dict))
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Macros to ease declaration of run-time selection tables.
volScalarField & p
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:84
Output to memory buffer stream.
Definition: OStringStream.H:49
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:116
const List< specieCoeffs > & rhs() const
Definition: ReactionI.H:59
Namespace for OpenFOAM.
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:106