cfMesh
2026-04-12
What is cfMesh?
There are many tools for generating mesh for OpenFOAM. One of them, that is often missed, is cfMesh.
cfMesh is easier and faster than others. It generates meshes, for OpenFOAM model, from surface geometry files (e.g. STL files). It is capable of making hex-dominant mesh, polyhedral mesh, boundary layers (anisotropic) and local mesh refinement.
There are two version of cfMesh, open-source version and commercial. cfMesh comes with OpenFOAM 2412 is open source code. Create Fields, from 2014, develops advanced features on top of cfMesh and sells it as a commercial meshing package CF-Mesh+.
In this blog, we discuss open source cfMesh coming with OpenFOAM 2412.
How to Prepare Geometry
The geometry for cfMesh is a set of STL files. One needs to prepare them before using cfMesh.
Many CAD programs can generate STL geometry file. There are some other program, such as gmsh or paraview, can also generate STL geometry file.
cfMesh doesn’t create patches for boundaries. The boundaries are from STL surface regions. For example, in a geometry STL file, e.g. geometry.stl, there are regions named inlet, outlet and walls, which can be used by cfMesh to specify boundaries.
How to Build Mesh?
cfMesh needs to work in the following file structure. The geometry file is placed under the sub-folder triSurface under the folder constant.
A file meshDict is configured and saved under the folder system. This is crucial for specifying how mesh is generated.
case/
├── system/
│ └── meshDict
├── constant/
│ └── triSurface/
│ └── geometry.stl
When meshDict and geometry.stl are prepared and placed, to generate mesh, the following is invoked from the case root folder to generate a hex-dominant mesh.
$ cartersianMesh
How to Write meshDict
To build a mesh, file meshDict is used to instruct the program on how to make a mesh. meshDict can be configured as simple as below. It is self-explanatory.
surfaceFile "geometry.stl";
// Global cell size
maxCellSize 0.005;
// Keep cells inside geometry
keepCellsIntersectingBoundary 1;
How to Specify Bounaries
It is also simple to specify boundaries. An example is given below.
// Boundary patch definitions
renameBoundary
{
defaultName walls;
patches
{
inlet
{
type patch;
newName inlet;
}
walls
{
type wall;
newName walls;
}
}
}
How to Refine Mesh?
Following gives an example of how to make a local mesh refinement. The example shows how to refine a mesh to cell size 2mm within a box. The region can also be sphere, cylinder etc.
localRefinement
{
refinementBox
{
type box;
centre (0 0 0.01);
lengthX 0.02;
lengthY 0.02;
lengthZ 0.02;
cellSize 0.002;
}
}
In addition to refine mesh in a region. cfMesh can also do surface refinement and edge refinement.
How to Specify Boundary Layer
The example below shows how to specify boundary layer. Note the mesh is anisotropic.
boundaryLayers
{
walls
{
nLayers 3;
thicknessRatio 1.2;
maxFirstLayerThickness 0.001;
allowDiscontinuity 1;
}
}
Summary
cfMesh is easier and faster meshing toolfor generating OpenFOAM mesh. It is an open-source code and is available with OpenFOAM 2412. It is a potentional CFD automation tool. cfMesh can generate hex-dominant and polyhedral mesh.