Updates to polyhedralRefinement and dynamicPolyRefinementFvMesh

1. Switched from pointBasedConsistency to edgeBasedConsistency in order to allow
   more than 2 refinement levels in a correct way (hopefully),
2. Note on parallelisation: getting edge cell addressing across processor
   boundaries is tricky, but if we use more stringent 1:1 face refinement across
   coupled boundaries, then the edge based consistency becomes a local operation
   (at least I'm 99% sure it does: hard to think of all variants with arbitrary
   polyhedra),
3. Added an option to skip unrefinement if both refinement/unrefinement are
   triggered for a single step. This is switched off by default since performing
   refinement/unrefinement in a single go should work without issues.
This commit is contained in:
Vuko Vukcevic 2018-04-17 12:24:52 +02:00
parent 4a4056f9f5
commit 9ee5d49575
5 changed files with 219 additions and 182 deletions

View file

@ -2930,15 +2930,19 @@ Foam::label Foam::polyhedralRefinement::faceConsistentRefinement
const label curOwnLevel =
cellsToRefine[own] ? cellLevel_[own] + 1 : cellLevel_[own];
if (neiLevel[i] > (curOwnLevel + 1))
// Note: we are using more stringent 1:1 consistency across coupled
// boundaries in order to simplify handling of edge based consistency
// checks for parallel runs
if (neiLevel[i] > curOwnLevel)
{
// Neighbour level is higher than owner level + 1, owner must be
// Neighbour level is higher than owner level, owner must be
// marked for refinement
cellsToRefine[own] = true;
++nAddCells;
}
// Note: other possibility (that owner level is higher than neighbour
// level + 1) is taken into account on the other side automatically
// level) is taken into account on the other side automatically
}
// Return number of added cells
@ -2946,7 +2950,7 @@ Foam::label Foam::polyhedralRefinement::faceConsistentRefinement
}
Foam::label Foam::polyhedralRefinement::pointConsistentRefinement
Foam::label Foam::polyhedralRefinement::edgeConsistentRefinement
(
boolList& cellsToRefine
) const
@ -2954,92 +2958,75 @@ Foam::label Foam::polyhedralRefinement::pointConsistentRefinement
// Count number of cells that will be added
label nAddCells = 0;
// Maximum surrounding cell refinement level for each point
labelList maxRefLevel(mesh_.nPoints(), 0);
// Algorithm: loop over all edges and visit all unique cell pairs sharing
// this particular edge. Then, ensure 2:1 edge consistency by marking
// cell with lower level for refinement
// Get point cells
const labelListList& meshPointCells = mesh_.pointCells();
// Get edge cells
const labelListList& meshEdgeCells = mesh_.edgeCells();
// Loop through all points and collect maximum point level for each point
forAll (maxRefLevel, pointI)
// Loop through all mesh edges
forAll (meshEdgeCells, edgeI)
{
// Get the cells for this point
const labelList& curCells = meshPointCells[pointI];
// Get current edge cells
const labelList& curEdgeCells = meshEdgeCells[edgeI];
// Get reference to maximum pooint level for this point
label& curMaxPointLevel = maxRefLevel[pointI];
// Find maximum refinement level for this point
forAll (curCells, i)
// Loop through all edge cells
forAll (curEdgeCells, i)
{
// Get cell index and "future" cell level
const label& curCellI = curCells[i];
const label curCellLevel =
cellsToRefine[curCellI]
? cellLevel_[curCellI] + 1
: cellLevel_[curCellI];
// Get first cell index
const label& cellI = curEdgeCells[i];
// Update maximum point level if the curCellLevel is higher
curMaxPointLevel = max(curMaxPointLevel, curCellLevel);
}
}
// Sync maximum refinement level across coupled boundaries
syncTools::syncPointList
(
mesh_,
maxRefLevel,
maxEqOp<label>(),
0, // Null value
true // Apply separation for parallel cyclics
);
// Now that the levels are synced, go through all points and add cells to
// refine
forAll (maxRefLevel, pointI)
{
// Get the cells for this point
const labelList& curCells = meshPointCells[pointI];
// Loop through these point cells and set cells for refinement which
// would end up having refinement level smaller than maximum level - 1
forAll (curCells, i)
{
// Get cell index, reference to refinement flag and "future" cell
// level
const label& curCellI = curCells[i];
bool& willBeRefined = cellsToRefine[curCellI];
const label curCellLevel =
willBeRefined
? cellLevel_[curCellI] + 1
: cellLevel_[curCellI];
if (curCellLevel < maxRefLevel[pointI] - 1)
// Loop through remaining edge cells
for (label j = i + 1; j < curEdgeCells.size(); ++j)
{
if (!willBeRefined)
// Get second cell index
const label& cellJ = curEdgeCells[j];
// Get levels of the two cells. If the cell is marked for
// refinement, the level is current level + 1, otherwise it is
// equal to the current level
// Note: cellsToRefine flag for both cellI and cellJ might
// change, this is why we need to recalculate cellI level here
const label cellILevel =
cellsToRefine[cellI]
? cellLevel_[cellI] + 1
: cellLevel_[cellI];
const label cellJLevel =
cellsToRefine[cellJ]
? cellLevel_[cellJ] + 1
: cellLevel_[cellJ];
if (cellILevel > cellJLevel + 1)
{
// Cell has not been marked for refinement, mark the cell
// for refinement and increment the counter
willBeRefined = true;
// Level of cellI is higher than level of cellJ + 1, cellJ
// must be marked for refinement
cellsToRefine[cellJ] = true;
++nAddCells;
}
else
else if (cellJLevel > cellILevel + 1)
{
FatalErrorIn
(
"label polyhedralRefinement::pointConsistentRefinement"
"(boolList cellsToRefine) const"
) << "Cell: " << curCellI << " is marked for refinement,"
<< "but the 4:1 consistency cannot be ensured." << nl
<< "This is probably because the refinement and "
<< "unrefinement regions are very close." << nl
<< "Try increasing nUnrefinementBufferLayers. "
<< abort(FatalError);
// Level of cellJ is higher than level of cellI + 1, cellI
// must be marked for refinement
cellsToRefine[cellI] = true;
++nAddCells;
}
}
}
}
// Note: in order to avoid very difficult and time-consuming parallelisation
// of edge cell connectivity and edge cell values, we enforce a more
// stringent face-based consistency across processor boundaries. Basically,
// if a face-based consistency of 1:1 (not 2:1 as for ordinary faces) is
// ensured, the edge-based consistency becomes a local operation (I'm not
// 100% sure to be honest since there are countless variants when dealing
// with arbitrary polyhedral cells).
// See faceConsistentRefinement for details. VV, 17/Apr/2018.
// Return number of added cells
return nAddCells;
}
@ -3074,7 +3061,7 @@ Foam::label Foam::polyhedralRefinement::faceConsistentUnrefinement
const label neiLevel =
cellsToUnrefine[nei] ? cellLevel_[nei] - 1 : cellLevel_[nei];
if (ownLevel < (neiLevel -1))
if (ownLevel < (neiLevel - 1))
{
// Owner level is smaller than neighbour level - 1, we must not
// unrefine owner
@ -3158,9 +3145,12 @@ Foam::label Foam::polyhedralRefinement::faceConsistentUnrefinement
const label curOwnLevel =
cellsToUnrefine[own] ? cellLevel_[own] - 1 : cellLevel_[own];
if (curOwnLevel < (neiLevel[i] - 1))
// Note: we are using more stringent 1:1 consistency across coupled
// boundaries in order to simplify handling of edge based consistency
// checkes for parallel runs
if (curOwnLevel < neiLevel[i])
{
// Owner level is smaller than neighbour level - 1, we must not
// Owner level is smaller than neighbour level, we must not
// unrefine owner
// Check whether the cell has not been marked for unrefinement
@ -3188,7 +3178,7 @@ Foam::label Foam::polyhedralRefinement::faceConsistentUnrefinement
}
// Note: other possibility (that neighbour level is smaller than owner
// level - 1) is taken into account on the other side automatically
// level) is taken into account on the other side automatically
}
// Return number of local cells removed from unrefinement
@ -3196,107 +3186,129 @@ Foam::label Foam::polyhedralRefinement::faceConsistentUnrefinement
}
Foam::label Foam::polyhedralRefinement::pointConsistentUnrefinement
Foam::label Foam::polyhedralRefinement::edgeConsistentUnrefinement
(
boolList& cellsToUnrefine
) const
{
// Count number of cells removed from unrefinement
// Count number of cells that will be removed
label nRemCells = 0;
// Minimum cell refinement level for each point. Note: initialise with
// labelMax
labelList minRefLevel(mesh_.nPoints(), labelMax);
// Algorithm: loop over all edges and visit all unique cell pairs sharing
// this particular edge. Then, ensure 2:1 edge consistency by protecting the
// cell with lower level from unrefinement
// Get point cells
const labelListList& meshPointCells = mesh_.pointCells();
// Get edge cells
const labelListList& meshEdgeCells = mesh_.edgeCells();
// Loop through all points and collect minimum point level for each point
forAll (minRefLevel, pointI)
// Loop through all mesh edges
forAll (meshEdgeCells, edgeI)
{
// Get the cell for this point
const labelList& curCells = meshPointCells[pointI];
// Get current edge cells
const labelList& curEdgeCells = meshEdgeCells[edgeI];
// Get reference to minimum point level for this point
label& curMinPointLevel = minRefLevel[pointI];
// Find minimum refinement level for this point
forAll (curCells, i)
// Loop through all edge cells
forAll (curEdgeCells, i)
{
// Get cell index and "future" cell level
const label& curCellI = curCells[i];
const label curCellLevel =
cellsToUnrefine[curCellI]
? cellLevel_[curCellI] - 1
: cellLevel_[curCellI];
// Get first cell index
const label& cellI = curEdgeCells[i];
// Update minimum point level if the curCellLevel is smaller
curMinPointLevel = min(curMinPointLevel, curCellLevel);
}
}
// Sync minimum refinement level across coupled boundaries
syncTools::syncPointList
(
mesh_,
minRefLevel,
minEqOp<label>(),
0, // Null value
true // Apply separation for parallel cyclics
);
// Now that the levels are synced, go through all points and protect some
// cells from unrefinement
forAll (minRefLevel, pointI)
{
// Get the cells for this point
const labelList& curCells = meshPointCells[pointI];
// Loop through these point cells and protected cells from unrefinement
// which would end up having refinement level greater than level + 1
forAll (curCells, i)
{
// Get cell index, reference to unrefinement flag and "future" cell
// level
const label& curCellI = curCells[i];
bool& willBeUnrefined = cellsToUnrefine[curCellI];
const label curCellLevel =
willBeUnrefined
? cellLevel_[curCellI] - 1
: cellLevel_[curCellI];
if (curCellLevel > minRefLevel[pointI] + 1)
// Loop through remaining edge cells
for (label j = i + 1; j < curEdgeCells.size(); ++j)
{
if (willBeUnrefined)
// Get second cell index
const label& cellJ = curEdgeCells[j];
// Get levels of the two cells. If the cell is marked for
// unrefinement, the level is current level - 1, otherwise it is
// equal to the current level
// Note: cellsToUnrefine flag for both cellI and cellJ might
// change, this is why we need to recalculate cellI level here
const label cellILevel =
cellsToUnrefine[cellI]
? cellLevel_[cellI] - 1
: cellLevel_[cellI];
const label cellJLevel =
cellsToUnrefine[cellJ]
? cellLevel_[cellJ] - 1
: cellLevel_[cellJ];
if (cellILevel < cellJLevel - 1)
{
// Cell has been marked for unrefinement, protect the cell
// from unrefinement and increment the counter
willBeUnrefined = false;
// Level of cellI is smaller than level of cellJ - 1, cellI
// must be protected from unrefinement
// Check whether the cell has not been marked for
// unrefinement
if (!cellsToUnrefine[cellI])
{
FatalErrorIn
(
"label polyhedralRefinement::"
"edgeConsistentUnrefinement"
"(boolList& cellsToUnrefine)"
) << "Cell not marked for unrefinement, indicating a"
<< " previous unnoticed problem with unrefinement."
<< nl
<< "cellI: " << cellI << ", cellJ: " << cellJ
<< nl
<< "Level of cellI: " << cellILevel
<< ", level of cellJ: " << cellJLevel << nl
<< "This is probably because the refinement and "
<< "unrefinement regions are very close." << nl
<< "Try increasing nUnrefinementBufferLayers. "
<< abort(FatalError);
}
cellsToUnrefine[cellI] = false;
++nRemCells;
}
else if (cellJLevel < cellILevel - 1)
{
// Level of cellJ is smaller than level of cellI - 1, cellJ
// must be protected from unrefinement
// Check whether the cell has not been marked for
// unrefinement
if (!cellsToUnrefine[cellJ])
{
FatalErrorIn
(
"label polyhedralRefinement::"
"edgeConsistentUnrefinement"
"(boolList& cellsToUnrefine)"
) << "Cell not marked for unrefinement, indicating a"
<< " previous unnoticed problem with unrefinement."
<< nl
<< "cellI: " << cellI << ", cellJ: " << cellJ
<< nl
<< "Level of cellI: " << cellILevel
<< ", level of cellJ: " << cellJLevel << nl
<< "This is probably because the refinement and "
<< "unrefinement regions are very close." << nl
<< "Try increasing nUnrefinementBufferLayers. "
<< abort(FatalError);
}
cellsToUnrefine[cellJ] = false;
++nRemCells;
}
// Note: I am pretty sure that this check is redundant and
// causes unnecessary issues when more than 2 maximum refinement
// levels are used. In case of problems, take a detailed look
// here. VV, 22/Mar/2018.
// else
// {
// FatalErrorIn
// (
// "label polyhedralRefinement::"
// "pointConsistentUnrefinement"
// "(boolList cellsToRefine) const"
// ) << "Cell: " << curCellI << " is not marked for "
// << "unrefinement, but the 4:1"
// << " point consistency cannot be ensured." << nl
// << "This is probably because the refinement and "
// << "unrefinement regions are very close." << nl
// << "Try increasing nUnrefinementBufferLayers. "
// << abort(FatalError);
// }
}
}
}
// Note: in order to avoid very difficult and time-consuming parallelisation
// of edge cell connectivity and edge cell values, we enforce a more
// stringent face-based consistency across processor boundaries. Basically,
// if a face-based consistency of 1:1 (not 2:1 as for ordinary faces) is
// ensured, the edge-based consistency becomes a local operation (I'm not
// 100% sure to be honest whether this is true all the time since there are
// countless variants when dealing with arbitrary polyhedral cells).
// See faceConsistentRefinement for details. VV, 3/Apr/2018.
// Return number of removed cells
return nRemCells;
}
@ -3346,9 +3358,9 @@ Foam::polyhedralRefinement::polyhedralRefinement
faceRemover_(mesh_, GREAT), // Merge boundary faces wherever possible
maxCells_(readLabel(dict.lookup("maxCells"))),
maxRefinementLevel_(readLabel(dict.lookup("maxRefinementLevel"))),
pointBasedConsistency_
edgeBasedConsistency_
(
dict.lookupOrDefault<Switch>("pointBasedConsistency", true)
dict.lookupOrDefault<Switch>("edgeBasedConsistency", true)
),
nRefinementBufferLayers_
(
@ -3426,7 +3438,7 @@ Foam::polyhedralRefinement::polyhedralRefinement
// If the maximum refinementLevel is greater than 2 and the user insists on
// not using point based refinement strategy, issue a warning
if (!pointBasedConsistency_ && maxRefinementLevel_ > 2)
if (!edgeBasedConsistency_ && maxRefinementLevel_ > 2)
{
WarningIn
(
@ -3445,7 +3457,7 @@ Foam::polyhedralRefinement::polyhedralRefinement
<< " 8:1 point conflicts."
<< nl
<< "In order to supress this message and use point based"
<< " consistency checks, set pointBasedConsistency to true."
<< " consistency checks, set edgeBasedConsistency to true."
<< endl;
}
@ -3583,11 +3595,11 @@ void Foam::polyhedralRefinement::setCellsToRefine
// Reset counter at the beginning of each iteration
nAddCells = 0;
if (pointBasedConsistency_)
if (edgeBasedConsistency_)
{
// Check for 4:1 point based consistent refinement. Updates
// Check for 4:1 edge based consistent refinement. Updates
// cellsToRefine and returns number of cells added in this iteration
nAddCells += pointConsistentRefinement(refineCell);
nAddCells += edgeConsistentRefinement(refineCell);
}
// Check for 2:1 face based consistent refinement. Updates cellsToRefine
@ -3836,12 +3848,12 @@ void Foam::polyhedralRefinement::setSplitPointsToUnrefine
// Reset number of removed cells from unrefinement for this iteration
nRemCells = 0;
if (pointBasedConsistency_)
if (edgeBasedConsistency_)
{
// Check for 4:1 point based consistent unrefinement. Updates
// Check for 4:1 edge based consistent unrefinement. Updates
// cellsToUnrefine and returns number of removed cells from
// unrefinement in this iteration
nRemCells += pointConsistentUnrefinement(cellsToUnrefine);
nRemCells += edgeConsistentUnrefinement(cellsToUnrefine);
}
// Check for 2:1 face based consistent unrefinement. Updates
@ -4126,7 +4138,7 @@ void Foam::polyhedralRefinement::write(Ostream& os) const
<< name() << nl
<< maxCells_ << nl
<< maxRefinementLevel_ << nl
<< pointBasedConsistency_ << nl
<< edgeBasedConsistency_ << nl
<< nRefinementBufferLayers_ << nl
<< nUnrefinementBufferLayers_ << endl;
}
@ -4145,7 +4157,7 @@ void Foam::polyhedralRefinement::writeDict(Ostream& os) const
<< token::END_STATEMENT << nl
<< " maxRefinementLevel " << maxRefinementLevel_
<< token::END_STATEMENT << nl
<< " pointBasedConsistency " << pointBasedConsistency_
<< " edgeBasedConsistency " << edgeBasedConsistency_
<< token::END_STATEMENT << nl
<< " nRefinementBufferLayers " << nRefinementBufferLayers_
<< token::END_STATEMENT << nl

View file

@ -124,8 +124,8 @@ private:
//- Maximum number of refinement levels for a given cell
label maxRefinementLevel_;
//- Switch whether to use point based consistency on refinement
Switch pointBasedConsistency_;
//- Switch whether to use edge based consistency on refinement
Switch edgeBasedConsistency_;
//- Number of buffer layers for refinement
label nRefinementBufferLayers_;
@ -363,17 +363,17 @@ private:
// is obtained. Returns local number of cells changed
label faceConsistentRefinement(boolList& cellsToRefine) const;
//- Updates cellsToRefine such that a point consistent 4:1 refinement
//- Updates cellsToRefine such that an edge consistent 4:1 refinement
// is obtained. Returns local number of cells changed
label pointConsistentRefinement(boolList& cellsToRefine) const;
label edgeConsistentRefinement(boolList& cellsToRefine) const;
//- Updates cellsToUnrefine such that a face consistent 2:1
// unrefinement is obtained. Returns local number of cells changed
label faceConsistentUnrefinement(boolList& cellsToUnrefine) const;
//- Updates cellsToUnrefine such that a point consistent 4:1
//- Updates cellsToUnrefine such that an edge consistent 4:1
// unrefinement is obtained. Returns local number of cells changed
label pointConsistentUnrefinement(boolList& cellsToUnrefine) const;
label edgeConsistentUnrefinement(boolList& cellsToUnrefine) const;
// Copy control

View file

@ -27,6 +27,12 @@ dynamicPolyRefinementFvMeshCoeffs
// Unrefine every unrefineInterval step
unrefineInterval 1;
// Separate refinement/unrefinement steps. In case this is switched on,
// if both refinement and unrefinement should have been performed in a
// single step, unrefinement is skipped. Switched off by default, meaning
// that it should be safe to perform both at the same time
separateUpdates false;
// Refinement selection criteria
refinementSelection
{
@ -59,9 +65,9 @@ dynamicPolyRefinementFvMeshCoeffs
// level inconsistencies
nUnrefinementBufferLayers 4;
// Whether to use point based consistency check. Needed when one allows more
// than 2 refinement levels (automatically switched on in that case)
pointBasedRefinement yes;
// Whether to use edge based consistency check. Needed when one allows more
// than 2 refinement levels (automatically switched on)
edgeBasedConsistency yes;
}

View file

@ -59,7 +59,7 @@ void Foam::dynamicPolyRefinementFvMesh::readDict()
<< " trigerring within a certain time step and should be > 0"
<< exit(FatalError);
}
unrefineInterval_ = readLabel(refinementDict_.lookup("unrefineInterval"));
if (refineInterval_ < 1)
{
@ -69,6 +69,10 @@ void Foam::dynamicPolyRefinementFvMesh::readDict()
<< " trigerring within a certain time step and should be > 0"
<< exit(FatalError);
}
// Read separate updates switch
separateUpdates_ =
refinementDict_.lookupOrDefault<Switch>("separateUpdates", false);
}
@ -97,6 +101,10 @@ Foam::dynamicPolyRefinementFvMesh::dynamicPolyRefinementFvMesh
),
refineInterval_(readLabel(refinementDict_.lookup("refineInterval"))),
unrefineInterval_(readLabel(refinementDict_.lookup("unrefineInterval"))),
separateUpdates_
(
refinementDict_.lookupOrDefault<Switch>("separateUpdates", false)
),
curTimeIndex_(-1),
refinementSelectionPtr_(refinementSelection::New(*this, refinementDict_))
@ -148,7 +156,14 @@ bool Foam::dynamicPolyRefinementFvMesh::update()
// Check whether to perform refinement and/or unrefinement
const bool performRefinement = timeID % refineInterval_ == 0;
const bool performUnrefinement = timeID % unrefineInterval_ == 0;
// Skip performing refinement/unrefinement in the same step if
// separateUpdates flag is switched on
bool performUnrefinement = timeID % unrefineInterval_ == 0;
if (performRefinement && separateUpdates_)
{
performUnrefinement = false;
}
if
(

View file

@ -68,6 +68,10 @@ class dynamicPolyRefinementFvMesh
//- Unrefinement interval
label unrefineInterval_;
//- Separate refinement/unrefinement: off by default, meaning that
// refinement and unrefinement can be performed in the same step
Switch separateUpdates_;
//- Current time index (helper variable to skip multiple topo changes in
// a single time step)
label curTimeIndex_;