0% found this document useful (0 votes)
6 views8 pages

Openfoam 1

This document provides a comprehensive guide for installing OpenFOAM on a Linux system, specifically using Ubuntu 16.04 within a VirtualBox environment. It details the installation steps for both Linux and OpenFOAM, including terminal commands for setup and configuration. Additionally, it outlines the structure of OpenFOAM cases, foundational concepts in computational fluid dynamics (CFD), and the process for running simulations and post-processing results.

Uploaded by

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

Openfoam 1

This document provides a comprehensive guide for installing OpenFOAM on a Linux system, specifically using Ubuntu 16.04 within a VirtualBox environment. It details the installation steps for both Linux and OpenFOAM, including terminal commands for setup and configuration. Additionally, it outlines the structure of OpenFOAM cases, foundational concepts in computational fluid dynamics (CFD), and the process for running simulations and post-processing results.

Uploaded by

kartik k
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/ 8

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

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

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

sudo apt-get update


sudo apt-get -y install openfoam4
2. Now, OpenFOAM has been installed on your computer. Do one more step to complete user
configuration
In the terminal, execute gedit ~/.bashrc, then a file will be opened.
At the end of the file, ADD a line: source /opt/openfoam4/etc/bashrc
Save the file.
3. create a your own directory to store your OpenFOAM file, by executing the following line in
a terminal:
mkdir -p $FOAM_RUN

Congratulations. Your OpenFOAM 4.0 should have been set up OK.


(The above steps are referred from https://openfoam.org/download/4-0-ubuntu/. Check it out
for problems and more information.)

1.2 OpenFOAM case setup


Once installed, OpenFOAM files are saved at the directory: computer/opt/openfoam4

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

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 Foundational 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 compose into the solution of the whole space domain. This is similar to a
film: a single frame is performed via many elements, and a higher cell number can provide a better
resolution.

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)

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:

5
1.2. OPENFOAM CASE SETUP CHAPTER 1. OPENFOAM BASIS

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. 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 ../../opt/openfoam4/tutorials/incompressile/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

You might also like