Commit 4fe8ed82 authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: use direct iteration for HashSet

- The iterator for a HashSet dereferences directly to its key.

- Eg,

      for (const label patchi : patchSet)
      {
          ...
      }
  vs.
      forAllConstIter(labelHashSet, patchSet, iter)
      {
          const label patchi = iter.key();
          ...
      }
parent 2a6ac7ed
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -85,9 +85,8 @@ VoFPatchTransfer::VoFPatchTransfer
Info<< " applying to patches:" << nl;
label pidi = 0;
forAllConstIter(labelHashSet, patchSet, iter)
for (const label patchi : patchSet)
{
const label patchi = iter.key();
patchIDs_[pidi++] = patchi;
Info<< " " << pbm[patchi].name() << endl;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -339,16 +339,17 @@ void subsetTopoSets
// Map the data
bitSet isSet(set.maxSize(mesh));
forAllConstIter(labelHashSet, set, iter)
for (const label id : set)
{
isSet.set(iter.key());
isSet.set(id);
}
label nSet = 0;
forAll(map, i)
for (const label id : map)
{
if (isSet[map[i]])
if (isSet.test(id))
{
nSet++;
++nSet;
}
}
......@@ -358,9 +359,10 @@ void subsetTopoSets
new TopoSet(subMesh, set.name(), nSet, IOobject::AUTO_WRITE)
);
TopoSet& subSet = subSets[i];
forAll(map, i)
{
if (isSet[map[i]])
if (isSet.test(map[i]))
{
subSet.insert(i);
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -92,12 +92,12 @@ label mergePatchFaces
{
// Store the faces of the face sets
List<faceList> allFaceSetsFaces(allFaceSets.size());
forAll(allFaceSets, setI)
forAll(allFaceSets, seti)
{
allFaceSetsFaces[setI] = UIndirectList<face>
allFaceSetsFaces[seti] = UIndirectList<face>
(
mesh.faces(),
allFaceSets[setI]
allFaceSets[seti]
);
}
......@@ -146,13 +146,13 @@ label mergePatchFaces
// Sets where the master is in error
labelHashSet errorSets;
forAll(allFaceSets, setI)
forAll(allFaceSets, seti)
{
label newMasterI = map().reverseFaceMap()[allFaceSets[setI][0]];
label newMasterI = map().reverseFaceMap()[allFaceSets[seti][0]];
if (errorFaces.found(newMasterI))
{
errorSets.insert(setI);
errorSets.insert(seti);
}
}
label nErrorSets = returnReduce(errorSets.size(), sumOp<label>());
......@@ -162,14 +162,12 @@ label mergePatchFaces
<< " These will be restored to their original faces."
<< endl;
if (nErrorSets > 0)
if (nErrorSets)
{
// Renumber stored faces to new vertex numbering.
forAllConstIter(labelHashSet, errorSets, iter)
for (const label seti : errorSets)
{
label setI = iter.key();
faceList& setFaceVerts = allFaceSetsFaces[setI];
faceList& setFaceVerts = allFaceSetsFaces[seti];
forAll(setFaceVerts, i)
{
......@@ -183,8 +181,8 @@ label mergePatchFaces
if (newVertI < 0)
{
FatalErrorInFunction
<< "In set:" << setI << " old face labels:"
<< allFaceSets[setI] << " new face vertices:"
<< "In set:" << seti << " old face labels:"
<< allFaceSets[seti] << " new face vertices:"
<< setFaceVerts[i] << " are unmapped vertices!"
<< abort(FatalError);
}
......@@ -198,12 +196,10 @@ label mergePatchFaces
// Restore faces
forAllConstIter(labelHashSet, errorSets, iter)
for (const label seti : errorSets)
{
label setI = iter.key();
const labelList& setFaces = allFaceSets[setI];
const faceList& setFaceVerts = allFaceSetsFaces[setI];
const labelList& setFaces = allFaceSets[seti];
const faceList& setFaceVerts = allFaceSetsFaces[seti];
label newMasterI = map().reverseFaceMap()[setFaces[0]];
......@@ -241,7 +237,7 @@ label mergePatchFaces
// Add the previously removed faces
for (label i = 1; i < setFaces.size(); i++)
for (label i = 1; i < setFaces.size(); ++i)
{
Pout<< "Restoring removed face " << setFaces[i]
<< " with vertices " << setFaceVerts[i] << endl;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -300,9 +300,8 @@ void addCutNeighbours
labelHashSet addCutFaces(cutCells.size());
forAllConstIter(labelHashSet, cutCells, iter)
for (const label celli : cutCells)
{
const label celli = iter.key();
const labelList& cFaces = mesh.cells()[celli];
forAll(cFaces, i)
......@@ -333,9 +332,9 @@ void addCutNeighbours
Info<< " Selected an additional " << addCutFaces.size()
<< " neighbours of cutCells to refine" << endl;
forAllConstIter(labelHashSet, addCutFaces, iter)
for (const label facei : addCutFaces)
{
cutCells.insert(iter.key());
cutCells.insert(facei);
}
}
......@@ -383,10 +382,9 @@ bool limitRefinementLevel
labelHashSet addCutCells(cutCells.size());
forAllConstIter(labelHashSet, cutCells, iter)
for (const label celli : cutCells)
{
// cellI will be refined.
const label celli = iter.key();
// celli will be refined.
const labelList& cCells = mesh.cellCells()[celli];
forAll(cCells, i)
......@@ -411,9 +409,9 @@ bool limitRefinementLevel
<< " to satisfy 1:" << limitDiff << " refinement level"
<< endl;
forAllConstIter(labelHashSet, addCutCells, iter)
for (const label celli : addCutCells)
{
cutCells.insert(iter.key());
cutCells.insert(celli);
}
return true;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -360,9 +360,9 @@ void writePointCells
label vertI = 0;
forAllConstIter(labelHashSet, allEdges, iter)
for (const label edgei : allEdges)
{
const edge& e = mesh.edges()[iter.key()];
const edge& e = mesh.edges()[edgei];
meshTools::writeOBJ(pointStream, mesh.points()[e[0]]); vertI++;
meshTools::writeOBJ(pointStream, mesh.points()[e[1]]); vertI++;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -886,10 +886,10 @@ void Foam::conformalVoronoiMesh::checkCellSizing()
labelHashSet cellsToResizeMap(pMesh.nFaces()/100);
// Find cells that are attached to the faces in wrongFaces.
forAllConstIter(labelHashSet, wrongFaces, iter)
for (const label facei : wrongFaces)
{
const label faceOwner = pMesh.faceOwner()[iter.key()];
const label faceNeighbour = pMesh.faceNeighbour()[iter.key()];
const label faceOwner = pMesh.faceOwner()[facei];
const label faceNeighbour = pMesh.faceNeighbour()[facei];
if (!cellsToResizeMap.found(faceOwner))
{
......@@ -1105,9 +1105,9 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
bitSet ptToBeLimited(pts.size(), false);
forAllConstIter(labelHashSet, wrongFaces, iter)
for (const label facei : wrongFaces)
{
const face f = pMesh.faces()[iter.key()];
const face f = pMesh.faces()[facei];
ptToBeLimited.setMany(f);
}
......@@ -1118,9 +1118,9 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
// const labelListList& ptCells = pMesh.pointCells();
// forAllConstIter(labelHashSet, wrongFaces, iter)
// for (const label facei : wrongFaces)
// {
// const face f = pMesh.faces()[iter.key()];
// const face f = pMesh.faces()[facei];
// forAll(f, fPtI)
// {
......@@ -1132,10 +1132,8 @@ Foam::labelHashSet Foam::conformalVoronoiMesh::checkPolyMeshQuality
// const labelListList& cellPts = pMesh.cellPoints();
// forAllConstIter(labelHashSet, limitCells, iter)
// for (const label celli : limitCells)
// {
// label celli = iter.key();
// const labelList& cP = cellPts[celli];
// ptToBeLimited.setMany(cP);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -394,9 +394,9 @@ void extractSurface
// processor patches)
HashTable<label> patchSize(1024);
label nFaces = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const polyPatch& pp = bMesh[iter.key()];
const polyPatch& pp = bMesh[patchi];
patchSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
......@@ -427,9 +427,9 @@ void extractSurface
// Collect faces on zones
DynamicList<label> faceLabels(nFaces);
DynamicList<label> compactZones(nFaces);
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const polyPatch& pp = bMesh[iter.key()];
const polyPatch& pp = bMesh[patchi];
forAll(pp, i)
{
faceLabels.append(pp.start()+i);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -837,9 +837,9 @@ int main(int argc, char *argv[])
fvMeshMapper mapper(mesh, map());
bool hasWarned = false;
forAllConstIter(wordHashSet, bafflePatches, iter)
for (const word& patchName : bafflePatches)
{
label patchi = mesh.boundaryMesh().findPatchID(iter.key());
label patchi = mesh.boundaryMesh().findPatchID(patchName);
const fvPatchMapper& pm = mapper.boundaryMap()[patchi];
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -699,9 +699,9 @@ int main(int argc, char *argv[])
);
// Repatch faces of the patches.
forAllConstIter(labelHashSet, patchSources, iter)
for (const label patchi : patchSources)
{
const polyPatch& pp = patches[iter.key()];
const polyPatch& pp = patches[patchi];
Info<< "Moving faces from patch " << pp.name()
<< " to patch " << destPatchi << endl;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1131,9 +1131,8 @@ int main(int argc, char *argv[])
// Detect any flips.
const labelHashSet& fff = map().flipFaceFlux();
forAllConstIter(labelHashSet, fff, iter)
for (const label facei : fff)
{
label facei = iter.key();
label masterFacei = faceProcAddressing[facei];
faceProcAddressing[facei] = -masterFacei;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -296,9 +296,8 @@ void Foam::regionSide::walkAllPointConnectedFaces
//
labelHashSet regionEdges(4*regionFaces.size());
forAllConstIter(labelHashSet, regionFaces, iter)
for (const label facei : regionFaces)
{
const label facei = iter.key();
const labelList& fEdges = mesh.faceEdges()[facei];
regionEdges.insertMany(fEdges);
......@@ -313,9 +312,9 @@ void Foam::regionSide::walkAllPointConnectedFaces
labelHashSet visitedPoint(4*regionFaces.size());
// Insert fence points so we don't visit them
forAllConstIter(labelHashSet, fencePoints, iter)
for (const label pointi : fencePoints)
{
visitedPoint.insert(iter.key());
visitedPoint.insert(pointi);
}
labelHashSet visitedEdges(2*fencePoints.size());
......@@ -326,10 +325,8 @@ void Foam::regionSide::walkAllPointConnectedFaces
Info<< "Excluding visit of points:" << visitedPoint << endl;
}
forAllConstIter(labelHashSet, regionFaces, iter)
for (const label facei : regionFaces)
{
const label facei = iter.key();
// Get side of face.
label celli;
......@@ -436,9 +433,9 @@ Foam::regionSide::regionSide
labelHashSet fencePoints(fenceEdges.size());
forAllConstIter(labelHashSet, fenceEdges, iter)
for (const label edgei : fenceEdges)
{
const edge& e = mesh.edges()[iter.key()];
const edge& e = mesh.edges()[edgei];
fencePoints.insert(e.start());
fencePoints.insert(e.end());
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -90,9 +90,8 @@ triSurface triangulate
label newPatchI = 0;
label localTriFaceI = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchI : includePatches)
{
const label patchI = iter.key();
const polyPatch& patch = bMesh[patchI];
const pointField& points = patch.points();
......@@ -147,9 +146,8 @@ triSurface triangulate
newPatchI = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchI : includePatches)
{
const label patchI = iter.key();
const polyPatch& patch = bMesh[patchI];
surface.patches()[newPatchI].index() = patchI;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -210,7 +210,6 @@ int main(int argc, char *argv[])
<< "Cannot find any faceZone name matching "
<< zoneName << endl;
}
}
Info<< "Additionally triangulating faceZones "
<< UIndirectList<word>
......@@ -234,17 +233,17 @@ int main(int argc, char *argv[])
// processor patches)
HashTable<label> patchSize(1024);
label nFaces = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const polyPatch& pp = bMesh[iter.key()];
const polyPatch& pp = bMesh[patchi];
patchSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
HashTable<label> zoneSize(1024);
forAllConstIter(labelHashSet, includeFaceZones, iter)
for (const label zonei : includeFaceZones)
{
const faceZone& pp = fzm[iter.key()];
const faceZone& pp = fzm[zonei];
zoneSize.insert(pp.name(), pp.size());
nFaces += pp.size();
}
......@@ -295,9 +294,9 @@ int main(int argc, char *argv[])
compactZones.setCapacity(nFaces);
// Collect faces on patches
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const polyPatch& pp = bMesh[iter.key()];
const polyPatch& pp = bMesh[patchi];
forAll(pp, i)
{
faceLabels.append(pp.start()+i);
......@@ -305,9 +304,9 @@ int main(int argc, char *argv[])
}
}
// Collect faces on faceZones
forAllConstIter(labelHashSet, includeFaceZones, iter)
for (const label zonei : includeFaceZones)
{
const faceZone& pp = fzm[iter.key()];
const faceZone& pp = fzm[zonei];
forAll(pp, i)
{
faceLabels.append(pp[i]);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -70,7 +70,7 @@ Foam::wordList Foam::fieldNames
}
}
forAllConstIter(wordHashSet, localNamesSet, iter)
if (localNamesSet.size())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -408,7 +408,7 @@ void Foam::readUniformFields
}
}
forAllConstIter(wordHashSet, localNamesSet, iter)
if (localNamesSet.size())
{
FatalErrorInFunction
<< "Fields not synchronised across processors." << endl
......
......@@ -312,10 +312,9 @@ void Foam::fileOperation::addWatches
DynamicList<label> newWatchIndices;