Using FreeCAD FEM workbench with External Gmsh mesh

Creating a body in FreeCAD but being able to use a mesh made externaly in Gmsh can be useful when you want to use all the latest features from Gmsh. In this article I will be exploring how this is done in FreeCAD.

  1. FILE TYPES

  2. HOW TO DO IT

  3.  DIFICULTY RATING

1. FILE TYPES

To be able to perform this approach it is important to understand the main file types involved in the process. To enable this we need to create in FreeCAD an output file that will be read by Gmsh and an input file generated by Gmsh that will be read by FreeCAD.

  • FREECAD output to Gmsh: .BREP file

 This file type is an OPENCascade format and will contain the geometry that Gmsh needs.

Want more details? Check here: https://dev.opencascade.org/doc/occt-6.7.0/overview/html/occt_brep_format.html

  • FREECAD input from Gmsh: .unv file

This file type will contain the mesh. Nodes, elements and solids… This format will replace a mesh built inside Gmsh in FreeCAD. The origin of this file type can be seen in the following link: http://fileformats.archiveteam.org/wiki/UNV

2. HOW TO DO IT

We start by creating or importing a geometry into FreeCAD. In my case I built the geometry.

FreeCAD 2D Geometry

FreeCAD 2D Geometry

You need to select the geometry or Part in FreeCAD and then go to File -> Export

FreeCAD Export menu

FreeCAD Export menu

Next you need to open Gmsh and go to File -> Open 

Gmsh BRep inport

Gmsh BRep inport

After this the geometry is displayed in Gmsh. Next you have to create a mesh. On the tree view in the left click 1D and finally 2D to get the surface elements. In my case I have a shell so I don’t need 3D elements.

Gmsh generic Hex mesh

Gmsh generic Hex mesh

After a mesh is generated we need to export the mesh in a format that FreeCAD can work with. For this we need to export to .unv, go to File -> Export

Gmsh mesh export

Gmsh mesh export

From the new window select I-deas Universal (*.unv)

Gmsh export to unv

Gmsh export to unv

Now you can close Gmsh if no more editing is needed.

It was in this part that I had most difficulty. Not because of the complexity but because I could find the unv file format. To import the mesh to FreeCAD you will need to go to File -> Import

FreeCAD import unv

FreeCAD import unv

The option is in FEM mesh formats (…, *.unv, …).

After this you will see on the tree view the following:

Imported mesh in FreeCAD

Imported mesh in FreeCAD

All the rest is the same procedure to create a simulation in the FEM workbench from FreeCAD.

FreeCAD FEM workbench model

FreeCAD FEM workbench model

 

Model with imported mesh

Model with imported mesh

From here with the model built with boundary conditions and material data you can now solve.

Calculix solved result

Calculix solved result

Importing the mesh done in Gmsh worked with no problems. The same workflow should work on other meshers as long as the formats keep the same.

3. DIFICULTY RATING

Afters this guide, meshing out of freeCAD is easy as it gets. Our rating for this guide is EASY to follow.