100% found this document useful (1 vote)
483 views138 pages

OpenFOAM Course Notes Release v1.0

A 3-day course at University College London taught students how to use and understand OpenFOAM, an open-source computational fluid dynamics (CFD) simulation tool. The course covered installing and setting up OpenFOAM cases, running simulations, and tutorials for ship flow, wave, and fluid-structure interaction simulations. The 55 students who attended represented a growing UK and international community interested in OpenFOAM. The document provides the course content to help more people learn OpenFOAM.
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
100% found this document useful (1 vote)
483 views138 pages

OpenFOAM Course Notes Release v1.0

A 3-day course at University College London taught students how to use and understand OpenFOAM, an open-source computational fluid dynamics (CFD) simulation tool. The course covered installing and setting up OpenFOAM cases, running simulations, and tutorials for ship flow, wave, and fluid-structure interaction simulations. The 55 students who attended represented a growing UK and international community interested in OpenFOAM. The document provides the course content to help more people learn OpenFOAM.
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/ 138

A doctoral skill course at University College London

Established with a UCl Research-led initiative Award

Course Notes:
UCL OpenFOAM Course 2019
funded by the UCL Doctoral Skills Development Programme

Authors:
Luofeng Huang
Daniela Benites
Shiyu Lyu
Tom Smith
Minghao Li
Yeru Shang
Christian Klettner

Department of Mechanical Engineering


University College London (UCL)

October 2019
Preface

OpenFOAM is an opensource simulation tool originally developed by Jasak et al. [1] and Weller at
al. [2]. It has been successfully applied to various research areas, including Engineering, Physics,
Chemistry and Biology. By employing OpenFOAM, we can simulate the desired practical processes
using a computer, followed by the post-processing utility to analyse the results. Pictures and videos
can be generated to assist illustration. As the development of IT technique, OpenFOAM has become
a powerful skill for a researcher/engineer to grasp.

Compared with other commercial simulation tools, people usually think that OpenFOAM is more
difficult to learn. The main difficulty includes:
• A beginner is not familiar with its operation environment, Linux. It can be very tricky even
trying installing OpenFOAM.

• To understand OpenFOAM codes requires a foundation in Computational Fluid Dynamics


(CFD) and C++.
• Online study materials are not comprehensive, and on-site courses are in scarcity.
Nevertheless, benefited from its open-source nature, every single line of OpenFOAM code is accessi-
ble, which means you are able to see and manipulate what is actually running behind the simulation.
By using OpenFOAM, you will gain a deep understanding on CFD theories and approached, as well
as how these methods are implemented. You are free to conduct any modifications upon the codes,
which allows you to perform innovations.

The UCL OpenFOAM Course was initiated by the Department of Mechanical Engineering, totally
free and registered under UCL doctoral school. It aims to popularise OpenFOAM among research
students and help beginners to get through the initial painful stage dealing with the unfamiliar opera-
tion environment, also an excellent chance to exchange simulation skills and generate collaborations.
In 2019, the course was held during 26-28 June, with our lecturers and 55 students attended. It was
fantastic to see so many conversations getting started, and to feel that our UK/London community
is getting stronger. We received very positive feedback, and more importantly, strong interests from
worldwide users who wanted but could not join us in London.

Thereby, this document is published online to demonstrate what we have taught. We hope this
will be helpful for a wider audience. In Chapter 1-4, we present step-by-step guideline for in-
stalling/using/understanding OpenFOAM; subsequently, our Appendixes provides advanced tutori-
als for various purposes.

