31 template<
class ThermoType>
34 if (phi0 == phi0->node()->leafRight())
36 phi0->node()->leafRight() =
nullptr;
37 phi0->node()->nodeRight() = newNode;
40 else if (phi0 == phi0->node()->leafLeft())
42 phi0->node()->leafLeft() =
nullptr;
43 phi0->node()->nodeLeft() = newNode;
50 <<
"trying to insert a node with a wrong pointer to a chemPoint" 55 template<
class ThermoType>
63 if ((n2ndSearch_ < max2ndSearch_) && (y!=
nullptr))
67 const scalar a = y->a();
69 for (
label i=0; i<phiq.size(); i++)
75 if (y->nodeLeft() ==
nullptr)
78 if (y->leafLeft()->inEOA(phiq))
86 if (inSubTree(phiq, y->nodeLeft(),
x))
93 if ((n2ndSearch_ < max2ndSearch_) && y->nodeRight() ==
nullptr)
97 if (y->leafRight()->inEOA(phiq))
110 return inSubTree(phiq, y->nodeRight(),
x);
115 if (y->nodeRight() ==
nullptr)
118 if (y->leafRight()->inEOA(phiq))
125 if (inSubTree(phiq, y->nodeRight(),
x))
133 if ((n2ndSearch_ < max2ndSearch_) && y->nodeLeft() ==
nullptr)
136 if (y->leafLeft()->inEOA(phiq))
149 return inSubTree(phiq, y->nodeLeft(),
x);
160 template<
class ThermoType>
163 if (subTreeRoot !=
nullptr)
167 deleteSubTree(subTreeRoot->nodeLeft());
168 deleteSubTree(subTreeRoot->nodeRight());
174 template<
class ThermoType>
180 if (u->parent() ==
nullptr)
185 else if (u == u->parent()->nodeLeft())
187 u->parent()->nodeLeft() = v;
190 else if (u == u->parent()->nodeRight())
192 u->parent()->nodeRight() = v;
197 <<
"wrong addressing of the initial node" 200 v->parent() = u->parent();
205 <<
"trying to transplant a nullptr node" 211 template<
class ThermoType>
215 if (y->parent() !=
nullptr)
217 if (y == y->parent()->nodeLeft())
220 return y->parent()->leafRight();
222 else if (y == y->parent()->nodeRight())
224 return y->parent()->leafLeft();
229 <<
"wrong addressing of the initial node" 240 template<
class ThermoType>
246 if (x == x->node()->leafLeft())
250 return x->node()->leafRight();
252 else if (x == x->node()->leafRight())
255 return x->node()->leafLeft();
260 <<
"wrong addressing of the initial leaf" 270 template<
class ThermoType>
273 if (y->parent()!=
nullptr)
275 if (y == y->parent()->nodeLeft())
278 return y->parent()->nodeRight();
280 else if (y == y->parent()->nodeRight())
282 return y->parent()->nodeLeft();
287 <<
"wrong addressing of the initial node" 296 template<
class ThermoType>
301 if (x == x->node()->leafLeft())
304 return x->node()->nodeRight();
306 else if (x == x->node()->leafRight())
309 return x->node()->nodeLeft();
314 <<
"wrong addressing of the initial leaf" 323 template<
class ThermoType>
326 if (subTreeRoot !=
nullptr)
328 deleteAllNode(subTreeRoot->nodeLeft());
329 deleteAllNode(subTreeRoot->nodeRight());
337 template<
class ThermoType>
344 chemistry_(chemistry),
350 coeffsDict_(coeffsDict)
355 template<
class ThermoType>
359 if (subTreeRoot ==
nullptr)
376 template<
class ThermoType>
383 const scalar& epsTol,
407 root_->leafLeft()=newChemPoint;
414 binaryTreeSearch(phiq, root_,phi0);
417 bn* parentNode = phi0->
node();
440 newNode =
new bn(phi0, newChemPoint, parentNode);
442 insertNode(phi0, newNode);
448 newNode =
new bn(phi0, newChemPoint,
nullptr);
452 phi0->
node() = newNode;
453 newChemPoint->
node()=newNode;
459 template<
class ThermoType>
471 const scalar& a = node->
a();
473 for (
label i=0; i<phiq.
size(); i++) vPhi += phiq[i]*v[i];
480 binaryTreeSearch(phiq, node->
nodeRight(), nearest);
492 binaryTreeSearch(phiq, node->
nodeLeft(), nearest);
504 nearest = root_->leafLeft();
513 template<
class ThermoType>
522 if ((n2ndSearch_ < max2ndSearch_) && (size_ > 1))
524 chP* xS = chemPSibling(x);
534 else if (inSubTree(phiq, nodeSibling(x),x))
541 while((y->
parent()!=
nullptr) && (n2ndSearch_ < max2ndSearch_))
543 xS = chemPSibling(y);
553 else if (inSubTree(phiq, nodeSibling(y),x))
571 template<
class ThermoType>
583 chP* siblingPhi0 = chemPSibling(phi0);
585 if (siblingPhi0 !=
nullptr)
588 if (z->
parent() ==
nullptr)
591 root_->leafLeft()=siblingPhi0;
592 siblingPhi0->
node()=root_;
594 else if (z == z->
parent()->nodeLeft())
596 z->
parent()->leafLeft() = siblingPhi0;
597 z->
parent()->nodeLeft() =
nullptr;
600 else if (z == z->
parent()->nodeRight())
602 z->
parent()->leafRight() = siblingPhi0;
603 z->
parent()->nodeRight() =
nullptr;
609 <<
"wrong addressing of the initial leaf" 615 x = nodeSibling(phi0);
623 <<
"inconsistent structure of the tree, no leaf and no node" 634 template<
class ThermoType>
649 chemPoints[chPi++] =
x;
650 x = treeSuccessor(x);
661 variance[vi] +=
sqr(phij[vi]-mean[vi]);
666 scalar maxVariance(-1.0);
670 if (maxVariance < variance[vi])
672 maxVariance = variance[vi];
684 phiMaxDir[j] = chemPoints[j]->phi()[maxDir];
695 chemPoints[phiMaxDir.
indices()[0]],
696 chemPoints[phiMaxDir.
indices()[phiMaxDir.
size()-1]],
701 chemPoints[phiMaxDir.
indices()[0]]->node() = newNode;
702 chemPoints[phiMaxDir.
indices()[phiMaxDir.
size()-1]]->node() = newNode;
704 for (
label cpi=1; cpi<chemPoints.
size()-1; cpi++)
709 chemPoints[phiMaxDir.
indices()[cpi]]->phi(),
715 new bn(phi0,chemPoints[phiMaxDir.
indices()[cpi]], phi0->
node());
717 insertNode(phi0, nodeToAdd);
718 phi0->
node() = nodeToAdd;
719 chemPoints[phiMaxDir.
indices()[cpi]]->node() = nodeToAdd;
724 template<
class ThermoType>
728 if (subTreeRoot!=
nullptr)
730 while(subTreeRoot->
nodeLeft() !=
nullptr)
732 subTreeRoot = subTreeRoot->
nodeLeft();
743 template<
class ThermoType>
749 if (x == x->
node()->leafLeft())
751 if (x->
node()->nodeRight() ==
nullptr)
753 return x->
node()->leafRight();
757 return treeMin(x->
node()->nodeRight());
760 else if (x == x->
node()->leafRight())
763 while((y->
parent() !=
nullptr))
765 if (y == y->
parent()->nodeLeft())
767 if (y->
parent()->nodeRight() ==
nullptr)
769 return y->
parent()->leafRight();
773 return treeMin(y->
parent()->nodeRight());
786 <<
"inconsistent structure of the tree, no leaf and no node" 796 template<
class ThermoType>
810 template<
class ThermoType>
813 return size_ >= maxNLeafs_;
817 template<
class ThermoType>
824 chP* chP0 = treeMin();
828 chP* nextChP = treeSuccessor(chP0);
829 while (nextChP !=
nullptr)
832 nextChP = treeSuccessor(nextChP);
Extends standardChemistryModel by adding the TDAC method.
#define forAll(list, i)
Loop across all elements in list.
void sort()
(stable) sort the list (if changed after construction time)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A list that is sorted upon construction or when explicitly requested with the sort() method...
chemPointISAT< ThermoType > *& leafLeft()
Access.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void balance()
Cheap balance function.
void size(const label)
Override size to be inconsistent with allocated storage.
void insertNewLeaf(const scalarField &phiq, const scalarField &Rphiq, const scalarSquareMatrix &A, const scalarField &scaleFactor, const scalar &epsTol, const label nCols, chP *&phi0)
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
bool secondaryBTSearch(const scalarField &phiq, chP *&x)
void binaryTreeSearch(const scalarField &phiq, bn *node, chP *&nearest)
binaryNode< ThermoType > *& node()
chemPointISAT< ThermoType > *& leafRight()
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
void clear()
Removes every entries of the tree and delete the associated objects.
binaryNode< ThermoType > *& parent()
const scalarField & phi() const
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
volScalarField scalarField(fieldObject, mesh)
binaryNode< ThermoType > *& nodeLeft()
void resetNumRetrieve()
Resets the number of retrieves at each time step.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
void deleteLeaf(chP *&phi0)
Delete a leaf from the binary tree and reshape the binary tree for.
bool inEOA(const scalarField &phiq)
To RETRIEVE the mapping from the stored chemPoint phi, the query.
binaryNode< ThermoType > *& nodeRight()
chP * treeSuccessor(chP *x)
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
binaryTree(TDACChemistryModel< ThermoType > &chemistry, dictionary coeffsDict)
Constructors.
const scalarField & v() const
Topology.
void deleteDemandDrivenData(DataPtr &dataPtr)
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.