/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2024 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "layerAdditionRemoval.H"
#include "polyMesh.H"
#include "primitiveMesh.H"
#include "polyTopoChange.H"
#include "oppositeFace.H"
#include "polyTopoChanger.H"
#include "polyRemoveCell.H"
#include "polyRemoveFace.H"
#include "polyRemovePoint.H"
#include "polyModifyFace.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::layerAdditionRemoval::validCollapse() const
{
// Check for valid layer collapse
// - no boundary-to-boundary collapse
if (debug)
{
Pout<< "Checking layer collapse for object " << name() << endl;
}
// Grab the face collapse mapping
const polyMesh& mesh = topoChanger().mesh();
const labelList& ftc = facesPairing();
const labelList& mf = mesh.faceZones()[faceZoneID_.index()];
label nBoundaryHits = 0;
forAll(mf, facei)
{
if
(
!mesh.isInternalFace(mf[facei])
&& !mesh.isInternalFace(ftc[facei])
)
{
nBoundaryHits++;
}
}
if (debug)
{
Pout<< "Finished checking layer collapse for object "
<< name() <<". Number of boundary-on-boundary hits: "
<< nBoundaryHits << endl;
}
return !returnReduceOr(nBoundaryHits);
}
void Foam::layerAdditionRemoval::removeCellLayer
(
polyTopoChange& ref
) const
{
// Algorithm for layer removal. Second phase: topological change
// 2) Go through all the faces of the master cell layer and remove
// the ones that are not in the master face zone.
//
// 3) Grab all the faces coming out of points that are collapsed
// and select the ones that are not marked for removal. Go
// through the remaining faces and replace the point to remove by
// the equivalent point in the master face zone.
if (debug)
{
Pout<< "Removing the cell layer for object " << name() << endl;
}
const polyMesh& mesh = topoChanger().mesh();
const labelList& own = mesh.faceOwner();
const labelList& nei = mesh.faceNeighbour();
const labelList& ptc = pointsPairing();
const labelList& ftc = facesPairing();
// Remove all the cells from the master layer
const labelList& mc =
mesh.faceZones()[faceZoneID_.index()].masterCells();
forAll(mc, facei)
{
label slaveSideCell = own[ftc[facei]];
if (mesh.isInternalFace(ftc[facei]) && slaveSideCell == mc[facei])
{
// Owner cell of the face is being removed.
// Grab the neighbour instead
slaveSideCell = nei[ftc[facei]];
}
ref.setAction(polyRemoveCell(mc[facei], slaveSideCell));
}
// Remove all the faces from the master layer cells which are not in
// the master face layer
labelHashSet facesToRemoveMap(mc.size()*primitiveMesh::facesPerCell_);
const cellList& cells = mesh.cells();
forAll(mc, celli)
{
const cell& curCell = cells[mc[celli]];
forAll(curCell, facei)
{
// Check if the face is in the master zone. If not, remove it
if
(
mesh.faceZones().whichZone(curCell[facei])
!= faceZoneID_.index()
)
{
facesToRemoveMap.insert(curCell[facei]);
}
}
}
for (const label facei : facesToRemoveMap)
{
ref.setAction(polyRemoveFace(facei));
}
// Remove all points that will be collapsed
for (const label pointi : ptc)
{
ref.setAction(polyRemovePoint(pointi));
}
// Grab all faces coming off points to be deleted. If the face
// has not been deleted, replace the removed point with the
// equivalent from the master layer.
// Make a map of all point to be removed, giving the master point label
// for each of them
const labelList& meshPoints =
mesh.faceZones()[faceZoneID_.index()].patch().meshPoints();
Map