Special thanks go to Professor Hrvoje Jasak, the founder of OpenFOAM, for providing invalu-
able supports on the course’s delivery. Now He has also commenced to be a visiting professor
at UCL to facilitate OpenFOAM-based teaching/research. Moreover, the course was inspired by
the OSCFD course being taught by Håkan Nilsson at Chalmers University of Technology, Sweden
(http://www.tfd.chalmers.se/~hani/kurser/OS_CFD/).

I
Group photo

Professor Hrvoje Jasak is lecturing

II
Contents

1 OpenFOAM basis 1
1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.1 Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1.2 OpenFOAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 OpenFOAM case setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Introductory CFD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.2 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2.3 Timestep and solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.4 Initial and boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2 Ship flow simulation 9


2.1 Case introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Free-surface modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Boundary conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Mesh around the ship . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4.1 Local mesh refinement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.4.2 SnappyHexMesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.5 Ship resistance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

3 Wave simulation 18
3.1 Waves2Foam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.1.2 Numerical Wave Tank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 ihFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.3 Wave pass through a fixed plate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4 Fluid-Structure Interaction 30
4.1 Preparation: stress-analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.2 Installation(FSI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2.1 foam-extend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2.2 fsiFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.3 FSI approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.4 FSI tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.4.1 Case structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.4.2 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.4.3 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.5 Wave-induced FSI problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.5.1 Code development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.5.2 Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Reference 40

III
CONTENTS CONTENTS

Appendixes: advance tutorials 40

A Coding tutorial 41

B Tutorial: Flow passes a motorbike 60

C Tutorial: Flow passes a cylinder 77

D Tutorial: Develop a turbulent model 87

E Tutorial: Parallelisation and HPC 114

F Programme of the 2nd UCL OpenFOAM Workshop 126

Reading recommendation 129

Acknowledgements 130

IV
Chapter 1

OpenFOAM basis

1.1 Installation
1.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.

The easiest way to install Linux system is to install a virtual machine on top of your original
operation system (e.g. Windows). 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 official version VirtualBox (both Platform Packages and Extension Pack), from
https://www.virtualbox.org/wiki/Downloads. Install it.
2. After installing VirtualBox, start it and:
Create new virtual disk:
Click on New
Name: Ubuntu 18.04 LTS
Operating System: Linux
Version: Ubuntu 64-bit (in case you can only select 32-bit here, see http://www.fixedbyvonnie.
com/2014/11/virtualbox-showing-32-bit-guest-versions-64-bit-host-os/#.WvHgFYgvxPY)
Base memory: 2048MB (minimum 2GB required for 64-bit operating system)

3. Create a virtual hard drive now


VDI
Dynamically allocated
Set a limit on hard drive storage to 50GB
Click on Create
(Settings can be changed later)
4. Download Ubuntu 18.04 from http://releases.ubuntu.com/18.04/,
click 64-bit PC (AMD64) desktop image, then you will get an iso file (1.9GB).

5. Double-click on the virtual disk you just created in VirtualBox. In the pop-up window, click
on the icon ”Choose a virtual optical disk file”, and browse to the Ubuntu iso-file you just
downloaded.
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

1
1.1. INSTALLATION CHAPTER 1. OPENFOAM BASIS

It is recommended that you tick: Download updates while installing, and Install third-party
software
Restart when asked (just click on the button that pops up). You may need to press Enter at
some point.
(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 disk.)
6. After the installation is done. You will enter an Linux Desktop (Ubuntu).

Figure 1.1: Linux desktop of Ubuntu

1.1.2 OpenFOAM
In a Linux system, you are ready to install OpenFOAM. OpenFOAM has different versions, and it
keeps updating. Here we give the example of how to install OpenFOAM-v1806. (most of functions
are the same in different versions)
To install and utilise OpenFOAM, it is essential to use a Terminal. By press ”Ctrl+Alt+T”, a
terminal window will occur, where you can type your commands.

Figure 1.2: A terminal 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 here
are ”ctrl+shift+c” and ”ctrl+shift+v” respectively.

mkdir $HOME/OpenFOAM
cd $HOME/OpenFOAM
sudo apt install git (Type password and ENTER, then later you need to ’Y)
git clone https://develop.openfoam.com/Development/OpenFOAM-plus.git (This step
requires a user name and password from your registration. Thus, go to: http://openfoam.

2
1.1. INSTALLATION CHAPTER 1. OPENFOAM BASIS

com/code/repositories.php and register an account)


mv OpenFOAM-plus OpenFOAM-v1806
At the following lines you should include the brackets ”(” and ”)”. The commands executed
between the brackets are in a subshell, and after the line you remain in the same directory as
before the command. (cd $HOME/OpenFOAM/OpenFOAM-v1806 && git fetch)
(cd $HOME/OpenFOAM/OpenFOAM-v1806 && git checkout maintenance-v1806)
(cd OpenFOAM-v1806 && git submodule init)
wget https://sourceforge.net/projects/openfoamplus/files/v1806/ThirdParty-v1806.tgz
md5sum ThirdParty-v1806.tgz #Should give 3c06cb20d08ab564b70f9df5186ec936
tar xvf ThirdParty-v1806.tgz
rm ThirdParty-v1806.tgz

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


and (b)$HOME/OpenFOAM/ThirdParty-v1806. 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.
We start by installing some required packages:
sudo -i (Type root password for your Ubuntu installation. Makes you root user, so that you
can run apt-get directly and without entering password. The following five lines all start with
”apt-get”. Copy each line separately. You may have to type Y at some point. )
apt-get install build-essential flex bison cmake zlib1g-dev libboost-system-dev \
libboost-thread-dev
apt-get install libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev
apt-get install qt5-default libqt5x11extras5-dev libqt5help5 qtdeclarative5-dev \
qttools5-dev libqtwebkit-dev
apt-get install freeglut3-dev libqt5opengl5-dev texinfo
apt-get install libscotch-dev libcgal-dev
exit (Stop being root user)

3. We set up an alias for activating the OpenFOAM-v1806 environment:


echo "alias OFv1806='. $HOME/OpenFOAM/OpenFOAM-v1806/etc/bashrc'" >> $HOME/.bashrc
(everytime you open a new terminal and intend to use OpenFOAM, you have to execute com-
mand ”OFv1806” to initialise it.)

4. Now we are ready to compile. To make sure that we get the correct environment we close
down the terminal window(s) and open a new one by ”Ctrl+Alt+T”. OFv1806
foam
export WM_NCOMPPROCS=4(To use all four cores on my virtual machine while compiling)
./Allwmake(This will take several hours. So just do something else and wait it to finish)

5. After the compilation of OpenFOAM-v1806, we will install ParaView, which is the post-
processing utility to view/process our computational results.
sudo apt-get install paraview

6. Test the installation, open a new terminal:


OFv1806
mkdir -p $FOAM_RUN
run
cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity .
cd cavity

3
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS

blockMesh
icoFoam
paraFoam (Click on Apply, a square should appear in the window.)

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

1.2 OpenFOAM case setup


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

There are many ready-to-use cases stored under the folder ”tutorials”, which are fantastic to start
with. Your own cases can always be modified based on these tutorials, so you should never write a
case from scratch.
Note: when modifying a tutorial, you should 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.

Let’s enter a tutorial case to see how a basic OpenFOAM case looks like,
go to: tutorials/incompressible/icoFoam/cavity/cavity

4
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS

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 discretization, time discretiza-
tion, solver (what governing equations to use) and numerical scheme/solution.

1.2.1 Introductory CFD


Before further learning of OpenFOAM, this is a short section to prepare a little CFD knowledge as
background.
The basic idea to solve an OpenFOAM simulation includes two parts, space discretization and time
discretization. Space discretization is to devide a domain of interest into a number of non-overlapping
cells, known as mesh; time discretization is to split a process into a number of timesteps.
When we want to learn a process, we mesh the domain by a number of cells and get the solution of
each single cell, which 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.
Timestep is simpler. When the time of a process you want to learn is certain, e.g. 10s. 100-timesteps
means you want to solve the results per 0.1s; then 1000-timesteps means 0.01s.
To sum up, increasing cell number or timestep number means solving a simulation with a higher
resolution, while the computational time will increase accordingly.

Then, for a single cell and a timestep, we can solve the governing equations to obtain the parametres
that are of interest, e.g. the Navier-Stokes equations to solve pressure (P ) and velocity (v).

∇·v =0 (1.1)

∂(ρv)
+ ∇ · (ρvv) − ∇ · τ = −∇p + ρg (1.2)
∂t

1.2.2 Mesh
The generation of mesh is dictated 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
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS

OpenFOAM always operates in a three-dimensional Cartesian coordinate system. In blockMeshDict,


first we need to define some vertices:
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 can form a hexahedron, which is defined in the blocks part, and this is our com-
putational domain.
(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 simplegrading (1 1 1) means the sizes of the mesh are uniform on all X Y Z directions.
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 part:

1.2.3 Timestep and solver


The system/controlDict codes are shown as follows, in which you can modify the solver, runtime,
time-step size, how often the results are stored, etc..
The name of a OpenFOAM solver ends with Foam, and the prefixion depends on the solver type.
For example:
icoFoam solves the incompressible laminar Navier-Stokes equations using the PISO algorithm;
interFoam is a solver for 2 incompressible fluids;
fsiFoam is used for Fluid-Structure Interaction (FSI) problems;

6
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS

1.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). IC is
straightforward to understand - 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 timestep.
Open the 0 folder, there are two files called P and U, which defines the IC and BC for presure 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 bound-
ary always have a constant velocity of (1 0 0), and the fixedWall does not have a velocity. ”empty”
BC is usually used on the inactive boundaries of a two-dimensional problem, which can be under-
stand as: no solution is required.

Thus, the case is set up as:


Fluid is initialised as static in a box.
The upper wall of the box start moving towards the right at a velocity of 1 m/s, while the other
walls keep 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.

7
1.3. SIMULATION CHAPTER 1. OPENFOAM BASIS

1.3 Simulation
To run this simulation you need to execute the following steps from your terminal:
1. as mentioned earlier, always copy the case to your user directory before running or modifying,
so as 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 opensource 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)

More details please see: https://www.openfoam.com/documentation/tutorial-guide/tutorialse2.


php#x6-60002.1

8
Chapter 2

Ship flow simulation

To study how to simulate ship flow in OpenFOAM, we use a case of DTCHull as an example in this
chapter, which is stored under tutorials/multiPhase/interFoam/ras/DTCHull.

2.1 Case introduction


A schematic diagram of the case is shown in Figure 2.1. The flow field is a multi-phase field, with
air in the upper part and water in the lower part. The ship model was initialised as floating on the
water surface according to the designed draft, and it is fixed. A constant velocity (U) against the
ship bow was set to the water, so there is a relative velocity between the ship and water. Thus,
the simulation is equivalent to a ship advancing in calm water. To be conformed to an open ocean
environment, the computational domain was modelling as infinite, i.e. no boundary wall was set at
the sides or the bottom. The resistance of the ship is of interest in this work, which is calculated as
the water force against the bow direction.

Figure 2.1: Schematic diagram of the simulation case. The hull is floating on the water surface and subjected
to flowing water of a constant velocity (U ).

2.2 Free-surface modelling


As the fluid domain is a two-phase mixture of air and water, the Volume of Fluid (VOF) method [3]
is used to model the free surface. The VOF method introduces a passive scalar α, which denotes the
fractional volume of a cell occupied by a specific phase. In this model, a value of α = 1 corresponds

9
2.3. BOUNDARY CONDITIONS CHAPTER 2. SHIP FLOW SIMULATION

to a cell full of water and a value of α = 0 indicates a cell full of air. Thus, the free surface, which
is a mix of these two phases, is formed by the cells with 0 < α < 1. The α value was solved by
its transport equation as expressed in Equation 2.1, and further the local density (ρ) and viscosity
(µ) were determined according to the corresponding α, as Equation 2.2 and 2.3. Fluid properties of
both fluids are set in constant/transportProperties.
∂α
+ ∇(vα) = 0 (2.1)
∂t

ρ = αρwater + (1 − α)ρair (2.2)

µ = αµwater + (1 − α)µair (2.3)


The multi-phase model is defined in system/setFieldDict, as:

It defines a specific area where α = 1, and the other area defaults α = 0. Here it says the cells of
Z < 0.244 m is water and Z > 0.244 m is air, so the free surface of this case is at Z = 0.244 m.

2.3 Boundary conditions


The BCs of this case is to generate a water flow of steady velocity, which is explained separately as
0/U and 0/P.

U:
• Inlet: fixedValue is a vbasic BC and easy to understand. Here it gives the inlet boundary a
constant speed of (-1.668 0 0) towards the outlet direction.
• Outlet: outletPhaseMeanVelocity adjusts the velocity for the given phase to achieve the
specified mean thus causing the phase-fraction to adjust according to the mass flow rate. By
applying this boundary condition, the mass flow rate of the water phase in the outlet boundary
is set to equal to the inlet mass rate, so that the water volume in the computational domain
can keep constant. This BC can avoid the waterline continuously increase/decrease, which is
typically used as the outlet condition for a towing-tank ship simulation in order to maintain
the outlet water level as the same as the inlet.

10
2.3. BOUNDARY CONDITIONS CHAPTER 2. SHIP FLOW SIMULATION

• Atmosphere: pressureInletOutletVelocity - here we specific the tangential velocity across


this face to equal (-1.668 0 0).

P:
• Inlet: fixedFluxPressure is used to set the pressure gradient to be specified by the velocity
boundary condition, so that the fixed water velocity can be matched.
• Outlet: zeroGradient means the gradient of pressure equals to zero, typically used as outlet
pressure BC.

• Atmosphere: totalPressure calculates the pressure from a specified total pressure p0 and
local velocity U. (Here we define the atmosphere pressure to be 0 pascal)

11
2.4. MESH AROUND THE SHIP CHAPTER 2. SHIP FLOW SIMULATION

2.4 Mesh around the ship


2.4.1 Local mesh refinement
Sometimes we need high-quality meshes in certain areas of a computational domain. For example, in
this case we want the mesh to be refined around the ship and in the free surface area. OpenFOAM
provides a utility called refineMesh, by which we can specify an area and just refine the mesh inside.
It is controlled by system/refineMeshDict:

Here we only refine X and Y directions, since Z direction has already been set to gradually increase
towards waterline in blockMeshDict. refineMesh cuts every grid in the area to be 2 in X direction
and 2 in Y direction, so one grid becomes four grids. If applied to all three directions, refineMesh
will cut one grid into eight. See more on https://openfoamwiki.net/index.php/RefineMesh.

2.4.2 SnappyHexMesh
As a hull geometry is complex, blockMesh is incapable to build the mesh around the hull. Here
we introduce another OpenFOAM mesh tool snappyHexMesh to generate high-quality grids fitting
around the hull surface. See more in Appendix B.

There are three main steps in SnappyHexMesh:


1. castellatedMesh
2. snap
3. addLayers

An example is given below to illustrate the process: (details see https://cfd.direct/openfoam/


user-guide/v6-snappyhexmesh/)

This is a geometry in a domain after blockMesh:

12
2.4. MESH AROUND THE SHIP CHAPTER 2. SHIP FLOW SIMULATION

castellatedMesh: the edges of the geometry are detected, and then the meshes that intersect with
the edges are refined.

snap: the cells inside the geometry are removed, and then the boundary is smoothed.

addLayers: shrink the existing mesh from the boundary and insert layers of cells

In the DTCHull case, the snappyHexMesh is governed by system/snappyHexMeshDict. First of all,


we need to store the geometry file of the hull under constant/triSurface, and it needs to be in
the form of STL.

Load the STL file of the hull and define the hull surface as wall:

13
2.4. MESH AROUND THE SHIP CHAPTER 2. SHIP FLOW SIMULATION

Now we open the system/snappyHexMeshDict file, where we can define the settings about how to
be refined the mesh around the ship.
Step 1, castellatedMesh:

Step 2, snap:

14
2.5. SHIP RESISTANCE CHAPTER 2. SHIP FLOW SIMULATION

Step 3, addLayers:

The generated mesh around the ship is shown below.

2.5 Ship resistance


Based on the simulation, the fluid force on the ship can be calculated as an integration of surrounding
fluid mesh over the hull surface:
Z
Fh = (−P n + τ · n)dS (2.4)

where p denotes the pressure, τ = µ[∇v + (∇v)T ] is the viscous term.

OpenFOAM uses a functionObject-forces to calculate ship resistance, which is added in the end
of the controlDict file. This functionObject outputs the pressure force and shear force acting on a
specific body after each timestep, and stores the result as a function of time.

15
2.5. SHIP RESISTANCE CHAPTER 2. SHIP FLOW SIMULATION

The result of this functionObject is stored under postprocessing/forces/0, where you can find a
data file. Open the file in Excel you can see the forces as a function of time, then the ship resistance
can be calculated as the sum of pressure force and shear force on the X direction.
As the ship is a symmetry geometry, we can only calculated resistance of half the ship (by applying
symmetryPlane boundary condition at Midship), which saves around half of the computational time
(only half mesh required). With this method used, we just need to manually double the resistance
result.

The ship resistance at six different velocities (velocity can be varied in the 0/U file) was calculated and
plotted in Figure 2.2, as a function of the simulation time. It can be seen that the resistance value
oscillates and the oscillation amplitude reduces over time. When the resistance curve eventually
approaches a steady harmonic state, the computational resistance was taken as the average value of
the crest and trough.
A comparison between the computational results (CFD) and the corresponding experimental data
(Exp.) [4] is given in Figure 2.3, where good agreement can be found. For all the six velocity
conditions, the computational results are slightly smaller than the experimental values and the
deviations are less than 5%. Therefore, it is concluded the applied numerical approach can accurately
predict the total resistance of a ship in open water.

16
2.5. SHIP RESISTANCE CHAPTER 2. SHIP FLOW SIMULATION

Figure 2.2: Total ship resistance at different velocities (U ) over simulation time.

Figure 2.3: Comparison between computational ship resistance and the corresponding experimental data
[4].

17
Chapter 3

Wave simulation

To generate ocean surface waves in a Numerical Wave Tank (NWT), two branches of method are
generally used: (a) mimic a physically wave generator (paddle/piston) in the NWT (b) manually
modify numerical solutions to achieve theoritical wave profiles. In OpenFOAM, there are two mature
NWT tools based on the branch (b), namely: waves2Foam [5] using a relaxation zone method, and
ihFoam [6] using a boundary control method. Both tools are introduced as follows.

3.1 Waves2Foam
3.1.1 Installation
In order to use the waves2Foam toolbox, we need to install it for the current version of OpenFOAM
(based on its manual [7]):

1. Before proceeding with the installation of waves2Foam, we must include the dependencies (or
verify they are already within the Ubuntu environment):
• GNU Scientific Library (GSL) (https://astrointro.wordpress.com/2017/05/17/ installing-
gnu-scientific-library-gsl-in-ubuntu-16-04-and-compiling -codes/) (you should get the lat-
est version)
• Subversion (SVN) (Execute in a terminal: sudo apt install subversion)
• git (Execute in a terminal: sudo apt install git)
• gfortran (Execute in a terminal: sudo apt install gfortran)

2. Download waves2Foam, execute in the terminal:


svn co http://svn.code.sf.net/p/openfoam-extend/svn/trunk/
Breeder_1.6/other/waves2Foam
3. Establish directories for waves2Foam:

cd OpenFOAM/
cd YOUR USER DIRECTORY (name-v1812)
mkdir -p applications
cd applications
mkdir -p utilities

4. Find the waves2Foam folder in your Downloads (or Home) section, extract and copy it into the
Utilities directory you just created (OpenFOAM/YOUR NAME-v1812/applications/utilities).
5. Compile waves2Foam with your OpenFOAM, open a terminal (take a while to complete):

18
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION

cd OpenFOAM/YOUR NAME-v1812/applications/utilities/waves2Foam
./Allwmake

Now, waves2Foam should have been set up OK. We are ready to try one of the tutorials and verify
that the toolbox is running smoothly. The manual of waves2Foam is available at ResearchGate,
search ”waves2Foam manual”.
To update waves2Foam, use:
cd OpenFOAM/YOUR NAME-v1812/applications/utilities/waves2Foam
svn update
./Allwmake
To verify that the toolbox is correctly installed we are going to run a tutorial case, waveFlume.
Further information regarding this and other tutorials available are described in the official manual.
Check that your terminal is still within the waves2Foam folder and execute:
cd tutorials/waveFoam/
cp -r waveFlume waveFlume_Example
cd waveFlume_Example
./Allrun
This tutorial will run for 10 to 20 minutes (if you want, you can reduce the 20 s of simulation
inside the controlDict file) and you can check its progress inside the folderâs window. After the
execution of the tutorial finishes, check that the post-processor is working as well, proceed with:
nano foam.foam
An edit file will be opened within the terminal window, type any letters (example XYZ), and save
the file by using CTRL+O, followed by exiting with CTRL+X. A dummy filed was created inside
our tutorial. Then, to open ParaView:
paraview foam.foam &
Click ”Apply”, select the option of visualisation of alpha.water and click âPlayâ button. You will
see the generation of the waves inside the NWT. The red section is the water, whilst the blue one
is the air. By playing the animation of this simulation, we can see that waves have been effectively
generated and propagated in the model.
Next, we will understand the theories behind waves2Foam: how this toolbox generates the free
surface waves, how we build our domain, which is the input data for the waves as to understand
what output results we can get depending on the case.

3.1.2 Numerical Wave Tank


The study case used in this tutorial is the implementation of a two-dimensional Numerical Wave
Tank (NWT), and its dimensions are 25.0 x 0.1 x 1.6 meters (Length x Breadth x Height). The
water level is set at 1.2 meters. For the waves generation the waves are regular and correspond to
the Stokes’ first order wave theory (or Airy’s Wave). The wave height used is 0.1 m, the wave period
2.0 s, whereas the wavelength is 5.5 m.

Theoretical background: relaxation zones


In physics, wave is actually the distribution of the free surface. To model the loads of waves on
a solid body, a desired wave field should be generated in the CFD model, which is known as a
numerical wave tank.
In OpenFOAM, the waves2foam toolkit can be used to model a numerical wave tank. Its installation
instruction and theoretical details can be found in the manual [7].
The waves2foam toolkit uses a technique known as relaxation zone [8] to facilitate the modelling of a
numerical wave tank. Commonly, two relaxation zones are set at the inlet and outlet of the domain,
as the schematic diagram shown in Figure 3.1. These two zones can effectively help generate and
absorb surface waves respectively. A relaxation zone can also be set to other shapes, e.g. cylindrical

19
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION

rather than rectangular.

Figure 3.1: Schematic diagram for the inlet and outlet relaxation zones (grey) in a numerical wave tank [9].)

