OpenFOAM Course Notes Release v1.0
OpenFOAM Course Notes Release v1.0
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
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.
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
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
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
A Coding tutorial 41
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)
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).
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.
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
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
3
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
blockMesh
icoFoam
paraFoam (Click on Apply, a square should appear in the window.)
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
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.
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
Every four vertices can form a face, which can be classified in the Boundary part:
6
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
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
8
Chapter 2
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.
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 ).
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
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.
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
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
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.
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
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:
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)
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.
19
3.1. WAVES2FOAM CHAPTER 3. WAVE SIMULATION
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:
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.
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:
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.
Now, we are going to see the results of the wave surface elevation measured at the centre of the
NWT. For this:
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.
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
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
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:
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.
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
4. Complie
source etc/bashrc
./Allwmake.firstInstall (this step takes hours)
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).
and do:
cd $WM_PROJECT_DIR/src/finiteVolume
wmake libso
34
4.4. FSI TUTORIAL CHAPTER 4. FLUID-STRUCTURE INTERACTION
[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
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
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
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.
[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
60
Appendix C
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
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.
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
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
(a)
(b)
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
87
Appendix E
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).
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
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
captionNumber of processors
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).
When you run in parallel, the Allrun file should be modified to include the following line
(<NPROCS> = numberOfSubdomains):
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).
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.
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.
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):
4
Figure 1.4: Scotch setup case
cd ..
nano Allrun
runApplication decomposePar
runParallel $(getApplication)
runApplication reconstructPar
./Allrun
After the run is performed, we should have the following files in our folder (or very similar).
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
6
Chapter 2
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
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
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:
8
Figure 2.4: Details of Paraview module
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
nano damBreak/system/decomposeParDict
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):
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
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):
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
126
Programme of the 2nd UCL OpenFOAM Workshop
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.
Local committee:
Luofeng Huang
Daniela Benites
Shiyu Lyu
Tom Smith
Reading recommendations
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)
129
Acknowledgements
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