BUG: autoHexMesh: allocation of zones. Base on cell zoning, not on surface

This commit is contained in:
mattijs
2015-12-17 12:16:34 +00:00
parent 0347bc5ae2
commit 1beb9b7acb

View File

@ -279,7 +279,6 @@ void Foam::meshRefinement::getIntersections
} }
// Determine patches for baffles on all intersected unnamed faces
void Foam::meshRefinement::getBafflePatches void Foam::meshRefinement::getBafflePatches
( (
const labelList& globalToMasterPatch, const labelList& globalToMasterPatch,
@ -293,9 +292,16 @@ void Foam::meshRefinement::getBafflePatches
labelList& neiPatch labelList& neiPatch
) const ) const
{ {
// This determines the patches for the intersected faces to
// - remove the outside of the mesh
// - introduce baffles for (non-faceZone) intersections
// Any baffles for faceZones (faceType 'baffle'/'boundary') get introduced
// later
// 1. Determine cell zones // 1. Determine cell zones
// ~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~
// Note that this does not determine the surface that was intersected // Note that this does not determine the surface+region that was intersected
// so that is done in step 2 below. // so that is done in step 2 below.
labelList cellToZone; labelList cellToZone;
@ -312,48 +318,48 @@ void Foam::meshRefinement::getBafflePatches
namedSurfaceIndex, namedSurfaceIndex,
posOrientation posOrientation
); );
}
// Some stats // The logic is quite complicated and depends on the cell zone allocation
if (debug) // (see zonify). Cells can have zone:
{ // -2 : unreachable
label nZones = gMax(cellToZone)+1; // -1 : in background zone
// >=0 : in named cellZone
label nUnvisited = 0; // Faces can be intersected by a
label nBackgroundCells = 0; // - unnamed surface (no faceZone defined for it)
labelList nZoneCells(nZones, 0); // - named surface (a faceZone defined for it)
forAll(cellToZone, cellI) // Per intersected faces, depending on the cellToZone on either side of
{ // the face we need to:
label zoneI = cellToZone[cellI]; //
if (zoneI >= 0) // surface type | cellToZone | action
{ // ----------------+-------------------+---------
nZoneCells[zoneI]++; // unnamed | -2 | same | -
} // unnamed | -2 | different | baffle
else if (zoneI == -1) // | | |
{ // unnamed | -1 | same | baffle
nBackgroundCells++; // unnamed | -1 | different | -
} // | | |
else if (zoneI == -2) // unnamed | >=0 | same | baffle
{ // unnamed | >=0 | different | -
nUnvisited++; //
} // named | -2 | same | -
else // named | -2 | different | see note
{ //
FatalErrorIn("meshRefinement::getBafflePatches()") // named | -1 | same | -
<< "problem" << exit(FatalError); // named | -1 | different | -
} //
} // named | >=0 | same | -
reduce(nUnvisited, sumOp<label>()); // named | >=0 | different | -
reduce(nBackgroundCells, sumOp<label>()); //
forAll(nZoneCells, zoneI) // So the big difference between surface with a faceZone and those
{ // without is that 'standing-up-baffles' are not supported. Note that
reduce(nZoneCells[zoneI], sumOp<label>()); // they are still in a faceZone so can be split etc. later on.
} // Note: this all depends on whether we allow named surfaces
Info<< "nUnvisited :" << nUnvisited << endl; // to be outside the unnamed geometry. 2.3 does not allow this
Info<< "nBackgroundCells:" << nBackgroundCells << endl; // so we do the same. We could implement it but it would require
Info<< "nZoneCells :" << nZoneCells << endl; // re-testing of the intersections with the named surfaces to
} // obtain the surface and region number.
}
// 2. Check intersections of all unnamed surfaces // 2. Check intersections of all unnamed surfaces
@ -380,7 +386,6 @@ void Foam::meshRefinement::getBafflePatches
// 3. Baffle all boundary faces // 3. Baffle all boundary faces
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Baffle all boundary faces except those on outside of unvisited cells // Baffle all boundary faces except those on outside of unvisited cells
// (cellToZone = -2)
// Use patch according to globalRegion1,2 // Use patch according to globalRegion1,2
// Note: the behaviour is slightly different from version3.0 and earlier // Note: the behaviour is slightly different from version3.0 and earlier
// in that it will not create baffles which are outside the meshed // in that it will not create baffles which are outside the meshed
@ -395,6 +400,21 @@ void Foam::meshRefinement::getBafflePatches
forAll(testFaces, i) forAll(testFaces, i)
{ {
label faceI = testFaces[i]; label faceI = testFaces[i];
if (globalRegion1[faceI] != -1 || globalRegion2[faceI] != -1)
{
label ownMasterPatch = -1;
if (globalRegion1[faceI] != -1)
{
ownMasterPatch = globalToMasterPatch[globalRegion1[faceI]];
}
label neiMasterPatch = -1;
if (globalRegion2[faceI] != -1)
{
neiMasterPatch = globalToMasterPatch[globalRegion2[faceI]];
}
label ownZone = cellToZone[mesh_.faceOwner()[faceI]]; label ownZone = cellToZone[mesh_.faceOwner()[faceI]];
label neiZone = -1; label neiZone = -1;
@ -407,15 +427,25 @@ void Foam::meshRefinement::getBafflePatches
neiZone = neiCellZone[faceI-mesh_.nInternalFaces()]; neiZone = neiCellZone[faceI-mesh_.nInternalFaces()];
} }
if (ownZone != -2 || neiZone != -2)
if (ownZone == -2)
{ {
if (globalRegion1[faceI] != -1) if (neiZone != -2)
{ {
ownPatch[faceI] = globalToMasterPatch[globalRegion1[faceI]]; ownPatch[faceI] = ownMasterPatch;
neiPatch[faceI] = neiMasterPatch;
} }
if (globalRegion2[faceI] != -1) }
else if (neiZone == -2)
{ {
neiPatch[faceI] = globalToMasterPatch[globalRegion2[faceI]]; ownPatch[faceI] = ownMasterPatch;
neiPatch[faceI] = neiMasterPatch;
}
else if (ownZone == neiZone)
{
// Free-standing baffle
ownPatch[faceI] = ownMasterPatch;
neiPatch[faceI] = neiMasterPatch;
} }
} }
} }
@ -2374,8 +2404,7 @@ void Foam::meshRefinement::zonify
label zoneID = mesh_.cellZones().findZoneID(name); label zoneID = mesh_.cellZones().findZoneID(name);
if (zoneID == -1) if (zoneID == -1)
{ {
FatalErrorIn("meshRefinement::zonify(..)") << "problem" FatalErrorInFunction << "problem" << abort(FatalError);
<< abort(FatalError);
} }
locationsZoneIDs[i] = zoneID; locationsZoneIDs[i] = zoneID;
} }
@ -2521,6 +2550,73 @@ void Foam::meshRefinement::zonify
); );
} }
} }
// Some stats
if (debug)
{
label nZones = gMax(cellToZone)+1;
label nUnvisited = 0;
label nBackgroundCells = 0;
labelList nZoneCells(nZones, 0);
forAll(cellToZone, cellI)
{
label zoneI = cellToZone[cellI];
if (zoneI >= 0)
{
nZoneCells[zoneI]++;
}
else if (zoneI == -1)
{
nBackgroundCells++;
}
else if (zoneI == -2)
{
nUnvisited++;
}
else
{
FatalErrorIn("meshRefinement::getBafflePatches()")
<< "problem" << exit(FatalError);
}
}
reduce(nUnvisited, sumOp<label>());
reduce(nBackgroundCells, sumOp<label>());
forAll(nZoneCells, zoneI)
{
reduce(nZoneCells[zoneI], sumOp<label>());
}
Info<< "nUnvisited :" << nUnvisited << endl;
Info<< "nBackgroundCells:" << nBackgroundCells << endl;
Info<< "nZoneCells :" << nZoneCells << endl;
}
if (debug&MESH)
{
Pout<< "Writing cell zone allocation on mesh to time "
<< timeName() << endl;
volScalarField volCellToZone
(
IOobject
(
"cellToZone",
timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh_,
dimensionedScalar("zero", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);
forAll(cellToZone, cellI)
{
volCellToZone[cellI] = cellToZone[cellI];
}
volCellToZone.write();
}
} }
@ -4211,41 +4307,6 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::meshRefinement::zonify
} }
if (debug&MESH)
{
const_cast<Time&>(mesh_.time())++;
Pout<< "Writing cell zone allocation on mesh to time "
<< timeName() << endl;
write
(
debugType(debug),
writeType(writeLevel() | WRITEMESH),
mesh_.time().path()/"cellToZone"
);
volScalarField volCellToZone
(
IOobject
(
"cellToZone",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh_,
dimensionedScalar("zero", dimless, 0),
zeroGradientFvPatchScalarField::typeName
);
forAll(cellToZone, cellI)
{
volCellToZone[cellI] = cellToZone[cellI];
}
volCellToZone.write();
}
// Allocate and assign faceZones from cellZones // Allocate and assign faceZones from cellZones
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~