binaryTree.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016-2017 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26Class
27 Foam::binaryTree
28
29Description
30
31 Data storage of the chemistryOnLineLibrary according to a binary
32 tree structure.
33
34 0 (root node)
35 / \
36 0 0
37 / \ / \
38 L R L 0
39 / \
40 L R
41
42 L: leafLeft_
43 R: leafRight_
44
45\*---------------------------------------------------------------------------*/
46
47#ifndef binaryTree_H
48#define binaryTree_H
49
50#include "binaryNode.H"
51#include "chemPointISAT.H"
52
53namespace Foam
54{
55
56template<class CompType, class ThermoType>
57class TDACChemistryModel;
58
59template<class CompType, class ThermoType>
60class binaryTree
61{
62
63public:
67
68
69private:
70
71 //- Reference to the chemistryModel
73
74 //- Root node of the binary tree
75 node *root_;
76
77 //- Maximum number of elements in the binary tree
78 label maxNLeafs_;
79
80 //- Size of the BST (= number of chemPoint stored)
81 label size_;
82
83 //- Secondary retrieve search variables
84 label n2ndSearch_;
85 label max2ndSearch_;
86
87 //- Insert new node at the position of phi0
88 // phi0 should be already attached to another node or the pointer to it
89 // will be lost
90 void insertNode
91 (
92 chemPoint*& phi0,
93 node*& newNode
94 );
95
96 //- Perform a search in the subtree starting from the subtree node y
97 // This search continue to use the hyperplan to walk the tree
98 // If covering EOA is found return true and x points to the chemPoint
99 bool inSubTree
100 (
101 const scalarField& phiq,
102 node* y,
103 chemPoint* x
104 );
105
106 void deleteSubTree(binaryNode<CompType, ThermoType>* subTreeRoot);
107
108 inline void deleteSubTree()
109 {
110 deleteSubTree(root_);
111 }
112
113 //- Replace the binaryNode u with v
114 void transplant(node* u, node* v);
115
116 chemPoint* chemPSibling(node* y);
117 chemPoint* chemPSibling(chemPoint* x);
118
119 node* nodeSibling(node* y);
120 node* nodeSibling(chemPoint* x);
121
122 void deleteAllNode(node* subTreeRoot);
123
124 dictionary coeffsDict_;
125
126
127public:
128
129 // Constructors
130
131 //- Construct from dictionary and chemistryOnLineLibrary
133 (
135 dictionary coeffsDict
136 );
137
138
139 // Member functions
141 inline label size()
142 {
143 return size_;
144 }
145
146 //- Computes iteratively the depth of the subTree
147 label depth(node* subTreeRoot);
149 inline label depth()
150 {
151 return depth(root_);
152 }
154 inline node* root()
155 {
156 return root_;
157 }
159 inline label maxNLeafs()
160 {
161 return maxNLeafs_;
162 }
163
164 // Insert a new leaf starting from the parent node of phi0
165 // Parameters: phi0 the leaf to replace by a node
166 // phiq the new composition to store
167 // Rphiq the mapping of the new composition point
168 // A the mapping gradient matrix
169 // B the matrix used to initialize the EOA
170 // nCols the size of the matrix
171 // Returns: void
172 // Description :
173 //1) Create a new leaf with the data to initialize the EOA and to
174 // retrieve the mapping by linear interpolation (the EOA is
175 // initialize in the chemPoint constructor)
176 //2) Get the parent node of phi0 and connect a new node in place of the
177 // leaf of phi0. This new node is constructed with phi0 on the left
178 // and phiq on the right (the hyperplane is computed inside the
179 // binaryNode constructor)
180 void insertNewLeaf
181 (
182 const scalarField& phiq,
183 const scalarField& Rphiq,
184 const scalarSquareMatrix& A,
185 const scalarField& scaleFactor,
186 const scalar& epsTol,
187 const label nCols,
188 chemPoint*& phi0
189 );
190
191
192
193 // Search the binaryTree until the nearest leaf of a specified
194 // leaf is found.
196 (
197 const scalarField& phiq,
198 node* node,
199 chemPoint*& nearest
200 );
201
202 // Perform a secondary binary tree search starting from a failed
203 // chemPoint x, with a depth-first search algorithm
204 // If another candidate is found return true and x points to the chemP
205 bool secondaryBTSearch(const scalarField& phiq, chemPoint*& x);
206
207 //- Delete a leaf from the binary tree and reshape the binary tree for
208 // the following binary tree search
209 // Return the index in the nodeList of the removed node
210 // (-1 when no node)
211 void deleteLeaf(chemPoint*& phi0);
212
213 //- Cheap balance function
214 // This function just roughly separate the space in two parts
215 // with a hyperplane which separate the two extreme chemPoint in the
216 // direction of the maximum the variance
217 // Then, it repopulate the tree with this hyperplane stored at the root
218 // and by inserting the chemPoint in increasing order of value in that
219 // direction
220 void balance();
222 inline void deleteAllNode()
223 {
224 deleteAllNode(root_);
225 }
226
227 chemPoint* treeMin(node* subTreeRoot);
229 inline chemPoint* treeMin()
230 {
231 return treeMin(root_);
232 }
233
235
236 //- Removes every entries of the tree and delete the associated objects
237 void clear();
238
239 //- ListFull
240 bool isFull();
241
242 void resetNumRetrieve();
243};
244
245
246// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247
248} // End namespace Foam
249
250// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251
252#ifdef NoRepository
253 #include "binaryTree.C"
254#endif
255
256// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257
258#endif
259
260// ************************************************************************* //
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
scalar y
Extends StandardChemistryModel by adding the TDAC method.
Node of the binary tree.
Definition: binaryNode.H:52
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
Definition: binaryTree.H:60
void resetNumRetrieve()
Definition: binaryTree.C:825
void deleteLeaf(chemPoint *&phi0)
Delete a leaf from the binary tree and reshape the binary tree for.
Definition: binaryTree.C:581
bool isFull()
ListFull.
Definition: binaryTree.C:818
label maxNLeafs()
Definition: binaryTree.H:158
void binaryTreeSearch(const scalarField &phiq, node *node, chemPoint *&nearest)
Definition: binaryTree.C:467
void insertNewLeaf(const scalarField &phiq, const scalarField &Rphiq, const scalarSquareMatrix &A, const scalarField &scaleFactor, const scalar &epsTol, const label nCols, chemPoint *&phi0)
Definition: binaryTree.C:383
void deleteAllNode()
Definition: binaryTree.H:221
chemPoint * treeMin()
Definition: binaryTree.H:228
chemPoint * treeSuccessor(chemPoint *x)
Definition: binaryTree.C:754
chemPointISAT< CompType, ThermoType > chemPoint
Definition: binaryTree.H:65
void clear()
Removes every entries of the tree and delete the associated objects.
Definition: binaryTree.C:804
binaryNode< CompType, ThermoType > node
Definition: binaryTree.H:64
void balance()
Cheap balance function.
Definition: binaryTree.C:645
bool secondaryBTSearch(const scalarField &phiq, chemPoint *&x)
Definition: binaryTree.C:524
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
BasicChemistryModel< psiReactionThermo > & chemistry
Namespace for OpenFOAM.