You are on page 1of 59

Institut de M

anique des Fluides de


Toulouse

Getting started with OpenFOAM 1.4

Author:
Delphine

Department:

Leroux

COSINUS

With the ollaboration of :


Alexe Stoukov (servi e responsible)
Annag Pedrono
Herv Neau

August 30, 2007

Contents

1 Presentation of the software OpenFOAM

1.1 General presentation . . . . . . . . . . . . . . . . . . . . .


1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3.1 Lid-driven avity ow . . . . . . . . . . . . . . . .
1.3.2 Steady turbulent ow over a ba kward-fa ing step

2 Deepening

2.1 Pre-pro essing . . . . . . . . . .


2.1.1 The interfa e . . . . . .
2.1.2 Create and lone a ase
2.1.3 Known bug . . . . . . .
2.1.4 Meshing . . . . . . . . .
2.2 Solving . . . . . . . . . . . . . .
2.2.1 How to solve ? . . . . .
2.2.2 Whi h solver ? . . . . .
2.3 Post-pro essing . . . . . . . . .
2.3.1 Utilities . . . . . . . . .
2.3.2 ParaView . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

. 3
. 4
. 4
. 4
. 11

.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

3 Setting a non uniform initial ondition

3.1 Create a non uniform initial ondition . . . . . . . . . . . .


3.1.1 The utility setFields . . . . . . . . . . . . . . . . . .
3.1.2 Compiling with wmake . . . . . . . . . . . . . . . . .
3.1.3 A very useful powerful little utility - funkySetFields

4 Validation tests

4.1 The tilted level . . . . . . . . . . . . . . . . .


4.1.1 Des ription of the ase . . . . . . . . .
4.1.2 Results . . . . . . . . . . . . . . . . .
4.1.3 Comparison with the analyti al results
4.2 The sho k tube . . . . . . . . . . . . . . . . .
4.2.1 Des ription of the ase . . . . . . . . .
1

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

14

14
14
16
17
18
18
18
18
19
19
20

29

29
29
31
32

34

34
34
36
38
38
38

CONTENTS

4.2.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.3 Comparison with the analyti al results . . . . . . . . . 45
5 Comparison with JADIM VOF

5.1 Presentation of JADIM VOF . . . . . .


5.2 Running the same ase - a rising bubble
5.2.1 Presentation of the ase . . . . .
5.2.2 Results . . . . . . . . . . . . . .
5.2.3 Comparison with JADIM . . . .

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

47

47
47
47
48
49

6 Con lusion

52

A File . sv to .txt

53

B Sod's model

54

C Websites memo

58

Chapter 1

Presentation of the software


OpenFOAM

1.1

General presentation

OpenFOAM, whi h means Open Field Operation And Manipulation, is an


open-sour e CFD ode (Computational Fluid Dynami s). It is written in
C++ and uses an obje t oriented approa h whi h makes it easy to extend.
The software in ludes modules for a wide range of appli ations ( ompressible/in ompressible, ele tromagneti s, ombustion or even a module named
nan e). The numeri s implemented in OpenFOAM uses the Finite Volume
Method on unstru tured meshes.
FOAM was written by Henry Weller et al. at Imperial College of London.
For a few years FOAM was sold as a ommer ial ode by the ompany Nabla
Ltd. However, in 2004 FOAM was released under GPL and was renamed to
OpenFOAM. OpenFOAM is urrently distributed by OpenCFD Ltd.

Figure 1.1: Flow around a ylinder


3

CHAPTER 1.

1.2

PRESENTATION OF THE SOFTWARE OPENFOAM

Installation

The installation pro ess is well des ribed on the website www.open fd. o.uk,
the pro ess will not be the same depending on the platform (Linux 32/64
bits or others). If you follow exa tly what is written, you will not have any
problem. But you really have to follow the instru tions and keep the the
imposed tree stru ture be ause everything in the software is set up for the
given paths. The installation an be performed without being root. The
version used in this report is the 1.4 version.
1.3

Tutorials

On the website you an download the User Guide and the Programmer's
Guide. In both, you will nd some tutorials. On the o ial website you
an also nd the C++ Sour e Guide, only onsultable on the Internet, it des ribes ea h lass, namespa e, le and dire tory. It is an impressive database.
Let us try some tutorials. I am going to explain the rst tutorial but all the
details of the work will be dis ussed in the next hapter.
1.3.1 Lid-driven avity ow

This tutorial is explained on page 19 of the User Guide (U-19).


Presentation of the ase

We suppose that we have an isothermal, in ompressible ow in a two dimensional square domain. All the boundaries are walls, the top wall is moving
in the x-dire tion at a speed of 1m/s and the others are stationary (see g
1.2).

Figure 1.2: Geometry of the avity

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

At the beginning, the ow is assumed to be laminar. For a rst ase, we


are going to use a simple regular mesh and the solver i oFoam whi h is a
transient solver for in ompressible, laminar ow of Newtonian uids.
The mesh

The mesh generator in luded with OpenFOAM is named blo kMesh. It


generates meshes from an input di tionary blo kMeshDi t lo ated in the
onstant/polyMesh dire tory in the ase dire tory. One an edit the le
blo kMeshDi t by hand or by using the ase manager FoamX.
By hand you will have to edit the following le :

onvertToMeters 0 . 1 ;

// 1

verti es
(
(0 0
(1 0
(1 1
(0 1
(0 0
(1 0
(1 1
(0 1
);

//

oordinates

//
//
//

vertex
vertex
..

0
1

//

vertex

0)
0)
0)
0)
0.1)
0.1)
0.1)
0.1)

blo ks
(
hex (0 1 2 3 4 5 6 7)
(20 20 1)
simpleGrading (1 1 1)
);

unity

orresponds
of

the

to

0 . 1m

points

forming

the

geometry

// v e r t e x numbers
// numbers o f e l l s i n ea h d i r e t i o n
// r a t i o s i z e s l a s t e l l / f i r s t e l l i n

ea h

dire tion

edges
(
);
pat hes
(
wall
//
movingWall
//
(
(3 7 6 2)
//
)
//
wall fixedWalls
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
)
empty frontAndBa k
(
(0 3 2 1)
(4 5 6 7)
)
);

pat h type
p a t h name

for

pat h

blo k fa e
end o f t h e

in t h i s pat h
des ription for

pat h

mergePat hPairs
(
);

The blo k stru ture expe ted is shown in g 1.3:

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

Figure 1.3: Geometry of the avity


It is important here to see that OpenFOAM only works in three dimensions. Even if you have a two dimensional ase, OpenFOAM needs a depth.
You an do like in this ase : set a small depth like 0.01 m for 1 ell.
The mesh an be generated by writing the following in the terminal :
blo kMesh $FOAM_RUN/tutorials/i oFoam avity
If you prefer to use the FoamX interfa e, you need rst to start up it by
typing in a terminal :
FoamX
A window should now appear as in g 1.4:

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

Figure 1.4: FoamX main window


You should now a tivate the host omputer by double li king on its
name. That produ es a tree list of dire tories of the tutorial ases. The
avity ase will be solved by the solver i oFoam so you should double li k
on $FOAM_RUN/tutorials/i oFoam dire tory. The ases will appear under
the dire tory name. Finally double li k on the ase avity.
The ase will be opened in a new tab in the same panel. To set the
mesh generation, you should li k with the right mouse button on the ase
name avity, then simply li k on Foam Utilities, mesh, generation and nally
blo kMesh. A new window appears (see g 1.5). Cli k on Edit Di ionary and
an other window appears with the same ategories as in the blo kMeshDi t
di tionary : onvertToMeters, verti es, et . Fill in the dierent ategories
as it is done in the le blo kMeshDi t written before. Then li k on Exe ute
to generate the mesh.

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

Figure 1.5: Mesh generation


With these two ways, we get the same result (g 1.6):

Figure 1.6: Mesh


Boundary and initial onditions

In order to load the new mesh into FoamX li k with the right button on
and sele t Read Mesh&Fields. Save the ase by li king on the save
button (diskette). Now double li k on Mesh then on Pat hes, the names
Mesh

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

of the pat hes will appear. You need to spe ify the boundary onditions for
ea h pat h by double li king on them. On e it is done, save your work.
Now you an set the initial onditions by double li king on Fields, the
names of the elds will appear. For ea h eld, you need to spe ify some
values depending on the boundary type (g 1.7). Save the work.

Figure 1.7: Settings of the velo ity eld in FoamX


