ENH: use back(), pop_back() instead remove()

- adjust looping to resemble LIFO pattern

STYLE: adjust some string includes
This commit is contained in:
Mark Olesen
2023-01-26 12:36:53 +01:00
parent 7c60c80edd
commit eb8b51b475
25 changed files with 125 additions and 132 deletions

View File

@ -113,11 +113,11 @@ void Foam::cellVolumeWeightMethod::calculateAddressing
List<DynamicList<label>> tgtToSrcAddr(tgt_.nCells());
List<DynamicList<scalar>> tgtToSrcWght(tgt_.nCells());
// list of tgt cell neighbour cells
DynamicList<label> nbrTgtCells(10);
// List of tgt cell neighbour cells
DynamicList<label> queuedCells(10);
// list of tgt cells currently visited for srcCelli to avoid multiple hits
DynamicList<label> visitedTgtCells(10);
// List of tgt cells currently visited for srcCellI to avoid multiple hits
DynamicList<label> visitedCells(10);
// list to keep track of tgt cells used to seed src cells
labelList seedCells(src_.nCells(), -1);
@ -127,17 +127,19 @@ void Foam::cellVolumeWeightMethod::calculateAddressing
do
{
nbrTgtCells.clear();
visitedTgtCells.clear();
queuedCells.clear();
visitedCells.clear();
// append initial target cell and neighbours
nbrTgtCells.append(tgtCelli);
appendNbrCells(tgtCelli, tgt_, visitedTgtCells, nbrTgtCells);
// Initial target cell and neighbours
queuedCells.push_back(tgtCelli);
appendNbrCells(tgtCelli, tgt_, visitedCells, queuedCells);
do
while (!queuedCells.empty())
{
tgtCelli = nbrTgtCells.remove();
visitedTgtCells.append(tgtCelli);
// Process new target cell as LIFO
tgtCelli = queuedCells.back();
queuedCells.pop_back();
visitedCells.push_back(tgtCelli);
scalar vol = interVol(srcCelli, tgtCelli);
@ -151,13 +153,12 @@ void Foam::cellVolumeWeightMethod::calculateAddressing
tgtToSrcAddr[tgtCelli].append(srcCelli);
tgtToSrcWght[tgtCelli].append(vol);
appendNbrCells(tgtCelli, tgt_, visitedTgtCells, nbrTgtCells);
appendNbrCells(tgtCelli, tgt_, visitedCells, queuedCells);
// accumulate intersection volume
V_ += vol;
}
}
while (!nbrTgtCells.empty());
mapFlag[srcCelli] = false;
@ -169,7 +170,7 @@ void Foam::cellVolumeWeightMethod::calculateAddressing
tgtCelli,
srcCellIDs,
mapFlag,
visitedTgtCells,
visitedCells,
seedCells
);
}

View File

@ -70,13 +70,13 @@ void Foam::correctedCellVolumeWeightMethod::calculateAddressing
List<DynamicList<scalar>> tgtToSrcWght(tgt_.nCells());
List<DynamicList<point>> tgtToSrcVec(tgt_.nCells());
// list of tgt cell neighbour cells
DynamicList<label> nbrTgtCells(10);
// List of tgt cell neighbour cells
DynamicList<label> queuedCells(10);
// list of tgt cells currently visited for srcCellI to avoid multiple hits
DynamicList<label> visitedTgtCells(10);
// List of tgt cells currently visited for srcCellI to avoid multiple hits
DynamicList<label> visitedCells(10);
// list to keep track of tgt cells used to seed src cells
// List to keep track of tgt cells used to seed src cells
labelList seedCells(src_.nCells(), -1);
seedCells[srcCellI] = tgtCellI;
@ -86,17 +86,19 @@ void Foam::correctedCellVolumeWeightMethod::calculateAddressing
do
{
nbrTgtCells.clear();
visitedTgtCells.clear();
queuedCells.clear();
visitedCells.clear();
// append initial target cell and neighbours
nbrTgtCells.append(tgtCellI);
appendNbrCells(tgtCellI, tgt_, visitedTgtCells, nbrTgtCells);
// Initial target cell and neighbours
queuedCells.push_back(tgtCellI);
appendNbrCells(tgtCellI, tgt_, visitedCells, queuedCells);
do
while (!queuedCells.empty())
{
tgtCellI = nbrTgtCells.remove();
visitedTgtCells.append(tgtCellI);
// Process new target cell as LIFO
tgtCellI = queuedCells.back();
queuedCells.pop_back();
visitedCells.push_back(tgtCellI);
Tuple2<scalar, point> vol = interVolAndCentroid
(
@ -116,13 +118,12 @@ void Foam::correctedCellVolumeWeightMethod::calculateAddressing
tgtToSrcWght[tgtCellI].append(vol.first());
tgtToSrcVec[tgtCellI].append(vol.second()-srcCc[srcCellI]);
appendNbrCells(tgtCellI, tgt_, visitedTgtCells, nbrTgtCells);
appendNbrCells(tgtCellI, tgt_, visitedCells, queuedCells);
// accumulate intersection volume
V_ += vol.first();
}
}
while (!nbrTgtCells.empty());
mapFlag[srcCellI] = false;
@ -134,7 +135,7 @@ void Foam::correctedCellVolumeWeightMethod::calculateAddressing
tgtCellI,
srcCellIDs,
mapFlag,
visitedTgtCells,
visitedCells,
seedCells
);
}

