The FEniCS project is a research and software project aimed at creating mathematical methods and software for solving partial differential equations. This includes creating intuitive, efficient and flexible software. The project was initiated in 2003, and is developed in collaboration between researchers from a number of universities and research institutes around the world. For the latest updates and more information about the FEniCS project, visit the FEniCS web-page.
The latest version of the FEniCS project, FEniCS-X, consists of several building blocks, namely basix, UFL, FFC-X and Dolfin-X. We will now go through the main objectives of each of these building blocks. Dolfin-X is the high performance C++ backend of FEniCS-X, where structures such as meshes, function spaces and functions are implemented. Additionally, Dolfin-X also contains compute intensive functions such as finite element assembly and mesh refinement algorithms. It also provides an interface to linear algebra solvers and data-structures, such as PETSc. UFL is a high-level form language for describing variational formulations with a high-level mathematical syntax. FFC-X is the form compiler of FEniCS; given variational formulations written with UFL, it generates efficient C code. Basix is the finite element backend of FEniCS, responsible for generating finite element basis functions.
The goal of this tutorial is to demonstrate how to apply the finite element to solve PDEs in FEniCS. Through a series of examples, we will demonstrate how to:
- Solve linear PDEs (such as the Poisson equation),
- Solve time-dependent PDEs (such as the heat equation),
- Solve non-linear PDEs,
- Solve systems of time-dependent non-linear PDEs.
Important topics involve how to set boundary conditions of various types (Dirichlet, Neumann, Robin), how to create meshes, how to define variable coefficients, how to interact with linear and non-linear solvers, and how to post-process and visualize solutions.
Most of the mathematical part of the examples will be kept at a simple level, such that we can keep the focus on the functionality and syntax of FEniCS-X. Therefore we will mostly use the Poisson equation and the time-dependent diffusion equation as model problems. We will use adjusted input data, such that the solution of the problem can be exactly reproduced on uniform, structured meshes with the finite element method. This greatly simplifies the verification of the implementations. Occasionally we will consider a more physically relevant example to remind the reader that there are no big leaps from solving simple model problems to challenging real-world problems when using FEniCS-X.
As this book has been published as a Jupyter Book, we provide interactive notebooks that can be run in the browser. To start such a notebook click the -symbol in the top right corner of the relevant tutorial.
If you would like to work with dolfin-X outside of the binder-notebooks, you need to install the FEniCS software. The recommended way of installing dolfin-X for new usesers is by using Docker. Docker is a software that uses containers to supply software across different kinds of operating systems (Linux, Mac, Windows). The first step is to install docker, following the instructions at their web-page.
All notebooks can be converted to python files using nbconvert.
We supply a pre-built docker image at https://hub.docker.com/r/dolfinx/dolfinx. The Dockerfile provides a definitive build recipe. As the dolfinx docker images are hosted at Docker-hub, one can directly access the image
docker run dolfinx/dolfinx
There are several ways of customizing a docker container, such as mounting volumes/sharing folder, setting a working directory, sharing graphical interfaces etc. See docker run --help
for an extensive list.
Once you have installed dolfin-X, either by using docker or installing form source, you can test the installation by running python3 -c "import dolfinx"
. If all goes well, no error-messages should appear.
To use the notebookes in this tutorial with dolfin-X on your own computer, you should use the docker image docker/lab
, using the following command
docker run --init -p 8888:8888 -v "$(pwd)":/root/shared dolfinx/lab
The tutorials can also be exported as a notebook or PDF by clicking the -symbol in the top right corner of the relevant tutorialThe notebook can in turn be used with a Python kernel which has dolfin-X.
The software is quite complex, and building the software and all the dependencies from source can be a daunting task. The list of dependencies can be found at [https://docs.fenicsproject.org/dolfinx/main/python/installation.html](https://docs.fenicsproject.org/dolfinx/main/python/installation.html.
If you are a beginner in Python, we suggest reading {cite}Langtangen2016
by Hans Petter Langtangen, which will give you a gentle introduction to the Python programming language. Note that dolfin-X, being a state of the art finite element solver, only supports Python 3, as Python 2 reached its end of life January 1st, 2020. To automatically transfer Python 2 scripts to Python 3, it is suggested to use the 2to3-package, which provides automated translation of the code.
In the last decade, a wide range of lecture notes on finite elements methods has been made open access. See for instance:
- Numerical methods for partial differential equations, by Hans Petter Langtangen
- Finite Elements - Analysis and implementation, by David A. Ham and Colin J. Cotter
- Finite Element Analysis for Coupled Problems, by David Kamensky.
- An Encyclopedia of Finite Element Definitions, by Matthew W. Scroggs.
There has been written many good text-books on the finite element method, and we refer to the original FEniCS tutorial, for references to these, see Chapter 1.6.2 of The FEniCS tutorial {cite}FenicsTutorial
.
:filter: cited and ({"fem"} >= docnames)