From 14a404170bdad5e784c7f313ec566409c06626e7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 7 Jan 2019 09:20:51 +0100 Subject: [PATCH] ENH: for-range, forAllIters() ... in applications/utilities - reduced clutter when iterating over containers --- applications/test/callback/Test-callback.C | 2 +- applications/test/cyclic/Test-cyclic.C | 2 +- applications/test/delete/Test-delete.C | 2 +- applications/test/fvc/Test-fvc.C | 2 +- applications/test/fvc2D/Test-fvc2D.C | 2 +- applications/test/graph/Test-graph.C | 2 +- applications/test/graph/graphTest2.C | 2 +- applications/test/graphXi/Test-graphXi.C | 2 +- .../passiveParticle/Test-passiveParticle.C | 16 +- applications/test/syncTools/Test-syncTools.C | 10 +- .../utilities/mesh/advanced/PDRMesh/PDRMesh.C | 25 +-- .../mesh/advanced/modifyMesh/cellSplitter.C | 79 +++---- .../mesh/advanced/modifyMesh/cellSplitter.H | 2 +- .../mesh/advanced/modifyMesh/modifyMesh.C | 38 +--- .../mesh/advanced/splitCells/splitCells.C | 11 +- .../mesh/conversion/ansysToFoam/ansysToFoam.L | 107 +++++----- .../fluent3DMeshToFoam/fluent3DMeshToFoam.L | 4 +- .../fluentMeshToFoam/fluentMeshToFoam.L | 10 +- .../mesh/conversion/gmshToFoam/gmshToFoam.C | 155 +++++++------- .../mesh/conversion/kivaToFoam/readKivaGrid.H | 23 +- .../netgenNeutralToFoam/netgenNeutralToFoam.C | 6 +- .../conversion/tetgenToFoam/tetgenToFoam.C | 19 +- .../conversion/writeMeshObj/writeMeshObj.C | 24 +-- .../mesh/generation/blockMesh/addCellZones.H | 2 +- .../extrudeToRegionMesh/extrudeToRegionMesh.C | 11 +- .../patchToPoly2DMesh/patchToPoly2DMesh.C | 2 +- .../DelaunayMesh/DistributedDelaunayMesh.C | 18 +- .../PrintTable/PrintTable.C | 4 +- .../linearDistance/linearDistance.C | 4 +- .../uniformDistance/uniformDistance.C | 4 +- .../conformalVoronoiMeshConformToSurface.C | 6 +- .../conformalVoronoiMeshFeaturePoints.C | 2 +- .../featurePointConformer.C | 7 +- .../pointFeatureEdgesTypes.C | 2 +- .../conformationSurfaces.C | 4 +- .../pointPairs/pointPairs.C | 14 +- .../foamyQuadMesh/shortEdgeFilter2D.C | 4 +- .../generation/snappyHexMesh/snappyHexMesh.C | 10 +- .../manipulation/checkMesh/checkGeometry.C | 2 +- .../mesh/manipulation/checkMesh/checkTools.C | 4 +- .../splitMeshRegions/splitMeshRegions.C | 65 +++--- .../decomposePar/decomposePar.C | 19 +- .../decomposePar/domainDecompositionMesh.C | 15 +- .../decomposePar/faMeshDecomposition.C | 200 ++++++++---------- .../decomposePar/lagrangianFieldDecomposer.C | 2 +- .../reconstructPar/reconstructPar.C | 29 +-- .../parLagrangianRedistributor.C | 12 +- .../parLagrangianRedistributorFields.C | 2 +- .../redistributePar/redistributePar.C | 15 +- .../foamToEnsight/convertLagrangian.H | 2 +- .../foamToEnsightParts/convertLagrangian.H | 2 +- .../foamToGMV/gmvOutputLagrangian.H | 16 +- .../foamToGMV/gmvOutputParcels.H | 28 +-- .../dataConversion/foamToGMV/gmvOutputSpray.H | 12 +- .../PVReaders/foamPv/foamPvCoreTemplates.C | 4 +- .../graphics/PVReaders/vtkPVFoam/vtkPVFoam.C | 16 +- .../vtkPVFoam/vtkPVFoamFieldTemplates.C | 42 ++-- .../PVReaders/vtkPVFoam/vtkPVFoamFields.C | 4 +- .../vtkPVFoam/vtkPVFoamMeshLagrangian.C | 4 +- .../PVReaders/vtkPVFoam/vtkPVFoamUpdateInfo.C | 6 +- .../ensightFoamReader/USERD_get_part_coords.H | 4 +- .../USERD_get_part_node_ids.H | 2 +- .../particleTracks/particleTracks.C | 20 +- .../steadyParticleTracks.C | 22 +- .../changeDictionary/changeDictionary.C | 24 +-- .../foamUpgradeCyclics/foamUpgradeCyclics.C | 2 +- .../preProcessing/mapFields/mapLagrangian.C | 18 +- .../mapFieldsPar/mapLagrangian.C | 18 +- .../utilities/surface/surfaceAdd/surfaceAdd.C | 28 +-- .../surfaceBooleanFeatures.C | 2 +- .../surfaceFeaturesExtraction.C | 2 +- .../surfaceMeshExtract/surfaceMeshExtract.C | 12 +- .../surfaceSplitNonManifolds.C | 12 +- .../surface/surfaceToPatch/surfaceToPatch.C | 8 +- .../adiabaticFlameT/adiabaticFlameT.C | 2 +- .../equilibriumCO/equilibriumCO.C | 4 +- 76 files changed, 592 insertions(+), 728 deletions(-) diff --git a/applications/test/callback/Test-callback.C b/applications/test/callback/Test-callback.C index 2599ada23e..3f1b794fe8 100644 --- a/applications/test/callback/Test-callback.C +++ b/applications/test/callback/Test-callback.C @@ -72,7 +72,7 @@ public: void testCallbackFunction() const { - forAllConstIter(callbackRegistry, *this, iter) + forAllConstIters(*this, iter) { iter().testCallbackFunction(); } diff --git a/applications/test/cyclic/Test-cyclic.C b/applications/test/cyclic/Test-cyclic.C index 5e1a7a833e..4da99a1115 100644 --- a/applications/test/cyclic/Test-cyclic.C +++ b/applications/test/cyclic/Test-cyclic.C @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) Info<< fvc::div(U); - Info<< "end" << endl; + Info<< "End" << endl; } diff --git a/applications/test/delete/Test-delete.C b/applications/test/delete/Test-delete.C index 1db0a002d1..60a34e6ef1 100644 --- a/applications/test/delete/Test-delete.C +++ b/applications/test/delete/Test-delete.C @@ -54,7 +54,7 @@ int main() a = h + i + j; Info<< a << endl; - Info<< "end" << endl; + Info<< "End" << endl; return 0; } diff --git a/applications/test/fvc/Test-fvc.C b/applications/test/fvc/Test-fvc.C index 32c926eb01..d27b4f50c2 100644 --- a/applications/test/fvc/Test-fvc.C +++ b/applications/test/fvc/Test-fvc.C @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) Info<< (gradx4a - gradx4[i])/gradx4a << endl; } - Info<< "end" << endl; + Info<< "End" << endl; } diff --git a/applications/test/fvc2D/Test-fvc2D.C b/applications/test/fvc2D/Test-fvc2D.C index 527cfbd3cc..dfe063e585 100644 --- a/applications/test/fvc2D/Test-fvc2D.C +++ b/applications/test/fvc2D/Test-fvc2D.C @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) mesh ); - Info<< "end" << endl; + Info<< "End" << endl; } diff --git a/applications/test/graph/Test-graph.C b/applications/test/graph/Test-graph.C index 5cfea035a4..68e4c0386d 100644 --- a/applications/test/graph/Test-graph.C +++ b/applications/test/graph/Test-graph.C @@ -65,7 +65,7 @@ int main() ); phi.write("phi", "xmgr"); - Info<< "end" << endl; + Info<< "End" << endl; } diff --git a/applications/test/graph/graphTest2.C b/applications/test/graph/graphTest2.C index f01b5ccca4..4c01f605a0 100644 --- a/applications/test/graph/graphTest2.C +++ b/applications/test/graph/graphTest2.C @@ -57,7 +57,7 @@ int main() "xmgr" ); - Info<< "end" << endl; + Info<< "End" << endl; } diff --git a/applications/test/graphXi/Test-graphXi.C b/applications/test/graphXi/Test-graphXi.C index 38ec520cb9..107ffa58a3 100644 --- a/applications/test/graphXi/Test-graphXi.C +++ b/applications/test/graphXi/Test-graphXi.C @@ -57,7 +57,7 @@ int main() graph("r", "x", "r", x, r).write("r", "xmgr"); - Info<< "end" << endl; + Info<< "End" << endl; return 0; } diff --git a/applications/test/passiveParticle/Test-passiveParticle.C b/applications/test/passiveParticle/Test-passiveParticle.C index 5506683b34..2853d4cb26 100644 --- a/applications/test/passiveParticle/Test-passiveParticle.C +++ b/applications/test/passiveParticle/Test-passiveParticle.C @@ -59,11 +59,11 @@ int main(int argc, char *argv[]) Pout<< "Adding a particle." << endl; particles.addParticle(new passiveParticle(mesh, Zero, -1)); - forAllConstIter(passiveParticleCloud, particles, iter) + for (const passiveParticle& p : particles) { - Pout<< " " << iter().position() << " cell:" << iter().cell() - << " origProc:" << iter().origProc() - << " origId:" << iter().origId() + Pout<< " " << p.position() << " cell:" << p.cell() + << " origProc:" << p.origProc() + << " origId:" << p.origId() << endl; } @@ -80,11 +80,11 @@ int main(int argc, char *argv[]) passiveParticleCloud particles(mesh, cloudName); Pout<< "Reread particles:" << particles.size() << endl; - forAllConstIter(passiveParticleCloud, particles, iter) + for (const passiveParticle& p : particles) { - Pout<< " " << iter().position() << " cell:" << iter().cell() - << " origProc:" << iter().origProc() - << " origId:" << iter().origId() + Pout<< " " << p.position() << " cell:" << p.cell() + << " origProc:" << p.origProc() + << " origId:" << p.origId() << endl; } } diff --git a/applications/test/syncTools/Test-syncTools.C b/applications/test/syncTools/Test-syncTools.C index cfdaaed586..19004f2caf 100644 --- a/applications/test/syncTools/Test-syncTools.C +++ b/applications/test/syncTools/Test-syncTools.C @@ -261,10 +261,10 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) } // 2. Does sparseData contain more? - forAllConstIter(Map, sparseData, iter) + forAllConstIters(sparseData, iter) { - const point& sparsePt = iter(); - label meshPointi = iter.key(); + const label meshPointi = iter.key(); + const point& sparsePt = iter.val(); const point& fullPt = fullData[meshPointi]; if (fullPt != sparsePt) @@ -350,9 +350,9 @@ void testSparseData(const polyMesh& mesh, Random& rndGen) { const edge& e = mesh.edges()[meshEdgeI]; - EdgeMap::const_iterator iter = sparseData.find(e); + const auto iter = sparseData.cfind(e); - if (iter != sparseData.end()) + if (iter.found()) { const point& sparsePt = iter(); const point& fullPt = fullData[meshEdgeI]; diff --git a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C index 3aa52a84c1..972cfbe8b5 100644 --- a/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C +++ b/applications/utilities/mesh/advanced/PDRMesh/PDRMesh.C @@ -711,18 +711,18 @@ int main(int argc, char *argv[]) setsAndPatches[setI][1] ); - forAllConstIter(faceSet, fSet, iter) + for (const label facei : fSet) { - if (wantedPatch[iter.key()] != -1) + if (wantedPatch[facei] != -1) { FatalErrorInFunction - << "Face " << iter.key() + << "Face " << facei << " is in faceSet " << setsAndPatches[setI][0] << " destined for patch " << setsAndPatches[setI][1] - << " but also in patch " << wantedPatch[iter.key()] + << " but also in patch " << wantedPatch[facei] << exit(FatalError); } - wantedPatch[iter.key()] = patchi; + wantedPatch[facei] = patchi; } } @@ -749,20 +749,21 @@ int main(int argc, char *argv[]) faceSet fSet(mesh, coupledAndPatches[setI][0]); label patchi = findPatch(patches, coupledAndPatches[setI][1]); - forAllConstIter(faceSet, fSet, iter) + for (const label facei : fSet) { - if (coupledWantedPatch[iter.key()] != -1) + if (coupledWantedPatch[facei] != -1) { FatalErrorInFunction - << "Face " << iter.key() + << "Face " << facei << " is in faceSet " << coupledAndPatches[setI][0] << " destined for patch " << coupledAndPatches[setI][1] - << " but also in patch " << coupledWantedPatch[iter.key()] + << " but also in patch " << coupledWantedPatch[facei] << exit(FatalError); } - coupledWantedPatch[iter.key()] = patchi; - cyclicWantedPatch_half0[iter.key()] = cyclicId; - cyclicWantedPatch_half1[iter.key()] = cyclicSlaveId; + + coupledWantedPatch[facei] = patchi; + cyclicWantedPatch_half0[facei] = cyclicId; + cyclicWantedPatch_half1[facei] = cyclicSlaveId; } } diff --git a/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C b/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C index a39690325b..799ce1ea97 100644 --- a/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C +++ b/applications/utilities/mesh/advanced/modifyMesh/cellSplitter.C @@ -80,25 +80,24 @@ Foam::label Foam::cellSplitter::newOwner const Map& cellToCells ) const { - label oldOwn = mesh_.faceOwner()[facei]; + const label old = mesh_.faceOwner()[facei]; - Map::const_iterator fnd = cellToCells.find(oldOwn); + const auto iter = cellToCells.cfind(old); - if (fnd == cellToCells.end()) + if (!iter.found()) { // Unsplit cell - return oldOwn; + return old; } - else - { - // Look up index of face in the cells' faces. - const labelList& newCells = fnd(); - const cell& cFaces = mesh_.cells()[oldOwn]; + // Look up index of face in the cells' faces. - return newCells[cFaces.find(facei)]; - } + const labelList& newCells = *iter; + + const cell& cFaces = mesh_.cells()[old]; + + return newCells[cFaces.find(facei)]; } @@ -108,31 +107,29 @@ Foam::label Foam::cellSplitter::newNeighbour const Map& cellToCells ) const { - label oldNbr = mesh_.faceNeighbour()[facei]; + const label old = mesh_.faceNeighbour()[facei]; - Map::const_iterator fnd = cellToCells.find(oldNbr); + const auto iter = cellToCells.cfind(old); - if (fnd == cellToCells.end()) + if (!iter.found()) { // Unsplit cell - return oldNbr; + return old; } - else - { - // Look up index of face in the cells' faces. - const labelList& newCells = fnd(); - const cell& cFaces = mesh_.cells()[oldNbr]; + // Look up index of face in the cells' faces. - return newCells[cFaces.find(facei)]; - } + const labelList& newCells = *iter; + + const cell& cFaces = mesh_.cells()[old]; + + return newCells[cFaces.find(facei)]; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -// Construct from components Foam::cellSplitter::cellSplitter(const polyMesh& mesh) : mesh_(mesh), @@ -140,12 +137,6 @@ Foam::cellSplitter::cellSplitter(const polyMesh& mesh) {} -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::cellSplitter::~cellSplitter() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::cellSplitter::setRefinement @@ -162,9 +153,9 @@ void Foam::cellSplitter::setRefinement // Introduce cellToMidPoints. // - forAllConstIter(Map, cellToMidPoint, iter) + forAllConstIters(cellToMidPoint, iter) { - label celli = iter.key(); + const label celli = iter.key(); label anchorPoint = mesh_.cellPoints()[celli][0]; @@ -173,7 +164,7 @@ void Foam::cellSplitter::setRefinement ( polyAddPoint ( - iter(), // point + iter.val(), // point anchorPoint, // master point -1, // zone for point true // supports a cell @@ -193,9 +184,9 @@ void Foam::cellSplitter::setRefinement Map cellToCells(cellToMidPoint.size()); - forAllConstIter(Map, cellToMidPoint, iter) + forAllConstIters(cellToMidPoint, iter) { - label celli = iter.key(); + const label celli = iter.key(); const cell& cFaces = mesh_.cells()[celli]; @@ -238,9 +229,9 @@ void Foam::cellSplitter::setRefinement // point. // - forAllConstIter(Map, cellToMidPoint, iter) + forAllConstIters(cellToMidPoint, iter) { - label celli = iter.key(); + const label celli = iter.key(); label midPointi = addedPoints_[celli]; @@ -368,9 +359,9 @@ void Foam::cellSplitter::setRefinement // Mark off affected face. bitSet faceUpToDate(mesh_.nFaces(), true); - forAllConstIter(Map, cellToMidPoint, iter) + forAllConstIters(cellToMidPoint, iter) { - label celli = iter.key(); + const label celli = iter.key(); const cell& cFaces = mesh_.cells()[celli]; @@ -462,15 +453,13 @@ void Foam::cellSplitter::updateMesh(const mapPolyMesh& morphMap) // point get mapped do they get inserted. Map