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-2023 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 ThermoType to handle reaction kinetics in
29  addition 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 ThermoType>
56 class Reaction;
57 
58 template<class ThermoType>
60 
61 class objectRegistry;
62 
63 
64 /*---------------------------------------------------------------------------*\
65  Class Reaction Declaration
66 \*---------------------------------------------------------------------------*/
67 
68 template<class ThermoType>
69 class Reaction
70 :
71  public reaction,
72  public ThermoType::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 PtrList<ThermoType>& speciesThermo);
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 PtrList<ThermoType>& speciesThermo,
113  const dictionary& dict
114  ),
115  (species, speciesThermo, dict)
116  );
117 
119  (
120  autoPtr,
121  Reaction,
123  (
124  const speciesTable& species,
125  const PtrList<ThermoType>& speciesThermo,
126  const objectRegistry& ob,
127  const dictionary& dict
128  ),
129  (species, speciesThermo, ob, dict)
130  );
131 
132 
133  // Constructors
134 
135  //- Construct from components
136  Reaction
137  (
138  const speciesTable& species,
139  const PtrList<ThermoType>& speciesThermo,
140  const List<specieCoeffs>& lhs,
141  const List<specieCoeffs>& rhs
142  );
143 
144  //- Construct as copy given new speciesTable
145  Reaction
146  (
147  const Reaction<ThermoType>&,
148  const speciesTable& species
149  );
150 
151  //- Construct from dictionary
152  Reaction
153  (
154  const speciesTable& species,
155  const PtrList<ThermoType>& speciesThermo,
156  const dictionary& dict
157  );
158 
159  //- Construct and return a clone
160  virtual autoPtr<Reaction<ThermoType>> clone() const = 0;
161 
162  //- Construct and return a clone with new speciesTable
164  (
165  const speciesTable& species
166  ) const = 0;
167 
168 
169  // Selectors
170 
171  //- Return a pointer to new reaction created from a dictionary
173  (
174  const speciesTable& species,
175  const PtrList<ThermoType>& speciesThermo,
176  const dictionary& dict
177  );
178 
179  //- Return a pointer to new reaction created from an objectRegistry and
180  // a dictionary
182  (
183  const speciesTable& species,
184  const PtrList<ThermoType>& speciesThermo,
185  const objectRegistry& ob,
186  const dictionary& dict
187  );
188 
189 
190  //- Destructor
191  virtual ~Reaction()
192  {}
193 
194 
195  // Member Functions
196 
197  // Access
198 
199  //- Return the name of the reaction
200  using reaction::name;
201 
202  //- Return the lower temperature limit for the reaction
203  inline scalar Tlow() const;
204 
205  //- Return the upper temperature limit for the reaction
206  inline scalar Thigh() const;
207 
208 
209  // Hooks
210 
211  //- Pre-evaluation hook
212  virtual void preEvaluate() const = 0;
213 
214  //- Post-evaluation hook
215  virtual void postEvaluate() const = 0;
216 
217 
218  // Reaction rate coefficients
219 
220  //- Concentration powers
221  void C
222  (
223  const scalar p,
224  const scalar T,
225  const scalarField& c,
226  const label li,
227  scalar& Cf,
228  scalar& Cr
229  ) const;
230 
231  //- Net reaction rate
232  scalar omega
233  (
234  const scalar p,
235  const scalar T,
236  const scalarField& c,
237  const label li,
238  scalar& omegaf,
239  scalar& omegar
240  ) const;
241 
242  //- The net reaction rate for each species involved
243  void dNdtByV
244  (
245  const scalar p,
246  const scalar T,
247  const scalarField& c,
248  const label li,
250  const bool reduced,
251  const List<label>& c2s,
252  const label Nsi0
253  ) const;
254 
255 
256  // Reaction rate coefficients
257 
258  //- Forward rate constant
259  virtual scalar kf
260  (
261  const scalar p,
262  const scalar T,
263  const scalarField& c,
264  const label li
265  ) const = 0;
266 
267  //- Reverse rate constant from the given forward rate constant
268  virtual scalar kr
269  (
270  const scalar kf,
271  const scalar p,
272  const scalar T,
273  const scalarField& c,
274  const label li
275  ) const = 0;
276 
277  //- Reverse rate constant
278  virtual scalar kr
279  (
280  const scalar p,
281  const scalar T,
282  const scalarField& c,
283  const label li
284  ) const = 0;
285 
286 
287  // Jacobian coefficients
288 
289  //- Temperature derivative of forward rate
290  virtual scalar dkfdT
291  (
292  const scalar p,
293  const scalar T,
294  const scalarField& c,
295  const label li
296  ) const = 0;
297 
298  //- Temperature derivative of reverse rate
299  virtual scalar dkrdT
300  (
301  const scalar p,
302  const scalar T,
303  const scalarField& c,
304  const label li,
305  const scalar dkfdT,
306  const scalar kr
307  ) const = 0;
308 
309  //- Does this reaction have concentration-dependent rate constants?
310  virtual bool hasDkdc() const = 0;
311 
312  //- Concentration derivative of forward rate
313  virtual void dkfdc
314  (
315  const scalar p,
316  const scalar T,
317  const scalarField& c,
318  const label li,
320  ) const = 0;
321 
322  //- Concentration derivative of reverse rate
323  virtual void dkrdc
324  (
325  const scalar p,
326  const scalar T,
327  const scalarField& c,
328  const label li,
329  const scalarField& dkfdc,
330  const scalar kr,
332  ) const = 0;
333 
334  //- Derivative of the net reaction rate for each species involved
335  // w.r.t. the concentration and temperature
336  void ddNdtByVdcTp
337  (
338  const scalar p,
339  const scalar T,
340  const scalarField& c,
341  const label li,
344  const bool reduced,
345  const List<label>& c2s,
346  const label csi0,
347  const label Tsi,
348  scalarField& cTpWork0,
349  scalarField& cTpWork1
350  ) const;
351 
352 
353  //- Write
354  virtual void write(Ostream&) const;
355 
356 
357  // Member Operators
358 
359  //- Disallow default bitwise assignment
360  void operator=(const Reaction<ThermoType>&) = delete;
361 
362 
363  // Ostream Operator
364 
365  friend Ostream& operator<< <ThermoType>
366  (
367  Ostream&,
368  const Reaction<ThermoType>&
369  );
370 };
371 
372 
373 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374 
375 } // End namespace Foam
376 
377 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
378 
379 #include "ReactionI.H"
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 #ifdef NoRepository
384  #include "Reaction.C"
385 #endif
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #endif
390 
391 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Simple extension of ThermoType to handle reaction kinetics in addition to the equilibrium thermodynam...
Definition: Reaction.H:72
virtual scalar kf(const scalar p, const scalar T, const scalarField &c, const label li) const =0
Forward rate constant.
virtual void postEvaluate() const =0
Post-evaluation hook.
virtual void write(Ostream &) const
Write.
Definition: Reaction.C:259
static scalar TlowDefault
Default temperature limits of applicability of reaction rates.
Definition: Reaction.H:79
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.
declareRunTimeSelectionTable(autoPtr, Reaction, dictionary,(const speciesTable &species, const PtrList< ThermoType > &speciesThermo, const dictionary &dict),(species, speciesThermo, dict))
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.
static scalar ThighDefault
Definition: Reaction.H:79
virtual void preEvaluate() const =0
Pre-evaluation hook.
scalar Tlow() const
Return the lower temperature limit for the reaction.
Definition: ReactionI.H:31
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:355
void C(const scalar p, const scalar T, const scalarField &c, const label li, scalar &Cf, scalar &Cr) const
Concentration powers.
Definition: Reaction.C:267
virtual scalar dkfdT(const scalar p, const scalar T, const scalarField &c, const label li) const =0
Temperature derivative of forward rate.
TypeName("Reaction")
Runtime type information.
virtual void dkfdc(const scalar p, const scalar T, const scalarField &c, const label li, scalarField &dkfdc) const =0
Concentration derivative of forward rate.
scalar Thigh() const
Return the upper temperature limit for the reaction.
Definition: ReactionI.H:38
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.
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:324
static autoPtr< Reaction< ThermoType > > New(const speciesTable &species, const PtrList< ThermoType > &speciesThermo, const dictionary &dict)
Return a pointer to new reaction created from a dictionary.
Definition: Reaction.C:146
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:296
void operator=(const Reaction< ThermoType > &)=delete
Disallow default bitwise assignment.
virtual ~Reaction()
Destructor.
Definition: Reaction.H:190
virtual autoPtr< Reaction< ThermoType > > clone() const =0
Construct and return a clone.
Reaction(const speciesTable &species, const PtrList< ThermoType > &speciesThermo, const List< specieCoeffs > &lhs, const List< specieCoeffs > &rhs)
Construct from components.
Definition: Reaction.C:94
virtual bool hasDkdc() const =0
Does this reaction have concentration-dependent rate constants?
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A wordList with hashed indices for faster lookup by name.
Registry of regIOobjects.
Reaction base-class holding the specie names and coefficients.
Definition: reaction.H:57
const speciesTable & species() const
Return the specie list.
Definition: reactionI.H:48
const List< specieCoeffs > & lhs() const
Return the components of the left hand side.
Definition: reactionI.H:36
const List< specieCoeffs > & rhs() const
Return the components of the right hand side.
Definition: reactionI.H:42
const word & name() const
Return the name of the reaction.
Definition: reactionI.H:30
const dimensionedScalar c
Speed of light in a vacuum.
Namespace for OpenFOAM.
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
Ostream & operator<<(Ostream &, const ensightPart &)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Macros to ease declaration of run-time selection tables.
dictionary dict
volScalarField & p