0% found this document useful (0 votes)
115 views9 pages

0.1 Installation: 0.1.1 Linux

Linux has the best compatibility with OpenFOAM, so it is recommended to install Linux. The document provides instructions to install Ubuntu Linux in a virtual machine on Windows or macOS. It then explains how to install OpenFOAM-v2006 in the Linux system, including downloading required files, compiling the software, and testing a tutorial case. Basic OpenFOAM case files are organized in constant, system, and time folders. The document introduces space and time discretization in CFD simulations.

Uploaded by

Ricky Velasco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views9 pages

0.1 Installation: 0.1.1 Linux

Linux has the best compatibility with OpenFOAM, so it is recommended to install Linux. The document provides instructions to install Ubuntu Linux in a virtual machine on Windows or macOS. It then explains how to install OpenFOAM-v2006 in the Linux system, including downloading required files, compiling the software, and testing a tutorial case. Basic OpenFOAM case files are organized in constant, system, and time folders. The document introduces space and time discretization in CFD simulations.

Uploaded by

Ricky Velasco
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

0.1.

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.

Figure 1: Ubuntu desktop in VirtualBox (Linux OS)

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).

Figure 2: A terminal window in Ubuntu

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

$ sudo apt-get install libscotch-dev libcgal-dev

Download the OpenFOAM and ThirdParty packages:


$ mkdir $HOME/OpenFOAM (Creates the folder named OpenFOAM were the software is in-
stalled)
$ cd $HOME/OpenFOAM
$ wget https://sourceforge.net/projects/openfoam/files/v2006/OpenFOAM-v2006.tgz
$ wget https://sourceforge.net/projects/openfoam/files/v2006/ThirdParty-v2006.tgz
$ md5sum OpenFOAM-v2006.tgz Note: Should show 1226d48e74a4c78f12396cb586c331d8
$ md5sum ThirdParty-v2006.tgz Note: Should show 6b598b6faa6ddeb25235c5dded0ca275
$ tar -xzf OpenFOAM-v2006.tgz (Unpacking the tarball)
$ tar -xzf ThirdParty-v2006.tgz

Source the OpenFOAM environment by executing, e.g. for bash shells:


$ source ~/OpenFOAM/OpenFOAM-v2006/etc/bashrc

2. At this point you have two directories: (a) $HOME/OpenFOAM/OpenFOAM-v2006


and (b)$HOME/OpenFOAM/ThirdParty-v2006. The first one contains all the source files to
compile OpenFOAM, and the second one contains instructions on how to compile third-party
packages, if necessary.

To test that the system is ready to install OpenFOAM type:


$ foamSystemCheck

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

Compile OpenFOAM by typing:


$ ./Allwmake This could take a few couple of hours depending on your laptop/computer. You
can do something else whilst you wait for it to finish.

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. We set up an alias for activating the OpenFOAM-v2006 environment:


$ echo "alias OFv2006='. $HOME/OpenFOAM/OpenFOAM-v2006/etc/bashrc'" >> $HOME/
.bashrc
Note: Every time you open a new terminal and intend to use OpenFOAM, you have to execute
command “OFv2006” to initialise it.

4. Now, we are going to check if OpenFOAM was installed successfully.


$ OFv2006 Source the OpenFOAM environment (remember to do this every time you are going
to use OpenFOAM, otherwise the system will not recognise any OpenFOAM tool/command)
$ foamInstallationTest (Testing the outcome of the installation)
$ mkdir -p $FOAM_RUN (Creating the run directory where the user cases will be stored)

Testing the pitzDaily tutorial case:


$ run

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

Congratulations. Your OpenFOAM-v2006 has been set up OK!

0.2 OpenFOAM case setup


Once installed, OpenFOAM files are saved at the directory: OpenFOAM/OpenFOAM-v2006.

Figure 3: OpenFOAM files

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.

Figure 4: Topics of tutorials available in OpenFOAM

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

Figure 5: Folders required to run a case in OpenFOAM - Cavity tutorial case

A basic OpenFOAM case consists of three separate directories:


1. The “0” time folder: the boundary and initial conditions for each of the variables in question,
e.g. pressure, velocity.

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.

0.2.1 Introductory CFD


Before further learning of OpenFOAM, this short section will prepare you with a little CFD knowl-
edge as background. The basic idea to solve an OpenFOAM simulation includes two parts, space
discretisation and time discretisation. Space discretisation is to divide a domain of interest into
a number of non-overlapping cells, known as mesh; time discretisation is to split a process into a
number of time-steps.
In order to understand the flow problem with numerical simulations, we first discretise the numerical
domain into a number of cells obtaining a mesh. The combination of the solution of the fluid in each
single cell forms the solution of the whole space domain. This is similar to a film: a single frame
consists of many elements; each element stores its own information, so a higher cell/element number
means you get a clearer image.
The case of the time-step is simpler. When the time of a process you want to analyse is certain, e.g.
10s. 100-time-steps means you want to solve the results per 0.1s; then 1000-time-steps means 0.01s.
It is worth noting that by increasing the number of cells or decreasing the time-step means solving
a simulation with a higher resolution, whilst the computational time will increase accordingly.

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

Figure 6: Domain construction using blockMeshDict - Cavity tutorial case

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:

Figure 7: Boundary Conditions of the faces in blockMeshDict - Cavity tutorial case

6
0.2. OPENFOAM CASE SETUP

0.2.3 Time-step and solver


The system/controlDict code is shown below, in which you can modify the solver, run time, time-
step size, how often the results are stored, among others.
Usually the name of an OpenFOAM solver ends with Foam, and the prefix depends on the type of
the solution. For example, the solver:
icoFoam is used for incompressible laminar Navier-Stokes equations using the PISO algorithm
interFoam is used for two incompressible fluids (multiphase solution)
fsiFoam is used for Fluid-Structure Interaction (FSI) problems

Figure 8: controlDict code for the time-step and time simulation - Cavity tutorial case

0.2.4 Initial and boundary conditions


So far, we introduced the setting of how to solve a case. Now we are going to discuss how to define a
problem physically, which is known as initial condition (IC) and boundary conditions (BC). Whilst
IC is straightforward to understand - as it defines the initial configurations of a simulation, i.e.
what you want the case to be when t = 0, BC defines how the simulation being pushed forward per
time-step.
Open the 0 folder, there are two files called P and U, which defines the IC and BC for pressure and
velocity, respectively.
Here we use the U file to give an example. As there are three kinds of boundary defined in
blockMeshDict, movingWall, fixedWall and frontAndBack. The U file shows the movingWall
boundary always have a constant velocity of (1 0 0), and the fixedWall does not have a velocity.
The BC empty is usually used on the inactive boundaries of a two-dimensional problem, which can
be understand as: no solution is required.

Thus, the case is set up as:


Fluid is initialised as static in a box.

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.

Figure 9: Boundary and Initial Conditions - Cavity tutorial case

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

Figure 10: Pressure and velocity fields - Cavity tutorial case

For more details of the Cavity tutorial, please check the website: https://www.openfoam.com/
documentation/tutorial-guide/tutorialse2.php#x6-60002.1

You might also like