STYLE: avoid global findIndex() in favour of UList::find()

This commit is contained in:
Mark Olesen
2018-02-21 11:50:34 +01:00
parent c126464d1c
commit 3ee2f3293e
8 changed files with 25 additions and 46 deletions

View File

@ -1253,10 +1253,9 @@ bool Foam::faMeshDecomposition::writeDecomposition()
{ {
const labelList& curEdgeLabels = curPatchEdgeLabels[nPatches]; const labelList& curEdgeLabels = curPatchEdgeLabels[nPatches];
label ngbPolyPatchIndex = const label ngbPolyPatchIndex =
findIndex fvBoundaryProcAddressing.find
( (
fvBoundaryProcAddressing,
meshPatches[curBoundaryAddressing[patchi]] meshPatches[curBoundaryAddressing[patchi]]
.ngbPolyPatchIndex() .ngbPolyPatchIndex()
); );

View File

@ -250,17 +250,21 @@ labelList identity(const label len);
template<class ListType> template<class ListType>
label findIndex label findIndex
( (
const ListType&, const ListType& input,
typename ListType::const_reference, typename ListType::const_reference val,
const label start=0 const label start=0
); )
{
return input.find(val, start);
}
//- Find all occurences of given element. Linear search. //- Find all occurences of given element. Linear search.
template<class ListType> template<class ListType>
labelList findIndices labelList findIndices
( (
const ListType& l, const ListType& input,
typename ListType::const_reference t, typename ListType::const_reference val,
const label start=0 const label start=0
); );

View File

@ -565,29 +565,6 @@ void Foam::invertManyToMany
} }
template<class ListType>
Foam::label Foam::findIndex
(
const ListType& l,
typename ListType::const_reference t,
const label start
)
{
label index = -1;
for (label i = start; i < l.size(); i++)
{
if (l[i] == t)
{
index = i;
break;
}
}
return index;
}
template<class ListType> template<class ListType>
Foam::labelList Foam::findIndices Foam::labelList Foam::findIndices
( (

View File

@ -90,8 +90,8 @@ void Foam::faGlobalMeshData::updateMesh()
label polyMeshPoint = label polyMeshPoint =
mesh_.patch().meshPoints()[localPointLabels[pointI]]; mesh_.patch().meshPoints()[localPointLabels[pointI]];
label sharedPolyMeshPoint = const label sharedPolyMeshPoint =
findIndex(polyMeshSharedPointLabels, polyMeshPoint); polyMeshSharedPointLabels.find(polyMeshPoint);
if if
( (
@ -124,9 +124,9 @@ void Foam::faGlobalMeshData::updateMesh()
sharedPointAddr_.setSize(sharedPointLabels_.size()); sharedPointAddr_.setSize(sharedPointLabels_.size());
forAll(sharedPointAddr_, pointI) forAll(sharedPointAddr_, pointI)
{ {
label polyMeshSharedPointIndex = findIndex const label polyMeshSharedPointIndex =
polyMeshSharedPointLabels.find
( (
polyMeshSharedPointLabels,
mesh_.patch().meshPoints()[sharedPointLabels_[pointI]] mesh_.patch().meshPoints()[sharedPointLabels_[pointI]]
); );

View File

@ -560,7 +560,7 @@ Foam::faMesh::faMesh
{ {
label curFace = edgeFaces[curPMeshEdge][faceI]; label curFace = edgeFaces[curPMeshEdge][faceI];
if (findIndex(faceLabels_, curFace) == -1) if (faceLabels_.found(curFace))
{ {
label polyPatchID = pbm.whichPatch(curFace); label polyPatchID = pbm.whichPatch(curFace);

View File

@ -1647,7 +1647,7 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const
{ {
List<List<vector>> procLsPoints(Pstream::nProcs()); List<List<vector>> procLsPoints(Pstream::nProcs());
label curSharedPointIndex = findIndex(addr, k); const label curSharedPointIndex = addr.find(k);
scalar tol = 0.0; scalar tol = 0.0;

View File

@ -269,8 +269,7 @@ void Foam::processorFaPatch::initUpdateMesh()
const edge& e = patchEdges[edgeI]; const edge& e = patchEdges[edgeI];
indexInEdge[patchPointI] = indexInEdge[patchPointI] = e.find(pointLabels()[patchPointI]);
findIndex(e, pointLabels()[patchPointI]);
} }
OPstream toNeighbProc OPstream toNeighbProc
@ -326,9 +325,9 @@ void Foam::processorFaPatch::updateMesh()
// Find edge and index in edge on this side. // Find edge and index in edge on this side.
const edge& e = patchEdges[nbrPatchEdge[nbrPointI]]; const edge& e = patchEdges[nbrPatchEdge[nbrPointI]];
label index = 1 - nbrIndexInEdge[nbrPointI]; const label index = 1 - nbrIndexInEdge[nbrPointI];
label patchPointI = findIndex(pointLabels(), e[index]); const label patchPointI = pointLabels().find(e[index]);
neighbPoints[patchPointI] = nbrPointI; neighbPoints[patchPointI] = nbrPointI;
} }

View File

@ -197,7 +197,7 @@ void Foam::faPatch::calcPointEdges() const
forAll(curPoints, pointI) forAll(curPoints, pointI)
{ {
label localPointIndex = findIndex(points, curPoints[pointI]); const label localPointIndex = points.find(curPoints[pointI]);
pointEdgs[localPointIndex].append(edgeI); pointEdgs[localPointIndex].append(edgeI);
} }