Installation/Outdated/Howto compile OpenFOAM

From OpenFOAMWiki

This document describes howto compile OpenFOAM on Unix from the source code provided by the nice folks at OpenCFD.

This document also describes howto download and compile some of the tools needed for compiling OpenFOAM.

The process described in this document is based on the OpenFOAM README file, Section "4. Building from Sources (Optional)", but with more details.

The information presented here has been tested and validated by the author while compiling OpenFOAM 1.3, under SuSE 9.1 x86_64, RedHat/Centos 4 and Debian/Knoppix 5.0. Depending on your Operating System and/or your OS version, your milleage may vary...

This is work in progress; please don't hesitate to complement the information presented here.


1 Preamble

1.1 Basic stuff

This document describes the compilation and installation of OpenFOAM 1.3 in the default installation directory $HOME/OpenFOAM and $HOME/OpenFOAM/linux, as suggested in http://www.openfoam.org/download.html.


If not already available, you first need to create these directories:


For x86:

 
mkdir -p $HOME/OpenFOAM/linux


For x86_64:

 
mkdir -p $HOME/OpenFOAM/linuxAMD64


For the rest of this document, only the x86 installation procedure will be presented in detail. The specific information for the installation on x86_64 platforms will be presented only when significantly different from the x86 installation procedure.

1.2 Not so basic (but very useful) stuff

In the process of recompiling and installing OpenFOAM 1.3, you will have to modify some of the files provided by OpenCFD.

Before doing so, I highly recommend archiving the original version of the file under RCS first.

RCS stands for Revision Control System. It's a revision control system that is the ancestor of the well known CVS and Subversion revision systems. RCS comes standard with probably almost every modern flavors of Unix.

The nice thing about RCS is its simplicity, the fact that it stores the file revision archive locally, and most importantly, it's a system that will help you memorize every revisions of any given ASCII file, so you will always be able to return any modified file back to a known and valid version.

So, take the time to RTFM about RCS (eg: man rcs). It might save you some headaches later on.

1.3 Finally, a little advice

As a rule of thumb, do not install OpenFOAM as the user root on your workstation. Instead, use your own username, or simply create a new user openfoam. The super-user root is usually reserved for system administration tasks.


2 Compiling and installing GNU Gcc

2.1 The motivation for compiling GNU gcc

Compiling the GNU gcc/g++ compiler can be a daunting task for the non-initiated. Usually, the installation of the pre-compiled gcc/g++ binary package offered by OpenCFD with any new release of OpenFOAM should cover the need of most OpenFOAM developers.

As mentioned on the mailing list by Hrvoje Jasak, it is usually recommended to keep your OpenFOAM gcc/g++ compiler very up-to-date because a new gcc/g++ release usually means fewer compiler bugs and better performance; OpenFOAM will usually benefit from the newer compiler. So this is one very good reason to visit the GNU gcc compiler web site regularly, and recompile gcc/g++ from the source code.

However, another good reason for recompiling gcc/g++ is related to some compatibilities issues that can arise when deploying the OpenCFD pre-compiled gcc/g++ package on your platform.

One issue that I have encountered on a SuSE 9.1 platform with the pre-compiled gcc/g++ binary package was related to the interaction of the new g++ compiler and the system GNU linker ld. Both the gcc/g++ compiler and the ld linker are necessary when compiling applications on Unix. And of course, they both need to be compatible with one another.

To make a long story short, when configuring gcc/g++, the configure script will automagically explore the availability of the numerous runtime options of your system GNU linker ld, and compile gcc/g++ accordingly. On recent operating systems like SuSE 10, the version of system linker ld is newer, hence new runtime ld options are available, and, on that platform, gcc/g++ will be compiled to take advantage of them.

However, when the same pre-compiled gcc/g++ compiler is deployed with an older OS, your default system GNU linker ld will be older too, and there is a definite chance that the compatibility between gcc/g++ and ld will be broken. I know it did when I installed the pre-compiled gcc/g++ package from OpenFOAM 1.2 on my SuSE 9.1 workstation.

In that situation, you have 3 options:

  1. You upgrade your Operating System to a newer version.
  2. You install a newer version of ld from GNU binutils for your spanking new gcc/g++ precompiled compiler.
  3. You recompile gcc/g++ in order for the configure script to discover the runtime options available from your system linker ld.


The rest of this section describes option #3.

2.2 Selecting the right package to download

You should always download a GNU gcc/g++ source package with at least the same version, if not newer, as the version of the pre-compiled gcc/g++ compiler provided by OpenCFD, for the version of OpenFOAM you plan to use. The GNU gcc/g++ compiler source package is downloadable from the GCC GNU Web site, or from one of it's numerous mirrors.

Here is an example for OpenFOAM 1.3:

 
# create a temporary working directory
mkdir -p $HOME/OpenFOAM/linux/tmp
cd $HOME/OpenFOAM/linux/tmp
 
# download using standard ftp
ftp ftp.gnu.org
cd /gnu/gcc/gcc-4.1.0/
bin
get gcc-4.1.0.tar.bz2

2.3 Configuration et compilation of GNU gcc

 
# extraction
bzcat gcc-4.1.0.tar.bz2 | tar -xvf - 
mkdir gcc-4.1.0/gcc-4.1.0-obj
cd gcc-4.1.0/gcc-4.1.0-obj 
 
# configuration
../gcc-4.1.0/configure --prefix=$HOME/OpenFOAM/linux/gcc-4.1.0 --exec-prefix=$HOME/OpenFOAM/linux/gcc-4.1.0 \
    --enable-languages=c,c++ --enable-shared --disable-multilib
 
# compilation
make bootstrap

2.4 Installation of GNU gcc

 
#installation
make install
 
