diff --git a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C index 80adedeed0..6c6de9d7e3 100644 --- a/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C +++ b/src/OpenFOAM/algorithms/indexedOctree/indexedOctree.C @@ -2076,7 +2076,7 @@ void Foam::indexedOctree::findSphere if (subBb.overlaps(centre, radiusSqr)) { - findBox(getNode(index), centre, radiusSqr, elements); + findSphere(getNode(index), centre, radiusSqr, elements); } } else if (isContent(index)) diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C index ac73884fa4..24f3cbeb46 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.C +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.C @@ -461,6 +461,55 @@ overlaps } +// Check if any point on shape is inside sphere. +template +< + class Face, + template class FaceList, + class PointField, + class PointType +> +bool +Foam::treeDataPrimitivePatch:: +overlaps +( + const label index, + const point& centre, + const scalar radiusSqr +) const +{ + // 1. Quick rejection: sphere does not intersect face bb at all + if (cacheBb_) + { + if (!bbs_[index].overlaps(centre, radiusSqr)) + { + return false; + } + } + else + { + if (!calcBb(patch_.points(), patch_[index]).overlaps(centre, radiusSqr)) + { + return false; + } + } + + const pointField& points = patch_.points(); + const face& f = patch_[index]; + + pointHit nearHit = f.nearestPoint(centre, points); + + // If the distance to the nearest point on the face from the sphere centres + // is within the radius, then the sphere touches the face. + if (sqr(nearHit.distance()) < radiusSqr) + { + return true; + } + + return false; +} + + // Calculate nearest point to sample. Updates (if any) nearestDistSqr, minIndex, // nearestPoint. template diff --git a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H index b87514a4a2..ba75e7d6dd 100644 --- a/src/meshTools/indexedOctree/treeDataPrimitivePatch.H +++ b/src/meshTools/indexedOctree/treeDataPrimitivePatch.H @@ -120,6 +120,13 @@ public: // (one point per shape) pointField shapePoints() const; + //- Return access to the underlying patch + const PrimitivePatch& + patch() const + { + return patch_; + } + // Search @@ -140,13 +147,21 @@ public: const point& ) const; - //- Does (bb of) shape at index overlap bb + //- Does shape at index overlap bb bool overlaps ( const label index, const treeBoundBox& sampleBb ) const; + //- Does shape at index overlap sphere + bool overlaps + ( + const label index, + const point& centre, + const scalar radiusSqr + ) const; + //- Calculates nearest (to sample) point in shape. // Returns actual point and distance (squared) void findNearest