Professional Documents
Culture Documents
gettingStartedWithOpenFOAMLeroux Sep2007
gettingStartedWithOpenFOAMLeroux Sep2007
Author:
Delphine
Department:
Leroux
COSINUS
Contents
2 Deepening
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. 3
. 4
. 4
. 4
. 11
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
4 Validation tests
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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
1.1
General presentation
CHAPTER 1.
1.2
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
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).
CHAPTER 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
(
);
CHAPTER 1.
CHAPTER 1.
CHAPTER 1.
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.
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.
Physi al properties
CHAPTER 1.
10
Control
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
CHAPTER 1.
11
A ept.
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.
12
CHAPTER 1.
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 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
CHAPTER 2.
DEEPENING
16
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).
CHAPTER 2.
DEEPENING
17
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
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
Solving
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 :
CHAPTER 2.
2.3
DEEPENING
19
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 :
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
CHAPTER 2.
DEEPENING
21
mation.
CHAPTER 2.
DEEPENING
22
CHAPTER 2.
DEEPENING
23
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.
Cell Centers
CHAPTER 2.
DEEPENING
24
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).
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
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
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).
Chapter 3
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
Let us try to break this dam! Go to the dire tory of the tutorial ase
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.
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
);
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.
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.
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.
EXE_LIBS = \
//
l f i n i t e V o l u m e \
lmeshTools
librairies
to
32
link
CHAPTER 3.
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
CHAPTER 4.
VALIDATION TESTS
35
U
, c = 1 U = Ma
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
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
CHAPTER 4.
VALIDATION TESTS
37
CHAPTER 4.
VALIDATION TESTS
38
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 :
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
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
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
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
60000
50000
40000
30000
20000
10000
-5
-4
-3
-2
-1
Chapter 5
5.1
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
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
CHAPTER 5.
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
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.
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.
50
CHAPTER 5.
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
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
! 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 .
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
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
Contrib_funkySetFields
58