35 template<
class CompType,
class ThermoType>
42 if (
phi0 ==
phi0->node()->leafRight())
45 phi0->node()->leafRight() =
nullptr;
46 phi0->node()->nodeRight() = newNode;
49 else if (
phi0 ==
phi0->node()->leafLeft())
52 phi0->node()->leafLeft() =
nullptr;
53 phi0->node()->nodeLeft() = newNode;
60 <<
"trying to insert a node with a wrong pointer to a chemPoint"
65 template<
class CompType,
class ThermoType>
73 if ((n2ndSearch_ < max2ndSearch_) && (
y !=
nullptr))
77 const scalar a =
y->a();
80 for (label i=0; i<phiq.size(); ++i)
87 if (
y->nodeLeft() ==
nullptr)
91 if (
y->leafLeft()->inEOA(phiq))
100 if (inSubTree(phiq,
y->nodeLeft(),
x))
107 if ((n2ndSearch_ < max2ndSearch_) &&
y->nodeRight() ==
nullptr)
111 if (
y->leafRight()->inEOA(phiq))
124 return inSubTree(phiq,
y->nodeRight(),
x);
130 if (
y->nodeRight() ==
nullptr)
133 if (
y->leafRight()->inEOA(phiq))
140 if (inSubTree(phiq,
y->nodeRight(),
x))
149 if ((n2ndSearch_ < max2ndSearch_) &&
y->nodeLeft() ==
nullptr)
152 if (
y->leafLeft()->inEOA(phiq))
164 return inSubTree(phiq,
y->nodeLeft(),
x);
172 template<
class CompType,
class ThermoType>
175 if (subTreeRoot !=
nullptr)
179 deleteSubTree(subTreeRoot->nodeLeft());
180 deleteSubTree(subTreeRoot->nodeRight());
186 template<
class CompType,
class ThermoType>
192 if (u->parent() ==
nullptr)
197 else if (u == u->parent()->nodeLeft())
199 u->parent()->nodeLeft() = v;
202 else if (u == u->parent()->nodeRight())
204 u->parent()->nodeRight() = v;
209 <<
"wrong addressing of the initial node"
212 v->parent() = u->parent();
217 <<
"trying to transplant a nullptr node"
223 template<
class CompType,
class ThermoType>
227 if (
y->parent() !=
nullptr)
229 if (
y ==
y->parent()->nodeLeft())
232 return y->parent()->leafRight();
234 else if (
y ==
y->parent()->nodeRight())
236 return y->parent()->leafLeft();
240 <<
"wrong addressing of the initial node"
249 template<
class CompType,
class ThermoType>
255 if (
x ==
x->node()->leafLeft())
259 return x->node()->leafRight();
261 else if (
x ==
x->node()->leafRight())
264 return x->node()->leafLeft();
268 <<
"wrong addressing of the initial leaf"
277 template<
class CompType,
class ThermoType>
281 if (
y->parent() !=
nullptr)
283 if (
y ==
y->parent()->nodeLeft())
286 return y->parent()->nodeRight();
288 else if (
y ==
y->parent()->nodeRight())
290 return y->parent()->nodeLeft();
294 <<
"wrong addressing of the initial node"
302 template<
class CompType,
class ThermoType>
308 if (
x ==
x->node()->leafLeft())
311 return x->node()->nodeRight();
313 else if (
x ==
x->node()->leafRight())
316 return x->node()->nodeLeft();
320 <<
"wrong addressing of the initial leaf"
328 template<
class CompType,
class ThermoType>
331 if (subTreeRoot !=
nullptr)
333 deleteAllNode(subTreeRoot->nodeLeft());
334 deleteAllNode(subTreeRoot->nodeRight());
342 template<
class CompType,
class ThermoType>
351 maxNLeafs_(coeffsDict.
get<label>(
"maxNLeafs")),
354 max2ndSearch_(coeffsDict.
getOrDefault(
"max2ndSearch", 0)),
355 coeffsDict_(coeffsDict)
360 template<
class CompType,
class ThermoType>
364 if (subTreeRoot ==
nullptr)
381 template<
class CompType,
class ThermoType>
388 const scalar& epsTol,
412 root_->leafLeft() = newChemPoint;
419 binaryTreeSearch(phiq, root_,
phi0);
445 newNode =
new node(
phi0, newChemPoint, parentNode);
447 insertNode(
phi0, newNode);
453 newNode =
new node(
phi0, newChemPoint,
nullptr);
457 phi0->node() = newNode;
458 newChemPoint->
node()=newNode;
465 template<
class CompType,
class ThermoType>
477 const scalar& a =
node->
a();
479 for (label i=0; i<phiq.size(); ++i)
481 vPhi += phiq[i]*v[i];
513 nearest = root_->leafLeft();
522 template<
class CompType,
class ThermoType>
531 if ((n2ndSearch_ < max2ndSearch_) && (size_ > 1))
543 else if (inSubTree(phiq, nodeSibling(
x),
x))
551 while ((
y->parent()!=
nullptr) && (n2ndSearch_ < max2ndSearch_))
553 xS = chemPSibling(
y);
563 else if (inSubTree(phiq, nodeSibling(
y),
x))
580 template<
class CompType,
class ThermoType>
594 if (siblingPhi0 !=
nullptr)
597 if (z->
parent() ==
nullptr)
600 root_->leafLeft()=siblingPhi0;
601 siblingPhi0->
node()=root_;
603 else if (z == z->
parent()->nodeLeft())
605 z->
parent()->leafLeft() = siblingPhi0;
606 z->
parent()->nodeLeft() =
nullptr;
609 else if (z == z->
parent()->nodeRight())
611 z->
parent()->leafRight() = siblingPhi0;
612 z->
parent()->nodeRight() =
nullptr;
618 <<
"wrong addressing of the initial leaf"
624 x = nodeSibling(
phi0);
632 <<
"inconsistent structure of the tree, no leaf and no node"
644 template<
class CompType,
class ThermoType>
651 label chemPointi = 0;
654 label
n =
x->phi().size();
660 chemPoints[chemPointi++] =
x;
661 x = treeSuccessor(
x);
663 mean /= scalar(size_);
672 variance[vi] +=
sqr(phij[vi] - mean[vi]);
677 scalar maxVariance(-1.0);
681 if (maxVariance < variance[vi])
683 maxVariance = variance[vi];
695 phiMaxDir[j] = chemPoints[j]->phi()[maxDir];
706 chemPoints[phiMaxDir.indices()[0]],
707 chemPoints[phiMaxDir.indices()[phiMaxDir.size()-1]],
712 chemPoints[phiMaxDir.indices()[0]]->node() = newNode;
713 chemPoints[phiMaxDir.indices()[phiMaxDir.size()-1]]->node() = newNode;
715 for (label cpi=1; cpi<chemPoints.size()-1; ++cpi)
720 chemPoints[phiMaxDir.indices()[cpi]]->phi(),
726 new node(
phi0, chemPoints[phiMaxDir.indices()[cpi]],
phi0->node());
728 insertNode(
phi0, nodeToAdd);
729 phi0->node() = nodeToAdd;
730 chemPoints[phiMaxDir.indices()[cpi]]->node() = nodeToAdd;
735 template<
class CompType,
class ThermoType>
739 if (subTreeRoot !=
nullptr)
741 while (subTreeRoot->
nodeLeft() !=
nullptr)
743 subTreeRoot = subTreeRoot->
nodeLeft();
752 template<
class CompType,
class ThermoType>
758 if (
x ==
x->node()->leafLeft())
760 if (
x->node()->nodeRight() ==
nullptr)
762 return x->node()->leafRight();
766 return treeMin(
x->node()->nodeRight());
769 else if (
x ==
x->node()->leafRight())
772 while ((
y->parent() !=
nullptr))
774 if (
y ==
y->parent()->nodeLeft())
776 if (
y->parent()->nodeRight() ==
nullptr)
778 return y->parent()->leafRight();
782 return treeMin(
y->parent()->nodeRight());
795 <<
"inconsistent structure of the tree, no leaf and no node"
803 template<
class CompType,
class ThermoType>
817 template<
class CompType,
class ThermoType>
820 return size_ >= maxNLeafs_;
824 template<
class CompType,
class ThermoType>
835 chemPoint* nextchemPoint = treeSuccessor(chemPoint0);
836 while (nextchemPoint !=
nullptr)
839 nextchemPoint = treeSuccessor(nextchemPoint);