You are on page 1of 7

Running OpenFOAM for the first time

OpenFOAM is an open source CFD code which generally can be run on Linux- or Unix-based
operating systems. To find more information about the program, download the installation files or
browse tutorials, visit http://www.openfoam.org/. In addition to the OpenFOAM package, we will
be using our in-house meshing software, Mega, and the post-processor Paraview.
To make everything a bit easier for those of you that do not have Linux, we have prepared a socalled virtual machine with Linux Mint 17, OpenFOAM 2.3.0, Mega and Paraview pre-installed.
Together with the software VirtualBox, you can run this machine inside Windows or Mac OS. The
performance degradation by using this approach is small, however the memory requirements are
large, because to operating systems has to be run at once.
This guide is intended to give most of you a quick start, however some of you probably does not
have computers that are suitable for CFD work, because they are simply too old.
If you run something else than Windows on your computer today, you should visit the webpage
https://www.hpc.ntnu.no/display/hpc/OpenFOAM+-+Installation to get OpenFOAM installed in the
best way.

Getting started with VirtualBox


1. Download and install the VirtualBox software from https://www.virtualbox.org/.
2. Download the previously mentioned virtual machine from
http://folk.ntnu.no/hakostra/TMR4300/OF-Vbox.ova Username: cfduser Password:
cfdpasswd
3. Import the virtual machine into VirtualBox, with File Import appliance
4. Start the machine by selecting Start from the menu bar.
Some tips

You can share folders between your host operating system (typically Windows/Mac) and the
guest system (in this case Linux). This is described in the VirtualBox manual:
https://www.virtualbox.org/manual/ch04.html#sharedfolders

You can get full screen by clicking (Right Ctrl)+F, and exit full screen the same way.

If you think the graphics performance is poor, for example when using Paraview, you can
share the folder with your analysis files between Linux and Windows. Download Paraview
for Windows, and install it. Then create an empty file in the OpenFOAM case directory,
with extension .foam. This file can be opened in Paraview in Windows.

Getting started with Linux Mint


The Linux Mint user interface is not that far from what you are used with from earlier windows
versions. There is a button in the lower left corner that gives you a menu with the different
applications on your system. In this course, you will only need three:

Terminal Emulator

Gedit the text editor

The file manager used to browse files and folders on the computer

All three is found under the Accessories menu.

Some technical information about the system:

Default user: cfduser

Password: cfdpasswd

Keyboard layout: Norwegian

If you need to run some command as root, use the sudo command and the default password
(i.e. sudo apt-get dist-upgrade to update all packages on the system).

Getting started with OpenFOAM


Before you start on your project, it is recommended that you do the two tutorials that is described in
the official OpenFOAM documentation. That is:

Lid driven cavity flow: http://www.openfoam.org/docs/user/cavity.php

Breaking of a dam: http://www.openfoam.org/docs/user/damBreak.php

Getting started with the project


To run OpenFOAM you will need a project directory containing a lot of input files. Every project
directory must contain at least three folders inside it: constant, system and 0. The definitions of
these folders are:

constant: includes the folder named polyMesh and file transportProperties.


transportProperties includes properties of the fluid such as kinematic viscosity and/or
density
polyMesh contains all the data about your mesh, such as nodes, cells, faces and
boundaries

system includes controlDict, fvSolution and fvSchemes


controlDict is a setup file for the control of the analysis
fvSolution and fvSchemes include the setup of numerical methods and discretizations.

0: These files include the boundary and initial conditions for the compuational domain (will
be discussed in detail later )

In order to get started we have prepared a basic set of files for you which you will need to modify to
get started. These files originate from the cavity tutorial, but is slightly modified to enhance
stability of the solution and computational speed.
Creating Mesh
Export your mesh file from Mega mesh generator to your project directory. Convert it to
OpenFOAM mesh file typing the following command within your project directory:
gmshToFoam <yourmesh.msh>
Now you have a ~/cylinder/constant/polyMesh folder including your mesh. This command creates
some unnecessary files. Remove them by typing:
rm

