About the Examples

The examples in this package are designed to be practical, reproducible, and educational. They demonstrate a wide range of finite element applications and PDE model problems.

Design Principles

  • All examples can be run directly from the Julia REPL.
  • Each example is a Julia module named after the file.
  • Examples can serve as templates for your own projects.
  • Many examples include test cases for automated verification.

Running the Examples

To run an example (e.g., Example212_PeriodicElasticity2D):

  1. Download the example file (see the source code link at the top of the example page).

  2. Start Julia in the root directory of the package (or in the directory that contains the example file). Some examples need additional dependencies beyond the core requirements, so the easiest way to get all of them is to use the package test environment. After Pkg.activate("."), it can be activated via the package TestEnv:

    julia julia> using Pkg; Pkg.activate(".") julia> using TestEnv; TestEnv.activate()

  3. Include the example file and call its main function:

    julia julia> include("Example212_PeriodicElasticity2D.jl") julia> Example212_PeriodicElasticity2D.main()

  4. Some examples offer visual output via the optional argument Plotter = PyPlot or Plotter = GLMakie (provided the package is installed and loaded):

    julia julia> Example212_PeriodicElasticity2D.main(Plotter = PyPlot)

Overview of the Examples

The examples are listed below in numerical order. Each name links to the documentation page of the example; the keywords indicate the application and the finite element concepts demonstrated there (method type, coupling, error estimation, etc.).

ExampleDescription
Example1031D Burgers equation (scalar conservation law) with periodic boundary conditions, solved by a DifferentialEquations-based and a manual implicit Euler time discretization — keywords: time-dependent, nonlinear, periodic boundary
Example1051D nonlinear Poisson equation with Dirichlet data, solved by Newton iteration — keywords: conforming FEM, nonlinear
Example1061D porous-medium (nonlinear) diffusion equation with Neumann data — keywords: conforming FEM, time-dependent, nonlinear
Example1081D convection–diffusion–reaction with a mixed Robin/Dirichlet boundary condition, verified against an exact solution — keywords: conforming FEM, Robin boundary condition, nonlinear, convergence study
Example2012D Poisson problem on the unit square; demonstrates BoundaryDataRestriction- and operator-based boundary data — keywords: conforming FEM, restrictions
Example2022D Poisson problem in mixed (stress–potential) form with H(div)-conforming stress — keywords: conforming FEM, mixed method, H(div)
Example2032D Poisson problem with inhomogeneous Dirichlet data, solved with the discontinuous Galerkin (interior penalty) method — keywords: discontinuous Galerkin, interior penalty
Example204eigenvalue problem for the Laplacian on the L-shaped domain, using a KrylovKit iterative solver — keywords: conforming FEM, eigenvalue problem
Example2052D heat equation with Dirichlet data and time integration via DifferentialEquations — keywords: conforming FEM, time-dependent
Example206two Poisson problems on subdomains, coupled across a new internal interface region by a penalized interface condition — keywords: conforming FEM, coupled problem, interface conditions, penalty
Example2072D advection equation with an upwind discontinuous Galerkin and inflow boundary data — keywords: discontinuous Galerkin, upwind stabilization, advection
Example210residual error estimator and adaptive mesh refinement for the Poisson problem on the L-shaped domain; also demonstrates second-order derivative evaluation — keywords: conforming FEM, error estimation, adaptive mesh refinement, convergence study
Example211locally equilibrated (dual stress-reconstruction) error estimator, assembled in parallel on non-overlapping node patch groups — keywords: conforming + mixed FEM, equilibrated error estimation, adaptive mesh refinement, low-level assembly, convergence study
Example212linear elasticity on an unstructured periodic 2D grid with periodic coupling along one axis — keywords: conforming FEM, elasticity, periodic boundary, homogenization
Example220convection–diffusion–reaction; compares a conforming discretization with and without a gradient-jump stabilization for small diffusion — keywords: conforming FEM, interior penalty stabilization, convergence study
Example225obstacle problem (Dirichlet energy minimization above an obstacle) via a penalty term and Newton iteration — keywords: conforming FEM, variational inequality, penalty, nonlinear
Example226thermoforming benchmark: nonlinear elasticity with temperature-dependent material parameters — keywords: conforming FEM, nonlinear elasticity
Example227the obstacle problem of Example225, solved with a latent-variable proximal-point algorithm instead of a penalty — keywords: conforming FEM, variational inequality, latent variable proximal point, nonlinear
Example230nonlinear (bimetal) elasticity; demonstrates region- and parameter-dependent nonlinear expressions — keywords: conforming FEM, nonlinear elasticity, convergence study
Example235Hagen–Poiseuille flow with the iterated penalty method (Bernardi–Raugel element) — keywords: incompressible flow, Stokes, iterated penalty method
Example240Stokes flow with a Scott–Vogelius type element: continuous Pk velocity functions enriched by Raviart–Thomas functions plus a discontinuous P{k-1} pressure, giving a pointwise divergence-free velocity on general meshes, with DOF reduction — keywords: incompressible flow, Stokes, H(div) velocity enrichment, inf-sup stability, convergence study
Example245DFG benchmark (flow around a cylinder) on an externally generated mesh; computes drag/lift coefficients — keywords: incompressible flow, Navier–Stokes, nonlinear, external mesh generation, postprocessing
Example250Navier–Stokes in a lid-driven cavity over a cone; demonstrates vortex formation — keywords: incompressible flow, Navier–Stokes, nonlinear
Example252planar lattice flow Navier–Stokes problem with exact data; compares the L2 error of two restriction-based discretizations — keywords: incompressible flow, Navier–Stokes, nonlinear, restrictions, convergence study
Example260three-dimensional stagnation-point flow via the 2.5D axisymmetric Navier–Stokes formulation — keywords: incompressible flow, Navier–Stokes, axisymmetric
Example264coupled Stokes (free flow) / Darcy (porous medium) problem with interface transmission conditions — keywords: incompressible flow, Stokes + Darcy, interface conditions
Example265Stokes flow in an Ω-shaped pipe driving a convection–diffusion transport equation; compares stabilized convection discretizations and uses a CallbackOperator — keywords: incompressible flow, Stokes, transport, upwind/grad-jump stabilization, callback operator
Example266Navier–Stokes flow in a bent channel with periodic coupling between inlet and outlet via a CoupledDofsRestriction and no-slip walls, discretized with Taylor–Hood elements; the periodicity of the computed velocity is verified at test points — keywords: incompressible flow, Navier–Stokes, periodic boundary, coupled DOFs, nonlinear
Example270natural convection (Boussinesq) in a triangular cavity, coupling Navier–Stokes and heat conduction — keywords: incompressible flow, Navier–Stokes, heat equation, convergence study
Example275optimal control for the Stokes problem; computes the optimal control with an adjoint formulation — keywords: incompressible flow, Stokes, optimal control, adjoint, convergence study
Example2802D compressible Stokes flow with an equation of state; a well-balanced (gradient-robust) discretization is compared against a standard one — keywords: incompressible flow, Stokes, compressible, equation of state, convergence study
Example282stationary incompressible viscous MHD: Navier–Stokes coupled with the magnetic induction equation — keywords: incompressible flow, Navier–Stokes, MHD, nonlinear
Example284time-dependent convection of a level set by a given velocity field — keywords: conforming FEM, level set, free boundary, time-dependent
Example285phase-field Cahn–Hilliard equation in mixed form — keywords: mixed method, phase field, time-dependent
Example290three-field Biot consolidation model with an H(div)-conforming reconstruction to avoid Poisson locking — keywords: mixed method, poroelasticity, H(div), time-dependent, convergence study
Example295droplet sliding down a surface with surface tension and slip, tracked with an ALE moving mesh up to a stationary state — keywords: incompressible flow, Navier–Stokes, ALE moving mesh, free boundary, time-dependent, nonlinear
Example3013D Poisson problem on the unit cube; demonstrates iterative (Krylov) solvers with incomplete LU preconditioners — keywords: conforming FEM, 3D, Krylov solvers and preconditioning
Example310best approximation of a divergence-free velocity by a divergence-free Raviart–Thomas (H(curl)-type) basis with a linearly independent basis construction — keywords: mixed method, H(curl), divergence-free basis, 3D
Example3123D periodic elasticity on a generated unstructured grid with periodic coupling along one axis — keywords: conforming FEM, elasticity, periodic boundary, 3D
Example3133D periodic Poisson problem verifying the restriction-based periodic boundary operator against the exactly linear solution — keywords: conforming FEM, periodic boundary, restrictions, 3D
Example330neo-Hookian hyperelasticity in 3D; the energy is twice differentiated automatically to set up the Newton scheme — keywords: conforming FEM, hyperelasticity, nonlinear, automatic differentiation, 3D

