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-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::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 
44 #include "binaryTree.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 namespace chemistryTabulationMethods
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class ISAT Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class ThermoType>
58 class ISAT
59 :
60  public chemistryTabulationMethod<ThermoType>
61 {
62  // Private Data
63 
64  //- List of the stored 'points' organised in a binary tree
65  binaryTree<ThermoType> chemisTree_;
66 
67  //- List of scale factors for species, temperature and pressure
68  scalarField scaleFactor_;
69 
70  const Time& runTime_;
71 
72  //- Lifetime (number of time steps) of a stored point
73  label chPMaxLifeTime_;
74 
75  //- Maximum number of growths before removing from the tree
76  label maxGrowth_;
77 
78  //- Check the binary tree for leafs to remove every interval
79  label checkEntireTreeInterval_;
80 
81  //- Factor that multiply the ideal depth of a binary tree to decide
82  // whether to try to balance of not
83  scalar maxDepthFactor_;
84 
85  //- Minimal size before trying to balance the tree
86  label minBalanceThreshold_;
87 
88  //- After a failed primary retrieve, look in the MRU list
89  Switch MRURetrieve_;
90 
91  //- Most Recently Used (MRU) list of chemPoint
93 
94  //- Maximum size of the MRU list
95  label maxMRUSize_;
96 
97  //- Store a pointer to the last chemPointISAT found
98  chemPointISAT<ThermoType>* lastSearch_;
99 
100  //- Switch to allow growth (on by default)
101  Switch growPoints_;
102 
103  // Statistics on ISAT usage
104  label nRetrieved_;
105  label nGrowth_;
106  label nAdd_;
107 
108  autoPtr<OFstream> nRetrievedFile_;
109  autoPtr<OFstream> nGrowthFile_;
110  autoPtr<OFstream> nAddFile_;
111  autoPtr<OFstream> sizeFile_;
112 
113  bool cleaningRequired_;
114 
115 
116  // Private Member Functions
117 
118  //- Add a chemPoint to the MRU list
119  void addToMRU(chemPointISAT<ThermoType>* phi0);
120 
121  //- Compute and return the mapping of the composition phiq
122  // Input : phi0 the nearest chemPoint used in the linear interpolation
123  // phiq the composition of the query point for which we want to
124  // compute the mapping
125  // Rphiq the mapping of the new composition point (given as empty)
126  // Output: void (the mapping is stored in the Rphiq array)
127  // Rphiq = Rphi0 + A * (phiq-phi0)
128  void calcNewC
129  (
131  const scalarField& phiq,
132  scalarField& Rphiq
133  );
134 
135  //- Check if the composition of the query point phiq lies in the
136  // ellipsoid of accuracy approximating the region of accuracy of the
137  // stored chemPoint phi0
138  // Input : phi0 the nearest chemPoint used in the linear interpolation
139  // phiq the composition of the query point for which we want to
140  // compute the mapping
141  // Output: true if phiq is in the EOA, false if not
142  bool grow
143  (
145  const scalarField& phiq,
146  const scalarField& Rphiq
147  );
148 
149  //- Clean and balance the tree
150  bool cleanAndBalance();
151 
152  //- Functions to construct the gradients matrix
153  // When mechanism reduction is active, the A matrix is given by
154  // Aaa Aad
155  // A = ( Ada Add ), where the sub gradient matrices are:
156  // (Aaa) active species according to active species, (Aad) active
157  // species according to disabled species, (Ada) disabled species
158  // according to active species, and (Add) disabled species according to
159  // disabled species.
160  // The current implementation computes Aaa with the Jacobian of the
161  // reduced set of species. Aad = 0, Ada = 0, and Add = I.
162  // To be implemented: add options to compute the A matrix for different
163  // strategies
164  void computeA
165  (
167  const scalarField& Rphiq,
168  const label li,
169  const scalar rho,
170  const scalar dt
171  );
172 
173 
174 public:
175 
176  //- Runtime type information
177  TypeName("ISAT");
178 
179 
180  // Constructors
181 
182  //- Construct from dictionary
183  ISAT
184  (
185  const dictionary& chemistryProperties,
187  );
188 
189  //- Disallow default bitwise copy construction
190  ISAT(const ISAT&) = delete;
191 
192 
193  // Destructor
194  virtual ~ISAT();
195 
196 
197  // Member Functions
200  {
201  return chemisTree_;
202  }
204  inline const scalarField& scaleFactor() const
205  {
206  return scaleFactor_;
207  }
208 
209  //- Return the size of the binary tree
210  virtual inline label size()
211  {
212  return chemisTree_.size();
213  }
214 
215  virtual void writePerformance();
216 
217  //- Find the closest stored leaf of phiQ and store the result in
218  // RphiQ or return false.
219  virtual bool retrieve
220  (
221  const Foam::scalarField& phiq,
222  scalarField& Rphiq
223  );
224 
225  //- Add information to the tabulation.
226  // This function can grow an existing point or add a new leaf to the
227  // binary tree Input : phiq the new composition to store Rphiq the
228  // mapping of the new composition point
229  virtual label add
230  (
231  const scalarField& phiq,
232  const scalarField& Rphiq,
233  const label li,
234  const scalar rho,
235  const scalar deltaT
236  );
238  virtual bool update()
239  {
240  return cleanAndBalance();
241  }
242 };
243 
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 } // End namespace chemistryTabulationMethods
248 } // End namespace Foam
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 
252 #ifdef NoRepository
253  #include "ISAT.C"
254 #endif
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 #endif
259 
260 // ************************************************************************* //
Extends standardChemistryModel by adding the TDAC method.
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
binaryTree< ThermoType > & chemisTree()
Definition: ISAT.H:198
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
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
virtual bool retrieve(const Foam::scalarField &phiq, scalarField &Rphiq)
Find the closest stored leaf of phiQ and store the result in.
Definition: ISAT.C:431
ISAT(const dictionary &chemistryProperties, TDACChemistryModel< ThermoType > &chemistry)
Construct from dictionary.
Definition: ISAT.C:33
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
Definition: binaryTree.H:57
virtual label add(const scalarField &phiq, const scalarField &Rphiq, const label li, const scalar rho, const scalar deltaT)
Add information to the tabulation.
Definition: ISAT.C:512
basicChemistryModel & chemistry
TypeName("ISAT")
Runtime type information.
label size()
Member functions.
Definition: binaryTree.H:142
An abstract class for chemistry tabulation.
virtual label size()
Return the size of the binary tree.
Definition: ISAT.H:209
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
Definition: ISAT.H:57
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].
const scalarField & scaleFactor() const
Definition: ISAT.H:203
Namespace for OpenFOAM.