mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: for-range, forAllIters() ... in sampling/, surfMesh/
- reduced clutter when iterating over containers
This commit is contained in:
committed by
Andrew Heather
parent
655f7d1997
commit
5c6b0989a4
@ -638,10 +638,9 @@ void Foam::meshToMesh::distributeAndMergeCells
|
|||||||
key[1] = max(proci, nbrProci[i]);
|
key[1] = max(proci, nbrProci[i]);
|
||||||
key[2] = localFacei[i];
|
key[2] = localFacei[i];
|
||||||
|
|
||||||
procCoupleInfo::const_iterator fnd =
|
const auto fnd = procFaceToGlobalCell.cfind(key);
|
||||||
procFaceToGlobalCell.find(key);
|
|
||||||
|
|
||||||
if (fnd == procFaceToGlobalCell.end())
|
if (!fnd.found())
|
||||||
{
|
{
|
||||||
procFaceToGlobalCell.insert(key, -1);
|
procFaceToGlobalCell.insert(key, -1);
|
||||||
}
|
}
|
||||||
@ -754,9 +753,9 @@ void Foam::meshToMesh::distributeAndMergeCells
|
|||||||
key[1] = max(proci, nbrProci[i]);
|
key[1] = max(proci, nbrProci[i]);
|
||||||
key[2] = localFacei[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();
|
label tgtFacei = fnd();
|
||||||
if (tgtFacei == -1)
|
if (tgtFacei == -1)
|
||||||
|
|||||||
@ -367,7 +367,7 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
|
|||||||
{
|
{
|
||||||
zoneToc_[zonei] = surfZoneIdentifier
|
zoneToc_[zonei] = surfZoneIdentifier
|
||||||
(
|
(
|
||||||
word("zone") + ::Foam::name(zonei),
|
"zone" + ::Foam::name(zonei),
|
||||||
zonei
|
zonei
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -477,53 +477,39 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
|
|||||||
|
|
||||||
// Step 1: get zone sizes and store (origId => zoneI)
|
// Step 1: get zone sizes and store (origId => zoneI)
|
||||||
Map<label> lookup;
|
Map<label> lookup;
|
||||||
forAll(zoneIds_, facei)
|
for (const label origId : zoneIds_)
|
||||||
{
|
{
|
||||||
const label origId = zoneIds_[facei];
|
++(lookup(origId, 0));
|
||||||
|
|
||||||
Map<label>::iterator fnd = lookup.find(origId);
|
|
||||||
if (fnd != lookup.end())
|
|
||||||
{
|
|
||||||
fnd()++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lookup.insert(origId, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: assign start/size (and name) to the newZones
|
// Step 2: assign start/size (and name) to the newZones
|
||||||
// re-use the lookup to map (zoneId => zoneI)
|
// re-use the lookup to map (zoneId => zoneI)
|
||||||
surfZoneList zoneLst(lookup.size());
|
surfZoneList zoneLst(lookup.size());
|
||||||
label start = 0;
|
label start = 0;
|
||||||
label zoneI = 0;
|
label zonei = 0;
|
||||||
forAllIter(Map<label>, lookup, iter)
|
forAllIters(lookup, iter)
|
||||||
{
|
{
|
||||||
label origId = iter.key();
|
const label origId = iter.key();
|
||||||
|
|
||||||
word name;
|
const word zoneName =
|
||||||
Map<word>::const_iterator fnd = zoneNames.find(origId);
|
zoneNames.lookup
|
||||||
if (fnd != zoneNames.end())
|
(
|
||||||
{
|
origId,
|
||||||
name = fnd();
|
"zone" + ::Foam::name(zonei) // default name
|
||||||
}
|
);
|
||||||
else
|
|
||||||
{
|
|
||||||
name = word("zone") + ::Foam::name(zoneI);
|
|
||||||
}
|
|
||||||
|
|
||||||
zoneLst[zoneI] = surfZone
|
zoneLst[zonei] = surfZone
|
||||||
(
|
(
|
||||||
name,
|
zoneName,
|
||||||
0, // initialize with zero size
|
0, // initialize with zero size
|
||||||
start,
|
start,
|
||||||
zoneI
|
zonei
|
||||||
);
|
);
|
||||||
|
|
||||||
// increment the start for the next zone
|
// increment the start for the next zone
|
||||||
// and save the (zoneId => zoneI) mapping
|
// and save the (zoneId => zoneI) mapping
|
||||||
start += iter();
|
start += iter();
|
||||||
iter() = zoneI++;
|
iter() = zonei++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -532,7 +518,7 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
|
|||||||
|
|
||||||
forAll(zoneIds_, facei)
|
forAll(zoneIds_, facei)
|
||||||
{
|
{
|
||||||
label zonei = lookup[zoneIds_[facei]];
|
const label zonei = lookup[zoneIds_[facei]];
|
||||||
faceMap[facei] = zoneLst[zonei].start() + zoneLst[zonei].size()++;
|
faceMap[facei] = zoneLst[zonei].start() + zoneLst[zonei].size()++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,10 +561,9 @@ Foam::UnsortedMeshedSurface<Face>::subsetMesh
|
|||||||
newFaces[facei] = Face(locFaces[origFacei]);
|
newFaces[facei] = Face(locFaces[origFacei]);
|
||||||
|
|
||||||
// Renumber labels for face
|
// Renumber labels for face
|
||||||
Face& f = newFaces[facei];
|
for (label& pointi : newFaces[facei])
|
||||||
forAll(f, fp)
|
|
||||||
{
|
{
|
||||||
f[fp] = oldToNew[f[fp]];
|
pointi = oldToNew[pointi];
|
||||||
}
|
}
|
||||||
|
|
||||||
newZones[facei] = zoneIds_[origFacei];
|
newZones[facei] = zoneIds_[origFacei];
|
||||||
|
|||||||
Reference in New Issue
Block a user