ENH: allow bitSet selector for removeCells (issue #951)

This commit is contained in:
Mark Olesen
2018-07-25 16:01:43 +02:00
parent adb90ef655
commit 3218b3dee3
2 changed files with 150 additions and 111 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,6 +24,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "removeCells.H" #include "removeCells.H"
#include "bitSet.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "polyTopoChange.H" #include "polyTopoChange.H"
#include "polyRemoveCell.H" #include "polyRemoveCell.H"
@ -39,23 +40,43 @@ namespace Foam
defineTypeNameAndDebug(removeCells, 0); defineTypeNameAndDebug(removeCells, 0);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
void Foam::removeCells::uncount namespace
(
const labelList& f,
labelList& nUsage
)
{ {
forAll(f, fp)
// Increase count (usage) of elements of list
inline void incrCount(const Foam::labelUList& list, Foam::labelList& counter)
{
for (auto idx : list)
{ {
nUsage[f[fp]]--; ++counter[idx];
} }
} }
// Decrease count (usage) of elements of list
inline void decrCount(const Foam::labelUList& list, Foam::labelList& counter)
{
for (auto idx : list)
{
--counter[idx];
}
}
} // End anonymous namespace
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::removeCells::removeCells
(
const polyMesh& mesh
)
:
removeCells(mesh, true)
{}
Foam::removeCells::removeCells Foam::removeCells::removeCells
( (
const polyMesh& mesh, const polyMesh& mesh,
@ -71,47 +92,37 @@ Foam::removeCells::removeCells
Foam::labelList Foam::removeCells::getExposedFaces Foam::labelList Foam::removeCells::getExposedFaces
( (
const labelList& cellLabels const bitSet& removedCell
) const ) const
{ {
// Create list of cells to be removed
boolList removedCell(mesh_.nCells(), false);
// Go from labelList of cells-to-remove to a boolList.
forAll(cellLabels, i)
{
removedCell[cellLabels[i]] = true;
}
const labelList& faceOwner = mesh_.faceOwner(); const labelList& faceOwner = mesh_.faceOwner();
const labelList& faceNeighbour = mesh_.faceNeighbour(); const labelList& faceNeighbour = mesh_.faceNeighbour();
// Count cells using face. // Count cells using face.
labelList nCellsUsingFace(mesh_.nFaces(), 0); labelList nCellsUsingFace(mesh_.nFaces(), 0);
for (label facei = 0; facei < mesh_.nInternalFaces(); facei++) for (label facei = 0; facei < mesh_.nInternalFaces(); ++facei)
{ {
label own = faceOwner[facei]; const label own = faceOwner[facei];
label nei = faceNeighbour[facei]; const label nei = faceNeighbour[facei];
if (!removedCell[own]) if (!removedCell[own])
{ {
nCellsUsingFace[facei]++; ++nCellsUsingFace[facei];
} }
if (!removedCell[nei]) if (!removedCell[nei])
{ {
nCellsUsingFace[facei]++; ++nCellsUsingFace[facei];
} }
} }
for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); facei++) for (label facei = mesh_.nInternalFaces(); facei < mesh_.nFaces(); ++facei)
{ {
label own = faceOwner[facei]; const label own = faceOwner[facei];
if (!removedCell[own]) if (!removedCell[own])
{ {
nCellsUsingFace[facei]++; ++nCellsUsingFace[facei];
} }
} }
@ -147,7 +158,7 @@ Foam::labelList Foam::removeCells::getExposedFaces
DynamicList<label> exposedFaces(mesh_.nFaces()/10); DynamicList<label> exposedFaces(mesh_.nFaces()/10);
for (label facei = 0; facei < mesh_.nInternalFaces(); facei++) for (label facei = 0; facei < mesh_.nInternalFaces(); ++facei)
{ {
if (nCellsUsingFace[facei] == 1) if (nCellsUsingFace[facei] == 1)
{ {
@ -157,17 +168,15 @@ Foam::labelList Foam::removeCells::getExposedFaces
const polyBoundaryMesh& patches = mesh_.boundaryMesh(); const polyBoundaryMesh& patches = mesh_.boundaryMesh();
forAll(patches, patchi) for (const polyPatch& pp : patches)
{ {
const polyPatch& pp = patches[patchi];
if (pp.coupled()) if (pp.coupled())
{ {
label facei = pp.start(); label facei = pp.start();
forAll(pp, i) forAll(pp, i)
{ {
label own = faceOwner[facei]; const label own = faceOwner[facei];
if (nCellsUsingFace[facei] == 1 && !removedCell[own]) if (nCellsUsingFace[facei] == 1 && !removedCell[own])
{ {
@ -176,7 +185,7 @@ Foam::labelList Foam::removeCells::getExposedFaces
exposedFaces.append(facei); exposedFaces.append(facei);
} }
facei++; ++facei;
} }
} }
} }
@ -187,9 +196,9 @@ Foam::labelList Foam::removeCells::getExposedFaces
void Foam::removeCells::setRefinement void Foam::removeCells::setRefinement
( (
const labelList& cellLabels, const bitSet& removedCell,
const labelList& exposedFaceLabels, const labelUList& exposedFaceLabels,
const labelList& exposedPatchIDs, const labelUList& exposedPatchIDs,
polyTopoChange& meshMod polyTopoChange& meshMod
) const ) const
{ {
@ -209,13 +218,14 @@ void Foam::removeCells::setRefinement
forAll(exposedFaceLabels, i) forAll(exposedFaceLabels, i)
{ {
label patchi = exposedPatchIDs[i]; const label facei = exposedFaceLabels[i];
const label patchi = exposedPatchIDs[i];
if (patchi < 0 || patchi >= patches.size()) if (patchi < 0 || patchi >= patches.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Invalid patch " << patchi << "Invalid patch " << patchi
<< " for exposed face " << exposedFaceLabels[i] << endl << " for exposed face " << facei << nl
<< "Valid patches 0.." << patches.size()-1 << "Valid patches 0.." << patches.size()-1
<< abort(FatalError); << abort(FatalError);
} }
@ -223,28 +233,20 @@ void Foam::removeCells::setRefinement
if (patches[patchi].coupled()) if (patches[patchi].coupled())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Trying to put exposed face " << exposedFaceLabels[i] << "Trying to put exposed face " << facei
<< " into a coupled patch : " << patches[patchi].name() << " into a coupled patch : " << patches[patchi].name()
<< endl << nl
<< "This is illegal." << "This is illegal."
<< abort(FatalError); << abort(FatalError);
} }
newPatchID[exposedFaceLabels[i]] = patchi; newPatchID[facei] = patchi;
} }
// Create list of cells to be removed // Walk all the cells mentioned for removal
boolList removedCell(mesh_.nCells(), false); for (const label celli : removedCell)
// Go from labelList of cells-to-remove to a boolList and remove all
// cells mentioned.
forAll(cellLabels, i)
{ {
label celli = cellLabels[i];
removedCell[celli] = true;
//Pout<< "Removing cell " << celli //Pout<< "Removing cell " << celli
// << " cc:" << mesh_.cellCentres()[celli] << endl; // << " cc:" << mesh_.cellCentres()[celli] << endl;
@ -260,26 +262,21 @@ void Foam::removeCells::setRefinement
const labelList& faceNeighbour = mesh_.faceNeighbour(); const labelList& faceNeighbour = mesh_.faceNeighbour();
const faceZoneMesh& faceZones = mesh_.faceZones(); const faceZoneMesh& faceZones = mesh_.faceZones();
// Count starting number of faces using each point. Keep up to date whenever // Count starting number of faces using each point.
// removing a face. // Update whenever removing a face.
labelList nFacesUsingPoint(mesh_.nPoints(), 0); labelList nFacesUsingPoint(mesh_.nPoints(), 0);
forAll(faces, facei) for (const face& f : faces)
{ {
const face& f = faces[facei]; incrCount(f, nFacesUsingPoint);
forAll(f, fp)
{
nFacesUsingPoint[f[fp]]++;
}
} }
for (label facei = 0; facei < mesh_.nInternalFaces(); facei++) for (label facei = 0; facei < mesh_.nInternalFaces(); ++facei)
{ {
const face& f = faces[facei]; const face& f = faces[facei];
label own = faceOwner[facei]; const label own = faceOwner[facei];
label nei = faceNeighbour[facei]; const label nei = faceNeighbour[facei];
if (removedCell[own]) if (removedCell[own])
{ {
@ -290,7 +287,7 @@ void Foam::removeCells::setRefinement
// << " fc:" << mesh_.faceCentres()[facei] << endl; // << " fc:" << mesh_.faceCentres()[facei] << endl;
meshMod.setAction(polyRemoveFace(facei)); meshMod.setAction(polyRemoveFace(facei));
uncount(f, nFacesUsingPoint); decrCount(f, nFacesUsingPoint);
} }
else else
{ {
@ -305,7 +302,7 @@ void Foam::removeCells::setRefinement
// nei is remaining cell. Facei becomes external cell // nei is remaining cell. Facei becomes external cell
label zoneID = faceZones.whichZone(facei); const label zoneID = faceZones.whichZone(facei);
bool zoneFlip = false; bool zoneFlip = false;
if (zoneID >= 0) if (zoneID >= 0)
@ -353,7 +350,7 @@ void Foam::removeCells::setRefinement
// << " into patch " << newPatchID[facei] << endl; // << " into patch " << newPatchID[facei] << endl;
// own is remaining cell. Facei becomes external cell. // own is remaining cell. Facei becomes external cell.
label zoneID = faceZones.whichZone(facei); const label zoneID = faceZones.whichZone(facei);
bool zoneFlip = false; bool zoneFlip = false;
if (zoneID >= 0) if (zoneID >= 0)
@ -380,10 +377,8 @@ void Foam::removeCells::setRefinement
} }
} }
forAll(patches, patchi) for (const polyPatch& pp : patches)
{ {
const polyPatch& pp = patches[patchi];
if (pp.coupled()) if (pp.coupled())
{ {
label facei = pp.start(); label facei = pp.start();
@ -396,7 +391,7 @@ void Foam::removeCells::setRefinement
// << " fc:" << mesh_.faceCentres()[facei] // << " fc:" << mesh_.faceCentres()[facei]
// << " into patch " << newPatchID[facei] << endl; // << " into patch " << newPatchID[facei] << endl;
label zoneID = faceZones.whichZone(facei); const label zoneID = faceZones.whichZone(facei);
bool zoneFlip = false; bool zoneFlip = false;
if (zoneID >= 0) if (zoneID >= 0)
@ -429,10 +424,10 @@ void Foam::removeCells::setRefinement
// << endl; // << endl;
meshMod.setAction(polyRemoveFace(facei)); meshMod.setAction(polyRemoveFace(facei));
uncount(faces[facei], nFacesUsingPoint); decrCount(faces[facei], nFacesUsingPoint);
} }
facei++; ++facei;
} }
} }
else else
@ -457,10 +452,10 @@ void Foam::removeCells::setRefinement
// << endl; // << endl;
meshMod.setAction(polyRemoveFace(facei)); meshMod.setAction(polyRemoveFace(facei));
uncount(faces[facei], nFacesUsingPoint); decrCount(faces[facei], nFacesUsingPoint);
} }
facei++; ++facei;
} }
} }
} }
@ -491,4 +486,35 @@ void Foam::removeCells::setRefinement
} }
Foam::labelList Foam::removeCells::getExposedFaces
(
const labelUList& cellsToRemove
) const
{
bitSet removeCell(mesh_.nCells(), cellsToRemove);
return getExposedFaces(removeCell);
}
void Foam::removeCells::setRefinement
(
const labelUList& cellsToRemove,
const labelUList& exposedFaceLabels,
const labelUList& exposedPatchIDs,
polyTopoChange& meshMod
) const
{
bitSet removedCell(mesh_.nCells(), cellsToRemove);
setRefinement
(
removedCell,
exposedFaceLabels,
exposedPatchIDs,
meshMod
);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,7 +25,7 @@ Class
Foam::removeCells Foam::removeCells
Description Description
Given list of cells to remove insert all the topology changes. Given list of cells to remove, insert all the topology changes.
Works in two passes: Works in two passes:
- get faces that will become boundary faces - get faces that will become boundary faces
@ -48,7 +48,8 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class bitSet;
class polyMesh; class polyMesh;
class polyTopoChange; class polyTopoChange;
class mapPolyMesh; class mapPolyMesh;
@ -67,17 +68,6 @@ class removeCells
//- Whether or not to synchronize parallel case. //- Whether or not to synchronize parallel case.
const bool syncPar_; const bool syncPar_;
// Private Member Functions
//- Decrease count of elements of f
static void uncount
(
const labelList& f,
labelList& nUsage
);
public: public:
//- Runtime type information //- Runtime type information
@ -86,35 +76,58 @@ public:
// Constructors // Constructors
//- Construct from mesh. syncPar: do parallel synchronization. //- Construct from mesh. With parallel synchronization.
removeCells(const polyMesh& mesh, const bool syncPar = true); explicit removeCells(const polyMesh& mesh);
//- Construct from mesh, optionally with parallel synchronization.
removeCells(const polyMesh& mesh, const bool syncPar);
//- Destructor
~removeCells() = default;
// Member Functions // Member Functions
// Topology changes //- Get labels of faces exposed after cells removal.
// These are
// - internal faces that become boundary faces
// - coupled faces that become uncoupled (since one of the sides
// gets deleted)
labelList getExposedFaces(const bitSet& removedCell) const;
//- Get labels of exposed faces. //- Get labels of faces exposed after cells removal.
// These are // These are
// - internal faces that become boundary faces // - internal faces that become boundary faces
// - coupled faces that become uncoupled (since one of the sides // - coupled faces that become uncoupled (since one of the sides
// gets deleted) // gets deleted)
labelList getExposedFaces(const labelList& cellsToRemove) const; labelList getExposedFaces(const labelUList& cellsToRemove) const;
//- Play commands into polyTopoChange to remove cells. //- Play commands into polyTopoChange to remove cells.
// patchIDs is for every element in facesToExpose (see above) the // patchIDs is for every element in facesToExpose (see above) the
// patch it has to go into. This cannot be a coupled patch! // patch it has to go into. This cannot be a coupled patch!
void setRefinement void setRefinement
( (
const labelList& cellsToRemove, const bitSet& removedCell,
const labelList& facesToExpose, const labelUList& facesToExpose,
const labelList& patchIDs, const labelUList& patchIDs,
polyTopoChange& polyTopoChange&
) const; ) const;
//- Force recalculation of locally stored data on topological change //- Play commands into polyTopoChange to remove cells.
void updateMesh(const mapPolyMesh&) // patchIDs is for every element in facesToExpose (see above) the
{} // patch it has to go into. This cannot be a coupled patch!
void setRefinement
(
const labelUList& cellsToRemove,
const labelUList& facesToExpose,
const labelUList& patchIDs,
polyTopoChange&
) const;
//- Force recalculation of locally stored data on topological change
void updateMesh(const mapPolyMesh&)
{}
}; };