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