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));
120 Foam::label Foam::meshSearch::findNearestCellLinear(
const point& location)
const 124 label nearestIndex = 0;
125 scalar minProximity =
magSqr(centres[nearestIndex] - location);
141 const point& location,
142 const label seedCelli
153 label curCelli = seedCelli;
154 scalar distanceSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
165 mesh_.cellCells()[curCelli],
175 Foam::label Foam::meshSearch::findNearestFaceTree(
const point& location)
const 178 const indexedOctree<treeDataCell>& tree = cellTree();
184 magSqr(tree.bb().max()-tree.bb().min())
190 info = tree.findNearest(location,
Foam::sqr(great));
196 const cell& ownFaces = mesh_.cells()[info.index()];
198 label nearestFacei = ownFaces[0];
199 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);
235 const point& location,
236 const label seedFacei
250 label curFacei = seedFacei;
251 scalar distanceSqr =
magSqr(centres[curFacei] - location);
255 label betterFacei = curFacei;
261 mesh_.cells()[mesh_.faceOwner()[curFacei]],
266 if (mesh_.isInternalFace(curFacei))
272 mesh_.cells()[mesh_.faceNeighbour()[curFacei]],
278 if (betterFacei == curFacei)
283 curFacei = betterFacei;
292 bool cellFound =
false;
297 while ((!cellFound) && (n < mesh_.nCells()))
299 if (mesh_.pointInCell(location, n, cellDecompMode_))
322 const point& location,
323 const label seedCelli
332 if (mesh_.pointInCell(location, seedCelli, cellDecompMode_))
338 label curCelli = seedCelli;
339 scalar nearestDistSqr =
magSqr(mesh_.cellCentres()[curCelli] - location);
345 const cell& cFaces = mesh_.cells()[curCelli];
347 label nearestCelli = -1;
351 label facei = cFaces[i];
353 if (mesh_.isInternalFace(facei))
355 label celli = mesh_.faceOwner()[facei];
356 if (celli == curCelli)
358 celli = mesh_.faceNeighbour()[facei];
362 if (mesh_.pointInCell(location, celli, cellDecompMode_))
368 scalar distSqr =
magSqr(mesh_.cellCentres()[celli] - location);
370 if (distSqr < nearestDistSqr)
372 nearestDistSqr = distSqr;
373 nearestCelli = celli;
378 if (nearestCelli == -1)
384 curCelli = nearestCelli;
391 Foam::label Foam::meshSearch::findNearestBoundaryFaceWalk
393 const point& location,
394 const label seedFacei
405 label curFacei = seedFacei;
407 const face& f = mesh_.faces()[curFacei];
409 scalar minDist = f.nearestPoint
424 label lastFacei = curFacei;
426 const labelList& myEdges = mesh_.faceEdges()[curFacei];
430 const labelList& neighbours = mesh_.edgeFaces()[myEdges[myEdgeI]];
437 label facei = neighbours[nI];
441 (facei >= mesh_.nInternalFaces())
442 && (facei != lastFacei)
445 const face& f = mesh_.faces()[facei];
454 if (curHit.distance() <
minDist)
477 label ownerCelli = mesh_.faceOwner()[bFacei];
479 const point& c = mesh_.cellCentres()[ownerCelli];
482 scalar typDim =
mag(c - bPoint);
484 return tol_*typDim*dir;
490 Foam::meshSearch::meshSearch
497 cellDecompMode_(cellDecompMode)
510 Foam::meshSearch::meshSearch
518 cellDecompMode_(cellDecompMode)
547 if (!boundaryTreePtr_.valid())
553 if (!overallBbPtr_.valid())
563 overallBb = overallBb.
extend(1
e-4);
567 labelList bndFaces(mesh_.nFaces()-mesh_.nInternalFaces());
570 bndFaces[i] = mesh_.nInternalFaces() + i;
573 boundaryTreePtr_.reset
591 return boundaryTreePtr_();
598 if (!cellTreePtr_.valid())
604 if (!overallBbPtr_.valid())
614 overallBb = overallBb.
extend(1
e-4);
635 return cellTreePtr_();
641 const point& location,
642 const label seedCelli,
643 const bool useTreeSearch
650 return findNearestCellTree(location);
654 return findNearestCellLinear(location);
659 return findNearestCellWalk(location, seedCelli);
666 const point& location,
667 const label seedFacei,
668 const bool useTreeSearch
675 return findNearestFaceTree(location);
679 return findNearestFaceLinear(location);
684 return findNearestFaceWalk(location, seedFacei);
691 const point& location,
692 const label seedCelli,
693 const bool useTreeSearch
701 return cellTree().findInside(location);
705 return findCellLinear(location);
710 return findCellWalk(location, seedCelli);
717 const point& location,
718 const label seedFacei,
719 const bool useTreeSearch
736 info = boundaryTree().findNearest
747 scalar minDist = great;
753 label facei = mesh_.nInternalFaces();
754 facei < mesh_.nFaces();
758 const face& f = mesh_.faces()[facei];
778 return findNearestBoundaryFaceWalk(location, seedFacei);
789 pointIndexHit curHit = boundaryTree().findLine(pStart, pEnd);
794 curHit.
setIndex(boundaryTree().shapes().faceLabels()[curHit.
index()]);
808 vector edgeVec = pEnd - pStart;
809 edgeVec /=
mag(edgeVec);
822 const vector& area = mesh_.faceAreas()[bHit.
index()];
839 }
while (bHit.
hit());
856 boundaryTreePtr_.clear();
857 cellTreePtr_.clear();
858 overallBbPtr_.clear();
#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)
const indexedOctree< treeDataCell > & cellTree() const
Get (demand driven) reference to octree holding all cells.
A face is a list of labels corresponding to mesh vertices.
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.
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Encapsulation of data needed to search for faces.
static scalar tol_
Tolerance on linear dimensions.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
label findNearestFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
void setIndex(const label index)
dimensionedScalar sqrt(const dimensionedScalar &ds)
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.
cellDecomposition
Enumeration defining the decomposition of the cell for.
scalar minDist(const List< pointIndexHit > &hitList)
const Point & hitPoint() const
Return hit point.
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...
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
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.
bool hit() const
Is there a hit.
const Type & shapes() const
Reference to shape.
List< label > labelList
A List of labels.
const treeBoundBox & bb() const
Top bounding box.
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.
defineTypeNameAndDebug(combustionModel, 0)
Encapsulation of data needed to search in/for cells. Used to find the cell containing a point (e...
void clearOut()
Delete all storage.
label findNearestBoundaryFace(const point &location, const label seedFacei=-1, const bool useTreeSearch=true) const
Find nearest boundary face.
Template functions to aid in the implementation of demand driven data.
const point & max() const
Maximum describing the bounding box.
vector point
Point is a vector.
pointHit nearestPoint(const point &p, const pointField &) const
Return nearest point to face.
Standard boundBox + extra functionality for use in octree.
dimensioned< scalar > mag(const dimensioned< Type > &)
Field< vector > vectorField
Specialisation of Field<T> for vector.
bool isInside(const point &) const
Determine inside/outside status.
const doubleScalar e
Elementary charge.
Mesh consisting of general polyhedral cells.
PointHit< point > pointHit
scalar distance() const
Return distance to hit.
const point & min() const
Minimum describing the bounding box.
List< pointIndexHit > intersections(const point &pStart, const point &pEnd) const
Find all intersections of boundary within segment pStart .. pEnd.
pointIndexHit intersection(const point &pStart, const point &pEnd) const
Find first intersection of boundary in segment [pStart, pEnd].
label index() const
Return index.
const labelList & faceLabels() const
treeBoundBox extend(const scalar s) const
Return asymetrically extended bounding box, with guaranteed.