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

  1. Build a first program to create a mesh and a finite element space.
  2. Solve the Poisson equation to connect a weak form to assembly, a solver, and visualization.
  3. 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.

TutorialMain idea
Solving the Poisson equationScalar diffusion and homogeneous Dirichlet data
Solving diffusion with discontinuous GalerkinDiscontinuous affine space, SIPG fluxes and convergence checks
Solving the elasticity equationVector displacement and boundary traction
Solving the Helmholtz equationWave propagation and complex-valued fields
Solving the Stokes equationsIncompressibility, mixed spaces and pressure normalization
Solving the Navier–Stokes equationsTransient cavity flow driven by a moving lid patch
Poisson equation with periodic boundary conditionsPeriodic boundary identification and a mean-value constraint
Solving PDEs on surface meshesTangential 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.

TutorialOutput and checks
Exporting a time-dependent fieldExport a time-dependent vector field with its mesh
Saving and reloading an MFEM fieldSave and reload a mesh and scalar field
Converting a MEDIT meshCreate 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.

TutorialMain idea
Generating uniform gridsCreate structured meshes and set their physical dimensions
Computing mesh connectivityInspect incidence relations between vertices, edges and cells
Evaluating interface tracesEvaluate 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.

TutorialMain idea
Saving an MMG meshRead and write MMG mesh data and check metadata
Using an MMG mesh in RodinWork with MMG and Geometry mesh interfaces
Improving triangle qualityImprove element quality and inspect the resulting mesh
Adapting to a size fieldAdapt the background to a prescribed size field
Adapting and fitting an implicit interfaceAdapt a background, classify a circle and fit its interface with SWIFT
MMG behavior and guaranteesRequired 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.

TutorialMain idea
Temperature minimizationSIMP 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.

TutorialMain idea
Shape optimization of a cantileverExplicit boundary displacement followed by remeshing
Optimizing a level-set cantileverSigned-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:

TutorialMethod
Linear cantilever beamLinear elasticity with $\sigma=\lambda(\operatorname{tr}\varepsilon)I+2\mu\varepsilon$
Hyperelastic cantileverTransient Neo-Hookean model with $W=\frac{\mu}{2}(I_1-d)-\mu\ln J+\frac{\lambda}{2}(\ln J)^2$

Distance and Eikonal

The Eikonal module solves $ F(x)|\nabla u| = 1 $ for positive propagation speed $F$ via the Fast Marching Method, and the Distance module wraps several distance-function computation strategies:

TutorialMethod
Computing arrival times with fast marchingFast marching with an exact point-source comparison and mesh refinement
Constructing a distance approximation from a Poisson fieldSpalding–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:

TutorialDescription
Sequential PoissonPETSc CG solver on a local mesh
MPI PoissonDistributed mesh and PETSc KSP
Sequential StokesMixed velocity, pressure and pressure-mean multiplier
Oseen flowTransient Picard/Oseen linearization
Oseen lid-driven cavityTransient cavity with Picard/Oseen linearization
Navier–StokesTransient nonlinear lid-driven cavity with PETSc SNES

Discontinuous Galerkin

Begin with two-sided traces, then assemble a complete interior-penalty solve.

TutorialOutput and checks
Evaluating interface tracesOne-sided values, jump and average on a two-cell mesh
Solving diffusion with discontinuous GalerkinIndependent 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 $ K(\mathbf{x}, \mathbf{y}) $ is convolved with the solution on the mesh:

TutorialMethod
Newtonian potentialScalar kernel $1/(4\pi\lVert\mathbf{x}-\mathbf{y}\rVert)$
Elastic distributionNavier $3\times3$ 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:

TutorialDescription
Conormal advectionMove the boundary along its conormal
Convergence studyParametric sweep over resolution and CFL
Plane evolutionPlanar 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:

TutorialMethod
Acoustic cloakingComplex Helmholtz solve, adjoint shape gradient and conormal advection