Difference between revisions of "Installation/Outdated/Howto compile OpenFOAM"

From OpenFOAMWiki
m (Adjusting the configuration)
Line 418: Line 418:
  
 
</bash>
 
</bash>
 +
 +
For compiling ParaView for x86_64, we need to modify some other configuration variables. Here are the variables I had to modify for SuSE 9.1 x86_64. Adjust accrodingly to your own specific 64-bit Operating System.
 +
 +
<bash>
 +
BUILD_SHARED_LIBS: ON
 +
CMAKE_BUILD_TYPE :
 +
CMAKE_CXX_COMPILER : /home/your_login_name/OpenFOAM/linuxAMD64/gcc-4.1.0/bin/g++
 +
CMAKE_CXX_FLAGS : -m64
 +
CMAKE_C_COMPILER : /home/your_login_name/OpenFOAM/linuxAMD64/gcc-4.1.0/bin/gcc
 +
CMAKE_C_FLAGS : -m64
 +
CMAKE_EXE_LINKER_FLAGS : -m64
 +
CMAKE_EXE_LINKER_FLAGS_RELEASE : -m64
 +
CCMAKE_MODULE_LINKER_FLAGS : -m64
 +
CMAKE_INSTALL_PREFIX : /home/your_login_name/OpenFOAM/linuxAMD64/paraview-2.4.3
 +
CMAKE_MODULE_LINKER_FLAGS : -m64
 +
CMAKE_MODULE_LINKER_FLAGS_RELEASE : -m64
 +
CMAKE_SHARED_LINKER_FLAGS : -m64
 +
CMAKE_SHARED_LINKER_FLAGS_RELEASE : -m64
 +
OPENGL_gl_LIBRARY : /usr/lib64/libGL.so
 +
OPENGL_glu_LIBRARY: /usr/X11R6/lib64/libGLU.a
 +
X11_X11_LIB : /usr/X11R6/lib64/libX11.so
 +
X11_Xext_LIB : /usr/X11R6/lib64/libXext.so
 +
CMAKE_X_LIBS : /usr/X11R6/lib64/libX11.so;/usr/X11R6/lib64/libXext.so;/usr/X11R6/lib64/libX11.so;/usr/X11R6/lib64/libXext.so
 +
X11_Xext_LIB: /usr/X11R6/lib64/libXext.so
 +
</bash>
 +
 +
''Note: my recompiled 64 bit version of paraView 2.4.3 is crashing under SuSE 9.1. I had no such problem with paraview 2.x.y (OpenFOAM 1.2). As soon as I find the source of the problem, I will document it here...''
  
 
=== Compiling and installing paraview ===
 
=== Compiling and installing paraview ===

Revision as of 06:44, 17 April 2006

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
make
make install
 
# cleanup
cd ../..
rm -rf ./tmp

Next, you need to modify the file $HOME/OpenFOAM/OpenFOAM-1.3/.bashrc or $HOME/OpenFOAM/OpenFOAM-1.3/.cshrc in order to add cmake to your $PATH environment variable. I usually insert those modifications at the end of the files.

Here is how to modify the file $HOME/OpenFOAM/OpenFOAM-1.3/.bashrc.

 
#
# cmake
#
# Make sure cmake is accessible
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export CMAKE=cmake-2.3.4
export CMAKE_ARCH_PATH=$WM_PROJECT_INST_DIR/$WM_ARCH/$CMAKE
AddPath $CMAKE_ARCH_PATH/bin

Here is how to modify the file $HOME/OpenFOAM/OpenFOAM-1.3/.cshrc.

 
#
# cmake
#
# Make sure cmake is accessible
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setenv CMAKE cmake-2.3.4
setenv CMAKE_ARCH_PATH $WM_PROJECT_INST_DIR/$WM_ARCH/$CMAKE
AddPath $CMAKE_ARCH_PATH/bin

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. Here is how.

6.1 Selecting the right version of ParaView

You first need to download the source code from Kitware's Web site.

But before doing so, please note the version number of the binary ParaView package provided by OpenCFD. You need to download the ParaView source package with the same version number, or very close to it if you like living on the bleeding edge. Otherwise, if your version is too different, you risk not being able to link in the modules needed for paraFoam.

