How to use cfMesh ? A first tutorial based on the Ahmed body
cfMesh is a mesher developed by Franjo Juretić (https://cfmesh.com/) and incorporated in OpenFOAM® (ESI-group version) since v1712. The version available within OpenFOAM® package is v1.1. The source code of cfMesh as well as the user guide can by found inside the installation directory of OpenFOAM® in modules/cfmesh. cfMesh is a very powerful mesher able to generate millions cells in a very short time.
The Ahmed body  is a simplified version of a vehicle geometry. Its shape is simple enough to allow for accurate flow simulation but retains some important practical features relevant to automobile bodies. This tutorial aims to described a simple and easy cfMesh workflow for external flows (aerodynamics, hydrodynamics etc..). Of course other workflows are possible but this one is intended to be as simple as possible.
 : https://www.cfd-online.com/Wiki/Ahmed_body
 : http://cfmesh.com/wp-content/uploads/2015/09/User_Guide-cfMesh_v1.1.pdf
 : https://grabcad.com/library/ahmed-body-4
Meshing with cfMesh
The Ahmed body geometry
The details of the geometry can be found in the reference . The CAD model can be downloaded from grabcad  thanks to Colby Mazzuca.
The geometry has to be exported to stl format to be used a input data of cfMesh. Generally all CAD software allow to export a geometry as stl. Nevertheless it is not always possible to control the density of triangles on the surface, and cfMesh (as well as snappyHexMesh) do prefers a high density of triangles. If you want to improve the surface quality of your stl geometry you can use for example SALOME and the MEFISTO surface mesher. But don’t worry for a first time if you can’t control the triangle density it will also work !
From stl to fms
As described in  cfMesh prefers an fms format for the geometry. Thus we are going to use the command surfaceFeatureEdges to convert our stl geometry to a fms geometry. But before proceeding to the conversion we need to generate a bounding box to define our inlet/outlet/top/bottom and side boundaries. cfMesh has an useful utility designed for that : surfaceGenerateBoundingBox. In the case directory you can type the following command to generate a new stl surface named ahmedBodyBox.stl containing the bounding box patches:
The last 6 numbers stand for the size of the box in each direction as indicated below with the surfaceGenerateBoundingBox -help command.
At this point by inspecting the ahmedBodyBox.stl we can see that 6 new patches have been created and added at the end of the file. The 6 new patches are automatically naturally named :
- xMax and xMin
- yMax and yMin
- zMax and zMin
Once the ahmedBodyBox.stl geometry has been generated the conversion to fms format is done by typing the following command :
For the features capture we use the -angle option with an angle value of 15°. Note that the default angle for features is 45°
Generate mesh and layer with cartesianMesh
The dictionary for mesh (called meshDict) instruction has to be located in the /system directory. cfMesh required minimal user parameters to work.
First the mesh dictionary contains the name of the surface. We have put the same max/min and boundary size to obtain a uniform far field hexaedral mesh.
Now we want to refine the cells close to the Ahmed body especially in the wake region. Thus, we are going to use a box refinement :
Then we would like to refine the cells in the vicinity of the Ahmed body. In the spirit of snappyHexMesh we use the additionalRefinementLevels keyword. A value of 5 means that cells are cut 5 times (in each Cartesian direction) relatively to the far field cells. We also use the keyword refinementThickness in order to define the thickness of the refinement zone.
In order to inflate boundary layer it’s necessary to define a special subdict detailed below. Here 5 layers are inflated with a ratio of 1.2. We also use the keyword optimiseLayer to improve the quality of the layers. The allowDiscontinuity 1 keyword ensures that the layer are not spread over neighboring patches. Note that the default value is 0. So you will often need to play with this parameter.
Finally, because we have used surfaceGenerateBoundingBox it’s useful to rename the patches xMax/xMin/yMax/yMin/zMax/Zmin in a more conventional manner.
Features and Layers
Generating the mesh
For generating the mesh you only need to type in the terminal :
Note that cartesianMesh is automatically parallelized. Don’t forget to run checkMesh to verify that the mesh quality is compatible with the solver requirements. In the present case we obtain the following checkMesh output (number of cells ~ 576 k):
Solving the model with OpenFOAM and simpleFoam solver
The resolution of the numerical model is done with the simpleFoam solver of OpenFOAM. simpleFoam is a special solver for steady-state incompressible laminar/turbulent flows. The air velocity is 40 m/s. The boundary conditions are very classic :
- inlet : fixedValue for U and turbulence. zeroGradient for p.
- outlet : zeroGradient for U and turbulence. fixedValue for p.
- ahmedBody : noSlip for U, zeroGradient for p. Wall laws for turbulence.
- top/bottom/side : zeroGradient for all fields.
For inlet turbulence parameters settings it’s generally advised to use a calculator. Inside the controlDict file it’s often useful to add runtime post-processing function. For example, in this particular case we can obtain forces, y+, wall shear stress and also residuals. During runtime all this results are written in a special folder named postProcessing in the case directory.