CAD File Import, Mesh, and Grid Generation with Gmsh

CAD File Import, Mesh, and Grid Generation with Gmsh

Gmsh is a popular cross platform and open source mesh generation software. Gmsh supports many CAD file formats such as STEP, IGES, and STL, as well as also includes a variety of integrated mesh generation algorithms, such as from Triangle, Tetgen, and Netgen, Gmsh can be used together with FEATool to allow for more complex geometries and models to be meshed than the built-in grid generator.

Although FEATool Multiphysics features built-in support for importing and meshing CAD geometries, more control of the process can be achieved by performing the import steps manually. This can for instance be useful for more difficult geometries which need to be repaired to allow simulation. In the following it is therefore described how Gmsh can be used to manually import a CAD geometry from a STEP file, and to generate a mesh which can be imported and used with FEATool.

Gmsh CAD File Import and Mesh Generation Tutorial

This is a tutorial example showing how to import STEP model into Gmsh, and generate a 3D volume finite element mesh. The STEP file CAD model used in the example can be downloaded from the link below

Fixed Spanner CAD STEP Model

1. Start Gmsh (using version 2 Mesh File Format)

FEATool currently only supports Gmsh mesh file format version 2 (default in Gmsh versions 2-3), which was replaced with an incompatible format in Gmsh version 4.0 and later. To ensure that Gmsh v4 saves and exports meshes in version 2 format one can either start Gmsh with the command line argument -format msh2, for example

gmsh.exe -format msh2

or set the following option in the general or mesh specific Gmsh .opt file

Mesh.MshFileVersion = 2;

The option files can be generated by selecting Save Model Options or Save Options As Default in the File menu.

If there are issues importing the mesh into FEATool one can also optionally try to add the -save_all command line argument which corresponds to the Mesh.SaveAll = 1; .opt file option.

2. CAD Model Import with the Merge Operation

The second step is to use the Gmsh Merge option, found in the File menu. This opens a file selection dialog box where the CAD file to import can be chosen. Select the spanner.step file and press Open to automatically let Gmsh load, import, and construct edges and faces for the geometry. If the model has been imported successfully it should be displayed and shown in the GUI CAD window where it can be inspected.

Gmsh CAD Step File Import And Mesh Generation Tutorial - Merge

3. Setting Mesh Options and Specifying Grid Size

Gmsh supports several options to specify mesh and grid sizes. One can for example prescribe sizes at points, and define mesh size functions. Here the Min/Max Element Size option is used to set a global maximum mesh size of 6 mm (as the model units is defined in millimeters). This option is found on the Mesh > General tab of the Options dialog box. A description of the available mesh options is available in the Gmsh reference guide.

Gmsh CAD Step File Import And Mesh Generation Tutorial - Options

4. 3D Mesh and Grid Generation

To generate a 3D volume mesh, first click on the [+] Mesh node in the left hand side tree list to expand it, then click to the 3D node option to call the selected mesh generation algorithm. If everything goes correctly the final mesh should be displayed in the Gmsh GUI window.

Gmsh CAD Step File Import And Mesh Generation Tutorial - 3D

5. Mesh Info, Saving and Mesh Export

Progress information and messages are displayed in the bottom line of the Gmsh GUI. Clicking on this line also opens the message and log window where one can see information about the mesh generation process.

Once a mesh has been generated it can be saved in the Gmsh ASCII file format by using the Save Mesh option from the File menu (the file will be saved in the same directory and name as the imported CAD file but with the .msh file extension).

Gmsh CAD Step File Import And Mesh Generation Tutorial - Info and Save

FEATool-Gmsh Mesh Import and Export Function

To import and use a Gmsh grid file with FEATool GUI one can either use the Import Grid > Gmsh Format option found under the Grid mode menu.

FEATool and MATLAB Gmsh Mesh and Grid Import

Alternatively, the impexp_gmsh function can be used directly on the MATLAB command line, with for example the following commands

grid = impexp_gmsh( 'spanner.msh', 'import' )
plotgrid( grid )
plotbdr( grid )

How to import the CAD model in FEATool, define and set up simulations is explained in the following parametric structural mechanics simulation, and stress and displacement analysis tutorial.

Download and try FEATool Multiphysics with Gmsh integration