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) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -48,9 +48,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
{
// Count number of faces
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
nPatchFaces += mesh_.boundary()[patchi].size();
}
@ -70,9 +69,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
// Add particles to track to sample locations
nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
const fvPatch& patch = mesh_.boundary()[patchi];
vectorField nf(patch.nf());

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) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -105,10 +105,8 @@ void Foam::functionObjects::nearWallFields::sampleBoundaryField
// Pick up data
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
fvPatchField<Type>& pfld = fldBf[patchi];
Field<Type> newFld(pfld.size());

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 | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -169,25 +169,25 @@ Foam::functionObjects::regionSizeDistribution::findPatchRegions
const labelHashSet patchIDs(mesh_.boundaryMesh().patchSet(patchNames_));
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
for (const label patchi : patchIDs)
{
nPatchFaces += mesh_.boundaryMesh()[iter.key()].size();
nPatchFaces += mesh_.boundaryMesh()[patchi].size();
}
Map<label> patchRegions(nPatchFaces);
forAllConstIter(labelHashSet, patchIDs, iter)
for (const label patchi : patchIDs)
{
const polyPatch& pp = mesh_.boundaryMesh()[iter.key()];
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
// Collect all regions on the patch
const labelList& faceCells = pp.faceCells();
forAll(faceCells, i)
for (const label celli : faceCells)
{
patchRegions.insert
(
regions[faceCells[i]],
regions[celli],
Pstream::myProcNo() // dummy value
);
}
@ -581,10 +581,9 @@ bool Foam::functionObjects::regionSizeDistribution::write()
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< endl;
forAllConstIter(Map<label>, patchRegions, iter)
for (const label regioni : patchRegions)
{
label regioni = iter.key();
Info<< " " << token::TAB << iter.key()
Info<< " " << token::TAB << regioni
<< token::TAB << allRegionVolume[regioni]
<< token::TAB << allRegionAlphaVolume[regioni] << endl;

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) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,9 +36,9 @@ void Foam::functionObjects::surfaceInterpolate::interpolateFields()
// Convert field to map
HashTable<word> fieldMap(2*fieldSet_.size());
forAll(fieldSet_, i)
for (const auto& namePair : fieldSet_)
{
fieldMap.insert(fieldSet_[i].first(), fieldSet_[i].second());
fieldMap.insert(namePair.first(), namePair.second());
}

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -171,9 +171,8 @@ bool Foam::functionObjects::wallHeatFlux::read(const dictionary& dict)
{
Info<< " processing wall patches: " << nl;
labelHashSet filteredPatchSet;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
if (isA<wallPolyPatch>(pbm[patchi]))
{
filteredPatchSet.insert(patchi);
@ -265,9 +264,8 @@ bool Foam::functionObjects::wallHeatFlux::write()
const surfaceScalarField::Boundary& magSf =
mesh_.magSf().boundaryField();
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
const fvPatch& pp = patches[patchi];
const scalarField& hfp = wallHeatFlux.boundaryField()[patchi];

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 | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -65,10 +65,8 @@ void Foam::functionObjects::wallShearStress::calcShearStress
{
shearStress.dimensions().reset(Reff.dimensions());
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
vectorField& ssp = shearStress.boundaryFieldRef()[patchi];
const vectorField& Sfp = mesh_.Sf().boundaryField()[patchi];
const scalarField& magSfp = mesh_.magSf().boundaryField()[patchi];
@ -156,9 +154,8 @@ bool Foam::functionObjects::wallShearStress::read(const dictionary& dict)
{
Info<< " processing wall patches: " << nl;
labelHashSet filteredPatchSet;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
if (isA<wallPolyPatch>(pbm[patchi]))
{
filteredPatchSet.insert(patchi);
@ -223,9 +220,8 @@ bool Foam::functionObjects::wallShearStress::write()
const fvPatchList& patches = mesh_.boundary();
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
const fvPatch& pp = patches[patchi];
const vectorField& ssp = wallShearStress.boundaryField()[patchi];

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) 2015-2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -222,9 +222,8 @@ void Foam::functionObjects::forces::initialiseBins()
// Determine extents of patches
binMin_ = GREAT;
scalar binMax = -GREAT;
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
const polyPatch& pp = pbm[patchi];
scalarField d(pp.faceCentres() & binDir_);
binMin_ = min(min(d), binMin_);
@ -244,9 +243,8 @@ void Foam::functionObjects::forces::initialiseBins()
const porosityModel& pm = *iter();
const labelList& cellZoneIDs = pm.cellZoneIDs();
forAll(cellZoneIDs, i)
for (const label zonei : cellZoneIDs)
{
label zonei = cellZoneIDs[i];
const cellZone& cZone = mesh_.cellZones()[zonei];
const scalarField d(dd, cZone);
binMin_ = min(min(d), binMin_);
@ -982,10 +980,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
const surfaceVectorField::Boundary& Sfb = mesh_.Sf().boundaryField();
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
vectorField Md
(
mesh_.C().boundaryField()[patchi] - coordSys_.origin()
@ -1026,10 +1022,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
// Scale pRef by density for incompressible simulations
scalar pRef = pRef_/rho(p);
forAllConstIter(labelHashSet, patchSet_, iter)
for (const label patchi : patchSet_)
{
label patchi = iter.key();
vectorField Md
(
mesh_.C().boundaryField()[patchi] - coordSys_.origin()
@ -1076,9 +1070,8 @@ void Foam::functionObjects::forces::calcForcesMoment()
const labelList& cellZoneIDs = pm.cellZoneIDs();
forAll(cellZoneIDs, i)
for (const label zonei : cellZoneIDs)
{
label zonei = cellZoneIDs[i];
const cellZone& cZone = mesh_.cellZones()[zonei];
const vectorField d(mesh_.C(), cZone);

View File

@ -244,9 +244,9 @@ bool Foam::functionObjects::ensightWrite::write()
}
}
forAllConstIter(wordHashSet, candidates, iter)
for (const word& cand : candidates)
{
process(iter.key());
process(cand);
}
Log << " )" << endl;