OpenFOAM.org compiling process on Linux or WSL for Windows

Originally developed as the commercial software FOAM by Nabla Ltd, OpenFOAM was released as an open-source C++ toolbox for computational fluid dynamics (CFD) under the GNU General Public License in December 2004. The name OpenFOAM stay for: Open Field Operation and Manipulation.
Over the years, its codebase branched into three main actively maintained variants:

  • the OpenFOAM Foundation version openfoam.org
  • the ESI-OpenCFD version openfoam.com
  • the community-driven fork foam-extend.


At foamBuilder, we started using it since version 1.2 in 2005, so it was only natural to discuss it on this website.
In this simple and straightforward guide, we will explain the main steps for compiling the OpenFOAM Foundation version openfoam.org, on Linux or in the same way in WSL (the Windows Subsistem Linux) for Windows.


openFOAM.org logo


Before starting, it is best practice to update and upgrade your Linux system using the following commands. Furthermore, you will need to install the following essential dependancies:

bash
sudo apt update
sudo apt upgrade

sudo apt install -y
build-essential
flex
bison
cmake
zlib1g-dev
libgmp-dev
libmpfr-dev
libboost-system-dev
libboost-thread-dev
libreadline-dev
libncurses-dev
libxt-dev
libfftw3-dev
libopenmpi-dev
openmpi-bin
git


Once updated, navigate to your preferred download directory and clone the repository:

bash
cd ~/download/fem
mkdir openFOAM
cd openFAOAM

wget -O - http://dl.openfoam.org/source/14 | tar xvz
wget -O - http://dl.openfoam.org/third-party/14 | tar xvz

cd
openFOAM

These two foders will be downloaded:

bash
OpenFOAM-14-version-14  ThirdParty-14-version-14/

Since compiling script expects folder paths without the "-version-14" suffix, rename the existing directories to OpenFOAM-14 and ThirdParty-14 respectively:

bash
mv OpenFOAM-14-version-14 OpenFOAM-14
mv ThirdParty-14-version-14 ThirdParty-14

Next, create the .OpenFOAM/14 directory and place an empty prefs.sh file inside it:

bash
mkdir -p ~/.OpenFOAM/14
touch -p ~/.OpenFOAM/14/prefs.sh

and edit it with the following content:

prefs.sh
export WM_COMPILER_TYPE=system
export WM_COMPILER=Gcc
export WM_MPLIB=SYSTEMOPENMPI

Now you are ready to start the compiling process. Just load the environment and select the number of processor:

bash
cd OpenFOAM-14

source etc/bashrc

./Allwmake -j 6

Depending on the number of selected cores, the compilation process may take anywhere from half an hour to several hours.

Once the compilation process is complete, you can verify the installation with the following commands:

bash
foamVersion
echo $FOAM_LIBBIN
ls -lh $FOAM_LIBBIN
which foamRun
which blockMesh
which simpleFoam
which icoFoam

If the compilation process finishes without any errors, you should see the following output:

bash
OpenFOAM-14
/home/user/downloads/fem/openFOAM/OpenFOAM-14/platforms/linux64GccDPInt32Opt/lib
/home/user/downloads/fem/openFOAM/OpenFOAM-14/platforms/linux64GccDPInt32Opt/bin/foamRun
/home/user/downloads/fem/openFOAM/OpenFOAM-14/platforms/linux64GccDPInt32Opt/bin/blockMesh
/home/user/downloads/fem/openFOAM/OpenFOAM-14/platforms/linux64GccDPInt32Opt/bin/simpleFoam
/home/user/downloads/fem/openFOAM/OpenFOAM-14/platforms/linux64GccDPInt32Opt/bin/icoFoam

Thats'all!

Following this straightforward guide, you should now be able to run your first CFD simulation using openFOAM.org.

Back to Quick start section