Want to easily Make advanced detailed Hex mesh in Gmsh?

Gmsh hex cube

Gmsh hex cube

On some commercial applications meshing is integrated like Ansys or Fusion 360, however on the open source landscape a mesh generation software is developed separately from the solver. Gmsh works with solvers like Calculix for example. Mesher and solver can come integrated into a CAD application like FreeCAD. Although the mesher can be quite powerful it’s user friendliness is still far from the target. Hopefully these valiant developers will get there! For now the best path is to try and simplify how things work and how they are integrated. I am hopping this will give a good push to those who want to know this application works and connects.

  1. HOW TO CREATE A CUBE IN GMSH, 

  2. DEFINING HEX ELEMENTS, SIZING AND REFINING,

  3. OUTPUT FORMATS

  4. SUMMARY

1. HOW TO CREATE A CUBE IN GMSH

When loading Gmsh make sure no geometry was loaded.

Gmsh 4.8.4 GUI

Gmsh 4.8.4 GUI

Creating a cube is very easy. Go to Geometry -> Elementary Entities -> Add -> Cube. To generate a cube you select the location of the cube coordinate (X, Y, Z) and the cube relative length (DX, DY, DZ) and don’t forget to press Add. To close press q or you will see another red cube moving around.

Gmsh 4.8.4 add cube

Gmsh 4.8.4 add cube

After the cube is generated a geo file is updated. Gmsh actually in the beguiling asks you to save a geo file. The solid you built information is stored in this file. All manipulations of geometry by Gmsh will be stored here. If you change the file coordinates and press reload script the geometry will refresh. This is good if you want to change the geometry on the fly without menus.

Cube geo file in Gmsh 4.8.4

Cube geo file in Gmsh 4.8.4

In another article I will dive into how we can import a file from a external format like a .STEP file.

2. DEFINING HEX ELEMENTS, SIZING AND REFINING

To start creating a mesh is very easy. I first click 1D to see the nodes, then click 2D to see the 2D mesh and if happy finally select the 3D menu item. By default what appears is controlled by the options menu, please verify if active the following:

  • 2D element edges
  • 2D element faces
  • 3D element edges
  • 3D element faces
Mesh visuals Gmsh 4.8.4

Mesh visuals Gmsh 4.8.4

By default Gmsh produces a tetrahedron mesh with the following config:

  • 2D algorithm: Frontal-Delaunay
  • 3D algorithm: Delaunay
  • 2D recombination: Blossom
  • Recombine all triangular meshes: Deactivated
  • Subdivision algorithm: None
  • Min/Max element size: [0,1e+22]
Default Gmsh 4.8.4 Tet mesh

Default Gmsh 4.8.4 Tet mesh

To generate a Hex mesh instead the following configurations need to be setup on the options menu:

  • 2D algorithm: Frontal-Delaunay for Quads Experimental
  • 3D algorithm: Delaunay
  • 2D recombination: Blossom
  • Recombine all triangular meshes: Activated
  • Subdivision algorithm: All Hexas
  • Min/Max element size: [0.05,0.1]
Gmsh 4.8.4 Hex mesh

Gmsh 4.8.4 Hex mesh

It is important to note if any errors were produced in the status window. If no errors appear you are good to go and press 3D for the final mesh. If everything runs ok you will get a summary of the generated mesh in the status window.

Gmsh 4.8.4 Status window 3D mesh

Gmsh 4.8.4 Status window 3D mesh

3. OUTPUT FORMATS

To export the mesh, under the mesh menu item select Save. This will create a .msh file that can be used with a solver like Calculix, Elmer, LS-Dyna, … The export function is located in the bottom of the file menu and provides numerous formats  that deserves a detailed look in the future. 

Exporting to STL file in Gmsh 4.8.4

Exporting to STL file in Gmsh 4.8.4

 

4. SUMMARY

In this article it was demonstrated what parameters need to be changed to produce a Hex mesh. It was also explained what is the basic workflow and configurations necessary to produce a basic mesh. In the end it is shown how to create the final mesh file .msh or to export to a more generic format like .stl.