Skip to content
Snippets Groups Projects
Commit a43eb01b authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

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

- reduced clutter when iterating over containers
parent bd78da22
Branches
Tags
No related merge requests found
Showing with 67 additions and 69 deletions
......@@ -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-2013 OpenFOAM Foundation
......@@ -36,24 +36,23 @@ void Foam::solutionControl::storePrevIter() const
{
typedef GeometricField<Type, fvPatchField, volMesh> GeoField;
HashTable<GeoField*>
flds(mesh_.objectRegistry::lookupClass<GeoField>());
HashTable<GeoField*> flds(mesh_.objectRegistry::lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
const word& fName = fld.name();
const word& fldName = fld.name();
size_t prevIterField = fName.find("PrevIter");
if ((prevIterField == word::npos) && mesh_.relaxField(fName))
if
(
(fldName.find("PrevIter") == std::string::npos)
&& mesh_.relaxField(fldName)
)
{
if (debug)
{
Info<< algorithmName_ << ": storing previous iter for "
<< fName << endl;
}
DebugInfo
<< algorithmName_ << ": storing previous iter for "
<< fldName << endl;
fld.storePrevIter();
}
......
......@@ -104,18 +104,12 @@ void Foam::singleCellFvMesh::agglomerateMesh
label myZone = agglom[patchi][i];
label nbrZone = nbrAgglom[bFacei];
Map<label>::const_iterator iter = localToNbr.find(myZone);
const auto iter = localToNbr.cfind(myZone);
if (iter == localToNbr.end())
{
// First occurrence of this zone. Store correspondence
// to remote zone number.
localToNbr.insert(myZone, nbrZone);
}
else
if (iter.found())
{
// Check that zone numbers are still the same.
if (iter() != nbrZone)
if (iter.val() != nbrZone)
{
FatalErrorInFunction
<< "agglomeration is not synchronised across"
......@@ -126,6 +120,12 @@ void Foam::singleCellFvMesh::agglomerateMesh
<< exit(FatalError);
}
}
else
{
// First occurrence of this zone. Store correspondence
// to remote zone number.
localToNbr.insert(myZone, nbrZone);
}
}
}
}
......
......@@ -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 OpenFOAM Foundation
......@@ -62,15 +62,14 @@ Foam::multivariateScheme<Type, Scheme>::multivariateScheme
dimless
)
{
typename multivariateSurfaceInterpolationScheme<Type>::
fieldTable::const_iterator iter = this->fields().begin();
auto iter = this->fields().cbegin();
surfaceScalarField limiter
(
Scheme(mesh, faceFlux_, *this).limiter(*iter())
);
for (++iter; iter != this->fields().end(); ++iter)
for (++iter; iter.good(); ++iter)
{
limiter = min
(
......
......@@ -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 OpenFOAM Foundation
......@@ -65,8 +65,7 @@ Foam::multivariateSelectionScheme<Type>::multivariateSelectionScheme
dimless
)
{
typename multivariateSurfaceInterpolationScheme<Type>::
fieldTable::const_iterator iter = this->fields().begin();
auto iter = this->fields().cbegin();
surfaceScalarField limiter
(
......@@ -78,7 +77,7 @@ Foam::multivariateSelectionScheme<Type>::multivariateSelectionScheme
)().limiter(*iter())
);
for (++iter; iter != this->fields().end(); ++iter)
for (++iter; iter.good(); ++iter)
{
limiter = min
(
......
......@@ -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) 2013-2016 OpenFOAM Foundation
......@@ -109,21 +109,21 @@ void Foam::pointConstraints::makePatchPatchAddressing()
forAll(bp, pointi)
{
label ppp = meshPoints[bp[pointi]];
const label ppp = meshPoints[bp[pointi]];
Map<label>::iterator iter = patchPatchPointSet.find(ppp);
const auto iter = patchPatchPointSet.cfind(ppp);
label constraintI = -1;
if (iter == patchPatchPointSet.end())
if (iter.found())
{
patchPatchPointSet.insert(ppp, pppi);
patchPatchPoints[pppi] = ppp;
constraintI = pppi++;
constraintI = iter.val();
}
else
{
constraintI = iter();
patchPatchPointSet.insert(ppp, pppi);
patchPatchPoints[pppi] = ppp;
constraintI = pppi++;
}
// Apply to patch constraints
......@@ -169,14 +169,15 @@ void Foam::pointConstraints::makePatchPatchAddressing()
forAll(bp, pointi)
{
label ppp = meshPoints[bp[pointi]];
const label ppp = meshPoints[bp[pointi]];
const auto iter = cpPointMap.cfind(ppp);
Map<label>::const_iterator fnd = cpPointMap.find(ppp);
if (fnd != cpPointMap.end())
if (iter.found())
{
// Can just copy (instead of apply) constraint
// will already be consistent across multiple patches.
constraints[fnd()] = patchPatchPointConstraints_
constraints[iter.val()] = patchPatchPointConstraints_
[
patchPatchPointSet[ppp]
];
......@@ -219,11 +220,22 @@ void Foam::pointConstraints::makePatchPatchAddressing()
{
label meshPointi = cpMeshPoints[coupledPointi];
Map<label>::iterator iter = patchPatchPointSet.find(meshPointi);
const auto iter = patchPatchPointSet.cfind(meshPointi);
label constraintI = -1;
if (iter == patchPatchPointSet.end())
if (iter.found())
{
//Pout<< indent << "on meshpoint:" << meshPointi
// << " coupled:" << coupledPointi
// << " at:" << mesh.points()[meshPointi]
// << " have possibly extended constraint:"
// << constraints[coupledPointi]
// << endl;
constraintI = iter.val();
}
else
{
//Pout<< indent << "on meshpoint:" << meshPointi
// << " coupled:" << coupledPointi
......@@ -250,17 +262,6 @@ void Foam::pointConstraints::makePatchPatchAddressing()
patchPatchPoints[pppi] = meshPointi;
constraintI = pppi++;
}
else
{
//Pout<< indent << "on meshpoint:" << meshPointi
// << " coupled:" << coupledPointi
// << " at:" << mesh.points()[meshPointi]
// << " have possibly extended constraint:"
// << constraints[coupledPointi]
// << endl;
constraintI = iter();
}
// Combine (new or existing) constraint with one
// on coupled.
......
......@@ -129,7 +129,7 @@ void Foam::pairPatchAgglomeration::setEdgeWeights
edgeHashSet fineFeaturedFaces(coarsePatch.nEdges()/10);
// Map fine faces with featured edge into coarse faces
forAllConstIter(EdgeMap<scalar>, facePairWeight_, iter)
forAllConstIters(facePairWeight_, iter)
{
if (iter() == -1.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 |
-------------------------------------------------------------------------------
License
......@@ -81,17 +81,17 @@ Foam::oversetGAMGInterface::oversetGAMGInterface
label coarseCelli = localRestrictAddressing[ffi];
// Do we have coarse face for it?
Map<label>::iterator iter = cellToCoarseFace.find(coarseCelli);
if (iter == cellToCoarseFace.end())
const auto iter = cellToCoarseFace.cfind(coarseCelli);
if (iter.found())
{
label coarseFacei = dynFaceCells.size();
cellToCoarseFace.insert(coarseCelli, coarseFacei);
dynFaceCells.append(coarseCelli);
dynFaceRestrictAddressing.append(coarseFacei);
dynFaceRestrictAddressing.append(iter.val());
}
else
{
dynFaceRestrictAddressing.append(iter());
const label coarseFacei = dynFaceCells.size();
cellToCoarseFace.insert(coarseCelli, coarseFacei);
dynFaceCells.append(coarseCelli);
dynFaceRestrictAddressing.append(coarseFacei);
}
}
......
......@@ -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
......@@ -43,7 +43,7 @@ filmModel() const
HashTable<const filmModelType*> models
= db().time().lookupClass<filmModelType>();
forAllConstIter(HashTable<const filmModelType*>, models, iter)
forAllConstIters(models, iter)
{
if (iter()->regionMesh().name() == filmRegionName_)
{
......@@ -52,7 +52,7 @@ filmModel() const
}
DynamicList<word> modelNames;
forAllConstIter(HashTable<const filmModelType*>, models, iter)
forAllConstIters(models, iter)
{
modelNames.append(iter()->regionMesh().name());
}
......@@ -74,7 +74,7 @@ pyrModel() const
HashTable<const pyrolysisModelType*> models =
db().time().lookupClass<pyrolysisModelType>();
forAllConstIter(HashTable<const pyrolysisModelType*>, models, iter)
forAllConstIters(models, iter)
{
if (iter()->regionMesh().name() == pyrolysisRegionName_)
{
......@@ -83,7 +83,7 @@ pyrModel() const
}
DynamicList<word> modelNames;
forAllConstIter(HashTable<const pyrolysisModelType*>, models, iter)
forAllConstIters(models, iter)
{
modelNames.append(iter()->regionMesh().name());
}
......
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