OF Example PDF
OF Example PDF
« Simulation in porous media from pore to large scale »
Stanford
Contact: [email protected] October 27, 2014
Version 5.0
Previously in OpenFOAM training...
So far, we have used OpenFOAM as a black box.
Actually, one of the strength of OpenFOAM is its simplicity to program partial differential equations:
[email protected] 2
General introduction to the OpenFOAM® technology
What is OpenFOAM ?
Where one can find help and documentation ?
#2 – Cavity
#3 – Poiseuille flow
#4 – Drainage experiment in a capillary tube
How to mesh complex geometry with OpenFOAM® ?
snappyHexMesh overview
#5 – Mesh a pore-space with snappyHexMesh
#6 – Scalar transport in porous media at the pore-scale
Programming equations with OpenFOAM®
General structure of an application
Basics of OpenFOAM programming
1 solver = 1 program
(for instance, the heat equation is solved using the program laplacianFoam)
OpenFOAM® initiation
The solvers are organized by type (basic, heat transfer, combustion, incompressible,
multiphase….). Note that the tutorials have a similar organisation.
[email protected] 4
Behind laplacianFoam: laplacianFoam.C
$ gedit laplacianFoam.C
[email protected] 5
Behind laplacianFoam: createFields.H
$ gedit createFields.H The temperature field T is declared as an instance of
the object volScalarField
- It is a scalar field with values defined at the cell
center
- It must be read at the initial time step
- Dimensions (units) are defined in 0/T
OpenFOAM® initiation
[email protected] 6
General structure of an application
Source code
The file with the .C extension is the main file
Create the directory for your personnal programs (this stage only needs to be done once)
$ mkdir -p $WM_PROJECT_USER_DIR/applications/solvers/
[email protected] 7
#7 – Program a “Darcy” solver (1a/6)
Objective: develop a program that solves the flow in a fully saturated porous
medium using Darcy's law.
(1)
(2)
OpenFOAM® initiation
How to solve this mathematical problem? The diffusion equation for the pressure field
is obtained by combining equation (1) and (2):
We are going to program our own solver on the basis of the existing laplacianFoam
$ cd $WM_PROJECT_USER_DIR/applications/solvers/
$ cp –r $FOAM_APP/solvers/basic/laplacianFoam darcyFoam
[email protected] 8
#7 – Program a “Darcy” solver (1b/6)
Once the laplacianFoam solver has been copied into the user directory, we rename the main file
and edit the Make/files :
$ cd darcyFoam
$ mv laplacianFoam.C darcyFoam.C
$ gedit Make/files
Add _USER_ to specify that the new executable will be compiled into
your user directory (without _USER_ your compilation will fail!)
We can now clean the previous compilation with wclean and compile this new program with wmake.
$ wclean
$ wmake
At this stage, we have a new program called darcyFoam which is exactly a copy of laplacianFoam
(you can run it on the flange tutorial or Exo1).
[email protected] 10
#7 – Program a “Darcy” solver (3/6)
$ gedit darcyFoam.C
$ rm write.H
$ wclean
$ wmake
[email protected] 11
#7 – Program a “Darcy” solver (4/6)
To prepare this « case » we are going to mimic the tutorial
Tip to define the laplacianFoam/flange, since its setup is quite similar to our example
vertices coordinates
$ run
$ cp -r $FOAM_TUTORIALS/basic/laplacianFoam/flange Exo7
$ cd Exo7
$ rm Allrun Allclean flange.ans
OpenFOAM® initiation
Mesh definition 3
2
(homogeneous grid with a inlet 7 6 outlet
single cell in the y and z axis 0
1
since the simulation is 1D)
y 4 5
z x 10 m
$ cp $FOAM_TUTORIALS/incompressible/icoFoam/cavity/constant/
polyMesh/blockMeshDict constant/polyMesh/.
Faces orthogonal to Oy $ gedit constant/polyMesh/blockMeshDict
and Oz axis are defined
as «empty» to specify that
the simulation is 1D
[email protected] 13
#7 – Program a “Darcy” solver (5b/6)
$ gedit system/fvSchemes
$ gedit constant/transportProperties
OpenFOAM® initiation
$ gedit system/fvSolution
[email protected] 14
#7 – Program a “Darcy” solver (5c/6)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 15
#7 – Program a “Darcy” solver (6/6)
Run the simulation : $ darcyFoam
Results will be plotted using the sample utility and the program Gnuplot. As blockMesh, the program
sample requires an input dictionary located in /system :
$ cp $FOAM_UTILITIES/postProcessing/sampling/sample/sampleDict system/.
$ gedit system/sampleDict
$ gnuplot
gnuplot> set xlabel "distance (m)"
gnuplot> set ylabel "Pressure (kg/m/s)"
gnuplot> plot “postProcessing/sets/1/lineX1_p.xy" using 1:2 with
lines lw 4 title "p“
Run the sample tool: Exo7Bis: Program a solver for heterogeneous porous media
$ sample
defining the permeability as a volScalarField and assigning it
different values with the utility setFields.
[email protected] 16
#8 – Heat transfer in porous media (1/7)
(1)
(2)
OpenFOAM® initiation
(3)
Objective 2: Use probes to plot the temperature evolution vs time at some points of
the domain
$ wclean
$ wmake
[email protected] 17
#8 – Heat transfer in porous media (2a/7)
$ gedit createFields.H
$ wmake
[email protected] 18
#8 – Heat transfer in porous media (2b/7)
$ gedit createFields.H
OpenFOAM® initiation
$ wmake
[email protected] 19
#8 – Heat transfer in porous media (3/7)
$ gedit darcyTemperatureFoam.C
$ wmake
Compilation of darcyTemperatureFoam
[email protected] 20
#8 – Heat transfer in porous media (4/7)
Probe 3
Probe 1 Probe 2
OpenFOAM® initiation
P1
P0
10 m Free stream
Tin
at the outlet
Porous medium with a permeability
k and a porosity eps
To save time, we can adapt the previous exercise to setup the case
$ run
$ cp –r ../Exo7 Exo8
$ cd Exo8
$ rm –r 0.* 1* 2* 3* 4* 5* 6* 7* 8* 9* postProcessing
$ cp 0/p 0/T
$ gedit 0/T
[email protected] 21
#8 – Heat transfer in porous media (5a/7)
$ gedit 0/T $ gedit 0/p
OpenFOAM® initiation
[email protected] 22
#8 – Heat transfer in porous media (5b/7)
$ gedit constant/transportProperties $ gedit system/fvSchemes
OpenFOAM® initiation
$ gedit system/fvSolution
[email protected] 23
#8 – Heat transfer in porous media (5c/7)
$ gedit system/controlDict
[email protected] 24
#8 – Heat transfer in porous media (6/7)
Run the simulation : $ darcyTemperatureFoam
We are going to plot the probe results with the following gnuplot script $ gedit plot_probes
OpenFOAM® initiation
[email protected] 25
#8 – Heat transfer in porous media (7/7)
Note in the previous simulation some unphysical oscillations at the temperature front. They are due
to the numerical scheme used to descretize the convection term. To improve the numerical stability,
you can use an upwind scheme or a flux limiter by specifying Gauss upwind or Gauss vanLeer in
system/fvSchemes instead of Gauss linear.
OpenFOAM® initiation
The upwind scheme is better than the linear but also more diffusive. The flux limiter schemes are
more suitable for this kind of simulation.
[email protected] 26
#9 – Two-temperature model (1/6)
Objectif n°1 : Résoudre un transfert de chaleur dans un milieu poreux
par un modèle à 2 équations
(1)
(2)
OpenFOAM® initiation
(3)
(4)
[email protected] 27
#9 – Two-temperature model (2/6)
$ gedit createFields.H
Le champ U est
maintenant initialisé à
partir de 0/U, ce qui
nous permet de définir
des conditions d’entrée
OpenFOAM® initiation
pour U
Déclaration des
champs de
température pour le
solide et pour le
fluide
[email protected] 28
#9– Two-temperature model (3/6)
$ gedit darcyTwoTemperaturesFoam.C
Résolution de la température
dans la matrice poreuse.
$ wclean
$ wmake
[email protected] 29
#9 – Two-temperature model (4/6)
On cherche à évaluer le transfert de chaleur dans un milieu poreux 1D via un modèle à
deux températures
Dans cet exemple, un milieu poreux initialement à 573K est refroidit par l’injection d’un
fluide à 273K
OpenFOAM® initiation
$ run
$ mkdir darcytwoTemperaturesFoam
$ cp –r ../darcyTemperatureFoam/Exo8 Exo10
$ cd Exo10
$ rm –r 0.* 1* 2* 3* 4* 5* 6* 7* 8* 9* sets probes
$ mv 0/T 0/Tf
$ cp 0/Tf 0/Ts
$ gedit 0/Tf
[email protected] 30
#9 – Two-temperature model (5a/6)
$ gedit 0/U
OpenFOAM® initiation
[email protected] 31
#9– Two-temperature model (5b/6)
$ gedit 0/p
OpenFOAM® initiation
[email protected] 32
#9 – Two-temperature model (5c/6)
$ gedit 0/Ts
OpenFOAM® initiation
[email protected] 33
#9 – Two-temperature model (5d/6)
$ gedit 0/Tf
OpenFOAM® initiation
[email protected] 34
#9 – Two-temperature model (5e/6)
$ gedit constant/transportProperties
OpenFOAM® initiation
[email protected] 35
#9 – Two-temperature model (5f/6)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 36
#9 – Two-temperature model (5g/6)
$ gedit system/fvSolution $ gedit system/fvSchemes
OpenFOAM® initiation
[email protected] 37
#9 – Two-temperature model (6/6)
On lance la simulation : $ darcyTwoTemperaturesFoam
On post-traite ensuite les résultats (ici on a tracé les valeurs de Ts et Tf en fonction du temps pour
les 3 sondes)
OpenFOAM® initiation
[email protected] 38
In the next parts...
http://web.stanford.edu/~csoulain/