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
155 label curCelli = seedCelli;
156 scalar distanceSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
167 mesh_.cellCells()[curCelli],
178 Foam::label Foam::meshSearch::findNearestFaceTree(
const point& location)
const 181 const indexedOctree<treeDataCell>& tree = cellTree();
187 magSqr(tree.bb().max()-tree.bb().min())
193 info = tree.findNearest(location,
Foam::sqr(GREAT));
199 const cell& ownFaces = mesh_.cells()[info.index()];
201 label nearestFacei = ownFaces[0];
202 scalar minProximity =
magSqr(centres[nearestFacei] - location);
218 Foam::label Foam::meshSearch::findNearestFaceLinear(
const point& location)
const 222 label nearestFacei = 0;
223 scalar minProximity =
magSqr(centres[nearestFacei] - location);
240 const point& location,
241 const label seedFacei
255 label curFacei = seedFacei;
256 scalar distanceSqr =
magSqr(centres[curFacei] - location);
260 label betterFacei = curFacei;
266 mesh_.cells()[mesh_.faceOwner()[curFacei]],
271 if (mesh_.isInternalFace(curFacei))
277 mesh_.cells()[mesh_.faceNeighbour()[curFacei]],
283 if (betterFacei == curFacei)
288 curFacei = betterFacei;
297 bool cellFound =
false;
302 while ((!cellFound) && (n < mesh_.nCells()))
304 if (mesh_.pointInCell(location, n, cellDecompMode_))
328 const point& location,
329 const label seedCelli
338 if (mesh_.pointInCell(location, seedCelli, cellDecompMode_))
344 label curCelli = seedCelli;
345 scalar nearestDistSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
351 const cell& cFaces = mesh_.cells()[curCelli];
353 label nearestCelli = -1;
357 label facei = cFaces[i];
359 if (mesh_.isInternalFace(facei))
361 label celli = mesh_.faceOwner()[facei];
362 if (celli == curCelli)
364 celli = mesh_.faceNeighbour()[facei];
368 if (mesh_.pointInCell(location, celli, cellDecompMode_))
374 scalar distSqr =
magSqr(mesh_.cellCentres()[celli] - location);
376 if (distSqr < nearestDistSqr)
378 nearestDistSqr = distSqr;
379 nearestCelli = celli;
384 if (nearestCelli == -1)
390 curCelli = nearestCelli;
397 Foam::label Foam::meshSearch::findNearestBoundaryFaceWalk
399 const point& location,
400 const label seedFacei
411 label curFacei = seedFacei;
413 const face& f = mesh_.faces()[curFacei];
415 scalar minDist = f.nearestPoint
430 label lastFacei = curFacei;
432 const labelList& myEdges = mesh_.faceEdges()[curFacei];
436 const labelList& neighbours = mesh_.edgeFaces()[myEdges[myEdgeI]];
443 label facei = neighbours[nI];
447 (facei >= mesh_.nInternalFaces())
448 && (facei != lastFacei)
451 const face& f = mesh_.faces()[facei];
460 if (curHit.distance() < minDist)
483 label ownerCelli = mesh_.faceOwner()[bFacei];
485 const point& c = mesh_.cellCentres()[ownerCelli];
488 scalar typDim =
mag(c - bPoint);
490 return tol_*typDim*dir;
496 Foam::meshSearch::meshSearch
503 cellDecompMode_(cellDecompMode)
514 Foam::meshSearch::meshSearch
522 cellDecompMode_(cellDecompMode)
547 if (!boundaryTreePtr_.valid())
553 if (!overallBbPtr_.valid())
563 overallBb = overallBb.
extend(rndGen, 1
e-4);
564 overallBb.
min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
565 overallBb.
max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
569 labelList bndFaces(mesh_.nFaces()-mesh_.nInternalFaces());
572 bndFaces[i] = mesh_.nInternalFaces() + i;
575 boundaryTreePtr_.reset
593 return boundaryTreePtr_();
600 if (!cellTreePtr_.valid())
606 if (!overallBbPtr_.valid())
616 overallBb = overallBb.
extend(rndGen, 1
e-4);
617 overallBb.
min() -=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
618 overallBb.
max() +=
point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
639 return cellTreePtr_();
731 const point& location,
732 const label seedCelli,
733 const bool useTreeSearch
740 return findNearestCellTree(location);
744 return findNearestCellLinear(location);
749 return findNearestCellWalk(location, seedCelli);
756 const point& location,
757 const label seedFacei,
758 const bool useTreeSearch
765 return findNearestFaceTree(location);
769 return findNearestFaceLinear(location);
774 return findNearestFaceWalk(location, seedFacei);
781 const point& location,
782 const label seedCelli,
783 const bool useTreeSearch
791 return cellTree().findInside(location);
795 return findCellLinear(location);
800 return findCellWalk(location, seedCelli);
807 const point& location,
808 const label seedFacei,
809 const bool useTreeSearch
826 info = boundaryTree().findNearest
837 scalar minDist = GREAT;
843 label facei = mesh_.nInternalFaces();
844 facei < mesh_.nFaces();
848 const face& f = mesh_.faces()[facei];
868 return findNearestBoundaryFaceWalk(location, seedFacei);
879 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
884 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
898 vector edgeVec = pEnd - pStart;
899 edgeVec /=
mag(edgeVec);
912 const vector& area = mesh_.faceAreas()[bHit.
index()];
929 }
while (bHit.
hit());
947 boundaryTreePtr_.clear();
948 cellTreePtr_.clear();
949 overallBbPtr_.clear();
cachedRandom rndGen(label(0),-1)
#define forAll(list, i)
Loop across all elements in list.
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)
A face is a list of labels corresponding to mesh vertices.
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of boundary within segment pStart .. pEnd.
const double e
Elementary charge.
const point & min() const
Minimum describing the bounding box.
label findNearestCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find nearest cell in terms of cell centre.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Encapsulation of data needed to search for faces.
bool hit() const
Is there a hit.
static scalar tol_
Tolerance on linear dimensions.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
void setIndex(const label index)
label findNearestFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
treeBoundBox extend(Random &, const scalar s) const
Return slightly wider bounding box.
dimensionedScalar sqrt(const dimensionedScalar &ds)
const point & max() const
Maximum describing the bounding box.
scalar distance(const vector &p1, const vector &p2)
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
PointIndexHit< point > pointIndexHit
Vector< scalar > vector
A scalar version of the templated Vector.
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.
cellDecomposition
Enumeration defining the decomposition of the cell for.
bool isInside(const point &) const
Determine inside/outside status.
scalar distance() const
Return distance to hit.
vectorField pointField
pointField is a vectorField.
void correct()
Correct for mesh geom/topo changes.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
const indexedOctree< treeDataFace > & boundaryTree() const
Get (demand driven) reference to octree holding all.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
List< label > labelList
A List of labels.
Simple random number generator.
Templated 3D Vector derived from VectorSpace adding construction from 3 components, element access using x(), y() and z() member functions and the inner-product (dot-product) and cross product operators.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
const treeBoundBox & bb() const
Top bounding box.
defineTypeNameAndDebug(combustionModel, 0)
const labelList & tetBasePtIs() const
Return the tetBasePtIs.
pointHit nearestPoint(const point &p, const pointField &) const
Return nearest point to face.
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e...
void clearOut()
Delete all storage.
Template functions to aid in the implementation of demand driven data.
vector point
Point is a vector.
const Type & shapes() const
Reference to shape.
label index() const
Return index.
const Point & hitPoint() const
Return hit point.
Standard boundBox + extra functionality for use in octree.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
Mesh consisting of general polyhedral cells.
PointHit< point > pointHit
label findNearestBoundaryFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
const labelList & faceLabels() const