For example, for OpenFOAM 1.3, OpenCFD ParaView binary package version is paraview-2.4.2; you should then download the same version for the source package from Kitware's Web site.

Note however that ParaView latest stable version is 2.4.3; since the version number is very close to 2.4.2, I have chosen to use this version instead.

6.2 Downloading and installing ParaView source code

 
cd $HOME/OpenFOAM/linux
wget http://www.paraview.org/files/v2.4/paraview-2.4.3.tar.gz
 
tar -zxvf ./paraview-2.4.3.tar.gz
mkdir -p paraview-2.4.3/lib/paraview-2.4

6.3 Patching Tcl/TK (optional)

Next, you may need to correct a bug that is not yet corrected in the companion Tcl/Tk source package that comes with ParaView.

That bug is documented on the Tcl/Tk mailing list, and is only affecting people running bash version 3.1 or later. I have stumbled on that bug when compiling OpenFOAM 1.3 under Knoppix 5.0.

For more information, please check out the following link

The correction is rather simple, there are two typos in the files paraview-2.4.3/Utilities/TclTk/tcl8.4.5/unix/tcl.m4 and paraview-2.4.3/Utilities/TclTk/tk8.4.5/unix/tcl.m4.

Here is the first correction (the old code is commented out):

 
# starting on line 776 for both files:
 
# Bug fix: Remove the extra single quote close to .relid
#	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
#		system=MP-RAS-`awk '{print $3}' /etc/.relid'`
#	    fi
 
	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
		system=MP-RAS-`awk '{print $3}' /etc/.relid`
	    fi
 

The second correction is identical, only the line numbers are different:

 
# starting on line 2107 for the file paraview-2.4.3/Utilities/TclTk/tk8.4.5/unix/tcl.m4:
# starting on line 2117 for the file paraview-2.4.3/Utilities/TclTk/tcl8.4.5/unix/tcl.m4:
 
# Bug fix: Remove the extra single quote close to .relid
#	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
#		system=MP-RAS-`awk '{print $3}' /etc/.relid'`
#	    fi
 
	    if test -r /etc/.relid -a "X`uname -n`" = "X`uname -s`" ; then
		system=MP-RAS-`awk '{print $3}' /etc/.relid`
	    fi
 


Next, you need to regenerate the Automake files. The command autoreconf is part of the Automake package. You need this package for recompiling ParaView.

 
cd $HOME/OpenFOAM/linux/paraview-2.4.3/Utilities/TclTk/tcl8.4.5/unix
autoreconf
 
cd $HOME/OpenFOAM/linux/paraview-2.4.3/Utilities/TclTk/tk8.4.5/unix
 
#This invocation of autoreconf will end with some error message about AC_LIBOBJ. 
#You can ignore this error message.
autoreconf

6.4 Modification to the file CMakeLists.txt

Next, we need to modify the file $HOME/OpenFOAM/linux/paraview-2.4.3/CMakeLists.txt in order to force the installation of the ParaView header files when we will invoke the commande make install a little bit later.

Here are the lines we need to modify; watch for the comments starting with OpenFOAM: ...:

 
# Setup install directories.
IF(NOT PV_INSTALL_BIN_DIR)
  SET(PV_INSTALL_BIN_DIR ${PV_INSTALL_ROOT}/bin)
ENDIF(NOT PV_INSTALL_BIN_DIR)
IF(NOT PV_INSTALL_INCLUDE_DIR)
#
# OpenFOAM: we need to modify this line
#  SET(PV_INSTALL_INCLUDE_DIR ${PV_INSTALL_ROOT}/include/paraview-${PARAVIEW_VERSION})
  SET(PV_INSTALL_INCLUDE_DIR ${PV_INSTALL_ROOT}/include)
#
# OpenFOAM: end of modification
#
ENDIF(NOT PV_INSTALL_INCLUDE_DIR)
IF(NOT PV_INSTALL_LIB_DIR)
  SET(PV_INSTALL_LIB_DIR ${PV_INSTALL_ROOT}/lib/paraview-${PARAVIEW_VERSION})
ENDIF(NOT PV_INSTALL_LIB_DIR)
IF(NOT PV_INSTALL_DATA_DIR)
  SET(PV_INSTALL_DATA_DIR ${PV_INSTALL_ROOT}/share/paraview-${PARAVIEW_VERSION})
