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>
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 
106 
107  bool operator==(const specieCoeffs& sc) const
108  {
109  return index == sc.index;
110  }
111 
112  bool operator!=(const specieCoeffs& sc) const
113  {
114  return index != sc.index;
115  }
116 
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
139 
140  //- Specie info for the right-hand-side of the reaction
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
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  {
201 
202  public:
203 
205  (
206  const speciesTable& species,
207  const HashPtrTable<ReactionThermo>& thermoDatabase
208  )
209  :
210  species_(species),
211  thermoDatabase_(thermoDatabase)
212  {}
213 
215  {
216  return autoPtr<Reaction>
217  (
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
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&,
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 // ************************************************************************* //
Foam::Reaction::specieCoeffs::index
label index
Definition: Reaction.H:93
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::Reaction::Reaction
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct from components.
Definition: Reaction.C:145
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:234
typeInfo.H
scalarField.H
Foam::Reaction::species
const speciesTable & species() const
Definition: Reaction.C:481
Foam::Reaction::reactionStrLeft
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:38
Foam::Reaction::name_
const word name_
Name of reaction.
Definition: Reaction.H:131
Foam::Reaction::setThermo
void setThermo(const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct reaction thermo.
Definition: Reaction.C:110
Foam::Reaction::specieCoeffs
Class to hold the specie index and its coefficients in the.
Definition: Reaction.H:91
Foam::Reaction::getNewReactionID
label getNewReactionID()
Return new reaction ID for un-named reactions.
Definition: Reaction.C:89
speciesTable.H
Foam::Reaction::specieCoeffs::exponent
scalar exponent
Definition: Reaction.H:95
Foam::Reaction::reactionStr
string reactionStr(OStringStream &reaction) const
Return string representation of reaction.
Definition: Reaction.C:97
Foam::Reaction::iNew::operator()
autoPtr< Reaction > operator()(Istream &is) const
Definition: Reaction.H:213
Foam::Reaction::gasSpecies
virtual const speciesTable & gasSpecies() const
Definition: Reaction.C:488
Foam::Reaction::New
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
Foam::Reaction::glhs
virtual const List< specieCoeffs > & glhs() const
Definition: Reaction.C:497
Foam::Reaction::iNew::iNew
iNew(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase)
Definition: Reaction.H:204
Foam::Reaction::specieCoeffs::operator!=
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:111
Foam::Reaction::lhs
const List< specieCoeffs > & lhs() const
Definition: ReactionI.H:51
Foam::Reaction::kf
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const
Forward rate constant.
Definition: Reaction.C:445
Foam::Reaction::reactionStrRight
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:63
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:457
Foam::Reaction::iNew
Class used for the read-construction of PtrLists of reaction.
Definition: Reaction.H:196
Foam::label
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
Foam::Reaction::declareRunTimeSelectionTable
declareRunTimeSelectionTable(autoPtr, Reaction, Istream,(const speciesTable &species, const HashPtrTable< ReactionThermo > &thermoDatabase, Istream &is),(species, thermoDatabase, is))
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::hashedWordList
A wordList with hashed indices for faster lookup by name.
Definition: hashedWordList.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Reaction::~Reaction
virtual ~Reaction()
Destructor.
Definition: Reaction.H:295
Foam::Reaction::write
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:435
Foam::Reaction::name
word & name()
Definition: ReactionI.H:36
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
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:254
Foam::Reaction::nUnNamedReactions
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:84
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Reaction::species_
const speciesTable & species_
List of specie names present in reaction system.
Definition: Reaction.H:134
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::Reaction::operator=
void operator=(const Reaction< ReactionThermo > &)
Disallow default bitwise assignment.
Foam::Reaction::rhs_
List< specieCoeffs > rhs_
Specie info for the right-hand-side of the reaction.
Definition: Reaction.H:140
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
reaction
Info<< "Creating reaction model\n"<< endl;autoPtr< combustionModels::psiCombustionModel > reaction(combustionModels::psiCombustionModel::New(mesh))
Foam::Reaction::iNew::species_
const speciesTable & species_
Definition: Reaction.H:198
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
Foam::Reaction::specieCoeffs::specieCoeffs
specieCoeffs()
Definition: Reaction.H:97
Foam::Reaction::rhs
const List< specieCoeffs > & rhs() const
Definition: ReactionI.H:59
Foam::HashPtrTable< ReactionThermo >
runTimeSelectionTables.H
Macros to ease declaration of run-time selection tables.
Foam::Reaction::specieCoeffs::stoichCoeff
scalar stoichCoeff
Definition: Reaction.H:94
Foam::Reaction::specieCoeffs::operator==
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:106
Foam::List
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
Foam::OStringStream
Output to memory buffer stream.
Definition: OStringStream.H:49
HashPtrTable.H
Foam::Reaction::lhs_
List< specieCoeffs > lhs_
Specie info for the left-hand-side of the reaction.
Definition: Reaction.H:137
ReactionI.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Reaction::grhs
virtual const List< specieCoeffs > & grhs() const
Definition: Reaction.C:506
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::Reaction
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:53
Foam::Reaction::specieCoeffs::operator<<
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:116
Reaction.C
Foam::Reaction::iNew::thermoDatabase_
const HashPtrTable< ReactionThermo > & thermoDatabase_
Definition: Reaction.H:199
Foam::token::SPACE
@ SPACE
Definition: token.H:95