You an do all this work by hand by editing the di tionary $FOAM_RUN
/tutorials/i oFoam/ avity/ onstant/polyMesh/boundary for the boundary onditions and $FOAM_RUN/tutorials/i oFoam/ avity/0/p or U for the initial
onditions.

Physi al properties

In FoamX, the physi al properties are lo ated in Di tionaries. In this ase,


only the kinemati vis osity is to be spe ied (the number of properties
depends on the solver). From page U-24, = 0.01 m2 s1 . When you open
the window, you see that to spe ify the unity, it is written : [0 2 -1 0 0 0
0. Ea h number orrespond to a unit depending on its position : [kg m s K
A mol d.
By hand, you an edit di tionaries lo ated in the dire tory $FOAM_RUN
/tutorials/i oFoam/ avity/ onstant.

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

10

Control

Controls of time, of reading/writing solution data an be spe ify in FoamX


in the di tionary ontrolDi t lo ated in Di tionaries. Be areful to hoose
a orre t time step, the ourant number is to be less than or equal to 1.
For this ase the solver is going to ompute the solution until 0.5 s with
t = 0.005 s.
By hand, you an edit the di tionary $FOAM_RUN/tutorials/i oFoam
/ avity/system/ ontrolDi t.
Dis retisation and linear-solver settings

You an hoose dierent nite volume dis retisation s hemes in the fvS hemes
di tionary. The spe i ation of the linear equation solvers and toleran es and
other algorithm ontrols is made in the fvSolution di tionary. Do not forget
to save your settings.
By hand, edit the di tionaries $FOAM_RUN/tutorials/i oFoam/ avity
/system/fvS hemes and fvSolution.
Run the solver

As usual, you an do it by hand or by using FoamX.


By hand you sould type in a terminal :
i oFoam $FOAM_RUN/tutorials/i oFoam avity
In FoamX, you should li k on the little arrow on the top panel to start
al ulations.
See the the results

OpenFOAM oers by default a ParaView format output. You an have


other output formats by doing some post-pro essing jobs that onvert the
foam data, see page U-88 and U-89 to see the list of the available formats. I
will only use in this report the ParaView software. Be ause ParaView is the
post-pro essing tool supplied with OpenFOAM, it is alled paraFOAM.
To see the results of our tutorial with ParaView, you should write in a
terminal :
paraFoam $FOAM_RUN/tutorials/i oFoam avity
Or if you are still with FoamX: right li k on the ase name, Foam Utilities, postPro essing, graphi s and then paraFoam.
The paraView window opens (g 1.8):

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

11

Figure 1.8: ParaFoam start window


To see the nal result, li k on 0.5 s (nal time) and on the green button
Cli k on the panel Display, here you an hoose what to see by
li king on the menu button of Color by and sele t p or U (g 1.9).

A ept.

Figure 1.9: Pressure (left) and velo ity (right) at 0.5 s


1.3.2 Steady turbulent ow over a ba kward-fa ing step

This ase is treated on page 54 of the Programmer's Guide (P-54). For this
ase I am just going to present the tutorial and the results.

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

12

Presentation of the ase

We suppose that we have a steady turbulent ow. The solution domain is


omposed by a short inlet, a ba kward-fa ing step and a onverging nozzle
at outlet, see g 1.10:

Figure 1.10: Geometry of the ba kward-fa ing step


The initial onditions are U = 0 m/s, p = 0 Pa inside the domain. The
boundary onditions are Ux = 10 m/s at the inlet, p = 0 Pa at the outlet.
We set no-slip walls on other boundaries. The kinemati vis osity is equal
to 14 m2/s. We need some spe i ations for the turbulen e model: we are
going to use the standard model with C = 0.09, C1 = 1.44, C2 = 1.92,
= 1 and = 0.76923.
In g 1.11 are the numbers of the verti ies and the blo ks :

Figure 1.11: Blo ks and verti ies of the mesh


We are going to use a solver named simpleFoam whi h is a steady-state
solver for in ompressible, turbulent ow of non-Newtonian uids. The ase
path is $FOAM_RUN/tutorials/simpleFoam/pitzDaily.

CHAPTER 1.

PRESENTATION OF THE SOFTWARE OPENFOAM

13

The results

In a steady ase, the time set is not used as time, it is just to ount the
number of iterations. My startTime was 0 and my endTime was 1000 with
a time step of 1. So after 1000 iterations, onvergen e is rea hed and I get
the results of g 1.12 :

Figure 1.12: Pressure (top) and velo ity (bottom) after 1000 iterations

Chapter 2

Deepening

In this hapter, pre-pro essing, solving and post-pro essing are going to be
explained. These are the three steps that one have to do to get results.
2.1

Pre-pro essing

The pre-pro essing in OpenFOAM an be done using FoamX or by hand


(see Chapter 1). In this se tion I will only present the FoamX utility. You
an easily nd the orresponden e if you want to do it by hand. FoamX will
only write the information into the orre t di tionary.
The main advantage of FoamX is when one have to ll a parameter, it
oers a list of keywords to the user. This way, the user annot make a syntax
mistake by writing by hand. It is very useful when you reate a new ase.
To laun h FoamX, just write into a terminal :
FoamX
2.1.1 The interfa e

The rst window that will appear is shown in g 1.4. You double li k on
the name of the host and then you hoose a ase by double li king on it, it
will open the ase in a new tab as in g 2.1:

14

CHAPTER 2.

DEEPENING

15

Figure 2.1: FoamX - open a ase


To lose the ase and ome ba k to the ase browser, just li k on the
lose button (the red square on the top panel).
On the ase panel, you an expand dire tories to see the dierent di tionaries that you an ll. On e you have found the di tionary to edit, double
li k on it and it will appear on the editing panel. When you have nished,
just lose the little window and save your work by li king on the save button
(the diskette on the top panel). A message will appear on the progress history panel to say that the modi ations have been orre tly saved. A tually
when you ask to FoamX to save, it writes on the orre t di tionaries all your
spe i ations.
To have more options about one di tionary, you an li k on it with the
right button of the mouse. For example, to import a mesh from an other
ase : right li k on Mesh, Import Mesh and then a window appears on the
edition panel.
FoamX is a ase manager, you an do pre-pro essing, running a solver,
post-pro essing from FoamX. All these a tions an be done by li king with
the right button on the ase name at the top of the ase panel. The seven
ategories are :

mesh : onversion, generation, ...

CHAPTER 2.

DEEPENING

16

prePro essing : setFields, ...


postPro essing : dataConversion, graphi s, ...
thermoPhysi al : equilibriumCO, ...
errorEstimation : estimateS alarError, ...
parallelPro essing : re onstru tPar, de omposePar, ...
mis ellaneous : foamInfoExe , ...

2.1.2 Create and lone a ase

For this se tion, return to the main window of FoamX as g 1.4 and double
li k on the host name and then a tree with all the tutorial ase names appear
(g 2.2).

Figure 2.2: FoamX - the ases tree

CHAPTER 2.

DEEPENING

17

Create a new ase

Sele t a dire tory (it does not matter whi h one) without opening it, just
li k on it. You an see that the button Create Case is now available (a pie e
of sheet with a little spark). Cli k on that button. A window appears on
the editing panel.
In the Create New Case window, you have to spe ify whi h solver you
want to use. This hoi e depends on the ase you want to reate, for more
details see the next se tion. Then you should write the root ase and nally
the name of your new ase. Press the OK button, the ase will be reated
and will be opened immediately.
Clone a ase

The fun tion Clone a ase ould be very useful and helpful if you want to
test something on a ase without loosing the old parameters and the old
results, espe ially if you want to rene the mesh.
First sele t the ase you want to lone, simply li k on it and the button
Clone Case is now available on the top panel (a pie e of sheet over an other
one). A window will appear on the editing panel. You should spe ify the
root of the ase you want to lone, the name of your new ase. The last
thing to hoose is the solver. The third blank needs some explanations.
When you run a solver, it writes the results into time dire tories. If you
have written into the ontrolDi t di tionary that the start time is 0 s, the
end time 2 s, and the write interval is 1 s, then the solver will reate two
more time dire tories. So you will have the dire tories 0/, 1/ and 2/. In
ea h dire tory, you will nd the results for the pressure p, the temperature
T at the time of the dire tory. So the third blank is the following: do you
want to opy the time dire tories ? The possible answers are:
rstTime : you will just opy the rst time dire tory, for example 0/,
latestTime : you will opy only the latest time, for example 2/, it an
be useful if you want to ontinue the al ulations with a rened mesh,
allTime : you will opy all the time dire tories,
noTime : you will not opy time dire tories (not re ommended be ause
FoamX will not reate the dire tory 0/, neither the di tionaries U and
p so you will have to write them by hand).
After all this set up, press lose and answer yes to the next question.
2.1.3 Known bug

It an o urs sometimes that the ase lo ks itself. Normally, a ase is lo ked


when it is opened, it is a se urity su h as two persons annot work on the

CHAPTER 2.

DEEPENING

18

same ase at the same time. So if you are sure that nobody works on that
ase, you an unlo k it by li king on the button Unlo k Case (button with
a green ribbon on the top panel).
2.1.4 Meshing

Generating meshes is explained in se tion 1.3.1 on page 5. It is also the topi


of the hapter 6 of the User Guide.
From my experien e, meshing a simple geometry an be done easily by
editing the mesh di tionary or by FoamX, but when the geometry be omes
omplex, meshing with OpenFOAM be omes omplex also. I think this
would not be a bad idea to import a mesh from an other meshing software
easier to use and then onvert it with one of the OpenFOAM utility (ansysToFoam, gambitToFoam, et ).
2.2

Solving

2.2.1 How to solve ?

There are two te hni s to solve, one from FoamX and one from a terminal.
From FoamX you just need to li k on the button run or the button run
now, see g 2.1. The dieren e between these two buttons is that the run
button opens a window and asks you if you want to run it in ba kground.
Cli king on run now will start the solving pro ess immediately in ba kground
without any suggestion before.
By hand, just write in a terminal:
nameSolver root nameCase
For example, if you want to solve the ase avity lo ated in the dire tory
$FOAM_RUN/tutorials/i oFoam with the solver i oFoam you should write:
i oFoam $FOAM_RUN/tutorials/i oFoam avity
2.2.2 Whi h solver ?

The hoi e of the solver depends on your ase. There is a list on page U-84
whi h des ribes in a few words ea h solver available in OpenFOAM. I will
not re-write the entire list. You an also nd their des riptions and their
sour e odes in the $FOAM_APP/solvers dire tory or simply by writing
app in a terminal. There are ten main ategories :

basi CFD ode: potentialFoam, ...


in ompressible ow: i oFoam, ...
ompressible ow: soni Foam, ...

CHAPTER 2.

2.3

DEEPENING

19

multiphase ow: interFoam; ...


DNS (Dire t Numeri al Simulation) and LES (Large Eddy Simulation):
dnsFoam,oodles, ...
ombustion: engineFoam, ...
heat transfer: buoyantFoam, ...
ele tromagneti s: ele trostati Foam, ...
stress analysis of solids: solidDispla ementFoam, ...
nan e: nan ialFoam .
Post-pro essing

Now that we have omputed the solution, we would like to see it. ParaFOAM
or ParaView is a post-pro essing software that an be laun hed from FoamX
(right- li k on the ase name, li k on Foam Utilities, postPro essing, graphi s, paraFoam ) or in a terminal write:
paraFoam root nameCase
You an do some post-pro essing jobs dire tly from FoamX like U omponents whi h is a fun tion that separates the omponents of the velo ity
elds into three s alars.
2.3.1 Utilities

From FoamX, some post-pro essing fun tions are available. A omplete list
of these fun tions is available on page U-86. They are separated into seven
ategories :

dataConversion: foamToEnsight, ...


wall: wallShearStress, ...
velo ityField: magU, U omponents, ...
mis ellaneous: writeCellCentres, ...
graphi s: paraFoam
stressField: stressComponents, ...
s alarField: pPrime2.

CHAPTER 2.

DEEPENING

20

After having run the solver on the ase, just li k with the right button
on the ase name, li k on Foam Utilities, on postPro essing, then on the ategory and the fun tion you want. It will open a window in the editing panel
to onrm the post-pro essing job, just li k on Exe ute. On this window a
message will say that the pro ess has nished su essfully. For example, the
fun tion stressComponents will reate a le in ea h time dire tory and write
into this le the stress omponents. If you want to see the results, laun h
paraFoam and sele t the orre t variable.
You an run these jobs from a terminal. For example for the fun tion
that omputes the magnitude of the velo ity eld :
magU root nameCase
Be areful, sometimes FoamX says that the pro ess has nished su essfully but you must he k the terminal from whi h you have laun hed FoamX.
It is on this terminal that the al ulations are displayed. This is there that
you really see if the pro ess is su essfull .
2.3.2 ParaView

This se tion is not really a tutorial about ParaView, I am only going to


explain a few fun tions that seem to me really important and very useful.
You an nd more omplete tutorials on the Internet very easily.
First laun h paraFoam or ParaView, it is the same thing as before, you
an do it from FoamX, by li king with the right mouse button on the ase
name then li k on Foam Utilities, postPro essing, graphi s, paraFoam and
nally Exe ute. Or if you prefer by hand from a terminal:
paraFoam root aseName
A tually paraFoam is a s ript, $HOME/OpenFOAM/OpenFOAM-1.4/bin
/paraFoam. It he ks if the ase exists and transforms output data in su h
a way that paraView an read them.
On e paraFoam is laun hed, hoose a time and li k on the green button
A ept. A tually, this button be omes green when you hange something, it
is like a warning to say that you have hanged something and that what you
see on the right window does not orrespond to the options that you have
hosen on the left window. Figure 2.3 is the window that you get when you
open a ase.

CHAPTER 2.

DEEPENING

21

Figure 2.3: Overview of ParaView with an opened ase


You an see that you have three panels : Parameters, Display and InforOn the Parameters panel, you an hoose the time, on the Display
panel, you an hoose whi h property you want to display, and on the Information panel, you have some informations about the properties.
If you want to add some annotations, go to the View menu on the top
bar and hoose 3D View Properties. Then sele t the Annotate panel. Here
you an display orner anotations or orientations axis. In the General panel,
you an set the ba kground olor.
Now go ba k to the sour e view by going on the View menu of the top
bar and sele t Sour e. Let us see what buttons we have here (g 2.4).

mation.

Figure 2.4: ParaView buttons


The three rst ones are dire tly onne ted to the 3D view, you an reset
the view, turn the view or translate the view. The other buttons are more
about post-pro essing:
adds a new variable (it will be explained and used later)

CHAPTER 2.

DEEPENING

22

displa es the geometry with a given ve tor eld


lips with an impli it plane
makes a ut
sele ts only the ells that threshold a riterion
generates isolines and isosurfa es
generates a symbol at ea h point
displays informations on a pi ked ell
analyzes a point and plots data over the time (it will be used later)
samples data values
generates streamtra es
extra ts a subgrid or a subsample
measures the distan e between two points
regular re tilinear grid in up to three dimensions with values varying
a ording to a periodi fun tion
You an add other buttons by li king on the arrow on the right on the
button pannel.
To use one of these fun tions, just li k on it and a new panel will appear,
hange the parameters and then li k on A ept.
You will see that progressively you will have some ases opened in the
Sele tion Window (see g 2.5).

CHAPTER 2.

DEEPENING

23

Figure 2.5: The sele tion window


On the left of ea h name there is a little eye. This eye is bla k if the
result is displayed and grey if not. To hange its olor simply li k on the
eye. There is a name with a yellow re tangle, this means that the ase is
sele ted so if you go to the parameters panel you will edit this ase. So be
areful if you want to hange something to sele t orre tly the ase.
Streamlines, ontour and glyph lters

All the post-pro essing jobs annot be represented by a button. To have the
ompelete list, go on the top menu bar and sele t Filter. All the available
fun tions will appear, you will re-nd for example lip, ut.
To illustrate, I am going to apply some lters on an example : the tutorial
pitzDaily seen before. Let us start with the streamlines (g 2.6).
In order to display the streamlines, we are going to use the lter Stream
Tra er but this lter annot work on surfa e geometry so we must rst
extra t the internal mesh. To do so, go to the lter menu and sele t Extra t
Parts, in the new panel opened sele t only Internal Mesh and then A ept.
Now you an sele t Stream Tra er from the Filter menu.

Figure 2.6: Streamlines


We an display also the velo ity like ve tors (g 2.7). First sele t the
lter, it will sele t only the ell enters. Then sele t the Glyph
lter. In the new panel, sele t Ve tor for the orientation mode, Data s aling
o for the s ale mode, hange the s ale fa tor in order to be able to see
learly, and hoose U to display. Then li k on A ept.

Cell Centers

CHAPTER 2.

DEEPENING

24

Figure 2.7: Ve tor plots


Now we ould display the ontour of the pressure for example (2.8). First,
you need to reate a utting plane, for this sele t the Cut lter, hoose the
ara teristi s and sele t the Contour lter. In the new panel, you have to
hange the number of values in the Generate range of values (by default it is
1). For example hoose 50 and li k on the button Generate and then li k
on A ept. Now you will see the ontour.

Figure 2.8: Contour of the pressure


You an also do the same pro ess by li king on one of the buttons
des ribed previously.
Tip : When you use the lter Streamlines, you may want to see the
ontour of the geometry. To get a ni e pi ture, use the lter Extra t Parts
and sele t only the boundaries of your geometry like the walls, the inlets,
the outlets, et and a ept. Now in the new opened panel, go to the Display
panel and sele t Wireframe Of Surfa e. Do not forget to have the eye olored
in bla k and not in grey on the sele tion window to display it.
Make an animation

To make a good animation, you need to set the olor range orre tly so sele t
the last time, li k on A ept and press reset range. Now go ba k and unsele t the last time and press A ept. It is important that no time is sele ted!

CHAPTER 2.

DEEPENING

25

In the display panel, hoose the variable you want to see in the animation.
Go to the View bar menu and sele t Keyframe Animation. Then you
just need to li k on the play button and you will see the animation. If you
want to save it, li k on the button save animation (movie strip).
Tip : Maybe you have a big red-yellow ross in the middle of the s reen
and it is not ni e on your animation or pi ture. You have it be ause the
rotation button is sele ted. To remove this ross, just sele t the translation
button (g 2.9).

Figure 2.9: Rotation (left) and translation (right) buttons


What ould be done to improve ParaView is to display the orresponding
time during the animation. This way, it would be easier to situate the pi ture
in the animation.
Add a new variable

If you want to add a new variable, you just need to li k the Create new
arrays button ( al ulator button), see g 2.10. Then write the expression
orresponding to this new variable. For example, I want to see the density
and I already have the temperature T and the pressure p. For perfe t
gaz we have p = R T so the expression for will be : = p/R T , in
the expression that you will write, just repla e R by its value and sele t the
variables p and T in the S alar menu. After having reated the density you
an display it as any other variable.

CHAPTER 2.

DEEPENING

26

Figure 2.10: Add a new variable

Make a 2-D graph

You an reate two kinds of 2-D graph : you an follow a point in the time
or you pi k up a line at a given time. The manipulation to get the graph is
not the same depending on the kind you want. If you hoose the point, you
need to sele t the rst time of the omputed results; for the line, sele t the
time you want to see.
To begin, you need to extra t the internal mesh for both options: sele t
the Extra t Parts lter and sele t Internal Mesh, a ept. Then sele t the
Probe lter. When you sele t Probe, the Extra t Parts has to be sele ted
( olored in yellow in the sele tion window). You will have a new panel like
in g 2.11.

CHAPTER 2.

DEEPENING

27

Figure 2.11: The Probe lter


Now it is time to hoose Point or Line. The option Point is used to follow
a point in the time and the other option Line is used to display the properties
on a line at a given time. Pi k up the point or the line by orrdinates or by
the mouse (you hoose the point with the mouse and without li king, just
push the letter P of the keyboard and the oordinates of the points will be
automati ally lled). Then a ept.
Let us begin with the option Point. First make sure that the option
Show XY-plot is sele ted. When you have li ked on A ept, a graph has
appeared on the bottom of the displayed window. But it is only a point. For
the moment, it is only a onstant, we need to re ord the data and then we
will be able to display the variable. It is the same pro ess as re ording an
animation. What you see on the displayed window is orresponding to the
rst time. It is very important that no time is sele ted. If not, ParaView
will lose itself with a segmentation error. To be sure, sele t time 0, a ept
and unsele t it, then a ept. Now you are ready. So go to the Keyframe
animation menu from the View bar menu and play the animation. You will
see the graph being built all alone (g 2.12). At the end of the animation,
you an save the data into a le with the extension . sv by returning on the
Sour e view. Cli k on Save as CSV.
For the Line option, it is simpler. Sele t Line, hoose the two points
forming the line, and the only thing that you really need to spe ify is the
resolution. If you have a regular mesh, it ould be interesting to write the
same resolution as the number of ell you have in the dire tion of the line.
Then a ept. The graph will appear at the bottom of the displayed window
(g 2.13). You an save the data into a le with the extension . sv by li king
on Save as CSV.

CHAPTER 2.

DEEPENING

28

After having saved the data, you an treat them in order to be used with
other softwares like gnuplot. CSV means Comma Separated Values, gnuplot
treats data in olumns so you need to write a s ript or a ode to re-order the
data into the orre t way (see annex A).

Figure 2.12: Point probe - pressure at 8s (left) then at 20s (right)

Figure 2.13: Line probe - pressure along a line


Tip : When you reate a 2-D graph, the legend of the graph is oftenly
like volPointInterpolate(p) and it is not so ni e, you ould use an other utility
named dataAnalysis whi h does the same thing as Probe with more options
like hanging the name of the legend or the olor of the graph. I have not
found the option to display the axis of the graph in bla k, by default it is in
white so I just set the ba kground olor in bla k (3D view properties from
the View bar menu).

Chapter 3

Setting a non uniform initial


ondition

Until now we have only seen uniform initial ondition, that is to say, we have
water with velo ity of 5 m/s and that is all. Now we would like to have air
on the left and water on the right or we would like to have dierent velo ities
or temperatures.
3.1

Create a non uniform initial ondition

There is a tutorial in OpenFOAM using a non uniform initial ondition :


damBreak. We need to set the position of the dam where there will be water
and everywhere else, there will be air. This tutorial is treated on page U-56
so I will not do it again. In this se tion I am going to explain how to set a
non uniform initial ondition only.
3.1.1 The utility setFields

Let us try to break this dam! Go to the dire tory of the tutorial ase

damBreak : $FOAM_RUN/tutorials/interFoam/damBreak. As usual at the


begining, we only have three dire tories : 0, onstant and system. If you
go into the dire tory 0, you will wee that one of the output is the phase

fra tion gamma or : 1 will orrespond to the water and 0 to the air. In the
dire tory onstant, nothing has hanged but in system one le has appeared
: setFieldsDi t. Open it.

defaultFieldValues
// Values by
(
v o l S a l a r F i e l d V a l u e gamma 0
v o l V e t o r F i e l d V a l u e U (0 0 0)
);

default

regions
(
boxToCell
{

ertain

//

Values

for

29

regions

CHAPTER 3.

SETTING A NON UNIFORM INITIAL CONDITION

30

box (0 0 1) ( 0 . 1 4 6 1 0 . 2 9 2 1 ) ;

);

fieldValues
(
v o l S a l a r F i e l d V a l u e gamma 1
);

The di tionary defaultFieldValues spe ies the values by default, that


means that it will be written these values in the entire domain ex ept for
the regions spe ied below. volS alarFieldValue and volVe torFieldValue
are lasses, so gamma is an obje t of the lass volS alarFieldValue and U
of volVe torFieldValue. Then follow the values of gamma and U. We set
by default that there is only air with no velo ity in the domain. I think
that spe ifying the zero velo ity by default is not ompulsory be ause it is
uniform .
Now omes the di tionary regions. It denes a region where the values
are dierent from the default ones. boxToCell reates a box where you dene
only two points (see g 3.1) to set the value of gamma at 1. Here again you
write rst the lass, then the names of the obje t and its value in its orre t
syntax.

Figure 3.1: boxToCell - denition of the box where there will be water
Maybe you do not want to reate a box but a surfa e or something else,
the list of what you an reate an be found in the dire tory $FOAM_SRC
/meshTools/sets/ ellSour es. You will see also the sour e ode of these utilities (*.C). See the next se tion for explanations about ompiling these fun tions. You an now exe ute setFields from the dire tory of the tutorial :
setFields $FOAM_RUN/tutorials/interFoam damBreak
To he k that the pro ess is su essfull, go to the dire tory 0 and open
the le gamma. You will see that there is a list of values, one for ea h ell.
Bigger the mesh is, bigger the list will be.
If you have a oarse mesh, so if you have a few ell you an dire tly write
ea h value by hand from FoamX for ea h ell. Open FoamX and sele t the
tutorial. Double li k on Fields and on gamma, in the new window on the

CHAPTER 3.

SETTING A NON UNIFORM INITIAL CONDITION

31

right you will be able to sele t nonuniform if the number of value to display
is not too high (g 3.2). Then you an write the values of gamma one by
one. You need to have dened the mesh rst with blo kMeshDi t.

Figure 3.2: Denition of a nonuniform variable


3.1.2 Compiling with wmake

If what you want to reate is not in the list of $FOAM_SRC/meshTools/sets


/ ellSour es then you may want to ode it yourself. As an example let us see
how setFields is built ( ompiling with wmake is explained on page U-71).
The utility setFields is lo ated in $FOAM_APP/utilities/prePro essing
/setFields. We an see two les and two dire tories. One le is already
known, it is setFieldsDi t seen just before. We have the sour e ode setFields.C. The dire tory FoamX ontains only onguration les for FoamX.
The dire tory Make ontains two les : les and options. The rst one, les,

spe ies the sour e les to ompile and the path where the exe utable will
be stored.

s e t F i e l d s .C

//

sour e

file

to

EXE = $ (FOAM_APPBIN)/ s e t F i e l d s

ompile
//

path

of

the

exe utable

If you want to reate your own utility, you are supposed to store the
exe utable in the dire tory $FOAM_USER_APPBIN/nameOfYourUtility.
It is re ommended to store the other les as the sour e ode in the
$WM_PROJECT_USER_DIR/nameOfYourUtility dire tory.
The se ond le, options, spe ies the headers to in lude and the path
of the librairies to in lude. Of ourse you annot write the paths of all the
headers and librairies needed so the ompiler has already a pre-dened list
with the paths of the usual headers and librairies (see on page U-71-72).

EXE_INC = \
// h e a d e r s t o i n l u d e
I $ (LIB_SRC)/ f i n i t e V o l u m e / l n I n l u d e \
I $ (LIB_SRC)/ meshTools/ l n I n l u d e

CHAPTER 3.

SETTING A NON UNIFORM INITIAL CONDITION

EXE_LIBS = \
//
l f i n i t e V o l u m e \
lmeshTools

librairies

to

32

link

It is important to write a ba kslash at the end of ea h line, ex ept at the


last one of ea h of the two parts EXE_INC and EXE_LIBS. Do not forget
also to write -I before ea h path for the headers and -l for the librairies.
When you write the name of a librairy, remove the extension .so. A tually
you are supposed to write rst the path of the librairy and then spe ify its
name but if the path is already in the pre-dened list of the ompiler then
you do not need to write it. All this is explanied in details on page U-72.
OpenFOAM is written in C++ so the ompiler is g++. The ommon
makele ommand is supposed to be make but OpenFOAM has its own
makele named wmake whi h is based on make but is more versatile and
easier to use. It uses the dynami linking.
3.1.3 A very useful powerful little utility - funkySetFields

is like the setFields utility. It sets the value of a s alar or a


ve tor eld depending on an expression that an be entered via the ommand
line or a di tionary. It an be used to set non-uniform intial- onditions
without programming.
It an be downloaded from the website
http://openfoamwiki.net/index.php/Contrib_funkySetFields.
You will also nd on this webpage the instru tions to install it and how
to use it. There are some known bugs so you need to be astute to avoid
them !
I needed a new utility be ause I wanted to set a bubble of air in the water.
So I wanted something doing the same thing than setFields and boxToCell
but with a ylinder. I do not have a lot of knowledges in C++, only the bases
so I have tried to ode without su ess. Then I have found this utility and
now it works ne for me. It is really easy to use and very intuitive. There is
a forum about non uniform initial ondition and also about funkySetFields,
if you have a problem maybe you an ask some help there :
http://openfoam. fd-online. om/ gi-bin/forum/board-auth. gi?le=/1/
368.html .
Now how to use it ? Like any other utility :
funkySetFields rootPath ase -spe i ations
In the spe i ations, you need to write, whi h time you want to do the
al ulations, the eld or the pat h you want to hange, the expression to
satisfy et . For example, if we want to apply funkySetFields to the damBreak
tutorial that would give :
funkySetFields

CHAPTER 3.

SETTING A NON UNIFORM INITIAL CONDITION

33

funkySetFields $FOAM_RUN/tutorials/interFoam damBreak -time 0 eld gamma -expression " pos().x <= 0.1461 && pos().y <= 0.292 ? 1 : 0"
Let us translate this ommande line. -time 0 means that we are going
to hange the values of the time 0, -eld gamma means that we are going
to hange the values of the variable gamma and -expression " pos().x <=
0.1461 && pos().y <= 0.292 ? 1 : 0" means that if the x omponent of the
enter of the ell is less than or equal to 0.1461 AND if the y omponent of
the enter of the ell is less than or equal to 0.292 THEN gamma will be
equal to 1 AND if NOT gamma will be equal to 0. Easier than setFields isn't
it? Well, from this, just be ome familiar with the OpenFOAM notations like
pos().x and you will do whatever you want. I will talk about the ase of
setting a bubble later on this report.

Chapter 4

Validation tests

In order to test OpenFOAM, I needed to validate some ases. I have hosen


to des ribe two tests in this report. The rst one is air arriving on a tilted
level provo ating a sho k. The se ond is a sho k tube with two gases at
dierent pressures. I will ompare the omputed results with the analyti al
ones.
4.1

The tilted level

4.1.1 Des ription of the ase

Suppose that we have laminar, ompressible air at Ma = 3 that is for ed to


turn through 10by a ramp at the body surfa e. A weak oblique sho k will
be formed by a ertain angle. I have dened the geometry and the mesh as
on g 4.1 : the bla k numbers are the measures in meters and the blue ones
are the number of ells in ea h dire tion (be ause OpenFOAM only works
with three dimensions, I have a 3-D geometry with a depth of 0.1 m with
only one ell). Air omes from the left and an exit by the top or by the
right.

Figure 4.1: Geometry of the tilted plan


In order to simplify the ase, I have nondimensionalized the problem to
34

CHAPTER 4.

VALIDATION TESTS

35

get a speed of sound of one. So at the begining we have :


Ma =

U
, c = 1 U = Ma
c

But after the sho k we do not have anymore = 1 so U 6= M a.


For a perfe t gas the speed of sound is dened as :
c=

RT

with :
c : speed of sound [m/s
: spe i heat ratio [ (1.4 for air)
R : gas onstant [m2 /(s2 K)
T : temperature [K
We set T = 1 K at the begining, T is not equal to 1 after the sho k. If
we want to have = 1 m/s then we need to hange the value of R :
R=

c2
1
= = 0.71429m2 /(s2 K)
T

and the spe i heat Cv will be :


Cv =

R
= 1.78571m2 /(s2 K)
1

I will display in the results se tion the stagnation temperature whose the
formula for a perfe t gas is :


1
T0 = T 1 +
M a2
2



U2
1

T0 = T 1 +
2
RT

We are going to ompute the solution for 1.5 s with a time step of 0.002
s with the solver soni Foam.
The boundary spe i ations are :
left : supersoni Inlet
top and right : extrapolatedOutlet
bottom : symmetryPlane
other boundaries : empty
I have hosen this ase to test be ause the analyti al solution is easy to
get with tables already written. I know that for an angle of 10I will have a
sho k of 27.4. The stagnation temperature is to be onstant. This is what
we are going to he k.

CHAPTER 4.

VALIDATION TESTS

36

4.1.2 Results

As expe ted, there is a sho k : in g 4.2 the pressure in reases suddenly


and then be omes stable. It takes some ells to treat this dis ontinuity. The
pressure samples have been taken along the line between the gray points at
the boundaries of the geometry.

Figure 4.2: Pressure


The stagnation temperature is more or less ontant ex ept near the begining of the tilted plan (see gs 4.3 and 4.4).

CHAPTER 4.

VALIDATION TESTS

Figure 4.3: Stagnation temperature

Figure 4.4: Zoom - stagnation temperature

37

CHAPTER 4.

VALIDATION TESTS

38

4.1.3 Comparison with the analyti al results

From the sho k theory, we expe ted a sho k angle of 27.38and when we
measure it from the omputed solution we nd an angle of 26.6 2(be ause the utility to measure in ParaView is not very a urate). That is a
good result.
This theoreti al result omes from this equation :

2cot M a21 sin2 1
tan =
M a21 ( + cos2) + 2

with the spe i heat ratio and the angles and as below :

Figure 4.5: Angles and for a sho k


Be ause we do not have any sour e or exit of energy, the stagnation
temperature is to be onstant, the pro ess is isoenergeti . In g 4.3, T0 is
almost onstant, it varies between 2.79 and 2.80, ex ept in the tilted orner
where T0 = 2.75. So we have less than 2% of error. That is ni e !
4.2

The sho k tube

This ase is a tually a tutorial that you an nd in the dire tory
$FOAM_RUN/tutorials/soni Foam.
4.2.1 Des ription of the ase

Suppose that we have a tube with air at dierent pressure on the left and on
the right. At the begining they are separated and at time t = 0 we mix them.
Sho ks appear. We have 105 P a on the left and 104 P a on the right. The tube
measures 10m by 2m and 2m in depth. Be ause we are only interested in
the horizontal hanges, the mesh is omposed of 100 ells in the x-dire tion,
1 ell in the y and z-dire tions.

CHAPTER 4.

VALIDATION TESTS

39

Figure 4.6: The sho k tube geometry


To impose a non uniform initial ondition, we have two hoi es, either
using funkySetFields or using the simple utility setSho k. The sour e ode
of setSho k is not di ult to understand that is why you would have been
able to write it yourself.
Let us start with funkySetFields, you should have written :
funkySetFields $FOAM_RUN/tutorials/soni Foam sho kTube -time 0
-eld p -expression pos().x <= 0 ? 1e5 : 1e4
Now let us see the utility setSho k. Go to the $FOAM_RUN/tutorials/
soni Foam/setSho k dire tory and open the le setSho k.C :

onst

v o l V e t o r F i e l d& e n t r e s = mesh .C ( ) ;

forAll ( entres , e l l i )
{

if

)
{

else

( e n t r e s [ e l l i . x ( ) <= x0 )
p [ e l l i = pL ;
T[ e l l i = TL ;
U[ e l l i = UL;

p [ e l l i = pR ;
T[ e l l i = TR;
U[ e l l i = UR;

p . orre tBoundaryConditions ( ) ;
p . write ( ) ;
T. orre tBoundaryConditions ( ) ;
T. write ( ) ;
U. o r r e t B o u n d a r y C o n d i t i o n s ( ) ;
U. w r i t e ( ) ;

At the rst line entres is reated and initialised to mesh.C(). That means
that now entres is the eld gathering all the entres of the mesh. It is like a
ve tor where there are all the numbers orrsponding to the entres : 1 for the
rst entre, 2 for the se ond, et ...Then we make a loop on all these numbers
with the variable elli that will take ea h value of the ve tor entres. Then we
he k with the if ondition if the enter is in the left or right part. p, T and U
are also ve tors and the pla e of their omponents orrespond to the ells of
the mesh : rst omponent for the rst entre...so the omponent orrepond-

CHAPTER 4.

VALIDATION TESTS

40

ing to the enter is lled depending on the pla e of the enter in the sho k
tube. The values of pL (pressure left), pR (pressure right), TL, et are written in the le $FOAM_RUN/tutorials/soni Foam/ onstant/initProperties.
At the end we write the new omponents of p, T and U in their respe tive
les. These elds be ome non uniform.

x0

0 ;

pL
TL
UL

1 . 0 e+5 ;
298.0 ;
( 0 0 0 ) ;

pR
TR
UR

1 . 0 e+4 ;
298.0 ;
( 0 0 0 ) ;

Maybe here we ould improve this utility by removing the parts of the
velo ity and of the temperature be ause they are uniform. This way, we
ould save some se onds.
About the onstants, we take R = 287m2 /(s2 K) and Cv = 717.5m2 /(s2
K).
If you have used funkySetFields, you need to initialize the temperature
and the velo ity.
For a perfe t gas, the density is :
=

p
RT

We are going to use again the solver soni Foam, for 7 ms with a time
step of 0.01 ms.
The boundary spe i ations are :
left and right : extrapolatedOutlet
other boundaries : empty
4.2.2 Results

Here are eight pi tures of the results for the density from 0 to 0.007s with a
time step of 0.001s. The rst dis ontinuity is alled the onta t dis ontinuity.

CHAPTER 4.

VALIDATION TESTS

41

CHAPTER 4.

VALIDATION TESTS

42

Here are eight pi tures of the results for the velo ity from 0 to 0.007s
with a time step of 0.001s :

CHAPTER 4.

VALIDATION TESTS

43

Here are eight pi tures of the results for the pressure from 0 to 0.007s
with a time step of 0.001s :

CHAPTER 4.

VALIDATION TESTS

44

CHAPTER 4.

45

VALIDATION TESTS

4.2.3 Comparison with the analyti al results

For this exa t situation there exists a model (the Sod's model) that des ribes
exa tly the sho k, see the following website to have more informations :
http://www.engineering.u sb.edu/ shengtai/MM/html/node12.html.
I am going to ompare the results at the nal time, 0.007 s. In order to
get the graphs with the analyti al and numeri al urves I have used the free
software gnuplot.
shockTube - density rho
1.2
analytical solution
numerical solution
1

rho

0.8

0.6

0.4

0.2

0
-5

-4

-3

-2

-1

Figure 4.7: Density at 0.007s

CHAPTER 4.

46

VALIDATION TESTS

shockTube - velocity Ux
300
analytical solution
numerical solution
250

Ux

200

150

100

50

0
-5

-4

-3

-2

-1

Figure 4.8: Velo ity at 0.007s


shockTube - pressure p
100000
analytical solution
numerical solution
90000
80000
70000

60000
50000
40000
30000
20000
10000
-5

-4

-3

-2

-1

Figure 4.9: Pressure at 0.007s


What we an see from these graphs is that the numeri al results t well
to the theoriti al ones. Of ourse it does not perfe tly t but that is not so
bad. Dis ontinuities are done in less than ten points, whi h is orre t.

Chapter 5

Comparison with JADIM VOF

5.1

Presentation of JADIM VOF

JADIM VOF is a resear h ode developped by Ja ques Magnaudet and Dominique Legendre of the Interfa e group at IMFT. It is a numeri al tool
whi h omputes numeri al solutions for Navier-Stokes equations in three dimensions for in ompressible non stationary uids. The ode an des ribe in
an a urate way physi al me anisms present in diphasi ows.
JADIM uses the nite volum method with se ond order in spa e and in
time (third order Runge-Kutta sheme for non linear term resolution oupled
with a Crank-Ni holson s heme for the semi-impli it part). A stru tured
mesh is used. The pressure is omputed from a proje tion method. The
poisson's equation is solved using a dire t soarse solver in two dimensions
(MUltifrontal Massively Parallel sparse dire t Solver or MUMPS) and an
iterative sparse solver in three dimensions (Conjugate Gradient with Ja obi
pre onditioning). The Volum Of Fluid (VOF) algorithm is a two uid approa h without interfa e rebuilding, whi h permits to model two phase ows
with omplex topology interfa es.
5.2

Running the same ase - a rising bubble

In order to ompare the JADIM and OpenFOAM odes, I have hosen a test
ase of JADIM and I have tried to solve it by the solver interFoam.
5.2.1 Presentation of the ase

Suppose that we have initially a uid at rest in a re tangular box. At time


t = 0 s, a bubble is formed at the bottom of the box with no velo ity. The
goal is to follow this bubble moving from the bottom to the top of the box.
Here are the properties of the two uids :
densities : 1 = 1kg/m3 and 2 = 103 kg/m3
47

CHAPTER 5.

COMPARISON WITH JADIM VOF

kinemati vis osities :


surfa e tension :
gravity :

48

1 = 2 = 0.68415 104 m2 /s

= 0.3442N/m

g = 9.81m/s2

We are going to ompute the results for 0.14 s with a time step of 1.4
so 1000 steps with the solver interFoam.
Fig 5.1 shows the geometry :

104 s

Figure 5.1: Geometry of the bubble ase


The bla k numbers represent the measures of the geometry and the blue
ones the number of ells in ea h dire tions.
We have here a non uniform initial ondition (the bubble). I have used
the utility funkySetFields with this ommand :
funkySetFields $FOAM_RUN/tutorials/interFoam as ension -time 0 eld gamma -expression sqrt(sqr(pos().x - 4. * pow(10.,-2.)) + sqr(pos().y
- 16. * pow(10.,-3.))) <= 0.005 ? 0 : 1
This ase is not a tutorial, you need to reate the ase and the geometry
on your own. The boundaries of the geometry are all walls.
5.2.2 Results

Here are the pi tures of the as ension of the bubble through the uid from
0 to 0.14 s. The rst pi ture orresponds to 0 s, the se ond to 0.01 s, the
third to 0.02s, et ...

CHAPTER 5.

COMPARISON WITH JADIM VOF

5.2.3 Comparison with JADIM

49

I have run this ase with both odes, JADIM and OpenFOAM, on the same
omputer. With JADIM, it took 454 s and with OpenFOAM 504 s. JADIM
is around 10% faster, whi h is not negligible when you want to solve ompli ate ases. I have superimposed the bubble of JADIM and OpenFOAM at
the nal time, 0.14 s (see g 5.2 to g 5.5). It seems that JADIM's bubble is
a little bit earlier than OpenFOAM's one but the dieren e is not signi ant.
Figs 5.2 and 5.3 are the ontours of the bubbles at = 0.1 0.5 0.9.

CHAPTER 5.

COMPARISON WITH JADIM VOF

Figure 5.2: OpenFOAM's bubble

Figure 5.3: JADIM's bubble

50

CHAPTER 5.

COMPARISON WITH JADIM VOF

Figure 5.4: Superimposing the two bubbles

Figure 5.5: Zoom on the bubble

51

Chapter 6

Con lusion

The goal of my internship was to dis over the OpenFOAM software, to run
some ases and to write a paper to explain how to use it.
After two weeks of C++ learning, I have started to dis over OpenFOAM.
I did not have any experien e on Computational Fluid Dynami s software
(only a ouple of hours to see Fluent working). My rst impression was that
it was really ompli ated, not by the te hni , it was more by the hugeness
of OpenFOAM : too mu h things for a beginner. Thanks to the tutorials of
the User's Guide, I have learned little by little to tame the ode and to use
it.
I have worked a lot on the tutorials, see how things were written, how
utilities were oded. Then I started to read the forum. I think this is a great
forum, there is a lot of people on it and most of the time you nd what you
are looking for. I have learned a lot on it.
I have tried to ode a little. I was qui kly lost : too mu h lasses, too
mu h fun tions. It is normal of ourse. Maybe what ould be done to
simplify the task of the beginer would be to write a new guide with the
main header les, variables, lasses and fun tions like the time, the spa e
variables, et ...just the minimum to start to ode. Of ourse on the website
http://foam.sour eforge.net/do /Doxygen/html/ all the lasses are listed so
if you know what to look, this is a really good data base.
Some people on the forum su eeded in writing modules for OpenFOAM.
That is why I think this software is very good if you are a resear her that is
used to ode but maybe not the best to dis over the eld of modeling uids
for students.
As a on lusion, I would say that OpenFOAM is a very good software,
the possibility to add modules is innite and it gives good results. Even if I
have found it di ult to start with, it is worth it.

52

Appendix A

File . sv to .txt

When you get results from the lters probe or data anlysis you an save data
in a sv format le. This looks like the following :

v o l P o i n t I n t e r p o l a t e (Ux) , 7 . 4 3 9 2 8 e 11 ,2.25881 e 10 ,9.6436 e 10 ,3.9076 e 09 ,
1 . 5 4 4 9 2 e 08 ,5.94779 e 08 ,2.22768 e 07 ,8.10977 e 07 ,2.8667 e 06 ,9.82898 e 06 ,
3.26485 e 05 ,0.000104926 ,0.000325788 ,0.000975738 ,0.0028138 ,0.00779737 ,
0.0207158 ,0.0526296 ,0.127482 ,0.293452 ,0.639835 ,1.31723 ,2.55235 ,4.64172
volPointInterpolate (p) ,100000 ,100000 ,100000 ,100000 ,100000 ,100000 ,100000 ,
100000 ,100000 ,100000 ,100000 ,100000 ,99999.9 ,99999.6 ,99998.9 ,99997 ,99992 ,
99979.5 ,99950 ,99884.6 ,99747.7 ,99479.5 ,98990.1 ,98164.5 ,96881.8 ,95054.3 ,
92673.4 ,89838.7 ,86709.7 ,83420.5 ,80061 ,76693.3 ,73360 ,70089.9
X
T, 5 , 4.9 , 4.8 , 4.7 , 4.6 , 4.5 , 4.4 , 4.3 , 4.2 , 4.1 , 4 , 3.9 , 3.8 ,
3.7 , 3.6 , 3.5 , 3.4 , 3.3 , 3.2 , 3.1 , 3 , 2.9 , 2.8 , 2.7 , 2.6 , 2.5 , 2.4 ,
2.3 , 2.2 , 2.1 , 2 , 1.9 , 1.8 , 1.7 , 1.6 , 1.5 , 1.4 , 1.3 , 1.2 , 1.1 , 1 , 0.9 ,
0.8 , 0.7 , 0.6 , 0.5 , 0.4

or

Values are stored in lines after the name of the variable, between omas.
The software gnuplot needs to have the values in olumns. Alexe Stoukov
has written this s ript in perl in order to onvert the data into the orre t
form
:

#! / u s r / bin / p e r l
 l i n e s = <>;
forea h $line
( $line
( $line
( $line

if
if
if

(  l i n e s ){
=~ m/ v o l P o i n t I n t e r p o l a t e \(Ux\)/ ){u = s p l i t ( ' , ' , $ l i n e ) } ;
=~ m/ v o l P o i n t I n t e r p o l a t e \( p \)/ ){p = s p l i t ( ' , ' , $ l i n e ) } ;
=~ m/X/ ){x = s p l i t ( ' , ' , $ l i n e ) } ;

for

( $ i =1; $i <$#x ; $ i++ ) {


p r i n t " $x [ $ i $u [ $ i $p [ $ i \ n" ;

You an use this s ript like : ./s ipt.pl le. sv > le.txt

It will reate a le .txt where there will be the data in olumns.

5 7 . 4 3 9 2 8 e 11 100000
4.9 2 . 2 5 8 8 1 e 10 100000
4.8 9 . 6 4 3 6 e 10 100000
4.7 3 . 9 0 7 6 e 09 100000
4.6 1 . 5 4 4 9 2 e 08 100000
4.5 5 . 9 4 7 7 9 e 08 100000
4.4 2 . 2 2 7 6 8 e 07 100000
4.3 8 . 1 0 9 7 7 e 07 100000

53

Appendix B

Sod's model

There is an analyti al solution for the sho k tube. I have used the following
oed in order to ompare the numeri and the analyti al results. It is written
in Fortran90.

Program exa t_sod
! // ///////////////////////////////////////////////////////////////
!/
! / Program a l u l a t e s the e x a t s o l u t i o n to Sodsho k tube
! / problems namely sho k t u b e s whi h produ e sho ks , o n t a t
!/
dis ontinuities ,
r a r e f r a t i o n waves .
!/
! / S o l u t i o n i s omputed at l o a t i o n s x at time t . ( Though
! / due to s e l f s i m i l a r i t y , the e x a t s o l u t i o n i s i d e n t i a l
!/
i d e n t i a l v a l u e s o f x/ t ) .
!/
! / NOTE : S i n e the post sho k f l o w i s n o n a d i a b a t i , whereas
! / the f l o w i n s i d e the r a r e f r a t i o n f a n i s a d i a b a t i , the problem
!/
is
l e f t r i g h t symmetri . In p a r t i u l a r , the high d e n s i t y
!/
i n i t i a l s t a t e MUST BE i n p u t on the l e f t s i d e .
!/
! / Written by Robert F i s h e r , 1 2 / 5 / 9 6 .
! / M o d i f i e par A. Stoukov , 21/10/2003
!/
p a s s a g e en F90
!/
l e t u r e des donnees d e p u i s l e f i h i e r
! // ///////////////////////////////////////////////////////////////

lass

and

for

not

i m p l i i t none
r e a l 8 gamma , mu2 , t , x0
r e a l 8 , a l l o a t a b l e , dimension ( : ) : : x , x , u , p , rho
integ er num ells
! xmax d e t e r m i n e s the s i z e o f the o m p u t a t i o n a l domain (xmax , +xmax ) .
! n u m e l l s d e t e r m i n e s the number o f e l l s i n the output t a b l e .
parameter (gamma
=
1 . 4 D0)
parameter (mu2
=
(gamma 1 . D0) / (gamma + 1 . D0 ) )
r e a l 8 pl , pr , r h o l , rhor , l , r , pm, p r e s s u r e , &
rhoml , vs , vt , rhomr , vm, d e n s i t y , v e l o i t y ,&
0 , rho0 , p0 , 1 , p1 , rho1 , us , u1
h a r a t e r 100 fname
integer i
ommon/ b l o k 1 / pl , pr , r h o l , rhor , l , r
r e a l 8 r t b i s
External rt b is
! D e f i n e the time o f the problem .
p r i n t , ' Donnez l e noms du f i h i e r a t r a i t e r : '
read ( , ) fname
p r i n t , ' Donnez l e temps : '
read ( , ) t

54

APPENDIX B.

55

SOD'S MODEL

! Premiere l e t u r e du f i h i e r a f i n de d e t e r m i n e r l e nombre de p o i n t s
open ( 1 0 , f i l e =fname )
i = 1 ,1000000000
read ( 1 0 , , end=111)
end
111
n u m e l l s = i 1
print , num ells
los e (10)
a l l o a t e ( x ( n u m e l l s ) , x ( n u m e l l s ) , u ( n u m e l l s ) , rho ( n u m e l l s ) , p ( n u m e l l s ) )
open ( 1 0 , f i l e =fname )
i = 1 , num ells
read ( 1 0 , ) x ( i ) , u ( i ) , p ( i ) , rho ( i )
end
! x0 = 0 . 5 ( x ( n u m e l l s ) x ( 1 ) )
x0 = 0 .
0 = s q r t (gamma p ( 1 ) / rho ( 1 ) )
1 = s q r t (gamma p ( n u m e l l s )/ rho ( n u m e l l s ) )
p1 = p ( n u m e l l s )
rho1 = rho ( n u m e l l s )
p0 = p ( 1 )
rho0 = rho ( 1 )
us = 1
u1 = us 0
p r i n t , ' V i t e s s e du sho k = ' , us , u1
t = t ! 1
i = 1 , num ells
x ( i ) = x ( i ) x0
p ( i ) = p ( i ) ! / p0
rho ( i ) = rho ( i ) ! / rho0
u ( i ) = u ( i ) ! / 0
end
! D e f i n e the Sod problem i n i t i a l o n d i t i o n s
the l e f t
right states .

do

do
ontinue

do

do

do

do

for

and

pl = p(1)
pr = p ( n u m e l l s )
r h o l = rho ( 1 )
r h o r = rho ( n u m e l l s )
p r i n t , pl , pr , r h o l , r h o r
! D e f i n e sound s p e e d s

for

the l e f t

and

r i g h t s i d e s o f tube .

l = d s q r t (gamma p l / r h o l )
r = d s q r t (gamma pr / r h o r )
! Solve

for

the p o s t s h o k p r e s s u r e pm.

pm = r t b i s ( pr , pl , 1 .D 16)
! D e f i n e the d e n s i t y to the l e f t o f the o n t a t d i s o n t i n u i t y rhoml .
rhoml = r h o l (pm / p l ) ( 1 . D0 / gamma)
! D e f i n e the p o s t s h o k f l u i d v e l o i t y vm.
vm = 2 . D0 l / (gamma 1 . D0) ( 1 . D0 (pm / p l ) &
( (gamma 1 .D0) / ( 2 . D0 gamma) ) )
! D e f i n e the p o s t s h o k d e n s i t y rhomr .
rhomr = r h o r

( (pm + mu2 pr ) / ( pr + mu2 pm) )

! D e f i n e the sho k v e l o i t y vs .
vs = vm / ( 1 . D0 r h o r / rhomr )
! D e f i n e the v e l o i t y o f the r a r e f r a t i o n t a i l , vt .
vt = l vm / ( 1 . D0 mu2)
! Output t a b l e s o f d e n s i t y , v e l o i t y ,

and

p r e s s u r e at time t .

open ( u n i t = 16 , f i l e = ' d i f f . out ' )

do

i = 1 , num ells

if ( x ( i ) . l e . l
density = rhol
else i f ( x ( i ) . l e .

t ) then

vt t ) then
d e n s i t y = r h o l (mu2 ( x ( i )
( 2 . D0 / (gamma 1 . D0 ) )
( x ( i ) . l e . vm t ) then

else i f

/ ( l t ) ) + (1 mu2) ) &

APPENDIX B.

d e n s i t y = rhoml

else i f ( x ( i ) . l e .
d e n s i t y = rhomr
else
density = rhor
end if
if ( x ( i ) . l e . l
!

56

SOD'S MODEL

vs t ) then

t ) then
pressure = pl
p r i n t , ' Pl = ' , p r e s s u r e
( x ( i ) . l e . vt t ) then
p r e s s u r e = r h o l (mu2 ( x ( i ) / ( l t ) ) + (1 mu2) ) &
p r e s s u r e = p l (mu2 ( x ( i ) / ( l t ) ) + (1 mu2) ) &
( 2 . D0 gamma / (gamma 1 . D0 ) )
p r i n t , ' P = ' , p r e s s u r e
( x ( i ) . l e . vs t ) then
p r e s s u r e = pm
p r i n t , ' Pm = ' , p r e s s u r e

else i f
else i f
else

p r e s s u r e = pr
p r i n t , ' Pr = ' , p r e s s u r e
end

if
if ( x ( i ) . l e . l t ) then
velo ity = 0.0
else i f ( x ( i ) . l e . vt t ) then
v e l o i t y = (1 mu2) ( x ( i ) /
else i f ( x ( i ) . l e . vs t ) then
v e l o i t y = vm
else
velo ity = 0.0
end if

t + l )

w r i t e ( 1 6 , 10) x ( i ) , d e n s i t y , rho ( i ) , v e l o i t y , u ( i ) , p r e s s u r e , p ( i )
end

do

lose (6)
! 10
10

format ( D22 . 1 6 , ' ' , D22 . 1 6 , ' ' , D22 . 1 6 , ' ' , D22 . 1 6 )
format ( 7 ( e12 . 6 , 1 x ) )
End

f u n t i o n fun (pm)
! // ////////////////////////////////////////////////////////////////////
!/
! / fun i s o b t a i n e d from an i d e n t i t y mat hing the post sho ked
! / p r e s s u r e to the post r a r e f r a t i o n p r e s s u r e (
sin e there is
! / no p r e s s u r e jump a r o s s the o n t a t d i s o n t i n u i t y ) . We use i t to
!/ numeri ally solve
pm g i v e n the l e f t
right i n i t i a l states .
!/
! // ////////////////////////////////////////////////////////////////////

for

and

true

i m p l i i t none
r e a l 8 fun , pm
r e a l 8 gamma , mu2
parameter (gamma
parameter (mu2

=
=

1 . 4 D0)
(gamma 1 . D0) / (gamma + 1 . D0 ) )

r e a l 8 pl , pr , r h o l , rhor , l , r
ommon/ b l o k 1 / pl , pr , r h o l , rhor , l , r
fun = 2 l (1 (pm/ p l ) (( 1 + gamma) / ( 2 gamma) ) ) /
&
( r ( 1 + gamma) ) &
( 1 + pm/ pr ) ( ( 1 mu2 ) / (gamma (mu2 + pm/ pr ) ) ) 0 . 5

return
end

FUNCTION r t b i s ( x1 , x2 , xa )
! // ///////////////////////////////////////////////////////////////////////
!/
! / r t b i s i s borrowed from Numeri al R e i p e s . I t i s a b i s e t i o n algorithm ,
! / whi h we use to s o l v e
pm
a a l l to fun .

for

using

APPENDIX B.

57

SOD'S MODEL

!/
! / Note t h a t the arguments to r t b i s have been a l t e r e d
the v a l u e o f
! / JMAX i n r e a s e d . Otherwise , i t i s i d e n t i a l to the NR v e r s i o n .
!/
! // ///////////////////////////////////////////////////////////////////////

and

INTEGER JMAX
REAL 8 r t b i s , x1 , x2 , xa , fun
EXTERNAL fun
PARAMETER (JMAX=100)
INTEGER j
REAL 8 dx , f , fmid , xmid
fmid=fun ( x2 )
f=fun ( x1 )
( f fmid . ge . 0 . ) pause ' r o o t must be b r a k e t e d i n r t b i s '
( f . l t . 0 . ) then
r t b i s=x1
dx=x2x1

if
if

else

r t b i s=x2
dx=x1x2
endif
11 j =1,JMAX
dx=dx 5 .D1
xmid=r t b i s+dx
fmid=fun ( xmid )
( fmid . l e . 0 . ) r t b i s=xmid
( dabs ( dx ) . l t . xa .
. fmid . eq . 0 . )

do
11

if
if
ontinue

or

return

pause ' too many b i s e t i o n s i n r t b i s '


END

The ode will ask you the name of the le where the numeri al results are
saved and the time where these results were taken. It will write an output
le di.out that an be used by gnuplot.

Appendix C

Websites memo

Here is a list of the websites that I have often used :


OpenFOAM o ial website : www.open fd. o.uk
OpenFOAM forum : http://openfoam. fd-online. om/ gi-bin/forum
C++ sour e guide : http://foam.sour eforge.net/do /Doxygen/html
funkySetFields website : http://openfoamwiki.net/index.php/

Contrib_funkySetFields

58

You might also like