CAD to FEniCS example

A geometry file can be created in a CAD software, meshed in NETGEN, and analyzed using FEniCS. Below is a short example showing the process.

Creating a .STL geometry file edit

Several CAD programs like SolidWorks or Pro/ENGINEER can export a geometry file to .STL format. This format allows a part to be meshed use NETGEN.

Pro/E Wildfire edit

Under File > Save a Copy... select STL in the drop down menu for file type. Hit OK and an Export STL window will appear. Choose ASCII under Format and set Chord Height to 0 (it will then default to the minimum acceptable value) and Angle Control to 1. Hit Apply and OK.

 

SolidWorks edit

Under File > Save As... select STL in the drop down menu for file type. An Options button will appear which will allow you to select ASCII format as well as the Resolution.

 

Generating and exporting a mesh edit

After installing NETGEN, you can open an STL file by typing "netgen filename.stl" in the terminal. Hit Generate Mesh for a very quick and basic meshing. You'll probably want to refine and optimize the mesh using the options under the Refinement and Mesh tabs.

 

We need to eventually convert the mesh into a format readable by FEniCS. Start by following File > Export Filetype and selecting DIFFPACK Format. Other formats can be converted but may have issues. For example, using the Gmsh format will lead to an error later. Now choose File > Export Mesh and enter a filename followed by .grid, the DIFFPACK extension.

Using dolfin-convert for a final conversion edit

In the terminal locate your recently exported mesh in .grid format. Enter "dolfin-convert filename.grid filename.xml" to convert the file to .xml, which is readable by FEniCS. You can then enter "gzip filename.xml" for good measure.

Using your mesh edit

The mesh file is now ready to be used in a python script, like any other mesh file. Below are some results from a Python script using FEniCS to determine eigenmodes.