ISAT.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-2024 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::chemistryTabulationMethods::ISAT
26 
27 Description
28  Implementation of the ISAT (In-situ adaptive tabulation), for chemistry
29  calculation.
30 
31  Reference:
32  \verbatim
33  Pope, S. B. (1997).
34  Computationally efficient implementation of combustion chemistry using
35  in situ adaptive tabulation.
36  Combustion Theory and Modelling, 1, 41-63.
37  \endverbatim
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef ISAT_H
42 #define ISAT_H
43 
45 #include "binaryTree.H"
46 #include "volFields.H"
47 #include "OFstream.H"
48 #include "cpuTime.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 namespace chemistryTabulationMethods
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class ISAT Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class ISAT
62 :
64 {
65  // Private Data
66 
67  const odeChemistryModel& chemistry_;
68 
69  //- Switch to select performance logging
70  Switch log_;
71 
72  //- Is reduction applied to the state vectors
73  const bool reduction_;
74 
75  //- List of the stored 'points' organised in a binary tree
76  binaryTree chemisTree_;
77 
78  //- List of scale factors for species, temperature and pressure
79  scalarField scaleFactor_;
80 
81  const Time& runTime_;
82 
83  label timeSteps_;
84 
85  //- Lifetime (number of time steps) of a stored point
86  label chPMaxLifeTime_;
87 
88  //- Maximum number of growths before removing from the tree
89  label maxGrowth_;
90 
91  //- Check the binary tree for leafs to remove every interval
92  label checkEntireTreeInterval_;
93 
94  //- Factor that multiply the ideal depth of a binary tree to decide
95  // whether to try to balance of not
96  scalar maxDepthFactor_;
97 
98  //- Minimal size before trying to balance the tree
99  label minBalanceThreshold_;
100 
101  //- After a failed primary retrieve, look in the MRU list
102  Switch MRURetrieve_;
103 
104  //- Most Recently Used (MRU) list of chemPoint
105  SLList<chemPointISAT*> MRUList_;
106 
107  //- Maximum size of the MRU list
108  label maxMRUSize_;
109 
110  //- Store a pointer to the last chemPointISAT found
111  chemPointISAT* lastSearch_;
112 
113  //- Switch to allow growth (on by default)
114  Switch growPoints_;
115 
116  scalar tolerance_;
117 
118  // Statistics on ISAT usage
119  label nRetrieved_;
120  label nGrowth_;
121  label nAdd_;
122  scalar addNewLeafCpuTime_;
123  scalar growCpuTime_;
124  scalar searchISATCpuTime_;
125 
126  cpuTime cpuTime_;
127 
128  autoPtr<OFstream> nRetrievedFile_;
129  autoPtr<OFstream> nGrowthFile_;
130  autoPtr<OFstream> nAddFile_;
131  autoPtr<OFstream> sizeFile_;
132 
133  //- Log file for the average time spent adding tabulated data
134  autoPtr<OFstream> cpuAddFile_;
135 
136  //- Log file for the average time spent growing tabulated data
137  autoPtr<OFstream> cpuGrowFile_;
138 
139  //- Log file for the average time spent retrieving tabulated data
140  autoPtr<OFstream> cpuRetrieveFile_;
141 
142  // Field containing information about tabulation:
143  // 0 -> add (direct integration)
144  // 1 -> grow
145  // 2 -> retrieve
146  volScalarField::Internal tabulationResults_;
147 
148  bool cleaningRequired_;
149 
150 
151  // Private Member Functions
152 
153  //- Add a chemPoint to the MRU list
154  void addToMRU(chemPointISAT* phi0);
155 
156  //- Compute and return the mapping of the composition phiq
157  // Input : phi0 the nearest chemPoint used in the linear interpolation
158  // phiq the composition of the query point for which we want to
159  // compute the mapping
160  // Rphiq the mapping of the new composition point (given as empty)
161  // Output: void (the mapping is stored in the Rphiq array)
162  // Rphiq = Rphi0 + A * (phiq-phi0)
163  void calcNewC
164  (
166  const scalarField& phiq,
167  scalarField& Rphiq
168  );
169 
170  //- Check if the composition of the query point phiq lies in the
171  // ellipsoid of accuracy approximating the region of accuracy of the
172  // stored chemPoint phi0
173  // Input : phi0 the nearest chemPoint used in the linear interpolation
174  // phiq the composition of the query point for which we want to
175  // compute the mapping
176  // Output: true if phiq is in the EOA, false if not
177  bool grow
178  (
180  const scalarField& phiq,
181  const scalarField& Rphiq
182  );
183 
184  //- Clean and balance the tree
185  bool cleanAndBalance();
186 
187  //- Functions to construct the gradients matrix
188  // When mechanism reduction is active, the A matrix is given by
189  // Aaa Aad
190  // A = ( Ada Add ), where the sub gradient matrices are:
191  // (Aaa) active species according to active species, (Aad) active
192  // species according to disabled species, (Ada) disabled species
193  // according to active species, and (Add) disabled species according to
194  // disabled species.
195  // The current implementation computes Aaa with the Jacobian of the
196  // reduced set of species. Aad = 0, Ada = 0, and Add = I.
197  // To be implemented: add options to compute the A matrix for different
198  // strategies
199  void computeA
200  (
202  const scalarField& Rphiq,
203  const label li,
204  const scalar dt
205  );
206 
207 
208  // Private constructors
209 
210  //- Construct from dictionary and coefficient dictionary
211  ISAT
212  (
213  const dictionary& chemistryProperties,
214  const dictionary& coeffDict,
216  );
217 
218 
219 public:
220 
221  //- Runtime type information
222  TypeName("ISAT");
223 
224 
225  // Constructors
226 
227  //- Construct from dictionary
228  ISAT
229  (
230  const dictionary& chemistryProperties,
232  );
233 
234  //- Disallow default bitwise copy construction
235  ISAT(const ISAT&) = delete;
236 
237 
238  // Destructor
239  virtual ~ISAT();
240 
241 
242  // Member Functions
243 
244  //- Return true as this tabulation method tabulates
245  virtual bool tabulates()
246  {
247  return true;
248  }
249 
250  //- Return true if reduction is applied to the state variables
251  bool reduction() const
252  {
253  return reduction_;
254  }
255 
257  {
258  return chemistry_;
259  }
260 
261  inline binaryTree& chemisTree()
262  {
263  return chemisTree_;
264  }
265 
266  inline const scalarField& scaleFactor() const
267  {
268  return scaleFactor_;
269  }
270 
271  //- Return the number of chemistry evaluations
272  inline label timeSteps() const
273  {
274  return timeSteps_;
275  }
276 
277  virtual void writePerformance();
278 
279  //- Find the closest stored leaf of phiQ and store the result in
280  // RphiQ or return false.
281  virtual bool retrieve
282  (
283  const Foam::scalarField& phiq,
284  scalarField& Rphiq
285  );
286 
287  //- Add information to the tabulation.
288  // This function can grow an existing point or add a new leaf to the
289  // binary tree Input : phiq the new composition to store Rphiq the
290  // mapping of the new composition point
291  virtual label add
292  (
293  const scalarField& phiq,
294  const scalarField& Rphiq,
295  const label nActive,
296  const label li,
297  const scalar deltaT
298  );
299 
300  virtual void reset();
301 
302  virtual bool update();
303 };
304 
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 } // End namespace chemistryTabulationMethods
309 } // End namespace Foam
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #endif
314 
315 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Template class for non-intrusive linked lists.
Definition: LList.H:76
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
Definition: binaryTree.H:58
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
An abstract class for chemistry tabulation.
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
Definition: ISAT.H:63
const odeChemistryModel & chemistry()
Definition: ISAT.H:255
virtual bool retrieve(const Foam::scalarField &phiq, scalarField &Rphiq)
Find the closest stored leaf of phiQ and store the result in.
Definition: ISAT.C:423
virtual label add(const scalarField &phiq, const scalarField &Rphiq, const label nActive, const label li, const scalar deltaT)
Add information to the tabulation.
Definition: ISAT.C:507
bool reduction() const
Return true if reduction is applied to the state variables.
Definition: ISAT.H:250
const scalarField & scaleFactor() const
Definition: ISAT.H:265
virtual bool tabulates()
Return true as this tabulation method tabulates.
Definition: ISAT.H:244
TypeName("ISAT")
Runtime type information.
label timeSteps() const
Return the number of chemistry evaluations.
Definition: ISAT.H:271
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:55
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Extends base chemistry model adding an ODESystem and the reduction maps needed for tabulation.
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
static const coefficient A("A", dimPressure, 611.21)
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