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 
63 /*---------------------------------------------------------------------------*\
64  Class Reaction Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 template<class ReactionThermo>
68 class Reaction
69 :
70  public ReactionThermo::thermoType
71 {
72 
73 public:
74 
75  // Static data
76 
77  //- Number of un-named reactions
78  static label nUnNamedReactions;
79 
80  //- Default temperature limits of applicability of reaction rates
81  static scalar TlowDefault, ThighDefault;
82 
83 private:
84 
85  // Private Data
86 
87  //- Name of reaction
88  const word name_;
89 
90  //- List of specie names present in reaction system
91  const speciesTable& species_;
92 
93  //- Temperature limits of applicability of reaction rates
94  scalar Tlow_, Thigh_;
95 
96  //- Specie info for the left-hand-side of the reaction
97  List<specieCoeffs> lhs_;
98 
99  //- Specie info for the right-hand-side of the reaction
100  List<specieCoeffs> rhs_;
101 
102 
103  // Private Member Functions
104 
105  //- Construct reaction thermo
106  void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
107 
108  //- Return new reaction ID for un-named reactions
109  label getNewReactionID();
110 
111 
112 public:
113 
114  //- Runtime type information
115  TypeName("Reaction");
116 
117 
118  // Declare run-time constructor selection tables
119 
121  (
122  autoPtr,
123  Reaction,
124  dictionary,
125  (
126  const speciesTable& species,
127  const HashPtrTable<ReactionThermo>& thermoDatabase,
128  const dictionary& dict
129  ),
130  (species, thermoDatabase, dict)
131  );
132 
133 
134  // Constructors
135 
136  //- Construct from components
137  Reaction
138  (
139  const speciesTable& species,
140  const List<specieCoeffs>& lhs,
141  const List<specieCoeffs>& rhs,
142  const HashPtrTable<ReactionThermo>& thermoDatabase
143  );
144 
145  //- Construct as copy given new speciesTable
146  Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
147 
148  //- Construct from dictionary
149  Reaction
150  (
151  const speciesTable& species,
152  const HashPtrTable<ReactionThermo>& thermoDatabase,
153  const dictionary& dict
154  );
155 
156  //- Construct and return a clone
157  virtual autoPtr<Reaction<ReactionThermo>> clone() const = 0;
158 
159  //- Construct and return a clone with new speciesTable
161  (
162  const speciesTable& species
163  ) const = 0;
164 
165 
166  // Selectors
167 
168  //- Return a pointer to new patchField created on freestore from dict
170  (
171  const speciesTable& species,
172  const HashPtrTable<ReactionThermo>& thermoDatabase,
173  const dictionary& dict
174  );
175 
176 
177  //- Destructor
178  virtual ~Reaction()
179  {}
180 
181 
182  // Member Functions
183 
184  // Access
185 
186  //- Return the name of the reaction
187  inline const word& name() const;
188 
189  //- Return the lower temperature limit for the reaction
190  inline scalar Tlow() const;
191 
192  //- Return the upper temperature limit for the reaction
193  inline scalar Thigh() const;
194 
195  //- Return the components of the left hand side
196  inline const List<specieCoeffs>& lhs() const;
197 
198  //- Return the components of the right hand side
199  inline const List<specieCoeffs>& rhs() const;
200 
201  //- Return the specie list
202  const speciesTable& species() const;
203 
204 
205  // Reaction rate coefficients
206 
207  //- Forward reaction rate
208  void ddot
209  (
210  const scalar p,
211  const scalar T,
212  const scalarField& c,
213  scalarField& d
214  ) const;
215 
216  //- Backward reaction rate
217  void fdot
218  (
219  const scalar p,
220  const scalar T,
221  const scalarField& c,
222  scalarField& f
223  ) const;
224 
225  //- Net reaction rate for individual species
226  void omega
227  (
228  const scalar p,
229  const scalar T,
230  const scalarField& c,
231  scalarField& dcdt
232  ) const;
233 
234  //- Net reaction rate
235  scalar omega
236  (
237  const scalar p,
238  const scalar T,
239  const scalarField& c,
240  scalar& pf,
241  scalar& cf,
242  label& lRef,
243  scalar& pr,
244  scalar& cr,
245  label& rRef
246  ) const;
247 
248  // Reaction rate coefficients
249 
250  //- Forward rate constant
251  virtual scalar kf
252  (
253  const scalar p,
254  const scalar T,
255  const scalarField& c
256  ) const = 0;
257 
258  //- Reverse rate constant from the given forward rate constant
259  virtual scalar kr
260  (
261  const scalar kfwd,
262  const scalar p,
263  const scalar T,
264  const scalarField& c
265  ) const = 0;
266 
267  //- Reverse rate constant
268  virtual scalar kr
269  (
270  const scalar p,
271  const scalar T,
272  const scalarField& c
273  ) const = 0;
274 
275 
276  // Jacobian coefficients
277 
278  //- Derivative of the net reaction rate for each species involved
279  // w.r.t. the species concentration
280  void dwdc
281  (
282  const scalar p,
283  const scalar T,
284  const scalarField& c,
286  scalarField& dcdt,
287  scalar& omegaI,
288  scalar& kfwd,
289  scalar& kbwd,
290  const bool reduced,
291  const List<label>& c2s
292  ) const;
293 
294  //- Derivative of the net reaction rate for each species involved
295  // w.r.t. the temperature
296  void dwdT
297  (
298  const scalar p,
299  const scalar T,
300  const scalarField& c,
301  const scalar omegaI,
302  const scalar kfwd,
303  const scalar kbwd,
305  const bool reduced,
306  const List<label>& c2s,
307  const label indexT
308  ) const;
309 
310  //- Temperature derivative of forward rate
311  virtual scalar dkfdT
312  (
313  const scalar p,
314  const scalar T,
315  const scalarField& c
316  ) const = 0;
317 
318  //- Temperature derivative of reverse rate
319  virtual scalar dkrdT
320  (
321  const scalar p,
322  const scalar T,
323  const scalarField& c,
324  const scalar dkfdT,
325  const scalar kr
326  ) const = 0;
327 
328  //- Third-body efficiencies (beta = 1-alpha)
329  // non-empty only for third-body reactions
330  // with enhanced molecularity (alpha != 1)
331  virtual const List<Tuple2<label, scalar>>& beta() const = 0;
332 
333  //- Species concentration derivative of the pressure dependent term
334  virtual void dcidc
335  (
336  const scalar p,
337  const scalar T,
338  const scalarField& c,
340  ) const = 0;
341 
342  //- Temperature derivative of the pressure dependent term
343  virtual scalar dcidT
344  (
345  const scalar p,
346  const scalar T,
347  const scalarField& c
348  ) const = 0;
349 
350 
351  //- Write
352  virtual void write(Ostream&) const;
353 
354 
355  // Member Operators
356 
357  //- Disallow default bitwise assignment
358  void operator=(const Reaction<ReactionThermo>&) = delete;
359 
360 
361  // Ostream Operator
362 
363  friend Ostream& operator<< <ReactionThermo>
364  (
365  Ostream&,
367  );
368 };
369 
370 
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
372 
373 } // End namespace Foam
374 
375 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
376 
377 #include "ReactionI.H"
378 
379 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
380 
381 #ifdef NoRepository
382  #include "Reaction.C"
383 #endif
384 
385 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
386 
387 #endif
388 
389 // ************************************************************************* //
void ddot(const scalar p, const scalar T, const scalarField &c, scalarField &d) const
Forward reaction rate.
Definition: Reaction.C:204
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
virtual ~Reaction()
Destructor.
Definition: Reaction.H:177
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
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:537
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:59
void fdot(const scalar p, const scalar T, const scalarField &c, scalarField &f) const
Backward reaction rate.
Definition: Reaction.C:216
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:190
const List< specieCoeffs > & lhs() const
Return the components of the left hand side.
Definition: ReactionI.H:57
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:228
Simple extension of ReactionThermo to handle reaction kinetics in addition to the equilibrium thermod...
Definition: Reaction.H:56
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:80
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:605
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)
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:374
static scalar ThighDefault
Definition: Reaction.H:80
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 operator=(const Reaction< ReactionThermo > &)=delete
Disallow default bitwise assignment.
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:93
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:159
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
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.
volScalarField & p
static label nUnNamedReactions
Number of un-named reactions.
Definition: Reaction.H:77
virtual scalar kf(const scalar p, const scalar T, const scalarField &c) const =0
Forward rate constant.
Namespace for OpenFOAM.