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)
374 depth(subTreeRoot->nodeLeft()),
375 depth(subTreeRoot->nodeRight())
381 template<
class CompType,
class ThermoType>
388 const scalar& epsTol,
399 chemPoint* newChemPoint =
412 root_->leafLeft() = newChemPoint;
419 binaryTreeSearch(phiq, root_,
phi0);
422 node* parentNode =
phi0->node();
426 chemPoint* newChemPoint =
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];
487 if (node->nodeRight() !=
nullptr)
489 binaryTreeSearch(phiq, node->nodeRight(), nearest);
493 nearest = node->leafRight();
499 if (node->nodeLeft() !=
nullptr)
501 binaryTreeSearch(phiq, node->nodeLeft(), nearest);
505 nearest = node->leafLeft();
513 nearest = root_->leafLeft();
522 template<
class CompType,
class ThermoType>
531 if ((n2ndSearch_ < max2ndSearch_) && (size_ > 1))
533 chemPoint* xS = chemPSibling(
x);
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>
590 node* z =
phi0->node();
592 chemPoint* siblingPhi0 = chemPSibling(
phi0);
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;
607 siblingPhi0->node() = z->parent();
609 else if (z == z->parent()->nodeRight())
611 z->parent()->leafRight() = siblingPhi0;
612 z->parent()->nodeRight() =
nullptr;
613 siblingPhi0->node() = z->parent();
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>
649 chemPoint*
x = treeMin();
650 List<chemPoint*> chemPoints(size_);
651 label chemPointi = 0;
654 label
n =
x->phi().size();
660 chemPoints[chemPointi++] =
x;
661 x = treeSuccessor(
x);
663 mean /= scalar(size_);
666 List<scalar> variance(
n,
Zero);
672 variance[vi] +=
sqr(phij[vi] - mean[vi]);
677 scalar maxVariance(-1.0);
681 if (maxVariance < variance[vi])
683 maxVariance = variance[vi];
692 SortableList<scalar> phiMaxDir(chemPoints.size(),
Zero);
695 phiMaxDir[j] = chemPoints[j]->phi()[maxDir];
704 node* newNode =
new node
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();
745 return subTreeRoot->leafLeft();
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>
831 chemPoint* chemPoint0 = treeMin();
832 chemPoint0->resetNumRetrieve();
835 chemPoint* nextchemPoint = treeSuccessor(chemPoint0);
836 while (nextchemPoint !=
nullptr)
838 nextchemPoint->resetNumRetrieve();
839 nextchemPoint = treeSuccessor(nextchemPoint);
void insertNewLeaf(const scalarField &phiq, const scalarField &Rphiq, const scalarSquareMatrix &A, const scalarField &scaleFactor, const scalar &epsTol, const label nCols, chemPoint *&phi0)
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
void size(const label n)
Older name for setAddressableSize.
errorManipArg< error, int > exit(error &err, const int errNo=1)
void binaryTreeSearch(const scalarField &phiq, node *node, chemPoint *&nearest)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void balance()
Cheap balance function.
Leaf of the binary tree. The chemPoint stores the composition 'phi', the mapping of this composition ...
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
bool secondaryBTSearch(const scalarField &phiq, chemPoint *&x)
BasicChemistryModel< psiReactionThermo > & chemistry
#define forAll(list, i)
Loop across all elements in list.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Data storage of the chemistryOnLineLibrary according to a binary tree structure.
void clear()
Removes every entries of the tree and delete the associated objects.
binaryTree(TDACChemistryModel< CompType, ThermoType > &chemistry, dictionary coeffsDict)
Construct from dictionary and chemistryOnLineLibrary.
void deleteLeaf(chemPoint *&phi0)
Delete a leaf from the binary tree and reshape the binary tree for.
Template functions to aid in the implementation of demand driven data.
chemPoint * treeSuccessor(chemPoint *x)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
void deleteDemandDrivenData(DataPtr &dataPtr)
SquareMatrix< scalar > scalarSquareMatrix
static constexpr const zero Zero
Global zero (0)