Figure 3.2: The value of spatial weighting factor, χ(ξ), as a function of local coordinate[9].)

The relaxation zones can be employed to prevent wave reflection from the outlet boundary and
also to prevent internally reflected waves, e.g. the waves reflected by internal structure to influence
the wave generation at the inlet boundary. In the relaxation zone method, a spatial weighting factor
χ is introduced as:
exp(ξ β − 1)
χ(ξ) = 1 − (3.1)
exp(1) − 1
where ξ is the local coordinate in the relaxation zone, which equals to 1 at the outer end and 0 at
the inner end of the relaxation zone, as indicated in Figure 3.2. The shape factor β can be defined
arbitrarily. Then a local value φ is dependent on χ as:

φ = χφcomputed + (1 − χ)φtarget (3.2)


where φtarget is the target solution such as U or α, and φcomputed is the numerically computed value,
obtained from the Navier-Stokes and VOF equations. Thus, the relaxation zone can obtain an ad-
justed φ over each timestep, thereby minimizing the interference caused by wave reflection. The tar-
get wave parameters are set according to wave theories through a file named waveProperties.input,
which will be introduced as below.
Based on the theory above, Figure 3.3 below shows the schematic of this tutorial case: the minimum
lengths of each zone depend on the wave length (L) considered.

20
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION

Figure 3.3: Layout of the NWT using waves2Foam: ZONE I - Inlet Relaxation Zone (Wave Generation);
ZONE II - Section for the analysis; ZONE III - Outlet Relaxation Zone.

Case setup and running


Now, in order to build our tutorial case, we are starting by copying the tutorial waveFlume and
rename it as waveFlume_NWT1:

run
cd ../applications/utilities/waves2foam/tutorials/waveFoam/
cp -r waveFlume waveFlume_NWT1
Mesh
For the mesh generation we are going to use the same option as it was done in the previous cavity
tutorial in 1.2.2, blockMeshDict, which produces a block-structured hexahedral mesh. The only
difference is that our domain here involves the two sections of the NWT: one for the water and the
other for the atmosphere. Below, the vertices show that our NWT has dimensions of 25.0 x 1.6 x
0.1m (the short distance -one-cell- in the z-direction indicates a 2D case), the depth of the tank is
1.2 m. The next sections of the blockMeshDict are the same as explained in section 1.2.2.

Waves
For setting up the wave parameters, inside the constant folder, we will open the file called waveProperties.input.
Inside this file we can include the average depth, the wave period, the wave height, the relaxation
zones and the wave theory to be applied (for this case we are using the first order wave theory,
named here firstStokes). In the first part of the inletCoeffs section the parameters of the wave
will be written:

21
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION

And in the second part would be the ones for the relaxation zones. More information on the
parameters used here can be found in Section 2.7 of the waves2foam manual [7].

Boundary Conditions
Below are the boundary conditions applied in each patch of the NWT and which are located in the
0.org folder:

Boundary alpha1 p-rgh/pd U


inlet waveAlpha zeroGradient waveVelocity
outlet zeroGradient zeroGradient fixedValue
bottom zeroGradient zeroGradient fixedValue
atmosphere inletOutlet totalPressure pressureInletOutletVelocity
frontBack empty empty empty

Table 3.1: Boundary Conditions

22
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION

Simulation
Now to run the model we execute the file ./Allrun:
run
cd ../applications/utilities/waves2foam/tutorials/waveFoam/waveFlume_NWT1
./Allrun
We should have new folders of each time step as well as the log files of each application in our
example window as it is shown below.

Post-processing: free surface elevation


First we create the dummy file called foam.foam and then open it in Paraview, as in the previous
examples.

Now, we are going to see the results of the wave surface elevation measured at the centre of the
NWT. For this:

1. Select Filters>Alphabetical>Contour option within Paraview, in the “Contour By” drop


window the alphawater field is selected to a value of 0.5 (in the Isosurfaces section) and
click “Apply”.
2. Select the Filters>Alphabetical>Slice option within Paraview. The origin is set to the
middle of the tank at water level: 12.5 x 0.05 x 1.2 and click “Apply”.

3. Select the “Split Horizontal” option on the right hand side of the view window (next to
RenderView1), select the SpreadSheet View and select one of the points showed for that
Slice.
4. Select Filters>Alphabetical>Plot Selection Over Time and click on the “Apply” button,
which will produce a picture as Figure 3.4.

5. you can also save the file with the extension .csv and open it using Excel.

23
3.2. IHFOAM CHAPTER 3. WAVE SIMULATION

Figure 3.4: Free Surface Elevation measured at 12.5 m from the wave-maker.

3.2 ihFoam
There is no need to install ihFoam as it is already within OpenFOAM-v1806. Same tutorial case
used with waves2foam will be perfoamed using ihFoam.

Boundary control method


In the technique used in ihFoam, the values of the velocity fields and the free surface elevation are
corrected at each time-step at the inlet patch according to the wave theory applied. This correction
is done by comparing the numerical measured value against the theoretical value, and, depending
on which one is greater, the initial values of U (velocity vector field) and alpha (phase fraction
factor used in the VOF method [3]) in the boundary are corrected. This static boundary wave
generator is combined with active wave absorption, and by thus, dissipation zones are not needed,
and unnecessary water level increase is avoided. The methodology is detailed in [10; 11]. The
pressure is calculated within the numerical model whilst the values of the velocity fields and the free
surface elevation are corrected in the wave generation patch according to the wave theory applied.
The free surface is measured at each time step and compared to the theoretical value, and, depending
which one is greater, corrections are done at the patch and the values of U and alpha are updated
to these corrections.

Case setup and running


Now, in order to build our tutorial case, we are starting by copying the tutorial waveFlume and
rename it as waveFlume_NWT1:
run
cp -r $FOAM_TUTORIALS/multiphase/interFoam/laminar/waveExampleStokesI waveFlume_NWT2

Mesh
For the mesh generation we are going to use the same option as the previous cases, blockMeshDict,
which produces a block-structured hexahedral mesh. In here, the domain of the NWT is set as
atmosphere only and the water will be included using the setFields application. Below, the vertices
show that our NWT has dimensions of 25.0 x 0.1 x 1.2 m (the short distance -one-cell- in the z-
direction indicates a 2D case). The next sections of the blockMeshDict are the same as explained
in section 1.2.2.

