Reaction.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 "simpleMatrix.H"
44 #include "Tuple2.H"
45 #include "typeInfo.H"
46 #include "runTimeSelectionTables.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 // Forward declaration of friend functions and operators
54 
55 template<class ReactionThermo>
56 class Reaction;
57 
58 template<class ReactionThermo>
59 inline Ostream& operator<<(Ostream&, const Reaction<ReactionThermo>&);
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class Reaction Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class ReactionThermo>
67 class Reaction
68 :
69  public ReactionThermo::thermoType
70 {
71 protected:
72 
73  // Protected member functions
74 
75  //- Return string representation of the left of the reaction
77 
78  //- Return string representation of the right of the reaction
80 
81 
82 public:
83 
84  // Static data
85 
86  //- Number of un-named reactions
87  static label nUnNamedReactions;
88 
89  //- Default temperature limits of applicability of reaction rates
90  static scalar TlowDefault, ThighDefault;
91 
92  // Public data types
93 
94  //- Class to hold the specie index and its coefficients in the
95  // reaction rate expression
96  struct specieCoeffs
97  {
99  scalar stoichCoeff;
100  scalar exponent;
102  specieCoeffs()
103  :
104  index(-1),
105  stoichCoeff(0),
106  exponent(1)
107  {}
108 
111  bool operator==(const specieCoeffs& sc) const
112  {
113  return index == sc.index;
114  }
116  bool operator!=(const specieCoeffs& sc) const
117  {
118  return index != sc.index;
119  }
121  friend Ostream& operator<<(Ostream& os, const specieCoeffs& sc)
122  {
123  os << sc.index << token::SPACE
124  << sc.stoichCoeff << token::SPACE
125  << sc.exponent;
126  return os;
127  }
128  };
129 
130 
131 private:
132 
133  // Private data
134 
135  //- Name of reaction
136  const word name_;
137 
138  //- List of specie names present in reaction system
139  const speciesTable& species_;
140 
141  //- Temperature limits of applicability of reaction rates
142  scalar Tlow_, Thigh_;
143 
144  //- Specie info for the left-hand-side of the reaction
145  List<specieCoeffs> lhs_;
146 
147  //- Specie info for the right-hand-side of the reaction
148  List<specieCoeffs> rhs_;
149 
150 
151  // Private Member Functions
152 
153  //- Return string representation of reaction
154  string reactionStr(OStringStream& reaction) const;
155 
156  //- Construct reaction thermo
157  void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
158 
159  //- Disallow default bitwise assignment
160  void operator=(const Reaction<ReactionThermo>&);
161 
162  //- Return new reaction ID for un-named reactions
163  label getNewReactionID();
164 
165 
166 public:
167 
168  //- Runtime type information
169  TypeName("Reaction");
170 
171 
172  // Declare run-time constructor selection tables
173 
175  (
176  autoPtr,
177  Reaction,
178  dictionary,
179  (
180  const speciesTable& species,
181  const HashPtrTable<ReactionThermo>& thermoDatabase,
182  const dictionary& dict
183  ),
184  (species, thermoDatabase, dict)
185  );
186 
187 
188  // Constructors
189 
190  //- Construct from components
191  Reaction
192  (
193  const speciesTable& species,
194  const List<specieCoeffs>& lhs,
195  const List<specieCoeffs>& rhs,
196  const HashPtrTable<ReactionThermo>& thermoDatabase
197  );
198 
199  //- Construct as copy given new speciesTable
200  Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
201 
202  //- Construct from dictionary
203  Reaction
204  (
205  const speciesTable& species,
206  const HashPtrTable<ReactionThermo>& thermoDatabase,
207  const dictionary& dict
208  );
209 
210  //- Construct and return a clone
211  virtual autoPtr<Reaction<ReactionThermo>> clone() const = 0;
212 
213  //- Construct and return a clone with new speciesTable
215  (
216  const speciesTable& species
217  ) const = 0;
218 
219  //- Construct the left- and right-hand-side reaction coefficients
220  void setLRhs
221  (
222  Istream&,
223  const speciesTable&,
224  List<specieCoeffs>& lhs,
225  List<specieCoeffs>& rhs
226  );
227 
228 
229  // Selectors
230 
231  //- Return a pointer to new patchField created on freestore from dict
233  (
234  const speciesTable& species,
235  const HashPtrTable<ReactionThermo>& thermoDatabase,
236  const dictionary& dict
237  );
238 
239 
240  //- Destructor
241  virtual ~Reaction()
242  {}
243 
244 
245  // Member Functions
246 
247  // Access
248 
249  //- Return the name of the reaction
250  inline const word& name() const;
251 
252  //- Return the lower temperature limit for the reaction
253  inline scalar Tlow() const;
254 
255  //- Return the upper temperature limit for the reaction
256  inline scalar Thigh() const;
257 
258  //- Return the components of the left hand side
259  inline const List<specieCoeffs>& lhs() const;
260 
261  //- Return the components of the right hand side
262  inline const List<specieCoeffs>& rhs() const;
263 
264  //- Return the specie list
265  const speciesTable& species() const;
266 
267 
268  // Reaction rate coefficients
269 
270  //- Forward reaction rate
271  void ddot
272  (
273  const scalar p,
274  const scalar T,
275  const scalarField& c,
276  scalarField& d
277  ) const;
278 
279  //- Backward reaction rate
280  void fdot
281  (
282  const scalar p,
283  const scalar T,
284  const scalarField& c,
285  scalarField& f
286  ) const;
287 
288  //- Net reaction rate for individual species
289  void omega
290  (
291  const scalar p,
292  const scalar T,
293  const scalarField& c,
294  scalarField& dcdt
295  ) const;
296 
297  //- Net reaction rate
298  scalar omega
299  (
300  const scalar p,
301  const scalar T,
302  const scalarField& c,
303  scalar& pf,
304  scalar& cf,
305  label& lRef,
306  scalar& pr,
307  scalar& cr,
308  label& rRef
309  ) const;
310 
311  // Reaction rate coefficients
312 
313  //- Forward rate constant
314  virtual scalar kf
315  (
316  const scalar p,
317  const scalar T,
318  const scalarField& c
319  ) const = 0;
320 
321  //- Reverse rate constant from the given forward rate constant
322  virtual scalar kr
323  (
324  const scalar kfwd,
325  const scalar p,
326  const scalar T,
327  const scalarField& c
328  ) const = 0;
329 
330  //- Reverse rate constant
331  virtual scalar kr
332  (
333  const scalar p,
334  const scalar T,
335  const scalarField& c
336  ) const = 0;
337 
338 
339  // Jacobian coefficients
340 
341  //- Derivative of the net reaction rate for each species involved
342  // w.r.t. the species concentration
343  void dwdc
344  (
345  const scalar p,
346  const scalar T,
347  const scalarField& c,
349  scalarField& dcdt,
350  scalar& omegaI,
351  scalar& kfwd,
352  scalar& kbwd,
353  const bool reduced,
354  const List<label>& c2s
355  ) const;
356 
357  //- Derivative of the net reaction rate for each species involved
358  // w.r.t. the temperature
359  void dwdT
360  (
361  const scalar p,
362  const scalar T,
363  const scalarField& c,
364  const scalar omegaI,
365  const scalar kfwd,
366  const scalar kbwd,
368  const bool reduced,
369  const List<label>& c2s,
370  const label indexT
371  ) const;
372 
373  //- Temperature derivative of forward rate
374  virtual scalar dkfdT
375  (
376  const scalar p,
377  const scalar T,
378  const scalarField& c
379  ) const = 0;
380 
381  //- Temperature derivative of reverse rate
382  virtual scalar dkrdT
383  (
384  const scalar p,
385  const scalar T,
386  const scalarField& c,
387  const scalar dkfdT,
388  const scalar kr
389  ) const = 0;
390 
391  //- Third-body efficiencies (beta = 1-alpha)
392  // non-empty only for third-body reactions
393  // with enhanced molecularity (alpha != 1)
394  virtual const List<Tuple2<label, scalar>>& beta() const = 0;
395 
396  //- Species concentration derivative of the pressure dependent term
397  virtual void dcidc
398  (
399  const scalar p,
400  const scalar T,
401  const scalarField& c,
403  ) const = 0;
404 
405  //- Temperature derivative of the pressure dependent term
406  virtual scalar dcidT
407  (
408  const scalar p,
409  const scalar T,
410  const scalarField& c
411  ) const = 0;
412 
413 
414  //- Write
415  virtual void write(Ostream&) const;
416 
417 
418  // Ostream Operator
419 
420  friend Ostream& operator<< <ReactionThermo>
421  (
422  Ostream&,
424  );
425 };
426 
427 
428 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
429 
430 } // End namespace Foam
431 
432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 
434 #include "ReactionI.H"
435 
436 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
437 
438 #ifdef NoRepository
439  #include "Reaction.C"
440 #endif
441 
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 
444 #endif
445 
446 // ************************************************************************* //
void ddot(const scalar p, const scalar T, const scalarField &c, scalarField &d) const
Forward reaction rate.
Definition: Reaction.C:404
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
Return the components of the left hand side.
Definition: ReactionI.H:58
virtual ~Reaction()
Destructor.
Definition: Reaction.H:240
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & name() const
Return the name of the reaction.
Definition: ReactionI.H:36
void dwdT(const scalar p, const scalar T, const scalarField &c, const scalar omegaI, const scalar kfwd, const scalar kbwd, scalarSquareMatrix &J, const bool reduced, const List< label > &c2s, const label indexT) const
Derivative of the net reaction rate for each species involved.
Definition: Reaction.C:737
virtual scalar dkfdT(const scalar p, const scalar T, const scalarField &c) const =0
Temperature derivative of forward rate.
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
void fdot(const scalar p, const scalar T, const scalarField &c, scalarField &f) const
Backward reaction rate.
Definition: Reaction.C:416
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:394
virtual scalar kr(const scalar kfwd, const scalar p, const scalar T, const scalarField &c) const =0
Reverse rate constant from the given forward rate constant.
TypeName("Reaction")
Runtime type information.
A HashTable specialization for hashing pointers.
Definition: HashPtrTable.H:50
void omega(const scalar p, const scalar T, const scalarField &c, scalarField &dcdt) const
Net reaction rate for individual species.
Definition: Reaction.C:428
Class to hold the specie index and its coefficients in the.
Definition: Reaction.H:95
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:55
scalar Tlow() const
Return the lower temperature limit for the reaction.
Definition: ReactionI.H:43
static scalar TlowDefault
Default temperature limits of applicability of reaction rates.
Definition: Reaction.H:89
virtual void dcidc(const scalar p, const scalar T, const scalarField &c, scalarField &dcidc) const =0
Species concentration derivative of the pressure dependent term.
const speciesTable & species() const
Return the specie list.
Definition: Reaction.C:805
void reactionStrLeft(OStringStream &reaction) const
Return string representation of the left of the reaction.
Definition: Reaction.C:44
A class for handling words, derived from string.
Definition: word.H:59
virtual const List< Tuple2< label, scalar > > & beta() const =0
Third-body efficiencies (beta = 1-alpha)
CombustionModel< rhoReactionThermo > & reaction
void dwdc(const scalar p, const scalar T, const scalarField &c, scalarSquareMatrix &J, scalarField &dcdt, scalar &omegaI, scalar &kfwd, scalar &kbwd, const bool reduced, const List< label > &c2s) const
Derivative of the net reaction rate for each species involved.
Definition: Reaction.C:574
bool operator!=(const specieCoeffs &sc) const
Definition: Reaction.H:115
static scalar ThighDefault
Definition: Reaction.H:89
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual scalar dkrdT(const scalar p, const scalar T, const scalarField &c, const scalar dkfdT, const scalar kr) const =0
Temperature derivative of reverse rate.
virtual autoPtr< Reaction< ReactionThermo > > clone() const =0
Construct and return a clone.
labelList f(nPoints)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
scalar Thigh() const
Return the upper temperature limit for the reaction.
Definition: ReactionI.H:50
void reactionStrRight(OStringStream &reaction) const
Return string representation of the right of the reaction.
Definition: Reaction.C:69
virtual scalar dcidT(const scalar p, const scalar T, const scalarField &c) const =0
Temperature derivative of the pressure dependent term.
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct from components.
Definition: Reaction.C:159
void setLRhs(Istream &, const speciesTable &, List< specieCoeffs > &lhs, List< specieCoeffs > &rhs)
Construct the left- and right-hand-side reaction coefficients.
Definition: Reaction.C:252
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:363
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:86
Output to memory buffer stream.
Definition: OStringStream.H:49
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const =0
Forward rate constant.
friend Ostream & operator<<(Ostream &os, const specieCoeffs &sc)
Definition: Reaction.H:120
const List< specieCoeffs > & rhs() const
Return the components of the right hand side.
Definition: ReactionI.H:66
Namespace for OpenFOAM.
bool operator==(const specieCoeffs &sc) const
Definition: Reaction.H:110