RETURN
Simulation
October 2021

FEniCS on Qarnot Cloud

FEniCS is an open source finite element software used to solve partial differential equations. The equations and physics are transcribed into FEniCS language implemented in Python. Running your FEniCS simulation on Qarnot is as easy as uploading your case and launching a script. Here’s a walk-through of the different steps.

Versions

The test case uses FEniCS 2019.2.0, released in 2019.

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

Test case

Please ensure that you have created a Qarnot account.

This test case is based the 2-D Poisson equation on a square unit. The equation is broadly used in physics and is a general form of the Laplace equation. To make our problem unique, we also need to choose a domain (a simple square) and some boundary conditions, which are presented below.

You can download the case folder here, which contains the test case as code in a Python file. You should put it at the same folder level as the script to launch the calculation. Please note that it needs to be unzipped before it can be used on Qarnot.

Launching the case

Before starting a calculation with the Python SDK, a few steps are required:

Note: in addition to the Python SDK, Qarnot provides C# and Node.js SDKs and a Command Line.
Once everything is set up, the following script needs to be used to start the calculation.

Be sure you have copied your authentication token in the script (instead of <<<MY_SECRET_TOKEN>>>) to be able to launch the task on Qarnot.

fenics.py

#!/usr/bin/env python

# Import the Qarnot SDK
import qarnot

# Create a connection, from which all other objects will be derived
# Enter client token here
conn = qarnot.connection.Connection(client_token='<<<MY_SECRET_TOKEN>>>')

# Create the task
task = conn.create_task("Hello World - FEniCS", "docker-batch", 1)

# Create the input bucket and synchronize with a local folder
# Insert a local folder directory
input_bucket = conn.create_bucket("fenics-in")
input_bucket.sync_directory("poisson")

# Attach the bucket to the task
task.resources.append(input_bucket)

# Create a result bucket and attach it to the task
task.results = conn.create_bucket("fenics-out")

# Define the Docker image and the command to be run in the container
task.constants["DOCKER_REPO"] = "qarnotlab/fenics"
task.constants["DOCKER_TAG"] = "2019.2.0"
task.constants["DOCKER_CMD"] = "bash -c 'mpirun -np \$((\$(nproc)/2)) python3 ft01_poisson.py'"

# Submit the task
task.run(output_dir="fenics_results")

To launch this script, simply copy the preceding code in a Python script, put at the same level as the poisson folder and execute python3 fenics.py & in your terminal. You should copy the gist code (shown here) and not the raw code.

Results

At any given time, you can monitor the status of your task on the general web interface Console.

You should also now have a result folder in the output bucket and on your computer containing all the numerical results. You can open solution000000.vtu file (in the poisson folder) in Paraview or any other viewer. You can also use our Paraview Web payload to view the results online if needed. To activate the 3D view in Paraview, go the Filters tab, go to Alphabetical and choose Warp By Scalar.

Wrapping up

That’s it! If you have any questions, please contact qlab@qarnot.com and we will help you with pleasure!

Return

Our articles