0.1 Installation: 0.1.1 Linux
0.1 Installation: 0.1.1 Linux
INSTALLATION
0.1 Installation
0.1.1 Linux
OpenFOAM can be installed on Linux, macOS and Windows, but Linux has the best compatibility
and covers all the functions of OpenFOAM. Therefore, it is recommended to install Linux to operate
OpenFOAM.
If you use a Windows/macOS machine the easiest way to use Linux system is by installing a virtual
machine on top of your original operation system. An instruction to install a virtual Linux system
is given as follows (based on the notes provided by Professor Håakan Nilsson).
1. Download the last version of VirtualBox packages from the official website https://www.
virtualbox.org/wiki/Downloads (under the section of VirtualBox binaries). Install them
following the recommended features.
2. After starting the VirtualBox create a virtual hard disk by:
Select New
Name the disk: Ubuntu 18.04 LTS
Select Operating System: Linux
Select Version: Ubuntu 64-bit
Select Next
Assign Memory Size: 4096 MB (minimum 2GB (2048 MB) required for 64-bit operating
system, but for OpenFOAM installation it is suggested to assign 4GB (4096 MB))
Select Create a virtual hard disk now and click on Create
Select VDI (VirtualBox Disk Image) and click on Next
On “Storage of physical hard disk”, select Dynamically allocated and click on Next
Set a limit on hard drive storage to 50GB and click on Create
Note: It is worth noting that the settings can be modified later if required.
3. Download the operating system Ubuntu 18.04 from the website http://releases.ubuntu.
com/18.04/ by selecting the link 64-bit PC (AMD64) desktop image. This file with
extension .iso has an approximate size of 2.0 GB.
4. Double-click on the virtual disk you just created in VirtualBox and install the operating system
by:
On “Select start-up disk”, browse and open the Ubuntu file (.iso) you just downloaded;
click on Start. Ubuntu should be initialised in a window named “Ubuntu 18.04 LTS [Running]
- Oracle VM VirtualBox”
Click on Install Ubuntu and select your specific settings of language and normal instal-
lation
It is recommended that you tick: Download updates while installing Ubuntu, and,
Install third-party software...
Click on Continue
Select Erase Disk and Install Ubuntu and click on Install Now . Note: When it asks
you if it should erase the disk, don’t worry - it refers to the virtual disk you have just created
in VirtualBox, not your Windows/macOS disk.
Add information regarding your location and access information for the virtual machine
(username and password)
Wait whilst installing and restart when asked (just click on the button that pops up).
You may need to press Enter when required as well.
1
0.1. INSTALLATION
5. After the installation is done. You will enter a Linux Desktop (Ubuntu, see Figure 1). Note:
When asked if you would like to upgrade to Ubuntu 20.04.1 LTS, select Don’t Upgrade.
0.1.2 OpenFOAM
In a Linux system, you are ready to install OpenFOAM. OpenFOAM has different branches, and,
each branch different versions; these are updated regularly. Here we give the example of how to
install OpenFOAM-v2006. For the material given in these notes most of functions are the same in the
different branches. The installation process has been based and taken on the one shown in the official
website of the OpenFOAM-v2006 version: https://openfoam.com/download/install-source.
php.
To install and utilise OpenFOAM, it is essential to use a Terminal. By pressing “Ctrl+Alt+T”, a
terminal window will open, where you can type the commands to operate Linux (see Figure 2).
1. In your terminal, copy-paste-enter the following commands (one by one, you may need to
enter your password at some points to give permission). Note the short cuts for copy and
paste within the terminal window are “Ctrl+Shift+C” and “Ctrl+Shift+V”, respectively.
Install the system requirements for the installation in Ubuntu:
$ sudo apt-get update (Note: Type password and press ENTER)
$ sudo apt-get install build-essential flex bison cmake zlib1g-dev
libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin
gnuplot libreadline-dev libncurses-dev libxt-dev (Here, or in the next processes press
Y if asked)
$ sudo apt-get install qt4-dev-tools libqt4-dev libqt4-opengl-dev
freeglut3-dev libqtwebkit-dev
2
0.1. INSTALLATION
By typing the following should change to the main OpenFOAM directory ($WM_PROJECT_DIR).
If this fails, the environment is not correctly configured. You have to be in this directory to
compile OpenFOAM
$ foam
To make sure that we get the correct environment we close down the terminal window(s) and
open a new one by pressing “Ctrl+Alt+T”.
3
0.2. OPENFOAM CASE SETUP
$ cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily ./
$ cd pitzDaily
$ blockMesh
$ simpleFoam
5. After the compilation of OpenFOAM-v2006, we will install ParaView, which is the post-
processing utility to view/process our computational results.
$ sudo apt-get install paraview
There are many ready-to-use cases stored under the folder tutorials, which are fantastic to start
with. It is a possibility that your own cases of study be modified based on these tutorials, so you
don’t need to write a case from scratch. When modifying a tutorial, it is important that you first
copy it to your own directory, which was created in the last step of the installation; thus, the original
case setting can be preserved.
To access to a tutorial case to see how a basic OpenFOAM case looks like, go to:
tutorials/incompressible/icoFoam/cavity/cavity
4
0.2. OPENFOAM CASE SETUP
2. The “constant” folder: the properties of the fluid in question, e.g. viscosity, density.
3. The “system” folder: how will we solve the case, including space discretisation, time discreti-
sation, solver (what governing equations to use) and numerical scheme/solution.
Then, for a single cell and a time-step, we can solve the governing equations to obtain the pa-
rameters that are of interest, e.g. the Navier-Stokes equations to solve the pressure (P ) and velocity
(v) fields.
∇·v =0 (1)
∂(ρv)
+ ∇ · (ρvv) − ∇ · τ = −∇p + ρg (2)
∂t
0.2.2 Mesh
The generation of mesh is executed by a file called blockMeshDict, stored under the system direc-
tory. Open the blockMeshDict of the cavity tutorial, we can see the content as in the picture below.
(after “//” are annotations)
5
0.2. OPENFOAM CASE SETUP
OpenFOAM operates in a three-dimensional Cartesian coordinate system. Despite this tutorial case
is two-dimensional, all three dimensions should be different to zero. In blockMeshDict, first we need
to define the vertices for a domain of 1.0 m x 1.0 m x 0.1 m. Once the vertices are defined, they
are numbered in order (start with 0, so there are 8 points in total, numbered 0-7). The vertices 0-7
form a hexahedron, which is defined in the blocks part, and this is our computational domain. The
part (20 20 1) means the hexahedron will be meshed with 20 cells in the X-direction, 20 cells in
the Y-direction and 1 cell in the Z-direction (in a two-dimensional problem, we only put one cell in
the inactive direction). Therefore, this domain will be divided into 20*20*1 = 400 cells.
The part simplegrading (1 1 1) means the sizes of the mesh are uniform on the X-, Y-, and,
Z-direction. Changing the value here can make the cell size gradually increase along a direction. For
example, simplegrading (10 1 1) means the length of the last cell is 10 times of that of the first
cell along the X-direction.
Every four vertices can form a face, which can be classified in the boundary section:
6
0.2. OPENFOAM CASE SETUP
Figure 8: controlDict code for the time-step and time simulation - Cavity tutorial case
7
0.3. SIMULATION
The upper wall of the box start moving towards the right at a velocity of 1 m/s, while the other
walls are fixed. The moving wall will change the status of the fluid inside, as the fluid has viscosity
(see constant/transportProperties).
If you run the simulation, OpenFOAM will tell you what would happen in such a box.
0.3 Simulation
To run this simulation you need to execute the following steps from your terminal:
1. As it was mentioned before, always copy the case to your user directory before running or
modifying in order to keep the original file:
$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity $FOAM_RUN
$ cd $FOAM_RUN/cavity
2. Build the mesh:
$ blockMesh
3. Launch the solver:
$ icoFoam
4. Post-processing (OpenFOAM is installed with an open-source post-processing tool - ParaView)
$ paraFoam
5. Now you have entered ParaView and you can view the computational results (the field of P
and U for each time step)
8
0.3. SIMULATION
For more details of the Cavity tutorial, please check the website: https://www.openfoam.com/
documentation/tutorial-guide/tutorialse2.php#x6-60002.1