OpenFOAM and FOAM-extend on Your Own Laptop
Table of Contents
Installation and updating of Ubuntu
16.04 LTS in Virtual Box (under Windows 7, in this case):
Install OpenFOAM-3.0.x Debug version
(after the above, i.e. with OpenFOAM-3.0.x installed)
Install Emacs, ddd, Python, Numpy,
SciPy, Matplotlib, Gnuplot, PyFoam
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 16.04 LTS,
OpenFOAM-3.0.x (one optimal and one debug version), FOAM-extend-3.2 (branch nextRelease), 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-3.0.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!
Lines with grey background
should be copy-pasted to a terminal window. 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.
Note: It should now also be
possible to bash on Ubuntu on Windows 10. I didn’t try, but you can have a look
here:
https://insights.ubuntu.com/2016/04/14/howto-ubuntu-on-windows-2/
It seems like this will only give you a bash shell however, so it is mostly
useful to play with Linux commands in a bash shell.
This
section takes about 1.5 hour to complete.
Download Ubuntu 16.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 and remember where you saved it.
You can use VirtualBox to install Linux and OpenFOAM
while keeping 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.
Note for anyone who already
has VirtualBox installed: Check if there is a new
version available. If so, close down VirtualBox, download
and install the new version. Unmount and re-insert the GuestAdditions
(see below). I had to upgrade to make re-sizing of the window and clip-board
sharing work (again).
After installing VirtualBox, start it and:
Create new virtual disk:
Click on New
Name: Ubuntu 16.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
Dynamically allocated (I have previously set a fixed disk space of 30GB, but
let’s try dynamic now)
Set a limit on hard drive storage to 50GB
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 16.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
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’ 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”, clicking o run, waiting until finished, 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 after the first line):
sudo –i
echo "ServerAliveInterval 60" >> /etc/ssh/ssh_config
exit
This
section takes about 6 hours to complete
Straight-forward according
to http://www.openfoam.org/download/git.php
(for 3.0.1, later in http://www.openfoam.org/archive/3.0.1/download/)
See also: http://openfoamwiki.net/index.php/Installation/Linux/OpenFOAM-3.0.1/Ubuntu
Open a
terminal window and press CTRL-ALT-T to open a new terminal window.
Type (copy-paste lines with grey background to terminal window, line-by-line):
mkdir $HOME/OpenFOAM
cd $HOME/OpenFOAM
sudo -i #Type root password. 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.
Note that now follows three lines starting with “apt-get”. The lines may be
long.
apt-get
install build-essential flex bison git-core cmake
zlib1g-dev libboost-system-dev libboost-thread-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 libptscotch-dev libcgal-dev
exit #Stop being root user
git
clone git://github.com/OpenFOAM/OpenFOAM-3.0.x.git
git clone git://github.com/OpenFOAM/ThirdParty-3.0.x.git
You may have to press Enter here, to get the prompt back.
Note that the following is a single line.
echo "alias OF30x='. $HOME/OpenFOAM/OpenFOAM-3.0.x/etc/bashrc'" >>
$HOME/.bashrc
Some
checks, before proceeding:
gcc --version #Gives
5.3.1. Required: 4.5.0. Ok!
flex --version
#Gives 2.6.0. Seems to have worked ok!
Close the terminal window,
open a new one by pressing CTRL-ALT-T and continue:
OF30x
Compile ParaView-4.4.0
(takes 2.5h):
(I guess that ParaView is compiled before OpenFOAM so that the readers will compile directly. It
makes sense to make sure that all ThirdParty software
is installed before OpenFOAM. I compiled everything
at once, so I had to fix the reader compilation, see below)
qmake --version #Gives Qt version 4.8.7. Required: ?.?.? or newer. Ok!
cmake --version #Gives 3.5.1. Required: ?.?.?
or newer. Ok!
cd $WM_THIRD_PARTY_DIR
Some of the following 6
lines are long.
The lines start with “wget”, “tar”, “mv”, “sed”, “wget”, “./makeParaView”
wget http://www.paraview.org/files/v${ParaView_MAJOR}/ParaView-v${ParaView_VERSION}-source.tar.gz
tar xzf
ParaView-v${ParaView_VERSION}-source.tar.gz
mv ParaView-v${ParaView_VERSION}-source
ParaView-${ParaView_VERSION}
sed -i '/if(PARAVIEW_INSTALL/,/endif()/d'
ParaView-${ParaView_VERSION}/Qt/Components/CMakeLists.txt
wget
https://raw.githubusercontent.com/Kitware/VTK/40937e934308e5009e80769dc0c451ee4f157749/IO/Geometry/vtkSTLReader.cxx
-O ParaView-4.4.0/VTK/IO/Geometry/vtkSTLReader.cxx
./makeParaView4 #This is what takes 2.5h
Compile OpenFOAM-3.0.x:
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 -j
./Allwmake -j >& log_Allwmake
#Second time is fast, just to easier check the log file for possible errors
(search for “rror”) - in my case I had an error
related to the paraFoam reader, which is fixed next.
rm log_Allwmake
Fix error with paraFoam (may not be needed if ParaView
is compiled first, but it does not hurt to do the following):
cd $FOAM_UTILITIES/postProcessing/graphics/PV4Readers
wmSET
./Allwclean
./Allwmake
Test the installation:
Press CTRL-ALT-T to open an new terminal window
OF30x
mkdir -p $FOAM_RUN
run
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam
This
section takes about 4h to complete.
Compile Debug version,
without recompiling ThirdParty:
Note that the following is a single line.
echo "alias
OF30xDebug='. $HOME/OpenFOAM/OpenFOAM-3.0.x/etc/bashrc
WM_COMPILE_OPTION=Debug'" >> $HOME/.bashrc
Open new terminal window by pressing CTRL-ALT-T
OF30xDebug
cd $WM_THIRD_PARTY_DIR/platforms
ln -s linux64GccDPOpt linux64GccDPDebug
foam
./Allwmake
-j #This takes 4 hours
./Allwmake -j >& 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
I did not have to do the following, but it doesn’t hurt to do it:
cd $FOAM_UTILITIES/postProcessing/graphics/PV4Readers
Don’t do wmSET since it will not pick Debug
version – see alias wmSET! Instead:
OF30xDebug
./Allwclean
./Allwmake
Test the installation:
Press CTRL-ALT-T to open an new terminal window
OF30xDebug
mkdir -p $FOAM_RUN
run
rm -r cavity
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam
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-3.0.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
Note that
the following is a long single line.
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/swak4Foam
“A 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.”
2016-05-25: There is
currently work going on for the next release, and yesterday I experienced that
there may occasionally be problems with the installation procedure. I suggest
that you wait until the new version is released before installing that version.
You will be fine in most cases with one of the vanilla versions of OpenFOAM (e.g. OpenFOAM-3.0.x).
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.2
·
And
later the file $WM_PROJECT_DIR/doc/buildInstructions/Ubuntu/,
also located here:
https://sourceforge.net/p/openfoam-extend/foam-extend-3.1/ci/master/tree/doc/buildInstructions/Ubuntu
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)
Note that each of the following lines start with “sudo”.
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
There was a problem with the
system-installed flex:
libmeshTools.so: undefined reference to `yyFlexLexer::yywrap()'
I solved this by (do this here to avoid the problem):
echo
"export WM_THIRD_PARTY_USE_FLEX_2535=1" >> etc/prefs.sh
However, I did that
after first trying to compile, and I then had to also re-source and recompile src/meshTools and
applications/utilities/mesh/conversion/{ansysToFoam,gambitToFoam}. Then all
worked fine. (you don’t have to do this if you followed these instructions)
mkdir $HOME/foam
cd $HOME/foam
git clone git://git.code.sf.net/p/foam-extend/foam-extend-3.2
foam-extend-3.2
cd foam-extend-3.2
git checkout nextRelease #This is done to get the cutting-edge that will
go into 3.3
A link was obsolete in my clone,
fixed by this single line:
sed -i
s/"http:\/\/portal.nersc.gov\/svn\/visit\/tags\/2.4.2\/third_party\/libccmio-2.6.1.tar.gz"/"ftp:\/\/www.daba.lv\/pub\/TIS\/bibliotekas\/dazadas\/libccmio-2.6.1.tar.gz"/g
ThirdParty/AllMake.stage3
This part is where I do some changes
to the installation procedure, to use more system installed software in Ubuntu
16.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.
Note that the lines to copy start with “cp” (1 line),
and “sed” (8 lines). At the end there are some
additional non-grey sed-lines that are commented
(line starts with #). Those are examples of further things that can be
modified.
####################################################################
#
# 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.10.2 as supplied by Ubuntu
16.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.7 as provided by Ubuntu 16.04
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 3.5.1 as provided by Ubuntu 16.04
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.2
environment:
echo "alias f32NR='.
\$HOME/foam/foam-extend-3.2/etc/bashrc'"
>> $HOME/.bashrc
Close the terminal window and open a new one (doing:
CTRL-ALT-T) and type:
f32NR
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:
Press CTRL-ALT-T to open an new terminal window
f32NR
mkdir -p $FOAM_RUN
run
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
cd cavity
blockMesh
icoFoam
paraFoam -nativeReader
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.
The reader did not work properly for me, which is why
is suggested to use the nativeReader above to avoid a
second pop-up window.