diff --git a/src/renumber/renumberMethods/Make/files b/src/renumber/renumberMethods/Make/files index 863d3d2100..68917a33d8 100644 --- a/src/renumber/renumberMethods/Make/files +++ b/src/renumber/renumberMethods/Make/files @@ -8,5 +8,6 @@ CuthillMcKeeRenumber/CuthillMcKeeRenumber.C springRenumber/springRenumber.C structuredRenumber/structuredRenumber.C structuredRenumber/OppositeFaceCellWaveBase.C +hpathRenumber/hpathRenumber.C LIB = $(FOAM_LIBBIN)/librenumberMethods diff --git a/src/renumber/renumberMethods/hpathRenumber/hpathRenumber.C b/src/renumber/renumberMethods/hpathRenumber/hpathRenumber.C new file mode 100644 index 0000000000..8490196993 --- /dev/null +++ b/src/renumber/renumberMethods/hpathRenumber/hpathRenumber.C @@ -0,0 +1,976 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | www.openfoam.com + \\/ M anipulation | +------------------------------------------------------------------------------- + Copyright (C) 2023 Alon Zameret, Noam Manaker Morag +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "hpathRenumber.H" +#include "addToRunTimeSelectionTable.H" + +#include "CircularBuffer.H" +#include + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(hpathRenumber, 0); + + addToRunTimeSelectionTable + ( + renumberMethod, + hpathRenumber, + dictionary + ); +} + + +// * * * * * * * * * * * * * * * * Local Details * * * * * * * * * * * * * * // + + +/*---------------------------------------------------------------------------*\ + Class hpathRenumber::hpathFinder Declaration +\*---------------------------------------------------------------------------*/ + +namespace Foam +{ + +// Class hpathFinder Declaration +class hpathRenumber::hpathFinder +{ + // Private Data + + // The input mesh + const Foam::polyMesh& mesh; + + // Counter for the number of renumbered cells + label nFoundCellCount; + + // Marks cells that have been added to the renumbering as 'true' + Foam::bitSet bIsRenumbered; + + // For every data structure, I explain what it is used for and which + // method is used to compute it + + // For every cell, a list of all its point-neighbouring cells - getMeshGraph() + Foam::labelListList nMeshGraph; + + // For each cell its 'layer index': - getLayers() + // - cells in the same layer will have the same layer index + Foam::labelList nCellLayerIndex; + + // For each cell its 'connected component index': - getConnectedComponents() + // - cells in the same connected component will have the same connected component index + Foam::labelList nCellConnnectedComponentIndex; + + // For each cell its face-neighbours in the connected component - getConnnectedComponentGraph() + Foam::labelListList nConnnectedComponentGraph; + + // Marks cells that have already been by BFS - getStartingCellInConnnectedComponent() + Foam::bitSet bBFSFoundCell; + + // For each cell its point distance from the connected components start cell - reorderDistFromStart() + Foam::labelList nCellPointDistFromStart; + Foam::labelList nCellFaceDistFromStart; + + // For each cell its DFS depth within the connected component - findPath() + Foam::labelList nDFSCellDepth; + + // For each cell its DFS parent within the connected component - findPath() + Foam::labelList nDFSParentCell; + + + public: // Public methods + + //- Constructor + explicit hpathFinder(const Foam::polyMesh& mesh); + + // Member Functions + + // Get Renumbering for the mesh + void getRenumbering + ( + Foam::labelList& cellOrder, + bool bApplyLayerSeparation + ); + + // Returns the accuracy of the renumbering: + // Accuracy is defined as the percentage of consecutive cells that are also face-neighbours in the mesh + // - Cells are face-neighbours if they have a common face + float getAccuracy(const Foam::labelList& cellOrder) const; + + + private: // Private methods + + // Initialize data structures for later use + void initialize(); + + // Given a cell and a face index, find its neighbour through the face + // - If facing the boundary, returns -1 + // - Otherwise, returns FaceOwner/FaceNeighbour[nFaceIdx], the one that's different from nCellIdx + label getNei(label nCellIdx, label nFaceIdx) const; + + // Creates the 'Mesh-Graph': for every cell, a list of cells that are point-neighbours with it in the mesh + // - Cells are point-neighbours if they have a common point + void getMeshGraph(); + + // Separates the mesh into layers: each cell has its layer saved in nCellLayerIndex + // Also returns for every layer a list of all cells in it + void getLayerSeparation(Foam::DynamicList>& nCellsByLayer); + + // For every connected component, find the deepest cell and choose it as a starting cell + // Returns a list with one starting cell per connected component + void getStartingCells(Foam::DynamicList