Introduction to FEM & Firedrake
Sia Ghelichkhan
- / -
By the end of this workshop, we want to have a (very) basic understanding of the finite element method:
Forward modelling is the process of using a known set of physical laws (mathematical equations), and input parameters to simulate or predict the behaviour of a physical system.
In essence, it involves solving a governing equation or system of equations to determine the state of the system under specified conditions.

Groundwater Flow
Groundwater fills the spaces between soil particles and fractured rock beneath the earth’s surface.
Mantle Convection
Mantle flow drives plate tectonics over geological timescales.
Glacial Isostatic Adjustment
Loading and unloading of ice sheets causes crustal deformation and rebound.
Common challenge: Complex geometries, heterogeneous materials, and coupled physics require numerical methods like FEM.
Forward modelling as a functional:
Where:
The functional relationship:
This maps control parameters to state variables through the solution of differential equations.
Examples:
Heat equation:
Stokes flow:
Wave equation:
Key insight: All involve derivatives → need numerical methods!

Domain discretisation:
Key insight: The mesh quality affects solution accuracy. Finer mesh = better approximation.
Strong form (exact solution):
A claim:
Problem: Too restrictive for complex domains!

Test the claim with test functions
The complexity of our solution depends on the complexity of test functions. (which FunctionSpace we choose)
The residual approach:
Apply integration by parts:
This becomes our discrete system:
Why this works:

From infinite to finite dimensions:
Trial functions
Test functions

Basis function properties:
The connection:
Remember our weak form:
UFL makes this direct:
# Define function space on mesh
V = FunctionSpace(mesh, "Lagrange", 1)
u = TrialFunction(V) # Our claimed solution
v = TestFunction(V) # Our testers
# Define the weak form
a = dot(grad(v), grad(u))*dx # Left side
L = v*f*dx # Right sideThe magic of UFL:

Physical problem: Heat conduction in a square
UFL implementation:
# Mesh and function space
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, "P", 1)
# Define problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(10.0)
# Variational forms
a = dot(grad(u), grad(v))*dx
L = f*v*dx