ENH: snappyHexMesh: revert zoneing back to e8d73e5546

since growing single cells just makes the zoneing inconsistent with the
surface intersections (so you don't have a patch when converting surface
intersections to baffles)
This commit is contained in:
mattijs
2016-06-20 16:39:34 +01:00
parent ae74a9ba6c
commit 5583b78d9d
2 changed files with 166 additions and 102 deletions

View File

@ -669,6 +669,7 @@ private:
//- Determines cell zone from cell region information. //- Determines cell zone from cell region information.
bool calcRegionToZone bool calcRegionToZone
( (
const label backgroundZoneID,
const label surfZoneI, const label surfZoneI,
const label ownRegion, const label ownRegion,
const label neiRegion, const label neiRegion,
@ -680,6 +681,7 @@ private:
// marked in namedSurfaceIndex regarded as blocked. // marked in namedSurfaceIndex regarded as blocked.
void findCellZoneTopo void findCellZoneTopo
( (
const label backgroundZoneID,
const pointField& locationsInMesh, const pointField& locationsInMesh,
const labelList& allSurfaceIndex, const labelList& allSurfaceIndex,
const labelList& namedSurfaceIndex, const labelList& namedSurfaceIndex,
@ -700,6 +702,7 @@ private:
void zonify void zonify
( (
const bool allowFreeStandingZoneFaces, const bool allowFreeStandingZoneFaces,
const label backgroundZoneID,
const pointField& locationsInMesh, const pointField& locationsInMesh,
const wordList& zonesInMesh, const wordList& zonesInMesh,

View File

@ -311,6 +311,7 @@ void Foam::meshRefinement::getBafflePatches
zonify zonify
( (
true, // allowFreeStandingZoneFaces true, // allowFreeStandingZoneFaces
-2, // zone to put unreached cells into
locationsInMesh, locationsInMesh,
zonesInMesh, zonesInMesh,
@ -1810,8 +1811,75 @@ void Foam::meshRefinement::findCellZoneInsideWalk
} }
bool Foam::meshRefinement::calcRegionToZone
(
const label backgroundZoneID,
const label surfZoneI,
const label ownRegion,
const label neiRegion,
labelList& regionToCellZone
) const
{
bool changed = false;
// Check whether inbetween different regions
if (ownRegion != neiRegion)
{
// Jump. Change one of the sides to my type.
// 1. Interface between my type and unset region.
// Set region to keepRegion
if (regionToCellZone[ownRegion] == -2)
{
if (regionToCellZone[neiRegion] == surfZoneI)
{
// Face between unset and my region. Put unset
// region into keepRegion
//MEJ: see comment in findCellZoneTopo
if (backgroundZoneID != -2)
{
regionToCellZone[ownRegion] = backgroundZoneID;
changed = true;
}
}
else if (regionToCellZone[neiRegion] != -2)
{
// Face between unset and other region.
// Put unset region into my region
regionToCellZone[ownRegion] = surfZoneI;
changed = true;
}
}
else if (regionToCellZone[neiRegion] == -2)
{
if (regionToCellZone[ownRegion] == surfZoneI)
{
// Face between unset and my region. Put unset
// region into keepRegion
if (backgroundZoneID != -2)
{
regionToCellZone[neiRegion] = backgroundZoneID;
changed = true;
}
}
else if (regionToCellZone[ownRegion] != -2)
{
// Face between unset and other region.
// Put unset region into my region
regionToCellZone[neiRegion] = surfZoneI;
changed = true;
}
}
}
return changed;
}
void Foam::meshRefinement::findCellZoneTopo void Foam::meshRefinement::findCellZoneTopo
( (
const label backgroundZoneID,
const pointField& locationsInMesh, const pointField& locationsInMesh,
const labelList& allSurfaceIndex, const labelList& allSurfaceIndex,
const labelList& namedSurfaceIndex, const labelList& namedSurfaceIndex,
@ -1825,12 +1893,17 @@ void Foam::meshRefinement::findCellZoneTopo
// know which side of the face it relates to. So all we are doing here // know which side of the face it relates to. So all we are doing here
// is get the correspondence between surface/cellZone and regionSplit // is get the correspondence between surface/cellZone and regionSplit
// region. // region.
// This can occasionally go wrong when surfaces pass through a // See the logic in calcRegionToZone. The problem is what to do
// cell centre and a cell completely gets blocked off so becomes a // with unreachable parts of the mesh (cellToZone = -2).
// separate region. The problem is to distinguish between a cell which // In 23x this routine was only called for actually zoneing an existing
// properly should be deleted (so in the 'background' mesh) // mesh so we had to do something with these cells and they
// or just a single-cell region from incorrect baffling. Currently the // would get set to -1 (background). However in this version this routine
// logic is just to detect cells that are on different regions. // also gets used much earlier on when after the surface refinement it
// removes unreachable cells ('Removing mesh beyond surface intersections')
// and this is when we keep -2 so it gets removed.
// So the zone to set these unmarked cells to is provided as argument:
// - backgroundZoneID = -2 : do not change so remove cells
// - backgroundZoneID = -1 : put into background
// Assumes: // Assumes:
@ -1920,107 +1993,95 @@ void Foam::meshRefinement::findCellZoneTopo
} }
} }
// Synchronise any changes due to locationInMesh
Pstream::listCombineGather(regionToCellZone, maxEqOp<label>());
Pstream::listCombineScatter(regionToCellZone);
// Get coupled neighbour cellRegion // Find correspondence between cell zone and surface
labelList neiCellRegion; // by changing cell zone every time we cross a surface.
syncTools::swapBoundaryCellList(mesh_, cellRegion, neiCellRegion); while (true)
// Detect unassigned cell (region) bordering two cellZones. Put these
// cells into either neighbouring cellZone.
labelList growCellToZone(mesh_.nCells(), -2);
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{ {
label own = mesh_.faceOwner()[faceI]; // Synchronise regionToCellZone.
label ownRegion = cellRegion[own]; // Note:
label nei = mesh_.faceNeighbour()[faceI]; // - region numbers are identical on all processors
label neiRegion = cellRegion[nei]; // - keepRegion is identical ,,
// - cellZones are identical ,,
// This done at top of loop to account for geometric matching
// not being synchronised.
Pstream::listCombineGather(regionToCellZone, maxEqOp<label>());
Pstream::listCombineScatter(regionToCellZone);
// Check whether inbetween different regions
if (ownRegion != neiRegion) bool changed = false;
// Internal faces
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{ {
if (regionToCellZone[ownRegion] == -2) label surfI = namedSurfaceIndex[faceI];
// Connected even if no cellZone defined for surface
if (surfI != -1)
{ {
if (regionToCellZone[neiRegion] != -2) // Calculate region to zone from cellRegions on either side
{ // of internal face.
if (growCellToZone[own] == -2) bool changedCell = calcRegionToZone
{ (
// First visit of cell backgroundZoneID,
growCellToZone[own] = regionToCellZone[neiRegion]; surfaceToCellZone[surfI],
} cellRegion[mesh_.faceOwner()[faceI]],
else if (regionToCellZone[neiRegion] != growCellToZone[own]) cellRegion[mesh_.faceNeighbour()[faceI]],
{ regionToCellZone
// Found a cell bordering multiple cellZones. Grow. );
cellToZone[own] = growCellToZone[own];
} changed = changed | changedCell;
}
}
else if (regionToCellZone[neiRegion] == -2)
{
if (growCellToZone[nei] == -2)
{
// First visit of cell
growCellToZone[nei] = regionToCellZone[ownRegion];
}
else if (regionToCellZone[ownRegion] != growCellToZone[nei])
{
cellToZone[nei] = growCellToZone[nei];
}
} }
} }
}
// Boundary faces
const polyBoundaryMesh& patches = mesh_.boundaryMesh(); const polyBoundaryMesh& patches = mesh_.boundaryMesh();
forAll(patches, patchI) // Get coupled neighbour cellRegion
{ labelList neiCellRegion;
const polyPatch& pp = patches[patchI]; syncTools::swapBoundaryCellList(mesh_, cellRegion, neiCellRegion);
if (pp.coupled()) // Calculate region to zone from cellRegions on either side of coupled
// face.
forAll(patches, patchI)
{ {
forAll(pp, i) const polyPatch& pp = patches[patchI];
if (pp.coupled())
{ {
label faceI = pp.start()+i; forAll(pp, i)
label own = mesh_.faceOwner()[faceI];
label ownRegion = cellRegion[own];
label neiRegion = neiCellRegion[faceI-mesh_.nInternalFaces()];
// Check whether inbetween different regions
if (ownRegion != neiRegion)
{ {
if (regionToCellZone[ownRegion] == -2) label faceI = pp.start()+i;
label surfI = namedSurfaceIndex[faceI];
// Connected even if no cellZone defined for surface
if (surfI != -1)
{ {
if (regionToCellZone[neiRegion] != -2) bool changedCell = calcRegionToZone
{ (
if (growCellToZone[own] == -2) backgroundZoneID,
{ surfaceToCellZone[surfI],
// First visit of cell cellRegion[mesh_.faceOwner()[faceI]],
growCellToZone[own] = neiCellRegion[faceI-mesh_.nInternalFaces()],
regionToCellZone[neiRegion]; regionToCellZone
} );
else if
( changed = changed | changedCell;
regionToCellZone[neiRegion]
!= growCellToZone[own]
)
{
// Found a cell bordering multiple cellZones.
cellToZone[own] = growCellToZone[own];
}
}
} }
} }
} }
} }
if (!returnReduce(changed, orOp<bool>()))
{
break;
}
} }
if (debug) if (debug)
{ {
forAll(regionToCellZone, regionI) forAll(regionToCellZone, regionI)
@ -2264,6 +2325,7 @@ void Foam::meshRefinement::getIntersections
void Foam::meshRefinement::zonify void Foam::meshRefinement::zonify
( (
const bool allowFreeStandingZoneFaces, const bool allowFreeStandingZoneFaces,
const label backgroundZoneID,
const pointField& locationsInMesh, const pointField& locationsInMesh,
const wordList& zonesInMesh, const wordList& zonesInMesh,
@ -2486,25 +2548,23 @@ void Foam::meshRefinement::zonify
} }
// 5. Find any unassigned regions (from regionSplit). This will // 5. Find any unassigned regions (from regionSplit)
// just walk slightly out to cover those single cells that
// are baffled off into a separate region.
Info<< "Growing from known cellZones to fix cells inbetween cellZones"
<< nl << endl;
findCellZoneTopo
(
pointField(0),
globalRegion1, // To split up cells
namedSurfaceIndex, // Step across named surfaces to propagate
surfaceToCellZone,
cellToZone
);
if (namedSurfaces.size()) if (namedSurfaces.size())
{ {
Info<< "Walking from known cellZones; crossing a faceZone "
<< "face changes cellZone" << nl << endl;
findCellZoneTopo
(
backgroundZoneID,
pointField(0),
globalRegion1, // To split up cells
namedSurfaceIndex, // Step across named surfaces to propagate
surfaceToCellZone,
cellToZone
);
// Make sure namedSurfaceIndex is unset inbetween same cell zones. // Make sure namedSurfaceIndex is unset inbetween same cell zones.
if (!allowFreeStandingZoneFaces) if (!allowFreeStandingZoneFaces)
{ {
@ -4269,6 +4329,7 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
zonify zonify
( (
allowFreeStandingZoneFaces, allowFreeStandingZoneFaces,
-1, // Set all cells with cellToZone -2 to -1
locationsInMesh, locationsInMesh,
zonesInMesh, zonesInMesh,