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

- reduced clutter when iterating over containers
This commit is contained in:
Mark Olesen
2019-01-07 09:20:51 +01:00
committed by Andrew Heather
parent bd78da22e7
commit a43eb01b7e
8 changed files with 67 additions and 69 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2013 OpenFOAM Foundation | Copyright (C) 2011-2013 OpenFOAM Foundation
@ -36,24 +36,23 @@ void Foam::solutionControl::storePrevIter() const
{ {
typedef GeometricField<Type, fvPatchField, volMesh> GeoField; typedef GeometricField<Type, fvPatchField, volMesh> GeoField;
HashTable<GeoField*> HashTable<GeoField*> flds(mesh_.objectRegistry::lookupClass<GeoField>());
flds(mesh_.objectRegistry::lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, flds, iter) forAllIters(flds, iter)
{ {
GeoField& fld = *iter(); GeoField& fld = *iter();
const word& fName = fld.name(); const word& fldName = fld.name();
size_t prevIterField = fName.find("PrevIter"); if
(
if ((prevIterField == word::npos) && mesh_.relaxField(fName)) (fldName.find("PrevIter") == std::string::npos)
&& mesh_.relaxField(fldName)
)
{ {
if (debug) DebugInfo
{ << algorithmName_ << ": storing previous iter for "
Info<< algorithmName_ << ": storing previous iter for " << fldName << endl;
<< fName << endl;
}
fld.storePrevIter(); fld.storePrevIter();
} }

View File

@ -104,18 +104,12 @@ void Foam::singleCellFvMesh::agglomerateMesh
label myZone = agglom[patchi][i]; label myZone = agglom[patchi][i];
label nbrZone = nbrAgglom[bFacei]; label nbrZone = nbrAgglom[bFacei];
Map<label>::const_iterator iter = localToNbr.find(myZone); const auto iter = localToNbr.cfind(myZone);
if (iter == localToNbr.end()) if (iter.found())
{
// First occurrence of this zone. Store correspondence
// to remote zone number.
localToNbr.insert(myZone, nbrZone);
}
else
{ {
// Check that zone numbers are still the same. // Check that zone numbers are still the same.
if (iter() != nbrZone) if (iter.val() != nbrZone)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "agglomeration is not synchronised across" << "agglomeration is not synchronised across"
@ -126,6 +120,12 @@ void Foam::singleCellFvMesh::agglomerateMesh
<< exit(FatalError); << exit(FatalError);
} }
} }
else
{
// First occurrence of this zone. Store correspondence
// to remote zone number.
localToNbr.insert(myZone, nbrZone);
}
} }
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation | Copyright (C) 2011 OpenFOAM Foundation
@ -62,15 +62,14 @@ Foam::multivariateScheme<Type, Scheme>::multivariateScheme
dimless dimless
) )
{ {
typename multivariateSurfaceInterpolationScheme<Type>:: auto iter = this->fields().cbegin();
fieldTable::const_iterator iter = this->fields().begin();
surfaceScalarField limiter surfaceScalarField limiter
( (
Scheme(mesh, faceFlux_, *this).limiter(*iter()) Scheme(mesh, faceFlux_, *this).limiter(*iter())
); );
for (++iter; iter != this->fields().end(); ++iter) for (++iter; iter.good(); ++iter)
{ {
limiter = min limiter = min
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation | Copyright (C) 2011 OpenFOAM Foundation
@ -65,8 +65,7 @@ Foam::multivariateSelectionScheme<Type>::multivariateSelectionScheme
dimless dimless
) )
{ {
typename multivariateSurfaceInterpolationScheme<Type>:: auto iter = this->fields().cbegin();
fieldTable::const_iterator iter = this->fields().begin();
surfaceScalarField limiter surfaceScalarField limiter
( (
@ -78,7 +77,7 @@ Foam::multivariateSelectionScheme<Type>::multivariateSelectionScheme
)().limiter(*iter()) )().limiter(*iter())
); );
for (++iter; iter != this->fields().end(); ++iter) for (++iter; iter.good(); ++iter)
{ {
limiter = min limiter = min
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2013-2016 OpenFOAM Foundation | Copyright (C) 2013-2016 OpenFOAM Foundation
@ -109,22 +109,22 @@ void Foam::pointConstraints::makePatchPatchAddressing()
forAll(bp, pointi) 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; label constraintI = -1;
if (iter == patchPatchPointSet.end()) if (iter.found())
{
constraintI = iter.val();
}
else
{ {
patchPatchPointSet.insert(ppp, pppi); patchPatchPointSet.insert(ppp, pppi);
patchPatchPoints[pppi] = ppp; patchPatchPoints[pppi] = ppp;
constraintI = pppi++; constraintI = pppi++;
} }
else
{
constraintI = iter();
}
// Apply to patch constraints // Apply to patch constraints
pbm[patchi].applyConstraint pbm[patchi].applyConstraint
@ -169,14 +169,15 @@ void Foam::pointConstraints::makePatchPatchAddressing()
forAll(bp, pointi) forAll(bp, pointi)
{ {
label ppp = meshPoints[bp[pointi]]; const label ppp = meshPoints[bp[pointi]];
Map<label>::const_iterator fnd = cpPointMap.find(ppp); const auto iter = cpPointMap.cfind(ppp);
if (fnd != cpPointMap.end())
if (iter.found())
{ {
// Can just copy (instead of apply) constraint // Can just copy (instead of apply) constraint
// will already be consistent across multiple patches. // will already be consistent across multiple patches.
constraints[fnd()] = patchPatchPointConstraints_ constraints[iter.val()] = patchPatchPointConstraints_
[ [
patchPatchPointSet[ppp] patchPatchPointSet[ppp]
]; ];
@ -219,11 +220,22 @@ void Foam::pointConstraints::makePatchPatchAddressing()
{ {
label meshPointi = cpMeshPoints[coupledPointi]; label meshPointi = cpMeshPoints[coupledPointi];
Map<label>::iterator iter = patchPatchPointSet.find(meshPointi); const auto iter = patchPatchPointSet.cfind(meshPointi);
label constraintI = -1; 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 //Pout<< indent << "on meshpoint:" << meshPointi
// << " coupled:" << coupledPointi // << " coupled:" << coupledPointi
@ -250,17 +262,6 @@ void Foam::pointConstraints::makePatchPatchAddressing()
patchPatchPoints[pppi] = meshPointi; patchPatchPoints[pppi] = meshPointi;
constraintI = pppi++; 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 // Combine (new or existing) constraint with one
// on coupled. // on coupled.

View File

@ -129,7 +129,7 @@ void Foam::pairPatchAgglomeration::setEdgeWeights
edgeHashSet fineFeaturedFaces(coarsePatch.nEdges()/10); edgeHashSet fineFeaturedFaces(coarsePatch.nEdges()/10);
// Map fine faces with featured edge into coarse faces // Map fine faces with featured edge into coarse faces
forAllConstIter(EdgeMap<scalar>, facePairWeight_, iter) forAllConstIters(facePairWeight_, iter)
{ {
if (iter() == -1.0) if (iter() == -1.0)
{ {

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -81,17 +81,17 @@ Foam::oversetGAMGInterface::oversetGAMGInterface
label coarseCelli = localRestrictAddressing[ffi]; label coarseCelli = localRestrictAddressing[ffi];
// Do we have coarse face for it? // Do we have coarse face for it?
Map<label>::iterator iter = cellToCoarseFace.find(coarseCelli); const auto iter = cellToCoarseFace.cfind(coarseCelli);
if (iter == cellToCoarseFace.end()) if (iter.found())
{ {
label coarseFacei = dynFaceCells.size(); dynFaceRestrictAddressing.append(iter.val());
cellToCoarseFace.insert(coarseCelli, coarseFacei);
dynFaceCells.append(coarseCelli);
dynFaceRestrictAddressing.append(coarseFacei);
} }
else else
{ {
dynFaceRestrictAddressing.append(iter()); const label coarseFacei = dynFaceCells.size();
cellToCoarseFace.insert(coarseCelli, coarseFacei);
dynFaceCells.append(coarseCelli);
dynFaceRestrictAddressing.append(coarseFacei);
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2013-2017 OpenFOAM Foundation | Copyright (C) 2013-2017 OpenFOAM Foundation
@ -43,7 +43,7 @@ filmModel() const
HashTable<const filmModelType*> models HashTable<const filmModelType*> models
= db().time().lookupClass<filmModelType>(); = db().time().lookupClass<filmModelType>();
forAllConstIter(HashTable<const filmModelType*>, models, iter) forAllConstIters(models, iter)
{ {
if (iter()->regionMesh().name() == filmRegionName_) if (iter()->regionMesh().name() == filmRegionName_)
{ {
@ -52,7 +52,7 @@ filmModel() const
} }
DynamicList<word> modelNames; DynamicList<word> modelNames;
forAllConstIter(HashTable<const filmModelType*>, models, iter) forAllConstIters(models, iter)
{ {
modelNames.append(iter()->regionMesh().name()); modelNames.append(iter()->regionMesh().name());
} }
@ -74,7 +74,7 @@ pyrModel() const
HashTable<const pyrolysisModelType*> models = HashTable<const pyrolysisModelType*> models =
db().time().lookupClass<pyrolysisModelType>(); db().time().lookupClass<pyrolysisModelType>();
forAllConstIter(HashTable<const pyrolysisModelType*>, models, iter) forAllConstIters(models, iter)
{ {
if (iter()->regionMesh().name() == pyrolysisRegionName_) if (iter()->regionMesh().name() == pyrolysisRegionName_)
{ {
@ -83,7 +83,7 @@ pyrModel() const
} }
DynamicList<word> modelNames; DynamicList<word> modelNames;
forAllConstIter(HashTable<const pyrolysisModelType*>, models, iter) forAllConstIters(models, iter)
{ {
modelNames.append(iter()->regionMesh().name()); modelNames.append(iter()->regionMesh().name());
} }