From c66993e288def90840fddd8d27de781616a54162 Mon Sep 17 00:00:00 2001 From: Mark OLESEN <mark.olesen@esi-group.com> Date: Fri, 3 Mar 2023 16:34:40 +0000 Subject: [PATCH] Revert "Merge branch 'primitiveMeshOptimization' into 'develop'" This reverts merge request !596 --- .../primitiveMesh/primitiveMeshCellPoints.C | 44 +----- .../primitiveMesh/primitiveMeshPointCells.C | 130 ++++-------------- 2 files changed, 29 insertions(+), 145 deletions(-) diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C index 7adcae2cc6d..f400f68948d 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCellPoints.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2018-2023 OpenCFD Ltd. + Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,7 +29,6 @@ License #include "primitiveMesh.H" #include "cell.H" #include "bitSet.H" -#include "DynamicList.H" #include "ListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -58,51 +57,12 @@ void Foam::primitiveMesh::calcCellPoints() const << "cellPoints already calculated" << abort(FatalError); } - else if (hasPointCells()) + else { // Invert pointCells cpPtr_ = new labelListList(nCells()); invertManyToMany(nCells(), pointCells(), *cpPtr_); } - else - { - // Calculate cell-point topology - - cpPtr_ = new labelListList(nCells()); - auto& cellPointAddr = *cpPtr_; - - const cellList& cellLst = cells(); - const faceList& faceLst = faces(); - - // Tracking (only use each point id once) - bitSet usedPoints(nPoints()); - - // Vertex labels for the current cell - DynamicList<label> currPoints(256); - - const label loopLen = nCells(); - - for (label celli = 0; celli < loopLen; ++celli) - { - // Clear any previous contents - usedPoints.unset(currPoints); - currPoints.clear(); - - for (const label facei : cellLst[celli]) - { - for (const label pointi : faceLst[facei]) - { - // Only once for each point id - if (usedPoints.set(pointi)) - { - currPoints.push_back(pointi); - } - } - } - - cellPointAddr[celli] = currPoints; // NB: unsorted - } - } } diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C index a93d23360c1..853e02d6ceb 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshPointCells.C @@ -6,7 +6,6 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,13 +28,14 @@ License #include "primitiveMesh.H" #include "cell.H" #include "bitSet.H" -#include "DynamicList.H" #include "ListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::primitiveMesh::calcPointCells() const { + // Loop through cells and mark up points + if (debug) { Pout<< "primitiveMesh::calcPointCells() : " @@ -59,128 +59,48 @@ void Foam::primitiveMesh::calcPointCells() const << "pointCells already calculated" << abort(FatalError); } - else if (hasCellPoints()) - { - // Invert cellPoints - pcPtr_ = new labelListList(nPoints()); - invertManyToMany(nPoints(), cellPoints(), *pcPtr_); - } - else if (hasPointFaces()) - { - // Calculate point-cell from point-face information - - const labelList& own = faceOwner(); - const labelList& nei = faceNeighbour(); - const labelListList& pFaces = pointFaces(); - - // Tracking (only use each cell id once) - bitSet usedCells(nCells()); - - // Cell ids for the point currently being processed - DynamicList<label> currCells(256); - - const label loopLen = nPoints(); - - pcPtr_ = new labelListList(nPoints()); - auto& pointCellAddr = *pcPtr_; - - for (label pointi = 0; pointi < loopLen; ++pointi) - { - // Clear any previous contents - usedCells.unset(currCells); - currCells.clear(); - - for (const label facei : pFaces[pointi]) - { - // Owner cell - only allow one occurance - if (usedCells.set(own[facei])) - { - currCells.push_back(own[facei]); - } - - // Neighbour cell - only allow one occurance - if (facei < nInternalFaces()) - { - if (usedCells.set(nei[facei])) - { - currCells.push_back(nei[facei]); - } - } - } - - pointCellAddr[pointi] = currCells; // NB: unsorted - } - } else { - // Calculate point-cell topology - - const cellList& cellLst = cells(); - const faceList& faceLst = faces(); - - // Tracking (only use each point id once) - bitSet usedPoints(nPoints()); + const cellList& cf = cells(); - // Which of usedPoints needs to be unset [faster] - DynamicList<label> currPoints(256); + // Count number of cells per point - const label loopLen = nCells(); + labelList npc(nPoints(), Zero); - // Step 1: count number of cells per point - - labelList pointCount(nPoints(), Zero); - - for (label celli = 0; celli < loopLen; ++celli) + forAll(cf, celli) { - // Clear any previous contents - usedPoints.unset(currPoints); - currPoints.clear(); + const labelList curPoints = cf[celli].labels(faces()); - for (const label facei : cellLst[celli]) + forAll(curPoints, pointi) { - for (const label pointi : faceLst[facei]) - { - // Only once for each point id - if (usedPoints.set(pointi)) - { - currPoints.push_back(pointi); // Needed for cleanup - ++pointCount[pointi]; - } - } + label ptI = curPoints[pointi]; + + npc[ptI]++; } } - // Step 2: set sizing, reset counters + // Size and fill cells per point - pcPtr_ = new labelListList(nPoints()); - auto& pointCellAddr = *pcPtr_; + pcPtr_ = new labelListList(npc.size()); + labelListList& pointCellAddr = *pcPtr_; forAll(pointCellAddr, pointi) { - pointCellAddr[pointi].resize_nocopy(pointCount[pointi]); - pointCount[pointi] = 0; + pointCellAddr[pointi].setSize(npc[pointi]); } + npc = 0; - // Step 3: fill in values. Logic as per step 1 - for (label celli = 0; celli < loopLen; ++celli) + forAll(cf, celli) { - // Clear any previous contents - usedPoints.unset(currPoints); - currPoints.clear(); + const labelList curPoints = cf[celli].labels(faces()); - for (const label facei : cellLst[celli]) + forAll(curPoints, pointi) { - for (const label pointi : faceLst[facei]) - { - // Only once for each point id - if (usedPoints.set(pointi)) - { - currPoints.push_back(pointi); // Needed for cleanup - pointCellAddr[pointi][pointCount[pointi]++] = celli; - } - } + label ptI = curPoints[pointi]; + + pointCellAddr[ptI][npc[ptI]++] = celli; } } } @@ -234,8 +154,12 @@ const Foam::labelList& Foam::primitiveMesh::pointCells if (storage.size() > 1) { std::sort(storage.begin(), storage.end()); + auto last = std::unique(storage.begin(), storage.end()); - storage.resize(label(last - storage.begin())); + + const label newLen = label(last - storage.begin()); + + storage.resize(newLen); } return storage; -- GitLab