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:
@ -842,16 +842,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
label i = 0;
|
||||
|
||||
forAllIter
|
||||
(
|
||||
Cloud<indexedParticle>,
|
||||
lagrangianPositions[cloudI],
|
||||
iter
|
||||
)
|
||||
for (indexedParticle& p : lagrangianPositions[cloudI])
|
||||
{
|
||||
iter().index() = i++;
|
||||
p.index() = i++;
|
||||
|
||||
label celli = iter().cell();
|
||||
label celli = p.cell();
|
||||
|
||||
// Check
|
||||
if (celli < 0 || celli >= mesh.nCells())
|
||||
@ -859,14 +854,14 @@ int main(int argc, char *argv[])
|
||||
FatalErrorInFunction
|
||||
<< "Illegal cell number " << celli
|
||||
<< " for particle with index "
|
||||
<< iter().index()
|
||||
<< p.index()
|
||||
<< " at position "
|
||||
<< iter().position() << nl
|
||||
<< p.position() << nl
|
||||
<< "Cell number should be between 0 and "
|
||||
<< mesh.nCells()-1 << nl
|
||||
<< "On this mesh the particle should"
|
||||
<< " be in cell "
|
||||
<< mesh.findCell(iter().position())
|
||||
<< mesh.findCell(p.position())
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
@ -876,7 +871,7 @@ int main(int argc, char *argv[])
|
||||
new SLList<indexedParticle*>();
|
||||
}
|
||||
|
||||
cellParticles[cloudI][celli]->append(&iter());
|
||||
cellParticles[cloudI][celli]->append(&p);
|
||||
}
|
||||
|
||||
// Read fields
|
||||
|
||||
@ -55,16 +55,16 @@ void Foam::domainDecomposition::addInterProcFace
|
||||
List<DynamicList<DynamicList<label>>>& interPatchFaces
|
||||
) const
|
||||
{
|
||||
Map<label>::iterator patchiter = nbrToInterPatch[ownerProc].find(nbrProc);
|
||||
|
||||
// Introduce turning index only for internal faces (are duplicated).
|
||||
label ownerIndex = facei+1;
|
||||
label nbrIndex = -(facei+1);
|
||||
const label ownerIndex = facei+1;
|
||||
const label nbrIndex = -(facei+1);
|
||||
|
||||
if (patchiter != nbrToInterPatch[ownerProc].end())
|
||||
const auto patchiter = nbrToInterPatch[ownerProc].cfind(nbrProc);
|
||||
|
||||
if (patchiter.found())
|
||||
{
|
||||
// Existing interproc patch. Add to both sides.
|
||||
label toNbrProcPatchi = patchiter();
|
||||
const label toNbrProcPatchi = *patchiter;
|
||||
interPatchFaces[ownerProc][toNbrProcPatchi].append(ownerIndex);
|
||||
|
||||
if (isInternalFace(facei))
|
||||
@ -76,8 +76,9 @@ void Foam::domainDecomposition::addInterProcFace
|
||||
else
|
||||
{
|
||||
// Create new interproc patches.
|
||||
label toNbrProcPatchi = nbrToInterPatch[ownerProc].size();
|
||||
const label toNbrProcPatchi = nbrToInterPatch[ownerProc].size();
|
||||
nbrToInterPatch[ownerProc].insert(nbrProc, toNbrProcPatchi);
|
||||
|
||||
DynamicList<label> oneFace;
|
||||
oneFace.append(ownerIndex);
|
||||
interPatchFaces[ownerProc].append(oneFace);
|
||||
|
||||
@ -435,59 +435,55 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
// inside boundaries for the owner processor and try to find
|
||||
// this inter-processor patch.
|
||||
|
||||
const label ownerProc = faceToProc_[owner[edgeI]];
|
||||
const label neighbourProc = faceToProc_[neighbour[edgeI]];
|
||||
|
||||
SLList<label>::iterator curInterProcBdrsOwnIter =
|
||||
interProcBoundaries[ownerProc].begin();
|
||||
|
||||
SLList<SLList<label>>::iterator curInterProcBEdgesOwnIter =
|
||||
interProcBEdges[ownerProc].begin();
|
||||
|
||||
bool interProcBouFound = false;
|
||||
|
||||
const label ownProc = faceToProc_[owner[edgeI]];
|
||||
const label neiProc = faceToProc_[neighbour[edgeI]];
|
||||
|
||||
auto curInterProcBdrsOwnIter =
|
||||
interProcBoundaries[ownProc].cbegin();
|
||||
|
||||
auto curInterProcBEdgesOwnIter =
|
||||
interProcBEdges[ownProc].begin();
|
||||
|
||||
// WARNING: Synchronous SLList iterators
|
||||
|
||||
for
|
||||
(
|
||||
;
|
||||
curInterProcBdrsOwnIter
|
||||
!= interProcBoundaries[ownerProc].end()
|
||||
&& curInterProcBEdgesOwnIter
|
||||
!= interProcBEdges[ownerProc].end();
|
||||
++curInterProcBdrsOwnIter, ++curInterProcBEdgesOwnIter
|
||||
curInterProcBdrsOwnIter.good()
|
||||
&& curInterProcBEdgesOwnIter.good();
|
||||
++curInterProcBdrsOwnIter,
|
||||
++curInterProcBEdgesOwnIter
|
||||
)
|
||||
{
|
||||
if (curInterProcBdrsOwnIter() == neighbourProc)
|
||||
if (curInterProcBdrsOwnIter() == neiProc)
|
||||
{
|
||||
// the inter - processor boundary exists. Add the face
|
||||
interProcBouFound = true;
|
||||
|
||||
bool neighbourFound = false;
|
||||
|
||||
curInterProcBEdgesOwnIter().append(edgeI);
|
||||
|
||||
SLList<label>::iterator curInterProcBdrsNeiIter =
|
||||
interProcBoundaries[neighbourProc].begin();
|
||||
auto curInterProcBdrsNeiIter =
|
||||
interProcBoundaries[neiProc].cbegin();
|
||||
|
||||
SLList<SLList<label>>::iterator
|
||||
curInterProcBEdgesNeiIter =
|
||||
interProcBEdges[neighbourProc].begin();
|
||||
|
||||
bool neighbourFound = false;
|
||||
auto curInterProcBEdgesNeiIter =
|
||||
interProcBEdges[neiProc].begin();
|
||||
|
||||
// WARNING: Synchronous SLList iterators
|
||||
|
||||
for
|
||||
(
|
||||
;
|
||||
curInterProcBdrsNeiIter !=
|
||||
interProcBoundaries[neighbourProc].end()
|
||||
&& curInterProcBEdgesNeiIter !=
|
||||
interProcBEdges[neighbourProc].end();
|
||||
curInterProcBdrsNeiIter.good()
|
||||
&& curInterProcBEdgesNeiIter.good();
|
||||
++curInterProcBdrsNeiIter,
|
||||
++curInterProcBEdgesNeiIter
|
||||
)
|
||||
{
|
||||
if (curInterProcBdrsNeiIter() == ownerProc)
|
||||
if (curInterProcBdrsNeiIter() == ownProc)
|
||||
{
|
||||
// boundary found. Add the face
|
||||
neighbourFound = true;
|
||||
@ -504,7 +500,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
("faDomainDecomposition::decomposeMesh()")
|
||||
<< "Inconsistency in inter - "
|
||||
<< "processor boundary lists for processors "
|
||||
<< ownerProc << " and " << neighbourProc
|
||||
<< ownProc << " and " << neiProc
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
@ -520,12 +516,13 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
// set the new addressing information
|
||||
|
||||
// owner
|
||||
interProcBoundaries[ownerProc].append(neighbourProc);
|
||||
interProcBEdges[ownerProc].append(SLList<label>(edgeI));
|
||||
interProcBoundaries[ownProc].append(neiProc);
|
||||
interProcBEdges[ownProc].append(SLList<label>(edgeI));
|
||||
|
||||
// neighbour
|
||||
interProcBoundaries[neighbourProc].append(ownerProc);
|
||||
interProcBEdges[neighbourProc].append
|
||||
interProcBoundaries[neiProc].append(ownProc);
|
||||
interProcBEdges[neiProc]
|
||||
.append
|
||||
(
|
||||
SLList<label>(edgeI)
|
||||
);
|
||||
@ -624,64 +621,59 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
|
||||
cyclicParallel_ = true;
|
||||
|
||||
label ownerProc = faceToProc_[firstEdgeFaces[edgeI]];
|
||||
label neighbourProc =
|
||||
bool interProcBouFound = false;
|
||||
|
||||
const label ownProc =
|
||||
faceToProc_[firstEdgeFaces[edgeI]];
|
||||
const label neiProc =
|
||||
faceToProc_[secondEdgeFaces[edgeI]];
|
||||
|
||||
SLList<label>::iterator curInterProcBdrsOwnIter =
|
||||
interProcBoundaries[ownerProc].begin();
|
||||
auto curInterProcBdrsOwnIter =
|
||||
interProcBoundaries[ownProc].cbegin();
|
||||
|
||||
SLList<SLList<label>>::iterator
|
||||
curInterProcBEdgesOwnIter =
|
||||
interProcBEdges[ownerProc].begin();
|
||||
|
||||
bool interProcBouFound = false;
|
||||
auto curInterProcBEdgesOwnIter =
|
||||
interProcBEdges[ownProc].begin();
|
||||
|
||||
// WARNING: Synchronous SLList iterators
|
||||
|
||||
for
|
||||
(
|
||||
;
|
||||
curInterProcBdrsOwnIter !=
|
||||
interProcBoundaries[ownerProc].end()
|
||||
&& curInterProcBEdgesOwnIter !=
|
||||
interProcBEdges[ownerProc].end();
|
||||
curInterProcBdrsOwnIter.good()
|
||||
&& curInterProcBEdgesOwnIter.good();
|
||||
++curInterProcBdrsOwnIter,
|
||||
++curInterProcBEdgesOwnIter
|
||||
)
|
||||
{
|
||||
if (curInterProcBdrsOwnIter() == neighbourProc)
|
||||
if (curInterProcBdrsOwnIter() == neiProc)
|
||||
{
|
||||
// the inter - processor boundary exists.
|
||||
// Add the face
|
||||
interProcBouFound = true;
|
||||
|
||||
curInterProcBEdgesOwnIter().append
|
||||
(patchStart + edgeI);
|
||||
|
||||
SLList<label>::iterator curInterProcBdrsNeiIter
|
||||
= interProcBoundaries[neighbourProc].begin();
|
||||
|
||||
SLList<SLList<label>>::iterator
|
||||
curInterProcBEdgesNeiIter =
|
||||
interProcBEdges[neighbourProc].begin();
|
||||
|
||||
bool neighbourFound = false;
|
||||
|
||||
curInterProcBEdgesOwnIter()
|
||||
.append(patchStart + edgeI);
|
||||
|
||||
auto curInterProcBdrsNeiIter
|
||||
= interProcBoundaries[neiProc].cbegin();
|
||||
|
||||
auto curInterProcBEdgesNeiIter =
|
||||
interProcBEdges[neiProc].begin();
|
||||
|
||||
// WARNING: Synchronous SLList iterators
|
||||
|
||||
for
|
||||
(
|
||||
;
|
||||
curInterProcBdrsNeiIter
|
||||
!= interProcBoundaries[neighbourProc].end()
|
||||
&& curInterProcBEdgesNeiIter
|
||||
!= interProcBEdges[neighbourProc].end();
|
||||
curInterProcBdrsNeiIter.good()
|
||||
&& curInterProcBEdgesNeiIter.good();
|
||||
++curInterProcBdrsNeiIter,
|
||||
++curInterProcBEdgesNeiIter
|
||||
)
|
||||
{
|
||||
if (curInterProcBdrsNeiIter() == ownerProc)
|
||||
if (curInterProcBdrsNeiIter() == ownProc)
|
||||
{
|
||||
// boundary found. Add the face
|
||||
neighbourFound = true;
|
||||
@ -705,7 +697,7 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
"faDomainDecomposition::decomposeMesh()"
|
||||
) << "Inconsistency in inter-processor "
|
||||
<< "boundary lists for processors "
|
||||
<< ownerProc << " and " << neighbourProc
|
||||
<< ownProc << " and " << neiProc
|
||||
<< " in cyclic boundary matching"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
@ -722,15 +714,13 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
// set the new addressing information
|
||||
|
||||
// owner
|
||||
interProcBoundaries[ownerProc]
|
||||
.append(neighbourProc);
|
||||
interProcBEdges[ownerProc]
|
||||
interProcBoundaries[ownProc].append(neiProc);
|
||||
interProcBEdges[ownProc]
|
||||
.append(SLList<label>(patchStart + edgeI));
|
||||
|
||||
// neighbour
|
||||
interProcBoundaries[neighbourProc]
|
||||
.append(ownerProc);
|
||||
interProcBEdges[neighbourProc]
|
||||
interProcBoundaries[neiProc].append(ownProc);
|
||||
interProcBEdges[neiProc]
|
||||
.append
|
||||
(
|
||||
SLList<label>
|
||||
@ -745,13 +735,13 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
else
|
||||
{
|
||||
// This cyclic edge remains on the processor
|
||||
label ownerProc = faceToProc_[firstEdgeFaces[edgeI]];
|
||||
label ownProc = faceToProc_[firstEdgeFaces[edgeI]];
|
||||
|
||||
// add the edge
|
||||
procEdgeList[ownerProc].append(patchStart + edgeI);
|
||||
procEdgeList[ownProc].append(patchStart + edgeI);
|
||||
|
||||
// increment the number of edges for this patch
|
||||
procPatchSize_[ownerProc][patchI]++;
|
||||
procPatchSize_[ownProc][patchI]++;
|
||||
|
||||
// Note: I cannot add the other side of the cyclic
|
||||
// boundary here because this would violate the order.
|
||||
@ -771,14 +761,14 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
)
|
||||
{
|
||||
// This cyclic edge remains on the processor
|
||||
label ownerProc = faceToProc_[firstEdgeFaces[edgeI]];
|
||||
label ownProc = faceToProc_[firstEdgeFaces[edgeI]];
|
||||
|
||||
// add the second edge
|
||||
procEdgeList[ownerProc].append
|
||||
procEdgeList[ownProc].append
|
||||
(patchStart + cycOffset + edgeI);
|
||||
|
||||
// increment the number of edges for this patch
|
||||
procPatchSize_[ownerProc][patchI]++;
|
||||
procPatchSize_[ownProc][patchI]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -806,15 +796,9 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
// calculate the size
|
||||
label nEdgesOnProcessor = curProcEdges.size();
|
||||
|
||||
for
|
||||
(
|
||||
SLList<SLList<label>>::iterator curInterProcBEdgesIter =
|
||||
interProcBEdges[procI].begin();
|
||||
curInterProcBEdgesIter != interProcBEdges[procI].end();
|
||||
++curInterProcBEdgesIter
|
||||
)
|
||||
for (const auto& bedges : interProcBEdges)
|
||||
{
|
||||
nEdgesOnProcessor += curInterProcBEdgesIter().size();
|
||||
nEdgesOnProcessor += bedges.size();
|
||||
}
|
||||
|
||||
curProcEdgeAddressing.setSize(nEdgesOnProcessor);
|
||||
@ -830,16 +814,11 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
// Add internal and boundary edges
|
||||
// Remember to increment the index by one such that the
|
||||
// turning index works properly.
|
||||
for
|
||||
(
|
||||
SLList<label>::iterator curProcEdgeIter = curProcEdges.begin();
|
||||
curProcEdgeIter != curProcEdges.end();
|
||||
++curProcEdgeIter
|
||||
)
|
||||
for (const label procEdgei : curProcEdges)
|
||||
{
|
||||
curProcEdgeAddressing[nEdges] = curProcEdgeIter();
|
||||
// curProcEdgeAddressing[nEdges] = curProcEdgeIter() + 1;
|
||||
nEdges++;
|
||||
curProcEdgeAddressing[nEdges] = procEdgei;
|
||||
// curProcEdgeAddressing[nEdges] = procEdgei + 1;
|
||||
++nEdges;
|
||||
}
|
||||
|
||||
// Add inter-processor boundary edges. At the beginning of each
|
||||
@ -862,18 +841,19 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
|
||||
label nProcPatches = 0;
|
||||
|
||||
SLList<label>::iterator curInterProcBdrsIter =
|
||||
interProcBoundaries[procI].begin();
|
||||
auto curInterProcBdrsIter =
|
||||
interProcBoundaries[procI].cbegin();
|
||||
|
||||
SLList<SLList<label>>::iterator curInterProcBEdgesIter =
|
||||
interProcBEdges[procI].begin();
|
||||
auto curInterProcBEdgesIter =
|
||||
interProcBEdges[procI].cbegin();
|
||||
|
||||
for
|
||||
(
|
||||
;
|
||||
curInterProcBdrsIter != interProcBoundaries[procI].end()
|
||||
&& curInterProcBEdgesIter != interProcBEdges[procI].end();
|
||||
++curInterProcBdrsIter, ++curInterProcBEdgesIter
|
||||
curInterProcBdrsIter.good()
|
||||
&& curInterProcBEdgesIter.good();
|
||||
++curInterProcBdrsIter,
|
||||
++curInterProcBEdgesIter
|
||||
)
|
||||
{
|
||||
curProcNeighbourProcessors[nProcPatches] =
|
||||
@ -889,37 +869,31 @@ void Foam::faMeshDecomposition::decomposeMesh()
|
||||
|
||||
// add faces for this processor boundary
|
||||
|
||||
for
|
||||
(
|
||||
SLList<label>::iterator curEdgesIter =
|
||||
curInterProcBEdgesIter().begin();
|
||||
curEdgesIter != curInterProcBEdgesIter().end();
|
||||
++curEdgesIter
|
||||
)
|
||||
for (const label edgei : *curInterProcBEdgesIter)
|
||||
{
|
||||
// add the edges
|
||||
|
||||
// Remember to increment the index by one such that the
|
||||
// turning index works properly.
|
||||
if (faceToProc_[owner[curEdgesIter()]] == procI)
|
||||
if (faceToProc_[owner[edgei]] == procI)
|
||||
{
|
||||
curProcEdgeAddressing[nEdges] = curEdgesIter();
|
||||
// curProcEdgeAddressing[nEdges] = curEdgesIter() + 1;
|
||||
curProcEdgeAddressing[nEdges] = edgei;
|
||||
// curProcEdgeAddressing[nEdges] = edgei + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// turning edge
|
||||
curProcEdgeAddressing[nEdges] = curEdgesIter();
|
||||
// curProcEdgeAddressing[nEdges] = -(curEdgesIter() + 1);
|
||||
curProcEdgeAddressing[nEdges] = edgei;
|
||||
// curProcEdgeAddressing[nEdges] = -(edgei + 1);
|
||||
}
|
||||
|
||||
// increment the size
|
||||
curSize++;
|
||||
++curSize;
|
||||
|
||||
nEdges++;
|
||||
++nEdges;
|
||||
}
|
||||
|
||||
nProcPatches++;
|
||||
++nProcPatches;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ Foam::lagrangianFieldDecomposer::lagrangianFieldDecomposer
|
||||
{
|
||||
SLList<indexedParticle*>& particlePtrs = *cellParticles[celli];
|
||||
|
||||
forAllConstIter(SLList<indexedParticle*>, particlePtrs, iter)
|
||||
forAllConstIters(particlePtrs, iter)
|
||||
{
|
||||
const indexedParticle& ppi = *iter();
|
||||
particleIndices_[pi++] = ppi.index();
|
||||
|
||||
Reference in New Issue
Block a user