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();
          ...
      }
This commit is contained in:
Mark Olesen
2018-03-06 00:29:03 +01:00
parent 2a6ac7edce
commit 4fe8ed8245
73 changed files with 475 additions and 602 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -425,10 +425,9 @@ restartUncoveredSourceFace
// list of faces currently visited for srcFacei to avoid multiple hits
DynamicList<label> visitedFaces(10);
forAllConstIter(labelHashSet, lowWeightFaces, iter)
for (const label srcFacei : lowWeightFaces)
{
label srcFacei = iter.key();
label tgtFacei = this->findTargetFace(srcFacei);
const label tgtFacei = this->findTargetFace(srcFacei);
if (tgtFacei != -1)
{
//bool faceProcessed =

View File

@ -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.
@ -57,9 +57,8 @@ void Foam::patchPatchDist::correct()
{
// Mark all edge connected to a nbrPatch.
label nBnd = 0;
forAllConstIter(labelHashSet, nbrPatchIDs_, iter)
for (const label nbrPatchi : nbrPatchIDs_)
{
label nbrPatchi = iter.key();
const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
nBnd += nbrPatch.nEdges()-nbrPatch.nInternalEdges();
}
@ -68,9 +67,8 @@ void Foam::patchPatchDist::correct()
// functionality for these.
EdgeMap<label> nbrEdges(2*nBnd);
forAllConstIter(labelHashSet, nbrPatchIDs_, iter)
for (const label nbrPatchi : nbrPatchIDs_)
{
label nbrPatchi = iter.key();
const polyPatch& nbrPatch = patch_.boundaryMesh()[nbrPatchi];
const labelList& nbrMp = nbrPatch.meshPoints();
@ -78,7 +76,7 @@ void Foam::patchPatchDist::correct()
(
label edgeI = nbrPatch.nInternalEdges();
edgeI < nbrPatch.nEdges();
edgeI++
++edgeI
)
{
const edge& e = nbrPatch.edges()[edgeI];

View File

@ -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.
@ -805,7 +805,7 @@ Foam::label Foam::cellClassification::fillRegionPoints
{
label nTotChanged = 0;
for (label iter = 0; iter < maxIter; iter++)
for (label iter = 0; iter < maxIter; ++iter)
{
// Get interface between meshType cells and non-meshType cells as a list
// of faces and for each face the cell which is the meshType.
@ -826,26 +826,25 @@ Foam::label Foam::cellClassification::fillRegionPoints
label nChanged = 0;
forAllConstIter(labelHashSet, nonManifoldPoints, iter)
for (const label nonManPti : nonManifoldPoints)
{
// Find a face on fp using point and remove it.
const label patchPointi = meshPointMap[iter.key()];
const label patchPointi = meshPointMap[nonManPti];
const labelList& pFaces = fp.pointFaces()[patchPointi];
// Remove any face using conflicting point. Does first face which
// has not yet been done. Could be more intelligent and decide which
// one would be best to remove.
forAll(pFaces, i)
for (const label patchFacei : pFaces)
{
const label patchFacei = pFaces[i];
const label ownerCell = outsideOwner[patchFacei];
if (operator[](ownerCell) == meshType)
{
operator[](ownerCell) = fillType;
nChanged++;
++nChanged;
break;
}
}

View File

@ -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.
@ -61,10 +61,8 @@ void Foam::patchToFace::combine(topoSet& set, const bool add) const
true // use patch groups if available
);
forAllConstIter(labelHashSet, patchIDs, iter)
for (const label patchi : patchIDs)
{
label patchi = iter.key();
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
Info<< " Found matching patch " << pp.name()

View File

@ -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.
@ -136,23 +136,24 @@ void Foam::topoSet::updateLabels(const labelList& map)
// Iterate over map to see if anything changed
bool changed = false;
forAllConstIter(labelHashSet, *this, iter)
const labelHashSet& labels = *this;
for (const label oldId : labels)
{
if ((iter.key() < 0) || (iter.key() > map.size()))
if (oldId < 0 || oldId > map.size())
{
FatalErrorInFunction
<< "Illegal content " << iter.key() << " of set:" << name()
<< "Illegal content " << oldId << " of set:" << name()
<< " of type " << type() << endl
<< "Value should be between 0 and " << map.size()-1
<< "Value should be between [0," << map.size() << ')'
<< abort(FatalError);
}
const label newCelli = map[iter.key()];
const label newId = map[oldId];
if (newCelli != iter.key())
if (newId != oldId)
{
changed = true;
break;
}
}
@ -162,13 +163,13 @@ void Foam::topoSet::updateLabels(const labelList& map)
{
labelHashSet newSet(2*size());
forAllConstIter(labelHashSet, *this, iter)
for (const label oldId : labels)
{
const label newCelli = map[iter.key()];
const label newId = map[oldId];
if (newCelli >= 0)
if (newId >= 0)
{
newSet.insert(newCelli);
newSet.insert(newId);
}
}
@ -179,14 +180,16 @@ void Foam::topoSet::updateLabels(const labelList& map)
void Foam::topoSet::check(const label maxLabel)
{
forAllConstIter(topoSet, *this, iter)
const labelHashSet& labels = *this;
for (const label oldId : labels)
{
if ((iter.key() < 0) || (iter.key() > maxLabel))
if (oldId < 0 || oldId > maxLabel)
{
FatalErrorInFunction
<< "Illegal content " << iter.key() << " of set:" << name()
<< " of type " << type() << endl
<< "Value should be between 0 and " << maxLabel
<< "Illegal content " << oldId << " of set:" << name()
<< " of type " << type() << nl
<< "Value should be between [0," << maxLabel << ']'
<< abort(FatalError);
}
}
@ -206,14 +209,14 @@ void Foam::topoSet::writeDebug
for (; (iter != end()) && (n < maxElem); ++iter)
{
if ((n != 0) && ((n % 10) == 0))
if (n && ((n % 10) == 0))
{
os << endl;
}
os << iter.key() << ' ';
n++;
elemI++;
++n;
++elemI;
}
}
@ -232,14 +235,14 @@ void Foam::topoSet::writeDebug
for (; (iter != end()) && (n < maxElem); ++iter)
{
if ((n != 0) && ((n % 3) == 0))
if (n && ((n % 3) == 0))
{
os << endl;
}
os << iter.key() << coords[iter.key()] << ' ';
n++;
elemI++;
++n;
++elemI;
}
}
@ -488,12 +491,12 @@ void Foam::topoSet::subset(const topoSet& set)
clear();
resize(2*min(currentSet.size(), set.size()));
forAllConstIter(labelHashSet, currentSet, iter)
for (const label currId : currentSet)
{
if (set.found(iter.key()))
if (set.found(currId))
{
// element present in both currentSet and set.
insert(iter.key());
insert(currId);
}
}
}
@ -501,18 +504,20 @@ void Foam::topoSet::subset(const topoSet& set)
void Foam::topoSet::addSet(const topoSet& set)
{
forAllConstIter(topoSet, set, iter)
const labelHashSet& labels = set;
for (const label id : labels)
{
insert(iter.key());
insert(id);
}
}
void Foam::topoSet::deleteSet(const topoSet& set)
{
forAllConstIter(topoSet, set, iter)
const labelHashSet& labels = set;
for (const label id : labels)
{
erase(iter.key());
erase(id);
}
}

View File

@ -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.
@ -121,18 +121,16 @@ License
// // Snap outside points to surface
// pointField newPoints(points);
//
// forAllConstIter(labelHashSet, flatCandidates, iter)
// for (const label celli : flatCandidates)
// {
// const cell& cFaces = cells[iter.key()];
// const cell& cFaces = cells[celli];
//
// forAll(cFaces, cFacei)
// for (const label facei : cFaces)
// {
// const face& f = faces[cFaces[cFacei]];
// const face& f = faces[facei];
//
// forAll(f, fp)
// for (const label pointi : f)
// {
// label pointi = f[fp];
//
// if (outsidePoints.insert(pointi))
// {
// // Calculate new position for this outside point
@ -147,10 +145,8 @@ License
//
// // Calculate new volume for mixed cells
// label nRemoved = 0;
// forAllConstIter(labelHashSet, flatCandidates, iter)
// for (const label celli : flatCandidates)
// {
// label celli = iter.key();
//
// const cell& cll = cells[celli];
//
// scalar newVol = cll.mag(newPoints, faces);
@ -374,20 +370,19 @@ Foam::labelHashSet Foam::surfaceSets::getHangingCells
labelHashSet mixedOnlyCells(internalCells.size());
forAllConstIter(labelHashSet, internalCells, iter)
for (const label celli : internalCells)
{
const label celli = iter.key();
const cell& cFaces = cells[celli];
label usesMixedOnly = true;
forAll(cFaces, i)
for (const label facei : cFaces)
{
const face& f = faces[cFaces[i]];
const face& f = faces[facei];
forAll(f, fp)
for (const label pointi : f)
{
if (pointSide[f[fp]] != MIXED)
if (pointSide[pointi] != MIXED)
{
usesMixedOnly = false;
break;

View File

@ -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.
@ -2294,31 +2294,26 @@ Foam::triSurface Foam::triSurfaceTools::triangulate
label newPatchi = 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();
label nTriTotal = 0;
forAll(patch, patchFacei)
for (const face& f : patch)
{
const face& f = patch[patchFacei];
faceList triFaces(f.nTriangles(points));
label nTri = 0;
f.triangles(points, nTri, triFaces);
forAll(triFaces, triFacei)
for (const face& f : triFaces)
{
const face& f = triFaces[triFacei];
triangles.append(labelledTri(f[0], f[1], f[2], newPatchi));
nTriTotal++;
++nTriTotal;
}
}
@ -2348,9 +2343,8 @@ Foam::triSurface Foam::triSurfaceTools::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].name() = patch.name();
@ -2399,9 +2393,8 @@ Foam::triSurface Foam::triSurfaceTools::triangulateFaceCentre
label newPatchi = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const label patchi = iter.key();
const polyPatch& patch = bMesh[patchi];
label nTriTotal = 0;
@ -2451,9 +2444,8 @@ Foam::triSurface Foam::triSurfaceTools::triangulateFaceCentre
newPatchi = 0;
forAllConstIter(labelHashSet, includePatches, iter)
for (const label patchi : includePatches)
{
const label patchi = iter.key();
const polyPatch& patch = bMesh[patchi];
surface.patches()[newPatchi].name() = patch.name();