Commit bafddd77 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: use binary search for polyBoundaryMesh::whichPatch() (issue #801)

parent 32565b4b
...@@ -747,36 +747,41 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const ...@@ -747,36 +747,41 @@ Foam::label Foam::polyBoundaryMesh::whichPatch(const label faceIndex) const
else if (faceIndex >= mesh().nFaces()) else if (faceIndex >= mesh().nFaces())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "given label " << faceIndex << "Face " << faceIndex
<< " greater than the number of geometric faces " << mesh().nFaces() << " out of bounds. Number of geometric faces " << mesh().nFaces()
<< abort(FatalError); << abort(FatalError);
} }
forAll(*this, patchi) // Patches are ordered, use binary search
{
const polyPatch& bp = operator[](patchi);
if const polyPatchList& patches = *this;
const label patchi =
findLower
( (
faceIndex >= bp.start() patches,
&& faceIndex < bp.start() + bp.size() faceIndex,
) 0,
{ // Must include the start in the comparison
return patchi; [](const polyPatch& p, label val) { return (p.start() <= val); }
} );
}
if (patchi < 0 || !patches[patchi].range().found(faceIndex))
{
// If not in any of above, it is trouble! // If not in any of above, it is trouble!
FatalErrorInFunction FatalErrorInFunction
<< "Cannot find face " << faceIndex << " in any of the patches " << "Face " << faceIndex << " not found in any of the patches "
<< names() << nl << flatOutput(names()) << nl
<< "It seems your patches are not consistent with the mesh :" << "The patches appear to be inconsistent with the mesh :"
<< " internalFaces:" << mesh().nInternalFaces() << " internalFaces:" << mesh().nInternalFaces()
<< " total number of faces:" << mesh().nFaces() << " total number of faces:" << mesh().nFaces()
<< abort(FatalError); << abort(FatalError);
return -1; return -1;
}
return patchi;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment