Skip to content
All projects

Cours

Course — Numerical methods

Lecture notes on numerical methods: finite differences, finite elements, finite volumes…

Différences finiesÉléments finisVolumes finisCours

Introduction

This course introduces the main numerical methods used to solve the partial differential equations (PDEs) arising in fluid mechanics and physics. It covers finite differences, finite elements and finite volumes.

These notes are a living document: they grow chapter by chapter.

1. Finite differences

The idea is to approximate derivatives by differences on a grid. For a function u(x)u(x), the centered approximation of the second derivative reads:

2ux2xiui+12ui+ui1Δx2+O(Δx2)\frac{\partial^2 u}{\partial x^2}\bigg|_{x_i} \approx \frac{u_{i+1} - 2u_i + u_{i-1}}{\Delta x^2} + \mathcal{O}(\Delta x^2)

Applied to the heat equation tu=αxxu\partial_t u = \alpha\, \partial_{xx} u, this gives an explicit scheme:

uin+1=uin+αΔtΔx2(ui+1n2uin+ui1n)u_i^{n+1} = u_i^{n} + \frac{\alpha \Delta t}{\Delta x^2}\left(u_{i+1}^n - 2u_i^n + u_{i-1}^n\right)

stable under the condition αΔtΔx212\dfrac{\alpha \Delta t}{\Delta x^2} \le \dfrac{1}{2}.

import numpy as np

def heat_step(u, alpha, dx, dt):
    lap = (np.roll(u, -1) - 2*u + np.roll(u, 1)) / dx**2
    return u + alpha * dt * lap

2. Finite elements

The finite element method (FEM) starts from the weak formulation. For the Poisson problem Δu=f-\Delta u = f on Ω\Omega with u=0u = 0 on Ω\partial\Omega, we look for uH01(Ω)u \in H_0^1(\Omega) such that:

ΩuvdΩ=ΩfvdΩvH01(Ω)\int_\Omega \nabla u \cdot \nabla v \, \mathrm{d}\Omega = \int_\Omega f\, v \, \mathrm{d}\Omega \qquad \forall\, v \in H_0^1(\Omega)

Discretizing over a basis of functions {φj}\{\varphi_j\} leads to the linear system Ku=f\mathbf{K}\mathbf{u} = \mathbf{f}, where K\mathbf{K} is the stiffness matrix.

3. Comparing the methods

MethodComplex geometriesConservationImplementation
Finite differencesSimple
Finite elements~Advanced
Finite volumesMedium

Going further

Upcoming chapters will cover finite volumes, spectral methods and schemes for multiphase flows. (coming soon)