Fenics
From ScientificComputing
Contents
Category
Differential equations, Finite elementsDescription
FEniCS is a project for the development of concepts and tools for automated scientific computing, with a focus on automated solution of differential equations by finite element methods. It has a list of features for automated, efficient solution of differential equations, including automated solution of variational problems, automated error control and adaptivity, a comprehensive library of finite elements, high performance linear algebra and many more. FEniCS is organized as a collection of interoperable components that together form the FEniCS Project. These components include the problem-solving environment DOLFIN, the form compiler FFC, the finite element tabulator FIAT, the just-in-time compiler Instant, the code generation interface UFC, the form language UFL and a range of additional components.Available versions (Euler, old software stack)
Legacy versions | Supported versions | New versions |
---|---|---|
0.8.0 |
Please note that this page refers to installations from the old software stack. There are two software stacks on Euler. Newer versions of software are found in the new software stack.
Environment modules (Euler, old software stack)
Version | Module load command | Additional modules loaded automatically |
---|---|---|
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 fenics-ufcx/0.8.0 fenics-basix/0.8.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1 |
Please note that this page refers to installations from the old software stack. There are two software stacks on Euler. Newer versions of software are found in the new software stack.
How to submit a job
You can submit a Python FEniCS job with the following command.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 fenics-ufcx/0.8.0 fenics-basix/0.8.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1 sbatch [Slurm options] --wrap="python3 my_fenics_python_script.py"Here you need to replace [Slurm options] with Slurm parameters for the resource requirements of the job. Please find a documentation about the parameters of sbatch on the wiki page about the batch system.
Example
As an example for using fenics, we are running a script that solves a differential equation:[eu-login-01 ~]$ 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 fenics-ufcx/0.8.0 fenics-basix/0.8.0 python/3.11.6 py-mpi4py/3.1.4 py-petsc4py/3.20.1 [eu-login-01 ~]$ ls -ltr total 4 -rwxr-xr-x 1 euler T0000 219 Sep 14 08:20 test.py [eu-login-01 ~]$ cat test.py #!/usr/bin/env python 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) [eu-login-1 ~]$ sbatch --mem-per-cpu=4g --wrap="python3 ./test.py" Generic job. Job <27435524> is submitted to queue <normal.4h>.The resource usage summary as well as the job logs can be found in the LSF log file lsf.o27435524.