78 point& intersectionPoint
88 const label newFacei =
tree_.shapes().faceLabels()[index];
89 const face& newFace =
mesh.faces()[newFacei];
90 const scalar newDot =
mesh.faceAreas()[newFacei] & (
end - start);
93 const label oldFacei =
hits_[hiti].index();
94 const face& oldFace =
mesh.faces()[oldFacei];
96 mesh.faceAreas()[oldFacei] & (
end - start);
100 hits_[hiti].index() == newFacei
112 treeDataFace::findIntersectOp::operator()
128 bool Foam::meshSearch::findNearer
133 scalar& nearestDistSqr
142 if (distSqr < nearestDistSqr)
144 nearestDistSqr = distSqr;
154 bool Foam::meshSearch::findNearer
160 scalar& nearestDistSqr
167 label pointi = indices[i];
171 if (distSqr < nearestDistSqr)
173 nearestDistSqr = distSqr;
184 Foam::label Foam::meshSearch::findNearestCellTree(
const point& location)
const
186 const indexedOctree<treeDataCell>& tree = cellTree();
191 magSqr(tree.bb().max()-tree.bb().min())
196 info = tree.findNearest(location,
Foam::sqr(GREAT));
202 Foam::label Foam::meshSearch::findNearestCellLinear(
const point& location)
const
206 label nearestIndex = 0;
207 scalar minProximity =
magSqr(centres[nearestIndex] - location);
221 Foam::label Foam::meshSearch::findNearestCellWalk
223 const point& location,
224 const label seedCelli
235 label curCelli = seedCelli;
236 scalar distanceSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
247 mesh_.cellCells()[curCelli],
257 Foam::label Foam::meshSearch::findNearestFaceTree(
const point& location)
const
260 const indexedOctree<treeDataCell>& tree = cellTree();
266 magSqr(tree.bb().max()-tree.bb().min())
272 info = tree.findNearest(location,
Foam::sqr(GREAT));
278 const cell& ownFaces = mesh_.cells()[info.index()];
280 label nearestFacei = ownFaces[0];
281 scalar minProximity =
magSqr(centres[nearestFacei] - location);
296 Foam::label Foam::meshSearch::findNearestFaceLinear(
const point& location)
const
300 label nearestFacei = 0;
301 scalar minProximity =
magSqr(centres[nearestFacei] - location);
315 Foam::label Foam::meshSearch::findNearestFaceWalk
317 const point& location,
318 const label seedFacei
332 label curFacei = seedFacei;
333 scalar distanceSqr =
magSqr(centres[curFacei] - location);
337 label betterFacei = curFacei;
343 mesh_.cells()[mesh_.faceOwner()[curFacei]],
348 if (mesh_.isInternalFace(curFacei))
354 mesh_.cells()[mesh_.faceNeighbour()[curFacei]],
360 if (betterFacei == curFacei)
365 curFacei = betterFacei;
372 Foam::label Foam::meshSearch::findCellLinear(
const point& location)
const
374 bool cellFound =
false;
379 while ((!cellFound) && (
n < mesh_.nCells()))
381 if (mesh_.pointInCell(location,
n, cellDecompMode_))
400 Foam::label Foam::meshSearch::findCellWalk
402 const point& location,
403 const label seedCelli
412 if (mesh_.pointInCell(location, seedCelli, cellDecompMode_))
418 label curCelli = seedCelli;
419 scalar nearestDistSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
425 const cell& cFaces = mesh_.cells()[curCelli];
427 label nearestCelli = -1;
431 label facei = cFaces[i];
433 if (mesh_.isInternalFace(facei))
435 label celli = mesh_.faceOwner()[facei];
436 if (celli == curCelli)
438 celli = mesh_.faceNeighbour()[facei];
442 if (mesh_.pointInCell(location, celli, cellDecompMode_))
448 scalar distSqr =
magSqr(mesh_.cellCentres()[celli] - location);
450 if (distSqr < nearestDistSqr)
452 nearestDistSqr = distSqr;
453 nearestCelli = celli;
458 if (nearestCelli == -1)
464 curCelli = nearestCelli;
471 Foam::label Foam::meshSearch::findNearestBoundaryFaceWalk
473 const point& location,
474 const label seedFacei
485 label curFacei = seedFacei;
487 const face&
f = mesh_.faces()[curFacei];
489 scalar minDist =
f.nearestPoint
504 label lastFacei = curFacei;
506 const labelList& myEdges = mesh_.faceEdges()[curFacei];
510 const labelList& neighbours = mesh_.edgeFaces()[myEdges[myEdgeI]];
517 label facei = neighbours[nI];
521 (facei >= mesh_.nInternalFaces())
522 && (facei != lastFacei)
525 const face&
f = mesh_.faces()[facei];
534 if (curHit.distance() < minDist)
536 minDist = curHit.distance();
551 Foam::meshSearch::meshSearch
558 cellDecompMode_(cellDecompMode)
572 Foam::meshSearch::meshSearch
580 cellDecompMode_(cellDecompMode)
608 if (!overallBbPtr_.valid())
624 return *overallBbPtr_;
631 if (!boundaryTreePtr_.valid())
636 identity(mesh_.nBoundaryFaces(), mesh_.nInternalFaces())
639 boundaryTreePtr_.reset
657 return *boundaryTreePtr_;
665 if (!nonCoupledBoundaryTreePtr_.valid())
670 labelList bndFaces(mesh_.nBoundaryFaces());
679 bndFaces[bndi++] = pp.start()+i;
683 bndFaces.setSize(bndi);
685 nonCoupledBoundaryTreePtr_.reset
703 return *nonCoupledBoundaryTreePtr_;
710 if (!cellTreePtr_.valid())
730 return *cellTreePtr_;
736 const point& location,
737 const label seedCelli,
738 const bool useTreeSearch
745 return findNearestCellTree(location);
749 return findNearestCellLinear(location);
753 return findNearestCellWalk(location, seedCelli);
759 const point& location,
760 const label seedFacei,
761 const bool useTreeSearch
768 return findNearestFaceTree(location);
772 return findNearestFaceLinear(location);
776 return findNearestFaceWalk(location, seedFacei);
782 const point& location,
783 const label seedCelli,
784 const bool useTreeSearch
792 return cellTree().findInside(location);
796 return findCellLinear(location);
800 return findCellWalk(location, seedCelli);
806 const point& location,
807 const label seedFacei,
808 const bool useTreeSearch
825 info = boundaryTree().findNearest
836 scalar minDist = GREAT;
842 label facei = mesh_.nInternalFaces();
843 facei < mesh_.nFaces();
847 const face&
f = mesh_.faces()[facei];
866 return findNearestBoundaryFaceWalk(location, seedFacei);
876 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
881 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
899 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd, iop);
900 if (!curHit.
hit())
break;
903 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
922 boundaryTreePtr_.clear();
923 cellTreePtr_.clear();
924 overallBbPtr_.clear();