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

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

- reduced clutter when iterating over containers
parent 60234ab0
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -106,17 +106,16 @@ bool Foam::functionObjects::fieldAverageItem::calculateMeanField
// Note: looks up all window fields from the registry
meanField = 0*baseField;
FIFOStack<scalar>::const_iterator timeIter =
windowTimes_.begin();
FIFOStack<word>::const_iterator nameIter =
windowFieldNames_.begin();
auto timeIter = windowTimes_.cbegin();
auto nameIter = windowFieldNames_.cbegin();
const Type* wOld = nullptr;
for
(
;
timeIter != windowTimes_.end();
timeIter.good();
++timeIter, ++nameIter
)
{
......@@ -223,10 +222,9 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
{
// Not storing old time mean fields - treat all as TIME (integrated)
prime2MeanField = 0*prime2MeanField;
FIFOStack<scalar>::const_iterator timeIter =
windowTimes_.begin();
FIFOStack<word>::const_iterator nameIter =
windowFieldNames_.begin();
auto timeIter = windowTimes_.cbegin();
auto nameIter = windowFieldNames_.cbegin();
switch (base_)
{
......@@ -236,7 +234,7 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
++timeIter;
++nameIter;
if (timeIter == windowTimes_.end()) return false;
if (!timeIter.good()) return false;
break;
}
......@@ -252,7 +250,7 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
for
(
;
timeIter != windowTimes_.end();
timeIter.good();
++timeIter, ++nameIter
)
{
......@@ -272,7 +270,6 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
prime2MeanField /= windowLength;
break;
}
default:
......
......@@ -160,9 +160,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
);
InfoInFunction << "Dumping tracks to " << str.name() << endl;
forAllConstIter(Cloud<findCellParticle>, cloud, iter)
for (const findCellParticle& tp : cloud)
{
const findCellParticle& tp = iter();
str.write(linePointRef(tp.position(), tp.end()));
}
}
......@@ -186,9 +185,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
{
start.setSize(nPatchFaces);
nPatchFaces = 0;
forAllConstIter(Cloud<findCellParticle>, cloud, iter)
for (const findCellParticle& tp : cloud)
{
const findCellParticle& tp = iter();
start[nPatchFaces++] = tp.position();
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2013-2016 OpenFOAM Foundation
......@@ -121,7 +121,7 @@ void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
// Knock out any cell not in patchRegions
forAll(liquidCore, celli)
{
label regioni = regions[celli];
const label regioni = regions[celli];
if (patchRegions.found(regioni))
{
backgroundAlpha[celli] = 0;
......@@ -130,7 +130,7 @@ void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
{
liquidCore[celli] = 0;
scalar regionVol = regionVolume[regioni];
const scalar regionVol = regionVolume[regioni];
if (regionVol < maxDropletVol)
{
backgroundAlpha[celli] = 0;
......@@ -144,8 +144,8 @@ void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
{
Info<< " Volume of liquid-core = "
<< fvc::domainIntegrate(liquidCore).value()
<< endl;
Info<< " Volume of background = "
<< nl
<< " Volume of background = "
<< fvc::domainIntegrate(backgroundAlpha).value()
<< endl;
}
......@@ -549,19 +549,18 @@ bool Foam::functionObjects::regionSizeDistribution::write()
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< token::TAB << "nCells"
<< endl;
<< nl;
scalar meshSumVol = 0.0;
scalar alphaSumVol = 0.0;
label nCells = 0;
Map<scalar>::const_iterator vIter = allRegionVolume.begin();
Map<scalar>::const_iterator aIter = allRegionAlphaVolume.begin();
Map<label>::const_iterator numIter = allRegionNumCells.begin();
auto vIter = allRegionVolume.cbegin();
auto aIter = allRegionAlphaVolume.cbegin();
auto numIter = allRegionNumCells.cbegin();
for
(
;
vIter != allRegionVolume.end()
&& aIter != allRegionAlphaVolume.end();
vIter.good() && aIter.good();
++vIter, ++aIter, ++numIter
)
{
......@@ -569,7 +568,7 @@ bool Foam::functionObjects::regionSizeDistribution::write()
<< token::TAB << vIter()
<< token::TAB << aIter()
<< token::TAB << numIter()
<< endl;
<< nl;
meshSumVol += vIter();
alphaSumVol += aIter();
......@@ -583,20 +582,20 @@ bool Foam::functionObjects::regionSizeDistribution::write()
}
if (log)
{
Info<< " Patch connected regions (liquid core):" << endl;
Info<< " Patch connected regions (liquid core):" << nl;
Info<< token::TAB << " Region"
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< endl;
<< nl;
forAllConstIters(patchRegions, iter)
{
const label regioni = iter.key();
Info<< " " << token::TAB << regioni
<< token::TAB << allRegionVolume[regioni]
<< token::TAB << allRegionAlphaVolume[regioni] << endl;
<< token::TAB << allRegionAlphaVolume[regioni] << nl;
}
Info<< endl;
......@@ -604,19 +603,19 @@ bool Foam::functionObjects::regionSizeDistribution::write()
if (log)
{
Info<< " Background regions:" << endl;
Info<< " Background regions:" << nl;
Info<< " " << token::TAB << "Region"
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< endl;
Map<scalar>::const_iterator vIter = allRegionVolume.begin();
Map<scalar>::const_iterator aIter = allRegionAlphaVolume.begin();
<< nl;
auto vIter = allRegionVolume.cbegin();
auto aIter = allRegionAlphaVolume.cbegin();
for
(
;
vIter != allRegionVolume.end()
&& aIter != allRegionAlphaVolume.end();
vIter.good() && aIter.good();
++vIter, ++aIter
)
{
......@@ -628,7 +627,7 @@ bool Foam::functionObjects::regionSizeDistribution::write()
{
Info<< " " << token::TAB << vIter.key()
<< token::TAB << vIter()
<< token::TAB << aIter() << endl;
<< token::TAB << aIter() << nl;
}
}
Info<< endl;
......@@ -651,9 +650,9 @@ bool Foam::functionObjects::regionSizeDistribution::write()
// allRegionAlphaVolume since background might not have alpha in it.
// Deleting regions where the volume-alpha-weighted is lower than
// threshold
forAllIter(Map<scalar>, allRegionVolume, vIter)
forAllIters(allRegionVolume, vIter)
{
label regioni = vIter.key();
const label regioni = vIter.key();
if
(
patchRegions.found(regioni)
......@@ -783,14 +782,14 @@ bool Foam::functionObjects::regionSizeDistribution::write()
<< " " << token::TAB << "Bin"
<< token::TAB << "Min distance"
<< token::TAB << "Count:"
<< endl;
<< nl;
scalar delta = 0.0;
forAll(binDownCount, bini)
{
Info<< " " << token::TAB << bini
<< token::TAB << delta
<< token::TAB << binDownCount[bini] << endl;
<< token::TAB << binDownCount[bini] << nl;
delta += deltaX;
}
Info<< endl;
......@@ -836,14 +835,14 @@ bool Foam::functionObjects::regionSizeDistribution::write()
<< " " << token::TAB << "Bin"
<< token::TAB << "Min diameter"
<< token::TAB << "Count:"
<< endl;
<< nl;
scalar diam = 0.0;
forAll(binCount, bini)
{
Info<< " " << token::TAB << bini
<< token::TAB << diam
<< token::TAB << binCount[bini] << endl;
<< token::TAB << binCount[bini] << nl;
diam += delta;
}
......
......@@ -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) 2012-2016 OpenFOAM Foundation
......@@ -43,18 +43,10 @@ Foam::Map<Type> Foam::functionObjects::regionSizeDistribution::regionSum
forAll(fld, celli)
{
label regioni = regions[celli];
typename Map<Type>::iterator fnd = regionToSum.find(regioni);
if (fnd == regionToSum.end())
{
regionToSum.insert(regioni, fld[celli]);
}
else
{
fnd() += fld[celli];
}
const label regioni = regions[celli];
regionToSum(regioni, Type(Zero)) += fld[celli];
}
Pstream::mapCombineGather(regionToSum, plusEqOp<Type>());
Pstream::mapCombineScatter(regionToSum);
......
......@@ -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-2017 OpenFOAM Foundation
......@@ -389,11 +389,11 @@ void Foam::streamLineParticle::readFields(Cloud<streamLineParticle>& c)
c.checkFieldIOobject(c, sampledPositions);
label i = 0;
forAllIter(Cloud<streamLineParticle>, c, iter)
for (streamLineParticle& p : c)
{
iter().lifeTime_ = lifeTime[i];
iter().sampledPositions_.transfer(sampledPositions[i]);
i++;
p.lifeTime_ = lifeTime[i];
p.sampledPositions_.transfer(sampledPositions[i]);
++i;
}
}
......@@ -402,7 +402,7 @@ void Foam::streamLineParticle::writeFields(const Cloud<streamLineParticle>& c)
{
particle::writeFields(c);
label np = c.size();
const label np = c.size();
IOField<label> lifeTime
(
......@@ -416,11 +416,11 @@ void Foam::streamLineParticle::writeFields(const Cloud<streamLineParticle>& c)
);
label i = 0;
forAllConstIter(Cloud<streamLineParticle>, c, iter)
for (const streamLineParticle& p : c)
{
lifeTime[i] = iter().lifeTime_;
sampledPositions[i] = iter().sampledPositions_;
i++;
lifeTime[i] = p.lifeTime_;
sampledPositions[i] = p.sampledPositions_;
++i;
}
lifeTime.write(np > 0);
......
......@@ -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
......@@ -46,7 +46,7 @@ void Foam::functionObjects::surfaceInterpolate::interpolateFields()
HashTable<const VolFieldType*> flds(obr_.lookupClass<VolFieldType>());
forAllConstIter(typename HashTable<const VolFieldType*>, flds, iter)
forAllConstIters(flds, iter)
{
const VolFieldType& fld = *iter();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -305,16 +305,8 @@ bool Foam::functionObjects::wallBoundedStreamLine::read(const dictionary& dict)
forAll(f, fp)
{
const edge e(f[fp], f.nextLabel(fp));
EdgeMap<label>::iterator eFnd = numFacesPerEdge.find(e);
if (eFnd != numFacesPerEdge.end())
{
eFnd()++;
}
else
{
numFacesPerEdge.insert(e, 1);
}
++(numFacesPerEdge(e, 0));
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -218,11 +218,11 @@ void Foam::wallBoundedStreamLineParticle::readFields
c.checkFieldIOobject(c, sampledPositions);
label i = 0;
forAllIter(Cloud<wallBoundedStreamLineParticle>, c, iter)
for (wallBoundedStreamLineParticle& p : c)
{
iter().lifeTime_ = lifeTime[i];
iter().sampledPositions_.transfer(sampledPositions[i]);
i++;
p.lifeTime_ = lifeTime[i];
p.sampledPositions_.transfer(sampledPositions[i]);
++i;
}
}
......@@ -234,7 +234,7 @@ void Foam::wallBoundedStreamLineParticle::writeFields
{
wallBoundedParticle::writeFields(c);
label np = c.size();
const label np = c.size();
IOField<label> lifeTime
(
......@@ -248,11 +248,11 @@ void Foam::wallBoundedStreamLineParticle::writeFields
);
label i = 0;
forAllConstIter(Cloud<wallBoundedStreamLineParticle>, c, iter)
for (const wallBoundedStreamLineParticle& p : c)
{
lifeTime[i] = iter().lifeTime_;
sampledPositions[i] = iter().sampledPositions_;
i++;
lifeTime[i] = p.lifeTime_;
sampledPositions[i] = p.sampledPositions_;
++i;
}
lifeTime.write();
......
......@@ -240,7 +240,7 @@ void Foam::functionObjects::forces::initialiseBins()
const scalarField dd(mesh_.C() & binDir_);
forAllConstIter(HashTable<const porosityModel*>, models, iter)
forAllConstIters(models, iter)
{
const porosityModel& pm = *iter();
const labelList& cellZoneIDs = pm.cellZoneIDs();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2016, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2015 OpenFOAM Foundation
......@@ -121,10 +121,8 @@ void Foam::functionObjects::runTimeControls::averageCondition::calc
windowValues.push(currentValue);
// Calculate the window average
typename FIFOStack<scalar>::const_iterator timeIter =
windowTimes.begin();
typename FIFOStack<Type>::const_iterator valueIter =
windowValues.begin();
auto timeIter = windowTimes.cbegin();
auto valueIter = windowValues.cbegin();
meanValue = pTraits<Type>::zero;
Type valueOld(pTraits<Type>::zero);
......@@ -132,7 +130,7 @@ void Foam::functionObjects::runTimeControls::averageCondition::calc
for
(
label i = 0;
timeIter != windowTimes.end();
timeIter.good();
++i, ++timeIter, ++valueIter
)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment