Mesh Generation with snappyHexMesh
Jukka-Pekka Keskinen,
Ville Vuorinen & Martti Larmi
Aalto University
School of Science and Technology
Internal Combustion Engine Research Group
Finnish OpenFOAM Users Day
22nd April 2010
Our Motivation for Using snappyHexMesh
Wall resolved LES: large amount of cells needed close to the
walls.
Simulation of internal combustion engines: plenty of walls,
complex geometries.
snappyHexMesh has the ability to produce ner grids in areas
where they are needed: savings in cell numbers.
Some contacts at KTH have been very happy with snappy.
Its open, its free and it comes with OpenFOAM.
Contents of the Presentation
Before snappyHexMesh
Cell Splitting
Snapping
Surface Layers
Some Problems with snappyHexMesh
Comments & Discussion
Input Needed by snappyHexMesh
A background mesh: The mesh to be rened in the process
snappyHexMeshDict dictionary:
Located in the system sub-directory of the case
Contains keywords for controlling the process
Some surface to snap:
A surface in STL format in constant/triSurface
sub-directory
One of the available generic surface types (sphere, cylinder,
box, plane and plate)
Combination of the two mentioned types
decomposeParDict dictionary and constant/triSurface
sub-directory
Have to exist even if not needed!
Background Mesh
The background mesh denes the extent of the computational
domain
Can be created with e.g. blockMesh
Requirements for the background mesh:
Fill the full area of interest
Must consist purely of hexahedra
Cell aspect ratio should be close to 1
Other aspect ratios might cause convergence problems with
the algorithm
The cell edges must intersect with the input surface
Background Mesh, View of the XY-Plane
Background Mesh, A View from an Angle
Cell Splitting (castellatedMesh)
The cell splitting procedure of snappyHexMesh is enabled with
by setting castellatedMesh true;
The splitting is controlled with castellatedMeshControls
and some given surface(s) in refinementSurfaces.
After the splitting is done, cells inside/outside the surface are
removed.
Additional areas for renement can be assigned with
refinementRegions and the renement can be specied to
happen inside, outside or near the given region.
Dierent areas can be selected to have dierent level of cell
renement. The changes in the renement level within the
mesh will change continuously with a modiable buer layer.
Region Inside the Cylinder is Discarded
Region Inside the Cylinder is Discarded
The Mesh After the Cell Splitting Phase, View of
XY-Plane
The Mesh After the Cell Splitting Phase, A View
from an Angle
Snapping (snap)
The snapping phase is activated by setting snap true;
The snapping phase is controlled with the entries of
snapControls.
In this phase of the process the mesh is deformed to follow the
input surface.
A number of cells will be deformed and some of the
right-angles will not be preserved.
Snapping is done iteratively:
1. Vertices close to the input surface are moved to the surface.
2. Relaxation of the internal mesh is computed.
3. If the quality parametres are violated, the displacement of the
violating vertices is reduced.
4. Repeat from 2 until quality parametres are satised or until set
iteration limits are reached.
The Mesh After the Snapping Phase, View of
XY-Plane
The Mesh After the Snapping Phase, A View
from an Angle
Surface Layers (doLayers)
If one is not satised with the mesh after the snapping phase,
additional surface layers can be added.
Surface layer phase of the process is activated by setting
doLayers true;
The process is controlled with the entries of
addLayersControls.
The layers will be added only to a specied patch(es).
Dierent levels of layer addition can be done to dierent
patches.
The earlier phases of SHM will have created patches from the
input geometries so these can be used.
In the example case the surface pipe has spawned a patch
named pipe_region0.
Surface Layers (doLayers)
The added surface layers are (supposedly) hexahedral.
The inserted layer thickness can be specied in absolute units
or relative to local undistorted cell size. Set with
relativeSize true/false;
As earlier, this phase too is done iteratively broadly in the
following way:
1. The mesh is projected back from the specied surface patch
according to the specied thickness.
2. Relaxation of the internal mesh is solved.
3. If the quality criteria is not met, the projected thickness is
reduced. Then continue from 2. If quality criteria is satised,
proceed to 4.
4. Mesh layers are inserted.
5. Another mesh quality check. If the check fails, inserted layers
are removed and the process is returned to 2.
The Cylinder with Three Added Layers
The Cylinder with Three Added Layers, Only
Added Cells Displayed
3D View of the Added Layers
Problematic Situations with snappyHexMesh
Edges (with right angles) do not usually right.
Extending the input surface past the boundaries of the
background mesh seems to prevent this on edges located at
the boundaries of the computational domain.
Making the cell size smaller close to the problematic edges
might be a way to reduce problems caused by the bad edge
behaviour.
The problematic edge behaviour causes unwanted cell features
to adjanced cell. In the test case the depth of the perturbation
was about two original cell sizes.
This is considered to be a major problem with snappyHexMesh.
A problem solving software seems to be on sale.
The End of the Cylinder (Extended Input Surface)
The End of the Cylinder (SHM Normal
Behaviour)
Problematic Situations with snappyHexMesh
(Continued)
Layer addition does not work properly near the limits of the
input surface.
Border cells will have improperly small surface layer or none at
all.
Take this in consideration when visually examining the mesh as
a slice is needed to see added layers (paraFoam).
ParaFoam has a problem with polyhedra. This might make
some cubes look like collection of pyramids.
According to checkMesh, max non-orthogonality is 36.7 after
cell splitting and 43.6 in the nal mesh. This number seems
too large. Can one trust all mesh statistics?
Problematic Layer Addition Results Near the End
of the Domain
The Mesh After the Cell Splitting Phase, View of
XY-Plane
Close-up of One of the Non-Cube Looking Cells
s
s
s
s
s
s
s
s
s
s
s
s
s
Final Comments on snappyHexMesh
+ Able to produce meshes for complex geometries with small
eort
+ Plenty of controls to play with
+ Open and free
- Poor documentation and thus the eects of some controls
remain unclear
- Diculties with sharp edges
Bibliography, Sources, Additional Material and
More Information on SnappyHexMesh
OpenFOAM User Guide, pp. U-140 U-148.
Tutorials in tutorials/mesh/snappyHexMesh/.
Discussion forums at CFD Online:
[Link]
Forums/openfoam-meshing-snappyhexmesh/
Thanks to Ville Tossavainen and Esko Jrvinen for helpful
comments and suggestions.
Files etc. used in the presentation are available on request:
[Link]@[Link]
Part II
Some Additional Slides
An Example of a More Dense Grid Done with
snappyHexMesh (1 050 040 Cells)
The End of the Cylinder (Inserted Surface Layers)
Controlling the Mesh Quality
(meshQualityControls)
The last snappyHexMesh control entry,
meshQualityControls, contains generic mesh quality
settings.
If any of the undoable phase produces violating cells, the
phase will be undone.
Some information given on the entries in the OF manual.
Most of the descriptions are poor.
Testing of the eects of the quality controls is dicult.
Disabling of the controls is well explained.
Too strict controls might prevent some or all meshing phases.
Visual inspection is recommended despite the use of the
quality controls.
Some Eects of Quality Controls (in the Case
Under Consideration)
The maximum non-orthogonality of a cell: maxNonOrtho
When set to 0, only the cell splitting phase is performed.
When set to the interval [4, 12], cell splitting and snapping
phases are performed but snapping produces poor results.
When set to the interval [13, 43], cell splitting and snapping
phases are performed with reasonable results.
When set to [44, 180], all of the phases are performed. The
quality control is disabled when set to 180.
Maximum face skewness: maxBoundarySkewness and
maxInternalSkewness
Highest values that still allow surface layer addition are 1.10
and 0.45 respectively.
Some Statistics (Acquired with checkMesh
Mesh Splitting Snapping Layers
No. of cells 1 280 8 880 8 880 13 896
Hex cells 1 280 7 680 7 680 11 808
Prism cells 0 0 0 800
Polyhedral cells 0 1 200 1 200 1 288
Min. vol. (m
3
) 3.91 10
3
6.10 10
5
6.10 10
5
4.14 10
5
Max. vol. (m
3
) 3.91 10
3
3.91 10
3
3.91 10
3
3.69 10
3
Tot. vol. (m
3
) 5.00 4.06 3.92 3.91
NB: The volume of the input cylinder is 3.93 m
3
.
The Used blockMeshDict, part 1
convertToMeters 1;
vertices
(
( 0 0 0 ) ( 1 0 0 ) ( 1 1 0 ) ( 0 1 0 )
( 0 0 5 ) ( 1 0 5 ) ( 1 1 5 ) ( 0 1 5 )
);
blocks
(
hex (0 1 2 3 4 5 6 7) (8 8 20) simpleGrading (1 1 1)
);
edges
();
The Used blockMeshDict, part 2
patches
(
patch in ( (0 1 2 3) )
patch out ( (7 6 5 4) )
wall right ( (2 6 5 1) )
wall left ( (3 7 4 0) )
wall up ( (2 6 7 3) )
wall down ( (4 5 1 0) )
);
mergePatchPairs
();
Geometry Entries
geometry {
pipe {
type searchableCylinder;
point1 (0.5 0.5 -1);
point2 (0.5 0.5 6);
radius 0.5; }
innerPipe {
type searchableCylinder;
point1 (0.5 0.5 0);
point2 (0.5 0.5 5);
radius 0.1; }
};
Entries of castellatedMeshControls
castellatedMeshControls {
maxLocalCells 1000000;
maxGlobalCells 2000000;
minRefinementCells 0;
nCellsBetweenLevels 1;
refinementSurfaces {
pipe { level (2 1); } }
refinementRegions {
innerPipe {
mode inside;
levels ((1 2)); } }
resolveFeatureAngle 20;
locationInMesh (0.54 0.52 0.16);
features (); }
The used snapControls entry
snapControls
{
nSmoothPatch 6;
tolerance 10;
nSolveIter 60;
nRelaxIter 10;
}
The Used addLayersControls Entry
relativeSizes true;
layers { "pipe_region0" {
nSurfaceLayers 3; } }
expansionRatio 2;
finalLayerThickness 0.5;
minThickness 0.05;
nGrow 1;
featureAngle 60;
nRelaxIter 5;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 130;
nBufferCellsNoExtrude 0;
nLayerIter 50;
The Used meshQualityControls Entry
meshQualityControls
{ maxNonOrtho 65;
maxBoundarySkewness 20;
maxInternalSkewness 4;
maxConcave 80;
minFlatness 0.5;
minVol -1e13;
minArea -1;
minTwist 0.05;
minDeterminant 0.001;
minFaceWeight 0.05;
minVolRatio 0.01;
minTriangleTwist -1;
nSmoothScale 4;
errorReduction 0.75; }
A Slice of the Cylinder at 2 Original Cell Lengths
(0.5 m) from the End
A Slice of the Cylinder at 1/5 Original Cell
Lengths (0.05 m) from the End