Update mapping of cell data on unrefinement to include all neighbours

This commit is contained in:
Hrvoje Jasak 2019-09-09 15:06:20 +01:00
parent 814f3de0a5
commit 326c61d8ab
10 changed files with 304 additions and 219 deletions

View file

@ -147,11 +147,15 @@ int main(int argc, char *argv[])
// Topo changes container // Topo changes container
directTopoChange meshMod(mesh); directTopoChange meshMod(mesh);
// Dummy point region master
labelList pointRegionMaster(cellRegionMaster.size(), -1);
// Insert mesh refinement into directTopoChange. // Insert mesh refinement into directTopoChange.
faceRemover.setRefinement faceRemover.setRefinement
( (
facesToRemove, facesToRemove,
cellRegion, cellRegion,
pointRegionMaster,
cellRegionMaster, cellRegionMaster,
meshMod meshMod
); );

View file

@ -5345,10 +5345,17 @@ void Foam::hexRef8::setUnrefinement
// Insert all commands to combine cells. Never fails so don't have to // Insert all commands to combine cells. Never fails so don't have to
// test for success. // test for success.
// Added dummy pointRegionMaster, which will be ignored.
// Probably, splitPointLabels should be used
// HJ, 6/Sep/2019
labelList pointRegionMaster(cellRegionMaster.size(), label(-1));
faceRemover_.setRefinement faceRemover_.setRefinement
( (
facesToRemove, facesToRemove,
cellRegion, cellRegion,
pointRegionMaster,
cellRegionMaster, cellRegionMaster,
meshMod meshMod
); );

View file

