mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: for-range, forAllIters() ... in applications/utilities
- reduced clutter when iterating over containers
This commit is contained in:
@ -711,18 +711,18 @@ int main(int argc, char *argv[])
|
||||
setsAndPatches[setI][1]
|
||||
);
|
||||
|
||||
forAllConstIter(faceSet, fSet, iter)
|
||||
for (const label facei : fSet)
|
||||
{
|
||||
if (wantedPatch[iter.key()] != -1)
|
||||
if (wantedPatch[facei] != -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Face " << iter.key()
|
||||
<< "Face " << facei
|
||||
<< " is in faceSet " << setsAndPatches[setI][0]
|
||||
<< " destined for patch " << setsAndPatches[setI][1]
|
||||
<< " but also in patch " << wantedPatch[iter.key()]
|
||||
<< " but also in patch " << wantedPatch[facei]
|
||||
<< exit(FatalError);
|
||||
}
|
||||
wantedPatch[iter.key()] = patchi;
|
||||
wantedPatch[facei] = patchi;
|
||||
}
|
||||
}
|
||||
|
||||
@ -749,20 +749,21 @@ int main(int argc, char *argv[])
|
||||
faceSet fSet(mesh, coupledAndPatches[setI][0]);
|
||||
label patchi = findPatch(patches, coupledAndPatches[setI][1]);
|
||||
|
||||
forAllConstIter(faceSet, fSet, iter)
|
||||
for (const label facei : fSet)
|
||||
{
|
||||
if (coupledWantedPatch[iter.key()] != -1)
|
||||
if (coupledWantedPatch[facei] != -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Face " << iter.key()
|
||||
<< "Face " << facei
|
||||
<< " is in faceSet " << coupledAndPatches[setI][0]
|
||||
<< " destined for patch " << coupledAndPatches[setI][1]
|
||||
<< " but also in patch " << coupledWantedPatch[iter.key()]
|
||||
<< " but also in patch " << coupledWantedPatch[facei]
|
||||
<< exit(FatalError);
|
||||
}
|
||||
coupledWantedPatch[iter.key()] = patchi;
|
||||
cyclicWantedPatch_half0[iter.key()] = cyclicId;
|
||||
cyclicWantedPatch_half1[iter.key()] = cyclicSlaveId;
|
||||
|
||||
coupledWantedPatch[facei] = patchi;
|
||||
cyclicWantedPatch_half0[facei] = cyclicId;
|
||||
cyclicWantedPatch_half1[facei] = cyclicSlaveId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,25 +80,24 @@ Foam::label Foam::cellSplitter::newOwner
|
||||
const Map<labelList>& cellToCells
|
||||
) const
|
||||
{
|
||||
label oldOwn = mesh_.faceOwner()[facei];
|
||||
const label old = mesh_.faceOwner()[facei];
|
||||
|
||||
Map<labelList>::const_iterator fnd = cellToCells.find(oldOwn);
|
||||
const auto iter = cellToCells.cfind(old);
|
||||
|
||||
if (fnd == cellToCells.end())
|
||||
if (!iter.found())
|
||||
{
|
||||
// Unsplit cell
|
||||
return oldOwn;
|
||||
return old;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look up index of face in the cells' faces.
|
||||
|
||||
const labelList& newCells = fnd();
|
||||
|
||||
const cell& cFaces = mesh_.cells()[oldOwn];
|
||||
// Look up index of face in the cells' faces.
|
||||
|
||||
return newCells[cFaces.find(facei)];
|
||||
}
|
||||
const labelList& newCells = *iter;
|
||||
|
||||
const cell& cFaces = mesh_.cells()[old];
|
||||
|
||||
return newCells[cFaces.find(facei)];
|
||||
}
|
||||
|
||||
|
||||
@ -108,31 +107,29 @@ Foam::label Foam::cellSplitter::newNeighbour
|
||||
const Map<labelList>& cellToCells
|
||||
) const
|
||||
{
|
||||
label oldNbr = mesh_.faceNeighbour()[facei];
|
||||
const label old = mesh_.faceNeighbour()[facei];
|
||||
|
||||
Map<labelList>::const_iterator fnd = cellToCells.find(oldNbr);
|
||||
const auto iter = cellToCells.cfind(old);
|
||||
|
||||
if (fnd == cellToCells.end())
|
||||
if (!iter.found())
|
||||
{
|
||||
// Unsplit cell
|
||||
return oldNbr;
|
||||
return old;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Look up index of face in the cells' faces.
|
||||
|
||||
const labelList& newCells = fnd();
|
||||
|
||||
const cell& cFaces = mesh_.cells()[oldNbr];
|
||||
// Look up index of face in the cells' faces.
|
||||
|
||||
return newCells[cFaces.find(facei)];
|
||||
}
|
||||
const labelList& newCells = *iter;
|
||||
|
||||
const cell& cFaces = mesh_.cells()[old];
|
||||
|
||||
return newCells[cFaces.find(facei)];
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// Construct from components
|
||||
Foam::cellSplitter::cellSplitter(const polyMesh& mesh)
|
||||
:
|
||||
mesh_(mesh),
|
||||
@ -140,12 +137,6 @@ Foam::cellSplitter::cellSplitter(const polyMesh& mesh)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::cellSplitter::~cellSplitter()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::cellSplitter::setRefinement
|
||||
@ -162,9 +153,9 @@ void Foam::cellSplitter::setRefinement
|
||||
// Introduce cellToMidPoints.
|
||||
//
|
||||
|
||||
forAllConstIter(Map<point>, cellToMidPoint, iter)
|
||||
forAllConstIters(cellToMidPoint, iter)
|
||||
{
|
||||
label celli = iter.key();
|
||||
const label celli = iter.key();
|
||||
|
||||
label anchorPoint = mesh_.cellPoints()[celli][0];
|
||||
|
||||
@ -173,7 +164,7 @@ void Foam::cellSplitter::setRefinement
|
||||
(
|
||||
polyAddPoint
|
||||
(
|
||||
iter(), // point
|
||||
iter.val(), // point
|
||||
anchorPoint, // master point
|
||||
-1, // zone for point
|
||||
true // supports a cell
|
||||
@ -193,9 +184,9 @@ void Foam::cellSplitter::setRefinement
|
||||
|
||||
Map<labelList> cellToCells(cellToMidPoint.size());
|
||||
|
||||
forAllConstIter(Map<point>, cellToMidPoint, iter)
|
||||
forAllConstIters(cellToMidPoint, iter)
|
||||
{
|
||||
label celli = iter.key();
|
||||
const label celli = iter.key();
|
||||
|
||||
const cell& cFaces = mesh_.cells()[celli];
|
||||
|
||||
@ -238,9 +229,9 @@ void Foam::cellSplitter::setRefinement
|
||||
// point.
|
||||
//
|
||||
|
||||
forAllConstIter(Map<point>, cellToMidPoint, iter)
|
||||
forAllConstIters(cellToMidPoint, iter)
|
||||
{
|
||||
label celli = iter.key();
|
||||
const label celli = iter.key();
|
||||
|
||||
label midPointi = addedPoints_[celli];
|
||||
|
||||
@ -368,9 +359,9 @@ void Foam::cellSplitter::setRefinement
|
||||
// Mark off affected face.
|
||||
bitSet faceUpToDate(mesh_.nFaces(), true);
|
||||
|
||||
forAllConstIter(Map<point>, cellToMidPoint, iter)
|
||||
forAllConstIters(cellToMidPoint, iter)
|
||||
{
|
||||
label celli = iter.key();
|
||||
const label celli = iter.key();
|
||||
|
||||
const cell& cFaces = mesh_.cells()[celli];
|
||||
|
||||
@ -462,15 +453,13 @@ void Foam::cellSplitter::updateMesh(const mapPolyMesh& morphMap)
|
||||
// point get mapped do they get inserted.
|
||||
Map<label> newAddedPoints(addedPoints_.size());
|
||||
|
||||
forAllConstIter(Map<label>, addedPoints_, iter)
|
||||
forAllConstIters(addedPoints_, iter)
|
||||
{
|
||||
label oldCelli = iter.key();
|
||||
const label oldCelli = iter.key();
|
||||
const label oldPointi = iter.val();
|
||||
|
||||
label newCelli = morphMap.reverseCellMap()[oldCelli];
|
||||
|
||||
label oldPointi = iter();
|
||||
|
||||
label newPointi = morphMap.reversePointMap()[oldPointi];
|
||||
const label newCelli = morphMap.reverseCellMap()[oldCelli];
|
||||
const label newPointi = morphMap.reversePointMap()[oldPointi];
|
||||
|
||||
if (newCelli >= 0 && newPointi >= 0)
|
||||
{
|
||||
|
||||
@ -109,7 +109,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
~cellSplitter();
|
||||
~cellSplitter() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -83,10 +83,8 @@ label findPoint(const primitivePatch& pp, const point& nearPoint)
|
||||
scalar almostMinDistSqr = GREAT;
|
||||
label almostMinI = -1;
|
||||
|
||||
forAll(meshPoints, i)
|
||||
for (const label pointi : meshPoints)
|
||||
{
|
||||
label pointi = meshPoints[i];
|
||||
|
||||
scalar distSqr = magSqr(nearPoint - points[pointi]);
|
||||
|
||||
if (distSqr < minDistSqr)
|
||||
@ -147,10 +145,8 @@ label findEdge
|
||||
scalar almostMinDist = GREAT;
|
||||
label almostMinI = -1;
|
||||
|
||||
forAll(edges, edgeI)
|
||||
for (const edge& e : edges)
|
||||
{
|
||||
const edge& e = edges[edgeI];
|
||||
|
||||
pointHit pHit(e.line(localPoints).nearestDist(nearPoint));
|
||||
|
||||
if (pHit.hit())
|
||||
@ -296,10 +292,8 @@ label findCell(const primitiveMesh& mesh, const point& nearPoint)
|
||||
label minI = -1;
|
||||
scalar minDistSqr = GREAT;
|
||||
|
||||
forAll(cPoints, i)
|
||||
for (const label pointi : cPoints)
|
||||
{
|
||||
label pointi = cPoints[i];
|
||||
|
||||
scalar distSqr = magSqr(nearPoint - mesh.points()[pointi]);
|
||||
|
||||
if (distSqr < minDistSqr)
|
||||
@ -432,11 +426,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Looking up points to move ..." << nl << endl;
|
||||
Map<point> pointToPos(pointsToMove.size());
|
||||
forAll(pointsToMove, i)
|
||||
for (const Pair<point>& pts : pointsToMove)
|
||||
{
|
||||
const Pair<point>& pts = pointsToMove[i];
|
||||
|
||||
label pointi = findPoint(allBoundary, pts.first());
|
||||
const label pointi = findPoint(allBoundary, pts.first());
|
||||
|
||||
if (pointi == -1 || !pointToPos.insert(pointi, pts.second()))
|
||||
{
|
||||
@ -450,10 +442,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Looking up edges to split ..." << nl << endl;
|
||||
Map<List<point>> edgeToCuts(edgesToSplit.size());
|
||||
forAll(edgesToSplit, i)
|
||||
for (const Pair<point>& pts : edgesToSplit)
|
||||
{
|
||||
const Pair<point>& pts = edgesToSplit[i];
|
||||
|
||||
label edgeI = findEdge(mesh, allBoundary, pts.first());
|
||||
|
||||
if
|
||||
@ -473,10 +463,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Looking up faces to triangulate ..." << nl << endl;
|
||||
Map<point> faceToDecompose(facesToTriangulate.size());
|
||||
forAll(facesToTriangulate, i)
|
||||
for (const Pair<point>& pts : facesToTriangulate)
|
||||
{
|
||||
const Pair<point>& pts = facesToTriangulate[i];
|
||||
|
||||
label facei = findFace(mesh, allBoundary, pts.first());
|
||||
|
||||
if (facei == -1 || !faceToDecompose.insert(facei, pts.second()))
|
||||
@ -494,10 +482,8 @@ int main(int argc, char *argv[])
|
||||
Info<< nl << "Looking up cells to convert to pyramids around"
|
||||
<< " cell centre ..." << nl << endl;
|
||||
Map<point> cellToPyrCentre(cellsToPyramidise.size());
|
||||
forAll(cellsToPyramidise, i)
|
||||
for (const Pair<point>& pts : cellsToPyramidise)
|
||||
{
|
||||
const Pair<point>& pts = cellsToPyramidise[i];
|
||||
|
||||
label celli = findCell(mesh, pts.first());
|
||||
|
||||
if (celli == -1 || !cellToPyrCentre.insert(celli, pts.second()))
|
||||
@ -513,10 +499,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< nl << "Looking up edges to collapse ..." << nl << endl;
|
||||
Map<point> edgeToPos(edgesToCollapse.size());
|
||||
forAll(edgesToCollapse, i)
|
||||
for (const Pair<point>& pts : edgesToCollapse)
|
||||
{
|
||||
const Pair<point>& pts = edgesToCollapse[i];
|
||||
|
||||
label edgeI = findEdge(mesh, allBoundary, pts.first());
|
||||
|
||||
if (edgeI == -1 || !edgeToPos.insert(edgeI, pts.second()))
|
||||
@ -590,7 +574,7 @@ int main(int argc, char *argv[])
|
||||
Map<point> collapsePointToLocation(mesh.nPoints());
|
||||
|
||||
// Get new positions and construct collapse network
|
||||
forAllConstIter(Map<point>, edgeToPos, iter)
|
||||
forAllConstIters(edgeToPos, iter)
|
||||
{
|
||||
label edgeI = iter.key();
|
||||
const edge& e = edges[edgeI];
|
||||
@ -598,7 +582,7 @@ int main(int argc, char *argv[])
|
||||
collapseEdge.set(edgeI);
|
||||
collapsePointToLocation.set(e[1], points[e[0]]);
|
||||
|
||||
newPoints[e[0]] = iter();
|
||||
newPoints[e[0]] = iter.val();
|
||||
}
|
||||
|
||||
// Move master point to destination.
|
||||
|
||||
@ -222,10 +222,8 @@ bool splitHex
|
||||
|
||||
const cell& cFaces = mesh.cells()[celli];
|
||||
|
||||
forAll(cFaces, i)
|
||||
for (const label facei : cFaces)
|
||||
{
|
||||
label facei = cFaces[i];
|
||||
|
||||
const face& f = faces[facei];
|
||||
|
||||
label fp0 = f.find(e[0]);
|
||||
@ -399,15 +397,12 @@ void collectCuts
|
||||
boolList edgeIsCut(mesh.nEdges(), false);
|
||||
scalarField edgeWeight(mesh.nEdges(), -GREAT);
|
||||
|
||||
forAllConstIter(cellSet, cellsToCut, iter)
|
||||
for (const label celli : cellsToCut)
|
||||
{
|
||||
const label celli = iter.key();
|
||||
const labelList& cEdges = cellEdges[celli];
|
||||
|
||||
forAll(cEdges, i)
|
||||
for (const label edgeI : cEdges)
|
||||
{
|
||||
label edgeI = cEdges[i];
|
||||
|
||||
label f0, f1;
|
||||
meshTools::getEdgeFaces(mesh, celli, edgeI, f0, f1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user