24
3.2. IHFOAM CHAPTER 3. WAVE SIMULATION

Now, to set the water depth of the NWT the water volume is initiated using setFields, for this, in
the setFieldsDict we set the water depth to 1.2 m:

Waves
For setting up the wave parameters we open the file waveProperties in the constant folder. Inside
this file we can include the average depth, the wave period, the wave height and the wave theory to
be applied (for this case we are using the first order wave theory, named here StokesI):

Boundary Conditions
Below are the boundary conditions applied in each patch of the NWT and which are located in the
0.org folder:

25
3.3. WAVE PASS THROUGH A FIXED PLATE CHAPTER 3. WAVE SIMULATION

Boundary alpha.water p-rgh/pd U


inlet waveAlpha zeroGradient waveVelocity
outlet zeroGradient zeroGradient waveVelocity
bottom zeroGradient zeroGradient fixedValue
atmosphere inletOutlet totalPressure pressureInletOutletVelocity
sides empty empty empty

Table 3.2: Boundary Conditions

Simulation
Now to run the model we execute the file ./Allrun:

run
cd waveFlume_NWT2
./Allrun
We should have now the processors employed to run this case (2) as well as the log files of each
application in our example window as it is shown below. To divide the domain into smaller sub-
domains into which the solutions are being solved decrease the total time of simulation, this is called
Parallelisation, which is addressed in another Chapter of these guidelines.

Post-processing
Same as in Page 23

3.3 Wave pass through a fixed plate


The study case used in this tutorial includes a Numerical Wave Tank (NWT) with a fixed vertical
plate located near its mid-section. In the Figure below are shown the dimensions of the plate as
well as the ones of the NWT. As for the characteristics of the regular wave used for the example,
the length is 5.5 m, the height is 0.1 m and the wave period is 2.0 s; the conditions are considered
for intermediate water depth.

Figure 3.5: Dimensions of the NWT and fixed vertical plate

For the wave generation at the inlet and wave absorption at the outlet a relaxation zone technique in
waves2Foam is used. The details of the wave generation have been introduced in the former section.
Now, in order to build our example case, we are starting by copying the tutorial waveFlume and
rename it as waveFlume Example:

26
3.3. WAVE PASS THROUGH A FIXED PLATE CHAPTER 3. WAVE SIMULATION

run
cd ../applications/utilities/waves2foam/tutorials/waveFoam/
cp -r waveFlume waveFlume Example

Mesh Generation
For the mesh generation of NWT, we are going to use the same option as the one in the former case of
waveFlume NWT1, blockMeshDict, which produces a block-structured hexahedral mesh. The only
difference is that here a patch for an object (a fixed plate) inside the NWT needs to be included.

