Examples and tutorials
Guided numerical problems and application source examples.
The tutorials explain a problem, its discretization, the code that realizes it, and the interpretation of the result. Source examples extend that workflow to other models and backends.
Start here
- Build a first program to create a mesh and a finite element space.
- Solve the Poisson equation to connect a weak form to assembly, a solver, and visualization.
- Continue with linear elasticity for a vector-valued field and boundary traction.
The General concepts guides supply the mathematical background. The Gallery collects visual results.
Before choosing a model
A variational problem combines a trial space, a test space, forms, and boundary conditions. The variational formulations guide explains this construction; the solver guide explains how the resulting matrix properties determine solver choice.
Partial differential equations
Begin with Poisson, then select a tutorial according to the field type, boundary conditions, or geometry needed for the problem.
| Tutorial | Main idea |
|---|---|
| Solving the Poisson equation | Scalar diffusion and homogeneous Dirichlet data |
| Solving diffusion with discontinuous Galerkin | Discontinuous affine space, SIPG fluxes and convergence checks |
| Solving the elasticity equation | Vector displacement and boundary traction |
| Solving the Helmholtz equation | Wave propagation and complex-valued fields |
| Solving the Stokes equations | Incompressibility, mixed spaces and pressure normalization |
| Solving the Navier–Stokes equations | Transient cavity flow driven by a moving lid patch |
| Poisson equation with periodic boundary conditions | Periodic boundary identification and a mean-value constraint |
| Solving PDEs on surface meshes | Tangential operators and refinement on a triangulated sphere |
The weak formulation guide derives the forms; the solver guide explains their algebraic requirements. The PDE overview provides the same tutorial sequence on a separate page.
Input/output
Select an example according to the data being exchanged. XDMF records fields and time-dependent snapshots for ParaView; MFEM and MEDIT examples demonstrate mesh and field exchange.
| Tutorial | Output and checks |
|---|---|
| Exporting a time-dependent field | Export a time-dependent vector field with its mesh |
| Saving and reloading an MFEM field | Save and reload a mesh and scalar field |
| Converting a MEDIT mesh | Create a mesh, save MEDIT and convert to MFEM |
The I/O guide explains format selection and field lifetimes. See also the I/O overview.
Mesh geometry
Generated meshes provide a starting point for geometry and incidence operations without an input file.
| Tutorial | Main idea |
|---|---|
| Generating uniform grids | Create structured meshes and set their physical dimensions |
| Computing mesh connectivity | Inspect incidence relations between vertices, edges and cells |
| Evaluating interface traces | Evaluate the two traces, jump and average on an interior facet |
The mesh guide covers traversal and queries, while the polytope guide explains reference elements and mappings. The geometry overview also links the distance-field examples below.
Working with MMG
MMG changes mesh topology to improve element shape, follow a size field or reconstruct an implicit domain. Construct fresh finite element spaces after remeshing and check required entities and labels at each stage.
| Tutorial | Main idea |
|---|---|
| Saving an MMG mesh | Read and write MMG mesh data and check metadata |
| Using an MMG mesh in Rodin | Work with MMG and Geometry mesh interfaces |
| Improving triangle quality | Improve element quality and inspect the resulting mesh |
| Adapting to a size field | Adapt the background to a prescribed size field |
| Adapting and fitting an implicit interface | Adapt a background, classify a circle and fit its interface with SWIFT |
| MMG behavior and guarantees | Required entities, level-set cuts and preservation guarantees |
The MMG overview collects these workflows.
Density optimization examples
Density optimization varies a material coefficient on a fixed domain. A state solve determines temperature, an adjoint supplies sensitivity, and a regularized update changes the density within its admissible interval.
| Tutorial | Main idea |
|---|---|
| Temperature minimization | SIMP conductivity, adjoint sensitivity and a projected material update |
Begin with the Poisson solve. The thermal tutorial supplies computed density and temperature fields, objective and material histories, and the complete source. Its fixed iteration budget defines the recorded experiment; stationarity or a prescribed material budget requires an associated optimization criterion. The density optimization overview develops the state–sensitivity–update sequence.
Shape optimization examples
Shape optimization varies the material boundary of an elastic body. Compliance and an area penalty define the objective; a regularized shape derivative supplies the geometry update. Both tutorials use MMG and require a hydrated input mesh from the repository's Git LFS resources.
| Tutorial | Main idea |
|---|---|
| Shape optimization of a cantilever | Explicit boundary displacement followed by remeshing |
| Optimizing a level-set cantilever | Signed-field transport and body-fitted interface reconstruction |
Start with the boundary-deformation example after the elasticity tutorial. Compare compliance, area and objective at solved states, then inspect Jacobian signs and element quality after each update. The level-set tutorial records both increasing objective steps and a reproduced low-quality triangle, making step acceptance and geometric quality part of interpreting its fixed-budget run. The shape optimization overview explains the two representations and prerequisites.
Solid mechanics source examples
The Solid module provides hyperelastic constitutive laws and nonlinear integrators for large-deformation solid mechanics. The LinearElasticityIntegral covers the small-deformation (linearized) case, while the Solid module handles finite-strain problems with constitutive laws such as NeoHookean, Saint-Venant-Kirchhoff, and Mooney-Rivlin:
| Tutorial | Method |
|---|---|
| Linear cantilever beam | Linear elasticity with |
| Hyperelastic cantilever | Transient Neo-Hookean model with |
Distance and Eikonal
The Eikonal module solves for positive propagation speed via the Fast Marching Method, and the Distance module wraps several distance-function computation strategies:
| Tutorial | Method |
|---|---|
| Computing arrival times with fast marching | Fast marching with an exact point-source comparison and mesh refinement |
| Constructing a distance approximation from a Poisson field | Spalding–Tucker normalization of a signed Poisson field and geometric error checks |
PETSc source examples
The PETSc module enables distributed solvers and multi-field block systems. Examples include:
| Tutorial | Description |
|---|---|
| Sequential Poisson | PETSc CG solver on a local mesh |
| MPI Poisson | Distributed mesh and PETSc KSP |
| Sequential Stokes | Mixed velocity, pressure and pressure-mean multiplier |
| Oseen flow | Transient Picard/Oseen linearization |
| Oseen lid-driven cavity | Transient cavity with Picard/Oseen linearization |
| Navier–Stokes | Transient nonlinear lid-driven cavity with PETSc SNES |
Discontinuous Galerkin
Begin with two-sided traces, then assemble a complete interior-penalty solve.
| Tutorial | Output and checks |
|---|---|
| Evaluating interface traces | One-sided values, jump and average on a two-cell mesh |
| Solving diffusion with discontinuous Galerkin | Independent cell-local affine unknowns, SIPG fluxes, weak Dirichlet data, an affine patch test and four-level refinement |
Integral equation source examples
The Potential operator enables integral equation formulations (boundary element methods). The kernel is convolved with the solution on the mesh:
| Tutorial | Method |
|---|---|
| Newtonian potential | Scalar kernel |
| Elastic distribution | Navier kernel |
Surface evolution source examples
The surface evolution examples demonstrate conormal advection — moving domain boundaries along their outward normal direction using level-set methods with MMG implicit-domain meshing:
| Tutorial | Description |
|---|---|
| Conormal advection | Move the boundary along its conormal |
| Convergence study | Parametric sweep over resolution and CFL |
| Plane evolution | Planar surface motion |
Boundary optimization source examples
Advanced shape and topology optimization examples that combine complex-valued PDE solvers, adjoint methods, Hilbert space regularization, and MMG remeshing:
| Tutorial | Method |
|---|---|
| Acoustic cloaking | Complex Helmholtz solve, adjoint shape gradient and conormal advection |