snappyHexMesh: Automatically remove zero-sized patches

All patches are preserved if the 'keepPatches' option is set true.
Patch contributed by Mattijs Janssens
This commit is contained in:
Henry Weller
2016-05-13 17:47:38 +01:00
parent bd52e35f77
commit 274d1df8a4
7 changed files with 92 additions and 62 deletions

View File

@ -57,6 +57,7 @@ Description
#include "MeshedSurface.H"
#include "globalIndex.H"
#include "IOmanip.H"
#include "fvMeshTools.H"
using namespace Foam;
@ -571,6 +572,73 @@ scalar getMergeDistance(const polyMesh& mesh, const scalar mergeTol)
}
void removeZeroSizedPatches(fvMesh& mesh)
{
// Remove any zero-sized ones. Assumes
// - processor patches are already only there if needed
// - all other patches are available on all processors
// - but coupled ones might still be needed, even if zero-size
// (e.g. processorCyclic)
// See also logic in createPatch.
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
labelList oldToNew(pbm.size(), -1);
label newPatchi = 0;
forAll(pbm, patchi)
{
const polyPatch& pp = pbm[patchi];
if (!isA<processorPolyPatch>(pp))
{
if
(
isA<coupledPolyPatch>(pp)
|| returnReduce(pp.size(), sumOp<label>())
)
{
// Coupled (and unknown size) or uncoupled and used
oldToNew[patchi] = newPatchi++;
}
}
}
forAll(pbm, patchi)
{
const polyPatch& pp = pbm[patchi];
if (isA<processorPolyPatch>(pp))
{
oldToNew[patchi] = newPatchi++;
}
}
const label nKeepPatches = newPatchi;
// Shuffle unused ones to end
if (nKeepPatches != pbm.size())
{
Info<< endl
<< "Removing zero-sized patches:" << endl << incrIndent;
forAll(oldToNew, patchi)
{
if (oldToNew[patchi] == -1)
{
Info<< indent << pbm[patchi].name()
<< " type " << pbm[patchi].type()
<< " at position " << patchi << endl;
oldToNew[patchi] = newPatchi++;
}
}
Info<< decrIndent;
fvMeshTools::reorderPatches(mesh, oldToNew, nKeepPatches, true);
Info<< endl;
}
}
// Write mesh and additional information
void writeMesh
(
@ -812,6 +880,8 @@ int main(int argc, char *argv[])
readScalar(meshDict.lookup("mergeTolerance"))
);
const Switch keepPatches(meshDict.lookupOrDefault("keepPatches", false));
// Read decomposePar dictionary
@ -1351,6 +1421,12 @@ int main(int argc, char *argv[])
motionDict
);
if (!keepPatches && !wantSnap && !wantLayers)
{
removeZeroSizedPatches(mesh);
}
writeMesh
(
"Refined mesh",
@ -1392,6 +1468,11 @@ int main(int argc, char *argv[])
snapParams
);
if (!keepPatches && !wantLayers)
{
removeZeroSizedPatches(mesh);
}
writeMesh
(
"Snapped mesh",
@ -1438,6 +1519,11 @@ int main(int argc, char *argv[])
distributor
);
if (!keepPatches)
{
removeZeroSizedPatches(mesh);
}
writeMesh
(
"Layer mesh",

View File

@ -26,6 +26,11 @@ addLayers false;
//singleRegionName false;
//Optional: preserve all generated patches. Default is to remove
// zero-sized patches.
//keepPatches true;
// Geometry. Definition of all surfaces. All surfaces are of class
// searchableSurface.
// Surfaces are used