constant/polyMesh/*Zones

You should modify the ~/cylinder/constant/polyMesh/boundary file to set some more useful
boundary names. Use consistent and descriptive names in the file to make the rest of the job easier
for yourself. You should also change the type of boundaries. The convenient types are:

patch: General boundaries, often used for inlets and outlets

zeroGradient: Farfield-type boundaries where we do not want any change in the variables.

wall: For fixed, no-slip walls

empty: for the front and back of a 2D mesh. This tells OpenFOAM that there is no flow in
this direction

Other boundaries also exist. If you are interested, please see


http://www.openfoam.org/docs/user/boundaries.php
In this case, we might use something like this (the nFaces and startFace might differ):
cylinder
{
type
nFaces
startFace
}
topAndBottom
{
type
nFaces
startFace
}
inlet
{
type
nFaces
startFace
}
outlet
{
type
nFaces
startFace
}

wall;
300;
2700;

patch;
100;
3000;

patch;
200;
3100;

patch;
200;
3300;

The last part we need to do is to check the mesh quality:


checkMesh
If this command prints Mesh OK at the end, then you can proceed. Otherwise, you will have to
locate the bad regions of your mesh and try to correct these. If needed, you can use the paraFoam
command to visualize the mesh before you start the simulation.
Fluid Properties
Modify the kinematic viscosity in the ~/cylinder/constant/transportProperties file. The file
indicates the value and the unit of the fluid property. The unit of the viscosity is m2/s . For ex. the

value is 0.01 m2/s then


nu [ 0 2 -1 0 0 0 0 ] 0.01;
You should modify this according to your Reynolds number.
Time setup
In the ~/cylinder/system directory, only modify the controlDict file. The other files contain
specifications about numerical methods and it is suggested to be modified only by advanced users.
In the controlDict file, modify the deltaT (it is your time interval to be used in your simulation) and
endTime (this is the time value when the simulation stops) . Choose the endTime value so you are
sure that the flow has stabilized. writeInterval controls how often you write out results/solutions to
the disk. It is important for post-processing and the smoothness of animations depends on this
value.
Drag and Lift Forces
For calculating drag and lift forces and coefficients, you should add a small script at the end of
controlDict file. The script is as follows:
functions
{
forceCoeffs
{
type
functionObjectLibs
outputControl
outputInterval
patches
pName
UName
rhoName
rhoInf
magUInf
log
liftDir
dragDir
CofR
pitchAxis
lRef
Aref
}
}

forceCoeffs;
( "libforces.so" );
timeStep;
1;
( cylinder );
p;
U;
rhoInf;
1000;
1.00;
true;
(0 1 0);
(1 0 0);
(0 0 0);
(0 0 1);
1;
0.1;

In this script, cylinder is the boundary name which we want to calculate the forces on. You must
change it if you have called the cylinder anything else. outputInterval is the frequency of
calculation and writing of force values. As it is known, the force coefficients are defined:

CD=

FD

1
U 2 A
2
FL
C L=
1
U 2 A
2

In the script rhoInf is density ( ) , magUInf is reference velocity ( U ). Aref is the projected
area (A), witch equals your meshs spanwise length/thickness (or cylinder length L if you like) if the
cylinder diameter (D) is unity (remember it from Mega). lRef is your reference length, but it is only
of importance if you are interested in the pitching moment coefficient (not further discussed here as
it is of no interest for cylinders). Modify these values according to your case. At the end of the
calculation, forces and forceCoeffs folders will be created in your project folder.
If you are working in another plane than the x-y-plane, for example the x-z-plane, you have to
change the lift- and drag axis directions. This is done by changing the liftDir and dragDir vectors
accordingly (the vectors indicate the direction of positive lift and drag forces and should be of unit
length).
Boundary and Initial Conditions
The folder 0 is indicating time zero. It means that the U and p files in that folder include velocity(U)
and pressure (p) values at the beginning of the simulation. As you start the simulation, according to
the given data writing interval, more folders will be created such as 0.1, 0.2 etc. Every folder has U
and p values for the actual time. In the 0/U and 0/p files, you can define
internalField

uniform 0;

and/or
internalField

uniform (0 0 0);

These statements represent the initial conditions of pressure and velocity (you can of course choose
for example uniform velocity equal to the inflow velocity as an initial condition if you like). As it is
seen, for pressure the value is a scalar, for velocity it is a vector (three components). Be careful
about the syntax for the vector.
That file also contains boundary conditions. You should add and modify the boundaries according to
your ~/cylinder/constant/polyMesh/boundary file. The boundary names should be consistent. For
example, for same top and bottom boundaries, it must be modified in the following manner:
topAndBottom
{
type
zeroGradient;
}
Another example for pressure at outlet:

// Boundary name

outlet
{
type
value
}
And velocity at inlet:

// Boundary name

inlet
{

fixedValue;
uniform 0;

// Boundary type

// Boundary type
// Pressure value at the boundary

// Boundary name

type
value

fixedValue;
uniform (1.0 0 0);

// Boundary type
// Velocity at the boundary

}
Other types of boundary conditions:

empty: use for front and back sides (defaultFaces)

symmetryPlane: means that the boundary, which must be plane, is to be treated as a plane of
symmetry. For a scalar quantity this is the same as zeroGradient, but for a vector it is not
(can you guess what the difference is?).

Summary of boundary condition types for all boundaries:


U

inlet

fixedValue

zeroGradient

outlet

zeroGradient

fixedValue

cylinder

fixedValue

zeroGradient

topAndBottom

zeroGradient

zeroGradient

defaultFaces

empty

empty

Starting the simulation


In your project directory, type
pisoFoam
to start OpenFOAM. If you receive any error message, follow the warnings. It is most probably due
to syntax error in boundary conditions or other edited files.
Post-processing
The open-source post-processor Paraview can be used to view the flow fields. When the simulation
has finished you can open the simulation by running the command
paraFoam
Some useful ParaView resources:

http://www.openfoam.org/docs/user/damBreak.php

https://www.hpc.ntnu.no/display/hpc/OpenFOAM+-+Postprocessing

https://www.hpc.ntnu.no/display/hpc/OpenFOAM+-+Spillway+Tutorial

Appendix
Some basic commands in Linux

cd - change directory to HOME

cd <path> - change directory to the one indicated in the path

cd .. - change directory to parent directory

pwd shows the working directory

mkdir <name> - make new directory

cp <source> <destination> copy file

ls - list the contains of current directory

rm - remove file or directory (to remove a directory, type rm r <dir name>)

mv - move file or directory

leafpad <document_name> - displays the document in a simpe text editor

mega - starts Mega mesh generator

<command> --help shows often a help menu

There are many web sites providing extensive lists of Linux commands with detailed descriptions.
Here are only few:

http://linuxcommand.org/learning_the_shell.php

http://www.unixguide.net/linux/linuxshortcuts.shtml

http://ss64.com/bash/