BlockMesh
Contents
- 1 Introduction
- 2 Tips
- 2.1 Using blockMesh to export blockMeshDict to .obj
- 2.2 Graphical User Interfaces for visualizing and designing blockMeshDict
- 2.3 Calculating the grading
- 2.4 Programmatically generating blockMeshDict files
- 2.5 Generating double-graded meshes
- 2.6 Generating multi-graded meshes
- 2.7 Generating meshes with smoothed mesh transitions
- 2.8 Defining cellZones
1 Introduction
blockMesh is one of the most basic mesh generators in OpenFOAM. It relies on a single dictionary file blockMeshDict, usually placed inside the folders constant/polyMesh or system/. The latest official documentation on how to use blockMesh can be found on the OpenFOAM User Guide and online at the OpenFOAM Foundation website at this page: 5.3 blockMesh
Feel free to contribute to this page!
1.1 Synopsis
blockMesh [OPTIONS]
1.2 Description
As the name implies, blockMesh helps the user build the mesh with blocks. It relies on a single dictionary file blockMeshDict, usually located at constant/polyMesh/blockMeshDict or system/blockMeshDict. Inside that dictionary file should be defined:
- all of the reference vertices of mesh;
- all of the building blocks for the mesh, each block composed of:
- 8 vertices (repeat vertices, for collapsing edges);
- grading definition;
- cell count over each major axis;
- optionally, one can assign special edge definitions for specific edges on blocks, such as arcs and splines;
- assign faces of blocks to patch names;
- and finally, be able to define special face merging, but associating/merging patches.
The following options can be used with blockMesh:
-case DIR
- Execute the command on the case directory DIR. If not provided, use the current directory.
-dict FILE
- Read dictionary from specified location.
-blockTopology
- Write block edges and centres as .obj files, for visual inspection elsewhere.
-noFunctionObjects
- Skip the execution of the functionObjects
-region NAME
- Generate the mesh only for a specific region (e.g. for multi-region simulations).
-help
- Display the help and exit
2 Tips
On this chapter are listed links and direct tips on using snappyHexMesh.
2.1 Using blockMesh to export blockMeshDict to .obj
Before there were any nice graphical user interfaces for visually designing and inspecting the blockMeshDict files, blockMesh can interpret the dictionary file and export it to an .obj file, which can be opened by any compatible 3D software, such as ParaView, JavaView and so on. There steps are as follows:
- Use the -blockTopology argument to dump out a blockTopology.obj file:
blockMesh -blockTopology
- The vertex numbering in this file is consistent with that of the vertices in the blockMeshDict file.
- The file blockTopology.obj can be visualized in the following 3D software:
- Visualize directly with JavaView;
- Visualize directly in ParaView or convert the file to VTK if you prefer:
objToVTK blockTopology.obj blockTopology.vtk
- Import in Blender.
- (fell free to add more...)
2.2 Graphical User Interfaces for visualizing and designing blockMeshDict
- paraFoam -block
- Introduced in OpenFOAM 2.0.0, this argument for the paraFoam script requires that the respective OpenFOAM plugin is built for ParaView. This means that ParaView has to be built from source code or to use the Deb/RPM packages provided by the OpenFOAM Foundation.
- blockMesh -blockTopology
- Already explained in the section Using blockMesh to export blockMeshDict to .obj
- pyFoamDisplayBlockMesh.py
- This Python script provides a way to visually inspect the current blockMeshDict settings in 3D. It is part of PyFoam, which relies on VTK and Qt for the graphical interface. For more information, see section pyFoamDisplayBlockMesh.py in the page Contrib/PyFoam.
- SwiftBlock
- This is also a Python script, but it's a powerful add-on for Blender, which provides an interactive way to design the blockMeshDict directly in 3D. For more information, see the respective wiki page: Contrib/SwiftBlock
- HexBlocker
- This is a dedicated application for visually editing in 3D the blockMeshDict file. For more information, see this forum page: HexBlocker a GUI for blockMeshDict, alpha release
- FreeCAD
- If you are looking for out of the box and cross platform solutions, there are attempts to import blockMeshDict topologies into FreeCAD. The other advantage is that it does not require the mesh, so if you have problems with mesh generation it help you to visualize in advance and debug the topology. An early version of the Python script can be found here. To follow up on this project you may follow this thread in FreeCAD forum.
2.3 Calculating the grading
There is this utility here on the Wiki and this thread with a utility on the MessageBoard.
2.4 Programmatically generating blockMeshDict files
Since the blockMeshDict files are essentially text files, they can be generated by any means necessary. In this section is addressed the currently known documented ways of using scripts to generate blockMeshDict files.
- #codeStream
- This is a feature that was introduced in OpenFOAM 2.0.0: OpenFOAM® v2.0.0: Run-time Control - Examples:
- The main tutorial provided in OpenFOAM for this feature in blockMeshDict: $FOAM_TUTORIALS/basic/potentialFoam/cylinder
- GNU m4, aka blockMeshDict.m4
-
- The GNU m4 (manual) is a macro processor, which is essentially a simple programming language for calculating values and definitions to be written in the resulting file. In the following wiki page is a good example on this topic: HowTo blockMesh with m4. For more examples, run in the command line:
find $FOAM_TUTORIALS -name "blockMeshDict.m4"
- A report by Erwin Adi Hartono for the MSc/PhD course in CFD with OpenSource software, 2010 at Chalmers University of Technology: Python Scripting and M4-Scripting for Automatization and Parameterization in OpenFOAM
- The GNU m4 (manual) is a macro processor, which is essentially a simple programming language for calculating values and definitions to be written in the resulting file. In the following wiki page is a good example on this topic: HowTo blockMesh with m4. For more examples, run in the command line:
- MATLAB
-
- BananaSplit: This is a MATLAB script for generating blockMeshDict files. For more information, see this forum thread: BananaSplit helper for OpenFOAM blockMesh
- Using Python scripts
-
- Generating a pipe: How to create large Mesh? - post #4
- Python library ofblockmeshdicthelper available at PyPi: ofblockmeshdicthelper
- Blog post on how to use numpy for creating the blockMeshDict file: Generating an OpenFOAM mesh from a point cloud (x,y,z)
2.5 Generating double-graded meshes
Although blockMesh is considerably powerful as it is, the community has provided a modified version named blockMeshDG for generating double graded meshes, in the sense of having an easy way to define symmetrical geometrical grading. For more information, see the dedicated wiki page: blockMeshDG
2.6 Generating multi-graded meshes
A new feature was introduced into OpenFOAM 2.3.x, some weeks after the release of 2.3.1, which is the ability to do multi-grading. This was introduced in the commit cf370883644e and is documented in the comment of the commit with the usage instructions. Quoting from said comment:
'''blockMesh: Add support for multi/sectional grading in a block''' Consider a block describing a channel with two opposite walls. Currently in order to grade the mesh towards the walls and have a uniform region in the centre the channel would need to be spit into 3 blocks. With the new multi/sectional grading this can be achieved in a single block e.g. blocks ( hex (0 1 2 3 4 5 6 7) (20 60 20) simpleGrading ( 1 ((0.2 0.3 4) (0.6 0.4 1) (0.2 0.3 0.25)) 1 ) ); In this example the block is divided uniformly in the x and z -directions and split into three grading sections in the y-direction described by three triples: ((0.2 0.3 4) (0.6 0.4 1) (0.2 0.3 0.25)). Each of the grading sections is described by a triple consisting of the fraction of the block, the fraction of the divisions and the grading ratio (size of first division/size of last division). Both the fraction of the block and the fraction of the divisions are normalized automatically so they can be specified scaled in anyway, e.g. as percentages: blocks ( hex (0 1 2 3 4 5 6 7) (20 60 20) simpleGrading ( 1 ((2 3 4) (6 4 1) (2 3 0.25)) 1 ) ); and they need not sum to 1 or 100. This is very new functionality and not well tested but backward compatibility has been well tested so all existing blockMeshDicts should parse correctly.
If you want to use this feature in older versions of OpenFOAM, follow the instructions given on this forum post: blockMesh with double grading. - post #86
2.7 Generating meshes with smoothed mesh transitions
Sometimes it's necessary to transition between different mesh formats, such as going from a cube-shaped block to a sphere-shaped block. This is where the extBlockMesh add-on for blockMesh comes in handy: Extend blockMesh with smoothing capability
2.8 Defining cellZones
Blocks are assigned to cellZones (which can be used for example to apply fvOptions to a selected region) the name of the cellZone can be specified in the block definition between the vertex numbers and the number of cells in each direction. This information is then used to generate a "cellZones" file in the polyMesh folder:
hex (0 1 2 3 4 5 6 7) myCellZone (20 1 1) simpleGrading (1 1 1)
- OpenFOAM Version 1.0
- OpenFOAM Version 1.1
- OpenFOAM Version 1.2
- OpenFOAM Version 1.3
- OpenFOAM Version 1.4
- 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.4-dev
- OpenFOAM-Extend Version 1.5-dev
- OpenFOAM-Extend Version 1.6-ext
- FOAM-Extend Version 3.0
- Mesh generation utilities