NACA 4-digit airfoil mesh using blockMesh with m4 macro


NACA airfoils are common in computational fluid dynamics (CFD). This post provides a mesh for NACA-4digits airfoils using blockMesh. It is a generalized piece of code where you can define the 4-digits and angle of attack inside the script to produce the desired mesh for your case. blockMesh is a built-in mesher in OpenFOAM®. It uses simple block structured meshes. I coded it using the m4 macro and Perl commands. I looked at the Håkon Strandenes code written in octave. However, I have coded it from scratch. Please take a look into it and feel free to report or modify it for enhancement using the github repository. I am open to any pull requests that improve this piece of meshing code. To cite this script, please use: DOI

Software requirements:

  • OpenFOAM-dev
  • m4

m4 file:

m4 file contains some commands that finally will generate the blockMesh dictionary. The advantage of using m4 is its ability of parametrisation the mesh.

  • add the complete perl-information into m4 file
define(calc, [esyscmd(perl -e 'use Math::Trig; print ($1)')])
  • labeling the vertices
define(vlabel, [{[{// }]Vertex $1 = VCOUNT define($1, VCOUNT)define([{VCOUNT}], incr(VCOUNT))}])
  • macro to initialize the blocks easily and more systematic
define(hex2D, hex ($1b $2b $3b $4b $1t $2t $3t $4t))
  • macro to define the walls and internal surfaces along $z$ direction
define(btQuad, ($1b $2b $2t $1t))
  • macro to define the inlet
define(bottomQuad, ($1b $2b $3b $4b))
  • macro to define the outlet
define(topQuad, ($1t $4t $3t $2t))
  • conversion of size
convertToMeters 1.0

In order to find the defined vertices and blocks easily, I also show them in a figure below with their labels:

Download blockMeshDict.m4 file:

You can download the file from blockMeshDict . once you downloaded the file move the file to:

$case/system/blockMeshDict.m4

Then executing the m4 macro will generate the blockMeshDict in the same folder:

m4 blockMeshDict.m4 > blockMeshDict

As it is obvious, blockMesh should be executed afterwards.

This offering is not approved or endorsed by OpenCFD Limited (ESI Group), the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks. Ehsan Madadi is not associated to any of these companies and trade marks.