FEniCSx & GMSH Tutorial Repository (v0.9.0)#
This repository contains all materials, scripts, and documentation for a Finite Element Modeling workshop, focusing on FEniCSx v0.9.0 and GMSH v4.11+. The project is directly related to Thomas Lavigne’s AFR-FNR research, a collaborative effort involving the University of Luxembourg, Bordeaux University (I2M), and ENSAM Paris (IBHGC); and to the workshop conducted at I2M Bordeaux of the 9th-11th September 2024.
The primary goal is to guide users through advanced finite element methods using FEniCSx and robust, complex mesh generation with GMSH.
Please give a look here https://th0maslavigne.github.io/FEniCSx_GMSH_tutorials/README.html
1. Repository Structure Overview#
The repository is logically divided into Installation methodologies and practical Tutorials.
Directory |
Content Summary |
|---|---|
|
Scripts and comprehensive documentation for setting up the FEniCSx environment on various platforms: Windows (WSL2, Docker) and High-Performance Computing (HPC) systems (Spack). |
|
Python scripts demonstrating a range of finite element simulations (Elasticity, Fluid Dynamics, Thermal Analysis) and advanced GMSH meshing techniques. |
Core Installation Sub-Folders Breakdown#
Sub-Folder |
Target Platform |
Primary Files |
|---|---|---|
|
Windows (WSL2 + Docker) |
|
|
Windows (WSL2 Native) |
|
|
Windows (Docker Desktop Direct) |
|
|
Linux / HPC |
Install Procedures and batch files |
2. Requirements & Environment Setup#
To successfully execute the provided examples, the following components are necessary:
FEniCSx v0.9.0 runtime environment (Requires one of the installation methods outlined below).
GMSH software (version >4.11) for mesh generation.
ParaView for post-processing and visualization.
Installation Guidance#
Detailed, step-by-step instructions for all setup methods are located in the Install/Install_processes.md file.
For Windows users, the WSL2 Docker Installer (Install/WSL_Docker_installer/install_wsl2_fenicsx_docker.bat) is the most recommended approach, offering a self-contained, high-performance Linux environment.
Here-after are links to the official download pages:
Docker Desktop v4.34.0 or later (macOS or linked with WSL2 on Windows)
Docker Engine (macOS or Linux or Ubuntu WSL2),
GMSH software,
Paraview software.
3. Usage and Execution Launchers#
Environment Aliases (WSL2 Docker Method)#
After running the WSL2 Docker Installer, custom aliases are available inside the resulting WSL distribution (FEniCSxenv):
Alias |
Function |
Description |
|---|---|---|
|
Interactive Shell |
Launches an interactive Bash shell inside the FEniCSx container. |
|
Run Script/Command |
Executes a single command or Python script non-interactively. |
|
Jupyter Lab |
Launches Jupyter Lab, exposing it for access via your web browser. |
Note on Graphical Interfaces (Crucial)#
By default, Docker containers lack a graphical environment. Any script that attempts to open a GUI window (e.g., GMSH’s interactive viewer or certain Matplotlib backends) within the container may fail or crash.
To prevent this when running GMSH-related scripts, you must pass the close argument to suppress the GUI:
# Example of running a GMSH script non-interactively
fenicsx-run "python3 Tutoriels/Other_GMSH_Examples/chip5x5.geo close"
4. FEniCSx & GMSH Workshop Contents#
The workshop is designed to provide a comprehensive introduction to meshing with GMSH and finite element analysis with FEniCSx.
4.1. Finite Element Method (FEM) Overview#
A brief reminder about the Finite Element Method fundamentals.
4.2. GMSH Mesh Creation Techniques#
The workshop explores versatile methods for generating complex meshes, focusing on control and export compatibility:
Geometry Definition:
Creation from a sketch.
Creation from elementary geometries.
Utilizing symmetries and boolean operations.
Generating meshes from a pre-existing STL file.
Advanced Meshing:
Implementing local refinement procedures (referencing Lavigne et al., 2023).
Boundary and domain tagging for material and boundary condition mapping.
Export:
Export compatibility: FEniCSx vs. Fenics Legacy.
4.3. FEniCSx Computation and Problem Solving#
The computational portion of the workshop covers a range of physics and solution methods:
Problem Types:
Thermal Problems: Stationary and transient analysis.
Fluid Dynamics: Stokes Equation solving in 2D and 3D.
Poro-Mechanics: Terzaghi poromechanical model (referencing Lavigne et al., 2023).
Solid Continuous Mechanics:
Elastic and hyper-elastic problems.
Problems involving penalty contact.
Incremental resolution (for updated Lagrangian formulation).
Evaluation of a quantity (e.g., reaction force).
Numerical Methods:
Linear and Non-Linear resolutions.
Updated mesh resolution (mesh update).
For updated lagrangian please contact Carla Cornillon
4.4. Key Academic References and Resources#
The specialized topics (local refinement, poromechanics, and incremental resolution) are supported by the author’s published work, available in full on their GitHub repositories:
Porous Media and Local Refinement:
Lavigne et al., 2023 (DOI: 10.1016/j.jmbbm.2023.105902)
This work is related to the Terzaghi poromechanical model and local refinement in the workshop.
GitHub Repository: Dolfinx Porous Media
Incremental Resolution and Mesh Update:
Lavigne et al., 2024 (Work presented for an example of incremental resolution and mesh update.)
This includes the use of volume tags for material mapping and reaction force evaluation.
GitHub Repository: Skin Porous Modelling
5. Utility Code Snippet#
A simple Python function is provided here for exporting data lists to a CSV file:
def export_to_csv(data, filename, header=None):
import csv
try:
with open(filename, 'w', newline='') as file:
writer = csv.writer(file)
if header:
writer.writerow(header)
writer.writerows(data)
print(f"Data exported to {filename} successfully")
except Exception as e:
print(f"An error occurred while exporting data to {filename}: {e}")
6. Acknowledgments and Licensing#
Research and Funding#
This activity is a core component of Thomas Lavigne’s PhD work. This research was entirely or partially funded by the Luxembourg National Research Fund (FNR), under grant reference No. 17013182.
Open Access License#
For the purpose of open access, the author has applied a Creative Commons Attribution 4.0 International (CC BY 4.0) license to this work.
Inspiration and Support#
The author extends thanks to:
Jørgen S. Dokken and Christophe Geuzaine, whose exemplary work and tutorials served as inspiration for this repository.
F. Daghia and Ludovic Chamoin for the high-quality finite element courses delivered at the École Normale Supérieure Paris-Saclay.
Jack Hale and Stéphane Urcun for their invaluable assistance in code debugging throughout the PhD journey.
Giuseppe Sciumè for the invitation to co-organize the workshop at the Bordeaux University.
7. Comprehensive Resource Links#
Category |
Resource Title |
Description / Context |
Link |
|---|---|---|---|
FEniCSx |
FEniCS Project Website |
Official project homepage and documentation portal. |
|
FEniCSx |
FEniCSx Tutorial |
Comprehensive tutorial by Jørgen S. Dokken. |
|
FEniCSx |
FEniCSx Workshop (Deep Dive) |
Workshop materials by Jørgen S. Dokken. |
https://jsdokken.com/FEniCS-workshop/src/deep_dive/expressions.html |
FEniCSx |
FEniCSx Discourse Forum |
Official community forum for questions and support. |
|
FEniCSx |
FEniCSx GitHub Repositories |
Main GitHub organization for the FEniCS project. |
|
FEniCSx |
DOLFINx Documentation (v0.8.0) |
Core documentation for the Python interface. |
|
FEniCSx |
BASIX Documentation (v0.8.0) |
Documentation for the finite element basis function library. |
|
FEniCSx |
UFL Documentation |
Unified Form Language documentation. |
|
FEniCSx |
FFCx Documentation |
FEniCS Form Compiler documentation. |
|
FEniCSx |
Solver Options (PETSc) |
Manual for the PETSc library used for linear and nonlinear solvers. |
|
FEniCSx |
Changelog |
Release notes for DOLFINx on GitHub. |
|
FEniCSx |
FEniCS Legacy Documentation |
Documentation for older versions of FEniCS. |
|
FEniCSx |
FEniCS Book |
The classic FEniCS book (2011). |
https://launchpadlibrarian.net/83776282/fenics-book-2011-10-27-final.pdf |
FEniCSx |
Mesh Update Discussion |
Discourse thread on incrementally deformed mesh schemes/mesh geometry. |
|
FEniCSx |
Parallel Run Discussion |
Discourse thread on discrepancies between serial and parallel runs. |
https://fenicsproject.discourse.group/t/different-results-in-serial-and-parallel-run-dolfinx/4370 |
FEniCSx |
Parallel Demo (PML) |
Example of a parallel run with Perfectly Matched Layers. |
|
FEniCSx |
Parallel Demo (Axisymmetry) |
Example of a parallel run for an axisymmetric problem. |
|
GMSH |
GMSH Download Page |
Official download page for GMSH software. |
|
GMSH |
GMSH Manual |
Detailed documentation and reference manual. |
|
GMSH |
GMSH Introductory Presentation |
General overview course material (PDF). |
|
GMSH |
GMSH GitLab Repository |
Source code and issue tracker. |
|
GMSH |
GMSH API Tutorials |
Tutorials on using the GMSH API. |
|
GMSH |
OpenCascade Commands |
Reference for OpenCascade commands within GMSH. |
|
Post-processing |
ParaView Download Page |
Official download page for the visualization tool. |
|
Docker |
Docker Website |
Official website for Docker Desktop and Docker Engine. |
|
Docker |
Docker Desktop Installer (Win) |
Direct link to the Windows Docker Desktop installer. |
|
Docker |
Docker Desktop Installer (Mac ARM64) |
Direct link for macOS with Apple Silicon. |
|
Docker |
Docker Desktop Installer (Mac AMD64) |
Direct link for macOS with Intel chips. |
|
Docker |
Docker Installation Resource |
Official guide for Windows installation. |
|
Docker |
Docker Hub |
Repository for Docker images. |
|
Docker |
Docker Cheat Sheet (Official) |
Official quick reference guide. |
|
Docker |
Docker Cheat Sheet (Collabnix) |
Alternative detailed cheat sheet. |
|
Docker |
Windows Docker Cheat Sheet |
Gist for Windows-specific Docker commands. |
https://gist.github.com/danijeljw/a7a2553bd06742648172363ce3983a9a |
Containers |
Singularity (Apptainer) |
Documentation for the HPC-focused container platform. |
https://docs.sylabs.io/guides/3.5/user-guide/introduction.html |
HPC |
Spack Package Manager |
Official GitHub repository for the Spack package manager. |
|
HPC Containers |
Spack Containers Intro |
Quick introduction to using Spack for creating container images (Docker/Singularity). |
https://spack.readthedocs.io/en/latest/containers.html#a-quick-introduction |
ULHPC Docs |
ULHPC-Docs Software Config |
Reference to a pull request on the ULHPC documentation for software stack configuration. |
|
ULHPC Spack Config |
Spack vs. ULHPC Std Env |
GitHub Gist comparing Spack configuration against the standard software set on uni.lu clusters. |
https://gist.github.com/jhale/23d4d7646e2dc05d0adc0395767d044a |
GIT |
GIT Documentation |
Official documentation for version control. |
|
GIT |
GIT Reference |
Comprehensive command line reference. |
|
GIT |
GIT Interactive Tutorial |
Learn Git branching through an interactive web tool. |
|
FE Library |
Deal.ii Website |
Official website for the Deal.ii finite element library. |
|
FE Library |
Deal.ii Tutorials |
Collection of official tutorials. |
https://www.dealii.org/current/doxygen/deal.II/Tutorial.html |
FE Library |
Deal.ii Documentation |
Main documentation page. |
|
FE Library |
Deal.ii Library Reference |
Doxygen reference for the C++ library. |
|
Meshing Tool |
Pygmsh |
Python library for easy GMSH scripting. |
|
Meshing Tool |
Pygmsh GitHub |
Source code repository. |
|
Meshing Tool |
Meshio |
Tool for reading and writing various mesh formats. |
|
Meshing Tool |
Meshio GitHub |
Source code repository. |
|
Meshing Tool |
Pymesh |
Geometry processing library for Python. |
|
Meshing Tool |
Pymesh GitHub |
Source code repository. |
|
Meshing Tool |
Netgen/NGSolve |
Finite element code and mesher. |
|
Meshing Tool |
NGSolve Tutorials |
Tutorials by J. Schöberl. |
|
Meshing Tool |
Neper |
Tool for generating polycrystals/complex microstructures. |
|
Boolean Lib |
CGAL |
Computational Geometry Algorithms Library. |
|
Boolean Lib |
VTK-based Booleans |
Improved boolean operations using VTK. |
|
Boolean Lib |
MeshLib |
Mesh processing library. |
|
Boolean Lib |
mcut |
Mesh cutting utility. |
|
Boolean Lib |
trimesh |
Python library for loading and using meshes. |
|
Boolean Lib |
vedo (Boolean Example) |
Python library for 3D visualization and analysis. |
|
Boolean Lib |
PyMeshLab |
Python interface to the MeshLab meshing system. |
|
Boolean Lib |
Pycork (PyPI) |
Python bindings for the Cork boolean library. |
|
Boolean Lib |
Cork (C Library) |
The underlying C library for Pycork. |
|
Boolean Lib |
Blender |
Open-source 3D creation suite (includes Python module). |
|
Tomography |
Tomo2FE GitHub |
Workflow for converting tomography data to compliant multipart meshes. |
|
Tomography |
Tomo2FE Article |
Associated RILEM technical article. |
|
Clean Code |
Clean Code - Lesson 1 |
Robert C. Martin’s “Uncle Bob” series on clean code principles. |
|
Clean Code |
Clean Code - Conference Series |
Playlist of related Clean Code conference talks. |
https://www.youtube.com/watch?v=7EmboKQH8lM&list=PLmmYSbUCWJ4x1GO839azG_BBw8rkh-zOj&index=1 |
Documentation |
Doxygen |
Tool for generating documentation from source code. |
General Coding Remark#
If you are unable to find the documentation for a specific object, you can use the interactive help() command within ipython3. For instance, if you have a class object named mesh, typing mesh. and pressing Tab will allow you to explore its attributes, after which you can execute help(mesh.attribute) to get its specific documentation.
Ubuntu Note#
On Ubuntu jammy, a known conflict with FEniCSx v0.8.0 may require the removal of the python3-numba package using the following command:
sudo apt remove python3-numba