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