Commit 28335215 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: for-range, forAllIters() ... in meshTools/

- reduced clutter when iterating over containers
parent 24861f51
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2013-2016 OpenFOAM Foundation
......@@ -80,28 +80,23 @@ Foam::cyclicACMIGAMGInterface::cyclicACMIGAMGInterface
Map<label> masterToCoarseFace(localRestrictAddressing.size());
forAll(localRestrictAddressing, ffi)
for (const label curMaster : localRestrictAddressing)
{
label curMaster = localRestrictAddressing[ffi];
const auto iter = masterToCoarseFace.cfind(curMaster);
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
if (fnd == masterToCoarseFace.end())
if (iter.found())
{
// Already have coarse face
dynFaceRestrictAddressing.append(iter.val());
}
else
{
// New coarse face
label coarseI = dynFaceCells.size();
const label coarseI = dynFaceCells.size();
dynFaceRestrictAddressing.append(coarseI);
dynFaceCells.append(curMaster);
masterToCoarseFace.insert(curMaster, coarseI);
}
else
{
// Already have coarse face
dynFaceRestrictAddressing.append(fnd());
}
}
faceCells_.transfer(dynFaceCells);
......@@ -127,26 +122,21 @@ Foam::cyclicACMIGAMGInterface::cyclicACMIGAMGInterface
Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
forAll(neighbourRestrictAddressing, ffi)
for (const label curMaster : neighbourRestrictAddressing)
{
label curMaster = neighbourRestrictAddressing[ffi];
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
const auto iter = masterToCoarseFace.cfind(curMaster);
if (fnd == masterToCoarseFace.end())
if (iter.found())
{
// New coarse face
label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
// Already have coarse face
dynNbrFaceRestrictAddressing.append(iter.val());
}
else
{
// Already have coarse face
dynNbrFaceRestrictAddressing.append(fnd());
// New coarse face
const label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -80,28 +80,23 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
Map<label> masterToCoarseFace(localRestrictAddressing.size());
forAll(localRestrictAddressing, ffi)
for (const label curMaster : localRestrictAddressing)
{
label curMaster = localRestrictAddressing[ffi];
const auto iter = masterToCoarseFace.cfind(curMaster);
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
if (fnd == masterToCoarseFace.end())
if (iter.found())
{
// Already have coarse face
dynFaceRestrictAddressing.append(iter.val());
}
else
{
// New coarse face
label coarseI = dynFaceCells.size();
const label coarseI = dynFaceCells.size();
dynFaceRestrictAddressing.append(coarseI);
dynFaceCells.append(curMaster);
masterToCoarseFace.insert(curMaster, coarseI);
}
else
{
// Already have coarse face
dynFaceRestrictAddressing.append(fnd());
}
}
faceCells_.transfer(dynFaceCells);
......@@ -127,26 +122,21 @@ Foam::cyclicAMIGAMGInterface::cyclicAMIGAMGInterface
Map<label> masterToCoarseFace(neighbourRestrictAddressing.size());
forAll(neighbourRestrictAddressing, ffi)
for (const label curMaster : neighbourRestrictAddressing)
{
label curMaster = neighbourRestrictAddressing[ffi];
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
const auto iter = masterToCoarseFace.cfind(curMaster);
if (fnd == masterToCoarseFace.end())
if (iter.found())
{
// New coarse face
label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
// Already have coarse face
dynNbrFaceRestrictAddressing.append(iter.val());
}
else
{
// Already have coarse face
dynNbrFaceRestrictAddressing.append(fnd());
// New coarse face
const label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
}
}
......
......@@ -144,7 +144,7 @@ namespace Foam
// );
//
// // Add the UniformValueField under the Function1 name
// forAllConstIter(typename F1Type, F1Table, iter)
// forAllConstIters(F1Table, iter)
// {
// //bool ok =
// PF1Table.insert(iter.key(), cstrIter());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -47,12 +47,6 @@ Foam::patchPatchDist::patchPatchDist
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::patchPatchDist::~patchPatchDist()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::patchPatchDist::correct()
......@@ -120,8 +114,8 @@ void Foam::patchPatchDist::correct()
{
const edge& e = patch_.edges()[edgeI];
const edge meshE = edge(mp[e[0]], mp[e[1]]);
EdgeMap<label>::const_iterator edgeFnd = nbrEdges.find(meshE);
if (edgeFnd != nbrEdges.end())
if (nbrEdges.found(meshE))
{
initialEdges.append(edgeI);
initialEdgesInfo.append
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2013 OpenFOAM Foundation
......@@ -57,10 +57,6 @@ class patchPatchDist
:
public scalarField
{
private:
// Private Member Data
//- Patch to operate on
......@@ -85,7 +81,7 @@ public:
//- Destructor
virtual ~patchPatchDist();
virtual ~patchPatchDist() = default;
// Member Functions
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2013-2016 OpenFOAM Foundation
......@@ -36,7 +36,7 @@ License
namespace Foam
{
defineTypeNameAndDebug(meshStructure, 0);
defineTypeNameAndDebug(meshStructure, 0);
}
......@@ -327,7 +327,7 @@ void Foam::meshStructure::correct
label pointi = f[fp];
label nextPointi = f.nextLabel(fp);
EdgeMap<label>::const_iterator fnd = pointsToEdge.find
const auto fnd = pointsToEdge.cfind
(
edge
(
......@@ -335,9 +335,10 @@ void Foam::meshStructure::correct
pointData[nextPointi].data()
)
);
if (fnd != pointsToEdge.end())
if (fnd.found())
{
faceToPatchEdgeAddressing_[facei] = fnd();
faceToPatchEdgeAddressing_[facei] = fnd.val();
faceToPatchFaceAddressing_[facei] = 0;
label own = mesh.faceOwner()[facei];
faceLayer_[facei] = cellData[own].distance();
......
......@@ -276,10 +276,8 @@ void Foam::meshTools::writeOBJ
{
writeOBJ(os, bb.points());
forAll(treeBoundBox::edges, edgei)
for (const edge& e : treeBoundBox::edges)
{
const edge& e = treeBoundBox::edges[edgei];
os << "l " << (e[0] + 1) << ' ' << (e[1] + 1) << nl;
}
}
......@@ -296,10 +294,9 @@ void Foam::meshTools::writeOBJ
{
labelHashSet usedFaces(4*cellLabels.size());
forAll(cellLabels, i)
for (const label celli : cellLabels)
{
const cell& cFaces = cells[cellLabels[i]];
usedFaces.insert(cFaces);
usedFaces.insert(cells[celli]);
}
writeOBJ(os, faces, points, usedFaces.toc());
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation
......@@ -71,24 +71,21 @@ Foam::regionCoupledBaseGAMGInterface::regionCoupledBaseGAMGInterface
{
label curMaster = localRestrictAddressing[ffi];
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
const auto fnd = masterToCoarseFace.cfind(curMaster);
if (fnd == masterToCoarseFace.end())
if (fnd.found())
{
// Already have coarse face
dynFaceRestrictAddressing.append(fnd.val());
}
else
{
// New coarse face
label coarseI = dynFaceCells.size();
const label coarseI = dynFaceCells.size();
dynFaceRestrictAddressing.append(coarseI);
dynFaceCells.append(curMaster);
masterToCoarseFace.insert(curMaster, coarseI);
}
else
{
// Already have coarse face
dynFaceRestrictAddressing.append(fnd());
}
}
faceCells_.transfer(dynFaceCells);
......@@ -153,22 +150,19 @@ Foam::regionCoupledBaseGAMGInterface::regionCoupledBaseGAMGInterface
{
label curMaster = nbrPatchRestrictMap[ffi];
Map<label>::const_iterator fnd = masterToCoarseFace.find
(
curMaster
);
const auto fnd = masterToCoarseFace.cfind(curMaster);
if (fnd == masterToCoarseFace.end())
if (fnd.found())
{
// New coarse face
label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
// Already have coarse face
dynNbrFaceRestrictAddressing.append(fnd.val());
}
else
{
// Already have coarse face
dynNbrFaceRestrictAddressing.append(fnd());
// New coarse face
const label coarseI = masterToCoarseFace.size();
dynNbrFaceRestrictAddressing.append(coarseI);
masterToCoarseFace.insert(curMaster, coarseI);
}
}
......
......@@ -124,9 +124,9 @@ void Foam::localPointRegion::countPointRegions
// From faces with any duplicated point on it to local face
meshFaceMap_.resize(meshPointMap_.size());
forAllConstIter(Map<label>, candidateFace, iter)
forAllConstIters(candidateFace, iter)
{
label facei = iter.key();
const label facei = iter.key();
if (!mesh.isInternalFace(facei))
{
......@@ -142,14 +142,14 @@ void Foam::localPointRegion::countPointRegions
forAll(f, fp)
{
label pointi = f[fp];
const label pointi = f[fp];
// Even points which were not candidates for splitting might
// be on multiple baffles that are being split so check.
if (candidatePoint[pointi])
{
label region = minRegion[facei][fp];
const label region = minRegion[facei][fp];
if (minPointRegion[pointi] == -1)
{
......@@ -158,10 +158,10 @@ void Foam::localPointRegion::countPointRegions
else if (minPointRegion[pointi] != region)
{
// Multiple regions for this point. Add.
Map<label>::iterator iter = meshPointMap_.find(pointi);
if (iter != meshPointMap_.end())
const auto iter = meshPointMap_.cfind(pointi);
if (iter.found())
{
labelList& regions = pointRegions[iter()];
labelList& regions = pointRegions[iter.val()];
if (!regions.found(region))
{
label sz = regions.size();
......@@ -190,9 +190,9 @@ void Foam::localPointRegion::countPointRegions
// Add internal faces that use any duplicated point. Can only have one
// region!
forAllConstIter(Map<label>, candidateFace, iter)
forAllConstIters(candidateFace, iter)
{
label facei = iter.key();
const label facei = iter.key();
if (mesh.isInternalFace(facei))
{
......@@ -204,7 +204,7 @@ void Foam::localPointRegion::countPointRegions
// speeds up rejection.
if (candidatePoint[f[fp]] && meshPointMap_.found(f[fp]))
{
label meshFaceMapI = meshFaceMap_.size();
const label meshFaceMapI = meshFaceMap_.size();
meshFaceMap_.insert(facei, meshFaceMapI);
}
}
......@@ -222,7 +222,7 @@ void Foam::localPointRegion::countPointRegions
// Compact minRegion
faceRegions_.setSize(meshFaceMap_.size());
forAllConstIter(Map<label>, meshFaceMap_, iter)
forAllConstIters(meshFaceMap_, iter)
{
faceRegions_[iter()].labelList::transfer(minRegion[iter.key()]);
......@@ -321,7 +321,7 @@ void Foam::localPointRegion::calcPointRegions
// only ones using a
// candidate point so the only ones that can be affected)
faceList minRegion(mesh.nFaces());
forAllConstIter(Map<label>, candidateFace, iter)
forAllConstIters(candidateFace, iter)
{
label facei = iter.key();
const face& f = mesh.faces()[facei];
......@@ -350,7 +350,7 @@ void Foam::localPointRegion::calcPointRegions
Map<label> minPointValue(128);
label nChanged = 0;
forAllConstIter(Map<label>, candidateCell, iter)
forAllConstIters(candidateCell, iter)
{
minPointValue.clear();
......@@ -368,8 +368,8 @@ void Foam::localPointRegion::calcPointRegions
forAll(f, fp)
{
label pointi = f[fp];
Map<label>::iterator iter = minPointValue.find(pointi);
const label pointi = f[fp];
auto iter = minPointValue.find(pointi);
if (iter == minPointValue.end())
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -355,9 +355,9 @@ void Foam::regionToCell::combine(topoSet& set, const bool add) const
cellSet subSet(mesh_, setName_);
selectedCell = false;
forAllConstIter(cellSet, subSet, iter)
for (const label celli : subSet)
{
selectedCell[iter.key()] = true;
selectedCell[celli] = true;
}
}
......
......@@ -136,10 +136,8 @@ void Foam::setsToFaceZone::applyToSet
DynamicList<label> newAddressing(zoneSet.addressing());
DynamicList<bool> newFlipMap(zoneSet.flipMap());
forAllConstIter(faceSet, fSet, iter)
for (const label facei : fSet)
{
label facei = iter.key();
if (!zoneSet.found(facei))
{
bool flipFace = false;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -60,16 +60,13 @@ void Foam::intersectedSurface::writeOBJ
Ostream& os
)
{
forAll(points, pointi)
for (const point& pt : points)
{
const point& pt = points[pointi];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
forAll(edges, edgei)
{
const edge& e = edges[edgei];
for (const edge& e : edges)
{
os << "l " << e.start()+1 << ' ' << e.end()+1 << nl;
}
}
......@@ -83,15 +80,13 @@ void Foam::intersectedSurface::writeOBJ
Ostream& os
)
{
forAll(points, pointi)
for (const point& pt : points)
{
const point& pt = points[pointi];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
forAll(faceEdges, i)
for (const label edgei : faceEdges)
{
const edge& e = edges[faceEdges[i]];
const edge& e = edges[edgei];
os << "l " << e.start()+1 << ' ' << e.end()+1 << nl;
}
......@@ -112,13 +107,13 @@ void Foam::intersectedSurface::writeLocalOBJ
label maxVerti = 0;
forAll(faceEdges, i)
for (const label edgei : faceEdges)
{
const edge& e = edges[faceEdges[i]];
const edge& e = edges[edgei];
forAll(e, i)
{
label pointi = e[i];
const label pointi = e[i];
if (pointMap[pointi] == -1)
{
......@@ -131,11 +126,11 @@ void Foam::intersectedSurface::writeLocalOBJ
}
}
forAll(faceEdges, i)
for (const label edgei : faceEdges)
{
const edge& e = edges[faceEdges[i]];
const edge& e = edges[edgei];
os << "l " << pointMap[e.start()]+1 << ' ' << pointMap[e.end()]+1
os << "l " << pointMap[e.start()]+1 << ' ' << pointMap[e.end()]+1
<< nl;
}
}