mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -57,6 +57,7 @@ Description
|
|||||||
#include "MeshedSurface.H"
|
#include "MeshedSurface.H"
|
||||||
#include "globalIndex.H"
|
#include "globalIndex.H"
|
||||||
#include "IOmanip.H"
|
#include "IOmanip.H"
|
||||||
|
#include "fvMeshTools.H"
|
||||||
|
|
||||||
using namespace Foam;
|
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
|
// Write mesh and additional information
|
||||||
void writeMesh
|
void writeMesh
|
||||||
(
|
(
|
||||||
@ -812,6 +880,8 @@ int main(int argc, char *argv[])
|
|||||||
readScalar(meshDict.lookup("mergeTolerance"))
|
readScalar(meshDict.lookup("mergeTolerance"))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const Switch keepPatches(meshDict.lookupOrDefault("keepPatches", false));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Read decomposePar dictionary
|
// Read decomposePar dictionary
|
||||||
@ -1351,6 +1421,12 @@ int main(int argc, char *argv[])
|
|||||||
motionDict
|
motionDict
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (!keepPatches && !wantSnap && !wantLayers)
|
||||||
|
{
|
||||||
|
removeZeroSizedPatches(mesh);
|
||||||
|
}
|
||||||
|
|
||||||
writeMesh
|
writeMesh
|
||||||
(
|
(
|
||||||
"Refined mesh",
|
"Refined mesh",
|
||||||
@ -1392,6 +1468,11 @@ int main(int argc, char *argv[])
|
|||||||
snapParams
|
snapParams
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!keepPatches && !wantLayers)
|
||||||
|
{
|
||||||
|
removeZeroSizedPatches(mesh);
|
||||||
|
}
|
||||||
|
|
||||||
writeMesh
|
writeMesh
|
||||||
(
|
(
|
||||||
"Snapped mesh",
|
"Snapped mesh",
|
||||||
@ -1438,6 +1519,11 @@ int main(int argc, char *argv[])
|
|||||||
distributor
|
distributor
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!keepPatches)
|
||||||
|
{
|
||||||
|
removeZeroSizedPatches(mesh);
|
||||||
|
}
|
||||||
|
|
||||||
writeMesh
|
writeMesh
|
||||||
(
|
(
|
||||||
"Layer mesh",
|
"Layer mesh",
|
||||||
|
|||||||
@ -26,6 +26,11 @@ addLayers false;
|
|||||||
//singleRegionName 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
|
// Geometry. Definition of all surfaces. All surfaces are of class
|
||||||
// searchableSurface.
|
// searchableSurface.
|
||||||
// Surfaces are used
|
// Surfaces are used
|
||||||
|
|||||||
@ -112,7 +112,7 @@ public:
|
|||||||
//- Change patchField to zero on registered fields
|
//- Change patchField to zero on registered fields
|
||||||
static void zeroPatchFields(fvMesh& mesh, const label patchI);
|
static void zeroPatchFields(fvMesh& mesh, const label patchI);
|
||||||
|
|
||||||
// -Reorder and remove trailing patches. If validBoundary call is parallel
|
//- Reorder and remove trailing patches. If validBoundary call is parallel
|
||||||
// synced and all add the same patch with same settings
|
// synced and all add the same patch with same settings
|
||||||
static void reorderPatches
|
static void reorderPatches
|
||||||
(
|
(
|
||||||
@ -121,7 +121,6 @@ public:
|
|||||||
const label nPatches,
|
const label nPatches,
|
||||||
const bool validBoundary
|
const bool validBoundary
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ cd ${0%/*} || exit 1 # Run from this directory
|
|||||||
runApplication blockMesh
|
runApplication blockMesh
|
||||||
runApplication surfaceFeatureExtract
|
runApplication surfaceFeatureExtract
|
||||||
runApplication snappyHexMesh -overwrite
|
runApplication snappyHexMesh -overwrite
|
||||||
runApplication createPatch -overwrite
|
|
||||||
|
|
||||||
runApplication $(getApplication)
|
runApplication $(getApplication)
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
/*--------------------------------*- C++ -*----------------------------------*\
|
|
||||||
| ========= | |
|
|
||||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
|
||||||
| \\ / O peration | Version: dev |
|
|
||||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
|
||||||
| \\/ M anipulation | |
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
FoamFile
|
|
||||||
{
|
|
||||||
version 2.0;
|
|
||||||
format ascii;
|
|
||||||
class dictionary;
|
|
||||||
object createPatchDict;
|
|
||||||
}
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// Do a synchronisation of coupled points after creation of any patches.
|
|
||||||
// Note: this does not work with points that are on multiple coupled patches
|
|
||||||
// with transformations (i.e. cyclics).
|
|
||||||
pointSync false;
|
|
||||||
|
|
||||||
// Patches to create. An empty patch list just removes patches with zero
|
|
||||||
// faces from $FOAM_CASE/constant/polyMesh/boundary.
|
|
||||||
patches
|
|
||||||
(
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
@ -16,9 +16,6 @@ runApplication snappyHexMesh -overwrite
|
|||||||
runApplication createBaffles -overwrite
|
runApplication createBaffles -overwrite
|
||||||
runApplication mergeOrSplitBaffles -split -overwrite
|
runApplication mergeOrSplitBaffles -split -overwrite
|
||||||
|
|
||||||
# Get rid of zero faced patches
|
|
||||||
runApplication createPatch -overwrite
|
|
||||||
|
|
||||||
# Copy fields after meshing to avoind the generation of unnecessary patch fields
|
# Copy fields after meshing to avoind the generation of unnecessary patch fields
|
||||||
cp -r 0.orig 0
|
cp -r 0.orig 0
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
/*--------------------------------*- C++ -*----------------------------------*\
|
|
||||||
| ========= | |
|
|
||||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
|
||||||
| \\ / O peration | Version: dev |
|
|
||||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
|
||||||
| \\/ M anipulation | |
|
|
||||||
\*---------------------------------------------------------------------------*/
|
|
||||||
FoamFile
|
|
||||||
{
|
|
||||||
version 2.0;
|
|
||||||
format ascii;
|
|
||||||
class dictionary;
|
|
||||||
object createPatchDict;
|
|
||||||
}
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// Do a synchronisation of coupled points after creation of any patches.
|
|
||||||
// Note: this does not work with points that are on multiple coupled patches
|
|
||||||
// with transformations (i.e. cyclics).
|
|
||||||
pointSync false;
|
|
||||||
|
|
||||||
// Patches to create.
|
|
||||||
patches
|
|
||||||
(
|
|
||||||
);
|
|
||||||
|
|
||||||
// ************************************************************************* //
|
|
||||||
Reference in New Issue
Block a user