34 template<
class CompType,
class ThermoType>
41 if (
phi0 ==
phi0->node()->leafRight())
44 phi0->node()->leafRight() =
nullptr;
45 phi0->node()->nodeRight() = newNode;
48 else if (
phi0 ==
phi0->node()->leafLeft())
51 phi0->node()->leafLeft() =
nullptr;
52 phi0->node()->nodeLeft() = newNode;
59 <<
"trying to insert a node with a wrong pointer to a chemPoint"
64 template<
class CompType,
class ThermoType>
72 if ((n2ndSearch_ < max2ndSearch_) && (
y !=
nullptr))
76 const scalar a =
y->a();
79 for (
label i=0; i<phiq.size(); ++i)
86 if (
y->nodeLeft() ==
nullptr)
90 if (
y->leafLeft()->inEOA(phiq))
99 if (inSubTree(phiq,
y->nodeLeft(),
x))
106 if ((n2ndSearch_ < max2ndSearch_) &&
y->nodeRight() ==
nullptr)
110 if (
y->leafRight()->inEOA(phiq))
123 return inSubTree(phiq,
y->nodeRight(),
x);
129 if (
y->nodeRight() ==
nullptr)
132 if (
y->leafRight()->inEOA(phiq))
139 if (inSubTree(phiq,
y->nodeRight(),
x))
148 if ((n2ndSearch_ < max2ndSearch_) &&
y->nodeLeft() ==
nullptr)
151 if (
y->leafLeft()->inEOA(phiq))
163 return inSubTree(phiq,
y->nodeLeft(),
x);
171 template<
class CompType,
class ThermoType>
174 if (subTreeRoot !=
nullptr)
178 deleteSubTree(subTreeRoot->nodeLeft());
179 deleteSubTree(subTreeRoot->nodeRight());
185 template<
class CompType,
class ThermoType>
191 if (u->parent() ==
nullptr)
196 else if (u == u->parent()->nodeLeft())
198 u->parent()->nodeLeft() = v;
201 else if (u == u->parent()->nodeRight())
203 u->parent()->nodeRight() = v;
208 <<
"wrong addressing of the initial node"
211 v->parent() = u->parent();
216 <<
"trying to transplant a nullptr node"
222 template<
class CompType,
class ThermoType>
226 if (
y->parent() !=
nullptr)
228 if (
y ==
y->parent()->nodeLeft())
231 return y->parent()->leafRight();
233 else if (
y ==
y->parent()->nodeRight())
235 return y->parent()->leafLeft();
239 <<
"wrong addressing of the initial node"
248 template<
class CompType,
class ThermoType>
254 if (
x ==
x->node()->leafLeft())
258 return x->node()->leafRight();
260 else if (
x ==
x->node()->leafRight())
263 return x->node()->leafLeft();
267 <<
"wrong addressing of the initial leaf"
276 template<
class CompType,
class ThermoType>
280 if (
y->parent() !=
nullptr)
282 if (
y ==
y->parent()->nodeLeft())
285 return y->parent()->nodeRight();
287 else if (
y ==
y->parent()->nodeRight())
289 return y->parent()->nodeLeft();
293 <<
"wrong addressing of the initial node"
301 template<
class CompType,
class ThermoType>
307 if (
x ==
x->node()->leafLeft())
310 return x->node()->nodeRight();
312 else if (
x ==
x->node()->leafRight())
315 return x->node()->nodeLeft();
319 <<
"wrong addressing of the initial leaf"
327 template<
class CompType,
class ThermoType>
330 if (subTreeRoot !=
nullptr)
332 deleteAllNode(subTreeRoot->nodeLeft());
333 deleteAllNode(subTreeRoot->nodeRight());
341 template<
class CompType,
class ThermoType>
350 maxNLeafs_(coeffsDict.
get<
label>(
"maxNLeafs")),
354 coeffsDict_(coeffsDict)
359 template<
class CompType,
class ThermoType>
363 if (subTreeRoot ==
nullptr)
380 template<
class CompType,
class ThermoType>
387 const scalar& epsTol,
411 root_->leafLeft() = newChemPoint;
418 binaryTreeSearch(phiq, root_,
phi0);
444 newNode =
new node(
phi0, newChemPoint, parentNode);
446 insertNode(
phi0, newNode);
452 newNode =
new node(
phi0, newChemPoint,
nullptr);
456 phi0->node() = newNode;
457 newChemPoint->
node()=newNode;
464 template<
class CompType,
class ThermoType>
476 const scalar& a =
node->
a();
478 for (
label i=0; i<phiq.size(); ++i)
480 vPhi += phiq[i]*v[i];
512 nearest = root_->leafLeft();
521 template<
class CompType,
class ThermoType>
530 if ((n2ndSearch_ < max2ndSearch_) && (size_ > 1))
542 else if (inSubTree(phiq, nodeSibling(
x),
x))
550 while ((
y->parent()!=
nullptr) && (n2ndSearch_ < max2ndSearch_))
552 xS = chemPSibling(
y);
562 else if (inSubTree(phiq, nodeSibling(
y),
x))
579 template<
class CompType,
class ThermoType>
593 if (siblingPhi0 !=
nullptr)
596 if (z->
parent() ==
nullptr)
599 root_->leafLeft()=siblingPhi0;
600 siblingPhi0->
node()=root_;
602 else if (z == z->
parent()->nodeLeft())
604 z->
parent()->leafLeft() = siblingPhi0;
605 z->
parent()->nodeLeft() =
nullptr;
608 else if (z == z->
parent()->nodeRight())
610 z->
parent()->leafRight() = siblingPhi0;
611 z->
parent()->nodeRight() =
nullptr;
617 <<
"wrong addressing of the initial leaf"
623 x = nodeSibling(
phi0);
631 <<
"inconsistent structure of the tree, no leaf and no node"
643 template<
class CompType,
class ThermoType>
650 label chemPointi = 0;
659 chemPoints[chemPointi++] =
x;
660 x = treeSuccessor(
x);
662 mean /= scalar(size_);
671 variance[vi] +=
sqr(phij[vi] - mean[vi]);
676 scalar maxVariance(-1.0);
680 if (maxVariance < variance[vi])
682 maxVariance = variance[vi];
694 phiMaxDir[j] = chemPoints[j]->phi()[maxDir];
705 chemPoints[phiMaxDir.indices()[0]],
706 chemPoints[phiMaxDir.indices()[phiMaxDir.size()-1]],
711 chemPoints[phiMaxDir.indices()[0]]->node() = newNode;
712 chemPoints[phiMaxDir.indices()[phiMaxDir.size()-1]]->node() = newNode;
714 for (
label cpi=1; cpi<chemPoints.size()-1; ++cpi)
719 chemPoints[phiMaxDir.indices()[cpi]]->phi(),
725 new node(
phi0, chemPoints[phiMaxDir.indices()[cpi]],
phi0->node());
727 insertNode(
phi0, nodeToAdd);
728 phi0->node() = nodeToAdd;
729 chemPoints[phiMaxDir.indices()[cpi]]->node() = nodeToAdd;
734 template<
class CompType,
class ThermoType>
738 if (subTreeRoot !=
nullptr)
740 while (subTreeRoot->
nodeLeft() !=
nullptr)
742 subTreeRoot = subTreeRoot->
nodeLeft();
751 template<
class CompType,
class ThermoType>
757 if (
x ==
x->node()->leafLeft())
759 if (
x->node()->nodeRight() ==
nullptr)
761 return x->node()->leafRight();
765 return treeMin(
x->node()->nodeRight());
768 else if (
x ==
x->node()->leafRight())
771 while ((
y->parent() !=
nullptr))
773 if (
y ==
y->parent()->nodeLeft())
775 if (
y->parent()->nodeRight() ==
nullptr)
777 return y->parent()->leafRight();
781 return treeMin(
y->parent()->nodeRight());
794 <<
"inconsistent structure of the tree, no leaf and no node"
802 template<
class CompType,
class ThermoType>
816 template<
class CompType,
class ThermoType>
819 return size_ >= maxNLeafs_;
823 template<
class CompType,
class ThermoType>
834 chemPoint* nextchemPoint = treeSuccessor(chemPoint0);
835 while (nextchemPoint !=
nullptr)
838 nextchemPoint = treeSuccessor(nextchemPoint);