Skip to content
System Status: All systems are operational • Services are available and operational.
Click for detailed status

FEniCS

FEniCS is a popular open-source computing platform for solving partial differential equations (PDEs) using the finite element method. It provides a high-level Python and C++ interface for expressing variational problems and automatically generates efficient code for solving them.

FEniCS on Euler

On Euler the following versions are available via modules:

Version Module command
0.9.0 module load stack/2024-06 gcc/12.2.0 openmpi/4.1.6 fenics-dolfinx/0.9.0 py-fenics-ufl/2024.2.0 py-fenics-ffcx/0.9.0 py-fenics-dolfinx/0.9.0 py-fenics-basix/0.9.0 fenics-ufcx/0.9.0 fenics-basix/0.9.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1
0.8.0 module load stack/2024-06 gcc/12.2.0 openmpi/4.1.6 fenics-dolfinx/0.8.0 py-fenics-ufl/2024.1.0.post1 py-fenics-ffcx/0.8.0 py-fenics-dolfinx/0.8.0 py-fenics-basix/0.8.0 fenics-ufcx/0.8.0 fenics-basix/0.8.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1

Example program

Create a file test.py with the following content:

from mpi4py import MPI
from petsc4py.PETSc import ScalarType  # type: ignore
import numpy as np
import ufl
from dolfinx import fem, io, mesh, plot
from dolfinx.fem.petsc import LinearProblem
from ufl import ds, dx, grad, inner

msh = mesh.create_rectangle(
    comm=MPI.COMM_WORLD,
    points=((0.0, 0.0), (2.0, 1.0)),
    n=(32, 16),
    cell_type=mesh.CellType.triangle,
)
V = fem.functionspace(msh, ("Lagrange", 1))

facets = mesh.locate_entities_boundary(
    msh,
    dim=(msh.topology.dim - 1),
    marker=lambda x: np.isclose(x[0], 0.0) | np.isclose(x[0], 2.0),
)

dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)
bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)

u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
x = ufl.SpatialCoordinate(msh)
f = 10 * ufl.exp(-((x[0] - 0.5) ** 2 + (x[1] - 0.5) ** 2) / 0.02)
g = ufl.sin(5 * x[0])
a = inner(grad(u), grad(v)) * dx
L = inner(f, v) * dx + inner(g, v) * ds

problem = LinearProblem(a, L, bcs=[bc], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
uh = problem.solve()

with io.XDMFFile(msh.comm, "poisson1.xdmf", "w") as file:
    file.write_mesh(msh)
    file.write_function(uh)
To run the example, load the module and execute the script:

module load stack/2024-06 gcc/12.2.0 openmpi/4.1.6 fenics-dolfinx/0.9.0 py-fenics-ufl/2024.2.0 py-fenics-ffcx/0.9.0 py-fenics-dolfinx/0.9.0 py-fenics-basix/0.9.0 fenics-ufcx/0.9.0 fenics-basix/0.9.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1
srun --mem-per-cpu=4G python test.py