π³ FEniCSx Environment Setup with Docker and WSL2#
This repository provides an automated, professional, and highly efficient setup for running FEniCSx simulations. It utilizes a Docker container orchestrated within the Windows Subsystem for Linux 2 (WSL2), delivering a consistent, isolated, and high-performance simulation environment on Windows systems.
IMPORTANT NOTE FOR INSTALLATION: The
install_wsl2_fenicsx_docker.batfile, along with its dependency folder (src_install/) and all other files from the root of this repository (the entire WSL_Docker_installer folder), must be run from a dedicated Windows folder containing ONLY the necessary installation files. This is crucial because the entire contents of this folder will be copied to your Linux home directory within WSL2 (~/Softwares/WSL2_Docker_FEniCSx) as the installation source. After a successful installation, you can safely delete this original Windows folder, as a safe version is stored within the WSL distribution. The other launcher batch files (FEniCSx_interactive.bat,FEniCSx_command.bat,uninstall_wsl2_fenicsx_docker.bat) can be placed anywhere else on your Windows system for convenience.
Performance and Efficiency Statement#
For local development and execution, the use of Docker within WSL2 (Windows 11) is often sufficient and demonstrably efficient. This methodology has specifically proven to be more performant than running Docker directly on Windows (via Docker Desktopβs native integration) or managing a local installation with a Python 3 virtual environment (venv) of FEniCSx. This efficiency is achieved through WSL2βs optimized I/O performance and direct integration with the Linux kernel.
Directory Structure#
The following tree represents the complete structure of the installation folder (WSL2_Docker_FEniCSx) that is copied into the WSL distributionβs home directory during the installation process:
WSL2_Docker_FEniCSx/
βββ FEniCSx_command.bat
βββ FEniCSx_interactive.bat
βββ README.md
βββ install_wsl2_fenicsx_docker.bat
βββ report.log
βββ report_uninstall.log
βββ src_install
βΒ Β βββ apt_environment_aliases
βΒ Β βΒ Β βββ fenicsx_aliases.sh
βΒ Β βΒ Β βββ verification.sh
βΒ Β βββ custom_packages
βΒ Β βΒ Β βββ package.txt
βΒ Β βΒ Β βββ pyproject.toml
βΒ Β βΒ Β βββ src
βΒ Β βΒ Β Β Β βββ MLacour_fenicsx
βΒ Β βΒ Β Β Β Β Β βββ Mesh_Bio.py
βΒ Β βΒ Β Β Β Β Β βββ Operators.py
βΒ Β βΒ Β Β Β Β Β βββ Retrieve_and_plot.py
βΒ Β βΒ Β Β Β Β Β βββ __init__.py
βΒ Β βββ docker
βΒ Β Β Β βββ docker_fenicsx_env.sh
βΒ Β Β Β βββ docker_install_check.sh
βββ test_codes
βΒ Β βββ Test.py
βββ uninstall_wsl2_fenicsx_docker.bat
Key Features#
Isolated and Consistent: FEniCSx runs inside a secure Docker container, ensuring environmental stability and reproducibility.
Optimized Performance: Leverages the performance benefits and native Linux compatibility of WSL2.
Simple Image Update: The Docker image can be updated or rebuilt (e.g., after custom modifications) by simply re-running
install_wsl2_fenicsx_docker.bat(respecting the insitial Note about file dependencies). The installer will update the image without requiring a full reinstallation of the WSL distribution or re-engaging the interactive user prompts.Extensible Environment: Other Python
pippackages can be added to the Docker image by modifying the Docker build logic within thesrc_install/docker/docker_fenicsx_env.shfile and placing any necessary configuration (likepyproject.toml) inside thesrc_install/custom_packagesdirectory.Windows-Native Launchers: All
.batfiles must be run from Windows (Command Prompt or PowerShell) to interact with and launch the environment inside WSL2.
Installation#
Execution: Run the main installer script from the dedicated Windows folder by double clicking on it:
install_wsl2_fenicsx_docker.bat
Process: The script will guide you through:
Naming your WSL distribution.
Creating a WSL username and password. You will need to type
exitto pursue the installation once this step is complete.The necessary steps to install Docker and build the FEniCSx image.
Completion: Upon success, a
report.logfile is generated, and the FEniCSx environment is ready for use.
Usage#
1. Launching from Windows (Using .bat files)#
All launcher batch files (.bat) are designed to be run directly from Windows.
Interactive Shell: Use
FEniCSx_interactive.batto open a command line session inside the FEniCSx Docker container. You will be prompted for the project folder path to mount.Run Script/Command: Use
FEniCSx_command.batto execute a single Python script or command non-interactively within the container. (You must edit the batch file to specify the target script path).
2. Direct Use in WSL2 Command Line (Using Aliases)#
Once your WSL distribution is running, you can open a shell directly and utilize the custom bash aliases created during installation.
Access WSL: Open the WSL distribution command line (e.g., by typing
wslin Windows search or opening Windows Terminal).Navigate: Change directory to the folder containing your FEniCSx code (e.g.,
cd ./Documents/MyProject).Run Interactive Session: To open an interactive shell inside the FEniCSx Docker environment:
fenicsx
This command mounts your current WSL directory into the container at
/home/fenicsx/shared.Run Non-Interactive Script: To execute a script using Python or MPI without entering the interactive shell:
# Run a simple Python script fenicsx-run "python3 filename.py" # Run a script using mpirun for parallel execution fenicsx-run "mpirun -np 4 python3 filename.py"
The
fenicsx-runalias passes the entire quoted string to a non-interactive bash session within the container.
Uninstallation#
To completely remove the installed FEniCSx environment and all associated files:
Run Uninstaller: Execute the uninstallation batch file from Windows:
uninstall_wsl2_fenicsx_docker.bat
Warning: This is an irreversible action and will delete the entire
FEniCSxenvWSL distribution, including all user files and the copied installation source code.