First batch of updates for removeFaces.?
This commit is contained in:
parent
b735b5829f
commit
b767b8aba6
2 changed files with 112 additions and 76 deletions
|
@ -48,8 +48,6 @@ defineTypeNameAndDebug(removeFaces, 0);
|
||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
// Changes region of connected set of cells. Can be recursive since hopefully
|
|
||||||
// only small area of faces removed in one go.
|
|
||||||
void Foam::removeFaces::changeCellRegion
|
void Foam::removeFaces::changeCellRegion
|
||||||
(
|
(
|
||||||
const label cellI,
|
const label cellI,
|
||||||
|
@ -62,8 +60,7 @@ void Foam::removeFaces::changeCellRegion
|
||||||
{
|
{
|
||||||
cellRegion[cellI] = newRegion;
|
cellRegion[cellI] = newRegion;
|
||||||
|
|
||||||
// Step to neighbouring cells
|
// Go through all neighbouring cells
|
||||||
|
|
||||||
const labelList& cCells = mesh_.cellCells()[cellI];
|
const labelList& cCells = mesh_.cellCells()[cellI];
|
||||||
|
|
||||||
forAll(cCells, i)
|
forAll(cCells, i)
|
||||||
|
@ -129,7 +126,7 @@ Foam::label Foam::removeFaces::changeFaceRegion
|
||||||
// - removal of faces
|
// - removal of faces
|
||||||
// - removal of edges
|
// - removal of edges
|
||||||
// - removal of points
|
// - removal of points
|
||||||
Foam::boolList Foam::removeFaces::getFacesAffected
|
Foam::Xfer<boolList> Foam::removeFaces::affectedFaces
|
||||||
(
|
(
|
||||||
const labelList& cellRegion,
|
const labelList& cellRegion,
|
||||||
const labelList& cellRegionMaster,
|
const labelList& cellRegionMaster,
|
||||||
|
@ -185,7 +182,8 @@ Foam::boolList Foam::removeFaces::getFacesAffected
|
||||||
affectedFace[pFaces[pFaceI]] = true;
|
affectedFace[pFaces[pFaceI]] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return affectedFace;
|
|
||||||
|
return affectedFace.xfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -579,20 +577,24 @@ Foam::label Foam::removeFaces::compatibleRemoves
|
||||||
labelList& newFacesToRemove
|
labelList& newFacesToRemove
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
|
// Get necessary mesh data
|
||||||
const labelList& faceOwner = mesh_.faceOwner();
|
const labelList& faceOwner = mesh_.faceOwner();
|
||||||
const labelList& faceNeighbour = mesh_.faceNeighbour();
|
const labelList& faceNeighbour = mesh_.faceNeighbour();
|
||||||
|
|
||||||
cellRegion.setSize(mesh_.nCells());
|
const label nCells = mesh_.nCells();
|
||||||
cellRegion = -1;
|
|
||||||
|
|
||||||
regionMaster.setSize(mesh_.nCells());
|
// Resize the lists and set elements to -1 by default
|
||||||
regionMaster = -1;
|
cellRegion.setSize(nCells, -1);
|
||||||
|
regionMaster.setSize(nCells, -1);
|
||||||
|
|
||||||
|
// Count regions
|
||||||
label nRegions = 0;
|
label nRegions = 0;
|
||||||
|
|
||||||
|
// Loop through initial set of faces to remove
|
||||||
forAll(facesToRemove, i)
|
forAll(facesToRemove, i)
|
||||||
{
|
{
|
||||||
label faceI = facesToRemove[i];
|
// Get face index
|
||||||
|
const label& faceI = facesToRemove[i];
|
||||||
|
|
||||||
if (!mesh_.isInternalFace(faceI))
|
if (!mesh_.isInternalFace(faceI))
|
||||||
{
|
{
|
||||||
|
@ -600,103 +602,119 @@ Foam::label Foam::removeFaces::compatibleRemoves
|
||||||
(
|
(
|
||||||
"removeFaces::compatibleRemoves(const labelList&"
|
"removeFaces::compatibleRemoves(const labelList&"
|
||||||
", labelList&, labelList&, labelList&)"
|
", labelList&, labelList&, labelList&)"
|
||||||
) << "Not internal face:" << faceI << abort(FatalError);
|
) << "Attempting to remove boundary face with face index: "
|
||||||
|
<< faceI << nl
|
||||||
|
<< "This is not allowed. Check facesToRemove list."
|
||||||
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get owner and neighbour data
|
||||||
|
const label& own = faceOwner[faceI];
|
||||||
|
const label& nei = faceNeighbour[faceI];
|
||||||
|
|
||||||
label own = faceOwner[faceI];
|
// Get region data for owner and neighbour
|
||||||
label nei = faceNeighbour[faceI];
|
label& ownRegion = cellRegion[own];
|
||||||
|
label& neiRegion = cellRegion[nei];
|
||||||
|
|
||||||
label region0 = cellRegion[own];
|
if (ownRegion == -1)
|
||||||
label region1 = cellRegion[nei];
|
|
||||||
|
|
||||||
if (region0 == -1)
|
|
||||||
{
|
{
|
||||||
if (region1 == -1)
|
// Owner region is not set
|
||||||
{
|
|
||||||
// Create new region
|
|
||||||
cellRegion[own] = nRegions;
|
|
||||||
cellRegion[nei] = nRegions;
|
|
||||||
|
|
||||||
// Make owner (lowest numbered!) the master of the region
|
if (neiRegion == -1)
|
||||||
|
{
|
||||||
|
// Neighbour region is also not set, create new region
|
||||||
|
ownRegion = nRegions;
|
||||||
|
neiRegion = nRegions;
|
||||||
|
|
||||||
|
// Make owner (lowest numbered!) the master of the region and
|
||||||
|
// increment the number of regions
|
||||||
regionMaster[nRegions] = own;
|
regionMaster[nRegions] = own;
|
||||||
nRegions++;
|
++nRegions;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Add owner to neighbour region
|
// Neighbour region is set, add owner to neighbour region
|
||||||
cellRegion[own] = region1;
|
ownRegion = neiRegion;
|
||||||
// See if owner becomes the master of the region
|
|
||||||
|
// See if owner becomes the master of the region (if its index
|
||||||
|
// is lower than the current master of the region)
|
||||||
regionMaster[region1] = min(own, regionMaster[region1]);
|
regionMaster[region1] = min(own, regionMaster[region1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (region1 == -1)
|
// Owner region is set
|
||||||
|
|
||||||
|
if (neiRegion == -1)
|
||||||
{
|
{
|
||||||
// Add neighbour to owner region
|
// Neighbour region is not set, add neighbour to owner region
|
||||||
cellRegion[nei] = region0;
|
neiRegion = ownRegion;
|
||||||
// nei is higher numbered than own so guaranteed not lower
|
|
||||||
// than master of region0.
|
// Note: nei has higher index than own so neighbour can't be the
|
||||||
|
// master of this region
|
||||||
}
|
}
|
||||||
else if (region0 != region1)
|
else if (ownRegion != neiRegion)
|
||||||
{
|
{
|
||||||
// Both have regions. Keep lowest numbered region and master.
|
// Both have regions. Keep lowest numbered region and master
|
||||||
label freedRegion = -1;
|
label freedRegion = -1;
|
||||||
label keptRegion = -1;
|
label keptRegion = -1;
|
||||||
|
|
||||||
if (region0 < region1)
|
if (ownRegion < neiRegion)
|
||||||
{
|
{
|
||||||
changeCellRegion
|
changeCellRegion
|
||||||
(
|
(
|
||||||
nei,
|
nei,
|
||||||
region1, // old region
|
neiRegion, // old region
|
||||||
region0, // new region
|
ownRegion, // new region
|
||||||
cellRegion
|
cellRegion
|
||||||
);
|
);
|
||||||
|
|
||||||
keptRegion = region0;
|
keptRegion = ownRegion;
|
||||||
freedRegion = region1;
|
freedRegion = neiRegion;
|
||||||
}
|
}
|
||||||
else if (region1 < region0)
|
else if (ownRegion < neiRegion)
|
||||||
{
|
{
|
||||||
changeCellRegion
|
changeCellRegion
|
||||||
(
|
(
|
||||||
own,
|
own,
|
||||||
region0, // old region
|
ownRegion, // old region
|
||||||
region1, // new region
|
neiRegion, // new region
|
||||||
cellRegion
|
cellRegion
|
||||||
);
|
);
|
||||||
|
|
||||||
keptRegion = region1;
|
keptRegion = neiRegion;
|
||||||
freedRegion = region0;
|
freedRegion = ownRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
label master0 = regionMaster[region0];
|
const label& ownRegionMaster = regionMaster[ownRegion];
|
||||||
label master1 = regionMaster[region1];
|
const label& neiRegionMaster = regionMaster[neiRegion];
|
||||||
|
|
||||||
regionMaster[freedRegion] = -1;
|
regionMaster[freedRegion] = -1;
|
||||||
regionMaster[keptRegion] = min(master0, master1);
|
regionMaster[keptRegion] = min(ownRegionMaster, neiRegionMaster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set size
|
||||||
regionMaster.setSize(nRegions);
|
regionMaster.setSize(nRegions);
|
||||||
|
|
||||||
|
// Various checks, additional scope for clarity
|
||||||
// Various checks
|
|
||||||
// - master is lowest numbered in any region
|
// - master is lowest numbered in any region
|
||||||
// - regions have more than 1 cell
|
// - regions have more than 1 cell
|
||||||
{
|
{
|
||||||
|
// Number of cells per region
|
||||||
labelList nCells(regionMaster.size(), 0);
|
labelList nCells(regionMaster.size(), 0);
|
||||||
|
|
||||||
|
// Loop through cell regions
|
||||||
forAll(cellRegion, cellI)
|
forAll(cellRegion, cellI)
|
||||||
{
|
{
|
||||||
label r = cellRegion[cellI];
|
// Get region for this cell
|
||||||
|
const label& r = cellRegion[cellI];
|
||||||
|
|
||||||
if (r != -1)
|
if (r != -1)
|
||||||
{
|
{
|
||||||
nCells[r]++;
|
// Region found, increment number of cells per region
|
||||||
|
++nCells[r];
|
||||||
|
|
||||||
if (cellI < regionMaster[r])
|
if (cellI < regionMaster[r])
|
||||||
{
|
{
|
||||||
|
@ -704,24 +722,25 @@ Foam::label Foam::removeFaces::compatibleRemoves
|
||||||
(
|
(
|
||||||
"removeFaces::compatibleRemoves(const labelList&"
|
"removeFaces::compatibleRemoves(const labelList&"
|
||||||
", labelList&, labelList&, labelList&)"
|
", labelList&, labelList&, labelList&)"
|
||||||
) << "Not lowest numbered : cell:" << cellI
|
) << "Not lowest numbered! Cell: " << cellI
|
||||||
<< " region:" << r
|
<< " region: " << r
|
||||||
<< " regionmaster:" << regionMaster[r]
|
<< " region master: " << regionMaster[r]
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
forAll(nCells, region)
|
// Loop through all regions
|
||||||
|
forAll(nCells, regionI)
|
||||||
{
|
{
|
||||||
if (nCells[region] == 1)
|
if (nCells[regionI] == 1)
|
||||||
{
|
{
|
||||||
FatalErrorIn
|
FatalErrorIn
|
||||||
(
|
(
|
||||||
"removeFaces::compatibleRemoves(const labelList&"
|
"removeFaces::compatibleRemoves(const labelList&"
|
||||||
", labelList&, labelList&, labelList&)"
|
", labelList&, labelList&, labelList&)"
|
||||||
) << "Region " << region
|
) << "Region " << region
|
||||||
<< " has only " << nCells[region] << " cells in it"
|
<< " has only " << nCells[region] << " cell in it."
|
||||||
<< abort(FatalError);
|
<< abort(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -735,28 +754,33 @@ Foam::label Foam::removeFaces::compatibleRemoves
|
||||||
{
|
{
|
||||||
if (regionMaster[i] != -1)
|
if (regionMaster[i] != -1)
|
||||||
{
|
{
|
||||||
nUsedRegions++;
|
++nUsedRegions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recreate facesToRemove to be consistent with the cellRegions.
|
// Recreate facesToRemove to be consistent with the cellRegions
|
||||||
dynamicLabelList allFacesToRemove(facesToRemove.size());
|
dynamicLabelList allFacesToRemove(facesToRemove.size());
|
||||||
|
|
||||||
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
|
// Get number of internal faces
|
||||||
|
const label nInternalFaces = mesh_.nInternalFaces();
|
||||||
|
|
||||||
|
// Loop through internal faces
|
||||||
|
for (label faceI = 0; faceI < nInternalFaces; ++faceI)
|
||||||
{
|
{
|
||||||
label own = faceOwner[faceI];
|
// Get owner and neighbour labels
|
||||||
label nei = faceNeighbour[faceI];
|
const label& own = faceOwner[faceI];
|
||||||
|
const label& nei = faceNeighbour[faceI];
|
||||||
|
|
||||||
if (cellRegion[own] != -1 && cellRegion[own] == cellRegion[nei])
|
if (cellRegion[own] != -1 && cellRegion[own] == cellRegion[nei])
|
||||||
{
|
{
|
||||||
// Both will become the same cell so add face to list of faces
|
// Both owner and neighbour of the face will become the same cell so
|
||||||
// to be removed.
|
// we can add this face to final list of faces to be removed
|
||||||
allFacesToRemove.append(faceI);
|
allFacesToRemove.append(faceI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newFacesToRemove.transfer(allFacesToRemove.shrink());
|
// Transfer dynamic list into the ordinary list
|
||||||
allFacesToRemove.clear();
|
newFacesToRemove.transfer(allFacesToRemove);
|
||||||
|
|
||||||
return nUsedRegions;
|
return nUsedRegions;
|
||||||
}
|
}
|
||||||
|
@ -1358,7 +1382,7 @@ void Foam::removeFaces::setRefinement
|
||||||
// Get all faces affected in any way by removal of points/edges/faces/cells
|
// Get all faces affected in any way by removal of points/edges/faces/cells
|
||||||
boolList affectedFace
|
boolList affectedFace
|
||||||
(
|
(
|
||||||
getFacesAffected
|
affectedFaces
|
||||||
(
|
(
|
||||||
cellRegion,
|
cellRegion,
|
||||||
cellRegionMaster,
|
cellRegionMaster,
|
||||||
|
|
|
@ -33,6 +33,15 @@ Description
|
||||||
SourceFiles
|
SourceFiles
|
||||||
removeFaces.C
|
removeFaces.C
|
||||||
|
|
||||||
|
Notes
|
||||||
|
All classes (hexRef8, undoableMeshCutter) that have a private member object
|
||||||
|
of this class (removeFaces) should be rewritten such that they are
|
||||||
|
polyMeshModifier classes. In order to allow for smooth transition between
|
||||||
|
using the directTopoChange engine towards polyTopoChange engine, the
|
||||||
|
member functions that actually do the refinement in this class are templated
|
||||||
|
on a Type which can either be polyTopoChange engine or directTopoChange
|
||||||
|
since they provide the same interface. VV, 16/Jan/2018.
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#ifndef removeFaces_H
|
#ifndef removeFaces_H
|
||||||
|
@ -64,11 +73,11 @@ class removeFaces
|
||||||
{
|
{
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Reference to mesh
|
//- Const reference to mesh
|
||||||
const polyMesh& mesh_;
|
const polyMesh& mesh_;
|
||||||
|
|
||||||
//- Cosine of angles between boundary faces. Boundary faces can be
|
//- Cosine of angles between boundary faces. Boundary faces can be
|
||||||
// merged only if angle between faces > minCos.
|
// merged only if angle between faces is greater than minCos
|
||||||
const scalar minCos_;
|
const scalar minCos_;
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,8 +104,8 @@ class removeFaces
|
||||||
labelList& faceRegion
|
labelList& faceRegion
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Get all affected faces (including faces marked for removal)
|
//- Find and return all affected faces (including faces marked for removal)
|
||||||
boolList getFacesAffected
|
Xfer<boolList> affectedFaces
|
||||||
(
|
(
|
||||||
const labelList& cellRegion,
|
const labelList& cellRegion,
|
||||||
const labelList& cellRegionMaster,
|
const labelList& cellRegionMaster,
|
||||||
|
@ -115,14 +124,15 @@ class removeFaces
|
||||||
const fileName&
|
const fileName&
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Merge faceLabels into single face.
|
//- Merge faceLabels into single face
|
||||||
|
template<class TopoChangeEngine>
|
||||||
void mergeFaces
|
void mergeFaces
|
||||||
(
|
(
|
||||||
const labelList& cellRegion,
|
const labelList& cellRegion,
|
||||||
const labelList& cellRegionMaster,
|
const labelList& cellRegionMaster,
|
||||||
const labelHashSet& pointsToRemove,
|
const labelHashSet& pointsToRemove,
|
||||||
const labelList& faceLabels,
|
const labelList& faceLabels,
|
||||||
directTopoChange& meshMod
|
TopoChangeEngine& ref
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Get patch, zone info for faceI
|
//- Get patch, zone info for faceI
|
||||||
|
@ -135,8 +145,10 @@ class removeFaces
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return face with all pointsToRemove removed.
|
//- Return face with all pointsToRemove removed.
|
||||||
face filterFace(const labelHashSet& pointsToRemove, const label)
|
face filterFace
|
||||||
const;
|
(
|
||||||
|
const labelHashSet& pointsToRemove, const label
|
||||||
|
) const;
|
||||||
|
|
||||||
//- Wrapper for meshMod.modifyFace. Reverses face if own>nei.
|
//- Wrapper for meshMod.modifyFace. Reverses face if own>nei.
|
||||||
void modFace
|
void modFace
|
||||||
|
|
Reference in a new issue