Meshing Tutorials 
 m4 macro for blockMesh 

blockMesh parametrisation with m4

Software Prequisites:

  • OpenFOAM 2.1.0
  • m4

About blockMesh:

BlockMesh is a built in mesher in OpenFOAM®. It has capabilities for creating simple block structured meshes, not meshes for complex geometries. The usage of blockMesh is described here.

This example shows how to parametrize my o-grid example. For parametrisation the m4 macro language will be used ( m4 homepage ), therefore it is required that you have m4 installed. A description of using m4 with blockMesh is also available on the OpenFOAM® Wiki page here.

About the m4 file:

The m4 file will generate the a similar blockMeshDict file as my blockMesh example.

Parametrisation of the mesh:

  • length of the pipe with variable zLength
    define(zLength, 1)dnl
  • size of core rectangle with coreWidth
    define(coreWidth, 8)dnl
  • pipe diameter with diameter
    define(diameter, 30)dnl
  • bounding rectangle with rectangleWidth
    define(rectangleWidth, 50)dnl
  • switching bounding rectangle on/off (1/0) with boundRect
    define(boundRect, 1)dnl
  • cell count for the half core rectangle with coreCount
    define(coreCount, 10)dnl
  • cell count for the blocks between pipe and bounding rectangle sides with rectangleCount
    define(rectangleCount, 20)dnl
  • conversion of sizes (basic blockMesh functionality, e.g. convert to mms with the value of 0.001)
    convertToMeters 0.001;
  • position of core rectangle corner points with cornerStretch
    define(cornerStretch, 0.77)dnl
  • position of ghost points for core rectangle side arcs with arcStretch
    define(arcStretch, 1.07)dnl
  • boundary patches are created in the current version of the macro. Bounding box is considered. Patch names are: in, out and walls.

Corner strecth

cornerStretch sets the position of the core rectangle corners. If this value is specified as 1.0 than the core rectangle will be an exact rectangle. Examples:

cornerStretch = 1.0

cornerStretch = 1.0

cornerStretch = 1.3

cornerStretch = 1.3

cornerStretch = 0.77

cornerStretch = 0.77

Usually the cornerStretch shall be specified to a value lower than 1.

Arc strecth

arcStretch has an impact on the shape of the sides of the core rectangle corners. In the blockMeshDict file these sides are defined as arcs. In blockMesh the definition of arc a third "ghost point" shall be defined: the arc will cross this point. The arcStretch variable is defined to have straight core rectangle sides when its value is 1.0. Examples:

arcStretch = 1.0

arcStretch = 1.0

arcStretch = 1.2

arcStretch = 1.2

arcStretch = 0.8

arcStretch = 0.8

cornerStretch = 0.77, arcStretch = 1.07

cornerStretch = 0.77, arcStretch = 1.07

Last example shows a good set up for both stretch factors.

M4 file:

Highslide JS

M4 Syntax:

  • Lines starting with define contain definitions. These wariables are used in the scripts afterwards. In the brackets, first the name of the variable than its value should be placed. E.g.:
    define(zLength, 100)
  • The value can be a calculation result based on already exising variables using the calc command. E.g.:
    define(negCoreWidth, calc(-1*coreWidth))
  • dnl prevents the macro to create a new line when in case of a definition or comment line

The m4 macro will simply substitute the calculated value of the variables at the place where the variable is called. E.g.:

( 0 0 zLength ) //1

results in:

( 0 0 100 ) //1


Executing the m4 macro file will create the output to the screen, this should be redirected preferably to the blockMeshDict file.

m4 blockMeshDict.m4 > blockMeshDict

Of course blockMesh should be executed afterwards


Download blockMeshDict.m4 file:


Put the file here: <case>/constant/polyMesh/blockMeshDict.m4

Version: 1.2, 2012-05-18