Commit 0c893278 authored by Mark Olesen's avatar Mark Olesen

STYLE: update iterator looping

- use range-for when iterating over HashSet

- prefer forAllIters(), forAllConstIters() with automatic decltype
parent a8278f71
......@@ -154,8 +154,7 @@ void cartesianMeshExtractor::createPolyMesh()
label nProcBoundaries(nFaces), patchI(0);
// allocate memory for processor patches
std::map<label, labelLongList>::const_iterator iter;
for (iter = procFaces.begin(); iter!=procFaces.end(); ++iter)
forAllConstIters(procFaces, iter)
{
const label procI = iter->first;
......@@ -182,7 +181,7 @@ void cartesianMeshExtractor::createPolyMesh()
// create processor faces
// they need to be created here because of the correct ordering
patchI = 0;
for (iter = procFaces.begin(); iter!=procFaces.end(); ++iter)
forAllConstIters(procFaces, iter)
{
procBoundaries[patchI].patchStart() = nProcBoundaries;
......
......@@ -203,12 +203,7 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
const Map<label>& globalToLocal = mse.globalToLocalBndPointAddressing();
const labelList& bPoints = mse.boundaryPoints();
for
(
Map<label>::const_iterator iter = globalToLocal.begin();
iter!=globalToLocal.end();
++iter
)
forAllConstIters(globalToLocal, iter)
{
const label bpI = iter();
procPoint[bPoints[bpI]] = true;
......@@ -376,8 +371,6 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
}
// create cells for corner nodes
typedef std::map<std::pair<label, label>, label> mPairToLabelType;
typedef std::map<label, mPairToLabelType> mPointsType;
typedef std::map<label, DynList<label, 3>> ppType;
ppType nodePatches;
......@@ -397,7 +390,7 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
ppfType parPointFaces;
ppType parPointPatches;
forAllConstIter(mPointsType, otherVrts_, iter)
forAllConstIters(otherVrts_, iter)
{
// skip points on feature edges
if (iter->second.size() == 2)
......@@ -504,7 +497,7 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
}
// sort faces sharing corners at the parallel boundaries
forAllIter(ppfType, parPointFaces, iter)
forAllIters(parPointFaces, iter)
{
DynList<DynList<label, 8>, 8>& pFaces = iter->second;
DynList<label, 3>& fPatches = parPointPatches[iter->first];
......@@ -545,7 +538,7 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
}
// sort out point which are not at inter-processor boundaries
forAllConstIter(mPointsType, otherVrts_, iter)
forAllConstIters(otherVrts_, iter)
{
if (iter->second.size() == 2)
{
......@@ -598,7 +591,7 @@ void boundaryLayers::createLayerCells(const labelList& patchLabels)
}
// create layer cells for corner nodes
forAllIter(ppType, nodePatches, iter)
forAllIters(nodePatches, iter)
{
const DynList<label, 3>& patchIDs = iter->second;
DynList<label, 3> pKeys;
......@@ -812,13 +805,7 @@ void boundaryLayers::createNewFacesFromPointsParallel
help::exchangeMap(exchangeData, receivedMap);
exchangeData.clear();
for
(
std::map<label, List<labelledPair>>::const_iterator
iter = receivedMap.begin();
iter!=receivedMap.end();
++iter
)
forAllConstIters(receivedMap, iter)
{
const List<labelledPair>& receivedData = iter->second;
......
......@@ -97,10 +97,8 @@ void boundaryLayers::findPatchesToBeTreatedTogether()
// patches must be treated together if there exist a corner where
// more than three patches meet
const labelHashSet& corners = mPart.corners();
forAllConstIter(labelHashSet, corners, it)
for (const label bpI : corners)
{
const label bpI = it.key();
if (mPart.numberOfFeatureEdgesAtPoint(bpI) > 3)
{
labelHashSet commonPatches;
......@@ -227,7 +225,7 @@ void boundaryLayers::findPatchesToBeTreatedTogether()
}
// store faces for sending
forAllConstIter(Map<label>, otherFaceProc, it)
forAllConstIters(otherFaceProc, it)
{
const label beI = it.key();
......@@ -359,8 +357,7 @@ void boundaryLayers::findPatchesToBeTreatedTogether()
mesh_.points().setSize(nPoints_);
}
std::map<std::pair<label, label>, Pair<label>>::const_iterator it;
for (it = edgeClassification.begin(); it!=edgeClassification.end(); ++it)
forAllConstIters(edgeClassification, it)
{
const std::pair<label, label>& edgePair = it->first;
const Pair<label>& nConvexAndConcave = it->second;
......@@ -481,12 +478,12 @@ void boundaryLayers::findPatchesToBeTreatedTogether()
}
}
forAllConstIter(std::set<label>, commonPatches, it)
forAllConstIters(commonPatches, it)
{
const label patchJ = *it;
treatPatchesWithPatch_[patchJ].clear();
forAllConstIter(std::set<label>, commonPatches, iter)
forAllConstIters(commonPatches, iter)
{
treatPatchesWithPatch_[patchJ].append(*iter);
}
......@@ -494,7 +491,7 @@ void boundaryLayers::findPatchesToBeTreatedTogether()
}
# ifdef DEBUGLayer
for (it = edgeClassification.begin(); it!=edgeClassification.end(); ++it)
forAllConstIters(edgeClassification, it)
{
const std::pair<label, label>& edgePair = it->first;
const Pair<label>& nConvexAndConcave = it->second;
......
......@@ -212,12 +212,7 @@ void boundaryLayers::createNewFacesParallel
label nTreatedEdges(0);
boolList treatEdge(edgeFaces.size(), false);
for
(
Map<label>::const_iterator iter = globalToLocal.begin();
iter!=globalToLocal.end();
++iter
)
forAllConstIters(globalToLocal, iter)
{
const label beI = iter();
......
......@@ -45,12 +45,11 @@ label boundaryLayers::findNewNodeLabel
if (it != otherVrts_.end())
{
const std::map<std::pair<label, label>, label>& m = it->second;
const auto& m = it->second;
std::map<std::pair<label, label>, label>::const_iterator mit;
if (m.size() == 2)
{
for (mit = m.begin(); mit!=m.end(); ++mit)
forAllConstIters(m, mit)
{
if (mit->first.first != pKey)
{
......@@ -60,7 +59,7 @@ label boundaryLayers::findNewNodeLabel
}
else
{
for (mit = m.begin(); mit!=m.end(); ++mit)
forAllConstIters(m, mit)
{
if (mit->first.first == pKey)
{
......@@ -101,13 +100,12 @@ inline void boundaryLayers::createNewCellFromEdge
Info<< "Creating cell for edge with nodes " << e << endl;
Info<< "pKeyI " << pKeyI << endl;
Info<< "pKeyJ " << pKeyJ << endl;
std::map<std::pair<label, label>, label>::const_iterator iter;
for (iter = ms.begin(); iter!=ms.end(); ++iter)
forAllConstIters(ms, iter)
{
Info<< "1. Pair(" << iter->first.first << ", "
<< iter->first.second << ") has value " << iter->second << endl;
}
for (iter = me.begin(); iter!=me.end(); ++iter)
forAllConstIters(me, iter)
{
Info<< "2. Pair(" << iter->first.first << ", "
<< iter->first.second << ") has value " << iter->second << endl;
......@@ -124,8 +122,7 @@ inline void boundaryLayers::createNewCellFromEdge
}
else
{
std::map<std::pair<label, label>, label>::const_iterator it;
for (it = ms.begin(); it!=ms.end(); ++it)
forAllConstIters(ms, it)
{
if
(
......@@ -161,8 +158,7 @@ inline void boundaryLayers::createNewCellFromEdge
}
else
{
std::map<std::pair<label, label>, label>::const_iterator it;
for (it = me.begin(); it!=me.end(); ++it)
forAllConstIters(me, it)
{
if
(
......
......@@ -154,7 +154,7 @@ public:
exchangeData[mse_.beNeiProcs()[procI]].clear();
}
forAllConstIter(Map<label>, globalToLocal, it)
forAllConstIters(globalToLocal, it)
{
const label beI = it();
......@@ -467,12 +467,7 @@ void detectBoundaryLayers::analyseLayers()
layerAtPatch_[i].clear();
}
for
(
patchToLayerType::const_iterator it = patchToLayer.begin();
it!=patchToLayer.end();
++it
)
forAllConstIters(patchToLayer, it)
{
const DynList<label>& layersAtPatch = it->second;
......
......@@ -260,7 +260,7 @@ void extrudeLayer::createNewVertices()
}
// collect the information about markes points at processor boundaries
forAllConstIter(Map<label>, globalToLocal, it)
forAllConstIters(globalToLocal, it)
{
if (frontPoints[it()] & FRONTVERTEX)
{
......@@ -331,7 +331,7 @@ void extrudeLayer::createNewVertices()
dualEdgesMap procPointsDual;
// fill in local data
forAllConstIter(Map<label>, globalToLocal, it)
forAllConstIters(globalToLocal, it)
{
if (frontPoints[it()] & FRONTVERTEXPROCBND)
{
......@@ -364,7 +364,7 @@ void extrudeLayer::createNewVertices()
{
if (Pstream::myProcNo() == procI)
{
forAllConstIter(dualEdgesMap, procPointsDual, it)
forAllConstIters(procPointsDual, it)
{
Pout<< "Point " << it->first
<< " local dual edges " << it->second << endl;
......@@ -461,7 +461,7 @@ void extrudeLayer::createNewVertices()
}
// fill in the exchangeData map
forAllConstIter(dualEdgesMap, procPointsDual, dIter)
forAllConstIters(procPointsDual, dIter)
{
const label pointI = dIter->first;
......@@ -516,7 +516,7 @@ void extrudeLayer::createNewVertices()
{
if (Pstream::myProcNo() == procI)
{
forAllConstIter(dualEdgesMap, procPointsDual, it)
forAllConstIters(procPointsDual, it)
{
Pout<< "Point " << it->first
<< " dual edges " << it->second << endl;
......@@ -529,7 +529,7 @@ void extrudeLayer::createNewVertices()
// Finally, find groups of faces and create new vertices
returnReduce(1, sumOp<label>());
Pout << "Finding groups of edges at vertex" << endl;
forAllConstIter(dualEdgesMap, procPointsDual, dIter)
forAllConstIters(procPointsDual, dIter)
{
const label pointI = dIter->first;
const DynList<edge>& dEdges = dIter->second;
......@@ -834,7 +834,7 @@ void extrudeLayer::movePoints()
}
// create displacements from local data
forAllConstIter(Map<label>, globalToLocal, it)
forAllConstIters(globalToLocal, it)
{
if (it() >= nOrigPoints_)
{
......@@ -910,17 +910,12 @@ void extrudeLayer::movePoints()
}
// calculate displacements of vertices at processor boundaries
for
(
std::map<label, vector>::const_iterator it = normals.begin();
it!=normals.end();
++it
)
forAllConstIters(normals, it)
{
vector n = it->second;
if (mag(n) > VSMALL)
{
n /= mag(n);
n /= mag(n);
}
displacements[it->first - nOrigPoints_] = n*distances[it->first];
}
......
......@@ -301,12 +301,7 @@ void refineBoundaryLayers::activateSpecialMode()
void refineBoundaryLayers::refineLayers()
{
bool refinePatch(false);
for
(
std::map<word, label>::const_iterator it = numLayersForPatch_.begin();
it!=numLayersForPatch_.end();
++it
)
forAllConstIters(numLayersForPatch_, it)
{
if (it->second > 1)
{
......
......@@ -1074,13 +1074,7 @@ void checkMeshDict::updateRenameBoundary
// current state of the dictionary
const dictionary& patchDicts = dict.subDict("newPatchNames");
std::map<word, wordList>::const_iterator it;
for
(
it = patchesFromPatch.begin();
it!=patchesFromPatch.end();
++it
)
forAllConstIters(patchesFromPatch, it)
{
const word& pName = it->first;
const wordList& newNames = it->second;
......@@ -1154,8 +1148,7 @@ void checkMeshDict::updateRenameBoundary
}
}
std::map<word, wordList>::const_iterator it;
for (it = patchesFromPatch.begin(); it!=patchesFromPatch.end(); ++it)
forAllConstIters(patchesFromPatch, it)
{
const word& pName = it->first;
const wordList& newNames = it->second;
......@@ -1186,8 +1179,7 @@ void checkMeshDict::updateRenameBoundary
// newPatchNames is not used
dictionary& newPatchesDict = newDict.subDict("newPatchNames");
std::map<word, wordList>::const_iterator it;
for (it = patchesFromPatch.begin(); it!=patchesFromPatch.end(); ++it)
forAllConstIters(patchesFromPatch, it)
{
const wordList& newPatchNames = it->second;
......@@ -1213,8 +1205,7 @@ void checkMeshDict::updateRenameBoundary
// create the dictionary if it has not existed before
dictionary& newPatchesDict = newDict.subDict("newPatchNames");
std::map<word, wordList>::const_iterator it;
for (it = patchesFromPatch.begin(); it!=patchesFromPatch.end(); ++it)
forAllConstIters(patchesFromPatch, it)
{
const wordList& newPatchNames = it->second;
......
......@@ -444,13 +444,7 @@ label groupMarking
List<List<labelPair>> globalNeiGroups(Pstream::nProcs());
DynList<labelPair> connsAtProc;
for
(
std::map<label, DynList<label>>::const_iterator it =
neiGroups.begin();
it!=neiGroups.end();
++it
)
forAllConstIters(neiGroups, it)
{
const DynList<label>& ng = it->second;
......
......@@ -1821,12 +1821,12 @@ inline label numberOfFaceGroups
labelHashSet triaInRange(containedElements.size());
const scalar rangeSq = range*range;
forAllConstIter(labelHashSet, containedElements, it)
for (const label elemi : containedElements)
{
const point p = nearestPointOnTheTriangle(it.key(), surface, centre);
const point p = nearestPointOnTheTriangle(elemi, surface, centre);
if (magSqr(p - centre) < rangeSq)
{
triaInRange.insert(it.key());
triaInRange.insert(elemi);
}
}
......@@ -1837,13 +1837,13 @@ inline label numberOfFaceGroups
DynList<label> front;
forAllConstIter(labelHashSet, triaInRange, it)
for (const label triIdx : triaInRange)
{
if (!elGroup.found(it.key()))
if (!elGroup.found(triIdx))
{
front.clear();
front.append(it.key());
elGroup.insert(it.key(), nGroups);
front.append(triIdx);
elGroup.insert(triIdx, nGroups);
while (front.size())
{
......@@ -1913,16 +1913,16 @@ inline label numberOfEdgeGroups
const scalar rangeSq = range*range;
labelHashSet edgesInRange(containedEdges.size());
forAllConstIter(labelHashSet, containedEdges, it)
for (const label edgei : containedEdges)
{
const edge& e = edges[it.key()];
const point& sp = points[e[0]];
const point& ep = points[e[1]];
const edge& e = edges[edgei];
const point& sp = points[e.first()];
const point& ep = points[e.second()];
const point p = nearestPointOnTheEdgeExact(sp, ep, centre);
if (magSqr(p - centre) < rangeSq)
{
edgesInRange.insert(it.key());
edgesInRange.insert(edgei);
}
}
......@@ -1933,13 +1933,13 @@ inline label numberOfEdgeGroups
DynList<label> front;
forAllConstIter(labelHashSet, edgesInRange, it)
for (const label edgei : edgesInRange)
{
if (!elGroup.found(it.key()))
if (!elGroup.found(edgei))
{
front.clear();
front.append(it.key());
elGroup.insert(it.key(), nGroups);
front.append(edgei);
elGroup.insert(edgei, nGroups);
while (front.size())
{
......
......@@ -151,11 +151,9 @@ void exchangeMap
FatalError << "Data is not contiguous" << exit(FatalError);
}
typename std::map<label, ListType>::const_iterator iter;
// check which processors shall exchange the data and which ones shall not
labelHashSet receiveData;
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
OPstream toOtherProc
(
......@@ -167,7 +165,7 @@ void exchangeMap
toOtherProc << iter->second.size();
}
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
IPstream fromOtherProc
(
......@@ -190,7 +188,7 @@ void exchangeMap
// start with blocking type of send and received operation
// send data to other processors
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
const ListType& dts = iter->second;
......@@ -209,7 +207,7 @@ void exchangeMap
}
// receive data from other processors
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
if (!receiveData.found(iter->first))
{
......@@ -232,7 +230,7 @@ void exchangeMap
// it does not require any buffer
// receive data from processors with lower ids
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
if (iter->first >= Pstream::myProcNo())
{
......@@ -253,7 +251,7 @@ void exchangeMap
}
// send data to processors with greater ids
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
if (iter->first <= Pstream::myProcNo())
{
......@@ -278,8 +276,7 @@ void exchangeMap
}
// receive data from processors with greater ids
typename std::map<label, ListType>::const_reverse_iterator riter;
for (riter = m.rbegin(); riter!=m.rend(); ++riter)
forAllConstReverseIters(m, riter)
{
if (riter->first <= Pstream::myProcNo())
{
......@@ -300,7 +297,7 @@ void exchangeMap
}
// send data to processors with lower ids
for (riter = m.rbegin(); riter!=m.rend(); ++riter)
forAllConstReverseIters(m, riter)
{
if (riter->first >= Pstream::myProcNo())
{
......@@ -332,7 +329,7 @@ void exchangeMap
# ifdef DEBUGExchangeMap
labelList nReceived(Pstream::nProcs(), 0);
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
nReceived[iter->first] += iter->second.size();
}
......@@ -365,7 +362,7 @@ void exchangeMap
typename std::map<label, ListType>::const_iterator iter;
// send data to other processors
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
const ListType& dataToSend = iter->second;
......@@ -379,7 +376,7 @@ void exchangeMap
}
// receive data from other processors
for (iter = m.begin(); iter!=m.end(); ++iter)
forAllConstIters(m, iter)
{
mOut.insert(std::make_pair(iter->first, List<T>()));
List<T>& dataToReceive = mOut[iter->first];
......
......@@ -122,9 +122,9 @@ void findCellsIntersectingSurface::findIntersectedCells()
// remove triangles which do not intersect the bounding box
labelHashSet reasonableCandidates;
forAllConstIter(labelHashSet, triangles, tIter)
for (const label triIdx : triangles)
{
const labelledTri& tri = surf[tIter.key()];
const labelledTri& tri = surf[triIdx];
boundBox obb(sp[tri[0]], sp[tri[0]]);
for (label i = 1; i < 3; ++i)
......@@ -140,7 +140,7 @@ void findCellsIntersectingSurface::findIntersectedCells()
if (obb.overlaps(bb))
{
reasonableCandidates.insert(tIter.key());
reasonableCandidates.insert(triIdx);
}
}
......@@ -148,9 +148,9 @@ void findCellsIntersectingSurface::findIntersectedCells()
// check if any of the surface vertices is contained within the cell
labelHashSet nodes, facetsInCell;
forAllConstIter(labelHashSet, triangles, tIter)
for (const label triIdx : triangles)
{
const labelledTri& tri = surf[tIter.key()];
const labelledTri& tri = surf[triIdx];
forAll(tri, i)
{
......@@ -159,9 +159,9 @@ void findCellsIntersectingSurface::findIntersectedCells()
}
// check which surface nodes are within the cell
forAllConstIter(labelHashSet, nodes, nIter)
for (const label nodei : nodes)
{
const point& p = sp[nIter.key()];
const point& p = sp[nodei];
if (!bb.contains(p))
{
......@@ -188,11 +188,11 @@ void findCellsIntersectingSurface::findIntersectedCells()
if (help::pointInTetrahedron(p, tet))
{
intersected = true;
forAllRow(pointFacets, nIter.key(), ptI)
forAllRow(pointFacets, nodei, ptI)
{
facetsInCell.insert
(
pointFacets(nIter.key(), ptI)
pointFacets(nodei, ptI)
);
}
......@@ -221,11 +221,11 @@ void findCellsIntersectingSurface::findIntersectedCells()
if (help::pointInTetrahedron(p, tet))
{
intersected = true;
forAllRow(pointFacets, nIter.key(), ptI)
forAllRow(pointFacets, nodei, ptI)
{
facetsInCell.insert
(
pointFacets(nIter.key(), ptI)
pointFacets(nodei, ptI)
);
}
......@@ -244,9 +244,9 @@ void findCellsIntersectingSurface::findIntersectedCells()
// check if any triangle in the surface mesh
// intersects any of the cell's faces
forAllConstIter(labelHashSet, triangles, tIter)
for (const label triIdx : triangles)
{