< Back

# Finite Element Analysis with FreeCAD on Qarnot Cloud – documentation

by Alexis de la Fournière - October 28, 2021 - Documentation

# Introduction

FreeCAD is an open-source parametric 3D modeler made primarily to design real-life objects of any size. Thanks to its active community, it also has many features integrated, including a module to perform finite element analysis.

The finite element method is the most widely used numerical method to perform physical simulations in fields like mechanics, heat science or electrostatic. It can even be used to perform fluid dynamics simulations and to resolve multiphysics problems. Many solvers, including free and open-source ones, implement this method. The FEM workbench from FreeCAD integrates these solvers inside FreeCAD, which makes it possible to use its modelling capabilities within a unified GUI.

Qarnot’s plugin makes it possible to send FEM computation on Qarnot’s platform, hence making you save time and computer power. It also makes it possible to send several simulations at once or let a simulation run overnight while the computer is shutdown.

# Versions

The macro works with FreeCAD 0.19. It doesn’t work with previous versions.

Release year Version
2021 0.19

The macro currently supports the following solvers :
• CalculiX

• Elmer

• z88

If you are interested in another version or another solver, please email us at qlab@qarnot.com

# Prerequisites

Make sure you fulfill Qarnot prerequisites before launching the case :

• Create an account here. First 15€ are free !
• Install Python SDK with the command pip install qarnot

You will also need FreeCAD with Gmsh installed and the macro. Here is how to install them :

1. Install the last version of FreeCAD from its website. If you are a Linux user, once the .AppImage is downloaded, use the command chmod +x FreeCAD_0.19****.AppImage to make it an executable.

2. Install and configure Gmsh :

1. Download Gmsh binaries and unzip it somewhere. Versions previous to 4.8.0 may cause some error. If you are a Linux user, make sure to download the last version instead of using, apt-get which installs a deprecated version. Run gmsh to make sure it is correctly installed.

2. Open FreeCAD and go to the FEM workbench, then to Edit -> Preferences -> FEM. Select Gmsh tab and fill in the path to the Gmsh binaries (for exemple /home/gmsh-4.8.4-Linux64/bin/gmsh)

3. If you want to use Elmer, you will need to install it as well. The method is the same as for Gmsh :
1. Download the binaries or install them with apt-get if you are a linux user
2. If you downloaded the binaries, go to Edit -> Preferences -> FEM, select Elmer and fill in the path to the two Elmer binaries (ElmerGrid and ElmerSolver)
4. Go to the macro’s GitHub, and clone or download the code in your macro folder. Its location can be seen at the bottom of the macro selection window opened by the execute macro button (see below).

5. If the macro code is in a subfolder of the Macro folder, do the following :

1. Copy the FemCloudComputingQarnot.FCmacro file in the macro folder

2. In FreeCAD, click the execute macro button, select, FemCloudComputingQarnot.FCmacro and click edit on the right.

3. Edit the line sys.path.insert(1, '*******') by changing the stars to the folder in which the code was downloaded. For example, on my computer it would be sys.path.insert(1, '/home/alexis/.FreeCAD/Macro/qarnot-freecad-plugin')

4. If you are using version 0.19.3 or after, you will also need to tell FreeCAD where you installed qarnot sdk. To do that, open a standard python console and execute
import qarnotqarnot.__file__
Then, in the macro, below the first sys.path.insert line, add a second one with the printed path to the SDK. For example, if the console outputs, '/usr/local/lib/python3.8/dist-packages/qarnot/__init__.py', the line sys.path.insert(1, '/usr/local/lib/python3.8/dist-packages') should be added.
6. Save with Ctrl+S. You can now close the tab displaying the macro code.

The execute macro button

The macro folder location

# Test case

The purpose of the test case is to study the bending of a rectangular beam under a load. It can be accessed directly in FreeCAD from the FEM workbench in Utilities -> Open FEM examples -> Solvers -> (CalculiX or Elmer or z88) -> CCX cantilever face load.

# Launching the case

The execute macro button

To start the case, simply click on the execute macro button, and select FemCloudComputingQarnot.FCmacro. If the macro doesn’t start, and you have an error like No module named 'gui', try to close and restart FreeCAD after making sure the macro and the code are at the right place. If the error is No module named 'qarnot' then make sure you filled in the right path for Qarnot SDK as explained in the prerequisite section (5.d)

On the window that appears, click on the set token button and fill in your secret token that you can get from here.

Then click on the solver you want to use (SolverCalculiX, SolverElmer or SolverZ88) and click on start. You can monitor your tasks on Qarnot’s console by clicking the link icon next to Current tasks. Once the task is finished, select it and click load.

# Results

The results can be visualized like any other FreeCAD FEM results. Here is a way to do so :

• If you used CalculiX or Z88, select CalculiX_static_Results or z88_Z88_static_result and click on FEM PostPipelineFromResult. If you used Elmer, you can skip this step.

• Before visualizing the result, make some place by hiding other objects (this may have been done automatically). To do so, simply select an object in the object tree (in Labels & Attributes panel) and press the space bar to hide or show the object. I would recommend hiding the Mesh object and the constraints.

• Double-click the post pipeline object (named ResultPipeline or SolverElmerResult). In the mode list, select Surface with Edges. Then, in field, choose displacement. The 3D view should now display a colored mesh that represent the magnitude of displacement of the cantilever beam. Click ok to close the task. If the faces of the mesh don’t appear colored, go to Edit -> Preferences -> Display -> 3D View and enable Backlight color

• To better visualize the bending, select the post pipeline object (ResultPipeline or SolverElmerResult) and click on Warp filter (next to the previously used create pipeline button). Use the slider to select the warp factor, e.g. the ratio between the real displacement and the one displayed. For example, you can choose 10 to best see the warp (change the maximum factor if needed). Then, in the panel underneath, chose Surface with edge and displacement in the mode and Field lists. A new 3D object should have appeared on the 3D view. It shows the bent cantilever. Click ok to close the task.

• At this point, it is possible that your previous mesh result object appears all red or orange. To solve this problem, you simply need to make FreeCAD actualize the drawing. Double-click the result object and in the list select Displacement again.

• Use the space bar to hide or show objects. In the object tree, the warped result object is inside the pipeline object, so click the expand triangle to see it.

# Wrapping up

The macro also has a few more features that are explained in the image below :

You can also find more information here on how the code works and how to use it in a non-GUI environment, for example in order to write a script to start a bunch of simulations at once.