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

- reduced clutter when iterating over containers
This commit is contained in:
Mark Olesen
2019-01-07 09:20:51 +01:00
committed by Andrew Heather
parent a766d38643
commit bd78da22e7
11 changed files with 59 additions and 84 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -168,8 +168,7 @@ public:
//- Destructor //- Destructor
virtual ~blockEdge() virtual ~blockEdge() = default;
{}
// Member Functions // Member Functions

View File

@ -913,13 +913,12 @@ Foam::label Foam::meshRefinement::splitFacesUndo
forAll(map.faceMap(), facei) forAll(map.faceMap(), facei)
{ {
label oldFacei = map.faceMap()[facei]; label oldFacei = map.faceMap()[facei];
Map<label>::iterator oldFaceFnd = splitFaceToIndex.find
( const auto oldFaceFnd = splitFaceToIndex.cfind(oldFacei);
oldFacei
); if (oldFaceFnd.found())
if (oldFaceFnd != splitFaceToIndex.end())
{ {
labelPair& twoFaces = facePairs[oldFaceFnd()]; labelPair& twoFaces = facePairs[oldFaceFnd.val()];
if (twoFaces[0] == -1) if (twoFaces[0] == -1)
{ {
twoFaces[0] = facei; twoFaces[0] = facei;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2014 OpenFOAM Foundation | Copyright (C) 2011-2014 OpenFOAM Foundation
@ -1235,10 +1235,10 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::mergeBaffles
} }
} }
forAllConstIter(Map<label>, faceToPatch, iter) forAllConstIters(faceToPatch, iter)
{ {
label faceI = iter.key(); const label faceI = iter.key();
label patchI = iter(); const label patchI = iter.val();
if (!mesh_.isInternalFace(faceI)) if (!mesh_.isInternalFace(faceI))
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -1300,18 +1300,18 @@ Foam::labelList Foam::meshRefinement::markFacesOnProblemCellsGeometric
} }
forAllConstIter(faceSet, wrongFaces, iter) for (const label facei : wrongFaces)
{ {
label patchi = mesh_.boundaryMesh().whichPatch(iter.key()); const label patchi = mesh_.boundaryMesh().whichPatch(facei);
if (patchi == -1 || mesh_.boundaryMesh()[patchi].coupled()) if (patchi == -1 || mesh_.boundaryMesh()[patchi].coupled())
{ {
facePatch[iter.key()] = nearestAdaptPatch[iter.key()]; facePatch[facei] = nearestAdaptPatch[facei];
nBaffleFaces++; nBaffleFaces++;
//Pout<< " " << iter.key() //Pout<< " " << facei
// //<< " on patch " << mesh_.boundaryMesh()[patchi].name() // //<< " on patch " << mesh_.boundaryMesh()[patchi].name()
// << " is destined for patch " << facePatch[iter.key()] // << " is destined for patch " << facePatch[facei]
// << endl; // << endl;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation | Copyright (C) 2011-2017 OpenFOAM Foundation
@ -504,12 +504,10 @@ void Foam::meshRefinement::markFeatureCellLevel
Pout<< "Constructing cloud for cell marking" << endl; Pout<< "Constructing cloud for cell marking" << endl;
} }
forAllIter(Cloud<trackedParticle>, startPointCloud, iter) for (const trackedParticle& startTp : startPointCloud)
{ {
const trackedParticle& startTp = iter(); const label featI = startTp.i();
const label pointI = startTp.j();
label featI = startTp.i();
label pointI = startTp.j();
const edgeMesh& featureMesh = features_[featI]; const edgeMesh& featureMesh = features_[featI];
const labelList& pEdges = featureMesh.pointEdges()[pointI]; const labelList& pEdges = featureMesh.pointEdges()[pointI];
@ -562,12 +560,10 @@ void Foam::meshRefinement::markFeatureCellLevel
cloud.move(cloud, td, maxTrackLen); cloud.move(cloud, td, maxTrackLen);
// Make particle follow edge. // Make particle follow edge.
forAllIter(Cloud<trackedParticle>, cloud, iter) for (trackedParticle& tp : cloud)
{ {
trackedParticle& tp = iter(); const label featI = tp.i();
const label pointI = tp.j();
label featI = tp.i();
label pointI = tp.j();
const edgeMesh& featureMesh = features_[featI]; const edgeMesh& featureMesh = features_[featI];
const labelList& pEdges = featureMesh.pointEdges()[pointI]; const labelList& pEdges = featureMesh.pointEdges()[pointI];

View File

@ -209,11 +209,10 @@ void Foam::meshRefinement::addPatchFields
mesh.objectRegistry::lookupClass<GeoField>() mesh.objectRegistry::lookupClass<GeoField>()
); );
forAllIter(typename HashTable<GeoField*>, flds, iter) forAllIters(flds, iter)
{ {
GeoField& fld = *iter(); GeoField& fld = *iter();
typename GeoField::Boundary& fldBf = auto& fldBf = fld.boundaryFieldRef();
fld.boundaryFieldRef();
label sz = fldBf.size(); label sz = fldBf.size();
fldBf.setSize(sz+1); fldBf.setSize(sz+1);
@ -243,7 +242,7 @@ void Foam::meshRefinement::reorderPatchFields
mesh.objectRegistry::lookupClass<GeoField>() mesh.objectRegistry::lookupClass<GeoField>()
); );
forAllIter(typename HashTable<GeoField*>, flds, iter) forAllIters(flds, iter)
{ {
iter()->boundaryFieldRef().reorder(oldToNew); iter()->boundaryFieldRef().reorder(oldToNew);
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -461,11 +461,11 @@ Foam::refinementSurfaces::refinementSurfaces
} }
// Overwrite with region specific information // Overwrite with region specific information
forAllConstIter(Map<label>, regionMinLevel[surfI], iter) forAllConstIters(regionMinLevel[surfI], iter)
{ {
label globalRegionI = regionOffset_[surfI] + iter.key(); label globalRegionI = regionOffset_[surfI] + iter.key();
minLevel_[globalRegionI] = iter(); minLevel_[globalRegionI] = iter.val();
maxLevel_[globalRegionI] = regionMaxLevel[surfI][iter.key()]; maxLevel_[globalRegionI] = regionMaxLevel[surfI][iter.key()];
gapLevel_[globalRegionI] = gapLevel_[globalRegionI] =
maxLevel_[globalRegionI] maxLevel_[globalRegionI]
@ -475,7 +475,7 @@ Foam::refinementSurfaces::refinementSurfaces
extendedGapMode_[globalRegionI] = extendedGapMode_[globalRegionI] =
regionGapMode[surfI][iter.key()]; regionGapMode[surfI][iter.key()];
} }
forAllConstIter(Map<scalar>, regionAngle[surfI], iter) forAllConstIters(regionAngle[surfI], iter)
{ {
label globalRegionI = regionOffset_[surfI] + iter.key(); label globalRegionI = regionOffset_[surfI] + iter.key();
@ -483,11 +483,12 @@ Foam::refinementSurfaces::refinementSurfaces
} }
const Map<autoPtr<dictionary>>& localInfo = regionPatchInfo[surfI]; const Map<autoPtr<dictionary>>& localInfo = regionPatchInfo[surfI];
forAllConstIter(Map<autoPtr<dictionary>>, localInfo, iter) forAllConstIters(localInfo, iter)
{ {
label globalRegionI = regionOffset_[surfI] + iter.key(); label globalRegionI = regionOffset_[surfI] + iter.key();
const dictionary& dict = *(iter.val());
patchInfo_.set(globalRegionI, iter()().clone()); patchInfo_.set(globalRegionI, dict.clone());
} }
} }
} }

View File

@ -314,18 +314,7 @@ void Foam::snappyLayerDriver::countCommonPoints
if (facei < nbFacei) if (facei < nbFacei)
{ {
// Only check once for each combination of two faces. // Only check once for each combination of two faces.
++(nCommonPoints(nbFacei, 0));
Map<label>::iterator fnd = nCommonPoints.find(nbFacei);
if (fnd == nCommonPoints.end())
{
// First common vertex found.
nCommonPoints.insert(nbFacei, 1);
}
else
{
fnd()++;
}
} }
} }
} }
@ -437,10 +426,10 @@ void Foam::snappyLayerDriver::checkCommonOrder
List<extrudeMode>& extrudeStatus List<extrudeMode>& extrudeStatus
) const ) const
{ {
forAllConstIter(Map<label>, nCommonPoints, iter) forAllConstIters(nCommonPoints, iter)
{ {
label nbFacei = iter.key(); const label nbFacei = iter.key();
label nCommon = iter(); const label nCommon = iter.val();
const face& curFace = pp[facei]; const face& curFace = pp[facei];
const face& nbFace = pp[nbFacei]; const face& nbFace = pp[nbFacei];
@ -1415,10 +1404,10 @@ void Foam::snappyLayerDriver::determineSidePatches
forAll(edgePatchID, i) forAll(edgePatchID, i)
{ {
label patchi = edgePatchID[i]; label patchi = edgePatchID[i];
Map<label>::const_iterator fnd = wantedToAddedPatch.find(patchi); const auto fnd = wantedToAddedPatch.cfind(patchi);
if (fnd != wantedToAddedPatch.end()) if (fnd.found())
{ {
edgePatchID[i] = fnd(); edgePatchID[i] = fnd.val();
} }
} }
@ -2098,10 +2087,8 @@ Foam::label Foam::snappyLayerDriver::truncateDisplacement
const Map<label>& meshPointMap = pp.meshPointMap(); const Map<label>& meshPointMap = pp.meshPointMap();
forAllConstIter(faceSet, illegalPatchFaces, iter) for (const label facei : illegalPatchFaces)
{ {
label facei = iter.key();
if (mesh.isInternalFace(facei)) if (mesh.isInternalFace(facei))
{ {
FatalErrorInFunction FatalErrorInFunction
@ -2115,9 +2102,10 @@ Foam::label Foam::snappyLayerDriver::truncateDisplacement
forAll(f, fp) forAll(f, fp)
{ {
if (meshPointMap.found(f[fp])) const auto fnd = meshPointMap.cfind(f[fp]);
if (fnd.found())
{ {
label patchPointi = meshPointMap[f[fp]]; const label patchPointi = fnd.val();
if (extrudeStatus[patchPointi] != NOEXTRUDE) if (extrudeStatus[patchPointi] != NOEXTRUDE)
{ {
@ -2820,8 +2808,8 @@ Foam::List<Foam::labelPair> Foam::snappyLayerDriver::getBafflesOnAddedMesh
{ {
label oldFacei = newToOldFaces[facei]; label oldFacei = newToOldFaces[facei];
Map<label>::const_iterator faceFnd = baffleSet.find(oldFacei); const auto faceFnd = baffleSet.find(oldFacei);
if (faceFnd != baffleSet.end()) if (faceFnd.found())
{ {
label bafflei = faceFnd(); label bafflei = faceFnd();
labelPair& p = newBaffles[bafflei]; labelPair& p = newBaffles[bafflei];

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -1113,9 +1113,8 @@ Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
// Pass2: check for oppositeness // Pass2: check for oppositeness
//forAllConstIter(cellSet, transitionCells, iter) //for (const label celli : transitionCells)
//{ //{
// const label celli : iter.key();
// const cell& cFaces = cells[celli]; // const cell& cFaces = cells[celli];
// const point& cc = cellCentres[celli]; // const point& cc = cellCentres[celli];
// const scalar rCVol = pow(cellVolumes[celli], -5.0/3.0); // const scalar rCVol = pow(cellVolumes[celli], -5.0/3.0);
@ -1226,9 +1225,8 @@ Foam::label Foam::snappyRefineDriver::refinementInterfaceRefine
const scalar oppositeCos = Foam::cos(degToRad(135.0)); const scalar oppositeCos = Foam::cos(degToRad(135.0));
forAllConstIter(cellSet, transitionCells, iter) for (const label celli : transitionCells)
{ {
label celli = iter.key();
const cell& cFaces = cells[celli]; const cell& cFaces = cells[celli];
label cLevel = cutter.cellLevel()[celli]; label cLevel = cutter.cellLevel()[celli];

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2015 OpenFOAM Foundation | Copyright (C) 2011-2015 OpenFOAM Foundation
@ -225,10 +225,7 @@ Foam::tmp<Foam::pointField> Foam::snappySnapDriver::smoothInternalDisplacement
// Unmark any point on the boundary. If we're doing zero iterations of // Unmark any point on the boundary. If we're doing zero iterations of
// face-cell wave we might have coupled points not being unmarked. // face-cell wave we might have coupled points not being unmarked.
forAll(pp.meshPoints(), pointi) isMovingPoint.unset(pp.meshPoints());
{
isMovingPoint.unset(pp.meshPoints()[pointi]);
}
// Make sure that points that are coupled to meshPoints but not on a patch // Make sure that points that are coupled to meshPoints but not on a patch
// are unmarked as well // are unmarked as well
@ -962,12 +959,11 @@ Foam::labelList Foam::snappySnapDriver::getZoneSurfacePoints
{ {
label meshPointi = f[fp]; label meshPointi = f[fp];
Map<label>::const_iterator iter = const auto iter = pp.meshPointMap().cfind(meshPointi);
pp.meshPointMap().find(meshPointi);
if (iter != pp.meshPointMap().end()) if (iter.found())
{ {
label pointi = iter(); const label pointi = iter.val();
pointOnZone[pointi] = true; pointOnZone[pointi] = true;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2015 OpenFOAM Foundation | Copyright (C) 2015 OpenFOAM Foundation
@ -49,12 +49,11 @@ Foam::labelList Foam::snappySnapDriver::getFacePoints
{ {
label meshPointi = f[fp]; label meshPointi = f[fp];
Map<label>::const_iterator iter = const auto iter = pp.meshPointMap().cfind(meshPointi);
pp.meshPointMap().find(meshPointi);
if (iter != pp.meshPointMap().end()) if (iter.found())
{ {
label pointi = iter(); const label pointi = iter.val();
pointOnZone[pointi] = true; pointOnZone[pointi] = true;
} }
} }