44 bool Foam::meshSearch::findNearer
49 scalar& nearestDistSqr
56 scalar distSqr =
magSqr(points[pointI] - sample);
58 if (distSqr < nearestDistSqr)
60 nearestDistSqr = distSqr;
70 bool Foam::meshSearch::findNearer
76 scalar& nearestDistSqr
83 label pointI = indices[i];
85 scalar distSqr =
magSqr(points[pointI] - sample);
87 if (distSqr < nearestDistSqr)
89 nearestDistSqr = distSqr;
100 Foam::label Foam::meshSearch::findNearestCellTree(
const point& location)
const
102 const indexedOctree<treeDataPoint>& tree = cellCentreTree();
104 scalar span = tree.bb().mag();
110 info = tree.findNearest(location,
Foam::sqr(GREAT));
117 Foam::label Foam::meshSearch::findNearestCellLinear(
const point& location)
const
121 label nearestIndex = 0;
122 scalar minProximity =
magSqr(centres[nearestIndex] - location);
137 Foam::label Foam::meshSearch::findNearestCellWalk
139 const point& location,
140 const label seedCellI
147 "meshSearch::findNearestCellWalk(const point&, const label)"
153 label curCellI = seedCellI;
154 scalar distanceSqr =
magSqr(mesh_.cellCentres()[curCellI] - location);
165 mesh_.cellCells()[curCellI],
176 Foam::label Foam::meshSearch::findNearestFaceTree(
const point& location)
const
179 const indexedOctree<treeDataPoint>& tree = cellCentreTree();
181 scalar span = tree.bb().mag();
189 info = tree.findNearest(location,
Foam::sqr(GREAT));
195 const cell& ownFaces = mesh_.cells()[info.index()];
197 label nearestFaceI = ownFaces[0];
198 scalar minProximity =
magSqr(centres[nearestFaceI] - location);
214 Foam::label Foam::meshSearch::findNearestFaceLinear(
const point& location)
const
218 label nearestFaceI = 0;
219 scalar minProximity =
magSqr(centres[nearestFaceI] - location);
234 Foam::label Foam::meshSearch::findNearestFaceWalk
236 const point& location,
237 const label seedFaceI
244 "meshSearch::findNearestFaceWalk(const point&, const label)"
253 label curFaceI = seedFaceI;
254 scalar distanceSqr =
magSqr(centres[curFaceI] - location);
258 label betterFaceI = curFaceI;
264 mesh_.cells()[mesh_.faceOwner()[curFaceI]],
269 if (mesh_.isInternalFace(curFaceI))
275 mesh_.cells()[mesh_.faceNeighbour()[curFaceI]],
281 if (betterFaceI == curFaceI)
286 curFaceI = betterFaceI;
293 Foam::label Foam::meshSearch::findCellLinear(
const point& location)
const
295 bool cellFound =
false;
300 while ((!cellFound) && (n < mesh_.nCells()))
302 if (pointInCell(location, n))
323 Foam::label Foam::meshSearch::findNearestBoundaryFaceWalk
325 const point& location,
326 const label seedFaceI
333 "meshSearch::findNearestBoundaryFaceWalk"
334 "(const point&, const label)"
340 label curFaceI = seedFaceI;
342 const face&
f = mesh_.faces()[curFaceI];
344 scalar minDist = f.nearestPoint
359 label lastFaceI = curFaceI;
361 const labelList& myEdges = mesh_.faceEdges()[curFaceI];
365 const labelList& neighbours = mesh_.edgeFaces()[myEdges[myEdgeI]];
372 label faceI = neighbours[nI];
376 (faceI >= mesh_.nInternalFaces())
377 && (faceI != lastFaceI)
380 const face& f = mesh_.faces()[faceI];
389 if (curHit.distance() < minDist)
412 label ownerCellI = mesh_.faceOwner()[bFaceI];
414 const point& c = mesh_.cellCentres()[ownerCellI];
417 scalar typDim =
mag(c - bPoint);
419 return tol_*typDim*dir;
426 Foam::meshSearch::meshSearch(
const polyMesh&
mesh,
const bool faceDecomp)
429 faceDecomp_(faceDecomp),
431 boundaryTreePtr_(NULL),
433 cellCentreTreePtr_(NULL)
450 if (!boundaryTreePtr_)
457 labelList bndFaces(mesh_.nFaces()-mesh_.nInternalFaces());
460 bndFaces[i] = mesh_.nInternalFaces() + i;
465 overallBb = overallBb.extend(rndGen, 1
E-4);
466 overallBb.min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
467 overallBb.max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
484 return *boundaryTreePtr_;
499 overallBb = overallBb.extend(rndGen, 1
E-4);
500 overallBb.min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
501 overallBb.max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
517 return *cellTreePtr_;
525 if (!cellCentreTreePtr_)
533 overallBb = overallBb.extend(rndGen, 1
E-4);
534 overallBb.min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
535 overallBb.max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
547 return *cellCentreTreePtr_;
559 const point& ctr = mesh_.cellCentres()[cellI];
562 scalar magDir =
mag(dir);
566 const labelList& cFaces = mesh_.cells()[cellI];
574 label faceI = cFaces[i];
576 pointHit inter = mesh_.faces()[faceI].ray
606 const labelList& f = mesh_.cells()[cellI];
607 const labelList& owner = mesh_.faceOwner();
613 label nFace = f[facei];
614 vector proj = p - cf[nFace];
616 if (owner[nFace] == cellI)
618 if ((normal & proj) > 0)
625 if ((normal & proj) < 0)
639 const point& location,
640 const label seedCellI,
641 const bool useTreeSearch
648 return findNearestCellTree(location);
652 return findNearestCellLinear(location);
657 return findNearestCellWalk(location, seedCellI);
664 const point& location,
665 const label seedFaceI,
666 const bool useTreeSearch
673 return findNearestFaceTree(location);
677 return findNearestFaceLinear(location);
682 return findNearestFaceWalk(location, seedFaceI);
689 const point& location,
690 const label seedCellI,
691 const bool useTreeSearch
695 label nearCellI = findNearestCell(location, seedCellI, useTreeSearch);
699 Pout<<
"findCell : nearCellI:" << nearCellI
700 <<
" ctr:" << mesh_.cellCentres()[nearCellI]
704 if (pointInCell(location, nearCellI))
713 point curPoint = mesh_.cellCentres()[nearCellI];
715 vector edgeVec = location - curPoint;
716 edgeVec /=
mag(edgeVec);
725 Pout<<
"findCell : tracked from curPoint:" << curPoint
726 <<
" nearCellI:" << nearCellI;
729 tracker.
track(location);
734 <<
" need:" << location
736 <<
" cell:" << tracker.
cell()
737 <<
" face:" << tracker.
face() <<
endl;
743 return tracker.
cell();
747 scalar typDim =
sqrt(
mag(mesh_.faceAreas()[tracker.
face()]));
749 if ((
mag(tracker.
position() - location)/typDim) < SMALL)
751 return tracker.
cell();
764 Pout<<
"Searching for next boundary from curPoint:"
766 <<
" to location:" << location <<
endl;
771 Pout<<
"Returned from line search with ";
782 nearCellI = mesh_.faceOwner()[curHit.
index()];
792 return findCellLinear(location);
801 const point& location,
802 const label seedFaceI,
803 const bool useTreeSearch
812 scalar span = tree.
bb().
mag();
822 info = boundaryTree().findNearest
833 scalar minDist = GREAT;
839 label faceI = mesh_.nInternalFaces();
840 faceI < mesh_.nFaces();
844 const face& f = mesh_.faces()[faceI];
864 return findNearestBoundaryFaceWalk(location, seedFaceI);
875 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
880 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
894 vector edgeVec = pEnd - pStart;
895 edgeVec /=
mag(edgeVec);
908 const vector& area = mesh_.faceAreas()[bHit.
index()];
937 boundaryTree().getVolumeType(p)