In this article, we’ll introduce FreeFem and the Finite Elements Method. If you’re a FreeFem and a FEM expert, you can jump directly to the Qarnot tutorial part of this article.

# FreeFem and the Finite Elements Method

FreeFem is an open source implementation of the GFEM (Generalized Finite Elements Method) that provides a simple way to solve Partial Differential Equations with automatized functions such as easy mesh generation. The project started in 1987 as MacFem/PCFem though it was rewritten in C++ and renamed FreeFem in 1992. It is now maintained by a team counting a dozen of individuals, and by the FreeFem community.

The Finite Elements Method (FEM), which FreeFem uses, is applied to a physical system by:### Defining the problem’s variables

The FEM is a method that solves a physical problem on a given physical system. Physical laws (elasticity, electromagnetism, ...) are modeled by a continuous partial differential equations system (PDES) that describes the whole system's physics. Those PDES are completed with boundary conditions modelizing the problem at the domain boundaries.

### Creating a mesh

This continuous complex system is discretized in small parts forming a mesh, each part called a finite element. Choosing the mesh size is essential as it will affect precision, errors and computing power needs.

### Applying the PDES to the mesh

With each finite element is associated a discretized partial differential equation system (representing the continuous system, adapted for discretized domains) that can be solved numerically. This system can be modeled by a matrix, each finite element's matrix can't be solved on its own as they are interdependent, but put together they form a matrix representing the complete system that can be solved using computers.

### Solving the matrix

The system is solved at the system mesh's nodes, meaning that the solution is not computed on each point of the system, only at the nodes hence “finite elements”. Interpolation, in particular polynomial interpolation, is used to solve the rest of the system. The FEM was originally used to solve mechanical problems such as stiffness analysis of aircraft structures behaviour, but its applications can be found in all areas of computational physics and engineering.

# How to run FreeFem on Qarnot

There are several steps to run a task on Qarnot, no worries it’s easy! Before we start, you need to create a Qarnot account, we offer 15€ worth of computation on your subscription. First, in a *Qarnot_freefem_distributed_example* folder, create a folder named *resources_freefem_qarnot* and save inside the following FreeFem script as *example.edp*. This example modelizes a 3D "Driven Cavity" problem, a Navier-Stokes case. You can of course test other examples that you can find in the very well written FreeFem documentation. Now, let’s use Qarnot Python SDK to launch the distributed calculation. Save the following script as *run.py* in your *Qarnot_freefem_distributed_example* folder. In this script, you need to enter your Qarnot Token linked to your account (you can find it here) to use our platform. In the *Qarnot_freefem_distributed_example* folder, follow these steps to set up a Python virtual environment. Then, you can run the Python script from your terminal by typing* chmod +x run.py* and then *./run.py*. You can then see the tasks details on your own console or on the Qarnot console Tasq. When it’s finished the results (a 2D visualization file) will be downloaded on your computer. We hope you enjoyed this tutorial! Should you have any question(s) or if you wish to use our platform for heavier computations (we can provide top of the art resources on demand), don’t hesitate to contact us.