Commit c508da8f authored by Mark Olesen's avatar Mark Olesen
Browse files

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

- reduced clutter when iterating over containers
parent 0fadde13
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -65,10 +65,8 @@ Foam::CollidingCloud<CloudType>::rotationalKineticEnergyOfSystem() const
{
scalar rotationalKineticEnergy = 0.0;
forAllConstIter(typename CollidingCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
rotationalKineticEnergy +=
p.nParticle()*0.5*p.momentOfInertia()*(p.omega() & p.omega());
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011, 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -155,14 +155,14 @@ void Foam::KinematicCloud<CloudType>::buildCellOccupancy()
List<DynamicList<parcelType*>>& cellOccupancy = cellOccupancyPtr_();
forAll(cellOccupancy, cO)
for (auto& list : cellOccupancy)
{
cellOccupancy[cO].clear();
list.clear();
}
forAllIter(typename KinematicCloud<CloudType>, *this, iter)
for (parcelType& p : *this)
{
cellOccupancy[iter().cell()].append(&iter());
cellOccupancy[p.cell()].append(&p);
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -273,10 +273,9 @@ template<class CloudType>
inline Foam::scalar Foam::KinematicCloud<CloudType>::massInSystem() const
{
scalar sysMass = 0.0;
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
sysMass += p.nParticle()*p.mass();
sysMass += p.nParticle()*p.mass();
}
return sysMass;
......@@ -289,10 +288,8 @@ Foam::KinematicCloud<CloudType>::linearMomentumOfSystem() const
{
vector linearMomentum(Zero);
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
linearMomentum += p.nParticle()*p.mass()*p.U();
}
......@@ -306,10 +303,8 @@ Foam::KinematicCloud<CloudType>::linearKineticEnergyOfSystem() const
{
scalar linearKineticEnergy = 0.0;
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
linearKineticEnergy += p.nParticle()*0.5*p.mass()*(p.U() & p.U());
}
......@@ -326,9 +321,8 @@ inline Foam::scalar Foam::KinematicCloud<CloudType>::Dij
{
scalar si = 0.0;
scalar sj = 0.0;
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
si += p.nParticle()*pow(p.d(), i);
sj += p.nParticle()*pow(p.d(), j);
}
......@@ -345,9 +339,8 @@ template<class CloudType>
inline Foam::scalar Foam::KinematicCloud<CloudType>::Dmax() const
{
scalar d = -GREAT;
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
d = max(d, p.d());
}
......@@ -477,9 +470,8 @@ Foam::KinematicCloud<CloudType>::vDotSweep() const
);
volScalarField& vDotSweep = tvDotSweep.ref();
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
const label celli = p.cell();
vDotSweep[celli] += p.nParticle()*p.areaP()*mag(p.U() - U_[celli]);
......@@ -516,9 +508,8 @@ Foam::KinematicCloud<CloudType>::theta() const
);
volScalarField& theta = ttheta.ref();
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
const label celli = p.cell();
theta[celli] += p.nParticle()*p.volume();
......@@ -554,9 +545,8 @@ Foam::KinematicCloud<CloudType>::alpha() const
);
scalarField& alpha = talpha.ref().primitiveFieldRef();
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
const label celli = p.cell();
alpha[celli] += p.nParticle()*p.mass();
......@@ -591,9 +581,8 @@ Foam::KinematicCloud<CloudType>::rhoEff() const
);
scalarField& rhoEff = trhoEff.ref().primitiveFieldRef();
forAllConstIter(typename KinematicCloud<CloudType>, *this, iter)
for (const parcelType& p : *this)
{
const parcelType& p = iter();
const label celli = p.cell();
rhoEff[celli] += p.nParticle()*p.mass();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -374,48 +374,42 @@ Foam::ThermoCloud<CloudType>::sigmap() const
template<class CloudType>
inline Foam::scalar Foam::ThermoCloud<CloudType>::Tmax() const
{
scalar T = -GREAT;
scalar n = 0;
forAllConstIter(typename ThermoCloud<CloudType>, *this, iter)
scalar val = -GREAT;
bool nonEmpty = false;
for (const parcelType& p : *this)
{
const parcelType& p = iter();
T = max(T, p.T());
n++;
val = max(val, p.T());
nonEmpty = true;
}
reduce(T, maxOp<scalar>());
reduce(n, sumOp<label>());
if (n > 0)
if (returnReduce(nonEmpty, orOp<bool>()))
{
return T;
return returnReduce(val, maxOp<scalar>());
}
return 0.0;
return 0;
}
template<class CloudType>
inline Foam::scalar Foam::ThermoCloud<CloudType>::Tmin() const
{
scalar T = GREAT;
scalar n = 0;
forAllConstIter(typename ThermoCloud<CloudType>, *this, iter)
scalar val = GREAT;
bool nonEmpty = false;
for (const parcelType& p : *this)
{
const parcelType& p = iter();
T = min(T, p.T());
n++;
val = min(val, p.T());
nonEmpty = true;
}
reduce(T, minOp<scalar>());
reduce(n, sumOp<label>());
if (n > 0)
if (returnReduce(nonEmpty, orOp<bool>()))
{
return T;
return returnReduce(val, minOp<scalar>());
}
return 0.0;
return 0;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2011 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011-2011, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -164,10 +164,8 @@ void Foam::CollidingParcel<ParcelType>::readFields(CloudType& c)
label i = 0;
forAllIter(typename CloudType, c, iter)
for (CollidingParcel<ParcelType>& p : c)
{
CollidingParcel<ParcelType>& p = iter();
p.f_ = f[i];
p.angularMomentum_ = angularMomentum[i];
p.torque_ = torque[i];
......@@ -183,7 +181,7 @@ void Foam::CollidingParcel<ParcelType>::readFields(CloudType& c)
collisionRecordsWallData[i]
);
i++;
++i;
}
}
......@@ -245,11 +243,8 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
);
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const CollidingParcel<ParcelType>& p : c)
{
const CollidingParcel<ParcelType>& p = iter();
f[i] = p.f();
angularMomentum[i] = p.angularMomentum();
torque[i] = p.torque();
......@@ -264,7 +259,7 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
collisionRecordsWallPRel[i] = p.collisionRecords().wallPRel();
collisionRecordsWallData[i] = p.collisionRecords().wallData();
i++;
++i;
}
const bool valid = (np > 0);
......@@ -303,15 +298,13 @@ void Foam::CollidingParcel<ParcelType>::writeObjects
IOField<vector>& torque(cloud::createIOField<vector>("torque", np, obr));
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const CollidingParcel<ParcelType>& p : c)
{
const CollidingParcel<ParcelType>& p = iter();
f[i] = p.f();
angularMomentum[i] = p.angularMomentum();
torque[i] = p.torque();
i++;
++i;
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011, 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -176,10 +176,8 @@ void Foam::KinematicParcel<ParcelType>::readFields(CloudType& c)
label i = 0;
forAllIter(typename CloudType, c, iter)
for (KinematicParcel<ParcelType>& p : c)
{
KinematicParcel<ParcelType>& p = iter();
p.active_ = active[i];
p.typeId_ = typeId[i];
p.nParticle_ = nParticle[i];
......@@ -191,7 +189,7 @@ void Foam::KinematicParcel<ParcelType>::readFields(CloudType& c)
p.tTurb_ = tTurb[i];
p.UTurb_ = UTurb[i];
i++;
++i;
}
}
......@@ -221,10 +219,8 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const KinematicParcel<ParcelType>& p : c)
{
const KinematicParcel<ParcelType>& p = iter();
active[i] = p.active();
typeId[i] = p.typeId();
nParticle[i] = p.nParticle();
......@@ -236,7 +232,7 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
tTurb[i] = p.tTurb();
UTurb[i] = p.UTurb();
i++;
++i;
}
const bool valid = np > 0;
......@@ -282,10 +278,8 @@ void Foam::KinematicParcel<ParcelType>::writeObjects
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const KinematicParcel<ParcelType>& p : c)
{
const KinematicParcel<ParcelType>& p = iter();
active[i] = p.active();
typeId[i] = p.typeId();
nParticle[i] = p.nParticle();
......@@ -297,7 +291,7 @@ void Foam::KinematicParcel<ParcelType>::writeObjects
tTurb[i] = p.tTurb();
UTurb[i] = p.UTurb();
i++;
++i;
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2013-2017 OpenFOAM Foundation
......@@ -92,14 +92,11 @@ void Foam::MPPICParcel<ParcelType>::readFields(CloudType& c)
c.checkFieldIOobject(c, UCorrect);
label i = 0;
forAllIter(typename CloudType, c, iter)
for (MPPICParcel<ParcelType>& p : c)
{
MPPICParcel<ParcelType>& p = iter();
p.UCorrect_ = UCorrect[i];
i++;
++i;
}
}
......@@ -117,13 +114,11 @@ void Foam::MPPICParcel<ParcelType>::writeFields(const CloudType& c)
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const MPPICParcel<ParcelType>& p : c)
{
const MPPICParcel<ParcelType>& p = iter();
UCorrect[i] = p.UCorrect();
i++;
++i;
}
UCorrect.write(np > 0);
......@@ -147,13 +142,11 @@ void Foam::MPPICParcel<ParcelType>::writeObjects
label i = 0;
forAllConstIter(typename CloudType, c, iter)
for (const MPPICParcel<ParcelType>& p : c)
{
const MPPICParcel<ParcelType>& p = iter();
UCorrect[i] = p.UCorrect();
i++;
++i;
}
}
......
......@@ -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-2017 OpenFOAM Foundation
......@@ -174,9 +174,8 @@ inline void Foam::MPPICParcel<ParcelType>::trackingData::updateAverages
AveragingMethod<scalar>& weightAverage = weightAveragePtr();
// averaging sums
forAllConstIter(typename TrackCloudType, cloud, iter)
for (const typename TrackCloudType::parcelType& p : cloud)
{
const typename TrackCloudType::parcelType& p = iter();
const tetIndices tetIs = p.currentTetIndices();
const scalar m = p.nParticle()*p.mass();
......@@ -192,9 +191,8 @@ inline void Foam::MPPICParcel<ParcelType>::trackingData::updateAverages
uAverage_->average(*massAverage_);
// squared velocity deviation
forAllConstIter(typename TrackCloudType, cloud, iter)
for (const typename TrackCloudType::parcelType& p : cloud)
{
const typename TrackCloudType::parcelType& p = iter();
const tetIndices tetIs = p.currentTetIndices();
const vector u = uAverage_->interpolate(p.coordinates(), tetIs);
......@@ -211,9 +209,8 @@ inline void Foam::MPPICParcel<ParcelType>::trackingData::updateAverages
// sauter mean radius
radiusAverage_() = volumeAverage_();
weightAverage = 0;
forAllConstIter(typename TrackCloudType, cloud, iter)
for (const typename TrackCloudType::parcelType& p : cloud)
{
const typename TrackCloudType::parcelType& p = iter();
const tetIndices tetIs = p.currentTetIndices();
weightAverage.add
......@@ -228,9 +225,8 @@ inline void Foam::MPPICParcel<ParcelType>::trackingData::updateAverages
// collision frequency
weightAverage = 0;
forAllConstIter(typename TrackCloudType, cloud, iter)
for (const typename TrackCloudType::parcelType& p : cloud)
{
const typename TrackCloudType::parcelType& p = iter();
const tetIndices tetIs = p.currentTetIndices();
const scalar a = volumeAverage_->interpolate(p.coordinates(), tetIs);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2011, 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2011, 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -115,9 +115,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
const wordList& stateLabels = compModel.stateLabels();
// Set storage for each Y... for each parcel
forAllIter(typename Cloud<ReactingMultiphaseParcel<ParcelType>>, c, iter)
for (ReactingMultiphaseParcel<ParcelType>& p : c)
{
ReactingMultiphaseParcel<ParcelType>& p = iter();
p.YGas_.setSize(gasNames.size(), 0.0);
p.YLiquid_.setSize(liquidNames.size(), 0.0);
p.YSolid_.setSize(solidNames.size(), 0.0);
......@@ -137,14 +136,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
);
label i = 0;
forAllIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
for (ReactingMultiphaseParcel<ParcelType>& p : c)
{
ReactingMultiphaseParcel<ParcelType>& p = iter();
p.YGas_[j] = YGas[i++]/(p.Y()[GAS] + ROOTVSMALL);
}
}
......@@ -162,14 +155,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
);
label i = 0;
forAllIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
for (ReactingMultiphaseParcel<ParcelType>& p : c)
{
ReactingMultiphaseParcel<ParcelType>& p = iter();
p.YLiquid_[j] = YLiquid[i++]/(p.Y()[LIQ] + ROOTVSMALL);
}
}
......@@ -187,14 +174,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::readFields
);
label i = 0;
forAllIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
for (ReactingMultiphaseParcel<ParcelType>& p : c)
{
ReactingMultiphaseParcel<ParcelType>& p = iter();
p.YSolid_[j] = YSolid[i++]/(p.Y()[SLD] + ROOTVSMALL);
}
}
......@@ -240,14 +221,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
for (const ReactingMultiphaseParcel<ParcelType>& p0 : c)
{
const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
YGas[i++] = p0.YGas()[j]*p0.Y()[GAS];
}
......@@ -269,14 +244,8 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
for (const ReactingMultiphaseParcel<ParcelType>& p0 : c)