ENDIF(NOT PV_INSTALL_DATA_DIR)
 
# Install no development files by default, but allow the user to get
# them installed by setting PV_INSTALL_DEVELOPMENT to true.  Disable
# the option altogether if PV_INSTALL_NO_DEVELOPMENT is already set to
# true.
#
# OpenFOAM: we need to add this line.
#
SET(PV_INSTALL_DEVELOPMENT 1)
#
# OpenFOAM: end of modification
#
IF(NOT PV_INSTALL_NO_DEVELOPMENT)
  # Leave this option out until we write code to install paraview headers
  # other than VTK.
  #OPTION(PV_INSTALL_DEVELOPMENT "Install ParaView plugin development files."
  #  OFF)
  #MARK_AS_ADVANCED(PV_INSTALL_DEVELOPMENT)

6.5 Initial configuration using cmake

Next, we use the default invocation of cmake to get the initial configuration of Paraview

 
cd $HOME/OpenFOAM/linux/paraview-2.4.3/lib/paraview-2.4
cmake ../..

6.6 Adjusting the configuration

Next, we need to adjust the initial ParaView configuration in order to get the proper settings for compiling with OpenFOAM.

For this, you need to edit the file $HOME/OpenFOAM/linux/paraview-2.4.3/lib/paraview-2.4/CMakeCache.txt using your favorite text editor. That file was automagically created by the prior invocation of cmake.

Here are the lines and configuration variables that need to be modified. The default values previously generated by cmake are commented out.

 
# BUILD_SHARED_LIBS:BOOL=OFF
BUILD_SHARED_LIBS:BOOL=ON
 
# BUILD_TESTING:BOOL=ON
BUILD_TESTING:BOOL=OFF
 
# CMAKE_INSTALL_PREFIX:PATH=/usr/local
CMAKE_INSTALL_PREFIX:PATH=/home/whatever_your_login_is/OpenFOAM/linux/paraview-2.4.3
 

For compiling ParaView for x86_64, we need to modify some other configuration variables. Here are the variables I had to modify for SuSE 9.1 x86_64. Adjust accrodingly to your own specific 64-bit Operating System.

 
BUILD_SHARED_LIBS: ON
CMAKE_BUILD_TYPE : 
CMAKE_CXX_COMPILER : /home/your_login_name/OpenFOAM/linuxAMD64/gcc-4.1.0/bin/g++
CMAKE_CXX_FLAGS : -m64
CMAKE_C_COMPILER : /home/your_login_name/OpenFOAM/linuxAMD64/gcc-4.1.0/bin/gcc
CMAKE_C_FLAGS : -m64
CMAKE_EXE_LINKER_FLAGS : -m64
CMAKE_EXE_LINKER_FLAGS_RELEASE : -m64
CCMAKE_MODULE_LINKER_FLAGS : -m64
CMAKE_INSTALL_PREFIX : /home/your_login_name/OpenFOAM/linuxAMD64/paraview-2.4.3
CMAKE_MODULE_LINKER_FLAGS : -m64
CMAKE_MODULE_LINKER_FLAGS_RELEASE : -m64
CMAKE_SHARED_LINKER_FLAGS : -m64
CMAKE_SHARED_LINKER_FLAGS_RELEASE : -m64
OPENGL_gl_LIBRARY : /usr/lib64/libGL.so
OPENGL_glu_LIBRARY: /usr/X11R6/lib64/libGLU.a
X11_X11_LIB : /usr/X11R6/lib64/libX11.so
X11_Xext_LIB : /usr/X11R6/lib64/libXext.so 
CMAKE_X_LIBS : /usr/X11R6/lib64/libX11.so;/usr/X11R6/lib64/libXext.so;/usr/X11R6/lib64/libX11.so;/usr/X11R6/lib64/libXext.so
X11_Xext_LIB: /usr/X11R6/lib64/libXext.so

Note: my recompiled 64 bit version of paraView 2.4.3 is crashing under SuSE 9.1. I had no such problem with paraview 2.x.y (OpenFOAM 1.2). As soon as I find the source of the problem, I will document it here...

6.7 Compiling and installing paraview

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)