FEniCSx Local Environment Setup with WSL2#
This repository provides a simplified, automated setup for a native FEniCSx installation using a Python Virtual Environment (venv) directly within a dedicated Windows Subsystem for Linux 2 (WSL2) distribution. This approach offers a clean, isolated, and locally controlled environment for simulation development.
IMPORTANT NOTE: The
install_local_fenicsx.batfile must be executed from a dedicated Windows folder as well asuninstall_local_fenicsx.bat).
Directory Structure#
The following tree represents the required structure of the installer folder. All files shown here are necessary for the installation process.
WSL_Local_installer/
βββ install_local_fenicsx.bat
βββ uninstall_local_fenicsx.bat
βββ apt-installed-list.txt
βββ pip-installed-list.txt
Key Features#
Native WSL2 Installation: Installs FEniCSx directly onto the Linux filesystem within a dedicated Ubuntu 24.04 distribution (
FEniCSxenv), providing near-native Linux performance.Isolated Virtual Environment: Uses a Python Virtual Environment (
venv) namedfenicsx-envto manage FEniCSx and its dependencies, ensuring system-wide Python installations remain clean.Pre-defined Dependencies: System (via
apt) and Python (viapip) packages are automatically installed based on the content of the provided.txtlist files, ensuring a consistent and reproducible setup.Automatic Activation: The virtual environment is automatically sourced upon launching the WSL distribution, meaning you can start running FEniCSx commands immediately without manual activation.
Windows-Native Launchers: The installation and uninstallation processes are entirely driven by Windows
.batfiles.
Installation#
Preparation: Ensure WSL2 is enabled and configured on your Windows machine.
Execution: From the dedicated Windows folder containing all installer files, run the main installer script:
install_local_fenicsx.bat
Prompts: The script will first install the Ubuntu 24.04 distribution (
FEniCSxenv). You will be prompted to:Set a WSL username and password in the new Ubuntu window.
After the Ubuntu setup is complete, you must re-enter the WSL username in the installerβs command prompt to allow the script to proceed with the FEniCSx installation, virtual environment setup, and auto-activation.
Completion: The script will automatically verify the installation by checking the dolfinx version. A success or failure message will be displayed upon completion.
Usage#
Since the environment is configured for automatic activation, usage is simple:
1. Launching the FEniCSx Environment#
Open your WSL distribution directly from the Windows search bar or by running this command in Windows Command Prompt/PowerShell:
wsl -d FEniCSxenv
You will be logged in, and the fenicsx-env virtual environment will be automatically activated. You are now ready to run your FEniCSx Python scripts (e.g., python3 myscript.py or using mpirun).
2. Running Scripts#
You can execute your FEniCSx scripts directly from the WSL command line:
# Run a single Python script
python3 filename.py
# Run a parallel simulation using mpirun
mpirun -np 4 python3 parallel_script.py
Uninstallation#
To completely remove the installed FEniCSx environment:
Run Uninstaller: Execute the uninstallation batch file from Windows:
uninstall_local_fenicsx.bat
Warning: This uses the
wsl --unregistercommand, which is an irreversible action. It will delete the entireFEniCSxenvWSL distribution, including all data, the Python virtual environment, and any user files stored inside it.