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-2021 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 "reaction.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 class objectRegistry;
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class Reaction Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 template<class ReactionThermo>
69 class Reaction
70 :
71  public reaction,
72  public ReactionThermo::thermoType
73 {
74 
75 public:
76 
77  // Static data
78 
79  //- Default temperature limits of applicability of reaction rates
80  static scalar TlowDefault, ThighDefault;
81 
82 
83 private:
84 
85  // Private Data
86 
87  //- Temperature limits of applicability of reaction rates
88  scalar Tlow_, Thigh_;
89 
90 
91  // Private Member Functions
92 
93  //- Construct reaction thermo
94  void setThermo(const HashPtrTable<ReactionThermo>& thermoDatabase);
95 
96 
97 public:
98 
99  //- Runtime type information
100  TypeName("Reaction");
101 
102 
103  // Declare run-time constructor selection tables
104 
106  (
107  autoPtr,
108  Reaction,
109  dictionary,
110  (
111  const speciesTable& species,
112  const HashPtrTable<ReactionThermo>& thermoDatabase,
113  const dictionary& dict
114  ),
115  (species, thermoDatabase, dict)
116  );
117 
119  (
120  autoPtr,
121  Reaction,
123  (
124  const speciesTable& species,
125  const HashPtrTable<ReactionThermo>& thermoDatabase,
126  const objectRegistry& ob,
127  const dictionary& dict
128  ),
129  (species, thermoDatabase, ob, dict)
130  );
131 
132 
133  // Constructors
134 
135  //- Construct from components
136  Reaction
137  (
138  const speciesTable& species,
139  const List<specieCoeffs>& lhs,
140  const List<specieCoeffs>& rhs,
141  const HashPtrTable<ReactionThermo>& thermoDatabase
142  );
143 
144  //- Construct as copy given new speciesTable
145  Reaction(const Reaction<ReactionThermo>&, const speciesTable& species);
146 
147  //- Construct from dictionary
148  Reaction
149  (
150  const speciesTable& species,
151  const HashPtrTable<ReactionThermo>& thermoDatabase,
152  const dictionary& dict
153  );
154 
155  //- Construct and return a clone
156  virtual autoPtr<Reaction<ReactionThermo>> clone() const = 0;
157 
158  //- Construct and return a clone with new speciesTable
160  (
161  const speciesTable& species
162  ) const = 0;
163 
164 
165  // Selectors
166 
167  //- Return a pointer to new patchField created on freestore
168  // from dictionary
170  (
171  const speciesTable& species,
172  const HashPtrTable<ReactionThermo>& thermoDatabase,
173  const dictionary& dict
174  );
175 
176  //- Return a pointer to new patchField created on freestore
177  // from objectRegistry and dictionary
179  (
180  const speciesTable& species,
181  const HashPtrTable<ReactionThermo>& thermoDatabase,
182  const objectRegistry& ob,
183  const dictionary& dict
184  );
185 
186  //- Return a pointer to new patchField created on freestore from dict.
187  // This is used to construct a single reaction given a speciesThermo
188  // list from which a temporary thermoDatabase is created.
190  (
191  const speciesTable& species,
192  const PtrList<ReactionThermo>& speciesThermo,
193  const dictionary& dict
194  );
195 
196 
197  //- Destructor
198  virtual ~Reaction()
199  {}
200 
201 
202  // Member Functions
203 
204  // Access
205 
206  //- Return the name of the reaction
207  using reaction::name;
208 
209  //- Return the lower temperature limit for the reaction
210  inline scalar Tlow() const;
211 
212  //- Return the upper temperature limit for the reaction
213  inline scalar Thigh() const;
214 
215 
216  // Hooks
217 
218  //- Pre-evaluation hook
219  virtual void preEvaluate() const = 0;
220 
221  //- Post-evaluation hook
222  virtual void postEvaluate() const = 0;
223 
224 
225  // Reaction rate coefficients
226 
227  //- Concentration powers
228  void C
229  (
230  const scalar p,
231  const scalar T,
232  const scalarField& c,
233  const label li,
234  scalar& Cf,
235  scalar& Cr
236  ) const;
237 
238  //- Net reaction rate
239  scalar omega
240  (
241  const scalar p,
242  const scalar T,
243  const scalarField& c,
244  const label li,
245  scalar& omegaf,
246  scalar& omegar
247  ) const;
248 
249  //- The net reaction rate for each species involved
250  void dNdtByV
251  (
252  const scalar p,
253  const scalar T,
254  const scalarField& c,
255  const label li,
257  const bool reduced,
258  const List<label>& c2s,
259  const label Nsi0
260  ) const;
261 
262 
263  // Reaction rate coefficients
264 
265  //- Forward rate constant
266  virtual scalar kf
267  (
268  const scalar p,
269  const scalar T,
270  const scalarField& c,
271  const label li
272  ) const = 0;
273 
274  //- Reverse rate constant from the given forward rate constant
275  virtual scalar kr
276  (
277  const scalar kf,
278  const scalar p,
279  const scalar T,
280  const scalarField& c,
281  const label li
282  ) const = 0;
283 
284  //- Reverse rate constant
285  virtual scalar kr
286  (
287  const scalar p,
288  const scalar T,
289  const scalarField& c,
290  const label li
291  ) const = 0;
292 
293 
294  // Jacobian coefficients
295 
296  //- Temperature derivative of forward rate
297  virtual scalar dkfdT
298  (
299  const scalar p,
300  const scalar T,
301  const scalarField& c,
302  const label li
303  ) const = 0;
304 
305  //- Temperature derivative of reverse rate
306  virtual scalar dkrdT
307  (
308  const scalar p,
309  const scalar T,
310  const scalarField& c,
311  const label li,
312  const scalar dkfdT,
313  const scalar kr
314  ) const = 0;
315 
316  //- Does this reaction have concentration-dependent rate constants?
317  virtual bool hasDkdc() const = 0;
318 
319  //- Concentration derivative of forward rate
320  virtual void dkfdc
321  (
322  const scalar p,
323  const scalar T,
324  const scalarField& c,
325  const label li,
327  ) const = 0;
328 
329  //- Concentration derivative of reverse rate
330  virtual void dkrdc
331  (
332  const scalar p,
333  const scalar T,
334  const scalarField& c,
335  const label li,
336  const scalarField& dkfdc,
337  const scalar kr,
339  ) const = 0;
340 
341  //- Derivative of the net reaction rate for each species involved
342  // w.r.t. the concentration and temperature
343  void ddNdtByVdcTp
344  (
345  const scalar p,
346  const scalar T,
347  const scalarField& c,
348  const label li,
349  scalarField& dNdtByV,
351  const bool reduced,
352  const List<label>& c2s,
353  const label csi0,
354  const label Tsi,
355  scalarField& cTpWork0,
356  scalarField& cTpWork1
357  ) const;
358 
359 
360  //- Write
361  virtual void write(Ostream&) const;
362 
363 
364  // Member Operators
365 
366  //- Disallow default bitwise assignment
367  void operator=(const Reaction<ReactionThermo>&) = delete;
368 
369 
370  // Ostream Operator
371 
372  friend Ostream& operator<< <ReactionThermo>
373  (
374  Ostream&,
376  );
377 };
378 
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 } // End namespace Foam
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 #include "ReactionI.H"
387 
388 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
389 
390 #ifdef NoRepository
391  #include "Reaction.C"
392 #endif
393 
394 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
395 
396 #endif
397 
398 // ************************************************************************* //
virtual void dkfdc(const scalar p, const scalar T, const scalarField &c, const label li, scalarField &dkfdc) const =0
Concentration derivative of forward rate.
void dNdtByV(const scalar p, const scalar T, const scalarField &c, const label li, scalarField &dNdtByV, const bool reduced, const List< label > &c2s, const label Nsi0) const
The net reaction rate for each species involved.
Definition: Reaction.C:347
virtual scalar dkfdT(const scalar p, const scalar T, const scalarField &c, const label li) const =0
Temperature derivative of forward rate.
scalar omega(const scalar p, const scalar T, const scalarField &c, const label li, scalar &omegaf, scalar &omegar) const
Net reaction rate.
Definition: Reaction.C:319
virtual bool hasDkdc() const =0
Does this reaction have concentration-dependent rate constants?
virtual ~Reaction()
Destructor.
Definition: Reaction.H:197
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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 void write(Ostream &) const
Write.
Definition: Reaction.C:282
TypeName("Reaction")
Runtime type information.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:50
const List< specieCoeffs > & lhs() const
Return the components of the left hand side.
Definition: reactionI.H:36
virtual void postEvaluate() const =0
Post-evaluation hook.
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:55
virtual void preEvaluate() const =0
Pre-evaluation hook.
Reaction base-class holding the specie names and coefficients.
Definition: reaction.H:56
static scalar TlowDefault
Default temperature limits of applicability of reaction rates.
Definition: Reaction.H:79
scalar Tlow() const
Return the lower temperature limit for the reaction.
Definition: ReactionI.H:31
virtual scalar kr(const scalar kf, const scalar p, const scalar T, const scalarField &c, const label li) const =0
Reverse rate constant from the given forward rate constant.
scalar Thigh() const
Return the upper temperature limit for the reaction.
Definition: ReactionI.H:38
static scalar ThighDefault
Definition: Reaction.H:79
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.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void operator=(const Reaction< ReactionThermo > &)=delete
Disallow default bitwise assignment.
void ddNdtByVdcTp(const scalar p, const scalar T, const scalarField &c, const label li, scalarField &dNdtByV, scalarSquareMatrix &ddNdtByVdcTp, const bool reduced, const List< label > &c2s, const label csi0, const label Tsi, scalarField &cTpWork0, scalarField &cTpWork1) const
Derivative of the net reaction rate for each species involved.
Definition: Reaction.C:378
Reaction(const speciesTable &species, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs, const HashPtrTable< ReactionThermo > &thermoDatabase)
Construct from components.
Definition: Reaction.C:95
const List< specieCoeffs > & rhs() const
Return the components of the right hand side.
Definition: reactionI.H:42
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.
void C(const scalar p, const scalar T, const scalarField &c, const label li, scalar &Cf, scalar &Cr) const
Concentration powers.
Definition: Reaction.C:290
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:147
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
const word & name() const
Return the name of the reaction.
Definition: reactionI.H:30
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
Registry of regIOobjects.
virtual void dkrdc(const scalar p, const scalar T, const scalarField &c, const label li, const scalarField &dkfdc, const scalar kr, scalarField &dkrdc) const =0
Concentration derivative of reverse rate.
virtual scalar kf(const scalar p, const scalar T, const scalarField &c, const label li) const =0
Forward rate constant.
Namespace for OpenFOAM.