46 bool Foam::meshSearch::findNearer
51 scalar& nearestDistSqr
58 scalar distSqr =
magSqr(points[pointI] - sample);
60 if (distSqr < nearestDistSqr)
62 nearestDistSqr = distSqr;
72 bool Foam::meshSearch::findNearer
78 scalar& nearestDistSqr
85 label pointI = indices[i];
87 scalar distSqr =
magSqr(points[pointI] - sample);
89 if (distSqr < nearestDistSqr)
91 nearestDistSqr = distSqr;
102 Foam::label Foam::meshSearch::findNearestCellTree(
const point& location)
const 104 const indexedOctree<treeDataCell>& tree = cellTree();
109 magSqr(tree.bb().max()-tree.bb().min())
114 info = tree.findNearest(location,
Foam::sqr(GREAT));
121 Foam::label Foam::meshSearch::findNearestCellLinear(
const point& location)
const 125 label nearestIndex = 0;
126 scalar minProximity =
magSqr(centres[nearestIndex] - location);
143 const point& location,
144 const label seedCellI
151 "meshSearch::findNearestCellWalk(const point&, const label)" 157 label curCellI = seedCellI;
158 scalar distanceSqr =
magSqr(mesh_.cellCentres()[curCellI] - location);
169 mesh_.cellCells()[curCellI],
180 Foam::label Foam::meshSearch::findNearestFaceTree(
const point& location)
const 183 const indexedOctree<treeDataCell>& tree = cellTree();
189 magSqr(tree.bb().max()-tree.bb().min())
195 info = tree.findNearest(location,
Foam::sqr(GREAT));
201 const cell& ownFaces = mesh_.cells()[info.index()];
203 label nearestFaceI = ownFaces[0];
204 scalar minProximity =
magSqr(centres[nearestFaceI] - location);
220 Foam::label Foam::meshSearch::findNearestFaceLinear(
const point& location)
const 224 label nearestFaceI = 0;
225 scalar minProximity =
magSqr(centres[nearestFaceI] - location);
242 const point& location,
243 const label seedFaceI
250 "meshSearch::findNearestFaceWalk(const point&, const label)" 259 label curFaceI = seedFaceI;
260 scalar distanceSqr =
magSqr(centres[curFaceI] - location);
264 label betterFaceI = curFaceI;
270 mesh_.cells()[mesh_.faceOwner()[curFaceI]],
275 if (mesh_.isInternalFace(curFaceI))
281 mesh_.cells()[mesh_.faceNeighbour()[curFaceI]],
287 if (betterFaceI == curFaceI)
292 curFaceI = betterFaceI;
301 bool cellFound =
false;
306 while ((!cellFound) && (n < mesh_.nCells()))
308 if (mesh_.pointInCell(location, n, cellDecompMode_))
332 const point& location,
333 const label seedCellI
340 "meshSearch::findCellWalk(const point&, const label)" 344 if (mesh_.pointInCell(location, seedCellI, cellDecompMode_))
350 label curCellI = seedCellI;
351 scalar nearestDistSqr =
magSqr(mesh_.cellCentres()[curCellI] - location);
357 const cell& cFaces = mesh_.cells()[curCellI];
359 label nearestCellI = -1;
363 label faceI = cFaces[i];
365 if (mesh_.isInternalFace(faceI))
367 label cellI = mesh_.faceOwner()[faceI];
368 if (cellI == curCellI)
370 cellI = mesh_.faceNeighbour()[faceI];
374 if (mesh_.pointInCell(location, cellI, cellDecompMode_))
380 scalar distSqr =
magSqr(mesh_.cellCentres()[cellI] - location);
382 if (distSqr < nearestDistSqr)
384 nearestDistSqr = distSqr;
385 nearestCellI = cellI;
390 if (nearestCellI == -1)
396 curCellI = nearestCellI;
403 Foam::label Foam::meshSearch::findNearestBoundaryFaceWalk
405 const point& location,
406 const label seedFaceI
413 "meshSearch::findNearestBoundaryFaceWalk" 414 "(const point&, const label)" 420 label curFaceI = seedFaceI;
422 const face& f = mesh_.faces()[curFaceI];
424 scalar minDist = f.nearestPoint
439 label lastFaceI = curFaceI;
441 const labelList& myEdges = mesh_.faceEdges()[curFaceI];
445 const labelList& neighbours = mesh_.edgeFaces()[myEdges[myEdgeI]];
452 label faceI = neighbours[nI];
456 (faceI >= mesh_.nInternalFaces())
457 && (faceI != lastFaceI)
460 const face& f = mesh_.faces()[faceI];
469 if (curHit.distance() < minDist)
492 label ownerCellI = mesh_.faceOwner()[bFaceI];
494 const point& c = mesh_.cellCentres()[ownerCellI];
497 scalar typDim =
mag(c - bPoint);
499 return tol_*typDim*dir;
505 Foam::meshSearch::meshSearch
512 cellDecompMode_(cellDecompMode)
523 Foam::meshSearch::meshSearch
531 cellDecompMode_(cellDecompMode)
556 if (!boundaryTreePtr_.valid())
562 if (!overallBbPtr_.valid())
572 overallBb = overallBb.
extend(rndGen, 1
e-4);
573 overallBb.
min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
574 overallBb.
max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
578 labelList bndFaces(mesh_.nFaces()-mesh_.nInternalFaces());
581 bndFaces[i] = mesh_.nInternalFaces() + i;
584 boundaryTreePtr_.reset
602 return boundaryTreePtr_();
609 if (!cellTreePtr_.valid())
615 if (!overallBbPtr_.valid())
625 overallBb = overallBb.
extend(rndGen, 1
e-4);
626 overallBb.
min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
627 overallBb.
max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
648 return cellTreePtr_();
740 const point& location,
741 const label seedCellI,
742 const bool useTreeSearch
749 return findNearestCellTree(location);
753 return findNearestCellLinear(location);
758 return findNearestCellWalk(location, seedCellI);
765 const point& location,
766 const label seedFaceI,
767 const bool useTreeSearch
774 return findNearestFaceTree(location);
778 return findNearestFaceLinear(location);
783 return findNearestFaceWalk(location, seedFaceI);
790 const point& location,
791 const label seedCellI,
792 const bool useTreeSearch
800 return cellTree().findInside(location);
804 return findCellLinear(location);
809 return findCellWalk(location, seedCellI);
816 const point& location,
817 const label seedFaceI,
818 const bool useTreeSearch
835 info = boundaryTree().findNearest
846 scalar minDist = GREAT;
852 label faceI = mesh_.nInternalFaces();
853 faceI < mesh_.nFaces();
857 const face& f = mesh_.faces()[faceI];
877 return findNearestBoundaryFaceWalk(location, seedFaceI);
888 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
893 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
907 vector edgeVec = pEnd - pStart;
908 edgeVec /=
mag(edgeVec);
921 const vector& area = mesh_.faceAreas()[bHit.
index()];
938 }
while (bHit.
hit());
956 boundaryTreePtr_.clear();
957 cellTreePtr_.clear();
958 overallBbPtr_.clear();
dimensionedScalar sqrt(const dimensionedScalar &ds)
Simple random number generator.
cachedRandom rndGen(label(0),-1)
const point & min() const
Minimum describing the bounding box.
const indexedOctree< treeDataFace > & boundaryTree() const
Get (demand driven) reference to octree holding all.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
vector point
Point is a vector.
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of boundary within segment pStart .. pEnd.
dimensioned< scalar > mag(const dimensioned< Type > &)
const labelList & tetBasePtIs() const
Return the tetBasePtIs.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
const Type & shapes() const
Reference to shape.
label findNearestCell(const point &location, const label seedCellI=-1, const bool useTreeSearch=true) const
Find nearest cell in terms of cell centre.
const treeBoundBox & bb() const
Top bounding box.
bool isInside(const point &) const
Determine inside/outside status.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Standard boundBox + extra functionality for use in octree.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
errorManipArg< error, int > exit(error &err, const int errNo=1)
PointIndexHit< point > pointIndexHit
bool hit() const
Is there a hit.
label findNearestFace(const point &location, const label seedFaceI=-1, const bool useTreeSearch=true) const
Encapsulation of data needed to search for faces.
void correct()
Correct for mesh geom/topo changes.
label index() const
Return index.
vectorField pointField
pointField is a vectorField.
PointHit< point > pointHit
const Point & hitPoint() const
Return hit point.
scalar distance(const vector &p1, const vector &p2)
A face is a list of labels corresponding to mesh vertices.
const double e
Elementary charge.
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
label findCell(const point &location, const label seedCellI=-1, const bool useTreeSearch=true) const
Find cell containing location.
treeBoundBox extend(Random &, const scalar s) const
Return slightly wider bounding box.
const labelList & faceLabels() const
Field< vector > vectorField
Specialisation of Field<T> for vector.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Template functions to aid in the implementation of demand driven data.
const point & max() const
Maximum describing the bounding box.
void setIndex(const label index)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
scalar distance() const
Return distance to hit.
Mesh consisting of general polyhedral cells.
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
pointHit nearestPoint(const point &p, const pointField &) const
Return nearest point to face.
List< label > labelList
A List of labels.
label findNearestBoundaryFace(const point &location, const label seedFaceI=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
Vector< scalar > vector
A scalar version of the templated Vector.
void clearOut()
Delete all storage.
static scalar tol_
Tolerance on linear dimensions.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e...
cellDecomposition
Enumeration defining the decomposition of the cell for.
defineTypeNameAndDebug(combustionModel, 0)