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-2014 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
74  void reactionStrLeft(OStringStream& reaction) const;
75 
76  //- Return string representation of the right of the reaction
77  void reactionStrRight(OStringStream& reaction) const;
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 
105  specieCoeffs(const speciesTable& species, Istream& is);
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  Istream,
172  (
173  const speciesTable& species,
174  const HashPtrTable<ReactionThermo>& thermoDatabase,
175  Istream& is
176  ),
177  (species, thermoDatabase, is)
178  );
179 
181  (
182  autoPtr,
183  Reaction,
184  dictionary,
185  (
186  const speciesTable& species,
187  const HashPtrTable<ReactionThermo>& thermoDatabase,
188  const dictionary& dict
189  ),
190  (species, thermoDatabase, dict)
191  );
192 
193 
194  // Public classes
195 
196  //- Class used for the read-construction of PtrLists of reaction
197  class iNew
198  {
199  const speciesTable& species_;
200  const HashPtrTable<ReactionThermo>& thermoDatabase_;
201 
202  public:
203 
205  (
206  const speciesTable& species,
207  const HashPtrTable<ReactionThermo>& thermoDatabase
208  )
209  :
210  species_(species),
211  thermoDatabase_(thermoDatabase)
212  {}
214  autoPtr<Reaction> operator()(Istream& is) const
215  {
216  return autoPtr<Reaction>
217  (
218  Reaction::New(species_, thermoDatabase_, is)
219  );
220  }
221  };
222 
223 
224  // Constructors
225 
226  //- Construct from components
227  Reaction
228  (
229  const speciesTable& species,
230  const List<specieCoeffs>& lhs,
231  const List<specieCoeffs>& rhs,
232  const HashPtrTable<ReactionThermo>& thermoDatabase
233  );
234 
235  //- Construct as copy given new speciesTable
236  Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
237 
238  //- Construct from Istream
239  Reaction
240  (
241  const speciesTable& species,
242  const HashPtrTable<ReactionThermo>& thermoDatabase,
243  Istream& is
244  );
245 
246  //- Construct from dictionary
247  Reaction
248  (
249  const speciesTable& species,
250  const HashPtrTable<ReactionThermo>& thermoDatabase,
251  const dictionary& dict
252  );
253 
254  //- Construct and return a clone
255  virtual autoPtr<Reaction<ReactionThermo> > clone() const //
256  {
258  (
259  new Reaction<ReactionThermo>(*this)
260  );
261  }
262 
263  //- Construct and return a clone with new speciesTable
265  (
266  const speciesTable& species
267  ) const
268  {
270  (
272  );
273  }
274 
275 
276  // Selectors
277 
278  //- Return a pointer to new patchField created on freestore from input
280  (
281  const speciesTable& species,
282  const HashPtrTable<ReactionThermo>& thermoDatabase,
283  Istream& is
284  );
285 
286  //- Return a pointer to new patchField created on freestore from dict
288  (
289  const speciesTable& species,
290  const HashPtrTable<ReactionThermo>& thermoDatabase,
291  const dictionary& dict
292  );
293 
294 
295  //- Destructor
296  virtual ~Reaction()
297  {}
298 
299 
300  // Member Functions
301 
302  // Access
303 
304  inline word& name();
305  inline const word& name() const;
306 
307  // - Access to basic components of the reaction
308  inline const List<specieCoeffs>& lhs() const;
309  inline const List<specieCoeffs>& rhs() const;
310 
311  // - Access to gas components of the reaction
312  virtual const List<specieCoeffs>& grhs() const;
313  virtual const List<specieCoeffs>& glhs() const;
314 
315  // - Access to specie list
316  const speciesTable& species() const;
317 
318  // - Access to gas specie list
319  virtual const speciesTable& gasSpecies() const;
320 
321  //- Construct the left- and right-hand-side reaction coefficients
322  void setLRhs
323  (
324  Istream&,
325  const speciesTable&,
326  List<specieCoeffs>& lhs,
327  List<specieCoeffs>& rhs
328  );
329 
330 
331  // Reaction rate coefficients
332 
333  //- Forward rate constant
334  virtual scalar kf
335  (
336  const scalar p,
337  const scalar T,
338  const scalarField& c
339  ) const;
340 
341  //- Reverse rate constant from the given forward rate constant
342  virtual scalar kr
343  (
344  const scalar kfwd,
345  const scalar p,
346  const scalar T,
347  const scalarField& c
348  ) const;
349 
350  //- Reverse rate constant.
351  // Note this evaluates the forward rate constant and divides by the
352  // equilibrium constant
353  virtual scalar kr
354  (
355  const scalar p,
356  const scalar T,
357  const scalarField& c
358  ) const;
359 
360 
361  //- Write
362  virtual void write(Ostream&) const;
363 
364 
365  // Ostream Operator
366 
367  friend Ostream& operator<< <ReactionThermo>
368  (
369  Ostream&,
371  );
372 };
373 
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 } // End namespace Foam
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #include "ReactionI.H"
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 #ifdef NoRepository
386 # include "Reaction.C"
387 #endif
388 
389 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
390 
391 #endif
392 
393 // ************************************************************************* //
virtual const List< specieCoeffs > & grhs() const
Definition: Reaction.C:525
const speciesTable & species() const
Definition: Reaction.C:492
TypeName("Reaction")
Runtime type information.
declareRunTimeSelectionTable(autoPtr, Reaction, Istream,( const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, Istream &is ),(species, thermoDatabase, is))
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:456
virtual autoPtr< Reaction< ReactionThermo > > clone() const
Construct and return a clone.
Definition: Reaction.H:254
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:106
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:38
Macros to ease declaration of run-time selection tables.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual const speciesTable & gasSpecies() const
Definition: Reaction.C:499
A class for handling words, derived from string.
Definition: word.H:59
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
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:116
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const List< specieCoeffs > & rhs() const
Definition: ReactionI.H:59
Namespace for OpenFOAM.
virtual ~Reaction()
Destructor.
Definition: Reaction.H:295
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:512
volScalarField & p
Definition: createFields.H:51
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:468
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:111
Output to memory buffer stream.
Definition: OStringStream.H:49
void setLRhs(Istream &, const speciesTable &, List< specieCoeffs > &lhs, List< specieCoeffs > &rhs)
Construct the left- and right-hand-side reaction coefficients.
Definition: Reaction.C:234
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:63
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:53
const List< specieCoeffs > & lhs() const
Definition: ReactionI.H:51
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:446
Class to hold the specie index and its coefficients in the.
Definition: Reaction.H:91
A wordList with hashed indices for faster lookup by name.
static autoPtr< Reaction< ReactionThermo > > New(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, Istream &is)
Return a pointer to new patchField created on freestore from input.
Definition: Reaction.C:360
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const dimensionedScalar c
Speed of light in a vacuum.
Class used for the read-construction of PtrLists of reaction.
Definition: Reaction.H:196
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct from components.
Definition: Reaction.C:145
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
word & name()
Definition: ReactionI.H:36
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:84