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

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

- reduced clutter when iterating over containers
parent f5163e50
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -105,16 +105,14 @@ void Foam::dynamicRefineFvMesh::mapNewInternalFaces
typedef GeometricField<T, fvsPatchField, surfaceMesh> GeoField;
HashTable<GeoField*> sFlds(this->objectRegistry::lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, sFlds, iter)
forAllIters(sFlds, iter)
{
//if (mapSurfaceFields_.found(iter.key()))
{
if (debug)
{
Info<< "dynamicRefineFvMesh::mapNewInternalFaces():"
<< " Mapping new internal faces by interpolation on "
<< iter.key()<< endl;
}
DebugInfo
<< "dynamicRefineFvMesh::mapNewInternalFaces():"
<< " Mapping new internal faces by interpolation on "
<< iter.key()<< endl;
GeoField& sFld = *iter();
......@@ -143,27 +141,23 @@ void Foam::dynamicRefineFvMesh::mapNewInternalFaces
typedef GeometricField<T, fvsPatchField, surfaceMesh> GeoField;
HashTable<GeoField*> sFlds(this->objectRegistry::lookupClass<GeoField>());
forAllIter(typename HashTable<GeoField*>, sFlds, iter)
forAllIters(sFlds, iter)
{
//if (mapSurfaceFields_.found(iter.key()))
{
if (debug)
{
Info<< "dynamicRefineFvMesh::mapNewInternalFaces():"
<< " Mapping new internal faces by interpolation on "
<< iter.key()<< endl;
}
DebugInfo
<< "dynamicRefineFvMesh::mapNewInternalFaces():"
<< " Mapping new internal faces by interpolation on "
<< iter.key() << endl;
GeoField& sFld = *iter();
if (sFld.oriented()())
{
if (debug)
{
Info<< "dynamicRefineFvMesh::mapNewInternalFaces(): "
<< "Converting oriented field " << iter.key()
<< " to intensive field and mapping" << endl;
}
DebugInfo
<< "dynamicRefineFvMesh::mapNewInternalFaces(): "
<< "Converting oriented field " << iter.key()
<< " to intensive field and mapping" << endl;
// Assume any oriented field is face area weighted (i.e. a flux)
// Convert to intensive (& oriented) before mapping. Untested.
......
......@@ -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-2016 OpenFOAM Foundation
......@@ -196,10 +196,9 @@ void Foam::attachDetach::attachInterface
forAll(newFace, pointi)
{
Map<label>::const_iterator rpmIter =
removedPointMap.find(newFace[pointi]);
const auto rpmIter = removedPointMap.cfind(newFace[pointi]);
if (rpmIter != removedPointMap.end())
if (rpmIter.found())
{
// Point mapped. Replace it
newFace[pointi] = rpmIter();
......@@ -225,7 +224,7 @@ void Foam::attachDetach::attachInterface
}
label patchID = mesh.boundaryMesh().whichPatch(curFaceID);
const label patchID = mesh.boundaryMesh().whichPatch(curFaceID);
label neiCell;
if (patchID == -1)
{
......
......@@ -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-2016 OpenFOAM Foundation
......@@ -398,9 +398,9 @@ void Foam::createShellMesh::calcPointRegions
{
label globalRegionI = pointGlobalRegions[facei][fp];
Map<label>::iterator fnd = globalToLocalRegion.find(globalRegionI);
const auto fnd = globalToLocalRegion.cfind(globalRegionI);
if (fnd != globalToLocalRegion.end())
if (fnd.found())
{
// Already encountered this global region. Assign same local one
pRegions[fp] = fnd();
......
......@@ -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-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -64,8 +64,7 @@ void Foam::fvMeshAdder::MapVolField
// Patch fields from old mesh
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
typename GeometricField<Type, fvPatchField, volMesh>::
Boundary& bfld = fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
{
const labelList& oldPatchMap = meshMap.oldPatchMap();
......@@ -93,7 +92,7 @@ void Foam::fvMeshAdder::MapVolField
forAll(oldPatchMap, patchi)
{
label newPatchi = oldPatchMap[patchi];
const label newPatchi = oldPatchMap[patchi];
if (newPatchi != -1)
{
......@@ -270,18 +269,16 @@ void Foam::fvMeshAdder::MapVolFields
const bool fullyMapped
)
{
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fields
typedef GeometricField<Type, fvPatchField, volMesh> fldType;
HashTable<const fldType*> fields
(
mesh.objectRegistry::lookupClass
<GeometricField<Type, fvPatchField, volMesh>>
()
mesh.objectRegistry::lookupClass<fldType>()
);
HashTable<const GeometricField<Type, fvPatchField, volMesh>*> fieldsToAdd
HashTable<const fldType*> fieldsToAdd
(
meshToAdd.objectRegistry::lookupClass
<GeometricField<Type, fvPatchField, volMesh>>
()
meshToAdd.objectRegistry::lookupClass<fldType>()
);
// It is necessary to enforce that all old-time fields are stored
......@@ -289,41 +286,25 @@ void Foam::fvMeshAdder::MapVolFields
// old-time-level field is mapped before the field itself, sizes
// will not match.
for
(
typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllIters(fields, fieldIter)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout
<< "MapVolFields : Storing old time for " << fieldIter()->name()
<< "MapVolFields : Storing old time for " << fld.name()
<< endl;
const_cast<GeometricField<Type, fvPatchField, volMesh>*>(fieldIter())
->storeOldTimes();
fld.storeOldTimes();
}
for
(
typename HashTable<const GeometricField<Type, fvPatchField, volMesh>*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllIters(fields, fieldIter)
{
GeometricField<Type, fvPatchField, volMesh>& fld =
const_cast<GeometricField<Type, fvPatchField, volMesh>&>
(
*fieldIter()
);
fldType& fld = const_cast<fldType&>(*fieldIter());
if (fieldsToAdd.found(fld.name()))
{
const GeometricField<Type, fvPatchField, volMesh>& fldToAdd =
*fieldsToAdd[fld.name()];
const fldType& fldToAdd = *fieldsToAdd[fld.name()];
DebugPout
<< "MapVolFields : mapping " << fld.name()
......@@ -355,8 +336,7 @@ void Foam::fvMeshAdder::MapSurfaceField
const fvMesh& mesh = fld.mesh();
const labelList& oldPatchStarts = meshMap.oldPatchStarts();
typename GeometricField<Type, fvsPatchField, surfaceMesh>::
Boundary& bfld = fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
// Internal field
// ~~~~~~~~~~~~~~
......@@ -424,7 +404,7 @@ void Foam::fvMeshAdder::MapSurfaceField
forAll(oldPatchMap, patchi)
{
label newPatchi = oldPatchMap[patchi];
const label newPatchi = oldPatchMap[patchi];
if (newPatchi != -1)
{
......@@ -618,29 +598,19 @@ void Foam::fvMeshAdder::MapSurfaceFields
// old-time-level field is mapped before the field itself, sizes
// will not match.
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllIters(fields, fieldIter)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
DebugPout
<< "MapSurfaceFields : Storing old time for "
<< fieldIter()->name() << endl;
<< fld.name() << endl;
const_cast<fldType*>(fieldIter())->storeOldTimes();
fld.storeOldTimes();
}
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllIters(fields, fieldIter)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
......@@ -708,13 +678,7 @@ void Foam::fvMeshAdder::MapDimFields
meshToAdd.objectRegistry::lookupClass<fldType>(true)
);
for
(
typename HashTable<const fldType*>::
iterator fieldIter = fields.begin();
fieldIter != fields.end();
++fieldIter
)
forAllIters(fields, fieldIter)
{
fldType& fld = const_cast<fldType&>(*fieldIter());
......
......@@ -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-2018 OpenFOAM Foundation
......@@ -713,20 +713,17 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::mergeSharedPoints
label globali = pointToGlobalMaster[pointi];
if (globali != -1)
{
Map<label>::const_iterator iter = globalMasterToLocalMaster.find
(
globali
);
const auto iter = globalMasterToLocalMaster.cfind(globali);
if (iter == globalMasterToLocalMaster.end())
if (iter.found())
{
// Found first point. Designate as master
globalMasterToLocalMaster.insert(globali, pointi);
pointToMaster.insert(pointi, pointi);
pointToMaster.insert(pointi, *iter);
}
else
{
pointToMaster.insert(pointi, iter());
// Found first point. Designate as master
globalMasterToLocalMaster.insert(globali, pointi);
pointToMaster.insert(pointi, pointi);
}
}
}
......@@ -1097,11 +1094,11 @@ void Foam::fvMeshDistribute::findCouples
{
labelPair myData(sourceFace[bFacei], sourceProc[bFacei]);
labelPairLookup::const_iterator iter = map.find(myData);
const auto iter = map.cfind(myData);
if (iter != map.end())
if (iter.found())
{
label nbrBFacei = iter();
label nbrBFacei = *iter;
masterCoupledFaces[coupledI] = mesh.nInternalFaces() + bFacei;
slaveCoupledFaces[coupledI] =
......
......@@ -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
......@@ -37,7 +37,7 @@ void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllConstIter(typename HashTable<const GeoField*>, flds, iter)
forAllConstIters(flds, iter)
{
const GeoField& fld = *iter();
......@@ -69,20 +69,19 @@ void Foam::fvMeshDistribute::saveBoundaryFields
HashTable<const fldType*> flds
(
static_cast<const fvMesh&>(mesh_).objectRegistry::lookupClass<fldType>()
mesh_.objectRegistry::lookupClass<const fldType>()
);
bflds.setSize(flds.size());
label i = 0;
forAllConstIter(typename HashTable<const fldType*>, flds, iter)
forAllConstIters(flds, iter)
{
const fldType& fld = *iter();
bflds.set(i, fld.boundaryField().clone().ptr());
i++;
++i;
}
}
......@@ -114,10 +113,10 @@ void Foam::fvMeshDistribute::mapBoundaryFields
label fieldi = 0;
forAllIter(typename HashTable<fldType*>, flds, iter)
forAllIters(flds, iter)
{
fldType& fld = *iter();
typename fldType::Boundary& bfld = fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldi++];
......@@ -158,20 +157,20 @@ void Foam::fvMeshDistribute::saveInternalFields
HashTable<const fldType*> flds
(
static_cast<const fvMesh&>(mesh_).objectRegistry::lookupClass<fldType>()
mesh_.objectRegistry::lookupClass<const fldType>()
);
iflds.setSize(flds.size());
label i = 0;
forAllConstIter(typename HashTable<const fldType*>, flds, iter)
forAllConstIters(flds, iter)
{
const fldType& fld = *iter();
iflds.set(i, fld.primitiveField().clone());
i++;
++i;
}
}
......@@ -204,7 +203,7 @@ void Foam::fvMeshDistribute::mapExposedFaces
label fieldI = 0;
forAllIter(typename HashTable<fldType*>, flds, iter)
forAllIters(flds, iter)
{
fldType& fld = *iter();
const bool oriented = fld.oriented()();
......@@ -253,11 +252,11 @@ void Foam::fvMeshDistribute::initPatchFields
mesh_.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld = fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
forAll(bfld, patchi)
{
......@@ -280,9 +279,9 @@ void Foam::fvMeshDistribute::correctBoundaryConditions()
mesh_.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
const GeoField& fld = *iter();
GeoField& fld = *iter();
fld.correctBoundaryConditions();
}
}
......
......@@ -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-2016 OpenFOAM Foundation
......@@ -465,11 +465,11 @@ Foam::fvMeshSubset::interpolate
// Get mesh point on original mesh.
label meshPointi = pointMap[subMeshPoints[localI]];
Map<label>::const_iterator iter = meshPointMap.find(meshPointi);
const auto iter = meshPointMap.cfind(meshPointi);
if (iter != meshPointMap.end())
if (iter.found())
{
directAddressing[localI] = iter();
directAddressing[localI] = *iter;
}
}
......
......@@ -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
......@@ -45,12 +45,11 @@ void Foam::fvMeshTools::addPatchFields
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
label sz = bfld.size();
bfld.setSize(sz+1);
......@@ -99,12 +98,11 @@ void Foam::fvMeshTools::setPatchFields
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
if (patchFieldDict.found(fld.name()))
{
......@@ -138,12 +136,11 @@ void Foam::fvMeshTools::setPatchFields
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
bfld[patchi] == value;
}
......@@ -159,7 +156,7 @@ void Foam::fvMeshTools::trimPatchFields(fvMesh& mesh, const label nPatches)
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
fld.boundaryFieldRef().setSize(nPatches);
......@@ -180,12 +177,11 @@ void Foam::fvMeshTools::reorderPatchFields
mesh.objectRegistry::lookupClass<GeoField>()
);
forAllIter(typename HashTable<GeoField*>, flds, iter)
forAllIters(flds, iter)
{
GeoField& fld = *iter();
typename GeoField::Boundary& bfld =
fld.boundaryFieldRef();
auto& bfld = fld.boundaryFieldRef();
bfld.reorder(oldToNew);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -221,10 +221,9 @@ void Foam::layerAdditionRemoval::removeCellLayer
forAll(newFace, pointi)
{
Map<label>::iterator rpmIter =
removedPointMap.find(newFace[pointi]);
const auto rpmIter = removedPointMap.cfind(newFace[pointi]);
if (rpmIter != removedPointMap.end())
if (rpmIter.found())
{
// Point mapped. Replace it
newFace[pointi] = rpmIter();
......
......@@ -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-2017 OpenFOAM Foundation
......@@ -178,13 +178,13 @@ void Foam::cellCuts::syncProc()
label facei = pp.start()+i;
label bFacei = facei-mesh().nInternalFaces();
const Map<edge>::const_iterator iter =
faceSplitCut_.find(facei);
if (iter != faceSplitCut_.end())
const auto iter = faceSplitCut_.cfind(facei);
if (iter.found())
{
const face& f = mesh().faces()[facei];
const labelList& fEdges = mesh().faceEdges()[facei];
const edge& cuts = iter();
const edge& cuts = iter.val();
forAll(cuts, i)