OpenFOAM and FOAM-extend on Your Own Laptop

Table of Contents

Basic information. 1

Installation and updating of Ubuntu 14.04 LTS in Virtual Box (under Windows 7, in this case): 1

Install OpenFOAM-2.4.x. 3

Install OpenFOAM-2.4.x Debug version (after the above, i.e. with OpenFOAM-2.4.x installed) 4

Install Emacs, ddd, Python, Numpy, SciPy, Matplotlib, Gnuplot, PyFoam.. 5

Install FOAM-extend-3.1 (including PyFoam, swak4Foam etc.) 6

 

Basic information

The teaching is designed so that you should follow the steps I do on a computer. It is highly recommended that you install the software on your own laptop so that you are independent. The Linux commands below are written for bash shell.

By following the instructions below, you should be able to install Ubuntu 14.04 LTS, OpenFOAM-2.4.x (one optimal and one debug version), FOAM-extend-3.1, PyFoam, Python packages, Gnuplot etc., and later perhaps some additional useful things that we will use in the course. We will pull the git source and compile from scratch, since we will then get access to updates and bug fixes. OpenFOAM-2.4.0 can also be installed as a package, which is much faster, but gives less control in my opinion (http://openfoam.com/download/ubuntu.php). Feel free to try it out if you like – you can have both that version and the git versions installed at the same time!

Note that I am (unfortunately) using Word to generate this web page, which means that Word sometimes decides to change some characters to other characters that look the same, but aren’t (e.g. – is not the same as - or -- and “ is not the same as "). I think that I have fixed this everywhere, but you never know. That is one reason for copy-pasting single rows rather than multiple rows, and check that all went well. Another reason is that some lines will require you to press a key at some point, such as the “sudo apt-get” lines. Let me know if you run into problems, and I’ll help you.

Installation and updating of Ubuntu 14.04 LTS in Virtual Box (under Windows 7, in this case):

This section takes about 1.5 hour to complete.

Download Ubuntu 14.04 LTS (note that you can get it for free by setting your contribution to zero):
http://www.ubuntu.com/download, get Ubuntu Desktop (in my case 64 bit), save iso-file
(Optional: burn iso to CD (if you do, make sure to burn it as iso, to make the CD bootable!))

You can use VirtualBox to install Linux and OpenFOAM in your current OS. It is recommended to use the official version downloadable from the Sun web page, https://www.virtualbox.org/wiki/Downloads. If you are installing VirtualBox in Ubuntu the version that is installed through the package manager does not support all options (e.g. the USB controllers), since that version omits some proprietary software. If you already have Virtualbox OSE installed from the Ubuntu repositories, uninstall it before installing the .deb file from Oracle’s website. See also: http://openfoam.com/resources/windows.php.

After installing VirtualBox, start it and:
Create new virtual disk:
Click on New
Name: Ubuntu 14.04 LTS
Operating System: Linux
Version: Ubuntu (in my case: “(64 bit)”)
Base memory: 2048MB (25% of total on the machine in my case, minimum 2GB required for 64-bit operating system)
Create a virtual hard drive now
VDI
Fixed size, 30GB (2GB is enough to just test one OpenFOAM installation)
Settings can be changed later, using "settings"
Click on Create

Install Ubuntu on the virtual disk:
Double-click on the virtual disk you just created
In the pop-up window, click on the icon “Choose a virtual optical disk file”, and browse to the downloaded Ubuntu iso-file
Ubuntu should initialize in a window named “Ubuntu 14.04 LTS [Running] – Oracle VM VirtualBox”.
At the top of the window there may be some information about “Auto capture keyboard” and “mouse pointer integration”. Just click the x to hide the comments.
Click on Install Ubuntu and choose your specific settings
I recommend that you tick: Download updates while installing, and Install this third-party software
When it asks you if it should erase the whole disk, it refers to the virtual disk you have just created in VirtualBox, and not your Windows disk. NOTE: MAKE SURE THAT THE INSTALLATION PROCESS HAPPENS IN A SEPARATE WINDOW, AS DESCRIBED ABOVE! YOU SHOULD BE ABLE TO READ THAT “This computer currently has no detected operating systems. What would you like to do?”. If it says that you already have an operating system, you are probably trying to install Ubuntu directly on your computer and not through VirtualBox. If so, make sure that you do it through VirtualBox – otherwise you may risk to delete your old operating system.
Restart when asked (just click on the button that pops up). You may need to press Enter at some point.
To the left of your Ubuntu window, there should be an icon which says ‘Search your computer and online resources’ when you move the pointer over it. Use it to search for Software Updater, and use the Software Updater to install recent updates to your Ubuntu installation. Restart again (just click on buttons).

I had some problems that the desktop did not resize. This was solved by clicking on “Devices/Insert Guest Addition CD image”, and restarting the virtual machine.
Occasionally, the Guest Addition may not be possible to mount and you get a pop-up window asking you if you want to force unmounts. This may not work. In Ubuntu, Open the Disks utility (click on “Search your computer and online sources”, in the left bar of Ubuntu, and enter “disks”), Under CD/DVD: mount the Guest Addition and then eject it. After that it should be possible to Insert it again, as explained above.
It is also convenient to be able to cut-and-paste between windows and Ubuntu: At the top of the VirtualBox window, do Devices/Shared Clipboard/Bidirectional
There is a risk that the terminal windows will time-out during ssh to some other computer. To avoid this behavior, you can do the following (you need to give your root password):
sudo echo "ServerAliveInterval 60" >> /etc/ssh/ssh_config

Install OpenFOAM-2.4.x

This section takes about 6 hours to complete

Straight-forward according to http://www.openfoam.org/download/git.php (for 2.4.x, later in http://www.openfoam.org/archive/2.4.0/download/)
See also: http://openfoamwiki.net/index.php/Installation/Linux/OpenFOAM-2.4.0/Ubuntu

Open a terminal window:
CTRL-ALT-T
type (copy-paste from homepage, line-by-line):
mkdir $HOME/OpenFOAM
cd $HOME/OpenFOAM

sudo su - #Makes you root user, so that you can run apt-get directly and without entering password
apt-get install git-core  #You may have to type Y at some point(s) when doing these commands
apt-get install build-essential flex bison cmake zlib1g-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev

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

apt-get install libscotch-dev libcgal-dev

exit #Stop being root user
git clone git://github.com/OpenFOAM/OpenFOAM-2.4.x.git

wget http://downloads.sourceforge.net/project/foam/foam/2.4.0/ThirdParty-2.4.0.tgz

You may have to press Enter here, to get the prompt back.
tar xzf ThirdParty-2.4.0.tgz
rm ThirdParty-2.4.0.tgz
mv ThirdParty-2.4.0 ThirdParty-2.4.x
echo "alias OF24x='. $HOME/OpenFOAM/OpenFOAM-2.4.x/etc/bashrc'" >> $HOME/.bashrc

Some checks, before proceeding:

gcc --version #Gives 4.8.4. Required: 4.5.0. Ok!
flex --version #Gives 2.5.35. Seems to have worked ok!

Close the terminal window, open a new one:
CTRL-ALT-T
and continue:
OF24x
foam
The following line takes about 3h. You can do CTRL-C and continue later, by starting again from where you opened a new terminal window above
./Allwmake
./Allwmake>& log_Allwmake
#Second time is fast, just to easier check the log file for possible errors (search for “rror”) - in my case none.
rm log_Allwmake

Compile ParaView-4.1.0 (takes 2.5h):
qmake --version #Gives Qt version 4.8.6. Required: 4.7.2 or newer. Ok!
cmake --version
#Gives 2.8.12.2. Required: 2.8.8 or newer. Ok!
cd $WM_THIRD_PARTY_DIR
./makeParaView4 #This is what takes 2.5h
cd $FOAM_UTILITIES/postProcessing/graphics/PV4Readers
wmSET
./Allwclean
./Allwmake

Test the installation:
CTRL-ALT_T #To open an new terminal window
OF24x
mkdir -p $FOAM_RUN
run
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam

Install OpenFOAM-2.4.x Debug version (after the above, i.e. with OpenFOAM-2.4.x installed)

This section takes about 4h to complete.

Compile Debug version, without recompiling ThirdParty:
echo "alias OF24xDebug='. $HOME/OpenFOAM/OpenFOAM-2.4.x/etc/bashrc WM_COMPILE_OPTION=Debug'" >> $HOME/.bashrc
Open new terminal window
CTRL-ALT_T
OF24xDebug
cd $WM_THIRD_PARTY_DIR/platforms
ln -s linux64GccDPOpt linux64GccDPDebug
foam

./Allwmake #This takes 4 hours
./Allwmake>& log_Allwmake
#Second time is fast, just to easier check the log file for possible errors (search for “rror”) - in my case none.
rm log_Allwmake
cd $FOAM_UTILITIES/postProcessing/graphics/PV4Readers
Don’t do wmSET since it will not pick Debug version – see alias wmSET! Instead:
OF24xDebug
./Allwclean
./Allwmake

Test the installation:
CTRL-ALT_T #To open an new terminal window
OF24xDebug
mkdir -p $FOAM_RUN
run
rm -r cavity
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam

Install Emacs, ddd, Python, Numpy, SciPy, Matplotlib, Gnuplot, PyFoam

This takes 10min to complete.

 

We will do debugging with gdb and Emacs. Emacs needs to be installed:

sudo apt-get install emacs24

You can also try ddd for debugging (not available at Chalmers):
sudo apt-get install ddd
Python-related packages
sudo apt-get install python python-dev python-matplotlib python-numpy python-scipy

Gnuplot

sudo apt-get install gnuplot

xmgrace

sudo apt-get install grace

 

For OpenFOAM-2.4.x, the PyFoam package is not included (which it is for FOAM-extend).

We will follow the installation instructions for PyFoam at http://openfoamwiki.net/index.php/Contrib_PyFoam

There was a problem installing version 0.6.5, so I switched back one version.

Condensed installation instructions:

mkdir $HOME/OpenFOAM/linuxSrc

cd $HOME/OpenFOAM/linuxSrc

wget http://openfoamwiki.net/images/3/3b/PyFoam-0.6.4.tar.gz

tar xzf PyFoam-0.6.4.tar.gz

rm PyFoam-0.6.4.tar.gz

cd PyFoam-0.6.4

Install as regular user (recommended):

python setup.py install --prefix=$HOME/OpenFOAM/PyFoam-0.6.4

echo "alias PF064='export PYTHONPATH=\$HOME/OpenFOAM/PyFoam/PyFoam-0.6.4/lib/python2.7/site-packages:\$PYTHONPATH; export PATH=\$HOME/OpenFOAM/PyFoam-0.6.4/bin:\$PATH'" >> $HOME/.bashrc

Open a new window and type (<TAB> refers to the tab key):

PF064

pyFoam<TAB><TAB>

 

You will see numerous pyFoam commands that can be used to help you use OpenFOAM efficiently.

 

You should also consider installing swak4foam: http://openfoamwiki.net/index.php/Contrib/swak4FoamA library that combines the functionality of groovyBC and funkySetFields: it offers the user the possibility to specify expressions involving the fields and evaluates them. This library offers a number of utilities (for instance funkySetFields to set fields using expression), boundary conditions (groovyBC to specify arbitrary boundary conditions based on expressions) and function objects that allow doing many things that would otherwise require programming.”

Install FOAM-extend-3.1 (including PyFoam, swak4Foam etc.)

The foam-extend (foam-extend.org) fork has some features that are not in OpenFOAM-x.x.x, such as the GGI interface. If you do not need those features, you do not have to follow this section.

 

This section takes about 5h or more – leave the computer over-night (where this message is repeated).

 

For other installation instructions, see also:

·         http://sourceforge.net/p/openfoam-extend/wiki/Home/

·         http://openfoamwiki.net/index.php/Installation/Linux/foam-extend-3.1

·         And later the file $WM_PROJECT_DIR/doc/buildInstructions/Ubuntu/Ubuntu_14.04, also located here:
https://sourceforge.net/p/openfoam-extend/foam-extend-3.1/ci/master/tree/doc/buildInstructions/Ubuntu/Ubuntu_14.04

 

The compilation procedure is actually very simple, but I modify it slightly to use more system installations. I have included some information that is commented, if anyone would like to do other modifications.

 

Open new terminal window and type (line-by-line, since you have to type your password on the “sudo” lines)

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install git-core build-essential binutils-dev flex zlib1g-dev qt4-dev-tools libqt4-dev
sudo apt-get install libncurses5-dev libiberty-dev libxt-dev rpm mercurial graphviz openmpi-bin libopenmpi-dev cmake

 

mkdir $HOME/foam
cd $HOME/foam

git clone git://git.code.sf.net/p/openfoam-extend/foam-extend-3.1 foam-extend-3.1

cd foam-extend-3.1

 

This part is where I do some changes to the installation procedure, to use more system installed software in Ubuntu 14.04. You can skip this if you like. But then you will not have Paraview compiled, and you will waste some disk space on software that may be installed in the system. Instead of compiling Paraview, you can also install it with “sudo apt-get paraview”, but then you don’t get the foam-extend-specific reader.

  ####################################################################

  #

  # Create a prefs.sh file

  cp etc/prefs.sh-EXAMPLE etc/prefs.sh

  # Make the sourcing less chatty

  sed -i s/"FOAM_VERBOSE=1"/"FOAM_VERBOSE="/g etc/prefs.sh

  # Use openmpi 1.6.5 as supplied by Ubuntu 14.04

  sed -i s/"#export WM_MPLIB=SYSTEMOPENMPI"/"export WM_MPLIB=SYSTEMOPENMPI"/g etc/prefs.sh

  sed -i s/"#export OPENMPI_DIR=path_to_system_installed_openmpi"/"export OPENMPI_DIR=\/usr"/g etc/prefs.sh

  sed -i s/"#export OPENMPI_BIN_DIR=\$OPENMPI_DIR\/bin"/"export OPENMPI_BIN_DIR=\$OPENMPI_DIR\/bin"/g etc/prefs.sh

  # Use Qt 4.8.6 as provided by Ubuntu 14.04 (instead of 4.8.5, in ThirdParty)

  sed -i s/"#export QT_DIR=path_to_system_installed_qt"/"export QT_DIR=\/usr"/g etc/prefs.sh

  sed -i s/"#export QT_BIN_DIR=\$QT_DIR\/bin"/"export QT_BIN_DIR=\$QT_DIR\/bin"/g etc/prefs.sh

  # Use cmake 2.8.12.2 as provided by Ubuntu 14.04 (instead of 2.8.12, in ThirdParty)

  sed -i s/"( rpm_make -p cmake"/"#( rpm_make -p cmake"/g ThirdParty/AllMake.stage1

  # Compile and install bison-2.7 from the ThirdParty packages.

  sed -i 0,/"#( rpm_make -p bison-2.7"/s//"( rpm_make -p bison-2.7"/ ThirdParty/AllMake.stage1

  #

  ####################################################################

  See the etc/prefs-sh-EXAMPLE file for more examples, e.g.:

  #Tell the compiler to use the number of cores you have available (if you uncomment the line and change the number 4 to what you have)
  #echo "export WM_NCOMPPROCS=4" >> etc/prefs.sh
  #Use the system installation of paraview (if you uncomment the following lines and make sure that you have Paraview installed in your system)
  #sed -i s/"#export PARAVIEW_SYSTEM=1"/"export PARAVIEW_SYSTEM=1"/g etc/prefs.sh
  #sed -i s/"#export PARAVIEW_DIR=path_to_system_installed_paraview"/"export PARAVIEW_DIR=\/usr "/g etc/prefs.sh
  #sed -i s/"#export PARAVIEW_BIN_DIR=\$PARAVIEW_DIR\/bin"/"export PARAVIEW_BIN_DIR=\$PARAVIEW_DIR\/bin"/g etc/prefs.sh
  #sed -i -e 's=\.OpenFOAM=\.foam=' bin/paraFoam

  ####################################################################

 

Set up the foam-extend-3.1 environment:
echo "alias f31='. \$HOME/foam/foam-extend-3.1/etc/bashrc'" >> $HOME/.bashrc

Close the terminal window and open a new one (doing: CTRL-ALT_T) and type:
f31

 

Compile (this takes 5h or more – leave the computer over-night):

foam

./Allwmake.firstInstall #Wait 5h!

Again, to make sure that all went well (takes some minutes):

./Allwmake.firstInstall >& log&

Look for errors in the log file. There should be none.

It should say "up to date" on each application/library

 

Test the installation:
CTRL-ALT_T #To open an new terminal window
f31
mkdir -p $FOAM_RUN
run
cp
-r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam

When running paraFoam you may get some messages in the terminal window and in a pop-up-window. Just move that pop-up-window out of sight and ignore the messages.