Learn a Concept

If you are looking for a particular finite element concept instead of a particular problem, this table shows where to look: the corresponding documentation page(s) and the examples that demonstrate the concept. Where no documentation page exists, the listed examples are currently the primary reference.

ConceptDocumentationExamples
Nonlinear equations (Newton iteration)NonlinearOperatorExample105, Example225, Example227, Example230, Example330
Boundary conditions (Dirichlet, Neumann, Robin)Restrictions, Interpolate boundary dataExample108, Example201, Example313
Periodic boundaryRestrictions, Combined DOFsExample212, Example266, Example312, Example313
Variational inequalities (obstacle problem)—Example225, Example227
Elasticity and hyperelasticity—Example212, Example226, Example230, Example312, Example330
Discontinuous Galerkin (nonconforming)—Example203, Example207
Stabilization (interior penalty, upwind)—Example203, Example207, Example220, Example265
Mixed methods (H(div), H(curl))—Example202, Example211, Example240, Example290, Example310
Error estimation & adaptive refinement—Example210, Example211
Incompressible flow (Stokes, Navier–Stokes)—Example235, Example240, Example245, Example250, Example252, Example260, Example264, Example265, Example266, Example270, Example275, Example280, Example282, Example295
Quantities of interest (drag/lift, Nusselt number, etc.)Item integratorsExample245, Example265, Example270, Example295
Coupled / multi-physics problems—Example206, Example264, Example265, Example270, Example282, Example290
Time-dependent problemsTime-dependent solversExample103, Example106, Example205, Example284, Example285, Example290, Example295
Free boundary, level set, phase field, ALE—Example284, Example285, Example295
Optimal control & adjoints—Example275
Eigenvalue problems—Example204
Stationary solvers & preconditioningStationary solversExample301
Parallel assemblyParallel assemblyExample211
Postprocessing & visualizationPostprocessingExample210, Example211, Example245