binaryTree.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::binaryTree
26 
27 Description
28 
29  Data storage of the chemistryOnLineLibrary according to a binary
30  tree structure.
31 
32  0 (root node)
33  / \
34  0 0
35  / \ / \
36  L R L 0
37  / \
38  L R
39 
40  L: leafLeft_
41  R: leafRight_
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef binaryTree_H
46 #define binaryTree_H
47 
48 #include "binaryNode.H"
49 #include "chemPointISAT.H"
50 
51 namespace Foam
52 {
53 
54 /*---------------------------------------------------------------------------*\
55  Class binaryTree Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class binaryTree
59 {
60  // Private Data
61 
62  //- Reference to the ISAT table
64 
65  //- Root node of the binary tree
66  binaryNode *root_;
67 
68  //- Maximum number of elements in the binary tree
69  label maxNLeafs_;
70 
71  //- Size of the BST (= number of chemPoint stored)
72  label size_;
73 
74  //- Secondary retrieve search variables
75  label n2ndSearch_;
76 
77  //- Secondary retrieve search variables
78  label max2ndSearch_;
79 
80  dictionary coeffsDict_;
81 
82 
83  // Private Member Functions
84 
85  //- Insert new node at the position of phi0. phi0 should be already
86  // attached to another node or the pointer to it will be lost.
87  inline void insertNode(chemPointISAT*& phi0, binaryNode*& newNode);
88 
89  //- Perform a search in the subtree starting from the subtree node y.
90  // This search continues to use the hyperplane to walk the tree.
91  // If covering EOA is found return true and x points to the chemPoint.
92  bool inSubTree
93  (
94  const scalarField& phiq,
95  binaryNode* y,
97  );
98 
99  inline void deleteSubTree(binaryNode* subTreeRoot);
100 
101  inline void deleteSubTree();
102 
103  //- Replace the binaryNode u with v
104  inline void transplant(binaryNode* u, binaryNode* v);
105 
106  inline chemPointISAT* chemPSibling(binaryNode* y);
107 
108  inline chemPointISAT* chemPSibling(chemPointISAT* x);
109 
110  inline binaryNode* nodeSibling(binaryNode* y);
111 
112  inline binaryNode* nodeSibling(chemPointISAT* x);
113 
114  inline void deleteAllNode(binaryNode* subTreeRoot);
115 
116 
117 public:
118 
119  //- Constructors
120 
121  //- Construct from dictionary and chemistryOnLineLibrary
122  binaryTree
123  (
125  dictionary coeffsDict
126  );
127 
128 
129  //- Member functions
130 
131  inline label size() const;
132 
133  //- Computes iteratively the depth of the subTree
134  inline label depth(binaryNode* subTreeRoot) const;
135 
136  inline label depth() const;
137 
138  inline binaryNode* root();
139 
140  inline label maxNLeafs() const;
141 
142  // Insert a new leaf starting from the parent node of phi0
143  // Parameters: phi0 the leaf to replace by a node
144  // phiq the new composition to store
145  // Rphiq the mapping of the new composition point
146  // A the mapping gradient matrix
147  // B the matrix used to initialise the EOA
148  // nCols the size of the matrix
149  // Returns: void
150  // Description :
151  //1) Create a new leaf with the data to initialise the EOA and to
152  // retrieve the mapping by linear interpolation (the EOA is
153  // initialise in the chemPoint constructor)
154  //2) Get the parent node of phi0 and connect a new node in place of the
155  // leaf of phi0. This new node is constructed with phi0 on the left
156  // and phiq on the right (the hyperplane is computed inside the
157  // binaryNode constructor)
158  void insertNewLeaf
159  (
160  const scalarField& phiq,
161  const scalarField& Rphiq,
162  const scalarSquareMatrix& A,
163  const scalarField& scaleFactor,
164  const scalar& epsTol,
165  const label nCols,
166  const label nActive,
168  );
169 
170  // Search the binaryTree until the nearest leaf of a specified
171  // leaf is found.
172  void binaryTreeSearch
173  (
174  const scalarField& phiq,
175  binaryNode* node,
176  chemPointISAT*& nearest
177  );
178 
179  // Perform a secondary binary tree search starting from a failed
180  // chemPoint x, with a depth-first search algorithm
181  // If another candidate is found return true and x points to the chemP
182  bool secondaryBTSearch(const scalarField& phiq, chemPointISAT*& x);
183 
184  //- Delete a leaf from the binary tree and reshape the binary tree for
185  // the following binary tree search
186  // Return the index in the nodeList of the removed node
187  // (-1 when no node)
188  void deleteLeaf(chemPointISAT*& phi0);
189 
190  //- Cheap balance function
191  // This function just roughly separate the space in two parts
192  // with a hyperplane which separate the two extreme chemPoint in the
193  // direction of the maximum the variance
194  // Then, it repopulate the tree with this hyperplane stored at the root
195  // and by inserting the chemPoint in increasing order of value in that
196  // direction
197  void balance();
198 
199  inline void deleteAllNode()
200  {
201  deleteAllNode(root_);
202  }
203 
204  inline chemPointISAT* treeMin(binaryNode* subTreeRoot);
205 
206  inline chemPointISAT* treeMin()
207  {
208  return treeMin(root_);
209  }
210 
212 
213  //- Removes every entries of the tree and delete the associated objects
214  inline void clear();
215 
216  //- ListFull
217  inline bool isFull();
218 
219  inline void resetNumRetrieve();
220 };
221 
222 
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
224 
225 } // End namespace Foam
226 
227 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228 
229 #include "binaryTreeI.H"
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 #endif
234 
235 // ************************************************************************* //
static const Foam::dimensionedScalar A("A", Foam::dimPressure, 611.21)
scalar y
Node of the binary tree.
Definition: binaryNode.H:49
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
Definition: binaryTree.H:58
void resetNumRetrieve()
Definition: binaryTreeI.H:365
void deleteLeaf(chemPointISAT *&phi0)
Delete a leaf from the binary tree and reshape the binary tree for.
Definition: binaryTree.C:296
binaryNode * root()
Definition: binaryTreeI.H:264
chemPointISAT * treeMin()
Definition: binaryTree.H:205
bool isFull()
ListFull.
Definition: binaryTreeI.H:359
label size() const
Member functions.
Definition: binaryTreeI.H:232
void binaryTreeSearch(const scalarField &phiq, binaryNode *node, chemPointISAT *&nearest)
Definition: binaryTreeI.H:277
bool secondaryBTSearch(const scalarField &phiq, chemPointISAT *&x)
Definition: binaryTree.C:240
chemPointISAT * treeSuccessor(chemPointISAT *x)
Definition: binaryTree.C:456
void insertNewLeaf(const scalarField &phiq, const scalarField &Rphiq, const scalarSquareMatrix &A, const scalarField &scaleFactor, const scalar &epsTol, const label nCols, const label nActive, chemPointISAT *&phi0)
Definition: binaryTree.C:155
binaryTree(chemistryTabulationMethods::ISAT &table, dictionary coeffsDict)
Constructors.
Definition: binaryTree.C:138
void deleteAllNode()
Definition: binaryTree.H:198
label maxNLeafs() const
Definition: binaryTreeI.H:270
void clear()
Removes every entries of the tree and delete the associated objects.
Definition: binaryTreeI.H:346
label depth() const
Definition: binaryTreeI.H:258
void balance()
Cheap balance function.
Definition: binaryTree.C:358
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
Implementation of the ISAT (In-situ adaptive tabulation), for chemistry calculation.
Definition: ISAT.H:63
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
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