From cea60ab8abe3aefe71c851e6a654d55470b07576 Mon Sep 17 00:00:00 2001 From: Vuko Vukcevic Date: Wed, 20 Feb 2019 12:55:06 +0100 Subject: [PATCH] Refactorisation in refinement polyMeshModifier Moved extendMarkedCellsAcrossFaces and extendMarkedCellsAcrossPoints from refinement to meshTools. --- .../polyhedralRefinement.C | 5 +- .../prismatic2DRefinement.C | 5 +- .../refinement/refinement/refinement.C | 124 ----------------- .../refinement/refinement/refinement.H | 6 - src/foam/meshes/meshTools/meshTools.C | 125 ++++++++++++++++++ src/foam/meshes/meshTools/meshTools.H | 19 +++ 6 files changed, 150 insertions(+), 134 deletions(-) diff --git a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/polyhedralRefinement/polyhedralRefinement.C b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/polyhedralRefinement/polyhedralRefinement.C index 777b60f4f..64862038f 100644 --- a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/polyhedralRefinement/polyhedralRefinement.C +++ b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/polyhedralRefinement/polyhedralRefinement.C @@ -31,6 +31,7 @@ Author #include "faceSet.H" #include "pointSet.H" #include "addToRunTimeSelectionTable.H" +#include "meshTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -2042,7 +2043,7 @@ void Foam::polyhedralRefinement::setCellsToRefine // layers for (label i = 0; i < nRefinementBufferLayers_; ++i) { - extendMarkedCellsAcrossFaces(refineCell); + meshTools::extendMarkedCellsAcrossFaces(mesh_, refineCell); } // Remove all cells that would exceed the maximum refinement level @@ -2266,7 +2267,7 @@ void Foam::polyhedralRefinement::setSplitPointsToUnrefine // unrefinement buffer layers for (label i = 0; i < nUnrefinementBufferLayers_; ++i) { - extendMarkedCellsAcrossPoints(protectedCell); + meshTools::extendMarkedCellsAcrossPoints(mesh_, protectedCell); } // Loop through all cells and if the cell should be protected, protect all diff --git a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/prismatic2DRefinement/prismatic2DRefinement.C b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/prismatic2DRefinement/prismatic2DRefinement.C index 5a85d071a..c24cee40c 100644 --- a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/prismatic2DRefinement/prismatic2DRefinement.C +++ b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/prismatic2DRefinement/prismatic2DRefinement.C @@ -33,6 +33,7 @@ Author #include "emptyPolyPatch.H" #include "wedgePolyPatch.H" #include "addToRunTimeSelectionTable.H" +#include "meshTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -2601,7 +2602,7 @@ void Foam::prismatic2DRefinement::setCellsToRefine // layers for (label i = 0; i < nRefinementBufferLayers_; ++i) { - extendMarkedCellsAcrossFaces(refineCell); + meshTools::extendMarkedCellsAcrossFaces(mesh_, refineCell); } // Remove all cells that exceed the maximum refinement level @@ -2838,7 +2839,7 @@ void Foam::prismatic2DRefinement::setSplitPointsToUnrefine // unrefinement buffer layers for (label i = 0; i < nUnrefinementBufferLayers_; ++i) { - extendMarkedCellsAcrossPoints(protectedCell); + meshTools::extendMarkedCellsAcrossPoints(mesh_, protectedCell); } // Loop through all cells and if the cell should be protected, protect all diff --git a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.C b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.C index 740aaced0..29d1ba59f 100644 --- a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.C +++ b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.C @@ -66,130 +66,6 @@ void Foam::refinement::setInstance(const fileName& inst) const } -void Foam::refinement::extendMarkedCellsAcrossFaces -( - boolList& markedCell -) const -{ - // Mark all faces for all marked cells - const label nFaces = mesh_.nFaces(); - boolList markedFace(nFaces, false); - - // Get mesh cells - const cellList& meshCells = mesh_.cells(); - - // Loop through all cells - forAll (markedCell, cellI) - { - if (markedCell[cellI]) - { - // This cell is marked, get its faces - const cell& cFaces = meshCells[cellI]; - - forAll (cFaces, i) - { - markedFace[cFaces[i]] = true; - } - } - } - - // Snyc the face list across processor boundaries - syncTools::syncFaceList(mesh_, markedFace, orEqOp(), false); - - // Get necessary mesh data - const label nInternalFaces = mesh_.nInternalFaces(); - const labelList& owner = mesh_.faceOwner(); - const labelList& neighbour = mesh_.faceNeighbour(); - - // Internal faces - for (label faceI = 0; faceI < nInternalFaces; ++faceI) - { - if (markedFace[faceI]) - { - // Face is marked, mark both owner and neighbour if the maximum - // refinement level is not exceeded - const label& own = owner[faceI]; - const label& nei = neighbour[faceI]; - - // Mark owner and neighbour cells - markedCell[own] = true; - markedCell[nei] = true; - } - } - - // Boundary faces - for (label faceI = nInternalFaces; faceI < nFaces; ++faceI) - { - if (markedFace[faceI]) - { - // Face is marked, mark owner if the maximum refinement level is not - // exceeded - const label& own = owner[faceI]; - - // Mark owner - markedCell[own] = true; - } - } -} - - -void Foam::refinement::extendMarkedCellsAcrossPoints -( - boolList& markedCell -) const -{ - // Mark all points for all marked cells - const label nPoints = mesh_.nPoints(); - boolList markedPoint(nPoints, false); - - // Get cell points - const labelListList& meshCellPoints = mesh_.cellPoints(); - - // Loop through all cells - forAll (markedCell, cellI) - { - if (markedCell[cellI]) - { - // This cell is marked, get its points - const labelList& cPoints = meshCellPoints[cellI]; - - forAll (cPoints, i) - { - markedPoint[cPoints[i]] = true; - } - } - } - - // Snyc point list across processor boundaries - syncTools::syncPointList - ( - mesh_, - markedPoint, - orEqOp(), - true, // Default value - true // Apply separation for parallel cyclics - ); - - // Get point cells - const labelListList& meshPointCells = mesh_.pointCells(); - - // Loop through all points - forAll (markedPoint, pointI) - { - if (markedPoint[pointI]) - { - // This point is marked, mark all of its cells - const labelList& pCells = meshPointCells[pointI]; - - forAll (pCells, i) - { - markedCell[pCells[i]] = true; - } - } - } -} - - Foam::label Foam::refinement::addFace ( polyTopoChange& ref, diff --git a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.H b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.H index 9cd293a39..f361ca707 100644 --- a/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.H +++ b/src/dynamicMesh/dynamicMesh/polyMeshModifiers/refinement/refinement/refinement.H @@ -159,12 +159,6 @@ protected: //- Set file instance for cellLevel_ and pointLevel_ void setInstance(const fileName& inst) const; - //- Extend marked cells across faces - void extendMarkedCellsAcrossFaces(boolList& markedCell) const; - - //- Extend marked cells across points - void extendMarkedCellsAcrossPoints(boolList& markedCell) const; - // Local topology modification functions (operate on cells/faces) diff --git a/src/foam/meshes/meshTools/meshTools.C b/src/foam/meshes/meshTools/meshTools.C index 5745a09c2..b99542297 100644 --- a/src/foam/meshes/meshTools/meshTools.C +++ b/src/foam/meshes/meshTools/meshTools.C @@ -27,6 +27,7 @@ License #include "polyMesh.H" #include "hexMatcher.H" #include "faceZone.H" +#include "syncTools.H" // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // @@ -927,4 +928,128 @@ void Foam::meshTools::setFaceInfo } +void Foam::meshTools::extendMarkedCellsAcrossFaces +( + const polyMesh& mesh, + boolList& markedCell +) +{ + // Mark all faces for all marked cells + const label nFaces = mesh.nFaces(); + boolList markedFace(nFaces, false); + + // Get mesh cells + const cellList& meshCells = mesh.cells(); + + // Loop through all cells + forAll (markedCell, cellI) + { + if (markedCell[cellI]) + { + // This cell is marked, get its faces + const cell& cFaces = meshCells[cellI]; + + forAll (cFaces, i) + { + markedFace[cFaces[i]] = true; + } + } + } + + // Snyc the face list across processor boundaries + syncTools::syncFaceList(mesh, markedFace, orEqOp(), false); + + // Get necessary mesh data + const label nInternalFaces = mesh.nInternalFaces(); + const labelList& owner = mesh.faceOwner(); + const labelList& neighbour = mesh.faceNeighbour(); + + // Internal faces + for (label faceI = 0; faceI < nInternalFaces; ++faceI) + { + if (markedFace[faceI]) + { + // Face is marked, mark both owner and neighbour + const label& own = owner[faceI]; + const label& nei = neighbour[faceI]; + + // Mark owner and neighbour cells + markedCell[own] = true; + markedCell[nei] = true; + } + } + + // Boundary faces + for (label faceI = nInternalFaces; faceI < nFaces; ++faceI) + { + if (markedFace[faceI]) + { + // Face is marked, mark owner + const label& own = owner[faceI]; + + // Mark owner + markedCell[own] = true; + } + } +} + + +void Foam::meshTools::extendMarkedCellsAcrossPoints +( + const polyMesh& mesh, + boolList& markedCell +) +{ + // Mark all points for all marked cells + const label nPoints = mesh.nPoints(); + boolList markedPoint(nPoints, false); + + // Get cell points + const labelListList& meshCellPoints = mesh.cellPoints(); + + // Loop through all cells + forAll (markedCell, cellI) + { + if (markedCell[cellI]) + { + // This cell is marked, get its points + const labelList& cPoints = meshCellPoints[cellI]; + + forAll (cPoints, i) + { + markedPoint[cPoints[i]] = true; + } + } + } + + // Snyc point list across processor boundaries + syncTools::syncPointList + ( + mesh, + markedPoint, + orEqOp(), + true, // Default value + true // Apply separation for parallel cyclics + ); + + // Get point cells + const labelListList& meshPointCells = mesh.pointCells(); + + // Loop through all points + forAll (markedPoint, pointI) + { + if (markedPoint[pointI]) + { + // This point is marked, mark all of its cells + const labelList& pCells = meshPointCells[pointI]; + + forAll (pCells, i) + { + markedCell[pCells[i]] = true; + } + } + } +} + + // ************************************************************************* // diff --git a/src/foam/meshes/meshTools/meshTools.H b/src/foam/meshes/meshTools/meshTools.H index f977f8fca..10ae04a43 100644 --- a/src/foam/meshes/meshTools/meshTools.H +++ b/src/foam/meshes/meshTools/meshTools.H @@ -318,6 +318,25 @@ namespace meshTools label& zoneFlip ); + + // Mark-up of mesh bits. Relocated from refinement polyMeshModifier + + //- Extend marked cells across faces given a bool list of already marked + // cells + void extendMarkedCellsAcrossFaces + ( + const polyMesh& mesh, + boolList& markedCell + ); + + //- Extend marked cells across points given a bool list of already + // marked cells + void extendMarkedCellsAcrossPoints + ( + const polyMesh& mesh, + boolList& markedCell + ); + } // End namespace meshTools