Installing foam-extend on Ubuntu and Windows WSL
Published:
A comprehensive guide to compilation of foam-extend on Ubuntu and Windows WSL.

In my previous articles, I’ve delved into the functionality and usage of OpenFOAM, exploring its diverse capabilities straight out of the box. However, the dynamic nature of its community has spurred the creation of various forks and extensions tailored to specific needs and preferences. Originating as FOAM (Field Operation And Manipulation) at Imperial College London [ADD links here], OpenFOAM emerged as an open-source solution, released under the GNU General Public License. This evolution led to the establishment of OpenCFD Ltd [ADD links here] and Wikki Ltd [ADD links here], ushering in three primary lines of development for OpenFOAM:
- OpenFOAM [Link here], maintained by OpenFOAM Foundation [Link here];
- OpenFOAM+ [Link here], maintained by the ESI Group [Link here];
- foam-extend [Link here], maintained by the Wikki Ltd [Link here]
While I previously covered the installation process for OpenFOAM+ [Link here], in this article, I focus on guiding you through the steps to install foam-extend. But before we dive in, it’s crucial to understand why foam-extend might be necessary. foam-extend extends the capabilities of OpenFOAM with additional well-tested solvers, including visco-elastic and solid mechanic solvers. Moreover, it offers Reduced Order Model (ROM) functionality using the Proper Orthogonal Decomposition (POD) and the snapshot method, enhancing its versatility in tackling fluid dynamics simulations. However, it’s essential to note that both foam-extend and OpenFOAM are inherently Linux-based programs. As such, users are expected to be familiar with Linux-based environments like Ubuntu or Windows Subsystem for Linux (WSL). In this guide, I’ll demonstrate the installation process using WSL, though the steps are applicable to Ubuntu as well.
For this installation, we’ll be working with foam-extend 4.1, and I recommend utilizing the Ubuntu 20.04.6 LTS distribution within WSL. Through my testing across multiple distributions, I’ve found Ubuntu 20.04.6 LTS to provide a seamless installation experience.
So, without further ado, let’s dive into the installation process!
First Steps
To begin the installation process for foam-extend on your Windows Subsystem for Linux (WSL) instance, ensure that you have Ubuntu 20.04.6 LTS available as the distribution. If not, you can easily install another instance of WSL with this specific distribution.
Once Ubuntu 20.04.6 LTS is set up, open your WSL instance in the Windows Terminal (preferably) and verify the current working directory using the following command:
pwd
Next, navigate to your home directory ($HOME
) where foam-extend will be installed:
cd ~
Before proceeding with the installation, it’s crucial to ensure that your system meets all the necessary requirements. These prerequisites include various libraries and toolchains essential for building the packages underlying foam-extend. You can install these libraries by running the following command:
sudo apt install git binutils-dev cmake flex zlib1g-dev libncurses5-dev
sudo curl bison libxt-dev rpm mercurial graphviz openmpi-bin libopenmpi-dev
sudo build-essential linux-generic libmpich-dev libopenmpi-dev metis libmetis-dev
sudo libparmetis-dev scotch libscotch-dev python3 python3-dev python-is-python3 python3-setuptools
Note: Each command may prompt you to install the corresponding packages; respond with ‘y’ as suggested.
Additionally, it’s recommended to update and upgrade your distribution to ensure that you have the latest packages installed:
sudo apt update
sudo apt upgrade
These commands will fetch the latest package information and upgrade the existing packages to their latest versions, ensuring a smooth installation process for foam-extend. With these prerequisites in place, you’re now ready to proceed with the installation of foam-extend on your Ubuntu 20.04.6 LTS distribution within WSL. Let’s continue with the installation process.
Source and compile foam-extend
With the necessary packages installed, let’s proceed with the installation of foam-extend. Follow these steps to set up foam-extend 4.1 on your Ubuntu 20.04.6 LTS distribution within WSL.
- First, create a folder named foam in your home directory by executing the following commands:
cd ~ mkdir foam
- Navigate to the newly created foam folder:
cd foam/
- Download the foam-extend 4.1 files from GitHub using the following command:
git clone https://git.code.sf.net/p/foam-extend/foam-extend-4.1 foam-extend-4.1
- Once the download is complete, navigate into the downloaded
foam-extend-4.1
folder, source the/etc/bashrc
file, and ensure a clean installation by clearing any past dependencies:cd foam-extend-4.1/ source etc/bashrc ./Allclean
Note: The
./Allclean
step is crucial as it ensures that any past build files and dependencies are cleared. Building or compiling on top of pre-built packages is not recommended, hence always perform the./Allclean
step before installation. - Now, let’s proceed to build the code, preferably in parallel. Begin by checking how many cores are available in your system using the
nproc
command. Then, export the number of available cores using:export WM_NCOMPPROCS=12
Replace
12
with the number of cores available in your system. - Finally, build the code using the following command:
./Allwmake.firstInstall
PS: Please note that this process may take anywhere from 30 minutes to 6 hours, depending on your system configuration and available resources.
With these steps completed, you’ll have successfully installed foam-extend 4.1 on your Ubuntu 20.04.6 LTS distribution within WSL. You’re now ready to explore the enhanced capabilities and features offered by foam-extend for your fluid dynamics simulations.
Post compilation steps
After successfully compiling foam-extend in the previous step without encountering any errors, it’s important to set up the necessary environment configurations. Follow these steps to ensure smooth integration and usage of foam-extend:
- Close the current terminal and open a new one to ensure that the changes take effect.
- Set up the source alias in your
.bashrc
file by executing the following command:echo 'alias FE41='source ~/foam/foam-extend-4.1/etc/bashrc'' >> ~/.bashrc
This command adds an alias to your .bashrc file, facilitating easy sourcing of the foam-extend environment.
- Close the terminal once again and open a new one to activate the changes made to the
.bashrc
file. - With the alias created, type
FE41
in the new terminal and press Enter to activate/source the foam-extend environment. - Once the foam-extend environment is activated, enter
foamInstallationTest
in the terminal to confirm the successful build and setup. - To run a simple tutorial, execute the following commands:
mkdir -p $FOAM_RUN cd run/ cp -r $FOAM_TUTORIAL/incomporesible/simpleFoam/pitzDaily . cd pitzDaily/ blockMesh && simpleFoam
These commands create a directory structure for foam-extend, copy a tutorial case into the working directory, perform mesh generation using
blockMesh
, and run the simulation usingsimpleFoam
. By following these steps, you’ll have successfully set up and verified the functionality of foam-extend, allowing you to explore its capabilities further in your fluid dynamics simulations.
In conclusion, we’ve embarked on a journey to harness the power of foam-extend, a comprehensive extension of OpenFOAM renowned for its additional solvers, utilities, and enhancements. By following the detailed steps outlined in this guide, you’ve successfully installed foam-extend on your Ubuntu or Windows Subsystem for Linux (WSL) system, unlocking a wealth of possibilities for your fluid dynamics simulations.
Happy simulating!