Professional Documents
Culture Documents
gettingStartedWithOpenFOAMLeroux Sep2007 PDF
gettingStartedWithOpenFOAMLeroux Sep2007 PDF
gettingStartedWithOpenFOAMLeroux Sep2007 PDF
Author: Department:
Delphine Leroux COSINUS
1
CONTENTS 2
4.2.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.2.3 Comparison with the analyti
al results . . . . . . . . . 45
5 Comparison with JADIM VOF 47
5.1 Presentation of JADIM VOF . . . . . . . . . . . . . . . . . . 47
5.2 Running the same
ase - a rising bubble . . . . . . . . . . . . 47
5.2.1 Presentation of the
ase . . . . . . . . . . . . . . . . . 47
5.2.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.2.3 Comparison with JADIM . . . . . . . . . . . . . . . . 49
6 Con
lusion 52
A File .
sv to .txt 53
B Sod's model 54
C Websites memo 58
Chapter 1
OpenFOAM
3
CHAPTER 1. PRESENTATION OF THE SOFTWARE OPENFOAM 4
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 de-
s
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 dimen-
sional 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).
The blo
k stru
ture expe
ted is shown in g 1.3:
CHAPTER 1. PRESENTATION OF THE SOFTWARE OPENFOAM 6
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 8
With these two ways, we get the same result (g 1.6):
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.
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.
To see the nal result,
li
k on 0.5 s (nal time) and on the green button
A
ept. 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).
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.
14
CHAPTER 2. DEEPENING 15
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
tio-
naries 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 his-
tory 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
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 (an-
sysToFoam, gambitToFoam, et
).
2.2 Solving
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, graph-
i
s, paraFoam ) or in a terminal write:
paraFoam root nameCase
You
an do some post-pro
essing jobs dire
tly from FoamX like U
om-
ponents 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
at-
egory 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
ess-
fully 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
You
an see that you have three panels : Parameters, Display and Infor-
mation. On 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 Infor-
mation 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).
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
makes a ut
analyzes a point and plots data over the time (it will be used later)
generates streamtra es
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
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.
We
an display also the velo
ity like ve
tors (g 2.7). First sele
t the
Cell Centers 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.
CHAPTER 2. DEEPENING 24
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.
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 un-
sele
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).
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).
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
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.
29
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 utili-
ties (*.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.
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 32
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
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 :
CHAPTER 3. SETTING A NON UNIFORM INITIAL CONDITION 33
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
34
CHAPTER 4. VALIDATION TESTS 35
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.
The stagnation temperature is more or less
ontant ex
ept near the be-
gining of the tilted plan (see gs 4.3 and 4.4).
CHAPTER 4. VALIDATION TESTS 37
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
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
(
(
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;
}
else
{
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 writ-
ten 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 1 . 0 e+5 ;
TL 298.0 ;
UL ( 0 0 0 ) ;
pR 1 . 0 e+4 ;
TR 298.0 ;
UR ( 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
ρ=
R·T
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. VALIDATION TESTS 45
0.8
rho
0.6
0.4
0.2
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
x
shockTube - velocity Ux
300
analytical solution
numerical solution
250
200
Ux
150
100
50
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
x
shockTube - pressure p
100000
analytical solution
numerical solution
90000
80000
70000
60000
p
50000
40000
30000
20000
10000
-5 -4 -3 -2 -1 0 1 2 3 4 5
x
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
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 48
gravity : g = 9.81m/s2
We are going to
ompute the results for 0.14 s with a time step of 1.4 ·
10−4 sso 1000 steps with the solver interFoam.
Fig 5.1 shows the geometry :
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 49
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 or 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
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 −w
l i n e s = <>;
forea
h $line ( l i n e s ){
if ( $line =~ 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 ) } ;
if ( $line =~ 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 ) } ;
if ( $line =~ 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 Sod−sho
k tube
lass
! / problems −− namely sho
k t u b e s whi
h produ
e sho
ks ,
o n t a
t
!/ dis
ontinuities , and 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
for
! / 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 not 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
! // ///////////////////////////////////////////////////////////////
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. SOD'S MODEL 55
! 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 )
do i = 1 ,1000000000
read ( 1 0 , ∗ , end=111)
end do
111
ontinue
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 )
do i = 1 , num
ells
read ( 1 0 , ∗ ) x
( i ) , u ( i ) , p ( i ) , rho ( i )
end do
! 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
do 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 do
! 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 for the l e f t and right states .
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 ∗ t ) then
density = rhol
else i f ( x ( i ) . l e . − vt ∗ t ) then
d e n s i t y = r h o l ∗ (−mu2 ∗ ( x ( i ) / (
l ∗ t ) ) + (1 − mu2) ) ∗∗ &
( 2 . D0 / (gamma − 1 . D0 ) )
else i f ( x ( i ) . l e . vm ∗ t ) then
APPENDIX B. SOD'S MODEL 56
d e n s i t y = rhoml
else i f ( x ( i ) . l e . vs ∗ t ) then
d e n s i t y = rhomr
else
density = rhor
end if
if ( x ( i ) . l e . −
l ∗ t ) then
pressure = pl
p r i n t ∗ , ' Pl = ' , p r e s s u r e
else i f ( 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
else i f ( 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
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 ) / t +
l )
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
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 format ( D22 . 1 6 , ' ' , D22 . 1 6 , ' ' , D22 . 1 6 , ' ' , D22 . 1 6 )
10 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 ( true
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 for
pm g i v e n the l e f t and
right i n i t i a l states .
!/
! // ////////////////////////////////////////////////////////////////////
i m p l i
i t none
r e a l ∗ 8 fun
, pm
r e a l ∗ 8 gamma , mu2
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
ommon/ b l o
k 1 / pl , pr , r h o l , rhor ,
l ,
r
!/
! / Note t h a t the arguments to r t b i s have been a l t e r e d and
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 .
!/
! // ///////////////////////////////////////////////////////////////////////
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 )
if( 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 '
if( f . l t . 0 . ) then
r t b i s=x1
dx=x2−x1
else
r t b i s=x2
dx=x1−x2
endif
do 11 j =1,JMAX
dx=dx ∗ 5 .D−1
xmid=r t b i s+dx
fmid=fun
( xmid )
if ( fmid . l e . 0 . ) r t b i s=xmid
if ( dabs ( dx ) . l t . xa
. or . fmid . eq . 0 . ) return
11
ontinue
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
58