Standard_chemistryModel.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) 2016-2026 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::chemistryModels::Standard
26 
27 Description
28  Extension to Foam::chemistryModels::standard templated on thermo
29  and provides stiff ODE integration functions.
30 
31  Integrates a standard OpenFOAM reaction system and evaluation of chemical
32  source terms with optional support for mechanism reduction and tabulation.
33 
34 See also
35  Foam::chemistryModels::standard
36 
37 SourceFiles
38  Standard_chemistryModelI.H
39  standard_chemistryModel.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef Standard_chemistryModel_H
44 #define Standard_chemistryModel_H
45 
47 #include "multicomponentMixture.H"
48 #include "ReactionList.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 namespace chemistryModels
57 {
58 
59 /*---------------------------------------------------------------------------*\
60  Class Standard Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class ThermoType>
64 class Standard
65 :
66  public standard
67 {
68  // Private classes
69 
70  //- Class to define scope of reaction evaluation. Runs pre-evaluate
71  // hook on all reactions on construction and post-evaluate on
72  // destruction.
73  class reactionEvaluationScope
74  {
76 
77  public:
78 
79  reactionEvaluationScope
80  (
82  )
83  :
85  {
86  forAll(chemistry_.reactions_, i)
87  {
88  chemistry_.reactions_[i].preEvaluate();
89  }
90  }
91 
92  ~reactionEvaluationScope()
93  {
94  forAll(chemistry_.reactions_, i)
95  {
96  chemistry_.reactions_[i].postEvaluate();
97  }
98  }
99  };
100 
101 
102  // Private data
103 
104  //- Switch to select performance logging
105  Switch log_;
106 
107  //- Switch to enable per-cell CPU load caching for load-balancing
108  Switch cpuLoad_;
109 
110  //- Type of the Jacobian to be calculated
111  const jacobianType jacobianType_;
112 
113  //- Reference to the multi component mixture
114  const multicomponentMixture<ThermoType>& mixture_;
115 
116  //- Thermodynamic data of the species
117  const PtrList<ThermoType>& specieThermos_;
118 
119  //- Reactions
120  const ReactionList<ThermoType> reactions_;
121 
122  //- List of reaction rate per specie [kg/m^3/s]
124 
125  //- Temporary mass fraction field
126  mutable scalarField Y_;
127 
128  //- Temporary simplified mechanism mass fraction field
130 
131  //- Temporary concentration field
132  mutable scalarField c_;
133 
134  //- Temporary simplified mechanism concentration field
136 
137  //- Specie-temperature-pressure workspace fields
138  mutable FixedList<scalarField, 5> YTpWork_;
139 
140  //- Specie-temperature-pressure workspace matrices
141  mutable FixedList<scalarSquareMatrix, 2> YTpYTpWork_;
142 
143  //- Mechanism reduction method
145 
146  //- Mechanism reduction method reference
148 
149  //- Tabulation method
150  autoPtr<chemistryTabulationMethod> tabulationPtr_;
151 
152  //- Tabulation method reference
153  chemistryTabulationMethod& tabulation_;
154 
155  //- Log file for average time spent solving the chemistry
156  autoPtr<OFstream> cpuSolveFile_;
157 
158 
159  // Private Member Functions
160 
161  //- Solve the reaction system for the given time step
162  // of given type and return the characteristic time
163  // Variable number of species added
164  template<class DeltaTType>
165  scalar solve(const DeltaTType& deltaT);
166 
167 
168 public:
169 
170  //- Runtime type information
171  TypeName("standard");
172 
173 
174  // Constructors
175 
176  //- Construct from thermo
178 
179  //- Disallow default bitwise copy construction
180  Standard(const Standard&) = delete;
181 
182 
183  //- Destructor
184  virtual ~Standard();
185 
186 
187  // Member Functions
188 
189  // Access
190 
191  //- Return reference to the mixture
192  inline const multicomponentMixture<ThermoType>& mixture() const;
193 
194  //- The reactions
195  inline const PtrList<Reaction<ThermoType>>& reactions() const;
196 
197  //- Thermodynamic data of the species
198  inline const PtrList<ThermoType>& specieThermos() const;
199 
200 
201  // Overrides to chemistryModel functions
202 
203  //- The number of reactions
204  virtual inline label nReaction() const;
205 
206  //- Return reaction rates of the species [kg/m^3/s]
207  virtual inline const PtrList<volScalarField::Internal>& RR() const;
208 
209  //- Return the name of reactioni
210  virtual inline const word& reactionName
211  (
212  const label reactioni
213  ) const;
214 
215  //- Return the rate of reactioni [kmol/m^3/s]
217  (
218  const label reactioni
219  ) const;
220 
221  //- Return reaction rates of the species in reactioni [kg/m^3/s]
223  (
224  const label reactioni
225  ) const;
226 
227  //- Calculates the reaction rates
228  virtual void calculate();
229 
230  //- Solve the reaction system for the given time step
231  // and return the characteristic time
232  virtual scalar solve(const scalar deltaT);
233 
234  //- Solve the reaction system for the given time step
235  // and return the characteristic time
236  virtual scalar solve(const scalarField& deltaT);
237 
238  //- Return the chemical time scale
239  virtual tmp<volScalarField> tc() const;
240 
241  //- Return the heat release rate [kg/m/s^3]
242  virtual tmp<volScalarField> Qdot() const;
243 
244 
245  // ODE solution functions
246 
247  //- Calculate the ODE derivatives
248  virtual void derivatives
249  (
250  const scalar t,
251  const scalarField& YTp,
252  const label li,
253  scalarField& dYTpdt
254  ) const;
255 
256  //- Calculate the ODE jacobian
257  virtual void jacobian
258  (
259  const scalar t,
260  const scalarField& YTp,
261  const label li,
262  scalarField& dYTpdt,
264  ) const;
265 
266  //- Solve the ODE system
267  virtual void solve
268  (
269  scalar& p,
270  scalar& T,
271  scalarField& Y,
272  const label li,
273  scalar& deltaT,
274  scalar& subDeltaT
275  ) const;
276 
277 
278  // Member Operators
279 
280  //- Disallow default bitwise assignment
281  void operator=(const Standard&) = delete;
282 };
283 
284 
285 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
286 
287 } // End namespace chemistryModels
288 } // End namespace Foam
289 
290 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
291 
293 
294 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
295 
296 #ifdef NoRepository
297  #include "Standard_chemistryModel.C"
298 #endif
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 #endif
303 
304 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:78
List of templated reactions.
Definition: ReactionList.H:54
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
const fluidMulticomponentThermo & thermo() const
Return const access to the thermo.
Switch chemistry_
Chemistry activation switch.
Switch chemistry() const
Chemistry activation switch.
Extension to Foam::chemistryModels::standard templated on thermo and provides stiff ODE integration f...
virtual void jacobian(const scalar t, const scalarField &YTp, const label li, scalarField &dYTpdt, scalarSquareMatrix &J) const
Calculate the ODE jacobian.
virtual tmp< volScalarField > tc() const
Return the chemical time scale.
virtual tmp< volScalarField::Internal > reactionRR(const label reactioni) const
Return the rate of reactioni [kmol/m^3/s].
const PtrList< ThermoType > & specieThermos() const
Thermodynamic data of the species.
Standard(const fluidMulticomponentThermo &thermo)
Construct from thermo.
virtual void derivatives(const scalar t, const scalarField &YTp, const label li, scalarField &dYTpdt) const
Calculate the ODE derivatives.
virtual label nReaction() const
The number of reactions.
const multicomponentMixture< ThermoType > & mixture() const
Return reference to the mixture.
TypeName("standard")
Runtime type information.
virtual const word & reactionName(const label reactioni) const
Return the name of reactioni.
void operator=(const Standard &)=delete
Disallow default bitwise assignment.
virtual PtrList< volScalarField::Internal > specieReactionRR(const label reactioni) const
Return reaction rates of the species in reactioni [kg/m^3/s].
const PtrList< Reaction< ThermoType > > & reactions() const
The reactions.
virtual tmp< volScalarField > Qdot() const
Return the heat release rate [kg/m/s^3].
virtual const PtrList< volScalarField::Internal > & RR() const
Return reaction rates of the species [kg/m^3/s].
virtual void calculate()
Calculates the reaction rates.
Non-templated Base class for Foam::chemistryModels::Standard.
jacobianType
Enumeration for the type of Jacobian to be calculated by the.
const PtrList< volScalarField > & Y() const
Return a reference to the list of mass fraction fields.
An abstract class for methods of chemical mechanism reduction.
An abstract class for chemistry tabulation.
Base-class for multi-component fluid thermodynamic properties.
Foam::multicomponentMixture.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
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
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
volScalarField & p
rhoEqn solve()