< Back

# FreeFEM and the Finite Element Method on Qarnot

by Ariane Robineau - December 6, 2019 - Engineering

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. Above are two L-shape meshes for a Poisson problem. The left one is randomly generated, the right one is optimized with freefem automatic meshing algorithm.

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 in the API Token section in your Qarnot account) 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.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8910226,"math_prob":0.81559014,"size":3748,"snap":"2019-51-2020-05","text_gpt3_token_len":815,"char_repetition_ratio":0.11645299,"word_repetition_ratio":0.0033557047,"special_character_ratio":0.19370331,"punctuation_ratio":0.09264706,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96860313,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-21T19:28:34Z\",\"WARC-Record-ID\":\"<urn:uuid:53054947-8e32-42b9-970e-929d9ce9347f>\",\"Content-Length\":\"13655\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a5df46c2-7f32-4f5e-9d29-a0c5ed99a3a8>\",\"WARC-Concurrent-To\":\"<urn:uuid:f3cd2062-37db-4740-a453-b559a84387b2>\",\"WARC-IP-Address\":\"51.68.244.221\",\"WARC-Target-URI\":\"https://blog.qarnot.com/freefem-and-the-finite-element-method-on-qarnot/\",\"WARC-Payload-Digest\":\"sha1:6ZK4S3DNUGP77WOCTTSLHOPXBPAYSRQY\",\"WARC-Block-Digest\":\"sha1:7EYD56YPD2NYBKQIY7ZNYPU3DLDKJKWH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250605075.24_warc_CC-MAIN-20200121192553-20200121221553-00345.warc.gz\"}"}