Commit 27c62303 authored by Mark Olesen's avatar Mark Olesen
Browse files

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

- reduced clutter when iterating over containers
parent 07a6e9d8
......@@ -39,7 +39,7 @@
).ptr()
);
phasei++;
++phasei;
}
// Cache p_rgh prior to solve for density update
......@@ -73,7 +73,7 @@
p_rghEqnComp.ref() += hmm;
}
phasei++;
++phasei;
}
solve
......@@ -86,18 +86,13 @@
if (pimple.finalNonOrthogonalIter())
{
phasei = 0;
forAllIter
(
PtrDictionary<phaseModel>,
mixture.phases(),
phase
)
for (phaseModel& phase : mixture.phases())
{
phase().dgdt() =
pos0(phase())
*(p_rghEqnComps[phasei] & p_rgh)/phase().thermo().rho();
phase.dgdt() =
pos0(phase)
*(p_rghEqnComps[phasei] & p_rgh)/phase.thermo().rho();
phasei++;
++phasei;
}
phi = phiHbyA + p_rghEqnIncomp.flux();
......
{
forAllIter(UPtrList<phaseModel>, fluid.phases(), iter)
for (phaseModel& phase : fluid.phases())
{
phaseModel& phase = iter();
PtrList<volScalarField>& Y = phase.Y();
if (!Y.empty())
......@@ -55,4 +54,3 @@
}
}
}
......@@ -133,7 +133,7 @@ void Foam::radiation::laserDTRM::initialiseReflection()
{
dictTable modelDicts(lookup("reflectionModel"));
forAllConstIter(dictTable, modelDicts, iter)
forAllConstIters(modelDicts, iter)
{
const phasePairKey& key = iter.key();
......@@ -142,7 +142,7 @@ void Foam::radiation::laserDTRM::initialiseReflection()
key,
reflectionModel::New
(
*iter,
iter.object(),
mesh_
)
);
......@@ -612,20 +612,23 @@ void Foam::radiation::laserDTRM::calculate()
reflectionUPtr.resize(reflections_.size());
label reflectionModelId(0);
forAllIter(reflectionModelTable, reflections_, iter1)
forAllIters(reflections_, iter1)
{
reflectionModel& model = iter1()();
reflectionUPtr.set(reflectionModelId, &model);
const word alpha1Name = "alpha." + iter1.key().first();
const word alpha2Name = "alpha." + iter1.key().second();
const volScalarField& alphaFrom =
mesh_.lookupObject<volScalarField>(alpha1Name);
mesh_.lookupObject<volScalarField>
(
IOobject::groupName("alpha", iter1.key().first())
);
const volScalarField& alphaTo =
mesh_.lookupObject<volScalarField>(alpha2Name);
mesh_.lookupObject<volScalarField>
(
IOobject::groupName("alpha", iter1.key().second())
);
const volVectorField nHatPhase(nHatfv(alphaFrom, alphaTo));
......@@ -700,9 +703,8 @@ void Foam::radiation::laserDTRM::calculate()
DynamicList<point> positionsMyProc;
DynamicList<point> p0MyProc;
forAllIter(Cloud<DTRMParticle>, DTRMCloud_, iter)
for (const DTRMParticle& p : DTRMCloud_)
{
DTRMParticle& p = iter();
positionsMyProc.append(p.position());
p0MyProc.append(p.p0());
}
......
......@@ -41,7 +41,6 @@ SourceFiles
#include "volFields.H"
#include "dictionary.H"
#include "hashedWordList.H"
#include "runTimeSelectionTables.H"
#include "Enum.H"
......
......@@ -44,7 +44,7 @@ Foam::MassTransferPhaseSystem<BasePhaseSystem>::MassTransferPhaseSystem
{
this->generatePairsAndSubModels("massTransferModel", massTransferModels_);
forAllConstIter(massTransferModelTable, massTransferModels_, iterModel)
forAllConstIters(massTransferModels_, iterModel)
{
if (!dmdt_.found(iterModel()->pair()))
{
......@@ -184,22 +184,17 @@ Foam::MassTransferPhaseSystem<BasePhaseSystem>::heatTransfer
fvScalarMatrix& eqn = tEqnPtr.ref();
forAllIter(phaseSystem::phaseModelTable, this->phaseModels_, iteri)
forAllConstIters(this->phaseModels_, iteri)
{
phaseModel& phasei = iteri()();
const phaseModel& phasei = iteri()();
phaseSystem::phaseModelTable::iterator iterk = iteri;
iterk++;
for
(
;
iterk != this->phaseModels_.end();
++iterk
)
auto iterk = iteri;
for (++iterk; iterk != this->phaseModels_.end(); ++iterk)
{
if (iteri()().name() != iterk()().name())
{
phaseModel& phasek = iterk()();
const phaseModel& phasek = iterk()();
// Phase i to phase k
const phasePairKey keyik(phasei.name(), phasek.name(), true);
......@@ -290,7 +285,7 @@ void Foam::MassTransferPhaseSystem<BasePhaseSystem>::massSpeciesTransfer
)
{
// Fill the volumetric mass transfer for species
forAllIter(massTransferModelTable, massTransferModels_, iter)
forAllConstIters(massTransferModels_, iter)
{
if (iter()->transferSpecie() == speciesName)
{
......
......@@ -63,7 +63,7 @@ MultiComponentPhaseModel
).ptr()
);
if (thermoPtr_->composition().species().size() == 0)
if (thermoPtr_->composition().species().empty())
{
FatalErrorInFunction
<< " The selected thermo is pure. Use a multicomponent thermo."
......
......@@ -65,18 +65,18 @@ Foam::multiphaseSystem::multiphaseSystem
Su_(phaseModels_.size()),
Sp_(phaseModels_.size())
{
label phaseI = 0;
label phasei = 0;
phases_.setSize(phaseModels_.size());
forAllConstIter(HashTable<autoPtr<phaseModel>>, phaseModels_, iter)
forAllIters(phaseModels_, iter)
{
phaseModel& pm = const_cast<phaseModel&>(iter()());
phases_.set(phaseI++, &pm);
phaseModel& pm = iter()();
phases_.set(phasei++, &pm);
}
// Initiate Su and Sp
forAllConstIter(HashTable<autoPtr<phaseModel>>, phaseModels_, iter)
forAllConstIters(phaseModels_, iter)
{
phaseModel& pm = const_cast<phaseModel&>(iter()());
const phaseModel& pm = iter()();
Su_.insert
(
......@@ -117,7 +117,7 @@ Foam::multiphaseSystem::multiphaseSystem
void Foam::multiphaseSystem::calculateSuSp()
{
forAllIter(phaseSystem::phasePairTable, totalPhasePairs_, iter)
forAllConstIters(totalPhasePairs_, iter)
{
const phasePair& pair = iter()();
......@@ -297,10 +297,9 @@ void Foam::multiphaseSystem::solve()
for (int acorr=0; acorr<nAlphaCorr; acorr++)
{
int phasei = 0;
forAllIter(UPtrList<phaseModel>, phases_, iter)
label phasei = 0;
for (phaseModel& phase1 : phases_)
{
phaseModel& phase1 = iter();
const volScalarField& alpha1 = phase1;
phiAlphaCorrs.set
......@@ -320,15 +319,11 @@ void Foam::multiphaseSystem::solve()
surfaceScalarField& phiAlphaCorr = phiAlphaCorrs[phasei];
forAllIter(UPtrList<phaseModel>, phases_, iter2)
for (phaseModel& phase2 : phases_)
{
phaseModel& phase2 = iter2();
const volScalarField& alpha2 = phase2;
if (&phase2 == &phase1)
{
continue;
}
if (&phase2 == &phase1) continue;
const phasePairKey key12(phase1.name(), phase2.name());
......@@ -337,7 +332,7 @@ void Foam::multiphaseSystem::solve()
FatalErrorInFunction
<< "Phase compression factor (cAlpha) not found for : "
<< key12
<< exit(FatalError);
<< exit(FatalError);
}
scalar cAlpha = cAlphas_.find(key12)();
......@@ -380,13 +375,12 @@ void Foam::multiphaseSystem::solve()
}
}
phasei++;
++phasei;
}
// Set Su and Sp tp zero
forAllIter(UPtrList<phaseModel>, phases_, iter)
// Set Su and Sp to zero
for (const phaseModel& phase : phases_)
{
phaseModel& phase = iter();
Su_[phase.name()] = dimensionedScalar("Su", dimless/dimTime, Zero);
Sp_[phase.name()] = dimensionedScalar("Sp", dimless/dimTime, Zero);
......@@ -402,9 +396,8 @@ void Foam::multiphaseSystem::solve()
// Limit phiAlphaCorr on each phase
phasei = 0;
forAllIter(UPtrList<phaseModel>, phases_, iter)
for (phaseModel& phase : phases_)
{
phaseModel& phase = iter();
volScalarField& alpha1 = phase;
surfaceScalarField& phiAlphaCorr = phiAlphaCorrs[phasei];
......@@ -425,7 +418,7 @@ void Foam::multiphaseSystem::solve()
0,
true
);
phasei ++;
++phasei;
}
MULES::limitSum(phiAlphaCorrs);
......@@ -443,9 +436,8 @@ void Foam::multiphaseSystem::solve()
);
phasei = 0;
forAllIter(UPtrList<phaseModel>, phases_, iter)
for (phaseModel& phase : phases_)
{
phaseModel& phase = iter();
volScalarField& alpha1 = phase;
const volScalarField::Internal& Su = Su_[phase.name()];
......@@ -508,13 +500,9 @@ void Foam::multiphaseSystem::solve()
}
phase.alphaPhi() /= nAlphaSubCycles;
}
else
{
phaseModel& phase = iter();
volScalarField& alpha1 = phase;
MULES::explicitSolve
(
geometricOneField(),
......@@ -530,7 +518,7 @@ void Foam::multiphaseSystem::solve()
phase.alphaPhi() = phiAlpha;
}
phasei++;
++phasei;
}
if (acorr == nAlphaCorr - 1)
......@@ -550,15 +538,13 @@ void Foam::multiphaseSystem::solve()
// Reset rhoPhi
rhoPhi_ = dimensionedScalar("rhoPhi", dimMass/dimTime, Zero);
forAllIter(UPtrList<phaseModel>, phases_, iter)
for (phaseModel& phase : phases_)
{
phaseModel& phase = iter();
volScalarField& alpha1 = phase;
sumAlpha += alpha1;
// Update rhoPhi
rhoPhi_ +=
fvc::interpolate(phase.rho())*phase.alphaPhi();
rhoPhi_ += fvc::interpolate(phase.rho()) * phase.alphaPhi();
}
......@@ -570,9 +556,8 @@ void Foam::multiphaseSystem::solve()
volScalarField sumCorr(1.0 - sumAlpha);
forAllIter(UPtrList<phaseModel>, phases_, iter)
for (phaseModel& phase : phases_)
{
phaseModel& phase = iter();
volScalarField& alpha = phase;
alpha += alpha*sumCorr;
......@@ -619,24 +604,16 @@ Foam::dimensionedScalar Foam::multiphaseSystem::ddtAlphaMax() const
Foam::scalar Foam::multiphaseSystem::maxDiffNo() const
{
phaseModelTable::const_iterator phaseModelIter = phaseModels_.begin();
tmp<surfaceScalarField> kapparhoCpbyDelta(phaseModelIter()->diffNo());
auto iter = phaseModels_.cbegin();
scalar DiNum =
max(kapparhoCpbyDelta.ref()).value()*mesh_.time().deltaT().value();
scalar maxVal = max(iter()->diffNo()).value();
++phaseModelIter;
for (; phaseModelIter != phaseModels_.end(); ++ phaseModelIter)
for (++iter; iter != phaseModels_.cend(); ++iter)
{
kapparhoCpbyDelta = phaseModelIter()->diffNo();
DiNum =
max
(
DiNum,
max(kapparhoCpbyDelta).value()*mesh_.time().deltaT().value()
);
maxVal = max(maxVal, max(iter()->diffNo()).value());
}
return DiNum;
return maxVal * mesh_.time().deltaT().value();
}
......
......@@ -23,7 +23,6 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class modelType>
......@@ -38,7 +37,7 @@ void Foam::phaseSystem::createSubModels
>& models
)
{
forAllConstIter(dictTable, modelDicts, iter)
forAllConstIters(modelDicts, iter)
{
const phasePairKey& key = iter.key();
......@@ -47,8 +46,8 @@ void Foam::phaseSystem::createSubModels
key,
modelType::New
(
*iter,
phasePairs_[key]
iter.object(),
phasePairs_[key]
)
);
}
......@@ -68,7 +67,7 @@ void Foam::phaseSystem::createSubModels
>& models
)
{
forAllConstIter(dictTable, modelDicts, iter)
forAllConstIters(modelDicts, iter)
{
const phasePairKey& key = iter.key();
......@@ -77,8 +76,8 @@ void Foam::phaseSystem::createSubModels
key,
modelType::New
(
*iter,
mesh
iter.object(),
mesh
)
);
}
......@@ -142,18 +141,18 @@ void Foam::phaseSystem::generatePairsAndSubModels
HashTable<autoPtr<modelType>, phasePairKey, phasePairKey::hash>
modelTypeTable;
forAllConstIter(wordList, phaseNames_, phaseNameIter)
for (const word& phaseName : phaseNames_)
{
modelTypeTable tempModels;
generatePairsAndSubModels
(
IOobject::groupName(modelName, *phaseNameIter),
IOobject::groupName(modelName, phaseName),
tempModels
);
forAllConstIter(typename modelTypeTable, tempModels, tempModelIter)
forAllConstIters(tempModels, tempModelIter)
{
const phasePairKey key(tempModelIter.key());
const phasePairKey& key = tempModelIter.key();
if (!models.found(key))
{
......@@ -164,9 +163,9 @@ void Foam::phaseSystem::generatePairsAndSubModels
);
}
models[tempModelIter.key()].insert
models[key].insert
(
*phaseNameIter,
phaseName,
*tempModelIter
);
}
......
......@@ -115,12 +115,6 @@ Foam::twoPhaseMixtureEThermo::twoPhaseMixtureEThermo
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::twoPhaseMixtureEThermo::~twoPhaseMixtureEThermo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::twoPhaseMixtureEThermo::correct()
......@@ -182,7 +176,7 @@ Foam::tmp<Foam::scalarField> Foam::twoPhaseMixtureEThermo::he
forAll(T, i)
{
label celli = cells[i];
const label celli = cells[i];
he[i] =
(
(T[i] - TSat_.value())
......
......@@ -94,7 +94,7 @@ public:
//- Destructor
virtual ~twoPhaseMixtureEThermo();
virtual ~twoPhaseMixtureEThermo() = default;
// Member Functions
......@@ -162,14 +162,14 @@ public:
//- i.e. rho != f(p)
bool incompressible() const
{
return (true);
return true;
}
//- Return true if the equation of state is isochoric
//- i.e. rho = const
bool isochoric() const
{
return (false);
return false;
}
//- Return rho of the mixture
......
......@@ -39,12 +39,12 @@ if (mesh.nInternalFaces())
fvc::surfaceSum(mag(phi))().primitiveField()
);
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
for (const phaseModel& phase : fluid.phases())
{
sumPhi = max
(
sumPhi,
fvc::surfaceSum(mag(iter().phi()))().primitiveField()
fvc::surfaceSum(mag(phase.phi()))().primitiveField()
);
}
......
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
for (phaseModel& phase : fluid.phases())
{
phaseModel& phase = iter();
phase.DDtU() =
fvc::ddt(phase.U())
+ fvc::div(phase.phi(), phase.U())
......
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
for (phaseModel& phase : fluid.phases())
{
MRF.correctBoundaryVelocity(iter().U());
MRF.correctBoundaryVelocity(phase.U());
}
MRF.correctBoundaryVelocity(U);
......@@ -3,14 +3,13 @@
PtrList<fvVectorMatrix> UEqns(fluid.phases().size());
autoPtr<multiphaseSystem::dragCoeffFields> dragCoeffs(fluid.dragCoeffs());
int phasei = 0;
forAllIter(PtrDictionary<phaseModel>, fluid.phases(), iter)
label phasei = 0;
for (<