From Documentation
Revision as of 15:26, 23 September 2011 by Syam (Talk | contribs)

Jump to: navigation, search

What is OpenFoam?

OpenFOAM is a free, open source CFD software package produced by a commercial company, OpenCFD Ltd ( It has a large user base across most areas of engineering and science, from both commercial and academic organisations.

OpenFoam v2.0.x Installation

It appears that the 2.0.1 official version has a bug preventing it from compiling on our systems, but the most up-to date, git version (2.0.x) does compile. The instructions below are for our newer systems (orca, saw, hound, kraken). If compiled on one of them, it should also work on the rest without any changes.

Preliminary steps

Assuming we want to compile OpenFOAM on global work, the following steps should be done.

First, we create the environment, by executing these commands (you only have to do it once, for the compilation; for using OpenFOAM, these commands will be added in the OpenFOAM bashrc file, as described below):

module unload compile
module unload intel
module unload openmpi/intel
module load gcc/4.3.4 
module load openmpi/gcc/1.4.2

Next, we create the root OpenFOAM directory, and go there:

mkdir /work/$USER/OpenFOAM
cd /work/$USER/OpenFOAM

Then we download, unpack, compile and install the package "flex", which is needed for OpenFOAM compilation:

tar xvzf flex-2.5.35.tar.gz
cd flex-2.5.35
./configure --prefix=/work/$USER/OpenFOAM/flex
make install

Getting and preparing the OpenFOAM packages

Getting the third party packages (currently for the 2.0.1 version):

cd /work/$USER/OpenFOAM
tar xvzf ThirdParty-2.0.1.gtgz
mv ThirdParty-2.0.1 ThirdParty-2.0.x

Getting the up-to-date OpenFOAM package from the git repository:

git clone git://
cd OpenFOAM-2.0.x
git pull

Now we should edit the etc/bashrc file (inside the OpenFOAM-2.0.x subdirectory), by adding these lines to the very top of the file:

module unload compile
module unload intel
module unload openmpi/intel
module load gcc/4.3.4 
module load openmpi/gcc/1.4.2

Further in the same file, change the value assigned to the foamInstall variable:


Comment - if you plan to share OpenFOAM between a few group members, in the above line you have to substitute "$USER" with the actual login name of the user where OpenFOAM is being installed.

Finally, find the line in etc/bashrc which starts with "export WM_MPLIB=", and change it to


Next, we add these lines to the bottom (but before the comment "# cleanup environment:") of the file etc/config/ :

_foamAddPath ${FLEX}/bin
_foamAddLib ${FLEX}/lib


Go to the OpenFOAM root directory:

cd /work/$USER/OpenFOAM/OpenFOAM-2.0.x

and execute there

source etc/bashrc

Attention: there is a small problem with the OpenFOAM not being able to find the flex header file, FlexLexer.h . The workaround is to let "Allwmake" run for a while (it should finish compiling in the ThirdParty-2.0.x subdirectory, and start compiling in the OpenFOAM-2.0.x subdirectory), then kill it by pressing Ctrl-C one ore more times, and execute the following command:

ln -s /work/$USER/OpenFOAM/flex/include/FlexLexer.h /work/$USER/OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/FlexLexer.h

and then run Allwmake for the second time:


This time it should run without generating many error messages for a long time (many hours), until OpenFOAM is completely built.

Using the compiled OpenFOAM

Every time you or your group member wants to use the compiled OpenFOAM, s/he has to first execute

source /work/$USER/OpenFOAM/OpenFOAM-2.0.x/etc/bashrc

where "$USER" has to correspond to the user who installed the package.

OpenFoam v1.7 Installation

Module loading

In this installation, Gcc compiler is used in conjunction with Openmpi. So, you should load appropriate modules like

module load gcc/4.3.4 
module load openmpi/gcc/1.4.2

Please note that you may have to 'unload' the default settings like

module unload intel/11.0.083 
module unload openmpi/intel/1.4.2

Unpacking the source files

The package requires two parts; one is a main solver part and the other is a third-party. Two gtgz files can be downloaded from the website above.

[isaac@hnd50:/work/isaac/hound/builds/OpenFOAM] ls -lrt
total 92196
-rwxr-xr-x  1 isaac isaac 38998257 Nov  3 01:27 OpenFOAM-1.7.0.gtgz
-rwxr-xr-x  1 isaac isaac 55390881 Nov  3 01:27 ThirdParty-1.7.0.gtgz

As shown, the mother directory is made in '/work/isaac/hound/builds/OpenFOAM' and unpacked all files there like;

[isaac@hnd50:/work/isaac/hound/builds/OpenFOAM] ls -lrt
drwxrwxr-x 10 isaac isaac     4096 Nov  3 02:19 ThirdParty-1.7.0
drwxrwxr-x 10 isaac isaac     4096 Nov  9 11:46 OpenFOAM-1.7.0

Setting Environment Variables

The environment variable settings are contained in files in an OpenFOAM-1.7.0/etc directory in the OpenFOAM release. Basically two environment files ('bashrc' and '') must be adjusted to the system.

In 'bashrc', there are some changes;

# Installation location
# Compiler: set to Gcc, Gcc43, Gcc44, or Icc (for Intel's icc)
: ${WM_COMPILER:=Gcc43}; export WM_COMPILER

# Detect system type and set environment variables appropriately
# 11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)~~
export WM_ARCH=`uname -s`
case $WM_ARCH in
    # compiler specifics
    case `uname -m` in

            export WM_COMPILER_LIB_ARCH=64
            export WM_CC='/opt/sharcnet/gcc/4.3.4/bin/gcc'
            export WM_CXX='/opt/sharcnet/gcc/4.3.4/bin/g++'

In '',

# Select compiler installation
# 11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)Isaac
# compilerInstall = OpenFOAM | system 
    if [ -n "$gcc_version" ]
# Communications library
# 11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)11:05, 14 February 2011 (EST)~~
case "$WM_MPLIB" in
    export MPI_ARCH_PATH=/opt/sharcnet/openmpi/current/gcc
    # Tell OpenMPI where to find its install directory
    _foamAddPath    $MPI_ARCH_PATH/bin
    _foamAddLib     $MPI_ARCH_PATH/lib
    _foamAddMan     $MPI_ARCH_PATH/man
    export FOAM_MPI_LIBBIN=$FOAM_LIBBIN/$mpi_version
    unset mpi_version

User environment setup

The environment variable FOAM_INST_DIR can be used to find and source the appropriate resource file. Here is a bash/ksh/sh example:

    * export FOAM_INST_DIR=/data/app/OpenFOAM
    * foamDotFile=$FOAM_INST_DIR/OpenFOAM-1.7.1/etc/bashrc
    * [ -f $foamDotFile ] && . $foamDotFile

and a csh/tcsh example:

    * setenv FOAM_INST_DIR /data/app/OpenFOAM
    * foamDotFile=$FOAM_INST_DIR/OpenFOAM-1.7.1/etc/cshrc
    * if ( -f $foamDotFile ) source $foamDotFile

The value set in $FOAM_INST_DIR will be used to locate the remaining parts of the OpenFOAM installation.

Building the Sources

Go to the top-level source directory $WM_PROJECT_DIR and execute the top-level build script