SnappyHexMesh
Contents
- 1 Introduction
- 2 Tutorials and Guides
- 3 Tips
- 3.1 Can't find the resulting mesh
- 3.2 Generate 2D meshes
- 3.3 Multi-region meshes
- 3.4 Running in parallel
- 3.5 GUI (Graphical User Interfaces)
- 3.6 Another way of projection of a mesh on an STL surface
- 3.7 Isolate and Conquer
- 3.8 Valid and invalid solid names
- 3.9 Handling inclined surfaces
- 3.10 Fixing STL files
- 3.11 Visual mesh diagnosis in ParaView
- 4 Deep analysis of each parameter
1 Introduction
In a nutshell, snappyHexMesh is a mesh generator that takes an already existing mesh (usually created with blockMesh) and chisels it into the mesh you want. But for this, it requires:
- A very well defined dictionary, namely system/snappyHexMeshDict.
- Good geometrical definitions, such as:
- STL/OBJ files with well defined surfaces;
- eMesh feature edge files, that define feature edges that have describe sharp corners.
Note: feature edges only available in:
Configuring both the dictionary file and providing good geometries can be a very arduous task. Therefore, at the moment of this writing (11:06, 18 August 2012 (CEST)), this wiki page will try to point you in the right direction, without describing each and every detail related to using snappyHexMesh. Feel free to contribute to this page!
1.1 Synopsis
snappyHexMesh [OPTIONS]
1.2 Description
snappyHexMesh is more of a mesh sculptor than a mesh generator, because it requires an already existing base mesh to work with. Depending on the options given through the file "system/snappyHexMeshDict", it can:
- refine the mesh;
- adjust the mesh to fit onto provided geometries;
- and add boundary layers near the requested patches.
The following options can be used with snappyHexMesh:
-case DIR
- Execute the command on the case directory DIR. If not provided, use the current directory
-dict FILE
- Read dictionary from specified location.
-checkGeometry
-noFunctionObjects
- Skip the execution of the functionObjects
-overwrite
- Overwrite existing mesh/results files
-parallel
- Run the utility in parallel
-roots "(DIR1 [...DIRN])"
- Directories through which the data are distributed
-help
- Display the help and exit
1.3 Examples
Several examples can be found in OpenFOAM, simply by running the following commands:
find $FOAM_UTILITIES -name "snappyHexMeshDict" find $FOAM_TUTORIALS -name "snappyHexMeshDict"
2 Tutorials and Guides
Here are listed links to tutorials and guides on using snappyHexMesh:
- Official OpenFOAM User Guide, chapter 5.4 - Mesh generation with the snappyHexMesh utility
- Training sessions given at the OFW community workshops, by people working at Engys:
- A Comprehensive Tour of snappyHexMesh - 7th OpenFOAM Workshop (25 June 2012):
- Original source: EugenedeVilliers-TrainingSlides.tgz
- Local copy here at openfoamwiki.net: Final-AndrewJacksonSlidesOFW7.pdf
- A Concise Introduction to Pre-Processing, Meshing, and Running OpenFOAM® Cases with HELYX-OS - 8th OpenFOAM Workshop:
- Original source: [1]
- Advanced Preprocessing and Meshing with snappyHexMesh
- Original source: [2]
- snappyHexMesh Theory and Application - 11th OpenFOAM Workshop:
- Original source: [3]
- Local copy of material: OFW11-Jackson-advSHM-FINAL.pdf, OFW11_SHM_trainingCases.zip
- A Comprehensive Tour of snappyHexMesh - 7th OpenFOAM Workshop (25 June 2012):
- Tutorials at SourceFlux's Blog: posts with the tag snappyHexMesh
- Dedicated wiki to snappyHexMesh by Elia Agnani: snappyWiki
- Development details for simulating the air flow around (and somewhat within) a Vespa, using OpenFOAM and snappyHexMesh: Vespa CFD/3D Model at Vespa Labs
- NTNU HPC Group wiki includes an interesting practical tutorial on how to use snappyHexMesh with great success: OpenFOAM - Spillway Tutorial
- Several realistic tutorials by Tobias Holzmann that use snappyHexMesh are available for free and more advanced ones for a fee to help support its updating and development: Advanced Tutorials
3 Tips
On this chapter are listed links and direct tips on using snappyHexMesh.
3.1 Can't find the resulting mesh
Creating a mesh with snappyHexMesh requires the following crucial steps:
- To already have a mesh ready, even if it's a simple brick-like mesh. For example, a simple mesh generated with blockMesh that has the dimensions of 10x4x2 meters and is divided in cells of 1 meter.
- The dictionary file snappyHexMeshDict should be properly configured. Look into the examples and tutorials for more information.
- snappyHexMesh must be executed with success.
If after these steps you can only find the original base mesh that was generated with blockMesh, then there are a few possibilities:
- snappyHexMesh might not have ran with success.
- If the option -overwrite was not used, then the resulting meshes should be in the next time folders, possibly inside the folders "1", "2" and/or "3".
- If the location in mesh given is on the outside of the geometry, then in ParaView you should either use the filter Clip or Extract Cells by Region, for inspecting how the mesh looks inside.
3.2 Generate 2D meshes
Instructions/examples on how to generate 2D meshes using snappyHexMesh can be found in at least two places:
- Here at the wiki: Main_ContribExamples/2DsHM
- In the tutorial incompressible/pimpleDyMFoam/wingMotion/wingMotion_snappyHexMesh
- At the following address: 2d rotational symmetric mesh
Other tutorials:
- This is an awesome tutorial: Dynamic Mesh for a Gear Pump.
- See in the previous section Tutorials and Guide from Tobias Holzmann. There you will find 2D cases, too.
3.3 Multi-region meshes
There are a few instructions/examples on how to generate multi-region meshes with snappyHexMesh:
- See the tutorial heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater.
- Instructions on how to remove an external unwanted region: Background Mesh in snappy with multi domain (CHT) post #3
- Note: this happens whenever the base mesh doesn't coincide with the outer limits of the target surface geometry. The tutorial heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater is such an example where the outside of the original STL files coincides with the base mesh.
- Discussion on this topic for simplified multi-tubes connected between two boxes: multiple regions at cfd-online.com.
- The resulting example case is provided here: Exhaust gas heat exchanger
- Not 100% multi-region, but more specifically a single mesh domain with a porous region: Multiple regions with a porous zone - post #5 - at cfd-online.com
- Tutorial for a multi region mesh with layer generation can be found here: MRM and Layer Generation
- Notes on how to create the STL files for multi-region meshes: chtMultiRegion not solving for velocity field - post #23
3.4 Running in parallel
Currently there are several official tutorials on how to use snappyHexMesh in parallel:
- incompressible/windSimpleFoam/turbineSiting - Valid versions:
- incompressible/simpleFoam/turbineSiting - Valid versions:
- incompressible/pisoFoam/les/motorBike/motorBike - Valid versions:
Other tutorials:
- Modified motorBike tutorial to be used as a benchmark case for running in parallel: Runtimes of OpenFOAM vs blueCFD - Valid versions:
3.5 GUI (Graphical User Interfaces)
Currently there are several interactive ways (using GUI) of generating meshes with snappyHexMesh. Here will only be listed the ones that are open-source:
- CfdOF
- A comprehensive OF GUI for FreeCAD.
- Discretizer
- Check the Screencasts page for more information.
- SwiftSnap
- (outdated) A very useful plug-in for Blender for configuring snappyHexMeshDict. There is SwiftBlock for blockMeshDict as well!
- HelyxOS
- A GUI for using OpenFOAM. See the video tutorials:
- Rheologic STL export addon
- A very handy blender addon that exports all objects in a blender scene as individual STL files using the object name as filename. Saves lots of time when frequent exporting of changes in geometry is needed. It's already part of Blender in the more recent versions, but if it's not available in your older version of Blender, you can grab it here: Rheologic Blender Addon: export multiple objects as separate STLs
- pyVTK script GUI for getting a sense for feature angles
- There is a script which uses pyVTK to give a GUI for seeing feature edges, which is made available on this thread: GUI for surfaceFeatureExtract
3.6 Another way of projection of a mesh on an STL surface
Adding boundary layers with snappyHexMesh can sometimes be very stressing, specially when it sometimes stops the layers in the wrong places. Trying to improve this feature was one of several works made in the MSc/PhD course in CFD with OpenSource software, 2011 at Chalmers, namely:
Other important links:
- Thread dedicated to discussing on this subject: [4]
- Adjusted code for working with the latest OpenFOAM versions: [5]
3.7 Isolate and Conquer
Since snappyHexMesh has so many mesh quality parameters, these sometimes to get in the way of the meshes you're trying to generate. The solution apparently is simple:
- Disable all quality controls.
- Diagnose visually the resulting mesh.
- Gradually turn back on one quality indicator at a time, while checking the resulting mesh with both checkMesh and ParaView.
For more on this, read the following posts/threads:
- Troubles with layer adding in my mesh - post #3
- (I know there are more threads at cfd-online.com, but currently I'm unable to find them -- Wyldckat (talk) 22:04, 3 September 2012 (CEST))
3.8 Valid and invalid solid names
There are 2 details to always keep in mind when exporting to STL:
- Always export to STL in ASCII or "coded" format (this means it'll be plain text).
- Edit the resulting file with a text editor and look for the lines that start with "solid". Next to the word "solid" is the name of said solid; that name should be a single C/C++ word.
Examples of valid words/names:
- wall
- ladder
- part_001_73_
Invalid names:
- This was generated by productnamehere
- part 001-73:
- 70 inch wall
3.9 Handling inclined surfaces
Q: Do you have a geometry that has an inclined surface and gets a very bad mesh, due to the cells not adjusting properly to the geometry, namely the inclined surfaces?
A: Check the following thread at CFD-Online: How to get a snapped mesh with SnappyHexMesh? post #4 and #5
3.10 Fixing STL files
If you need to fill or fix small gaps, here is a list of possible applications that can help:
- adMesh
- Can be installed on Debian/Ubuntu by running:
sudo apt-get install admesh
- Can be installed on Debian/Ubuntu by running:
- ReMESH
- MeshLab
- Can be installed on Debian/Ubuntu by running:
sudo apt-get install meshlab
- Can be installed on Debian/Ubuntu by running:
- Blender
- Check the wiki page Blender for more information.
- Fixing holes is explained in the following link, but the instructions are for the old Blender 2.49b: Unstructured Grids for OpenFOAM With Blender and enGrid 1.2, chapter Modelling with Blender
- As of you have the following OpenFOAM utilities that can assist in doing surface manipulations and checks, which is listed here: Main OFUtilities, section Surface mesh
Short list of topic related threads at CFD-Online's forums:
- Dirty STL with small gaps
- External mesh crawls into car model. Holes in STL model?
- Command line tool for finding the bounding box of an STL file
- .STL: non-closed manifold surface
- SnappyHexMesh Troubles
3.11 Visual mesh diagnosis in ParaView
This is already explained in this FAQ: FAQ/Postprocessing - Visual mesh diagnosis in ParaView
4 Deep analysis of each parameter
This chapter is dedicated to analysing in detail how each parameter affects the resulting mesh. Please feel free to document each parameter.
4.1 castellatedMeshControls
4.1.1 refinementRegions
4.1.1.1 Using non-closed surfaces
For more details, see this thread: Patch volume refinement in sHMD - solution in post #6.
4.1.2 nCellsBetweenLevels
- Notes
- Older versions of OpenFOAM also have this parameter, but some versions might be have a bug related to this parameter and might not act in the same way. Please feel free to check with which older versions this parameter act differently and please document your findings on this subsection.
- This parameter doesn't always work in the exact same way as reported here when the geometries are too complex, because the algorithm used by snappyHexMesh gets confused when there are too many corners, e.g. a geometry with shaped like a W over XY and like a T over XZ.
- Valid values
- nCellsBetweenLevels must be equal or greater than 1, integer values only.
- Studying nCellsBetweenLevels
- Using the cube case from the (unofficial) snappywiki, it's possible to easily study how this parameter affects the resulting mesh. In addition, keep in mind to follow the instructions given at FAQ/Postprocessing#Visual mesh diagnosis in ParaView. An additional test case is available at the discussion thread SnappyHexMesh Refinement nCellsBetweenLevels - post #14.
In review of how level refinement works, it's simple: for each level value, it divides a cell in the base mesh the number of times that "2 to the power of the level" equates to, in each direction. For example:
- Level 0: the original cell stays the same.
- Level 1: the original cell is divided into 8 parts, namely twice in each direction.
- Level 2: each level 1 cell is divided further into 8 parts, which means that the big cell has been divided into 64 cells in total.
- Level 3: each level 2 cell is divided further into 8 parts, which means that the big cell has been divided into 512 cells in total.
As for what a layer stands for: it's all of the cells that are at the same distance from a particular patch or wall.
Here is how the parameter affects the resulting mesh, where on the left is the image that demonstrates the mesh and on the right is the explanation:
Take into account that the mesh is set to use refinement of level 2 near the cube's wall. This means that the cells near those walls will have to be split in half twice in each direction. | |
When nCellsBetweenLevels is set to 1, it means that it will use at least 1 layer of cells at a particular refinement level in between changes of resolution. Furthermore:
| |
As demonstrated in the previous value, in this case it tries to have at least 2 cells before going to the next level of resolution. | |
This one may look a bit weird, but it's because snappyHexMesh is trying to be conservative. Why should it be necessary to have to split a third layer of cells at level 1; it's an error of 1 missing layer at level 1, but it's preferable than having an excessive number of cells. | |
Everything is fine on this one. It's doing at least 4 layers of cells on each level. | |
Here's another situation where it's able to perform somewhat well: it has 6 layers of cells at level 2 and 5 layers of cells at level 1. |
Keep in mind that if you set nCellsBetweenLevels set to a much larger value, e.g. 50, it would mean that the whole cube would be at the level 2 of refinement, because the requested number of layer cells was at least 50.
- And what about when it doesn't look like it's respecting at all the value you've defined?
- Well, keep in mind the layer indicated earlier in this subsection: what matters is that the cells are all at the same distance from a particular wall... and if the algorithm has got a hard time figuring out to which wall it was meant to be measuring the distance, then it makes it a lot harder to figure out where the layers should change resolution.
- The other possibility is that the algorithm is trying to be conservative and/or is respecting the parameter minRefinementCells.
- Or perhaps the parameters maxLocalCells and/or maxGlobalCells are the constraint that limits the how many refinement layers can in fact be used, without going over the requested limit.
- Thread where this can be discussed?
- Please ask questions about this parameter on this thread: SnappyHexMesh Refinement nCellsBetweenLevels
- OpenFOAM Version 1.5
- OpenFOAM Version 1.6
- OpenFOAM Version 1.7
- OpenFOAM Version 2.0
- OpenFOAM Version 2.1
- OpenFOAM Version 2.2
- OpenFOAM Version 2.3
- OpenFOAM-Extend Version 1.5-dev
- OpenFOAM-Extend Version 1.6-ext
- FOAM-Extend Version 3.0
- FOAM-Extend Version 3.1
- OpenFOAM Version 2.4
- OpenFOAM Version 3.0
- OpenFOAM Version 4
- OpenFOAM Version 5
- OpenFOAM Version 2.0.x
- OpenFOAM Version 2.1.x
- Mesh generation utilities