In the case of the fixed object inside the NWT, we are going to create the patch using the topoSetDict
as it is shown below. This file must be in the folder called system. Please download it from the
folder Wave Generation in the Dropbox link shared for the course. In the case of this patch, the
geometry of the object is a rectangle (with the boxToCell selection, but other options are available,
check https://openfoamwiki.net/index.php/TopoSet ). Then, the dimensions of the plate would be
0.05 x 0.50 x 0.1 m. What this will do is to create a void geometry whose sides will be acting as
walls, in the limits we set of the bounding box.

27
3.3. WAVE PASS THROUGH A FIXED PLATE CHAPTER 3. WAVE SIMULATION

Wave Generation For setting up the wave parameters, inside the constant folder, we will open
waveProperties.input file. Inside this file we can include the average depth, the wave period, the
wave height, the relaxation zones dimensions and characteristics and the wave theory applied to its
generation. For this case, we are using the first order wave theory, named here stokesFirst, which is
same as the former waveFlum NWT1 tutorial.
Boundary Conditions In the case of the BCs of the cell faces we must include the created fixedPlate
patch in each one of the files of the 0.org folder, as it is highlighted below:

Boundary name alpha1 p-rgh/pd U


inlet waveAlpha zeroGradient waveVelocity
outlet zeroGradient zeroGradient fixedValue
bottom zeroGradient zeroGradient fixedValue
atmosphere inletOutlet totalPressure pressureInletOutletVelocity
frontBack empty empty empty
fixedPlate zeroGradient fixedFluxPressure fixedValue

Simulation First, we need to enter through the window terminal to the folder
waveFlume Example:

run
cd ../applications/utilities/waves2foam/tutorials/waveFoam
/waveFlume Example
gedit Allrun

The text file to execute the simulation of the model will be opened. Below the line of meshing
we are going to include the lines for running the topoSetDict:

runApplication topoSet
runApplication subsetMesh -overwrite c0 -patch fixedPlate

After this, we save and close the file and go back to the window terminal. We execute the command:

./Allrun

We should have new folders of each time step as well the log files of each application in our ex-
ample window as it is shown below.

28
3.3. WAVE PASS THROUGH A FIXED PLATE CHAPTER 3. WAVE SIMULATION

Post-Processing
First create the dummy file foam.foam and then open it in Paraview, as in the previous examples.
This is the image you will get:

Now, we are going to see some of the results of the free surface elevation obtained and measured in
the front and rear of the fixed plate (See Page 23).

29
Chapter 4

Fluid-Structure Interaction

In previous simulations, fluid-induced solid deformation is negligible, and the solid is commonly
assumed as rigid, so we only obtain the solution of the fluid field. However, when considerable solid
deformation occurs, FSI approach is required to solve both fluid and solid mechanics.

4.1 Preparation: stress-analysis


To solve an FSI problem with OpenFOAM, this section will present how to solve solid mechan-
ics in OpenFOAM, as a preparation. The tutorial case we are using is plateHole, stored under
tutorials/stressAnalysis/solidDisplacementFoam/plateHole.

The case conducts the structural analysis of a square plate with a circular hole at its centre. It is
loaded with a uniform traction of σ = 10 kPa over its left and right faces

According to the symmetry, only one quarter of the plate was taken into calculation, to save com-
putational costs. The mesh and boundary conditions of the case were defined as below.

30
4.1. PREPARATION: STRESS-ANALYSIS
CHAPTER 4. FLUID-STRUCTURE INTERACTION

The mechanical properties of the solid is defined in mechanicalProperties, including density, Pois-
son’s ratio and Young’s modulus.

31
4.2. INSTALLATION(FSI) CHAPTER 4. FLUID-STRUCTURE INTERACTION

The results are presented as the displacement of each cell (D). By varying the Young’s modulus
(E) of the plate, it can be observed (with the filter wrap by vector) that considerable deformation
occurs with a small Young’s modulus applied.
More details please see: https://www.openfoam.com/documentation/tutorial-guide/tutorialse9.
php#x16-830005.1.

Figure 4.1: Structural response of the plate. Left: E = 2e11 Pa; Right: E = 2e5 Pa.

In the above case, the load on the solid body was applied by boundary conditions, i.e. a specific
traction value was set on the solid boundaries. However, in an FSI problem, the load on the solid
body is usually unknown. We need to solve the fluid field first, get the fluid load on the solid, and
then the solid solver can solve the solid mechanism. In OpenFOAM, such a process can be preformed
via fsiFoam, an opensource FSI solver developed by Tukovic et al. [12; 13]. Next, we will introduce
how to install and use fsiFoam.

4.2 Installation(FSI)
fsiFoam needs to be installed on foam-extend, which is the extended/advanced version of openFOAM
that developed by active contributors. To conduct FSI simulations, this section first provides in-
structions on installing foam-extend and fsiFoam.

4.2.1 foam-extend
foam-extend is a different version to the original openFOAM. First, we need to revise the bashrc file
(the commands that will automatically execute when you open a terminal):
1. open the bashrc file by: go to the home direcotory, ctrl+H to show hiden files, open .bashrc
2. in the file, REMOVE the line for initialising openFOAM
source /opt/openfoam4/etc/bashrc
AND ADD
alias of40='source ../../opt/openfoam4/etc/bashrc'
3. ADD one line under the last line for initialising foam-extend:
alias fe40='source $HOME/foam/foam-extend-4.0/etc/bashrc'

Thus, when you open a new terminal, type of40 to use openFoam 4.0, type fe40 to use foam-
extend 4.0. Otherwise, these two versions will interrupt each other.

The steps to install foam-extend 4.0 are outlined as below. (based on the notes given by Prof
Hakan Nillson)
1. Install dependences, Open new terminal window and execute the following commands. (line-
by-line, since you have to type your password on the ”sudo” lines, and also agree to do the

32
4.2. INSTALLATION(FSI) CHAPTER 4. FLUID-STRUCTURE INTERACTION

installations by typing Y)
sudo apt-get install git-core build-essential binutils-dev cmake flex
sudo apt-get install zlib1g-dev qt4-dev-tools libqt4-dev libncurses5-dev libiberty-dev
sudo apt-get install libxt-dev rpm mercurial graphviz python python-dev
sudo apt-get install openmpi-bin libopenmpi-dev
sudo apt-get install paraview

2. Download it
mkdir $HOME/foam
cd $HOME/foam
git clone git://git.code.sf.net/p/foam-extend/foam-extend-4.0 foam-extend-4.0

3. Some changes to the installation procedure to save time and disk:


echo "export WM_THIRD_PARTY_USE_BISON_27=1" > etc/prefs.sh
echo "export WM_MPLIB=SYSTEMOPENMPI" >> etc/prefs.sh
echo "export OPENMPI_DIR=/usr" >> etc/prefs.sh
echo "export OPENMPI_BIN_DIR=\$OPENMPI_DIR/bin" >> etc/prefs.sh

4. Complie
source etc/bashrc
./Allwmake.firstInstall (this step takes hours)

5. Make a user derectory


mkdir -p $FOAM_RUN

4.2.2 fsiFoam
1. Download the package (oepn a terminal and use fe40 to initialise foam-extend)
mkdir -p $WM_PROJECT_USER_DIR
cd $WM_PROJECT_USER_DIR
wget https://openfoamwiki.net/images/d/d6/Fsi_40.tar.gz
tar -xzf Fsi_40.tar.gz

2. Compile
cd FluidSolidInteraction/src
./Allwmake
3. Then, before we try running the tutorial cases, we need to fix a few dependencies (note, be-
tween ”do” and ”done”, the two ”sed” commands are both end with ”item” in the second
line):
cd ..
find run -name options | while read item
do
sed -i -e 's=$(WM_PROJECT_DIR)/applications/solvers/FSI=$(WM_PROJECT_USER_DIR)/
FluidSolidInteraction/src=' $item
sed -i -e 's=$(WM_THIRD_PARTY_DIR)/packages/eigen3=$(WM_PROJECT_USER_DIR)/
FluidSolidInteraction/src/ThirdParty/eigen3=' $item
done
4. Fix some bugs
Open $WM_PROJECT_DIR/src/finiteVolume/finiteVolume/fvSchemes/fvSchemes.C,

33
4.3. FSI APPROACH CHAPTER 4. FLUID-STRUCTURE INTERACTION

uncomment the following lines (they should be commended, when you open the file).

Open $WM_PROJECT_DIR/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C, comment the


following lines.

and do:
cd $WM_PROJECT_DIR/src/finiteVolume
wmake libso

4.3 FSI approach


In fsiFoam, a partitioned algorithm is used to solve the FSI problem, which solves the fluid and
solid mechanism separately and links them together via the fluid-solid interface. In other words,
fsiFoam employs a fluid solver (e.g. icoFoam) to obtain the fluid field, and employs a solid solver
(e.g. solidDisplacementFoam) to solve the solid mechanism. Besides, an FSI scheme is used to link
the fluid solution and solid solution. The process is illustrated as below.

34
4.4. FSI TUTORIAL CHAPTER 4. FLUID-STRUCTURE INTERACTION

4.4 FSI tutorial


Here we use a tutorial to demonstrate how to conduct an FSI simulation. The case is stored under
USER-DIRECTORY/FluidSolidInteraction/run/fsiFoam/beamInCrossFlow
The case consists of an elastic thick plate attached to the bottom surface of a rectangular channel.
The geometry of the spatial domain is given below. An incompressible viscous fluid enters the
channel from the left-hand side with a velocity that gradually increases [13].

4.4.1 Case structure


Since the fluid and solid parts are solved separately, they are defined in two folders. As shown in
the tree diagram below, the FSI case mainly consists of two parts: fluid and solid. Each of them
has its own 0, constant and system directory, as a common OpenFOAM case, and the “create-
Zones” and “setBatch” define the fluid/solid interface. The “makeLinks”, “makeSerialLinks” and
“removeSerialLinks” files manage the link between the fluid and solid. The “Allrun” and “Allclean”
files are located in the fluid part, and the “AllrunPar” file is used for parallel computation. During
the process of an FSI simulation, only the fluid part needs to be executed, because the solid part
will be called automatically over each timestep.

[A FSI CASE]
|-- fluid
|-- |-- 0
|-- |-- Allclean
|-- |-- Allrun
|-- |-- AllrunPar
|-- |-- constant
|-- |-- createZones
|-- |-- setBatch
|-- |-- system
|-- makeLinks
|-- makeSerialLinks
|-- removeSerialLinks
|-- solid
|-- 0
|--constant
|-- createZones
|-- setBatch
|-- system

35
4.4. FSI TUTORIAL CHAPTER 4. FLUID-STRUCTURE INTERACTION

4.4.2 Mesh
The mesh of an FSI case also contains two parts, i.e. fluid mesh and solid mesh, defined separately in
their constant/polyMesh/blockMeshDict. The fluid mesh and solid mesh must match each other
through their interface and compose a whole computational domain, as shown in Figure 4.2.
An interface boundary condition has to be defined in both the fluid and solid mesh. Moreover,
the interface in fluid mesh and the interface in solid mesh have to be at a same location. Through
the interface, the loads of fluid on solid is outputted to the solid solver and converted into the
displacement of the solid surface.

Figure 4.2: Fluid mesh, solid mesh and the integral mesh. (Blue: fluid field; Red: interface; Grey: Solid
field)

4.4.3 Simulation
Running the case with ./Allrun
(If you are using this case for the first time, you need to do:)
sed -i s/tcsh/sh/g *Links
./removeSerialLinks fluid solid
./makeSerialLinks fluid solid
cd fluid
./Allclean
./Allrun

Use paraview to view the results and it can be seen that obvious deformation of the solid body
has been simulated (upper: t=0s; lower: t=10s).

36
4.5. WAVE-INDUCED FSI PROBLEMS CHAPTER 4. FLUID-STRUCTURE INTERACTION

4.5 Wave-induced FSI problems


Last section introduced how to conduct an FSI simulation via fsiFoam. However, the fsiFoam
package that we can download from public domain has not included a multiphase library, which
means it cannot be used to simulate the FSI problems containing free-surface modelling. In order
to investigate the FSI problems in maritime/ocean field, e.g. [14], this section will develop the code
of fsiFoam. Specifically, we will compose three solvers: fsiFoam, interDyMFoam and waves2Foam.

4.5.1 Code development


The development route of this work is shown below, where the original FSI package will first be
extended into two-phase (fsiFoam+interDyMFoam) and then be endowed the capability of generating
a target wave field (fsiFoam+interDyMFoam+waves2Foam).

To extend the FSI package from single-phase to two-phase, essentially it is to build a new free-surface
fluid library beside other existing fluid libraries, e.g. pisoFluid, icoFluid. The fluid libraries of
FSI package are stored under src/fluidSolidInteraction/fluidSolvers/. For this purpose, the
code of interDyMFoam will be transplanted as a new two-phase fluid library under the fluidSolvers
directory, which will be named as “interFluid”.
The coupling of waves2Foam with FSI package is divided into two parts: on the one hand, to build
a new solver that can call both waves2Foam package and FSI package, named waveFsiFoam; on the
other hand, to include necessary wave objects into interFluid,named waveInterFluid.

37
4.5. WAVE-INDUCED FSI PROBLEMS CHAPTER 4. FLUID-STRUCTURE INTERACTION

Detailed steps can be found at [15]:


http://www.tfd.chalmers.se/~hani/kurser/OS_CFD_2017/LuofengHuang/2017_OSCFD_Report_
Luofeng.pdf

4.5.2 Tutorial
Here we provide a tutorial of how to use the developed solver, waveFsiFoam, to run a wave-induced
FSI case: beamInWave.
First of all, we need to modify the case file of “beamInCrossFlow” as follows.

Boundary conditions
Compared with the original “beamInCrossFlow” case , the following revises are required under
fluid/0/ :
1. Copy the alpha1.org file from the tutorial case “damBreakWithoutObstacle” (within the instal-
lation of foam-extend 4.0), so that the VOF method will divide the domain into two phase.
2. Rename the pressure field from p to pd; Revise its outlet boundary into a zeroGradient condition
and its top boundary into a totalPressure (typically used to model the atmosphere) condition.
3. To generate waves at the inlet boundary, the inlet boundary conditions of volume fraction
alpha1.org and velocity U are set as waveAlpha and waveVelocity respectively, which are the
boundary conditions installed with the waves2Foam package.
For alpha1.org
inlet
{
type waveAlpha;
refValue uniform 0;
refGrad uniform 0;
valueFraction uniform 1;
value uniform 0;
}
For U
inlet
{
type waveVelocity;
refValue uniform ( 0 0 0 );
refGradient uniform ( 0 0 0 );
valueFraction uniform 1;
value uniform ( 0 0 0 );
}

Constant
Compared with the original “beamInCrossFlow” case, the following revises are required under
fluid/constant/ :
1. In fluidProperties, set the “fluidslover” as waveInterFluid (this step calls the new fluid library
developed in this study), also change the following “fluidcoeffs” value into waveInterFluidCoeffs.
2. Replace the transportProperties file by that of the tutorial case “damBreakWithoutObsta-
cle”.
3. Copy waveProperties.input from the toturial case “waveFlume”, as well as the g file and
RASproperties file. Adjust the “sealevel” and other wave parameters according to the geometry.

38
4.5. WAVE-INDUCED FSI PROBLEMS CHAPTER 4. FLUID-STRUCTURE INTERACTION

System and Allrun


Compared with the original “beamInCrossFlow” case, the following revises are required under
fluid/system/ :
1. In controlDict, change the “application” value into waveFsiFoam (this step calls the developed
new solver) and comment the previous object functions.
2. Replace the fvSchemes file and fvSolution file by those of the tutorial case “damBreakWith-
outObstacle”, and revise the pressure field of the two files from p to pd.

To run the case by the command “./Allrun”, the fluid/Allrun file needs to be revised as be-
low:

• Allrun:line 21-30

cd fluid
cp 0/alpha1.org 0/alpha1

runApplication setWaveParameters
runApplication setWaveField

runApplication $application

# ----------------------------------------------------------------- end-of-file

The utility setWaveParameters is a pre-processing utility, which computes all the necessary wave
parameters based on physical meaningful properties, e.g. setWaveParametes converts information
on water depth and wave period into a wave number for first order Stokes wave theory. In this step,
it will load the constant/waveProperties.input and output the processed data into a new file,
constant/waveProperties .
The utility setWaveField is used to set the initial conditions according to a user defined wave the-
ory, which is defined by the keyword “initializationName” in the file waveProperties.input (see
Section 2.3).
The last step calls the solver waveFsiFoam, as defined by “getAppapplication” in fluid/controlDict.
Thus, the new solver waveFsiFoam will solve the case.

Figure 4.3: The interaction of the beam with incoming waves: when the beam is hit by a wave crest, it
deforms forward (above); when the beam is hit by a wave trough, it deforms backward (below).

39
Reference

[1] Jasak H, Jemcov A, Tukovic Z, et al. OpenFOAM: A C++ library for complex physics simu-
lations. In: International workshop on coupled methods in numerical dynamics. vol. 1000. IUC
Dubrovnik, Croatia; 2007. p. 1–20.
[2] Weller HG, Tabor G, Jasak H, Fureby C. A tensorial approach to computational continuum
mechanics using object-oriented techniques. Computers in physics. 1998;12(6):620–631.

[3] Hirt CW, Nichols BD. Volume of fluid (VOF) method for the dynamics of free boundaries.
Journal of computational physics. 1981;39(1):201–225.
[4] Moctar Oe, Shigunov V, Zorn T. Duisburg Test Case: Post-panamax container ship for bench-
marking. Ship Technology Research. 2012;59(3):50–64.

[5] Jacobsen NG, Fuhrman DR, Fredsøe J. A Wave Generation Toolbox for the Open-Source
CFD Library: OpenFoam .R International Journal for Numerical Methods in Fluids.
2012;70(9):1073–1088.
[6] Higuera P, Lara JL, Losada IJ. Realistic wave generation and active wave absorption for
Navier–Stokes models: Application to OpenFOAM .R Coastal Engineering. 2013;71:102–118.

[7] Jacobsen N. waves2Foam Manual. Deltares, The Netherlands. 2017;.


[8] Mayer S, Garapon A, Sørensen LS. A fractional step method for unsteady free-surface flow
with applications to non-linear wave dynamics. International Journal for Numerical Methods
in Fluids. 1998;28(2):293–315.

[9] Bruinsma N. Validation and application of a fully nonlinear numerical wave tank (Master
Thesis, TU Delft). 2016;.
[10] Higuera P, Lara JL, Losada IJ. Three-dimensional interaction of waves and porous coastal
structures using OpenFOAM . R Part I: formulation and validation. Coastal Engineering.
2014;83:243–258.

[11] Higuera P, Lara JL, Losada IJ. Three-dimensional interaction of waves and porous coastal
structures using OpenFOAM .R Part II: Application. Coastal Engineering. 2014;83:259–270.

[12] Tukovic Z, Cardiff P, Karac A, Jasak H, Ivankovic A. OpenFOAM library for fluid structure
interaction. In: 9th OpenFOAM Workshop. vol. 2014; 2014. .

[13] Tukovic Z, Karac A, Cardiff P, Jasak H, Ivankovic A. OpenFOAM finite volume solver for
fluid-solid interaction. Tractions of FAMENA. 2018;.
[14] Huang L, Ren K, Li M, Tuković Ž, Cardiff P, Thomas G. Fluid-structure interaction of a large
ice sheet in waves. Ocean Engineering. 2019;182:102–111.

[15] Huang L. An opensource solver for wave-induced FSI problems. In Proceedings of CFD with-
OpenSource Software; 2018.

40
Appendix A

Coding tutorial

41
Appendix B

Tutorial: Flow passes a motorbike

60
Appendix C

Tutorial: Flow passes a cylinder

77
1

Figure 1: A typical von Karman vortex street behind a cylinder where hydrodgen bubbles
were used to highlight the flowfield (unpublished).

1. Introduction
In many engineering applications it is necessary to analyse a stationary or moving
object which is exposed to a uniform or turbulent flow, including automobile and plane
aerodynamics, ship and submarine hydrodynamics, flow past oil riser pipes, flow through
and around cities etc. The case that will be considered is the two-dimensional laminar
flow past a cylinder which exhibits many interesting flow features (see figure 1), that are
also present in more complex applications, including:
• boundary layer formation
• flow separation
• vortex shedding

In this tutorial the learning outcomes are:


• extract the the drag and lift coefficients on the cylinder
• pressure and friction coefficients on a bluff body
• take out velocity data in the flow domain
using the following Openfoam utilities
• forces object
• sample
• wallGradU
• probes
2

U∞ W

Figure 2: Schematic of the computational domain of width W to investigate the flow past
a cylinder (of diameter D). The inlet boundary condition is u = {U∞ , 0}. The side walls
have the no flux condition and zero shear condition. The cylinder boundary condition
has the no flux and no-slip conditions (u = 0) applied it.

1.1. Problem statement


A schematic of the problem is shown in figure 2, where a cylinder (diameter D) is placed
20D from the inlet in a domain of width W = 40D. The inlet boundary condition is
u = {u, v} = {U∞ , 0}. The side walls have the no flux condition and zero shear condition.
The cylinder boundary condition has the no flux and no-slip conditions (u = 0) applied
it and the normal gradient of the pressure is zero. The non-dimensional number that
controls this physical system is the Reynolds number, Re = U∞ D/ν where ν is the
kinematic viscosity. θ is taken from the front stagnation point.

1.2. Definition of diagnostics


The force on a body is defined as
Z
F = (pI − τ ) · n̂dS,
S

where S is the surface of the body, p is the pressure, I is the identity matrix, τ is the
viscous stress tensor and n̂ is the normal pointing out of the fluid domain (Batchelor
1957). Note, a bold F indicates that it is a vector quantity, while the pressure is a scalar
and therefore is not bold.
The mean and root mean square of a time series ξ(t) are defined as
Z T2 s Z T2
ξ¯ 1 ξ0 1 ¯ 2 dt.
= ξdt, = |ξ − ξ| (1.1)
D T2 − T1 T1 D T2 − T1 T1
In this work the time series (τ = tU∞ /D) of interest are the drag and lift coefficient
which are the force coefficients in the streamwise and cross-stream direction, defined as
1
FD (τ ) FL (τ )
CD (τ ) = 2 A
, CL (τ ) = 2 A
.
1/2ρU∞ 1/2ρU∞
where A is a reference area. The force on a body is composed of a pressure and shear
stress component, therefore it is insightful to also consider the pressure coefficient and
3
friction coefficient on the surface of the body. The pressure coefficient is defined as
p − p∞
Cp = 2
,
1/2ρU∞
where p∞ is the free stream pressure. The potential flow solution for the pressure coeffi-
cient on the surface of the cylinder is given by
Cp = 2 cos(2θ) − 1,
which provides a point of comparison. The friction coefficient is defined as
τw
Cf = 2
,
1/2ρU∞
where the wall shear stress τw is
∂us
τw = µ , (1.2)
∂n
where us = −u sin θ + v cos θ is the tangential velocity and n is the normal. Therefore,
∂us ∂u ∂v
=− sin θ + cos θ. (1.3)
∂n ∂n ∂n
This diagnostic is also of interest as flow separation occurs at τw = 0.
4
1.3. Understanding the case files
The following section will go through the important aspects of the all the casefiles in the
three folders ’0’, ’constant’ and ’system’. Additionally, at the end, is a brief description
of the utility ’WallGradU’.

1.3.1. 0

U
The inlet is set to u = {U∞ , 0} where U∞ = 1. The no slip condition is applied to the
cylinder. As two-dimensional simulations are carried out the boundaries ’frontandback’
are set to ’empty’. The top and bottom are taken to be symmetry planes (for these
boundaries the normal and normal gradient of u are set to zero).
p
On the cylinder the boundary condition is that the normal gradient of the pressure is
zero. For the inlet and outlet the pressure is set to the freestream value. Again, as two-
dimensional simulations are carried out the boundaries ’frontandback’ are set to ’empty’.
The top and bottom are taken to be symmetry planes (for these boundaries the normal
and normal gradient of p are set to zero).

1.3.2. constant

RASProperties
The Reynolds averaged stress Model (RASModel) is set to laminar as Re = 100.

transportProperties
The diameter of the cylinder is D = 0.1 and the inlet flow is set to U∞ = 1. Therefore
to have Re = 100, the kinematic viscosity is set to ν = 0.001.

blockMesh

The mesh is already present in ’constant’ folder and is defined in the file ’constant/poly-
Mesh/blockMesh’. The no-slip condition on the cylinder surface results in the formation
of a boundary layer adjacent to the cylinder where the flow varies rapidly from zero to
the freestream (in the radial direction). As the Reynolds number in the boundary layer
must be O(1), an estimate of the thickness δ can be made:
δ ∼ DRe−1/2 .
As a rule of thumb it is advised to have ten elements across the boundary layer to resolve
it and so, the above estimate is helpful in determining the smallest element size. This
rapid variation is only in the radial direction, the variation in the azimuthal direction is
more gradual and so the finer resolution is only required in the radial direction.
Note in the ’blockMesh’ file that the cylinder is defined as ’type wall’. This ensures
that it is possible to use the ’wallGradU’ utility later on.
5
1.3.3. system

controlDict

The standard aspects of the file ’controlDict’ have already been covered in a previous
tutorial. The following code takes out the force on the body (denoted by cylinder in the
blockMesh file). The ’outputInterval’ determines how often the force is written to file and
can be varied if long simulations are being carried out. In setting our Reynolds number
the kinematic viscosity was set. Here we see that one needs to define the density ρ∞ ,
which is set to unity such that µ = ν. The ’CoR’ is the centre of rotation and needs to
be set appropriately for calculating moments on the cylinder.
forces_cylinder_1
{
type forces;
functionObjectLibs ("libforces.so");
outputControl timeStep;
outputInterval 1;
patches (cylinder);
rhoName rhoInf;
pName p;
UName U;
rhoInf 1;
CofR (0 0 0); ;
}

Forces are collated in the files in ’postProcessing/forcesc ylinder1 /0/f orces.dat0 .T hef ormatof theoutputisthef ollowi

T ime Fpx Fpy Fpz Fνx Fνy Fνz Fporx Fpory Fporz
| {z } | {z } | {z }
P ressure V iscous P orous

Mpx Mpy Mpz Mνx Mνy Mνz Mporx Mpory Mporz


| {z } | {z } | {z }
P ressure V iscous P orous
The following code takes out the velocity and pressure at all the locations under ’pro-
beLocations’ every tenth time step. Care must be taken here as if many points are chosen
and long simulations are run, the data that is collected can be massive.
probes1
{

type probes;

functionObjectLibs ("libsampling.so");

//dictionary probesDict;

writeInterval 10;

region region0;

probeLocations
6
(
(1.5 -1 0)
...
(1.5 1 0)
);

fields
(
p
U
);

}
It is also possible to use the utility probes as a postprocessing tool by running the
command ’postProcess -func probes’.

sampleDict

The ’sample’ utility (called by printing ’sample’ in the command line in the main
directory) allows one to extract data from the time files. Two different types of data can
be extracted - sets and surfaces. In this tutorial only the latter will be covered. Below
is an extract from the file ’system/sampleDict’, which indicates that the pressure should
be taken out at the cylinder surface.

surfaces
(
cylinder
{
type patch;
patches (cylinder);
}
);

fields
(
p
);

The files are output in the folder ’postProcessing/surfaces/TIMES’. The output from
this file

# p FACE_DATA 160
# x y z p
0.0346477 0.0360357 0 0
...
where the values printed are described on the second line. In this case it is the Cartesian
coordinate of the cell centre (x, y, z) and the pressure at that point.
7
’wallGradU’

The wallGradU utility (called by printing ’wallGradU’ in the command line in the
main directory) can be used to calculate velocity gradient normal to the surface of the
cylinder. This will only be calculated on surfaces which were defined as ’type wall’ in the
’blockMesh’ file. The files are output in the main directory for that time (i.e. ’0’ etc.). A
section of the output for this

outlet
{
type calculated;
value uniform (0 0 0);
}

cylinder
{
type calculated;
value nonuniform List<vector>
160
(
(-8.82272 8.60517 -2.908e-16)
...

In this case, there are 160 values of the gradient of the velocity which corresponds to
the number of cells on the cylinder surface. The three values shown are:
∂u ∂v ∂w
, , .
∂n ∂n ∂n

1.4. Tutorial steps


The impulsively started flow past a cylinder at Re = 100 results in a wake bubble forming
behind the cylinder, which can be seen in figure 3. This will eventually go unstable and
then the flow will proceed into a quasi-steady regime of von Karman vortex shedding,
shown in figure 3.
As the simulation takes some time to run, there are two time files in the directory,
namely ’0’ and ’100’. The simulation can therefore be started at 0, to capture the transient
and the quasi-steady state or can be started after τ = 100 to only analyse the periodic
vortex shedding. This can be controlled in the file ’/system/controlDict’ through the
parameter ’startTime’ and stopAt’. For this tutorial we will only consider the periodic
regime and so the ’startTime’ and ’stopAt’ are set to 100 and 105 respectively. The
choice of end time has been determined by looking at the forces on the cylinder which
shows that a time period of 5 is approximately 15 periods which is sufficiently long for
velocity averaging. Note: for turbulent flows one might require much longer time series
for averaging. The commands to run the code are:
icoFoam
wallGradU
sample
These commands show that we can differentiate between runtime diagnostics and post-
processing diagnostics. In the current case, the runtime diagnostics are (i) the forces on
the cylinder and (ii) the velocity probes, whereas postprocessing diagnostics are cylinder
8

(a)

(b)

Figure 3: Vorticity field at τ = 15 showing a symmetrical recirculation region (highlighted


by the streamlines) behind the cylinder which results in zero lift. This will eventually go
unstable τ ≈ 50, which result in a von Karman vortex street behind the cylinder, which
can be seen in (b). Vorticity is shown in (a) and (b), ranging from -0.2 (blue) to zero
(green) to 0.2 (yellow).

surface pressure and velocity gradient measurements. To plot out the diagnostics, Mat-
lab is used and the code has been provided in the folder ’Analysis’ to plot out the data.
Forces files are in in the folder ’postProcessing/forcesc ylinder1/0/’. Once you have run
the code from ’100’ to ’105’, there will be a new folder in here, ’100’, which will have the
force data for that run. Copy/paste the ’forces.dat’ file into your ’Analysis/Forces’ folder
and run the following command in Matlab
plot_forces
The file ’wallGradU’ can be found in the time folders in the main directory. Copy-
/paste this into the folder ’Analysis/Cf’. Additionally you will need to copy/paste the
file ’postProcessing/surfaces/0/pcylinder.raw’ into ’Analysis/Cf’ and run the following
command in Matlab
c_f_plot
Copy/paste the file ’postProcessing/surfaces/0/pcylinder.raw’ into ’Analysis/Cp’ and
run the following command in Matlab
c_p_plot
Sample outputs for the time series of the drag and lift coefficient are shown in figure
4 and additionally the pressure and friction coefficient are shown in figure 5.
Note: as the probes generate a lot of data, this functionality should be turned off if
the simulation is started from the beginning.
Things to consider in the future:
• Mesh independence study - try varying the size of the mesh in the wake to fully
resolve the shed vortices from the cylinder. Does this affect the drag and lift coefficients?
• Calculate the mean, rms and Strouhal number of the drag and lift coefficients
References
Batchelor, G.K. (1957) An introduction to fluid dynamics. Cambridge University Press.
Dimopoulous, H.G. & Hanratty, T.J. (1968) Velocity gradients at the wall for flow
around a cylinder for Reynolds number between 60 and 360. J. Fluid Mech. 33 303-319.
Homann, F. (1936) Influence of higher viscosity on flow around cylinder. Forsch. Ge-
biete Ingenieur. 17
Rajani, B.N., Kandasamy, A. & Majumdar, S. (2009) Numerical simulation of laminar
flow past a circular cylinder. App. Math. Mod. 33 1228-1247.
9
1.5 0.5

0.4

0.3

0.2
1
0.1

-0.1
0.5
-0.2

-0.3

-0.4

0 -0.5
0 50 100 150 200 250 0 50 100 150 200 250

Figure 4: Time series of the (a) drag and (b) lift coefficient.
0.5 1.5

1
0.4
0.5

0.3 0

-0.5
0.2
-1

0.1 -1.5

-2
0
-2.5

-0.1 -3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Figure 5: Surface profiles of the mean (a) friction and (b) pressure coefficient. In (a) the
present simulations (black line), the experiments by Dimopoulous & Hanratty (1968)
(◦) (Re = 104) and the numerical simulations of Rajani et al. (2009) (red line) are
shown. In (b) the present simulations (black line), the experiments by Homann (1936)
(◦) (Re = 107), the numerical simulations of Rajani et al. (2009) (red line) and the
analytical solution for a potential flow (dashed line) are shown. The front stagnation
point is at zero radians.

Williamson, C.H.K. (1996) Vortex dynamics in the cylinder wakes. Ann. Rev. Fluid
Mech. 28 477-539.
Zdravkovich, M. (1997) Flow around circular cylinders. Oxford Science Publication.
Appendix D

Tutorial: Develop a turbulent


model

87
Appendix E

Tutorial: Parallelisation and HPC

114
Chapter 1

Parallel running

In order to decrease the time to run a computational simulation, the numerical domain
can be divided into sub-domains, in which the governing equations will be solved for the
fluid pressure and velocity, this is called parallelisation. This procedure is done using
the OpenFOAM tools: decomposePar (for the domain partition in sub-domains) and
reconstrucPar (for building/connecting the whole domain from the sub-domains).

The domain decomposition performed in OpenFOAM is done by breaking the geometrical


and associated fields to smalls sub-domains and assigning each one to a processor. This
option is already available in OpenFOAM for most of the solvers/utilities, but you do need
MPI (message passing interface) library installed (mpirun command) and for this you can
check the Wiki installation site (https://openfoamwiki.net/index.php/Main Page) of the
programme version you desire to use. The utilities that are not supported to run in parallel
are those used for the parallelisation, such as decomposePar and reconstructPar, and
the mesh generator blockMesh.

1.1 Cores/Processors availability

Before being able to do a parallelised simulation, you need to know how many processors/-
cores you can use or have available in your computer, and for this you type the following
line in the terminal window:

lscpu

You’ll see a similar description to the following:

In which you can determine the number of physical cores/processors you can use to de-
compose your case in, which in the current case would be 16 processors. The process of
parallelisation is done by:

1. Decomposing the domain into sub-domains

2. Running the simulation in parallel using openMPI

1
captionNumber of processors

3. Reconstructing the whole domain

1.2 Domain decomposition

Now for the domain decomposition using decomposePar command, the file decomposeParDict
within the system folder needs to be set up. The number of processors used in each
direction is defined in this dictionary along with the decomposition method available:
hierarchical, manual, metis, multilevel, none, scotch, simple and structured
(more information of each of the methods can be checked at the OpenFOAM page:
https://www.openfoam.com/documentation/guides/latest/doc/openfoam-guide-parallel.html.
From which the most used are the simple, scotch and hierarchical. According to the
method used, different specifications should be done, an example for these three methods
is later shown in the case study (damBreak tutorial).

The information in each processor folder (processorN) will contain the mesh information,
boundary conditions, initial conditions and solution of each sub-domain (N = 0, 1, 2,. . .
numberOfSubdomains\verb).

1.3 Running the case

When you run in parallel, the Allrun file should be modified to include the following line
(<NPROCS> = numberOfSubdomains):

mpirun \{np <NPROCS> <application/utility> \{parallel

Or, depending in the foam functions are already directed in the header, you can use:

runParallel $(getApplication)

2
1.4 Reconstructing the case

Following, to build the whole domain back to have continuous information and solution,
the command reconstrucPar is used. And the results are shown as in the previous case,
per time-step selected for the interval to be written (writeInterval).

1.5 Tutorial case parallel: damBreak

This is a two-dimensional multiphase tutorial case for incompressible fluids (water and
air) available in most of OpenFOAM versions. The dimensions of the domain is of 0.584 x
0.584 meters, in which a water column is “dropped” when the simulation begins, at time t
= 0 (remember all cases in OpenFOAM are dealt as three-dimensional, considering a unit
cell in the z-direction), as seen in the figure below.

Figure 1.1: damBreak case geometry (figure taken from


https://cfd.direct/openfoam/user-guide/v6-dambreak/)

The total simulation time is 1s, whilst the time-step, deltaT, is 0.001 s and the writeInterval
is 0.05 s. The solver used for this multiphase case is interFoam. The cell discretisation in
this case is of 46 x 50 x 1 cells in the x, y and z-directions, respectively (cell size of 0.012
x 0.011 x 0.100 m).

Additional relevant setup data, such as boundary and initial conditions, can be checked
following previous material given during the workshop.

Now to do the damBreak (or any case) we must edit or include the decomposeParDict file

3
in the system folder, first we copy the tutorial case in our run folder by:

run
cp -r $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak damBreak_Example
cd damBreak_Example

For this case, the simulation is executed using 1, 2, 4, 8 and 16 processors, and, applying the
simple, hierarchical and scotch decomposition methods, in order to compare the different
execution times the cases take and select the appropriate amount required.

To edit the file, we type the following in the command window:

cd system
nano decomposeParDict

For 8 processors the domain will be sub-divided in 4 pieces in the x-direction and 2 in
the z-direction, whilst for the 16 processors, it is a 4 x 4 system. In the case of the 4
processors, the domain is sub-divided in 2 pieces in the x- and y-directions, as for the 2
processors case it is a 2 x 1 system.

An example of how to set the 8 processors case for the hierarchical, simple and scotch
methods is done below (but for this tutorial we only include the information required for
the hierarchical method):

Figure 1.2: Hierarchical setup case

Figure 1.3: Simple setup case

Now, we need to edit the Allrun file as follows:

4
Figure 1.4: Scotch setup case

cd ..
nano Allrun

To the Allrun file we add:

runApplication decomposePar
runParallel $(getApplication)
runApplication reconstructPar

To run Allrun file, we put in the terminal window:

./Allrun

After the run is performed, we should have the following files in our folder (or very similar).

Figure 1.5: List of Folders and Results

We create the dummy file for Paraview visualisation foam.foam by:

nano foam.foam

Write “XYZ” followed by “CTRL+O” and “CTRL+X” to save it. The visualisation and
post-processing can be done using Paraview, for which the case should be selected to be
the reconstructed one (select Reconstructed Case in the dropdown menu from Case Type
in the Properties window on the left).

paraview foam.foam

The post-processing tools are the same as learned before during the workshop tutorials.
Now, we are going to evaluate the amount of processors that perform better for each
decomposition method (taking the simulation time from the log.interFoam files of each
cases). It can be seen in the table below that with 16 processors, the time taken to run
the cases increases considerably, therefore, using all of them, may not be a good idea for
this specific case.

Refining the mesh by its half it takes longer execution time (around 1600 s). Below is a
comparison of both cases at 0.30 s. As it was seen previously in the workshop, you should
also do a convergence mesh study.

5
Figure 1.6: Paraview window

Figure 1.7: Simulation time

Figure 1.8: Alpha water view (original and refined cases)

6
Chapter 2

High Performance Computing


(HPC) usage, based on UCL
Computing Systems

The UCL High Performance Computing (HPC) manages three HPC systems or platforms
available for researchers at UCL, these are Legion, Grace and Myriad, which you can choose
according to your computational requirements (the technical specifications of each of the
clusters can be found here https://wiki.rc.ucl.ac.uk/wiki/RC Systems). These clusters
run a software stack based upon Red Hat Enterprise Linux 7 and Son of Grid Engine and
can be used by UNIX-like operating system users. Grace for example has more than 684
nodes, each node has 16 cores in total that can be used. The Research Centre (RC) at
UCL are the ones in charge of giving the maintenance and addressing the concerns of the
users and they have drop-in sessions every two Tuesdays at the main campus. The first
step to use the HPC is to require access to the RC department, in which you state the
technical requirements and other specifications related to the research itself. For this, you
need to fill the form available in https://wiki.rc.ucl.ac.uk/wiki/Account Services.

2.1 Access

Once you have the user access to one of the cluster, you can enter from the terminal
window by typing (the examples given here are for the Grace cluster):

ssh <your_UCL_user_id>@grace.rc.ucl.ac.uk

Or, when requiring the graphic tools available for post-processing (using Paraview)

ssh -X <your_UCL_user_id>@grace.rc.ucl.ac.uk

Other way is to use PuTTY for Windows users and adding Exceed for the graphic util-
ity, which is the way will be presented during the workshop. To access outside UCL you
need to have IS VPN service accessed, and it will allow you to work with all the op-
tions mentioned above (UNIX and Windows). More information on this, can be found in

7
https://wiki.rc.ucl.ac.uk/wiki/Accessing RC Systems.

2.2 Modules

There are modules that are already loaded for all the users, which are the basic ones, to
see them you can type this in the HPC terminal window:

module list

Figure 2.1: Modules loaded by default

In which can already be recognised some, that are required for running OpenFOAM, such
as subversion, gerun and mpi, and other known utilities such as nano and nedit. To check
the programmes that are available, we type (in which we obtain a quite large list, in which
OpenFOAM is included):

module available

Figure 2.2: Modules Available (section of the list)

Among the software that are available are openfoam 2.4.0 and openfoamplus v1706. The
platforms are Linux based, therefore similar commands to those learnt in this course can
be used in their terminal windows. In order to know which utilities are required for
OpenFOAM and Paraview, we type:

module show openfoamplus

Figure 2.3: Details of openfoamplus module

module show paraview

8
Figure 2.4: Details of Paraview module

Now, in order to load these modules (for both programmes) we type:

module unload compilers


module unload mpi
module load gcc-libs
module load compilers/gnu/4.9.2
module load mpi/openmpi/1.10.1/gnu-4.9.2
module load openfoamplus/v1706/gnu-4.9.2
module load llvm/3.9.1
module load mesa/13.0.6/gnu-4.9.2
module load xorg-utils
module load paraview/5.3.0

2.3 HPC tutorial case: damBreak

Now, we are copying the case of the damBreak to our system, once you have access
to the HPC, you will have one folder called output, inside another one called Scratch
(which has larger storage, but is not backed up, more information on this can be found
in https://wiki.rc.ucl.ac.uk/wiki/Managing Data on RC Systems), and is in there, where
all your cases are going to be stored (and run).

cd Scratch/output
cp -r /shared/ucl/apps/openfoamplus/v1706/gnu-4.9.2/OpenFOAM-v1706/tutorials/multiphase/int
cd damBreak_Example2

In order to process the case (batch processing), we include the file script.sh, as follows:

nano script.sh

And to this empty file we include:

Then, we click “CTRL+O” and “CTRL+X” to save it.

Now, we change the number of processors in decomposeParDict as follows:

nano damBreak/system/decomposeParDict

Change numberOfSubdomains to 32 and method to scotch. Again, we click “CTRL+O”

9
Figure 2.5: Script for HPC Running

and “CTRL+X” to save it. For Grace cluster these are the maximum wallclock times
according to the required processors (https://wiki.rc.ucl.ac.uk/wiki/Resource Allocation):

Figure 2.6: Wallclock time (Grace Cluster)

Now, to submit the case for the job scheduler, type the command:

qsub script.sh

To check the status of the case, the following is used (12345 represents the number assigned
to the simulation once is submitted):

qstat -f -j 12345

To erase the simulation while in the batch processing, we type:

qdel 12345

10
It is important to know two things, first, that the selection of the cases simulated is not in
order of submission (check job scheduler in https://wiki.rc.ucl.ac.uk/wiki/Legion Scheduler)
and second, it is very important to select the correct amount of time and processors to run
the simulation because this is an important factor to select the cases to be simulated in the
queue. To get and send data from the personal computer to the HPC you can use the fol-
lowing commands (available in https://wiki.rc.ucl.ac.uk/wiki/Managing Data on RC Systems):

Figure 2.7: Copy-paste commands for interaction HPC-desktop

You can also do changes to the certain solvers/utilities/codes, and compile them normally
as you would do in your personal computer, just verify the location with the module show
option. The information for this section was based on the website of the Research Centre
of UCL: (https://www.ucl.ac.uk/research-it-services/research-computing-platforms).

11
Appendix F

Programme of the 2nd UCL


OpenFOAM Workshop

126
Programme of the 2nd UCL OpenFOAM Workshop

Day 1 (the 26th of June) - Venue: B40 LT, Darwin Building


9:00 - 9:45 Registration desk opens and audience in seats
9:50 – 10:00 Opening remarks, Luofeng Huang
10:00 - 11:00 Keynote speech: You will meet the founder of
OpenFOAM, from 1993 towards 2030 OpenFOAM, listening to his
Prof Hrvoje Jasak, principal developer of OpenFOAM stories and future expectation.
11:00 – 11:25 Theme speech 1: (Chair – Daniela Benites) You will know what has driven
Computational fluid dynamics of multi-body problems OpenFOAM to the position today,
Dr Christian Klettner, UCL teaching fellow what has been achieved, how are
11:25 – 11:50 Theme speech 2: (Chair – Shiyu Lyu) academia and industry using it.
Large Eddy Simulation of a channel with cavities You will see interesting examples
Dr Yeru Shang, Engineer at Mott MacDonald of how OpenFOAM simulates our
11:50 – 12:30 Round-table discussion (Chair – Tom Smith) real life.
Prof Hrvoje Jasak, Prof Giles Thomas,
Dr Christian Klettner, Dr Yeru Shang. A round-table discussion will be
12:30 – 12:55 Theme speech 3: (Chair – Bojan Igrec) performed, where four experts
Hydroelastic interaction between waves and ice will have interesting
Mr Luofeng Huang, UCL PhD communications around
12:55 – 13:00 Group Photo OpenFOAM. You can also ask
questions of your interests and
13:00 – 14:30 Networking Lunch
trigger their discussion.
Tutorial Session: (Chair – Daniela Benites)
14:30 – 15:30 OpenFOAM basis You will learn how OpenFOAM
Dr Rui Song, University of Liverpool work and its usage in varied
15:30 – 16:30 Fluid dynamics 1 simulations of fluid.
Dr Christian Klettner, UCL teaching fellow
16:30 – 17:30 Fluid dynamics 2 You will learn to how to use post-
Mr Tom Smith, UCL PhD processing to create a digital and
17:30 – 18:30 Fluid dynamics 3 precise view of fluid in our life,
Dr Yeru Shang, Engineer at Mott MacDonald e.g. air and water.

Day 2 (the 27th of June) - Venue: Anatomy B15, Medical Sciences and Anatomy
Tutorial Session: (Chair – Morning/Shiyu Lyu, Afternoon/Daniela Benites)
10:00 - 11:30 Ship hydrodynamics Step by step tutorials will be given
Mr Luofeng Huang, UCL PhD to teach the applications of
11:30 – 13:00 Wave modelling OpenFOAM in maritime and civil
Ms Daniela Benites, UCL PhD engineering. You will learn how to
14:00 – 15:30 Fluid-solid Interaction (rigid body) model ship advancement, ocean
Mr Shiyu Lyu, UCL PhD waves; how to solve vibration and
15:30 – 17:30 Solid Mechanics and Fluid-solid Interaction deformation of solids, as well as
(elastic body) their interactions with fluid.
Mr Minghao Li, Engineer at FsDynamics
Day 3 (the 28th of June) - Venue: G15 Public Cluster, DMS Watson Building
Tutorial Session: (Chair – Morning/Shiyu Lyu, Afternoon/Luofeng Huang)
10:00 - 11:00 Programming1: basis You will learn how to implement
Mr Tom Smith, UCL PhD extended functions based on
11:30 – 12:30 Programming2: implement functions OpenFOAM, also how to use high-
Mr Tom Smith, UCL PhD performance computation (HPC)
13:30 – 15:00 Programming3: implement a new solver power to speed up simulations.
Mr Minghao Li, Engineer at FsDynamics
15:00 – 16:00 Turbulence modelling With these advanced skills, you
Mr Tom Smith, UCL PhD will be able to simulate amazing
16:00 – 17:30 Parallel simulation and supercomputing turbulence and write your own
Ms Daniela Benites, UCL PhD solver for specific purposes.

*This activity is a Researcher-led Initiative that has been funded by UCL Organisational Development.

Department of Mechanical Engineering


University College London

Local committee:
Luofeng Huang
Daniela Benites
Shiyu Lyu
Tom Smith
Reading recommendations

1. OpenFOAM user guide


http://foam.sourceforge.net/docs/Guides-a4/OpenFOAMUserGuide-A4.pdf

2. Youtube channel of József Nagy, excellent tutorial-vedios to begin with:


https://www.youtube.com/channel/UCjdgpuxuAxH9BqheyE82Vvw?&ab_channel=J%C3%B3zsefNagy

3. OpenFOAM tutorials of Victor Pozzobon on Researchgate:


https://www.researchgate.net/project/OpenFOAM-Tutoring

4. Maric, T., Hopken, J. and Mooney, K., 2014. The OpenFOAM technology primer.
(first five chapters provide comprehensive OpenFOAM foundation)

5. Moukalled, F., Mangani, L. and Darwish, M., 2016. The finite volume method in computa-
tional fluid dynamics.
(the theoretical foundation of OpenFOAM)

6. ”15 days” OpenFOAM online course: https://wiki.openfoam.com/%223_weeks%22_series.

129
Acknowledgements

Leading the way


Professor Hrvoje Jasak (University of Zagreb)
Professor Giles Thomas (University College London)
Prof Håkan Nilsson (Chalmers University of Technology)
Prof Gavin Tabor (University of Exeter)
Dr Željko Tukovic (University of Zagreb)
Dr Vuko Vukcevic (University of Zagreb)
Dr Philip Cardiff (University College Dublin)

Logistical supports
Rochelle Rowe (UCL Doctoral Skills Team)
Kasia Bronk (UCL Doctoral Skills Team)
Emillia Brzozowska (UCL Doctoral Skills Team)
Sheetal Saujani (UCL Doctoral Skills Team)
Alexandra Grimova (UCL Mechanical Engineering Financial)
Martina Bertazzon (UCL Mechanical Engineering Financial)
Edward drinkwater (UCL Mechanical Engineering Financial)
Luke Kelly (UCL Mechanical Engineering Logistical)

Fighting together
Dimitris Stagonas (Cranfield University)
Rui Song (The university of Liverpool)
Alberto Alberello (The UUniversity of Adelaide)
Filippo Nelli (The University of Melbourne)
Sasan Tavakoli (The University of Melbourne)
Edward Ransley (University of Plymouth)
Pal Schmitt (Queen’s University Belfast)
Josh Davidson (Budapest University of T&E)
Yuzhu Li (Technical University of Denmark)
Azam Dolatshah (Swinburne University of Technology)
Peiying Sun (University of Sussex)
Bojan Igrec (UCL)
Thomas Peach (UCL)
Christopher Ryan (UCL)
Andrea GL Rosa (UCL)
Christopher-John Cassar (UCL)
Dian Fan (UCL)
Nathaniel Henman (UCL)
Katherine Wang (UCL)

130

You might also like