ENH: use CircularBuffer instead SLList for FIFO-style handling

- PrimitivePatch localPointOrder
- enrichedPatch
- polyMeshZipUpCells
This commit is contained in:
Mark Olesen
2022-11-01 12:15:08 +01:00
committed by Andrew Heather
parent f3ba6c6da0
commit db88265163
5 changed files with 68 additions and 61 deletions

View File

@ -99,7 +99,7 @@ Foam::labelList cuthill_mckee_algorithm
// Starting from currCelli - walk breadth-first // Starting from currCelli - walk breadth-first
queuedCells.append(currCelli); queuedCells.push_back(currCelli);
// Loop through queuedCells list. Add the first cell into the // Loop through queuedCells list. Add the first cell into the
// cell order if it has not already been visited and ask for its // cell order if it has not already been visited and ask for its
@ -109,7 +109,7 @@ Foam::labelList cuthill_mckee_algorithm
while (!queuedCells.empty()) while (!queuedCells.empty())
{ {
// Process as FIFO // Process as FIFO
currCelli = queuedCells.first(); currCelli = queuedCells.front();
queuedCells.pop_front(); queuedCells.pop_front();
if (unvisited.test(currCelli)) if (unvisited.test(currCelli))
@ -151,7 +151,7 @@ Foam::labelList cuthill_mckee_algorithm
// 3. Add to FIFO in sorted order // 3. Add to FIFO in sorted order
for (const label nbrIdx : nbrOrder) for (const label nbrIdx : nbrOrder)
{ {
queuedCells.append(nbrCells[nbrIdx]); queuedCells.push_back(nbrCells[nbrIdx]);
} }
} }
} }
@ -240,7 +240,7 @@ Foam::labelList Foam::meshTools::bandCompression
// Starting from currCellii - walk breadth-first // Starting from currCellii - walk breadth-first
queuedCells.append(currCelli); queuedCells.push_back(currCelli);
// loop through the nextCell list. Add the first cell into the // loop through the nextCell list. Add the first cell into the
// cell order if it has not already been visited and ask for its // cell order if it has not already been visited and ask for its
@ -255,7 +255,7 @@ Foam::labelList Foam::meshTools::bandCompression
while (!queuedCells.empty()) while (!queuedCells.empty())
{ {
// Process as FIFO // Process as FIFO
currCelli = queuedCells.first(); currCelli = queuedCells.front();
queuedCells.pop_front(); queuedCells.pop_front();
if (unvisited.test(currCelli)) if (unvisited.test(currCelli))
@ -298,7 +298,7 @@ Foam::labelList Foam::meshTools::bandCompression
// 3. Add to FIFO in sorted order // 3. Add to FIFO in sorted order
for (const label nbrIdx : nbrOrder) for (const label nbrIdx : nbrOrder)
{ {
queuedCells.append(nbrCells[nbrIdx]); queuedCells.push_back(nbrCells[nbrIdx]);
} }
} }
} }

View File

