OpenFOAM Setup in Windows using WSL
Hi there !
Today we will be laying out the steps for setting up openFOAM environment in Windows sytem using the power of WSL.
To install OpenFOAM 9 (.org) and OpenFOAM v2412 (.com) on Windows using the Windows Subsystem for Linux (WSL), follow these step-by-step instructions.
Phase 1: Prepare Windows and Install WSL
Before installing OpenFOAM, you must enable the necessary Windows features and install a Linux distribution.
- Enable Windows Features: Open “Turn Windows features on or off” in your Windows search bar.
- Select Required Components: Ensure that “Virtual Machine Platform” and “Windows Subsystem for Linux” are both checked.
- Restart Your System: Click OK and restart your computer when prompted.
- Install Ubuntu via PowerShell:
- Open Windows PowerShell as an Administrator.
- Run the command: wsl –install to begin the installation of Ubuntu (typically version 22.04).
- Restart again if prompted by the terminal.
- Set Up Ubuntu: Launch the Ubuntu app. You will be asked to create a username and password. Choose a simple password you will remember, as it will not be visible when you type it into the terminal.
Phase 2: Install OpenFOAM 9 (Foundation Version)
- Open your Ubuntu terminal and execute the following commands to install the Foundation version of OpenFOAM.
- Add GPG Key: Add the public key for the repository to enable package verification:
sudo sh -c "wget -O - https://dl.openfoam.org/gpg.key > /etc/apt/trusted.gpg.d/openfoam.asc". - Add the Repository: Add the OpenFOAM software repository:
sudo add-apt-repository http://dl.openfoam.org/ubuntu. - Update Package List: Update your system’s package list to include the new repository: sudo apt-get update.
- Install OpenFOAM 9: Run the installation command: sudo apt-get -y install openfoam9.
Note: If you encounter dependency errors regarding
csh, enable the universe repository first:sudo apt-add-repository universefollowed bysudo apt-get update.
Phase 3: Install OpenFOAM v2412 (ESI Version)
The ESI version has a slightly different setup process. You can perform this in the same Ubuntu terminal.
- Set Up the Repository: Use the curl command to add the official ESI repository:
curl -s https://dl.openfoam.com/add-debian-repo.sh | sudo bash. - Update the Repository: Refresh your package list:
sudo apt-get update. - Install OpenFOAM v2412: Install the default version, which includes tutorials:
sudo apt-get install openfoam2412-default.
Note: Using the
-defaultsuffix ensures you get the full version with tutorials and documentation.
Phase 4: User Configuration (Setting Up Aliases)
Because you have two versions installed, you should use “aliases” to switch between them easily. Otherwise, they may conflict in your .bashrc file.
- Install a Text Editor: If you don’t have one, install gedit: sudo apt-get install gedit.
- Open
.bashrc: Open the configuration file in your home directory:gedit ~/.bashrc. - Add Version Aliases: Scroll to the very bottom of the file and add these lines:
- For OpenFOAM 9:
alias of9='source /opt/openfoam9/etc/bashrc'. - For OpenFOAM v2412:
alias of2412='source /usr/lib/openfoam/openfoam2412/etc/bashrc'.
- For OpenFOAM 9:
- Save and Refresh: Save the file and close the editor. In the terminal, run:
source ~/.bashrc.
Phase 5: Verification and Running a Test Case
To ensure everything is working, run a basic simulation for each version.
- Activate the Version: Type
of9orof2412in your terminal to source the specific version you want to use. - Create a Run Directory: Create a project folder to avoid modifying system files:
mkdir -p $FOAM_RUN run. - Copy a Tutorial: Copy the pitzDaily incompressible flow example:
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily.. - Run the Simulation:
- Enter the directory:
cd pitzDaily. - Generate the mesh:
blockMesh. - Run the solver:
simpleFoam.
- Enter the directory:
- Visualize Results: Type
paraFoamto open the results in ParaView. IfparaFoamfails, you can install ParaView manually usingsudo apt-get install paraview.