diff --git a/src/OpenFOAM/meshes/bandCompression/bandCompression.C b/src/OpenFOAM/meshes/bandCompression/bandCompression.C index d10984e74ac550be3f051affdabcbd71436fb447..f3dfdd16d15457c255b88fb03829ca95110745f8 100644 --- a/src/OpenFOAM/meshes/bandCompression/bandCompression.C +++ b/src/OpenFOAM/meshes/bandCompression/bandCompression.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,253 +24,311 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -Description - The function renumbers the addressing such that the band of the - matrix is reduced. The algorithm uses a simple search through the - neighbour list - - See http://en.wikipedia.org/wiki/Cuthill-McKee_algorithm - \*---------------------------------------------------------------------------*/ #include "bandCompression.H" -#include "SLList.H" -#include "IOstreams.H" -#include "DynamicList.H" -#include "ListOps.H" #include "bitSet.H" +#include "CircularBuffer.H" +#include "CompactListList.H" +#include "DynamicList.H" +#include "ListOps.H" // sortedOrder +#include "IOstreams.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // -Foam::labelList Foam::bandCompression(const labelListList& cellCellAddressing) +namespace { - labelList newOrder(cellCellAddressing.size()); - // the business bit of the renumbering - SLList<label> nextCell; +// Process connections with the Cuthill-McKee algorithm. +// The connections are CompactListList<label> or a labelListList. +template<class ConnectionListListType> +Foam::labelList cuthill_mckee_algorithm +( + const ConnectionListListType& cellCellAddressing +) +{ + using namespace Foam; - bitSet visited(cellCellAddressing.size()); + const label nOldCells(cellCellAddressing.size()); + + // Which cells are visited/unvisited + bitSet unvisited(nOldCells, true); + + // The new output order + labelList newOrder(nOldCells); - label cellInOrder = 0; + // Various work arrays + // ~~~~~~~~~~~~~~~~~~~ - // Work arrays. Kept outside of loop to minimise allocations. - // - neighbour cells - DynamicList<label> nbrs; - // - corresponding weights + // Neighbour cells + DynamicList<label> nbrCells; + + // Neighbour ordering + DynamicList<label> nbrOrder; + + // Corresponding weights for neighbour cells DynamicList<label> weights; - // - ordering - labelList order; + // FIFO buffer for renumbering. + CircularBuffer<label> queuedCells(1024); + label cellInOrder = 0; while (true) { // For a disconnected region find the lowest connected cell. + label currCelli = -1; + label minCount = labelMax; - label currentCell = -1; - label minWeight = labelMax; - - forAll(visited, celli) + for (const label celli : unvisited) { - // find the lowest connected cell that has not been visited yet - if (!visited[celli]) + const label nbrCount = cellCellAddressing[celli].size(); + + if (minCount > nbrCount) { - if (cellCellAddressing[celli].size() < minWeight) - { - minWeight = cellCellAddressing[celli].size(); - currentCell = celli; - } + minCount = nbrCount; + currCelli = celli; } } - - if (currentCell == -1) + if (currCelli == -1) { break; } - // Starting from currentCell walk breadth-first - + // Starting from currCelli - walk breadth-first - // use this cell as a start - nextCell.append(currentCell); + queuedCells.append(currCelli); - // loop through the nextCell 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 // neighbours. If the neighbour in question has not been visited, - // add it to the end of the nextCell list + // add it to the end of the queuedCells list - while (nextCell.size()) + while (!queuedCells.empty()) { - currentCell = nextCell.removeHead(); + // Process as FIFO + currCelli = queuedCells.first(); + queuedCells.pop_front(); - if (visited.set(currentCell)) + if (unvisited.test(currCelli)) { - // On first visit... + // First visit... + unvisited.unset(currCelli); - // add into cellOrder - newOrder[cellInOrder] = currentCell; - cellInOrder++; - - // find if the neighbours have been visited - const labelList& neighbours = cellCellAddressing[currentCell]; + // Add into cellOrder + newOrder[cellInOrder] = currCelli; + ++cellInOrder; // Add in increasing order of connectivity // 1. Count neighbours of unvisited neighbours - nbrs.clear(); + nbrCells.clear(); weights.clear(); - forAll(neighbours, nI) + // Find if the neighbours have been visited + const auto& neighbours = cellCellAddressing[currCelli]; + + for (const label nbr : neighbours) { - label nbr = neighbours[nI]; - if (!visited[nbr]) + const label nbrCount = cellCellAddressing[nbr].size(); + + if (unvisited.test(nbr)) { - // not visited, add to the list - nbrs.append(nbr); - weights.append(cellCellAddressing[nbr].size()); + // Not visited (or removed), add to the list + nbrCells.append(nbr); + weights.append(nbrCount); } } - // 2. Sort in ascending order - sortedOrder(weights, order); - // 3. Add in sorted order - forAll(order, i) + + // Resize DynamicList prior to sortedOrder + nbrOrder.resize_nocopy(weights.size()); + + // 2. Ascending order + Foam::sortedOrder(weights, nbrOrder); + + // 3. Add to FIFO in sorted order + for (const label nbrIdx : nbrOrder) { - nextCell.append(nbrs[i]); + queuedCells.append(nbrCells[nbrIdx]); } } } } + // Now we have new-to-old in newOrder. return newOrder; } +} // End anonymous namespace -Foam::labelList Foam::bandCompression + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::labelList Foam::meshTools::bandCompression ( - const labelList& cellCells, - const labelList& offsets + const labelUList& cellCells, + const labelUList& offsets ) { + // Protect against zero-sized offset list + const label nOldCells = max(0, (offsets.size()-1)); + // Count number of neighbours - labelList numNbrs(offsets.size()-1, Zero); - forAll(numNbrs, celli) + labelList numNbrs(nOldCells, Zero); + for (label celli = 0; celli < nOldCells; ++celli) { - label start = offsets[celli]; - label end = offsets[celli+1]; + const label beg = offsets[celli]; + const label end = offsets[celli+1]; - for (label facei = start; facei < end; facei++) + for (label idx = beg; idx < end; ++idx) { - numNbrs[celli]++; - numNbrs[cellCells[facei]]++; + ++numNbrs[celli]; + ++numNbrs[cellCells[idx]]; } } - labelList newOrder(offsets.size()-1); + // Which cells are visited/unvisited + bitSet unvisited(nOldCells, true); - // the business bit of the renumbering - SLList<label> nextCell; + // The new output order + labelList newOrder(nOldCells); - bitSet visited(offsets.size()-1); - label cellInOrder = 0; + // Various work arrays + // ~~~~~~~~~~~~~~~~~~~ + + // Neighbour cells + DynamicList<label> nbrCells; + // Neighbour ordering + DynamicList<label> nbrOrder; - // Work arrays. Kept outside of loop to minimise allocations. - // - neighbour cells - DynamicList<label> nbrs; - // - corresponding weights + // Corresponding weights for neighbour cells DynamicList<label> weights; - // - ordering - labelList order; + // FIFO buffer for renumbering. + CircularBuffer<label> queuedCells(1024); + label cellInOrder = 0; + while (true) { - // For a disconnected region find the lowest connected cell. + // Find lowest connected cell that has not been visited yet + label currCelli = -1; + label minCount = labelMax; - label currentCell = -1; - label minWeight = labelMax; - - forAll(visited, celli) + for (const label celli : unvisited) { - // find the lowest connected cell that has not been visited yet - if (!visited[celli]) + const label nbrCount = numNbrs[celli]; + + if (minCount > nbrCount) { - if (numNbrs[celli] < minWeight) - { - minWeight = numNbrs[celli]; - currentCell = celli; - } + minCount = nbrCount; + currCelli = celli; } } - - if (currentCell == -1) + if (currCelli == -1) { break; } - // Starting from currentCell walk breadth-first - + // Starting from currCellii - walk breadth-first - // use this cell as a start - nextCell.append(currentCell); + queuedCells.append(currCelli); // loop through the nextCell list. Add the first cell into the // cell order if it has not already been visited and ask for its // neighbours. If the neighbour in question has not been visited, // add it to the end of the nextCell list - while (nextCell.size()) + // Loop through queuedCells list. Add the first cell into the + // cell order if it has not already been visited and ask for its + // neighbours. If the neighbour in question has not been visited, + // add it to the end of the queuedCells list + + while (!queuedCells.empty()) { - currentCell = nextCell.removeHead(); + // Process as FIFO + currCelli = queuedCells.first(); + queuedCells.pop_front(); - if (!visited[currentCell]) + if (unvisited.test(currCelli)) { - visited.set(currentCell); + // First visit... + unvisited.unset(currCelli); - // add into cellOrder - newOrder[cellInOrder] = currentCell; - cellInOrder++; + // Add into cellOrder + newOrder[cellInOrder] = currCelli; + ++cellInOrder; // Add in increasing order of connectivity // 1. Count neighbours of unvisited neighbours - nbrs.clear(); + nbrCells.clear(); weights.clear(); - label start = offsets[currentCell]; - label end = offsets[currentCell+1]; + const label beg = offsets[currCelli]; + const label end = offsets[currCelli+1]; - for (label facei = start; facei < end; facei++) + for (label idx = beg; idx < end; ++idx) { - label nbr = cellCells[facei]; - if (!visited[nbr]) + const label nbr = cellCells[idx]; + const label nbrCount = numNbrs[nbr]; + + if (unvisited.test(nbr)) { - // not visited, add to the list - nbrs.append(nbr); - weights.append(numNbrs[nbr]); + // Not visited (or removed), add to the list + nbrCells.append(nbr); + weights.append(nbrCount); } } - // 2. Sort in ascending order - sortedOrder(weights, order); - // 3. Add in sorted order - forAll(order, i) + + // Resize DynamicList prior to sortedOrder + nbrOrder.resize_nocopy(weights.size()); + + // 2. Ascending order + Foam::sortedOrder(weights, nbrOrder); + + // 3. Add to FIFO in sorted order + for (const label nbrIdx : nbrOrder) { - nextCell.append(nbrs[i]); + queuedCells.append(nbrCells[nbrIdx]); } } } } + // Now we have new-to-old in newOrder. + return newOrder; } +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +Foam::labelList Foam::meshTools::bandCompression +( + const CompactListList<label>& cellCellAddressing +) +{ + return cuthill_mckee_algorithm(cellCellAddressing); +} + + +Foam::labelList Foam::meshTools::bandCompression +( + const labelListList& cellCellAddressing +) +{ + return cuthill_mckee_algorithm(cellCellAddressing); +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/bandCompression/bandCompression.H b/src/OpenFOAM/meshes/bandCompression/bandCompression.H index 8bf698e305d29c68f5139c045303ca53507ecf73..805a0783bfcb5ff4fdecdf1c17343bb3dd194607 100644 --- a/src/OpenFOAM/meshes/bandCompression/bandCompression.H +++ b/src/OpenFOAM/meshes/bandCompression/bandCompression.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2013 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,15 +31,16 @@ Description The bandCompression function renumbers the addressing such that the band of the matrix is reduced. The algorithm uses a simple search through the neighbour list in order of connectivity. - (CutHill-McKee algorithm) + + See http://en.wikipedia.org/wiki/Cuthill-McKee_algorithm SourceFiles bandCompression.C \*---------------------------------------------------------------------------*/ -#ifndef bandCompression_H -#define bandCompression_H +#ifndef Foam_bandCompression_H +#define Foam_bandCompression_H #include "labelList.H" @@ -47,17 +49,72 @@ SourceFiles namespace Foam { -//- Renumbers the addressing to reduce the band of the matrix. -// The algorithm uses a simple search through the neighbour list -// Returns the order in which the cells need to be visited (i.e. ordered to -// original) +// Forward Declarations +template<class T> class CompactListList; + +} // End namespace Foam + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace meshTools +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Renumber (mesh) addressing to reduce the band of the matrix, +//- using the Cuthill-McKee algorithm. +// +// \returns order in which the cells are to be visited (ordered to original) +labelList bandCompression(const CompactListList<label>& addressing); + +//- Renumber (mesh) addressing to reduce the band of the matrix, +//- using the Cuthill-McKee algorithm. +// +// \returns order in which the cells are to be visited (ordered to original) labelList bandCompression(const labelListList& addressing); -//- Renumber with addressing in losort form (neighbour + start in neighbour) -labelList bandCompression(const labelList& cellCells, const labelList& offsets); +//- Renumber with addressing in losort form (neighbour + start in neighbour), +//- using the Cuthill-McKee algorithm. +// +// \returns order in which the cells are to be visited (ordered to original) +labelList bandCompression +( + const labelUList& cellCells, + const labelUList& offsets +); + +} // End namespace meshTools } // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +//- Forward to meshTools::bandCompression +inline labelList bandCompression(const labelListList& cellCellAddressing) +{ + return meshTools::bandCompression(cellCellAddressing); +} + +//- Forward to meshTools::bandCompression +inline labelList bandCompression +( + const labelUList& cellCells, + const labelUList& offsets +) +{ + return meshTools::bandCompression(cellCells, offsets); +} + +} // End namespace Foam + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C index 20b72272ea84c50ca1a19e21ab0adafd40e228e2..97add49b7a57de340f9110dd1afcd8788db7b91b 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchPointAddressing.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -30,7 +30,7 @@ Description \*---------------------------------------------------------------------------*/ #include "PrimitivePatch.H" -#include "SLList.H" +#include "DynamicList.H" #include "ListOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -73,10 +73,10 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointFaces() const << abort(FatalError); } - const List<face_type>& locFcs = localFaces(); + // Local storage while creating pointFaces + List<DynamicList<label>> pointFcs(meshPoints().size()); - // set up storage for pointFaces - List<SLList<label>> pointFcs(meshPoints().size()); + const List<face_type>& locFcs = localFaces(); forAll(locFcs, facei) { @@ -86,13 +86,13 @@ Foam::PrimitivePatch<FaceList, PointField>::calcPointFaces() const } } - // Copy the list + // Copy the lists, recovering content pointFacesPtr_.reset(new labelListList(pointFcs.size())); auto& pf = *pointFacesPtr_; forAll(pointFcs, pointi) { - pf[pointi] = pointFcs[pointi]; + pf[pointi].transfer(pointFcs[pointi]); } DebugInfo << " Finished." << endl; diff --git a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchProjectPoints.C b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchProjectPoints.C index 7ca7f5d079ca4363bc71e40ec81ddd55d63408f5..658bb7b5c3033ee00f01ebfeda34887f58134f85 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchProjectPoints.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PrimitivePatch/PrimitivePatchProjectPoints.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -293,7 +293,7 @@ Foam::PrimitivePatch<FaceList, PointField>::projectFaceCentres << abort(FatalError); } - labelList slaveFaceOrder = bandCompression(faceFaces()); + labelList slaveFaceOrder = meshTools::bandCompression(faceFaces()); // calculate master face centres Field<point_type> masterFaceCentres(targetPatch.size()); diff --git a/src/meshTools/polyTopoChange/polyTopoChange.C b/src/meshTools/polyTopoChange/polyTopoChange.C index 58a49e98dd63f5ead8e3908637591a81e97d0767..c641cce3401ceaa4012436dcd3e2fdd29ab85df9 100644 --- a/src/meshTools/polyTopoChange/polyTopoChange.C +++ b/src/meshTools/polyTopoChange/polyTopoChange.C @@ -37,10 +37,11 @@ License #include "polyAddCell.H" #include "polyModifyCell.H" #include "polyRemoveCell.H" +#include "CircularBuffer.H" #include "CompactListList.H" #include "objectMap.H" #include "processorPolyPatch.H" -#include "ListOps.H" +#include "ListOps.H" // sortedOrder #include "mapPolyMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -588,111 +589,130 @@ Foam::label Foam::polyTopoChange::getCellOrder labelList& oldToNew ) const { - labelList newOrder(cellCellAddressing.size()); + const label nOldCells(cellCellAddressing.size()); - // Fifo buffer for string of cells - SLList<label> nextCell; + // Which cells are visited/unvisited + bitSet unvisited(nOldCells, true); - // Whether cell has been done already - bitSet visited(cellCellAddressing.size()); + // Exclude removed cells + for (label celli = 0; celli < nOldCells; ++celli) + { + if (cellRemoved(celli)) + { + unvisited.unset(celli); + } + } + + // The new output order + labelList newOrder(unvisited.count()); - label cellInOrder = 0; + // Various work arrays + // ~~~~~~~~~~~~~~~~~~~ - // Work arrays. Kept outside of loop to minimise allocations. - // - neighbour cells - DynamicList<label> nbrs; - // - corresponding weights + //- Neighbour cells + DynamicList<label> nbrCells; + + //- Neighbour ordering + DynamicList<label> nbrOrder; + + //- Corresponding weights for neighbour cells DynamicList<label> weights; - // - ordering - labelList order; + // FIFO buffer for renumbering. + CircularBuffer<label> queuedCells(1024); + label cellInOrder = 0; + while (true) { // For a disconnected region find the lowest connected cell. + label currCelli = -1; + label minCount = labelMax; - label currentCell = -1; - label minWeight = labelMax; - - forAll(visited, celli) + for (const label celli : unvisited) { - // find the lowest connected cell that has not been visited yet - if (!cellRemoved(celli) && !visited.test(celli)) + const label nbrCount = cellCellAddressing[celli].size(); + + if (minCount > nbrCount) { - if (cellCellAddressing[celli].size() < minWeight) - { - minWeight = cellCellAddressing[celli].size(); - currentCell = celli; - } + minCount = nbrCount; + currCelli = celli; } } - - if (currentCell == -1) + if (currCelli == -1) { break; } - // Starting from currentCell walk breadth-first + // Starting from currCelli - walk breadth-first + queuedCells.append(currCelli); - // use this cell as a start - nextCell.append(currentCell); - - // loop through the nextCell 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 // neighbours. If the neighbour in question has not been visited, - // add it to the end of the nextCell list + // add it to the end of the queuedCells list - while (nextCell.size()) + while (!queuedCells.empty()) { - currentCell = nextCell.removeHead(); + // Process as FIFO + currCelli = queuedCells.first(); + queuedCells.pop_front(); - if (visited.set(currentCell)) + if (unvisited.test(currCelli)) { - // On first visit... + // First visit... + unvisited.unset(currCelli); - // add into cellOrder - newOrder[cellInOrder] = currentCell; - cellInOrder++; + // Add into cellOrder + newOrder[cellInOrder] = currCelli; + ++cellInOrder; - // find if the neighbours have been visited - const labelUList neighbours = cellCellAddressing[currentCell]; + // Find if the neighbours have been visited + const auto& neighbours = cellCellAddressing[currCelli]; // Add in increasing order of connectivity // 1. Count neighbours of unvisited neighbours - nbrs.clear(); + nbrCells.clear(); weights.clear(); for (const label nbr : neighbours) { - if (!cellRemoved(nbr) && !visited.test(nbr)) + const label nbrCount = cellCellAddressing[nbr].size(); + + if (unvisited.test(nbr)) { - // not visited, add to the list - nbrs.append(nbr); - weights.append(cellCellAddressing[nbr].size()); + // Not visited (or removed), add to the list + nbrCells.append(nbr); + weights.append(nbrCount); } } - // 2. Sort - sortedOrder(weights, order); - // 3. Add in sorted order - for (const label nbri : order) + + // Resize DynamicList prior to sortedOrder + nbrOrder.resize_nocopy(weights.size()); + + // 2. Ascending order + Foam::sortedOrder(weights, nbrOrder); + + // 3. Add to FIFO in sorted order + for (const label nbrIdx : nbrOrder) { - nextCell.append(nbrs[nbri]); + queuedCells.append(nbrCells[nbrIdx]); } } } } // Now we have new-to-old in newOrder. - newOrder.setSize(cellInOrder); + newOrder.resize(cellInOrder); // Extra safety, but should be a no-op // Invert to get old-to-new. Make sure removed (i.e. unmapped) cells are -1. - oldToNew = invert(cellCellAddressing.size(), newOrder); + oldToNew = invert(nOldCells, newOrder); return cellInOrder; } diff --git a/src/renumber/SloanRenumber/SloanRenumber.C b/src/renumber/SloanRenumber/SloanRenumber.C index 374a411520b3d6385fbb17c919391b7ab9465948..04b8f265ca7dbc118918654bf5a18a4e95535ff0 100644 --- a/src/renumber/SloanRenumber/SloanRenumber.C +++ b/src/renumber/SloanRenumber/SloanRenumber.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2020-2021 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,7 +47,6 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // using namespace boost; -using namespace std; //Defining the graph type typedef adjacency_list @@ -90,19 +89,68 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::SloanRenumber::SloanRenumber(const dictionary& renumberDict) +Foam::SloanRenumber::SloanRenumber(const dictionary& dict) : - renumberMethod(renumberDict), + renumberMethod(dict), reverse_ ( - renumberDict.optionalSubDict - ( - typeName + "Coeffs" - ).getOrDefault("reverse", false) + dict.optionalSubDict(typeName + "Coeffs") + .getOrDefault("reverse", false) ) {} +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace +{ + +Foam::labelList renumberImpl(Graph& G, const bool useReverse) +{ + using namespace Foam; + + //Creating two iterators over the vertices + graph_traits<Graph>::vertex_iterator ui, ui_end; + + //Creating a property_map with the degrees of the degrees of each vertex + property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G); + for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) + { + deg[*ui] = degree(*ui, G); + } + + //Creating a property_map for the indices of a vertex + property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G); + + //Creating a vector of vertices + std::vector<Vertex> sloan_order(num_vertices(G)); + + sloan_ordering + ( + G, + sloan_order.begin(), + get(vertex_color, G), + make_degree_map(G), + get(vertex_priority, G) + ); + + labelList orderedToOld(sloan_order.size()); + forAll(orderedToOld, c) + { + orderedToOld[c] = index_map[sloan_order[c]]; + } + + if (useReverse) + { + Foam::reverse(orderedToOld); + } + + return orderedToOld; +} + +} // End anonymous namespace + + // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::labelList Foam::SloanRenumber::renumber @@ -132,6 +180,7 @@ Foam::labelList Foam::SloanRenumber::renumber { add_edge(mesh.faceOwner()[facei], mesh.faceNeighbour()[facei], G); } + // Add cyclics for (const polyPatch& pp : mesh.boundaryMesh()) { @@ -161,100 +210,57 @@ Foam::labelList Foam::SloanRenumber::renumber } } + return renumberImpl(G, reverse_); +} - //Creating two iterators over the vertices - graph_traits<Graph>::vertex_iterator ui, ui_end; - - //Creating a property_map with the degrees of the degrees of each vertex - property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G); - for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) - deg[*ui] = degree(*ui, G); - - //Creating a property_map for the indices of a vertex - property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G); - - //Creating a vector of vertices - std::vector<Vertex> sloan_order(num_vertices(G)); - sloan_ordering - ( - G, - sloan_order.begin(), - get(vertex_color, G), - make_degree_map(G), - get(vertex_priority, G) - ); +Foam::labelList Foam::SloanRenumber::renumber +( + const CompactListList<label>& cellCells, + const pointField& +) const +{ + Graph G(cellCells.size()); - labelList orderedToOld(sloan_order.size()); - forAll(orderedToOld, c) + forAll(cellCells, celli) { - orderedToOld[c] = index_map[sloan_order[c]]; - } + const auto& neighbours = cellCells[celli]; - if (reverse_) - { - reverse(orderedToOld); + for (const label nbr : neighbours) + { + if (celli < nbr) + { + add_edge(celli, nbr, G); + } + } } - return orderedToOld; + return renumberImpl(G, reverse_); } Foam::labelList Foam::SloanRenumber::renumber ( const labelListList& cellCells, - const pointField& points + const pointField& ) const { Graph G(cellCells.size()); forAll(cellCells, celli) { - const labelList& nbrs = cellCells[celli]; - forAll(nbrs, i) + const auto& neighbours = cellCells[celli]; + + for (const label nbr : neighbours) { - if (nbrs[i] > celli) + if (celli < nbr) { - add_edge(celli, nbrs[i], G); + add_edge(celli, nbr, G); } } } - //Creating two iterators over the vertices - graph_traits<Graph>::vertex_iterator ui, ui_end; - - //Creating a property_map with the degrees of the degrees of each vertex - property_map<Graph,vertex_degree_t>::type deg = get(vertex_degree, G); - for (boost::tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) - deg[*ui] = degree(*ui, G); - - //Creating a property_map for the indices of a vertex - property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G); - - //Creating a vector of vertices - std::vector<Vertex> sloan_order(num_vertices(G)); - - sloan_ordering - ( - G, - sloan_order.begin(), - get(vertex_color, G), - make_degree_map(G), - get(vertex_priority, G) - ); - - labelList orderedToOld(sloan_order.size()); - forAll(orderedToOld, c) - { - orderedToOld[c] = index_map[sloan_order[c]]; - } - - if (reverse_) - { - reverse(orderedToOld); - } - - return orderedToOld; + return renumberImpl(G, reverse_); } diff --git a/src/renumber/SloanRenumber/SloanRenumber.H b/src/renumber/SloanRenumber/SloanRenumber.H index 2c55ece530372ef2d0171256d8563781757637f4..7f61b3912bb7915cdd77930a21e11488dc612f3c 100644 --- a/src/renumber/SloanRenumber/SloanRenumber.H +++ b/src/renumber/SloanRenumber/SloanRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,11 +37,10 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef SloanRenumber_H -#define SloanRenumber_H +#ifndef Foam_SloanRenumber_H +#define Foam_SloanRenumber_H #include "renumberMethod.H" -#include "Switch.H" namespace Foam { @@ -53,7 +53,7 @@ class SloanRenumber : public renumberMethod { - // Private data + // Private Data const bool reverse_; @@ -76,7 +76,7 @@ public: // Constructors //- Construct given the renumber dictionary - SloanRenumber(const dictionary& renumberDict); + explicit SloanRenumber(const dictionary& dict); //- Destructor @@ -85,17 +85,17 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber ( @@ -103,8 +103,16 @@ public: const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres + ) const; + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // The connectivity is equal to mesh.cellCells() except // - the connections are across coupled patches virtual labelList renumber diff --git a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C index d404f93dae23c341b7c21254ce4311e90eb02c39..fe8bcc29368de039345fb2f69546aa3f96f446d5 100644 --- a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C +++ b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.C @@ -48,15 +48,13 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::CuthillMcKeeRenumber::CuthillMcKeeRenumber(const dictionary& renumberDict) +Foam::CuthillMcKeeRenumber::CuthillMcKeeRenumber(const dictionary& dict) : - renumberMethod(renumberDict), + renumberMethod(dict), reverse_ ( - renumberDict.optionalSubDict - ( - typeName + "Coeffs" - ).getOrDefault("reverse", false) + dict.optionalSubDict(typeName + "Coeffs") + .getOrDefault("reverse", false) ) {} @@ -79,7 +77,7 @@ Foam::labelList Foam::CuthillMcKeeRenumber::renumber cellCells ); - labelList orderedToOld = bandCompression(cellCells.unpack()); + labelList orderedToOld = meshTools::bandCompression(cellCells); if (reverse_) { @@ -97,7 +95,24 @@ Foam::labelList Foam::CuthillMcKeeRenumber::renumber const pointField& cc ) const { - labelList orderedToOld = bandCompression(cellCells, offsets); + labelList orderedToOld = meshTools::bandCompression(cellCells, offsets); + + if (reverse_) + { + reverse(orderedToOld); + } + + return orderedToOld; +} + + +Foam::labelList Foam::CuthillMcKeeRenumber::renumber +( + const CompactListList<label>& cellCells, + const pointField& cc +) const +{ + labelList orderedToOld = meshTools::bandCompression(cellCells); if (reverse_) { @@ -114,7 +129,7 @@ Foam::labelList Foam::CuthillMcKeeRenumber::renumber const pointField& points ) const { - labelList orderedToOld = bandCompression(cellCells); + labelList orderedToOld = meshTools::bandCompression(cellCells); if (reverse_) { diff --git a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H index aabe31271e87daa95bf3e15406e200c2265935cd..fd6df4cc2755674883396c88dca9f9c2e5cce453 100644 --- a/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H +++ b/src/renumber/renumberMethods/CuthillMcKeeRenumber/CuthillMcKeeRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,11 +35,10 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef CuthillMcKeeRenumber_H -#define CuthillMcKeeRenumber_H +#ifndef Foam_CuthillMcKeeRenumber_H +#define Foam_CuthillMcKeeRenumber_H #include "renumberMethod.H" -#include "Switch.H" namespace Foam { @@ -51,7 +51,7 @@ class CuthillMcKeeRenumber : public renumberMethod { - // Private data + // Private Data const bool reverse_; @@ -74,7 +74,7 @@ public: // Constructors //- Construct given the renumber dictionary - CuthillMcKeeRenumber(const dictionary& renumberDict); + explicit CuthillMcKeeRenumber(const dictionary& dict); //- Destructor @@ -83,17 +83,17 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber ( @@ -101,8 +101,8 @@ public: const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Connectivity in losort addressing (= neighbour + offsets into // neighbour) virtual labelList renumber @@ -112,14 +112,22 @@ public: const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres + ) const; + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // The connectivity is equal to mesh.cellCells() except // - the connections are across coupled patches virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const; }; diff --git a/src/renumber/renumberMethods/manualRenumber/manualRenumber.C b/src/renumber/renumberMethods/manualRenumber/manualRenumber.C index 146bf729b5a0897e9ebff0281e0b07e1d952f37f..c537d7fa53ab5b92dd5d0333d7ef523542d288de 100644 --- a/src/renumber/renumberMethods/manualRenumber/manualRenumber.C +++ b/src/renumber/renumberMethods/manualRenumber/manualRenumber.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,13 +48,12 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::manualRenumber::manualRenumber(const dictionary& renumberDict) +Foam::manualRenumber::manualRenumber(const dictionary& dict) : - renumberMethod(renumberDict), + renumberMethod(dict), dataFile_ ( - renumberDict.optionalSubDict(typeName+"Coeffs") - .get<fileName>("dataFile") + dict.optionalSubDict(typeName+"Coeffs").get<fileName>("dataFile") ) {} diff --git a/src/renumber/renumberMethods/manualRenumber/manualRenumber.H b/src/renumber/renumberMethods/manualRenumber/manualRenumber.H index 77d8dfcd205af890ed473d801af730719fc9c2e7..f6dbb1abf5aaa6ac950779bf88464dc603159752 100644 --- a/src/renumber/renumberMethods/manualRenumber/manualRenumber.H +++ b/src/renumber/renumberMethods/manualRenumber/manualRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef manualRenumber_H -#define manualRenumber_H +#ifndef Foam_manualRenumber_H +#define Foam_manualRenumber_H #include "renumberMethod.H" @@ -50,9 +51,9 @@ class manualRenumber : public renumberMethod { - // Private data + // Private Data - const fileName dataFile_; + fileName dataFile_; // Private Member Functions @@ -72,7 +73,7 @@ public: // Constructors //- Construct given the renumber dictionary - manualRenumber(const dictionary& renumberDict); + explicit manualRenumber(const dictionary& dict); //- Destructor @@ -81,36 +82,45 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // This is only defined for geometric renumberMethods. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // Use the mesh connectivity (if needed) + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + // Uses mesh for regIOobject virtual labelList renumber ( const polyMesh& mesh, const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // The connectivity is equal to mesh.cellCells() except - // - the connections are across coupled patches + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres + ) const + { + NotImplemented; + return labelList(); + } + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const { NotImplemented; - return labelList(0); + return labelList(); } }; diff --git a/src/renumber/renumberMethods/randomRenumber/randomRenumber.C b/src/renumber/renumberMethods/randomRenumber/randomRenumber.C index 8b18ecdf18cd4ef40442d0ea923a2bae96fef198..a18be4d3c8d424f0d0b5ab6d90f00c9c28fcc7a1 100644 --- a/src/renumber/renumberMethods/randomRenumber/randomRenumber.C +++ b/src/renumber/renumberMethods/randomRenumber/randomRenumber.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation - Copyright (C) 2021 OpenCFD Ltd. + Copyright (C) 2021-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,8 +27,8 @@ License \*---------------------------------------------------------------------------*/ #include "randomRenumber.H" -#include "addToRunTimeSelectionTable.H" #include "Random.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -47,9 +47,9 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::randomRenumber::randomRenumber(const dictionary& renumberDict) +Foam::randomRenumber::randomRenumber(const dictionary& dict) : - renumberMethod(renumberDict) + renumberMethod(dict) {} @@ -86,6 +86,16 @@ Foam::labelList Foam::randomRenumber::renumber } +Foam::labelList Foam::randomRenumber::renumber +( + const CompactListList<label>& cellCells, + const pointField& points +) const +{ + return renumber(points); +} + + Foam::labelList Foam::randomRenumber::renumber ( const labelListList& cellCells, diff --git a/src/renumber/renumberMethods/randomRenumber/randomRenumber.H b/src/renumber/renumberMethods/randomRenumber/randomRenumber.H index 15ee4de2db1b85fd9ebff5f8c7b40422bc8fdcbb..233a98638c6f5f14864f11aa28ba6cac6cf404dc 100644 --- a/src/renumber/renumberMethods/randomRenumber/randomRenumber.H +++ b/src/renumber/renumberMethods/randomRenumber/randomRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2012 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef randomRenumber_H -#define randomRenumber_H +#ifndef Foam_randomRenumber_H +#define Foam_randomRenumber_H #include "renumberMethod.H" @@ -68,7 +69,7 @@ public: // Constructors //- Construct given the renumber dictionary - randomRenumber(const dictionary& renumberDict); + explicit randomRenumber(const dictionary& dict); //- Destructor @@ -77,28 +78,28 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // This is only defined for geometric renumberMethods. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber(const pointField&) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // Use the mesh connectivity (if needed) + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber(const polyMesh&, const pointField&) const; + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber ( - const polyMesh& mesh, - const pointField& cc + const CompactListList<label>& cellCells, + const pointField& cellCentres ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // The connectivity is equal to mesh.cellCells() except - // - the connections are across coupled patches + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const; }; diff --git a/src/renumber/renumberMethods/renumberMethod/renumberMethod.C b/src/renumber/renumberMethods/renumberMethod/renumberMethod.C index 934c04c19c927469b5fd2e91d7080c7b7c58c531..3c2b1acf34a4f6596a2347bddb9a5217c167501b 100644 --- a/src/renumber/renumberMethods/renumberMethod/renumberMethod.C +++ b/src/renumber/renumberMethods/renumberMethod/renumberMethod.C @@ -24,9 +24,6 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. -InClass - renumberMethod - \*---------------------------------------------------------------------------*/ #include "renumberMethod.H" @@ -40,7 +37,7 @@ namespace Foam defineRunTimeSelectionTable(renumberMethod, dictionary); } -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // Foam::autoPtr<Foam::renumberMethod> Foam::renumberMethod::New ( @@ -68,6 +65,8 @@ Foam::autoPtr<Foam::renumberMethod> Foam::renumberMethod::New } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + Foam::labelList Foam::renumberMethod::renumber ( const polyMesh& mesh, @@ -84,7 +83,16 @@ Foam::labelList Foam::renumberMethod::renumber cellCells ); - // Renumber based on agglomerated points + return renumber(cellCells, points); +} + + +Foam::labelList Foam::renumberMethod::renumber +( + const CompactListList<label>& cellCells, + const pointField& points +) const +{ return renumber(cellCells.unpack(), points); } @@ -121,11 +129,7 @@ Foam::labelList Foam::renumberMethod::renumber // Renumber based on agglomerated points labelList coarseDistribution ( - renumber - ( - coarseCellCells.unpack(), - coarsePoints - ) + renumber(coarseCellCells, coarsePoints) ); // Rework back into renumbering for original mesh_ diff --git a/src/renumber/renumberMethods/renumberMethod/renumberMethod.H b/src/renumber/renumberMethods/renumberMethod/renumberMethod.H index 46dc5d43468edf53f5cc9518b7d5270030eaaea7..bc23c854041a001e731a93ba7eed4a99d9c3830b 100644 --- a/src/renumber/renumberMethods/renumberMethod/renumberMethod.H +++ b/src/renumber/renumberMethods/renumberMethod/renumberMethod.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef renumberMethod_H -#define renumberMethod_H +#ifndef Foam_renumberMethod_H +#define Foam_renumberMethod_H #include "polyMesh.H" #include "pointField.H" @@ -98,9 +99,9 @@ public: // Constructors //- Construct given the renumber dictionary - renumberMethod(const dictionary& renumberDict) + explicit renumberMethod(const dictionary& dict) : - renumberDict_(renumberDict) + renumberDict_(dict) {} @@ -110,8 +111,8 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { @@ -119,13 +120,13 @@ public: return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber(const polyMesh&, const pointField&) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Addressing in losort addressing (= neighbour + offsets into // neighbour) virtual labelList renumber @@ -135,8 +136,8 @@ public: const pointField& ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Gets passed agglomeration map (from fine to coarse cells) and coarse // cell // location. Can be overridden by renumberMethods that provide this @@ -146,20 +147,28 @@ public: virtual labelList renumber ( const polyMesh& mesh, - const labelList& cellToRegion, - const pointField& regionPoints + const labelList& fineToCoarse, + const pointField& coarsePoints ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + // Uses 'unpack' internally, so should be overloaded when possible + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres + ) const; + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // The connectivity is equal to mesh.cellCells() except // - the connections are across coupled patches virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const = 0; - }; diff --git a/src/renumber/renumberMethods/springRenumber/springRenumber.C b/src/renumber/renumberMethods/springRenumber/springRenumber.C index 9078f4bc3e9412b5cbd4a30cc7f93b6a5d06a8e1..ce6370649ff622d3de9f5291ed22692b236b3b1c 100644 --- a/src/renumber/renumberMethods/springRenumber/springRenumber.C +++ b/src/renumber/renumberMethods/springRenumber/springRenumber.C @@ -47,58 +47,43 @@ namespace Foam // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::springRenumber::springRenumber(const dictionary& renumberDict) +Foam::springRenumber::springRenumber(const dictionary& dict) : - renumberMethod(renumberDict), - dict_(renumberDict.optionalSubDict(typeName+"Coeffs")), - maxCo_(dict_.get<scalar>("maxCo")), - maxIter_(dict_.get<label>("maxIter")), - freezeFraction_(dict_.get<scalar>("freezeFraction")) + renumberMethod(dict), + coeffsDict_(dict.optionalSubDict(typeName+"Coeffs")), + maxIter_(coeffsDict_.get<label>("maxIter")), + maxCo_(coeffsDict_.get<scalar>("maxCo")), + freezeFraction_(coeffsDict_.get<scalar>("freezeFraction")) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::labelList Foam::springRenumber::renumber +template<class ConnectionListListType> +Foam::labelList Foam::springRenumber::renumberImpl ( - const polyMesh& mesh, - const pointField& points + const ConnectionListListType& cellCells ) const { - CompactListList<label> cellCells; - decompositionMethod::calcCellCells - ( - mesh, - identity(mesh.nCells()), - mesh.nCells(), - false, // local only - cellCells - ); - - return renumber(cellCells.unpack(), points); -} - + const label nOldCells(cellCells.size()); -Foam::labelList Foam::springRenumber::renumber -( - const labelListList& cellCells, - const pointField& points -) const -{ // Look at cell index as a 1D position parameter. // Move cells to the average 'position' of their neighbour. - scalarField position(cellCells.size()); + scalarField position(nOldCells); forAll(position, celli) { position[celli] = celli; } - labelList oldToNew(identity(cellCells.size())); + // Sum force per cell. Also reused for the displacement + scalarField sumForce(nOldCells); + + labelList oldToNew(identity(nOldCells)); - scalar maxCo = maxCo_ * cellCells.size(); + scalar maxCo = (maxCo_ * nOldCells); - for (label iter = 0; iter < maxIter_; iter++) + for (label iter = 0; iter < maxIter_; ++iter) { //Pout<< "Iteration : " << iter << nl // << "------------" @@ -111,15 +96,15 @@ Foam::labelList Foam::springRenumber::renumber // << endl; // Sum force per cell. - scalarField sumForce(cellCells.size(), Zero); - forAll(cellCells, oldCelli) + sumForce = Zero; + for (label oldCelli = 0; oldCelli < nOldCells; ++oldCelli) { - const labelList& cCells = cellCells[oldCelli]; - label celli = oldToNew[oldCelli]; + const label celli = oldToNew[oldCelli]; + const auto& neighbours = cellCells[oldCelli]; - forAll(cCells, i) + for (const label nbr : neighbours) { - label nbrCelli = oldToNew[cCells[i]]; + const label nbrCelli = oldToNew[nbr]; sumForce[celli] += (position[nbrCelli]-position[celli]); } @@ -140,8 +125,9 @@ Foam::labelList Foam::springRenumber::renumber << " deltaT:" << deltaT << " average force:" << average(mag(sumForce)) << endl; - // Determine displacement. - scalarField displacement(deltaT*sumForce); + // Determine displacement + scalarField& displacement = sumForce; + displacement *= deltaT; //Pout<< "Displacement :" << nl // << " min : " << min(displacement) << nl @@ -167,7 +153,47 @@ Foam::labelList Foam::springRenumber::renumber // Reorder oldToNew inplaceReorder(shuffle, oldToNew); - return invert(oldToNew.size(), oldToNew); + return invert(nOldCells, oldToNew); +} + + +Foam::labelList Foam::springRenumber::renumber +( + const polyMesh& mesh, + const pointField& +) const +{ + CompactListList<label> cellCells; + decompositionMethod::calcCellCells + ( + mesh, + identity(mesh.nCells()), + mesh.nCells(), + false, // local only + cellCells + ); + + return renumberImpl(cellCells); +} + + +Foam::labelList Foam::springRenumber::renumber +( + const CompactListList<label>& cellCells, + const pointField& +) const +{ + return renumberImpl(cellCells); +} + + +Foam::labelList Foam::springRenumber::renumber +( + const labelListList& cellCells, + const pointField& +) const +{ + return renumberImpl(cellCells); } diff --git a/src/renumber/renumberMethods/springRenumber/springRenumber.H b/src/renumber/renumberMethods/springRenumber/springRenumber.H index 9dee17978e06eaf3b40f02dacecf12a0089b7839..c7e6ae4f9e9e47e4840c21d59fa693312ebc1f2a 100644 --- a/src/renumber/renumberMethods/springRenumber/springRenumber.H +++ b/src/renumber/renumberMethods/springRenumber/springRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,8 +46,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef springRenumber_H -#define springRenumber_H +#ifndef Foam_springRenumber_H +#define Foam_springRenumber_H #include "renumberMethod.H" @@ -61,18 +62,27 @@ class springRenumber : public renumberMethod { - // Private data + // Private Data - const dictionary& dict_; - - const scalar maxCo_; + const dictionary& coeffsDict_; const label maxIter_; + const scalar maxCo_; + const scalar freezeFraction_; + // Private Member Functions + //- The spring renumber implementation. + // The connections are CompactListList<label> or a labelListList. + template<class ConnectionListListType> + labelList renumberImpl + ( + const ConnectionListListType& cellCellAddressing + ) const; + //- No copy construct springRenumber(const springRenumber&) = delete; @@ -89,7 +99,7 @@ public: // Constructors //- Construct given the renumber dictionary - springRenumber(const dictionary& renumberDict); + explicit springRenumber(const dictionary& dict); //- Destructor @@ -98,32 +108,40 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber ( const polyMesh& mesh, - const pointField& cc + const pointField& + ) const; + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // The connectivity is equal to mesh.cellCells() except // - the connections are across coupled patches virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const; }; diff --git a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C index f3d7c8f061af96e185b882143814e320b3dfc1d1..e94aa0406b1f71271a0e6e6910810ee599303e50 100644 --- a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C +++ b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.C @@ -51,16 +51,16 @@ namespace Foam Foam::structuredRenumber::structuredRenumber ( - const dictionary& renumberDict + const dictionary& dict ) : - renumberMethod(renumberDict), - methodDict_(renumberDict.optionalSubDict(typeName + "Coeffs")), - patches_(methodDict_.get<wordRes>("patches")), - nLayers_(methodDict_.getOrDefault<label>("nLayers", labelMax)), - depthFirst_(methodDict_.get<bool>("depthFirst")), - reverse_(methodDict_.get<bool>("reverse")), - method_(renumberMethod::New(methodDict_)) + renumberMethod(dict), + coeffsDict_(dict.optionalSubDict(typeName + "Coeffs")), + patches_(coeffsDict_.get<wordRes>("patches")), + nLayers_(coeffsDict_.getOrDefault<label>("nLayers", labelMax)), + depthFirst_(coeffsDict_.get<bool>("depthFirst")), + reverse_(coeffsDict_.get<bool>("reverse")), + method_(renumberMethod::New(coeffsDict_)) {} diff --git a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.H b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.H index ea8e22a8edbe8d4aa9cc8003787d7bfa168f5607..c79ce09a46a695d8df41628c412e2a6ff040beee 100644 --- a/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.H +++ b/src/renumber/renumberMethods/structuredRenumber/structuredRenumber.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -40,14 +40,15 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef structuredRenumber_H -#define structuredRenumber_H +#ifndef Foam_structuredRenumber_H +#define Foam_structuredRenumber_H #include "renumberMethod.H" namespace Foam { +// Forward Declarations template<class Type> class topoDistanceData; /*---------------------------------------------------------------------------*\ @@ -60,7 +61,7 @@ class structuredRenumber { public: - // Public classes + // Public Classes //- Less function class that can be used for sorting according to // column and layer @@ -88,9 +89,9 @@ public: }; - // Private data + // Private Data - const dictionary methodDict_; + const dictionary& coeffsDict_; const wordRes patches_; @@ -121,7 +122,7 @@ public: // Constructors //- Construct given the renumber dictionary - structuredRenumber(const dictionary& renumberDict); + explicit structuredRenumber(const dictionary& dict); //- Destructor @@ -130,17 +131,17 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber ( @@ -148,18 +149,28 @@ public: const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // The connectivity is equal to mesh.cellCells() except - // - the connections are across coupled patches + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const CompactListList<label>& cellCells, + const pointField& cellCentres + ) const + { + NotImplemented; + return labelList(); + } + + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber ( const labelListList& cellCells, - const pointField& cc + const pointField& cellCentres ) const { NotImplemented; - return labelList(0); + return labelList(); } }; diff --git a/src/renumber/zoltanRenumber/zoltanRenumber.C b/src/renumber/zoltanRenumber/zoltanRenumber.C index 1f62813b446487c0b6134f1fbd9994f569161f79..cca2e8a07b128205fe8c25e351eeb42c9fd131e8 100644 --- a/src/renumber/zoltanRenumber/zoltanRenumber.C +++ b/src/renumber/zoltanRenumber/zoltanRenumber.C @@ -261,10 +261,10 @@ static void get_geom_list // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::zoltanRenumber::zoltanRenumber(const dictionary& renumberDict) +Foam::zoltanRenumber::zoltanRenumber(const dictionary& dict) : - renumberMethod(renumberDict), - coeffsDict_(renumberDict.optionalSubDict(typeName+"Coeffs")) + renumberMethod(dict), + coeffsDict_(dict.optionalSubDict(typeName+"Coeffs")) {} diff --git a/src/renumber/zoltanRenumber/zoltanRenumber.H b/src/renumber/zoltanRenumber/zoltanRenumber.H index b2fd74b50f75b14198aa109d4c94cee6764fb144..e2574b057a1e103fae67945bce92acf00d3298a8 100644 --- a/src/renumber/zoltanRenumber/zoltanRenumber.H +++ b/src/renumber/zoltanRenumber/zoltanRenumber.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,8 +35,8 @@ SourceFiles \*---------------------------------------------------------------------------*/ -#ifndef zoltanRenumber_H -#define zoltanRenumber_H +#ifndef Foam_zoltanRenumber_H +#define Foam_zoltanRenumber_H #include "renumberMethod.H" @@ -50,10 +51,9 @@ class zoltanRenumber : public renumberMethod { - // Private data - - const dictionary coeffsDict_; + // Private Data + const dictionary& coeffsDict_; // Private Member Functions @@ -74,7 +74,7 @@ public: // Constructors //- Construct given the renumber dictionary - zoltanRenumber(const dictionary& renumberDict); + explicit zoltanRenumber(const dictionary& dict); //- Destructor @@ -83,17 +83,17 @@ public: // Member Functions - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // This is only defined for geometric renumberMethods. virtual labelList renumber(const pointField&) const { NotImplemented; - return labelList(0); + return labelList(); } - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). // Use the mesh connectivity (if needed) virtual labelList renumber ( @@ -101,20 +101,29 @@ public: const pointField& cc ) const; - //- Return the order in which cells need to be visited, i.e. - // from ordered back to original cell label. - // The connectivity is equal to mesh.cellCells() except - // - the connections are across coupled patches + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). virtual labelList renumber ( - const labelListList& cellCells, - const pointField& cc + const CompactListList<label>& cellCells, + const pointField& cellCentres ) const { NotImplemented; - return labelList(0); + return labelList(); } + //- Return the order in which cells need to be visited + //- (ie. from ordered back to original cell label). + virtual labelList renumber + ( + const labelListList& cellCells, + const pointField& cellCentres + ) const + { + NotImplemented; + return labelList(); + } };