Openfoam 1
Openfoam 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 16.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)
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)
3. Download Ubuntu 16.04 from http://releases.ubuntu.com/16.04/,
click 64-bit PC (AMD64) desktop image (under Select an image - Desktop image),
then you will get an iso file (1.5GB).
4. 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 16.04 LTS [Running] Oracle VM
VirtualBox”.
Click on Install Ubuntu and select your specific settings
It is recommended that you tick: Download updates while installing, and Install third-party
1
1.1. INSTALLATION CHAPTER 1. OPENFOAM BASIS
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.)
5. 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 4.0. (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 are
”ctrl+shift+c” and ”ctrl+shift+v” respectively.
sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -"
2
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
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
the whole codes.
Note: when modifying a tutorial, you should first copy it to your own directory, which was created in
the last step of the installation(home/OpenFOAM/yourname/run), so that the original case setting
can be preserved.
3
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
Let’s enter a tutorial case to see how a basic OpenFOAM case looks like,
go to: tutorials/incompressible/icoFoam/cavity/cavity
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.
4
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
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
requirement, 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 the 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)
Every four vertices can form a face, which can be classified in the Boundary part:
5
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS
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 ../../opt/openfoam4/tutorials/incompressile/icoFoam/cavity/cavity $FOAM_RUN
cd $FOAM_RUN/cavity