Skolan för
och datavetenskap

The Finite Element Method, fem12


Basic laws of nature are typically expressed in the form of partial differential equations (PDE), such as Navier's equations of elasticity, Maxwell's equations of electromagnetics, Navier-Stokes equations of fluid flow, and Schrödinger's equations of quantum mechanics. The Finite element method (FEM) has emerged as a universal tool for the computational solution of PDEs with a multitude of applications in engineering and science. Adaptivity is an important computational technology where the FEM algorithm is automatically tailored to compute a user specified output of interest to a chosen accuracy, to a minimal computational cost. This FEM course aims to provide the student both with abstract skills (for example proving properties of methods) and concrete skills (for example constructing methods and formulating them in computer language), including the ability to construct adaptive FEM algorithms for an important family of PDEs and analyzing their properties.

Course goals

In the course the student should be able to:
  1. construct a finite element method by deriving the weak formulation, formulating the corresponding finite element approximation, and formulating the approximation in computer language, or modifying an existing general computer program for scalar linear PDE.
  2. derive a priori and a posteriori error estimates in the energy norm, the L2-norm, and linear functionals of the solution.
  3. construct an adaptive finite element method based on an a posteriori error estimate, implement an adaptive mesh refinement algorithm, and analyze the performance of the adaptive method.
  4. describe standard components in general FEM algorithms and how they fit together
  5. estimate the stability of a given linear PDE and its FEM approximation and be able to reflect on the concept of stability
  6. state and apply the Lax-Milgram theorem for a given variational problem.

Advanced course continuation

A natural continuation of the finite element course is the Advanced Computation in Fluid Mechanics course (DN2275), starting in january 2013 given by Johan Hoffman.


  1. (Software environment)
  2. Science - differential equations
  3. Function approximation using polynomials
  4. Galerkin's method (finite element method)
  5. Assembly of discrete systems
  6. Error estimation
  7. Adaptive mesh refinement
    Undocumented base code for adaptivity
    Starting mesh
  8. Stability
    Convection-diffusion solver (without stabilization)
    Velocity field
    Subdomain markers (for boundary conditions)
  9. Existence and uniqueness of solutions

News (2012):

Nov 14: Grades for written exam sent out, put up exam and solutions on home page.

Oct 17: Note that the written exam will take place in M22.

Oct 12: Put up updated source code and data/mesh files for module 6 and 7 (see above).

Oct 5: Please register yourself in the RAPP system. Put up notes from exercise.

Sep 25: Put up lecture notes up to and including lecture 8.

Sep 18: Moved first module deadline to September 24.

Sep 17: Updated modules.

Sep 7: Schedule updates.


Coordinator and lecturer: Johan Jansson; email:

Assistant: Doghonay Arjmand; email:

Office Hours

Johan Jansson (1517): By appointment.
Doghonay Arjmand: By appointment.


NB: Please activate yourself in the RAPP system.


The examination consists of submissions of written reports and software for the course modules and a written exam.
(1) Written exam: Thursday October 18, 8-13 in M22. Typical examination questions.

Exam 2012-11-14 solutions

Grading levels (out of 30):
Fx: 10
E: 13
D: 16
C: 19
B: 23
A: 26

(2) Reports for modules 1-3 are due September 24, modules 4-5 October 8, the rest of the modules October 22. Give your answers with source code and possible figures in a PDF. Mail the PDF to me ( with the text "module 1-3" in the title (replace the numbers appropriately).
The modules should be carried out individually or in groups of two.


In this course we will study the open source FEniCS automated finite element framwork for solving partial differential equations. More information is in the Software Environment description and in the extra material below.


K. Eriksson, D. Estep, P. Hansbo, C. Johnson: Computational Differential Equations. Studentlitteratur, ISBN ISBN 91-44-49311-8.

Extra material

FEniCS Book

FEniCS Quick reference

FEniCS tutorial (long)

Hints and solutions to some of the problems in the book.

Useful inequalities.

Navier-Stokes quick and easy (from "Applied Mathematics: Body and Soul III")

Material from exercises:

Exercise notes from Oct 2: 1, 2


NB! Johan Jansson will be away at a conference 9-14 September and unable to give lectures. Therefore the schedule will be modified as follows (just a switch between exercise sessions and lecures):

Monday 10 September 10-12 will be an exercise session in L1
Thursday 13 September 13-15 will be an exercise session in L1

Wednesday 19 September 8-10 will be a lecture in M31
Wednesday 26 September 10-12 will be a lecture in L22

Schedule at

Preliminary weekly plan

Week 1

Lecture 1:
Course overview, differential equations, Poisson 1D, boundary conditions, weak formulation, polynomial approximation, Galerkin method, piecewise polynomials 1D (CDE 1-4,6,8.1).

Lecture notes

Conference presentation with examples

Lecture 2:
Poisson 2D, assembly algorithm, FEM mesh, piecewise polynomials 2D, interpolation, L2 projection (CDE 5.5,(7),13,14.1-14.2,14.4,15.1).

Lecture notes

Week 2

Lecture 3:
Boundary conditions, FEniCS (CDE 8.1.5, 15.1,15.3,15,4, Robin boundary conditions in 1D and 2D).

Lecture notes

Expanded Poisson demo (Python)

Robin boundary conditions in 1D (Python)

Simple general matrix/vector assembly (mini-FEniCS)

Assembles weak forms on the reference triangle below, compare against hand-computation of matrices.

Reference triangle mesh. Use like so:

mesh = Mesh("triangle.xml")

Lecture 4:
error estimation, adaptivity

Lecture notes

Week 3

Lecture 5:
error estimation 2D, mesh operations (CDE 5,8.2-8.6,14.2,15.2-15.3).

Example code for help with modules.

Lecture notes

Lecture 6:
Initial value problem, heat equation, space-time FEM, stability (CDE 9.1-9.2,16,17).

Week 4

Lecture 7:
Convection-diffusion-reaction equation, stabilization, wave equation, adaptive algorithm implementation (CDE 18,19).

Undocumented base code for adaptive implementation (see module Adaptive mesh refinement)

Lecture notes (combined for lecture 6 and 7, see also the Stability module)

Week 5

Lecture 8:
Uniqueness and existence for elliptic PDE, Lax-Milgram (CDE 21,12).

Lecture notes (see also the Existence and uniqueness module)

Week 6

Lecture 9:
ALE, Navier-Stokes, overview/repetition.

Week 7

Work on modules.

Week 8

Copyright © Sidansvarig: Johan Jansson <>
Uppdaterad 2012-11-14