Skip to content

High-level overview of meshing for OpenFOAM (and others)

Here, I’ll give a high-level overview of my opinions on open-source meshing for OpenFOAM. This post should help point you in direction of the mesher you could use to accomplish your simulating goals! But I won’t go into each mesher in detail here. As this would become a novel. This is just my opinion on what mesher I use in a few typical cases.

During my PhD we were very spoiled and used the software Pointwise to generate our meshes. I still love Pointwise, and if I ever decide to move away from open source meshing that will be my choice. But today is not that day! For users of open-sources software, including OpenFOAM, meshing is a constant struggle. Especially if you’re new. I have even known people who thought about using OpenFOAM and then gave up simply because they thought that blockMesh was the only way to make meshes in OpenFOAM. If that were the case – needless to say – countless applications would be impossible. Don’t give up! You can mesh pretty much anything given the tools that are out there!

In my experience the key meshing options for the user of OpenFOAM are:

  • blockMesh (All version of OF)
  • cfMesh ( <=v4, foam-extend, V18+)
  • SnappyHexMesh (All versions of OF)
  • gmsh (independent)
  • Salome (independent)

Of these, each meshing software has its own advantages and disadvantages and have types of meshing where they perform the best. I’ll try to break this down based on my experience. Of course, some people will disagree with my views as meshing (somehow) can be a deeply personal adventure.

Structured 2D or Simple 3D Meshes

In this case, the answer is pretty simple: blockMesh

blockMesh has a slightly steep learning curve but all it takes is practice and reminding yourself of the right-hand-rule. If your geometry is easily represented by a reasonable number of points and curves – blockMesh is a good option. You would be surprised what you can mesh in blockMesh – if you have the time… but who has the time! That being said, blockMesh is the ideal OpenFOAM mesher for simple 2D and 3D geometries. Because it is essentially a “structured” mesher you easily achieve very good mesh quality, excellent orthogonality, and have fine control over the mesh in ways unstructured meshers do not provide. (NOTE: Structured vs Unstructured has become a blurry terminology, and in fact, all OF meshes are unstructured…. even if you use a blocking strategy… Ugh.).

A major advantage of using the native OpenFOAM meshers is that they can interface seamlessly with whatever scripting language you prefer. If your code can interface with the OS, it can interface with OpenFOAM – and by extension its meshers. I frequently use blockMesh to build a template. I then leave blanks where my control variables will go and then fill them in at run-time using either bash or python scripting! This makes parametric studies a breeze.

Moving structured mesh created in blockMesh

Tetrahedral (Tet-Dominant) Meshes

There are lots of limitations of using tet-dominant meshes in CFD. However, I won’t go into those here. There are many times when a tet-mesh is the most straight-forward to produce. If you don’t have important boundary layer zones to produce, ripping out a quick tet-mesh can have huge time savings.

In these cases, I usually use either Salome’s built-in Netgen module or gmsh. cfMesh has a tet-mesh generator as well, but if I’m using cfMesh I am always using a hex-dominant mesh.

Key to the effective generation of tetrahedral dominant meshes is the ability to generate layers at the wall. This can be a challenge in each of these programs. So no matter what you use – prepare to be patient. I have found that the boundary layer generation in Salome is quite robust. However, it occasionally produces some very poor quality regions which you need to be careful of. I have not had much success with layer generation in gmsh, but if I’m being honest, I haven’t spent too long trying. I have other tools – and generally prefer hex-meshes anyway.

Salome-Netgen Mesh of the Drag Prediction Workshop geometry

Hex-Dominant Meshing

For hex-dominant meshing, your options are blockMesh (if you can create your geometry easily enough), cfMesh, or snappyHexMesh.

snappyHexMesh is a pretty nice tool, and is my mesher of choice for any multi-region meshing (see next section). But compared to cfMesh I find it much less robust. The key area where this is true is in layer generation. There are ways to get consistent layer generation in snappyHexMesh (i.e. providing a separate meshQualityDict where you turn off many of the paraemeters) but even then it can still be challenging. I have found that in almost all cases, I can achieve consistent, high-quality, boundary layers using cfMesh. Not only this, but I have found the workflow using cfMesh to be a breeze. Especially if you use the supplied Salome scripts to produce your geometry file (separate post on this to follow).

snappyHexMesh grid of the Drag Prediction Workshop Geometry
cfMesh of the Ahmed Body

Multi-Region Meshing

Multi-region meshing is required for several different applications. The main ones I have encountered are rotating zones (for machinery and turbines), and conjugate heat transfer (for separate solid and fluid regions). For multi-region meshing in OpenFOAM, I almost always use snappyHexMesh. The primary reason for this is that is extremely simple to create in your workflow. As an example, let’s consider the case of a simulation where you plan to have rotating and static zones separated by an arbitrary mesh interface (AMI). When using cfMesh, gmsh, or Salome you typically have to create both meshes, and then combine them using the mergeMeshes command. This is can be very tedious. However, in some cases it can be worth it if you can achieve better mesh quality with one of these programs. However, you can definitely get good mesh quality with snappyHexMesh.

Multi-region rotating mesh created in snappyHexMesh

A sobering exercise

If you want a sobering exercise, google the Drag Prediction Workshop website, get the geometry, and try to mesh it using open source software and meet their gridding requirements. Here are some of the requirements for the COARSEST MESH:

  • Minimum of 8 cells across the trailing edge of the wing
  • Y+ < 1.0 (equivalent to dy=0.0006 mm)
  • 2 cells close to the wall with no growth
  • Growth rate <1.25 for the rest of the layers

The list goes on – and some of the example meshes will have 20+ layers.

Anyway, I hope someone finds this post useful to point them in the direction of a good meshing software for their application!

If you are struggling with CFD, are interested in getting started, or are looking for consulting services, visit for information on CFD consulting services including training, development, private webinars and other simulation services.

Happy Open-Source Gridding!




2 thoughts on “High-level overview of meshing for OpenFOAM (and others) Leave a comment

  1. I’ve been trying to learn how to generate mesh with Salome. I’m currently using DPW 6 geometry, but everytime I import it to salome I always have this error when trying to generate the surface mesh.

    It shows error in triangulation thing after meshing process. I’m completely confused and I don’t know what to do. I wonder if it just the bad geometry or me not knowing how to generate mesh properly and handling these kind of errors? Please enlighten me.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: