Best Open-Source Mesh Generation Libraries (GUIs + Python)

Best Open-Source Mesh Generation Libraries (GUIs + Python)

This is a quick review of the some of the most important open-source mesh generation platforms and libraries.


Introduction

In the complex landscape of engineering simulation, the tools we use can make a significant difference in the efficiency and effectiveness of our projects. Open source software has emerged as a powerful alternative to proprietary tools, offering flexibility, cost savings, and a vibrant community of developers and users to which we are proud to be a part of.

Of course, one of the main appeals of open-source tools is they eliminate the need for expensive licenses, making high-quality software accessible to small businesses, startups, and individual engineers. Additionally, with access to the source code, users can customize and adapt the tools to meet their specific needs.

But are there any shortcomings associated with these libraries? How are they in terms of ease of use and feature-parity with their commercial counterparts?

In this blog post, we will provide a quick overview of some of the most important open-source meshing tools, exploring their potential and the challenges they present for engineering projects.

Meshing and Pre-processing “Platforms”

The first type of projects that users will tipically encounter are large “pre-processing platforms” that integrate many different algorithms and functionalities. These include even some of the funcionality we would expect from CAD software rather than from purely mesh-generation software.

The most well-known and most popular pre-processing platforms are Gmsh and Salome, which we discuss in the following subsections.

Salome: Comprehensive Pre- and Post-Processing

Salome mesh example

Salome integrates multiple open-source tools and offers a comprehensive environment for pre- and post-processing. It includes a GUI for geometry and meshing tasks and supports scripting in Python to automate workflows.

Gmsh: Flexible Meshing for 3D Simulations

Gmsh mesh example

Gmsh is known for its powerful meshing algorithms and flexibility. It offers a GUI for basic operations and extensive scripting capabilities in Python and its own scripting language (in .geo files) for advanced meshing tasks. In addition to its own core routines, it provides bindings to many third-party open-source libraries for specific low-level routines.

Netgen: A pre-processing platform

Netgen mesh example

Netgen produces high-quality surface and volume meshes for finite element simulations. Tightly integrated with NGSolve, it relies on a Python interface and a GUI. It integrates its own constructive solid geometry (CSG) system for parametric modelling, and it can also supports boundary representations based on STL files as well as STEP and IGES files via the OpenCascade CAD kernel.

OpenFOAM snappyHexMesh: hex meshing for CFD

Netgen mesh example

Even though OpenFOAM is an open-source CFD simulation tool, it also contains its own meshing routines. For example, snappyHexMesh is one of the key meshing utilities within OpenFOAM, designed to generate 3D meshes based on hexahedral and split-hexahedral elements. It is particularly suited for handling complex geometries, working directly from triangulated surface data, such as STL files. snappyHexMesh automatically refines and snaps the mesh to surfaces, ensuring a good fit to complex shapes, and allows for local refinement based on user-specified criteria, making it highly flexible for fluid dynamics simulations. Additionally, it includes tools for boundary layer generation and mesh smoothing to optimize mesh quality.

  • License: GPL (General Public License)
  • Website: OpenFOAM
  • Documentation: snappyHexMesh section in the OpenFOAM user guide.

Lower-level 3D meshing libraries

Tetgen: Efficient Tetrahedral Mesh Generation

Tetgen mesh example

Tetgen specializes in generating tetrahedral meshes efficiently, making it ideal for 3D simulations requiring complex meshing. While it does not have a native GUI, it can be integrated with other tools and scripted using Python.

TetWild: Robust Tetrahedral Meshing

TetWild mesh example

TetWild focuses on robust tetrahedral meshing and can handle challenging geometries with ease, providing reliable meshing for complex projects. It can be scripted using Python for customized workflows.

MMG3D: Automatic 3D Mesh Adaptation

MMG3d mesh example

MMG3D focuses on remeshing rather than meshing. It can adapt tetrahedral meshes to fit complex geometries and improve mesh quality. While it does not offer a GUI, it can be easily integrated into other software and scripted in Python for automated mesh adaptation processes.

CGAL Mesh Generation Package

MMG3d mesh example

The CGAL Mesh Generation Package is part of the Computational Geometry Algorithms Library (CGAL) and provides tools for generating high-quality tetrahedral meshes for 3D domains, as well as 2D triangular and 1D meshes. It is designed for applications such as finite element methods (FEM) and numerical simulations, with advanced algorithms for mesh refinement and optimization. The package supports complex geometries, including implicit functions, CAD data, and polyhedral surfaces, and offers adaptive meshing based on user-defined criteria for improved precision and quality.

  • License: Some parts of CGAL are available under the LGPL, whereas other parts are under the GPL. A commercial license is also offered.
  • Website: CGAL
  • Documentation: for the mesh generation package can be found here.

2D meshing

Of course, platforms like Gmsh can be used for 2d meshing, but they might be somewhat of an overkill in some applicaitons. If you are looking for a lightweight and powerful solution for 2d problems specifically, you can resort to the following tools:

Triangle: High-Quality 2D Meshes

Triangle mesh example

Triangle is a 2D mesh generator that excels in creating high-quality triangular meshes for planar problems. It does not include a GUI but can be controlled via command-line and scripted in Python.

scipy.spatial.Delaunay

Scipy mesh example

scipy.spatial.Delaunay is a part of the SciPy library that provides tools for computing the Delaunay triangulation of a set of points. While it is mostly used as a 2D triangulator, it supports N dimensions. The function takes a set of input points and constructs simplices (triangles in 2D, tetrahedra in 3D, etc.) that cover the convex hull of the points. It ensures that no point is inside the circumcircle of any simplex.

Potential Challenges and Sweet Spots

In many simulation problems, we have simple geometries but very challenging physics. These types of situations arise naturally both in academic research and industry. If the geometric requirements of a problem are relatively straightforward and can, for example, be scripted or drawn with ease, it can be anticipated that all of the benefits of leveraging open-source software and very few of the shortcomings will be met, making this the ideal use case for open-source meshing tools for the non-expert user.

As for the challenges cases, they take place especially when dealing with complex geometries. Here are some common issues and tips for overcoming them:

  • GUI limitations: Tools like Gmsh have powerful algorithms, but their graphical user interfaces (GUIs) can be limited. To fully leverage their potential, users often need to delve into scripting to build their desired workflow. Investing time in learning the scripting languages and capabilities of tools like Gmsh can pay off in the long run.
  • CAD software and mesher communication: Ensuring seamless communication between CAD software and the mesher can be tricky. For example, surface and volume markers might get lost during the transition.
  • CAD model preparation: A difficulty that is not specific to open-source, preparing CAD models for meshing can be challenging due to issues like geometry imperfections, inconsistent surface definitions, and complex topology, which often require extensive manual cleanup and adjustments to ensure proper mesh generation and simulation accuracy.

Conclusion

Open source meshing tools offer a compelling alternative to proprietary software, providing flexibility and cost savings. While they present unique challenges particularly for very complex geometries, the benefits they offer make them a valuable addition to any engineer’s toolkit.

Professional Support and Consulting for your Simulation Projects

Learning how to use open-source simulation tools and resolving the various steps involved, such as CAD modeling, mesh generation, and pre- and post-processing, can be challenging and time-consuming. Given this context, getting help from consultants or contractors can be very convenient.

At EpsilonForge, our core service is providing professional support and consulting for your Electromagnetic simulation needs. We would be very pleased to work with you. Let's talk!