HowTo blockMesh with m4

From OpenFOAMWiki
Revision as of 12:41, 30 January 2006 by Bgschaid (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to quickly change the mesh with blockMesh

The Gnu preprocessor m4 is handy for parametric refinement to the mesh. It is also possible to change position of multiple vertices at the same time, thus reducing the possibility of errors when altering the mesh.

Example:

 
changecom(//)changequote([,])
 
define(calc, [esyscmd(perl -e 'printf ($1)')])
 
define(VCOUNT, 0)
 
define(vlabel, [[// ]Vertex $1 = VCOUNT define($1, VCOUNT)define([VCOUNT], incr(VCOUNT))])
 
 
define(hex2D, hex ($1b $2b $3b $4b $1t $2t $3t $4t))
 
define(quad2D, ($1b $2b $2t $1t))
 
define(frontQuad, ($1t $2t $3t $4t))
 
define(backQuad, ($1b $4b $3b $2b))

The first four line of codes simply define a calculator, sets a variable VCOUNT = 0 and defines a new way of defining vertices. The last four are for defining 2D cells, as well as patches for the boundaries. The b is short for the bottom and t for top, that is the bottom and top of the 2D cell set.

So imagine we want to create a vertex at the position (2,4,8), instead of:

 
vertices
    (
        (2 4 8)
    )

We can now type:

 
define(Ax, 2)
define(Ay, calc(2*Ax))
define(Az, calc(2*Ay))
 
vertices
    (
        (Ax Ay Az) vlabel(a1b)
    )

Then, assuming a1t, a2b,a2t,b1b,b1t, b2b, and b2t has been defined, the definition of a block is simply:

 
blocks
    (
        hex2D(a1, b1, b2, a2)
    )

When the file is finished, assuming it's called blockMeshDict.m4, one simply types

m4 blockMeshDict.m4 > blockMeshDict

Before running blockMesh as usual.