Skip to content

Robiolab/FEniCSx-tutorials

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FEniCSx Tutorial Series

Hands-on tutorials for engineers learning FEniCSx (DOLFINx 0.10). Covers fundamentals through coupled physics and design automation. Each tutorial is a Python script with inline comments plus a companion markdown explanation.

Quick Start

# Pull the Docker image
docker pull dolfinx/dolfinx:stable

# Run a tutorial
docker run --rm -v $(pwd):/work -w /work dolfinx/dolfinx:stable \
    python3 tutorials/01_fundamentals/01_poisson.py

For visualization (optional):

docker run -it --rm -v $(pwd):/work -w /work dolfinx/dolfinx:stable bash
pip install pyvista matplotlib
python3 tutorials/01_fundamentals/01_poisson.py

Output files (XDMF) go to output/ and can be opened in ParaView.

Tutorials

00 Setup

# Topic Script
- Docker environment & install verification 00_setup/

01 Fundamentals

# Topic Script
00 FEM math refresher (weak forms, basis functions) 01_fundamentals/00_math_fundamentals.py
01 Poisson equation — the 7-step FEniCSx pipeline 01_fundamentals/01_poisson.py
02 Boundary conditions (Dirichlet, Neumann, Robin) 01_fundamentals/02_boundary_conditions.py
03 Visualization and export (XDMF, PyVista) 01_fundamentals/03_visualization.py
04 Mesh convergence study 01_fundamentals/04_convergence.py
05 Gmsh integration: 2D meshes 01_fundamentals/05_gmsh_2d.py
06 Gmsh integration: 3D meshes 01_fundamentals/06_gmsh_3d.py
07 Gmsh parametric geometry 01_fundamentals/07_gmsh_parametric.py

02 Heat Transfer

# Topic Script
01 Steady conduction with Robin BCs 02_heat_transfer/01_steady_heat.py
02 Transient conduction (backward Euler) 02_heat_transfer/02_transient_heat.py

03 Solid Mechanics

# Topic Script
01 Linear elasticity (3D cantilever, von Mises) 03_solid_mechanics/01_linear_elasticity.py
02 Hyperelasticity (neo-Hookean, Newton solver) 03_solid_mechanics/02_hyperelasticity.py
03 CAD workflow: spring stiffness from STEP/OCC 03_solid_mechanics/03_cad_spring_stiffness.py

04 Fluid Flow

# Topic Script
01 Stokes flow (Taylor-Hood elements) 04_fluid_flow/01_stokes.py
02 Navier-Stokes (IPCS splitting scheme) 04_fluid_flow/02_navier_stokes.py

05 Coupled Problems & Automation

# Topic Script
01 Thermoelastic coupling 05_coupled_and_automation/01_thermoelastic.py
02 Parametric sweep (CSV export) 05_coupled_and_automation/02_parametric_sweep.py
03 Optimization (scipy + FEniCSx) 05_coupled_and_automation/03_optimization.py

How to Approach This Efficiently

If you want to start running your own simulations quickly, you don't need to go through every tutorial in order.

The minimum path (3-4 tutorials):

  1. 01_fundamentals/01_poisson.py — The 7-step FEniCSx pipeline: mesh, function space, BCs, weak form, solve, export. Every other tutorial reuses this skeleton. Understand this one well.

  2. 01_fundamentals/03_visualization.py — Skim. Know how to export XDMF and view in ParaView.

  3. Pick the physics you need:

    • Structural: 03_solid_mechanics/01_linear_elasticity.py
    • Thermal: 02_heat_transfer/01_steady_heat.py
    • Fluid: 04_fluid_flow/01_stokes.py

    The jump from Poisson is mainly the function space and weak form — the solver setup is identical.

  4. 03_solid_mechanics/03_cad_spring_stiffness.py — If you're working with real CAD parts instead of boxes. Covers the Gmsh OCC / STEP import pipeline.

Skip until you actually need them:

  • Hyperelasticity (03/02) — large deformations only
  • Transient heat (02/02) — time-dependent problems only
  • Navier-Stokes (04/02) — when Stokes isn't enough
  • Coupled/optimization (05/) — multi-physics or parametric studies

The pattern to internalize: every FEniCSx simulation is the same loop — define the mesh, pick the function space, write the weak form in UFL, solve, post-process. The weak form is the only part that changes between physics; the rest is boilerplate. Once you've done it twice, you can set up a new problem by copying an existing tutorial and modifying it.

Tech Stack

  • FEniCSx (DOLFINx 0.10) via dolfinx/dolfinx:stable Docker image
  • Gmsh for meshing (built-in and OCC/STEP workflows)
  • PETSc for linear algebra (KSP, SNES)
  • matplotlib / PyVista for visualization (optional)
  • scipy for optimization loops (tutorial 05/03)

About

Tutorials for FeniCSx - DOLFINx (FEM)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages