Gmsh is a popular cross platform and open source mesh generation software which supports many CAD file formats such as STEP, IGES, and STL. In addition to its own mesh generation algorithms, Gmsh also includes support for a variety of integrated mesh generators, such as Netgen, Tetgen, and Triangle. As such is it one of the most flexible mesh generators, and can be used with
1. Start Gmsh (using version 2 Mesh File Format)
If the resulting mesh is to be used with the FEATool Multiphysics toolbox (or the Gmsh MATLAB API), it is important that the Gmsh mesh file is saved in Gmsh ASCII mesh file format version 2. This format is default in Gmsh versions 2-3, but not in the current Gmsh versions 4.x.
To make sure Gmsh 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 options file
Mesh.MshFileVersion = 2;
The option files can be generated by selecting Save Model Options or Save Options As Default in the File menu of the Gmsh GUI.
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 Merge… option, from the File menu in the Gmsh menubar. Choosing this menu option opens a file selection dialog box where the CAD file to import can be chosen. In this example, select the spanner.step file and press the Open button 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 main GUI window of Gmsh (you can use mouse controls to rotate and zoom in/out).
A description of the different mesh options is available in the Mesh options section of the Gmsh reference guide.
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 to start and run the selected mesh generation algorithm. Once the mesh generation algorithm has finished the resulting mesh should be displayed in the Gmsh GUI window.
Gmsh Import and Export in FEATool Multiphysics
To import and use a Gmsh .msh file with FEATool Multiphysics use the Import Grid > Gmsh Format… option found under the Grid mode menu of the toolbox GUI (note that the mesh file has to have the same 2D or 3D space dimension as the model, and be in Gmsh version 2 ASCII format to be compatible with the toolbox).
.
MATLAB Gmsh Import and Export Functionality
Alternatively, the impexp_gmsh function, from the MATLAB programming and scripting API, can be used directly on the command line to import a Gmsh mesh directly into MATLAB. The following commands imports, exports, and visualizes the mesh in MATLAB
input_file = 'C:\temp\spanner.msh'; % Full path to input mesh file.
mesh = impexp_gmsh( input_file, 'import' );
plotgrid( mesh ) % Plot and visualize mesh
plotsubd( mesh ) % Plot and visualize subdomains
plotbdr( mesh ) % Plot and visualize boundaries
output_file = 'C:\temp\output.msh'; % Full path to output mesh file.
impexp_gmsh( output_file, 'export', mesh );
Toolbox Availability and Download
The FEATool Multiphysics™ toolbox is available as stand-alone
Desktop App, and also as MATLAB toolbox Add-Ons, with fully interactive GUI and cross-platform support for the Microsoft Windows, Linux, and MacOS operating systems. The toolboxes can be downloaded directly from the homepage https://www.featool.com (or installed with one-click from the MATLAB Add-Ons Toolbar).
SOCIAL SHARE CARD GENERATOR