View File

@ -174,27 +174,23 @@ void Foam::directMethod::appendToDirectSeeds
const labelList& srcNbr = src_.cellCells()[srcSeedI];
const labelList& tgtNbr = tgt_.cellCells()[tgtSeedI];
forAll(srcNbr, i)
for (const label srcI : srcNbr)
{
label srcI = srcNbr[i];
if (mapFlag[srcI] && (srcTgtSeed[srcI] == -1))
{
// source cell srcI not yet mapped
// identify if target cell exists for source cell srcI
bool found = false;
forAll(tgtNbr, j)
for (const label tgtI : tgtNbr)
{
label tgtI = tgtNbr[j];
if (intersect(srcI, tgtI))
{
// new match - append to lists
found = true;
srcTgtSeed[srcI] = tgtI;
srcSeeds.append(srcI);
srcSeeds.push_back(srcI);
break;
}
@ -208,10 +204,11 @@ void Foam::directMethod::appendToDirectSeeds
}
}
if (srcSeeds.size())
if (!srcSeeds.empty())
{
srcSeedI = srcSeeds.remove();
srcSeedI = srcSeeds.back();
tgtSeedI = srcTgtSeed[srcSeedI];
srcSeeds.pop_back();
}
else
{

View File

@ -217,27 +217,29 @@ void Foam::mapNearestMethod::findNearestCell
const vector& p1 = Cc1[cell1];
DynamicList<label> cells2(10);
cells2.append(cell2);
DynamicList<label> queuedCells(10);
DynamicList<label> visitedCells(10);
queuedCells.push_back(cell2);
scalar d = GREAT;
do
while (!queuedCells.empty())
{
label c2 = cells2.remove();
visitedCells.append(c2);
// Process as LIFO
const label currCelli = queuedCells.back();
queuedCells.pop_back();
visitedCells.push_back(currCelli);
scalar dTest = p1.distSqr(Cc2[currCelli]);
scalar dTest = magSqr(Cc2[c2] - p1);
if (dTest < d)
{
cell2 = c2;
cell2 = currCelli;
d = dTest;
appendNbrCells(cell2, mesh2, visitedCells, cells2);
appendNbrCells(cell2, mesh2, visitedCells, queuedCells);
}
} while (cells2.size() > 0);
}
}
@ -290,19 +292,22 @@ Foam::label Foam::mapNearestMethod::findMappedSrcCell
const List<DynamicList<label>>& tgtToSrc
) const
{
DynamicList<label> testCells(16);
DynamicList<label> queuedCells(16);
DynamicList<label> visitedCells(16);
testCells.append(tgtCelli);
queuedCells.push_back(tgtCelli);
do
while (!queuedCells.empty())
{
// Process as LIFO
const label tgtI = queuedCells.back();
queuedCells.pop_back();
// search target tgtCelli neighbours for match with source cell
label tgtI = testCells.remove();
if (!visitedCells.found(tgtI))
{
visitedCells.append(tgtI);
visitedCells.push_back(tgtI);
if (tgtToSrc[tgtI].size())
{
@ -316,12 +321,12 @@ Foam::label Foam::mapNearestMethod::findMappedSrcCell
{
if (!visitedCells.found(nbrCelli))
{
testCells.append(nbrCelli);
queuedCells.push_back(nbrCelli);
}
}
}
}
} while (testCells.size());
}
// did not find any match - should not be possible to get here!
return -1;