31 template<
class CompType,
class ThermoType>
38 if (phi0 == phi0->node()->leafRight())
40 phi0->node()->leafRight() =
nullptr;
41 phi0->node()->nodeRight() = newNode;
44 else if (phi0 == phi0->node()->leafLeft())
46 phi0->node()->leafLeft() =
nullptr;
47 phi0->node()->nodeLeft() = newNode;
54 <<
"trying to insert a node with a wrong pointer to a chemPoint" 59 template<
class CompType,
class ThermoType>
67 if ((n2ndSearch_ < max2ndSearch_) && (y!=
nullptr))
71 const scalar a = y->a();
73 for (
label i=0; i<phiq.size(); i++)
79 if (y->nodeLeft() ==
nullptr)
82 if (y->leafLeft()->inEOA(phiq))
90 if (inSubTree(phiq, y->nodeLeft(),
x))
97 if ((n2ndSearch_ < max2ndSearch_) && y->nodeRight() ==
nullptr)
101 if (y->leafRight()->inEOA(phiq))
114 return inSubTree(phiq, y->nodeRight(),
x);
119 if (y->nodeRight() ==
nullptr)
122 if (y->leafRight()->inEOA(phiq))
129 if (inSubTree(phiq, y->nodeRight(),
x))
137 if ((n2ndSearch_ < max2ndSearch_) && y->nodeLeft() ==
nullptr)
140 if (y->leafLeft()->inEOA(phiq))
153 return inSubTree(phiq, y->nodeLeft(),
x);
164 template<
class CompType,
class ThermoType>
167 if (subTreeRoot !=
nullptr)
171 deleteSubTree(subTreeRoot->nodeLeft());
172 deleteSubTree(subTreeRoot->nodeRight());
178 template<
class CompType,
class ThermoType>
184 if (u->parent() ==
nullptr)
189 else if (u == u->parent()->nodeLeft())
191 u->parent()->nodeLeft() = v;
194 else if (u == u->parent()->nodeRight())
196 u->parent()->nodeRight() = v;
201 <<
"wrong addressing of the initial node" 204 v->parent() = u->parent();
209 <<
"trying to transplant a nullptr node" 215 template<
class CompType,
class ThermoType>
219 if (y->parent() !=
nullptr)
221 if (y == y->parent()->nodeLeft())
224 return y->parent()->leafRight();
226 else if (y == y->parent()->nodeRight())
228 return y->parent()->leafLeft();
233 <<
"wrong addressing of the initial node" 244 template<
class CompType,
class ThermoType>
250 if (x == x->node()->leafLeft())
254 return x->node()->leafRight();
256 else if (x == x->node()->leafRight())
259 return x->node()->leafLeft();
264 <<
"wrong addressing of the initial leaf" 274 template<
class CompType,
class ThermoType>
278 if (y->parent()!=
nullptr)
280 if (y == y->parent()->nodeLeft())
283 return y->parent()->nodeRight();
285 else if (y == y->parent()->nodeRight())
287 return y->parent()->nodeLeft();
292 <<
"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();
320 <<
"wrong addressing of the initial leaf" 329 template<
class CompType,
class ThermoType>
332 if (subTreeRoot !=
nullptr)
334 deleteAllNode(subTreeRoot->nodeLeft());
335 deleteAllNode(subTreeRoot->nodeRight());
343 template<
class CompType,
class ThermoType>
350 chemistry_(chemistry),
356 coeffsDict_(coeffsDict)
361 template<
class CompType,
class ThermoType>
365 if (subTreeRoot ==
nullptr)
382 template<
class CompType,
class ThermoType>
389 const scalar& epsTol,
413 root_->leafLeft()=newChemPoint;
420 binaryTreeSearch(phiq, root_,phi0);
423 bn* parentNode = phi0->
node();
446 newNode =
new bn(phi0, newChemPoint, parentNode);
448 insertNode(phi0, newNode);
454 newNode =
new bn(phi0, newChemPoint,
nullptr);
458 phi0->
node() = newNode;
459 newChemPoint->
node()=newNode;
465 template<
class CompType,
class ThermoType>
477 const scalar& a = node->
a();
479 for (
label i=0; i<phiq.
size(); i++) vPhi += phiq[i]*v[i];
486 binaryTreeSearch(phiq, node->
nodeRight(), nearest);
498 binaryTreeSearch(phiq, node->
nodeLeft(), nearest);
510 nearest = root_->leafLeft();
519 template<
class CompType,
class ThermoType>
528 if ((n2ndSearch_ < max2ndSearch_) && (size_ > 1))
530 chP* xS = chemPSibling(x);
540 else if (inSubTree(phiq, nodeSibling(x),x))
547 while((y->
parent()!=
nullptr) && (n2ndSearch_ < max2ndSearch_))
549 xS = chemPSibling(y);
559 else if (inSubTree(phiq, nodeSibling(y),x))
577 template<
class CompType,
class ThermoType>
589 chP* siblingPhi0 = chemPSibling(phi0);
591 if (siblingPhi0 !=
nullptr)
594 if (z->
parent() ==
nullptr)
597 root_->leafLeft()=siblingPhi0;
598 siblingPhi0->
node()=root_;
600 else if (z == z->
parent()->nodeLeft())
602 z->
parent()->leafLeft() = siblingPhi0;
603 z->
parent()->nodeLeft() =
nullptr;
606 else if (z == z->
parent()->nodeRight())
608 z->
parent()->leafRight() = siblingPhi0;
609 z->
parent()->nodeRight() =
nullptr;
615 <<
"wrong addressing of the initial leaf" 621 x = nodeSibling(phi0);
629 <<
"inconsistent structure of the tree, no leaf and no node" 640 template<
class CompType,
class ThermoType>
655 chemPoints[chPi++] =
x;
656 x = treeSuccessor(x);
667 variance[vi] +=
sqr(phij[vi]-mean[vi]);
672 scalar maxVariance(-1.0);
676 if (maxVariance < variance[vi])
678 maxVariance = variance[vi];
690 phiMaxDir[j] = chemPoints[j]->phi()[maxDir];
701 chemPoints[phiMaxDir.
indices()[0]],
702 chemPoints[phiMaxDir.
indices()[phiMaxDir.
size()-1]],
707 chemPoints[phiMaxDir.
indices()[0]]->node() = newNode;
708 chemPoints[phiMaxDir.
indices()[phiMaxDir.
size()-1]]->node() = newNode;
710 for (
label cpi=1; cpi<chemPoints.
size()-1; cpi++)
715 chemPoints[phiMaxDir.
indices()[cpi]]->phi(),
721 new bn(phi0,chemPoints[phiMaxDir.
indices()[cpi]], phi0->
node());
723 insertNode(phi0, nodeToAdd);
724 phi0->
node() = nodeToAdd;
725 chemPoints[phiMaxDir.
indices()[cpi]]->node() = nodeToAdd;
730 template<
class CompType,
class ThermoType>
734 if (subTreeRoot!=
nullptr)
736 while(subTreeRoot->
nodeLeft() !=
nullptr)
738 subTreeRoot = subTreeRoot->
nodeLeft();
749 template<
class CompType,
class ThermoType>
755 if (x == x->
node()->leafLeft())
757 if (x->
node()->nodeRight() ==
nullptr)
759 return x->
node()->leafRight();
763 return treeMin(x->
node()->nodeRight());
766 else if (x == x->
node()->leafRight())
769 while((y->
parent() !=
nullptr))
771 if (y == y->
parent()->nodeLeft())
773 if (y->
parent()->nodeRight() ==
nullptr)
775 return y->
parent()->leafRight();
779 return treeMin(y->
parent()->nodeRight());
792 <<
"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>
830 chP* chP0 = treeMin();
834 chP* nextChP = treeSuccessor(chP0);
835 while (nextChP !=
nullptr)
838 nextChP = treeSuccessor(nextChP);
Extends chemistryModel 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)
binaryNode< CompType, ThermoType > *& node()
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.
chP * treeSuccessor(chP *x)
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...
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 ...
const dimensionedScalar phi0
Magnetic flux quantum: default SI units: [Wb].
bool secondaryBTSearch(const scalarField &phiq, chP *&x)
void binaryTreeSearch(const scalarField &phiq, bn *node, chP *&nearest)
binaryNode< CompType, ThermoType > *& parent()
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< CompType, ThermoType > *& nodeLeft()
label readLabel(Istream &is)
const scalarField & phi() const
const labelList & indices() const
Return the list of sorted indices. Updated every sort.
volScalarField scalarField(fieldObject, mesh)
binaryTree(TDACChemistryModel< CompType, ThermoType > &chemistry, dictionary coeffsDict)
Constructors.
void resetNumRetrieve()
Resets the number of retrieves at each time step.
binaryNode< CompType, ThermoType > *& nodeRight()
chemPointISAT< CompType, ThermoType > *& leafLeft()
Access.
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.
const scalarField & v() const
Topology.
void deleteDemandDrivenData(DataPtr &dataPtr)
chemPointISAT< CompType, ThermoType > *& leafRight()
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.