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

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

- reduced clutter when iterating over containers
parent 655f7d19
......@@ -638,10 +638,9 @@ void Foam::meshToMesh::distributeAndMergeCells
key[1] = max(proci, nbrProci[i]);
key[2] = localFacei[i];
procCoupleInfo::const_iterator fnd =
procFaceToGlobalCell.find(key);
const auto fnd = procFaceToGlobalCell.cfind(key);
if (fnd == procFaceToGlobalCell.end())
if (!fnd.found())
{
procFaceToGlobalCell.insert(key, -1);
}
......@@ -754,9 +753,9 @@ void Foam::meshToMesh::distributeAndMergeCells
key[1] = max(proci, nbrProci[i]);
key[2] = localFacei[i];
procCoupleInfo::iterator fnd = procFaceToGlobalCell.find(key);
auto fnd = procFaceToGlobalCell.find(key);
if (fnd != procFaceToGlobalCell.end())
if (fnd.found())
{
label tgtFacei = fnd();
if (tgtFacei == -1)
......
......@@ -367,7 +367,7 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
{
zoneToc_[zonei] = surfZoneIdentifier
(
word("zone") + ::Foam::name(zonei),
"zone" + ::Foam::name(zonei),
zonei
);
......@@ -477,53 +477,39 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
// Step 1: get zone sizes and store (origId => zoneI)
Map<label> lookup;
forAll(zoneIds_, facei)
for (const label origId : zoneIds_)
{
const label origId = zoneIds_[facei];
Map<label>::iterator fnd = lookup.find(origId);
if (fnd != lookup.end())
{
fnd()++;
}
else
{
lookup.insert(origId, 1);
}
++(lookup(origId, 0));
}
// Step 2: assign start/size (and name) to the newZones
// re-use the lookup to map (zoneId => zoneI)
surfZoneList zoneLst(lookup.size());
label start = 0;
label zoneI = 0;
forAllIter(Map<label>, lookup, iter)
label zonei = 0;
forAllIters(lookup, iter)
{
label origId = iter.key();
const label origId = iter.key();
word name;
Map<word>::const_iterator fnd = zoneNames.find(origId);
if (fnd != zoneNames.end())
{
name = fnd();
}
else
{
name = word("zone") + ::Foam::name(zoneI);
}
const word zoneName =
zoneNames.lookup
(
origId,
"zone" + ::Foam::name(zonei) // default name
);
zoneLst[zoneI] = surfZone
zoneLst[zonei] = surfZone
(
name,
zoneName,
0, // initialize with zero size
start,
zoneI
zonei
);
// increment the start for the next zone
// and save the (zoneId => zoneI) mapping
start += iter();
iter() = zoneI++;
iter() = zonei++;
}
......@@ -532,7 +518,7 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
forAll(zoneIds_, facei)
{
label zonei = lookup[zoneIds_[facei]];
const label zonei = lookup[zoneIds_[facei]];
faceMap[facei] = zoneLst[zonei].start() + zoneLst[zonei].size()++;
}
......@@ -575,10 +561,9 @@ Foam::UnsortedMeshedSurface<Face>::subsetMesh
newFaces[facei] = Face(locFaces[origFacei]);
// Renumber labels for face
Face& f = newFaces[facei];
forAll(f, fp)
for (label& pointi : newFaces[facei])
{
f[fp] = oldToNew[f[fp]];
pointi = oldToNew[pointi];
}
newZones[facei] = zoneIds_[origFacei];
......
Markdown is supported
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