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 and organized in collaboration with G. Sciumè.

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

Install/

Scripts and comprehensive documentation for setting up the FEniCSx environment on various platforms: Windows (WSL2, Docker) and High-Performance Computing (HPC) systems (Spack).

Tutorials/

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

WSL_Docker_installer

Windows (WSL2 + Docker)

install_wsl2_fenicsx_docker.bat, FEniCSx_interactive.bat

WSL_Local_installer

Windows (WSL2 Native)

install_local_fenicsx.bat, apt-installed-list.txt

Windows_docker_installer

Windows (Docker Desktop Direct)

FEniCSx_docker_0-9-0.bat, Interactive_FEniCSx_0-9-0.bat

Spack_Install_FEniCSx (MCIA or Cassiopee)

Linux / HPC

Install Procedures and batch files


2. Requirements & Environment Setup#

To successfully execute the provided examples, the following components are necessary:

  1. FEniCSx v0.9.0 runtime environment (Requires one of the installation methods outlined below).

  2. GMSH software (version >4.11) for mesh generation.

  3. 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:


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

fenicsx

Interactive Shell

Launches an interactive Bash shell inside the FEniCSx container.

fenicsx-run

Run Script/Command

Executes a single command or Python script non-interactively.

fenicsx-jupyter

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:

  • 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.