@ -29,8 +29,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "SLList.H"
#include "boolList.H" #include "boolList.H"
#include "CircularBuffer.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -55,58 +55,57 @@ Foam::PrimitivePatch<FaceList, PointField>::calcLocalPointOrder() const
const labelListList& ff = faceFaces(); const labelListList& ff = faceFaces();
boolList visitedFace(lf.size(), false);
localPointOrderPtr_.reset(new labelList(meshPoints().size(), -1)); localPointOrderPtr_.reset(new labelList(meshPoints().size(), -1));
auto& pointOrder = *localPointOrderPtr_; auto& pointOrder = *localPointOrderPtr_;
boolList visitedFace(lf.size(), false);
boolList visitedPoint(pointOrder.size(), false); boolList visitedPoint(pointOrder.size(), false);
label nPoints = 0; label nPoints = 0;
// FIFO buffer managing point/face insertion order
CircularBuffer<label> faceOrder(32);
forAll(lf, facei) forAll(lf, facei)
{ {
if (!visitedFace[facei]) if (!visitedFace[facei])
{ {
SLList<label> faceOrder(facei); faceOrder.push_back(facei);
do while (!faceOrder.empty())
{ {
const label curFace = faceOrder.first(); // Process as FIFO
const label curFace = faceOrder.front();
faceOrder.removeHead(); faceOrder.pop_front();
if (!visitedFace[curFace]) if (!visitedFace[curFace])
{ {
visitedFace[curFace] = true; visitedFace[curFace] = true;
const labelList& curPoints = lf[curFace];
// mark points // mark points
forAll(curPoints, pointi) for (const label pointi : lf[curFace])
{ {
if (!visitedPoint[curPoints[pointi]]) if (!visitedPoint[pointi])
{ {
visitedPoint[curPoints[pointi]] = true; visitedPoint[pointi] = true;
pointOrder[nPoints] = curPoints[pointi]; pointOrder[nPoints] = pointi;
nPoints++; ++nPoints;
} }
} }
// add face neighbours to the list // Add unvisited face neighbours to the list
const labelList& nbrs = ff[curFace];
forAll(nbrs, nbrI) for (const label nbrFacei : ff[curFace])
{ {
if (!visitedFace[nbrs[nbrI]]) if (!visitedFace[nbrFacei])
{ {
faceOrder.append(nbrs[nbrI]); faceOrder.push_back(nbrFacei);
} }
} }
} }
} while (faceOrder.size()); }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,6 +32,7 @@ Description
#include "enrichedPatch.H" #include "enrichedPatch.H"
#include "boolList.H" #include "boolList.H"
#include "CircularBuffer.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "labelPair.H" #include "labelPair.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
@ -101,6 +102,9 @@ void Foam::enrichedPatch::calcCutFaces() const
edgeHashSet edgesUsedTwice(pp.size()*primitiveMesh::edgesPerPoint_); edgeHashSet edgesUsedTwice(pp.size()*primitiveMesh::edgesPerPoint_);
DynamicList<bool> usedFaceEdges(256);
CircularBuffer<edge> edgeSeeds(256);
forAll(lf, facei) forAll(lf, facei)
{ {
const face& curLocalFace = lf[facei]; const face& curLocalFace = lf[facei];
@ -141,25 +145,22 @@ void Foam::enrichedPatch::calcCutFaces() const
// internal to the current face if used only once. // internal to the current face if used only once.
// Track the edge usage to avoid duplicate faces and reset it to unused // Track the edge usage to avoid duplicate faces and reset it to unused
boolList usedFaceEdges(curLocalFace.size(), false); usedFaceEdges.resize_nocopy(curLocalFace.size());
usedFaceEdges = false;
SLList<edge> edgeSeeds; // Add edges of current face into the seed list.
edgeSeeds.clear();
// Insert the edges of current face into the seed list. edgeSeeds.push_back(curLocalFace.edges());
edgeList cfe = curLocalFace.edges();
for (const edge& e : cfe)
{
edgeSeeds.append(e);
}
// Grab face normal // Grab face normal
const vector normal = curLocalFace.unitNormal(lp); const vector normal = curLocalFace.unitNormal(lp);
while (edgeSeeds.size()) while (!edgeSeeds.empty())
{ {
// Pout<< "edgeSeeds.size(): " << edgeSeeds.size() << endl; // Pout<< "edgeSeeds.size(): " << edgeSeeds.size() << endl;
const edge curEdge = edgeSeeds.removeHead(); const edge curEdge = edgeSeeds.front();
edgeSeeds.pop_front();
// Locate the edge in current face // Locate the edge in current face
const label curEdgeWhich = curLocalFace.which(curEdge.start()); const label curEdgeWhich = curLocalFace.which(curEdge.start());
@ -407,7 +408,7 @@ void Foam::enrichedPatch::calcCutFaces() const
// << curCutFaceEdge // << curCutFaceEdge
// << endl; // << endl;
edgeSeeds.append(curCutFaceEdge.reverseEdge()); edgeSeeds.push_back(curCutFaceEdge.reverseEdge());
} }
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,6 +29,8 @@ License
#include "polyMeshZipUpCells.H" #include "polyMeshZipUpCells.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "Time.H" #include "Time.H"
#include "CircularBuffer.H"
#include "DynamicList.H"
// #define DEBUG_ZIPUP 1 // #define DEBUG_ZIPUP 1
// #define DEBUG_CHAIN 1 // #define DEBUG_CHAIN 1
@ -66,6 +69,9 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
labelHashSet problemCells; labelHashSet problemCells;
DynamicList<bool> singleEdgeUsage(256);
CircularBuffer<label> pointChain(256);
do do
{ {
nChangedFacesInMesh = 0; nChangedFacesInMesh = 0;
@ -198,7 +204,8 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
} }
} }
boolList singleEdgeUsage(singleEdges.size(), false); singleEdgeUsage.resize_nocopy(singleEdges.size());
singleEdgeUsage = false;
// loop through all edges and eliminate the ones that are // loop through all edges and eliminate the ones that are
// blocked out // blocked out
@ -246,7 +253,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// Find a good edge // Find a good edge
forAll(singleEdges, edgeI) forAll(singleEdges, edgeI)
{ {
SLList<label> pointChain; pointChain.clear();
bool blockHead = false; bool blockHead = false;
bool blockTail = false; bool blockTail = false;
@ -259,8 +266,8 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
label newEdgeStart = singleEdges[edgeI].start(); label newEdgeStart = singleEdges[edgeI].start();
label newEdgeEnd = singleEdges[edgeI].end(); label newEdgeEnd = singleEdges[edgeI].end();
pointChain.insert(newEdgeStart); pointChain.push_front(newEdgeStart);
pointChain.append(newEdgeEnd); pointChain.push_back(newEdgeEnd);
#ifdef DEBUG_CHAIN #ifdef DEBUG_CHAIN
Info<< "found edge to start with: " Info<< "found edge to start with: "
@ -320,16 +327,16 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// Try to add the edge onto the head // Try to add the edge onto the head
if (!blockHead) if (!blockHead)
{ {
if (pointChain.first() == addStart) if (pointChain.front() == addStart)
{ {
// Added at start mark as used // Added at start mark as used
pointChain.insert(addEnd); pointChain.push_front(addEnd);
singleEdgeUsage[addEdgeI] = true; singleEdgeUsage[addEdgeI] = true;
} }
else if (pointChain.first() == addEnd) else if (pointChain.front() == addEnd)
{ {
pointChain.insert(addStart); pointChain.push_front(addStart);
singleEdgeUsage[addEdgeI] = true; singleEdgeUsage[addEdgeI] = true;
} }
@ -339,24 +346,24 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
// did not add it // did not add it
if (!blockTail && !singleEdgeUsage[addEdgeI]) if (!blockTail && !singleEdgeUsage[addEdgeI])
{ {
if (pointChain.last() == addStart) if (pointChain.back() == addStart)
{ {
// Added at start mark as used // Added at start mark as used
pointChain.append(addEnd); pointChain.push_back(addEnd);
singleEdgeUsage[addEdgeI] = true; singleEdgeUsage[addEdgeI] = true;
} }
else if (pointChain.last() == addEnd) else if (pointChain.back() == addEnd)
{ {
pointChain.append(addStart); pointChain.push_back(addStart);
singleEdgeUsage[addEdgeI] = true; singleEdgeUsage[addEdgeI] = true;
} }
} }
// check if the new head or tail are blocked // check if the new head or tail are blocked
label curEdgeStart = pointChain.first(); label curEdgeStart = pointChain.front();
label curEdgeEnd = pointChain.last(); label curEdgeEnd = pointChain.back();
#ifdef DEBUG_CHAIN #ifdef DEBUG_CHAIN
Info<< "curEdgeStart: " << curEdgeStart Info<< "curEdgeStart: " << curEdgeStart
@ -396,7 +403,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
Info<< "closed loop" << endl; Info<< "closed loop" << endl;
#endif #endif
pointChain.removeHead(); pointChain.pop_front();
blockHead = true; blockHead = true;
blockTail = true; blockTail = true;
@ -405,8 +412,8 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
} }
#ifdef DEBUG_CHAIN #ifdef DEBUG_CHAIN
Info<< "current pointChain: " << pointChain Info<< "current pointChain: "
<< endl; << pointChain << endl;
#endif #endif
if (stopSearching) break; if (stopSearching) break;
@ -421,7 +428,7 @@ bool Foam::polyMeshZipUpCells(polyMesh& mesh)
if (pointChain.size() > 2) if (pointChain.size() > 2)
{ {
edgesToInsert[nEdgesToInsert] = pointChain; edgesToInsert[nEdgesToInsert] = pointChain.list();
nEdgesToInsert++; nEdgesToInsert++;
} }
} }

View File

@ -649,7 +649,7 @@ Foam::label Foam::polyTopoChange::getCellOrder
// Starting from currCelli - walk breadth-first // Starting from currCelli - walk breadth-first
queuedCells.append(currCelli); queuedCells.push_back(currCelli);
// Loop through queuedCells list. Add the first cell into the // Loop through queuedCells list. Add the first cell into the
// cell order if it has not already been visited and ask for its // cell order if it has not already been visited and ask for its
@ -659,7 +659,7 @@ Foam::label Foam::polyTopoChange::getCellOrder
while (!queuedCells.empty()) while (!queuedCells.empty())
{ {
// Process as FIFO // Process as FIFO
currCelli = queuedCells.first(); currCelli = queuedCells.front();
queuedCells.pop_front(); queuedCells.pop_front();
if (unvisited.test(currCelli)) if (unvisited.test(currCelli))
@ -701,7 +701,7 @@ Foam::label Foam::polyTopoChange::getCellOrder
// 3. Add to FIFO in sorted order // 3. Add to FIFO in sorted order
for (const label nbrIdx : nbrOrder) for (const label nbrIdx : nbrOrder)
{ {
queuedCells.append(nbrCells[nbrIdx]); queuedCells.push_back(nbrCells[nbrIdx]);
} }
} }
} }