Skip to content

Commit 0616225

Browse files
committed
refine docs and link to demos programs
1 parent f31b552 commit 0616225

File tree

1 file changed

+25
-87
lines changed

1 file changed

+25
-87
lines changed

docs/software/cae/fenics.md

Lines changed: 25 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22

33
<!-- Intro start -->
44

5-
[FEniCS](https://fenicsproject.org/) is a popular open-source computing platform for solving partial differential equations (PDEs) using the finite element method ([FEM](https://en.wikipedia.org/wiki/Finite_element_method)). Originally developed in 2003, the earlier version is now known as legacy FEniCS. In 2020, the next-generation framework [FEniCSx](https://docs.fenicsproject.org/) was introduced, with the latest stable [release v0.9.0](https://fenicsproject.org/blog/v0.9.0/) in October 2024. Though it builds on the legacy FEniCS but introduces significant improvements over the legacy libraries. FEniCSx is comprised of the libraries [UFL](https://github.com/FEniCS/ufl), [Basix](https://github.com/FEniCS/basix), [FFCx](https://github.com/FEniCS/ffcx), and [DOLFINx](https://github.com/FEniCS/dolfinx) which are the build blocks of it. And new users are encouraged to adopt [FEniCSx](https://docs.fenicsproject.org/) for its modern features and active development support.
5+
[FEniCS](https://fenicsproject.org/) is a popular open-source computing platform for solving partial differential equations (PDEs) using the finite element method ([FEM](https://en.wikipedia.org/wiki/Finite_element_method)). Originally developed in 2003, the earlier version is now known as legacy FEniCS. In 2020, the next-generation framework [FEniCSx](https://docs.fenicsproject.org/) was introduced, with the latest stable [release v0.9.0](https://fenicsproject.org/blog/v0.9.0/) in October 2024. Though it builds on the legacy FEniCS but introduces significant improvements over the legacy libraries. FEniCSx is comprised of the libraries [UFL](https://github.com/FEniCS/ufl), [Basix](https://github.com/FEniCS/basix), [FFCx](https://github.com/FEniCS/ffcx), and [DOLFINx](https://github.com/FEniCS/dolfinx) which are the build blocks of it. And new users are encouraged to adopt [FEniCSx](https://fenicsproject.org/documentation/) for its modern features and active development support.
66

77

8-
<!-- // Tutorials: https://jsdokken.com/dolfinx-tutorial/index.html -->
8+
(Maybe add a short intro into the stack the software depends on, and further more the internal dependencies UFL->FFCx ...)Like: the internal workflow typically follows [UFL](https://github.com/FEniCS/ufl)[FFCx](https://github.com/FEniCS/ffcx)[Basix](https://github.com/FEniCS/basix)[DOLFINx](https://github.com/FEniCS/dolfinx), transforming mathematical PDE descriptions into efficient numerical solvers.
99

1010

11-
<!-- Intro end -->
1211

13-
## Installation of FEniCSx
1412

1513
FEniCSx can be installed on [ULHPC](https://www.uni.lu/research-en/core-facilities/hpc/) systems using [Easybuild](https://docs.easybuild.io) or [Spack](https://spack.io/), Below are detailed instructions for each method,
1614

17-
15+
<!-- Intro end -->
1816

1917
### Building FEniCS With Spack
2018

2119

22-
Building FEniCSx with Spack requires that Spack is already installed, configured, and its environment sourced on the [ULHPC] system. If Spack is not yet configured, follow the [spack documentation](../../environment/spack.md) for installation and configuration.
20+
Building FEniCSx with Spack on the [ULHPC](https://www.uni.lu/research-en/core-facilities/hpc/) system requires that Users already installed Spack and sourced its enviroment on the cluster. If Spack is not yet configured, follow the [spack documentation](../../environment/spack.md) for installation and configuration.
21+
2322

2423
!!! note
25-
Spack can a good choice to build FEniCSx with its many complex dependencies, leveraging the system-provided packages defined in ~/.spack/packages.yaml for optimal performance.
24+
25+
Spack would be a good choice for building FEniCSx because it automatically manages complex dependencies, isolates all installations in a dedicated environment, leverages system-provided packages in ~/.`spack/packages.yaml` for optimal performance, and simplifies reproducibility and maintenance across different systems.
2626

2727
Create and Activate a Spack Environment:
2828

2929
To maintain an isolated installation, create a dedicated Spack environment in a chosen directory.
3030
The following example builds FEniCSx in the `home` directory:
3131

3232
cd ~
33-
spack env create -d fenicsx-main-20230126/
34-
spack env activate fenicsx-main-20230126/
33+
spack env create -d fenicsx-0.9.0/
34+
spack env activate fenicsx-0.9.0/
3535

3636

3737
Add the core FEniCSx components and common dependencies:
@@ -43,13 +43,13 @@ Add the core FEniCSx components and common dependencies:
4343
spack install -j16
4444

4545

46-
!!! note
46+
!!! question " why concretize and -j16 ? "
4747

48-
`spack concretize` resolves all dependencies and selects compatible versions for the specified packages. `-j16` sets the number of parallel build jobs. Using a higher number can speed up the build but should be chosen based on available CPU cores and cluster policies.
48+
`spack concretize` resolves all dependencies and selects compatible versions for the specified packages. `-j16` sets the number cores to use for building. Using a higher number can speed up the build but should be chosen based on available CPU cores and cluster policies.
4949

5050

5151

52-
or the same directly in `spack.yaml` in `$SPACK_ENV`
52+
or its also possible to define build packages in `$SPACK_ENV` in a `spack.yaml` file.
5353

5454
spack:
5555
# add package specs to the `specs` list
@@ -63,7 +63,13 @@ or the same directly in `spack.yaml` in `$SPACK_ENV`
6363
concretizer:
6464
unify: true
6565

66-
The following are also commonly used in FEniCS scripts and may be useful
66+
!!! question " why unify : true ? "
67+
68+
`unify: true` ensures all packages share the same dependency versions, preventing multiple builds of the same library. Without it, each `spec` could resolve dependencies independently, leading to potential conflicts and redundant installations.
69+
70+
71+
72+
The following are also common dependencies used in FEniCS scripts:
6773

6874
spack add gmsh+opencascade py-numba py-scipy py-matplotlib
6975

@@ -72,7 +78,6 @@ Note that the hash must be the full hash.
7278
It is best to specify appropriate git refs on all components.
7379

7480
# This is a Spack Environment file.
75-
#
7681
# It describes a set of packages to be installed, along with
7782
# configuration settings.
7883
spack:
@@ -96,11 +101,11 @@ It is best to specify appropriate git refs on all components.
96101
concretizer:
97102
unify: true
98103
99-
It is also possible to build only the C++ layer using
104+
It is also possible to build only the C++ layer using (Need to comment about why we add python depndencies?)
100105

101-
spack add fenics-dolfinx@main+adios2 py-fenics-ffcx@main petsc+mumps
106+
spack add fenics-dolfinx@0.9.0+adios2 py-fenics-ffcx@0.9.0 petsc+mumps
102107

103-
To rebuild FEniCSx from main branches inside an existing environment
108+
To rebuild FEniCSx from main branches inside an existing environment (merge with main install desription before?)
104109

105110
spack install --overwrite -j16 fenics-basix py-fenics-basix py-fenics-ffcx fenics-ufcx py-fenics-ufl fenics-dolfinx py-fenics-dolfinx
106111

@@ -110,14 +115,11 @@ Quickly test the build with
110115

111116
srun python -c "from mpi4py import MPI; import dolfinx"
112117

113-
#### Using the build
118+
!!! info "Try the Build Explicitly"
114119

115-
See the uni.lu documentation for full details - using the environment should be as
116-
simple as adding the following where `...` is the name/folder of your environment.
120+
After installation, the [FEniCSx](https://fenicsproject.org/documentation/) build can be tried explicitly by running the demo problems corresponding to the installed release version, as provided in the [FEniCSx documentation](https://docs.fenicsproject.org/).
121+
For [DOLFINx](https://docs.fenicsproject.org/dolfinx/main/python/) Python bindings, see for example the demos in the [stable release v0.9.0](https://docs.fenicsproject.org/dolfinx/v0.9.0/python/demos.html).
117122

118-
#!/bin/bash -l
119-
source $HOME/spack/share/spack/setup-env.sh
120-
spack env activate ...
121123

122124
#### Known issues
123125

@@ -133,71 +135,7 @@ Workaround for inability to find adios2 Python package:
133135
### Building FEniCS With EasyBuild
134136

135137

136-
### Example (Poisson.py)
137-
```bash
138-
139-
# Demo possion problem
140-
# https://docs.fenicsproject.org/dolfinx/main/python/demos/demo_poisson.html
141-
142-
from mpi4py import MPI
143-
from petsc4py.PETSc import ScalarType
144-
145-
import numpy as np
146-
147-
import ufl
148-
from dolfinx import fem, mesh
149-
from dolfinx.fem.petsc import LinearProblem
150-
151-
# Create mesh
152-
msh = mesh.create_rectangle(
153-
comm=MPI.COMM_WORLD,
154-
points=((0.0, 0.0), (2.0, 1.0)),
155-
n=(32, 16),
156-
cell_type=mesh.CellType.triangle,
157-
)
158-
159-
# Function space
160-
V = fem.functionspace(msh, ("Lagrange", 1))
161-
162-
# Boundary facets (x=0 and x=2)
163-
facets = mesh.locate_entities_boundary(
164-
msh,
165-
dim=(msh.topology.dim - 1),
166-
marker=lambda x: np.isclose(x[0], 0.0) | np.isclose(x[0], 2.0),
167-
)
168-
dofs = fem.locate_dofs_topological(V=V, entity_dim=1, entities=facets)
169-
170-
# Dirichlet BC u = 0
171-
bc = fem.dirichletbc(value=ScalarType(0), dofs=dofs, V=V)
172-
173-
# Variational problem
174-
u = ufl.TrialFunction(V)
175-
v = ufl.TestFunction(V)
176-
x = ufl.SpatialCoordinate(msh)
177-
f = 10 * ufl.exp(-((x[0] - 0.5) ** 2 + (x[1] - 0.5) ** 2) / 0.02)
178-
g = ufl.sin(5 * x[0])
179-
a = ufl.inner(ufl.grad(u), ufl.grad(v)) * ufl.dx
180-
L = ufl.inner(f, v) * ufl.dx + ufl.inner(g, v) * ufl.ds
181-
182-
# Create problem (no petsc_options_prefix in 0.9.0)
183-
problem = LinearProblem(
184-
a,
185-
L,
186-
bcs=[bc],
187-
petsc_options={"ksp_type": "preonly", "pc_type": "lu", "ksp_error_if_not_converged": True},
188-
)
189-
190-
# Solve
191-
uh = problem.solve()
192-
193-
# Only print from rank 0 to avoid MPI spam
194-
if MPI.COMM_WORLD.rank == 0:
195-
print("First 10 values of the solution vector:", uh.x.array[:10])
196-
197-
assert isinstance(uh, fem.Function)
198-
199138

200-
```
201139

202140
## Additional information
203141
FEniCS provides the [technical documentation](https://fenicsproject.org/documentation/),

0 commit comments

Comments
 (0)