#cleanup
cd ../..
rm -rf gcc-4.1.0

3 Installing the Java JSDK

Nothing special to do here; simply download the default package from OpenCFD or SourceForge using your browser or a tool like wget, and install it under the right directory:

 
# download from a nearby SourceForge mirror
cd $HOME/OpenFOAM/linux/
wget http://umn.dl.sourceforge.net/sourceforge/foam/j2sdk1.4.2_05.linux.tgz
 
# extraction and installation
tar -zxvf j2sdk1.4.2_05.linux.tgz
 
# cleanup
rm j2sdk1.4.2_05.linux.tgz

4 Installing the OpenFOAM source code


4.1 Downloading and extracting the source code

It is now time to install the OpenFOAM source code, not because we are ready to compile it right away, but simply because we need to properly set some environment variables, and the OpenFOAM initialization scripts are exactly what is needed for such a job.

 
# download the OpenFOAM source code from OpenCFD or the closest SourceForge mirror
cd $HOME/OpenFOAM
wget http://umn.dl.sourceforge.net/sourceforge/foam/OpenFOAM-1.3.General.gtgz
 
# extract the source code
tar -zxvf OpenFOAM-1.3.General.gtgz

4.2 Modifying the file $HOME/OpenFOAM/OpenFOAM-1.3/.bashrc or $HOME/OpenFOAM/OpenFOAM-1.3/.cshrc (optional)

Next, we need to adjust some environment variables to reflect our compiler version if the version of gcc installed is newer than the default version available from OpenCFD.

This is specified in the file

$HOME/OpenFOAM/OpenFOAM-1.3/.bashrc or
$HOME/OpenFOAM/OpenFOAM-1.3/.cshrc

For example, for the file $HOME/OpenFOAM/OpenFOAM-1.3/.bashrc, we need to adjust the following line

 
# replace gcc-4.1.0 by gcc-4.xx.yy for the version 4.xx.yy of gcc
export WM_COMPILER_DIR=$WM_PROJECT_INST_DIR/$WM_ARCH/gcc-4.1.0$WM_COMPILER_ARCH

For the file $HOME/OpenFOAM/OpenFOAM-1.3/.cshrc, we need to adjust the following line

 
# replace gcc-4.1.0 by gcc-4.xx.yy for the version 4.xx.yy of gcc
setenv WM_COMPILER_DIR $WM_PROJECT_INST_DIR/$WM_ARCH/gcc-4.1.0$WM_COMPILER_ARCH

4.3 Modifying the file $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/bashrc or $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/cshrc (optional)

Next, we need to specify if we want to compile and use OpenFOAM on a AMD64 system, or if we want our root directory for OpenFOAM under a different directory than $HOME/OpenFOAM.

For this, we need to modify the file

$HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/bashrc or
$HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/cshrc

For example, for the file $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/bashrc, we may want to adjust or add the following lines

 
# uncomment the following line on a AMD64 workstation 
#export WM_64=1
 
# uncomment the following line if your OpenFOAM root directory in under /opt	
#export WM_PROJECT_INST_DIR=/opt/$WM_PROJECT

For the file $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/cshrc, we may want to adjust or add the following lines

 
# uncomment the following line on a AMD64 workstation 
#setenv WM_64 1
 
# uncomment the following line if your OpenFOAM root directory in under /opt	
#setenv WM_PROJECT_INST_DIR /opt/$WM_PROJECT

4.4 Initializing the OpenFOAM environment variables

We can now initialize all the required environment variables and aliases for properly compiling and running OpenFOAM.

If your current shell is bash

 
. $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/bashrc

If your current shell is csh or a csh look-alike like tcsh

 
source $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/cshrc

5 Compiling and installing cmake


Cmake is a cross-platform, open-source make system.

You need cmake for compiling ParaView.

Even though cmake is not supplied by OpenCFD as a companion tool for OpenFOAM, I find it useful to install cmake under the $HOME/OpenFOAM/linux directory, close to ParaView.

Here is the procedure for downloading, compiling and installing cmake:

 
# download the latest cmake source package from Kitware's ftp site:
mkdir $HOME/OpenFOAM/linux/tmp
cd $HOME/OpenFOAM/linux/tmp
 
ftp public.kitware.com
cd pub/cmake/v2.3
bin
get cmake-2.3.4-20060317.tar.gz
 
# extract the source code
tar -zxvf ./cmake-2.3.4-20060317.tar.gz
 
# configure cmake
cd cmake-2.3.4-20060317
./configure --prefix=$HOME/OpenFOAM/linux/cmake-2.3.4-20060317
make
make install
 
# cleanup
cd ../..
rm -rf ./tmp

Next, you need to modify the file xxx or yyy in order to adjust OpenFOAM environment variable CMAKE_HOME correctly.

Here is how to modify the file xxx.

 
[add stuff]

Here is how to modify the file yyy.

 
[add stuff]

And of course, don't forget to reinitialize your environment:

If your current shell is bash

 
. $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/bashrc

If your current shell is csh or a csh look-alike like tcsh

 
source $HOME/OpenFOAM/OpenFOAM-1.3/.OpenFOAM-1.3/cshrc

6 Compiling and installing ParaView


ParaView is probably the trickiest package to recompile.
[add stuff]

7 Partial installation of GNU binutils (optional)


You need to do a partial installation of binutils on some platforms because of the absence of the very important include header /usr/include/demangle.h. [add stuff]

8 Miscellaneous adjustments (optional)


Gmake is absent on Knoppix 5.0. Need to create a symlink in /usr/local/bin. [add stuff]

9 Compiling OpenFOAM

Now the easy stuff... Allwmake
[add stuff]


Valid versions: OF version 13.png

--MB 05:16, 10 Apr 2006 (CEST)