@ -149,10 +149,14 @@ Foam::Xfer<Foam::boolList> Foam::removeFaces::affectedFaces
{ {
const label& region = cellRegion[cellI]; const label& region = cellRegion[cellI];
if (region != -1 && (cellI != cellRegionMaster[region])) // Bug fix: map coarse cell from all fine neighbours
// All cells will be removed and replacew with a new one from
// the central point. HJ, 9/Sep/2019
if (region != -1)
{ {
// Get this cell (list of cell faces) and mark all of its faces // Get this cell (list of cell faces) and mark all of its faces
const labelList& cFaces = meshCells[cellI]; const labelList& cFaces = meshCells[cellI];
forAll(cFaces, cFaceI) forAll(cFaces, cFaceI)
{ {
affectedFace[cFaces[cFaceI]] = true; affectedFace[cFaces[cFaceI]] = true;
@ -284,7 +288,7 @@ Foam::label Foam::removeFaces::compatibleRemoves
( (
const labelList& facesToRemove, const labelList& facesToRemove,
labelList& cellRegion, labelList& cellRegion,
labelList& regionMaster, labelList& cellRegionMaster,
labelList& newFacesToRemove labelList& newFacesToRemove
) const ) const
{ {
@ -298,8 +302,8 @@ Foam::label Foam::removeFaces::compatibleRemoves
cellRegion.setSize(nCells); cellRegion.setSize(nCells);
cellRegion = -1; cellRegion = -1;
regionMaster.setSize(nCells); cellRegionMaster.setSize(nCells);
regionMaster = -1; cellRegionMaster = -1;
// Count regions // Count regions
label nRegions = 0; label nRegions = 0;
@ -342,7 +346,7 @@ Foam::label Foam::removeFaces::compatibleRemoves
// Make owner (lowest numbered!) the master of the region and // Make owner (lowest numbered!) the master of the region and
// increment the number of regions // increment the number of regions
regionMaster[nRegions] = own; cellRegionMaster[nRegions] = own;
++nRegions; ++nRegions;
} }
else else
@ -352,7 +356,7 @@ Foam::label Foam::removeFaces::compatibleRemoves
// See if owner becomes the master of the region (if its index // See if owner becomes the master of the region (if its index
// is lower than the current master of the region) // is lower than the current master of the region)
regionMaster[region1] = min(own, regionMaster[region1]); cellRegionMaster[region1] = min(own, cellRegionMaster[region1]);
} }
} }
else else
@ -400,24 +404,29 @@ Foam::label Foam::removeFaces::compatibleRemoves
freedRegion = region0; freedRegion = region0;
} }
label master0 = regionMaster[region0]; label master0 = cellRegionMaster[region0];
label master1 = regionMaster[region1]; label master1 = cellRegionMaster[region1];
regionMaster[freedRegion] = -1; cellRegionMaster[freedRegion] = -1;
regionMaster[keptRegion] = min(master0, master1); cellRegionMaster[keptRegion] = min(master0, master1);
} }
} }
} }
// Set size // Set size
regionMaster.setSize(nRegions); cellRegionMaster.setSize(nRegions);
// Note:
// It is legal to have cellRegionMaster = -1 if the region has been created
// and then abandoned because it has been merged with another region
// HJ, 6/Sep/2019
// Various checks, additional scope for clarity and memory management // Various checks, additional scope for clarity and memory management
// - 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 // Number of cells per region
labelList nCells(regionMaster.size(), 0); labelList nCells(cellRegionMaster.size(), 0);
// Loop through cell regions // Loop through cell regions
forAll(cellRegion, cellI) forAll(cellRegion, cellI)
@ -430,15 +439,12 @@ Foam::label Foam::removeFaces::compatibleRemoves
// Region found, increment number of cells per region // Region found, increment number of cells per region
++nCells[r]; ++nCells[r];
if (cellI < regionMaster[r]) if (cellI < cellRegionMaster[r])
{ {
FatalErrorIn FatalErrorInFunction
( << "Not lowest numbered! Cell: " << cellI
"removeFaces::compatibleRemoves(const labelList&"
", labelList&, labelList&, labelList&)"
) << "Not lowest numbered! Cell: " << cellI
<< " region: " << r << " region: " << r
<< " region master: " << regionMaster[r] << " region master: " << cellRegionMaster[r]
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -449,11 +455,8 @@ Foam::label Foam::removeFaces::compatibleRemoves
{ {
if (nCells[regionI] == 1) if (nCells[regionI] == 1)
{ {
FatalErrorIn FatalErrorInFunction
( << "Region " << regionI
"removeFaces::compatibleRemoves(const labelList&"
", labelList&, labelList&, labelList&)"
) << "Region " << regionI
<< " has only " << nCells[regionI] << " cell in it." << " has only " << nCells[regionI] << " cell in it."
<< abort(FatalError); << abort(FatalError);
} }
@ -464,9 +467,9 @@ Foam::label Foam::removeFaces::compatibleRemoves
// Count number of used regions // Count number of used regions
label nUsedRegions = 0; label nUsedRegions = 0;
forAll(regionMaster, i) forAll(cellRegionMaster, i)
{ {
if (regionMaster[i] != -1) if (cellRegionMaster[i] != -1)
{ {
++nUsedRegions; ++nUsedRegions;
} }

View file

@ -28,8 +28,6 @@ Description
Given list of faces to remove insert all the topology changes. Contains Given list of faces to remove insert all the topology changes. Contains
helper function to get consistent set of faces to remove. helper function to get consistent set of faces to remove.
Not very well tested in parallel.
SourceFiles SourceFiles
removeFaces.C removeFaces.C
@ -185,6 +183,7 @@ public:
// and always merge (if on same patch) // and always merge (if on same patch)
removeFaces(const polyMesh&, const scalar minCos); removeFaces(const polyMesh&, const scalar minCos);
// Member Functions // Member Functions
//- Given a set of faces to pierce calculates: //- Given a set of faces to pierce calculates:
@ -210,7 +209,9 @@ public:
( (
const labelList& piercedFaces, const labelList& piercedFaces,
const labelList& cellRegion, const labelList& cellRegion,
const labelList& cellRegionMaster, const labelList& pointRegionMaster,
labelList& cellRegionMaster,
TopoChangeEngine& ref TopoChangeEngine& ref
) const; ) const;

View file

@ -67,18 +67,9 @@ void Foam::removeFaces::mergeFaces
if (fp.edgeLoops().size() != 1) if (fp.edgeLoops().size() != 1)
{ {
writeOBJ(fp, mesh_.time().path()/"facesToBeMerged.obj"); writeOBJ(fp, mesh_.time().path()/"facesToBeMerged.obj");
FatalErrorIn
( FatalErrorInFunction
"template<class TopoChangeEngine>" << "Cannot merge faces " << faceLabels
"void removeFaces::mergeFaces"
"\n("
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n const labelHashSet& pointsToRemove,"
"\n const labelList& faceLabels,"
"\n const TopoChangeEngine& ref"
"\n) const"
) << "Cannot merge faces " << faceLabels
<< " into single face since outside vertices " << fp.edgeLoops() << " into single face since outside vertices " << fp.edgeLoops()
<< " do not form single loop but form " << fp.edgeLoops().size() << " do not form single loop but form " << fp.edgeLoops().size()
<< " loops instead." << abort(FatalError); << " loops instead." << abort(FatalError);
@ -131,18 +122,9 @@ void Foam::removeFaces::mergeFaces
if (masterIndex == -1) if (masterIndex == -1)
{ {
writeOBJ(fp, mesh_.time().path()/"facesToBeMerged.obj"); writeOBJ(fp, mesh_.time().path()/"facesToBeMerged.obj");
FatalErrorIn
( FatalErrorInFunction
"template<class TopoChangeEngine>" << "Problem." << abort(FatalError);
"void removeFaces::mergeFaces"
"\n("
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n const labelHashSet& pointsToRemove,"
"\n const labelList& faceLabels,"
"\n const TopoChangeEngine& ref"
"\n) const"
) << "Problem." << abort(FatalError);
} }
@ -312,7 +294,8 @@ void Foam::removeFaces::setRefinement
( (
const labelList& faceLabels, const labelList& faceLabels,
const labelList& cellRegion, const labelList& cellRegion,
const labelList& cellRegionMaster, const labelList& pointRegionMaster,
labelList& cellRegionMaster,
TopoChangeEngine& ref TopoChangeEngine& ref
) const ) const
@ -343,18 +326,8 @@ void Foam::removeFaces::setRefinement
if (!mesh_.isInternalFace(faceI)) if (!mesh_.isInternalFace(faceI))
{ {
FatalErrorIn FatalErrorInFunction
( << "Face " << faceI << " is not an internal faces, therefore"
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Face " << faceI << " is not an internal faces, therefore"
<< " it cannot be removed. Check faceLabels argument." << " it cannot be removed. Check faceLabels argument."
<< abort(FatalError); << abort(FatalError);
} }
@ -446,18 +419,8 @@ void Foam::removeFaces::setRefinement
mesh_.write(); mesh_.write();
// Write data for debugging // Write data for debugging
FatalErrorIn FatalErrorInFunction
( << "Problem : edge has too few face neighbours:"
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Problem : edge has too few face neighbours:"
<< eFaces << endl << eFaces << endl
<< "edge:" << edgeI << "edge:" << edgeI
<< " vertices:" << e << " vertices:" << e
@ -586,18 +549,8 @@ void Foam::removeFaces::setRefinement
const edge& e = mesh_.edges()[edgeI]; const edge& e = mesh_.edges()[edgeI];
// Only found one boundary face. Problem // Only found one boundary face. Problem
FatalErrorIn FatalErrorInFunction
( << "Problem : edge would have one boundary face"
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Problem : edge would have one boundary face"
<< " and one internal face using it." << endl << " and one internal face using it." << endl
<< "Your remove pattern is probably incorrect." << endl << "Your remove pattern is probably incorrect." << endl
<< "edge:" << edgeI << "edge:" << edgeI
@ -620,18 +573,7 @@ void Foam::removeFaces::setRefinement
{ {
const edge& e = mesh_.edges()[edgeI]; const edge& e = mesh_.edges()[edgeI];
FatalErrorIn FatalErrorInFunction
(
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
)
<< "Problem : edge would get 1 face using it only" << "Problem : edge would get 1 face using it only"
<< " edge:" << edgeI << " edge:" << edgeI
<< " nFaces:" << nFacesPerEdge[edgeI] << " nFaces:" << nFacesPerEdge[edgeI]
@ -779,18 +721,8 @@ void Foam::removeFaces::setRefinement
if (nRegion < 1) if (nRegion < 1)
{ {
FatalErrorIn FatalErrorInFunction
( << "Problem with region number." << abort(FatalError);
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Problem with region number." << abort(FatalError);
} }
else if (nRegion == 1) else if (nRegion == 1)
{ {
@ -837,18 +769,8 @@ void Foam::removeFaces::setRefinement
{ {
if (nbrRegion != myRegion) if (nbrRegion != myRegion)
{ {
FatalErrorIn FatalErrorInFunction
( << "Inconsistent face region across coupled patches."
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Inconsistent face region across coupled patches."
<< endl << endl
<< "This side has for faceI:" << faceI << "This side has for faceI:" << faceI
<< " region:" << myRegion << endl << " region:" << myRegion << endl
@ -868,18 +790,8 @@ void Foam::removeFaces::setRefinement
// Second visit of this region // Second visit of this region
if (toNbrRegion[myRegion] != nbrRegion) if (toNbrRegion[myRegion] != nbrRegion)
{ {
FatalErrorIn FatalErrorInFunction
( << "Inconsistent face region across coupled patches."
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Inconsistent face region across coupled patches."
<< endl << endl
<< "This side has for faceI:" << faceI << "This side has for faceI:" << faceI
<< " region:" << myRegion << " region:" << myRegion
@ -938,18 +850,8 @@ void Foam::removeFaces::setRefinement
{ {
if (nEdgesPerPoint[pointI] == 1) if (nEdgesPerPoint[pointI] == 1)
{ {
FatalErrorIn FatalErrorInFunction
( << "Problem : point would get 1 edge using it only."
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Problem : point would get 1 edge using it only."
<< " pointI:" << pointI << " pointI:" << pointI
<< " coord:" << mesh_.points()[pointI] << " coord:" << mesh_.points()[pointI]
<< abort(FatalError); << abort(FatalError);
@ -1060,11 +962,43 @@ void Foam::removeFaces::setRefinement
ref.setAction(polyRemovePoint(pointI, -1)); ref.setAction(polyRemovePoint(pointI, -1));
} }
// Add master cells for correct mapping
forAll (cellRegionMaster, regionI)
{
// Note: it is legal to have cellRegionMaster = -1 if the region
// has been created and them marged into another region.
// Such masters will also have pointRegionMaster = -1 and should
// be ignored. HJ, 6/Sep/2019
// Additionally protect for old directTopoChangers which do not
// identify points for mapping. Non-existent pointRegionMaster
// is rejected
if (cellRegionMaster[regionI] > -1 && pointRegionMaster[regionI] > -1)
{
// Add master cell from master point for correct mapping
cellRegionMaster[regionI] =
ref.setAction
(
polyAddCell
(
pointRegionMaster[regionI], // masterPointID
-1, // masterEdgeID
-1, // masterFaceID
-1, // masterCellID
mesh_.cellZones().whichZone(cellRegionMaster[regionI])
)
);
}
}
// Remove cells // Remove cells
forAll(cellRegion, cellI) forAll(cellRegion, cellI)
{ {
label region = cellRegion[cellI]; label region = cellRegion[cellI];
// Old check is acceptable: for mapping from point, the cellRegionMaster
// has been replaced in polyAddPoint
// HJ, 6/Sep/2019
if (region != -1 && (cellI != cellRegionMaster[region])) if (region != -1 && (cellI != cellRegionMaster[region]))
{ {
ref.setAction(polyRemoveCell(cellI, cellRegionMaster[region])); ref.setAction(polyRemoveCell(cellI, cellRegionMaster[region]));
@ -1087,18 +1021,8 @@ void Foam::removeFaces::setRefinement
if (rFaces.size() <= 1) if (rFaces.size() <= 1)
{ {
FatalErrorIn FatalErrorInFunction
( << "Region: " << regionI
"template<class TopoChangeEngine>"
"\n"
"void removeFaces::setRefinement"
"\n("
"\n const labelList& faceLabels,"
"\n const labelList& cellRegion,"
"\n const labelList& cellRegionMaster,"
"\n TopoChangeEngine& ref"
"\n)"
) << "Region: " << regionI
<< " contains only these faces: " << rFaces << " contains only these faces: " << rFaces
<< abort(FatalError); << abort(FatalError);
} }

View file

@ -634,10 +634,16 @@ Foam::labelList Foam::undoableMeshCutter::removeSplitFaces
// Insert all commands to combine cells. Never fails so don't have to // Insert all commands to combine cells. Never fails so don't have to
// test for success. // test for success.
// Added dummy pointRegionMaster, which will be ignored.
// HJ, 6/Sep/2019
labelList pointRegionMaster(cellRegionMaster.size(), label(-1));
faceRemover().setRefinement faceRemover().setRefinement
( (
facesToRemove, facesToRemove,
cellRegion, cellRegion,
pointRegionMaster,
cellRegionMaster, cellRegionMaster,
meshMod meshMod
); );

View file

@ -1260,10 +1260,8 @@ void Foam::polyhedralRefinement::setRefinementInstruction
// cell points // cell points
const labelList& cPoints = meshCellPoints[cellI]; const labelList& cPoints = meshCellPoints[cellI];
FatalErrorIn FatalErrorInFunction
( << "Cell " << cellI
"polyhedralRefinement::setRefinementInstruction(...)"
) << "Cell " << cellI
<< " of level " << cellLevel_[cellI] << " of level " << cellLevel_[cellI]
<< " does not seem to have enough points of " << " does not seem to have enough points of "
<< " lower level" << endl << " lower level" << endl
@ -1967,11 +1965,73 @@ void Foam::polyhedralRefinement::setUnrefinementInstruction
} }
} }
// Find point region master for every cell region. This is the central point
// from which the coarse cell will be made
// The property of the point region master is that all cells that touch it
// have the same cell region index
// HJ, 6/Sep/2019
labelList pointRegionMaster(cellRegionMaster.size(), label(-1));
// Get point-cell addressing
const labelListList& pc = mesh_.pointCells();
forAll (splitPointsToUnrefine_, i)
{
const labelList& curPc = pc[splitPointsToUnrefine_[i]];
label curRegion = -1;
forAll (curPc, curPcI)
{
if (curRegion == -1)
{
// First region found. Grab it
curRegion = cellRegion[curPc[curPcI]];
}
else
{
// Region already found. Check that all other cells that
// touch this point have the same region
if (curRegion != cellRegion[curPc[curPcI]])
{
// Error: different region cells touching in split point
// This is not a valid unrefinement pattern
FatalErrorIn
(
"polyhedralRefinement::setUnrefinementInstruction"
"(polyTopoChange& ref)"
) << "Different region cells touching in split point."
<< abort(FatalError);
}
}
}
// Record point region master
if (curRegion > -1)
{
pointRegionMaster[curRegion] = splitPointsToUnrefine_[i];
}
else
{
// Error: Cannot find region for point
FatalErrorIn
(
"polyhedralRefinement::setUnrefinementInstruction"
"(polyTopoChange& ref)"
) << "Different region cells touching in split point."
<< abort(FatalError);
}
}
Info<< "pointRegionMaster: " << pointRegionMaster << nl
<< " cellRegionMaster: " << cellRegionMaster << endl;
// Insert all commands to combine cells // Insert all commands to combine cells
faceRemover_.setRefinement faceRemover_.setRefinement
( (
facesToRemove, facesToRemove,
cellRegion, cellRegion,
pointRegionMaster,
cellRegionMaster, cellRegionMaster,
ref ref
); );

View file

@ -2329,7 +2329,7 @@ void Foam::prismatic2DRefinement::setRefinementInstruction
if (minPointI != labelMax && minPointI != mesh_.nPoints()) if (minPointI != labelMax && minPointI != mesh_.nPoints())
{ {
FatalErrorIn("prismatic2DRefinement::setRefinementInstruction(...)") FatalErrorInFunction
<< "Added point labels not consecutive to existing mesh points." << "Added point labels not consecutive to existing mesh points."
<< nl << nl
<< "mesh_.nPoints():" << mesh_.nPoints() << "mesh_.nPoints():" << mesh_.nPoints()
@ -2352,10 +2352,8 @@ void Foam::prismatic2DRefinement::setUnrefinementInstruction
// Check whether the refinementLevelIndicator is valid // Check whether the refinementLevelIndicator is valid
if (refinementLevelIndicator_.size() != mesh_.nCells()) if (refinementLevelIndicator_.size() != mesh_.nCells())
{ {
FatalErrorIn FatalErrorInFunction
( << "Refinement level indicator list has invalid size: "
"prismatic2DRefinement::setUnrefinementInstruction(...)"
) << "Refinement level indicator list has invalid size: "
<< refinementLevelIndicator_.size() << refinementLevelIndicator_.size()
<< ", number of cells: " << mesh_.nCells() << ", number of cells: " << mesh_.nCells()
<< nl << nl
@ -2379,11 +2377,8 @@ void Foam::prismatic2DRefinement::setUnrefinementInstruction
{ {
if (cellLevel_[cellI] < 0) if (cellLevel_[cellI] < 0)
{ {
FatalErrorIn FatalErrorInFunction
( << "Illegal cell level " << cellLevel_[cellI]
"prismatic2DRefinement::setUnrefinementInstruction"
"(polyTopoChange& ref)"
) << "Illegal cell level " << cellLevel_[cellI]
<< " for cell " << cellI << " for cell " << cellI
<< abort(FatalError); << abort(FatalError);
} }
@ -2526,11 +2521,70 @@ void Foam::prismatic2DRefinement::setUnrefinementInstruction
} }
} }
// Find point region master for every cell region. This is the central point
// from which the coarse cell will be made
// The property of the point region master is that all cells that touch it
// have the same cell region index
// HJ, 6/Sep/2019
labelList pointRegionMaster(cellRegionMaster.size(), label(-1));
// Get point-cell addressing
const labelListList& pc = mesh_.pointCells();
forAll (splitPointsToUnrefine_, i)
{
const labelList& curPc = pc[splitPointsToUnrefine_[i]];
label curRegion = -1;
forAll (curPc, curPcI)
{
if (curRegion == -1)
{
// First region found. Grab it
curRegion = cellRegion[curPc[curPcI]];
}
else
{
// Region already found. Check that all other cells that
// touch this point have the same region
if (curRegion != cellRegion[curPc[curPcI]])
{
// Error: different region cells touching in split point
// This is not a valid unrefinement pattern
FatalErrorIn
(
"polyhedralRefinement::setUnrefinementInstruction"
"(polyTopoChange& ref)"
) << "Different region cells touching in split point."
<< abort(FatalError);
}
}
}
// Record point region master
if (curRegion > -1)
{
pointRegionMaster[curRegion] = splitPointsToUnrefine_[i];
}
else
{
// Error: Cannot find region for point
FatalErrorIn
(
"polyhedralRefinement::setUnrefinementInstruction"
"(polyTopoChange& ref)"
) << "Different region cells touching in split point."
<< abort(FatalError);
}
}
// Insert all commands to combine cells // Insert all commands to combine cells
faceRemover_.setRefinement faceRemover_.setRefinement
( (
facesToRemove, facesToRemove,
cellRegion, cellRegion,
pointRegionMaster,
cellRegionMaster, cellRegionMaster,
ref ref
); );

View file

@ -23,6 +23,7 @@ License
Author Author
Vuko Vukcevic, Wikki Ltd. All rights reserved. Vuko Vukcevic, Wikki Ltd. All rights reserved.
Hrvoje Jasak, Wikki Ltd.
Notes Notes
Generalisation of hexRef8 for polyhedral cells and refactorisation into mesh Generalisation of hexRef8 for polyhedral cells and refactorisation into mesh
@ -423,6 +424,54 @@ Foam::label Foam::refinement::countAnchors
return nAnchors; return nAnchors;
} }
void Foam::refinement::adjustRefLevel
(
label& curNewCellLevel,
const label oldCellI
)
{
if (oldCellI == -1)
{
// This cell is inflated (does not originate from other cell), set
// cell level to -1
curNewCellLevel = -1;
}
else
{
// This cell has either been added based on another cell or it
// hasn't changed. Update new cell level according to refinement
// level indicator and old cell level
// Get refinement status of the old cell
const label& refStatus = refinementLevelIndicator_[oldCellI];
if (refStatus == UNREFINED)
{
// New cell has been obtained by unrefining other cells - this
// is the remaining "master" cell. Decrement cell level
curNewCellLevel = cellLevel_[oldCellI] - 1;
}
else if (refStatus == UNCHANGED)
{
// Cell hasn't been changed during this refinement, copy old
// cell level
curNewCellLevel = cellLevel_[oldCellI];
}
else if (refStatus == REFINED)
{
// Cell has been refined, increment cell level
curNewCellLevel = cellLevel_[oldCellI] + 1;
}
else
{
FatalErrorInFunction
<< "Invalid refinement status detected: "
<< refStatus << nl
<< "Old cell index: " << oldCellI << abort(FatalError);
}
}
}
void Foam::refinement::checkInternalOrientation void Foam::refinement::checkInternalOrientation
( (
@ -1386,51 +1435,21 @@ void Foam::refinement::updateMesh(const mapPolyMesh& map)
// Loop through all new cells // Loop through all new cells
forAll (cellMap, newCellI) forAll (cellMap, newCellI)
{ {
// Get index of the corresponding old cell adjustRefLevel(newCellLevel[newCellI], cellMap[newCellI]);
const label& oldCellI = cellMap[newCellI]; }
if (oldCellI == -1) // Do cells from points: unrefinement
{ // Note: should other types be done as well?
// This cell is inflated (does not originate from other cell), set // HJ, 9/Sep/2019
// cell level to -1 const List<objectMap>& cellsFromPoints = map.cellsFromPointsMap();
newCellLevel[newCellI] = -1;
}
else
{
// This cell has either been added based on another cell or it
// hasn't changed. Update new cell level according to refinement
// level indicator and old cell level
// Get refinement status of the old cell forAll (cellsFromPoints, cfpI)
const label& refStatus = refinementLevelIndicator_[oldCellI]; {
adjustRefLevel
if (refStatus == UNREFINED) (
{ newCellLevel[cellsFromPoints[cfpI].index()],
// New cell has been obtained by unrefining other cells - this cellsFromPoints[cfpI].masterObjects()[0]
// is the remaining "master" cell. Decrement cell level );
newCellLevel[newCellI] = cellLevel_[oldCellI] - 1;
}
else if (refStatus == UNCHANGED)
{
// Cell hasn't been changed during this refinement, copy old
// cell level
newCellLevel[newCellI] = cellLevel_[oldCellI];
}
else if (refStatus == REFINED)
{
// Cell has been refined, increment cell level
newCellLevel[newCellI] = cellLevel_[oldCellI] + 1;
}
else
{
FatalErrorIn
(
"refinement::updateMesh(const mapPolyMesh& map)"
) << "Invalid refinement status detected: " << refStatus << nl
<< "Old cell index: " << oldCellI << nl
<< "New cell index: " << newCellI << abort(FatalError);
}
}
} }
// Transfer the new cell level into the data member // Transfer the new cell level into the data member

View file

@ -232,7 +232,14 @@ protected:
const label anchorLevel const label anchorLevel
) const; ) const;
//- Adjust cell refinement level after topo change
void adjustRefLevel
(
label& curNewCellLevel,
const label oldCellI
);
// Debug functions // Debug functions
//- Check orientation of added internal face //- Check orientation of added internal face