How to Install OpenFOAM v2012 from Source Pack on Ubuntu

In this post you will learn how to install OpenFOAM v2012 from source pack. The procedure is tested on Ubuntu 18.04 LTS and Ubuntu 20.04 LTS. It is assumed that you are installing OpenFOAM v2012 on a fresh operating system.

Note1: If you previously installed the older version of OpenFOAM from source pack, you may not need to install some of the prerequisite packages on your computer and skip them.

Note2: The method described here enables you to install multiple version/distribution of OpenFoam on a single computer. Then you can use either of them when needed.

You can find instructions to install older versions of OpenFOAM:

 

A) Download and Initial Checks

1) Downloading source code: go to official website of OpenFOAM v2012 and download the source pack of the latest version (at the moment it is OpenFOAM v2012). Or simply follow these links to download the compressed files by clicking on them:

2) Creating installation folder in the home folder: move the downloaded compressed files to the directory in which you want to install (compile) OpenFOAM v2012. Here we keep everything on the home folder of the computer. Create a new folder with name “OpenFOAM” (if you already do not have it) on the home folder and move the compressed files into this folder.

3) Unpacking the files: open a new terminal in this folder and decompress these two files:

tar -xzf OpenFOAM-v2012.tgz
tar -xzf ThirdParty-v2012.tgz

Two folders with names “OpenFOAM-v2012” and “ThirdParty-v2012” are created under ~/OpenFOAM folder.

4) Compiler version: check the compiler version. You need gcc version 4.8.5 or higher (the version of default compiler on Ubuntu 18.xx and Ubuntu 20.xx is higher than this).

gcc --version

if you do not have gcc installed on your computer or gcc version is lower than 4.8.5, execute the following commands:

sudo apt-get update
sudo apt-get install gcc
B) Installing prerequisites on your Computer

5) Installing prerequisites: you need to install other packages to be able to compile and run OpenFoam and Paraview. To install these packages on Ubuntu, execute the following commands in the terminal (for compiling and running OpenFOAM):

sudo apt-get update

sudo apt-get install build-essential autoconf autotools-dev cmake gawk gnuplot

sudo apt-get install flex libfl-dev libreadline-dev zlib1g-dev openmpi-bin libopenmpi-dev mpi-default-bin mpi-default-dev

sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev bison libncurses-dev libxt-dev

sudo apt-get install libscotch-dev libptscotch-dev libfftw3-dev libboost-system-dev libboost-thread-dev libcgal-dev

sudo apt-get install qt4-dev-tools libqt4-dev libqt4-opengl-dev freeglut3-dev libqtwebkit-dev

In any stage of package installation, if you get error “unable to fetch some archives”, try the following command:

sudo apt-get update --fix-missing

and restart installing packages.

6) Setting environmental variables: in this step, you need to set environmental variables. The method allows you to install multiple versions of OpenFOAM v2012 on your computer at the same time. So, open ~/.bashrc file using this command:

gedit ~/.bashrc

and add the following line at the end of this file, save and close the file (assuming that you installed OpenFOAM v2012 in the $HOME/OpenFOAM directory).

alias of2012="source $HOME/OpenFOAM/OpenFOAM-v2012/etc/bashrc"

then enter this commands in the current terminal window:

source ~/.bashrc

the bashrc file of OpenFoam which contains the environmental setting is not configured in the current terminal window. To load these settings into the current terminal window (or any new terminal window that you open) you need to enter the following command:

of2012
C) Compiling and running

7) Installing Third-party packages: change the current directory to $HOME/OpenFOAM/ThirdParty-v2012 in the terminal (you already entered of2012 command in this terminal) and then enter this command to install third party packages:

./Allwmake

Note: If you performed step 6 successfully, most of the third-party packages are already installed on your computer. OpenFOAM, by default,  uses these packages that are installed on your system (from apt repository or other official repositories). So building packages from Third-party folder is not mandatory. However, if in any circumstance you fail to install any package on your computer from apt repository, you can install/build that package from Third-party folder.

 

8) Compiling OpenFOAM: change the current directory to $HOME/OpenFOAM/OpenFOAM-v2012 in the terminal (you already entered of2012 command in this terminal) and then enter this command to compile OpenFOAM:

./Allwmake -j

this may take several minutes to hours to finish.

Note: The above command builds OpenFOAM using all the available processors on your computer. If you do not have enough RAM and/or Swap space, compilation may fail due to shortage of memory. In this case, just remove -j flag from above command.

9) using OpenFOAM: you will find some tutorials on using OpenFOAM v2012 on this website (for intermediate users) and cfd.at (for beginners) .

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *