OPENFOAM FORMATION v5-1-EN
OPENFOAM FORMATION v5-1-EN
net/publication/304511422
CITATIONS READS
2 5,348
1 author:
Cyprien Soulaine
CNRS Orleans Campus
60 PUBLICATIONS 1,065 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
- Modeling of flow and transport in porous media - Supporting the creation of a household appliance that produces mineral water View project
All content following this page was uploaded by Cyprien Soulaine on 28 June 2016.
June, 23 2016
Contact: [email protected] Version 5.1 EN
http://web.stanford.edu/~csoulain/ (OF 3.0.1)
Foreword
I started this document in 2010 when I was discovering OpenFOAM® during
my PhD thesis. The initial idea was to have a document to train people from my
former lab at Institut de Mécanique des Fluides de Toulouse, in particular the
interns that need to be ready to work quickly.
This document has evolved a lot since the first version. It now gathers
OpenFOAM® initiation
Cyprien Soulaine
[email protected] 2
Objectives
[email protected] 3
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 geometries 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
Heat transfer in porous media with OpenFOAM®
#7 – Create a « Darcy » solver
#8 – Temperature in porous media
#9 – Customize boundary conditions
#10 – Two-equations model for heat transfer in porous media
How to solve Navier-Stokes equation with OpenFOAM®?
[email protected] 4
What is OpenFOAM® ?
Pre-processing:
-
OpenFOAM® initiation
Solvers:
- incompressible / compressible flow
- multiphase flow
- combustion, electro-magnetism, solid mechanics
- heat transfer
- several turbulence approach (DNS, RANS, LES)
- etc…
post-processing:
- Distributed with ParaView (and the famous paraFoam)
- Exportation toward other post-treatment softwares (Fluent, Fieldview, EnSight, Tecplot…)
- « sample » utility for 1D or 2D sampling (export to gnuplot, Grace/xmgr et jPlot)
[email protected] 6
OpenFOAM® initiation
openfoam.com
[email protected]
Romain Guibert, 2013
7
Simulation in porous media with OpenFOAM
P. Horgue, C. Soulaine, J. Franc, R. Guibert, G. Debenest, An open-source toolbox for multiphase flow in porous
media, Computer Physics Communications (2014) https://github.com/phorgue/porousMultiphaseFoam.git
C. Soulaine, P. Horgue, J. Franc, M. Quintard, Gas–Liquid Flow Modeling in Columns Equipped with Structured
Packing, AIChE Journal 60 (2014) 3665-3674
P. Horgue, F. Augier, P. Duru, M. Prat, M. Quintard, Experimental and numerical study of two-phase flows in arrays of
cylinders, Chemical Engineering Science 102 (2013) 335 - 345
C. Soulaine and H. A. Tchelepi, Micro-continuum approach for pore-scale simulation of subsurface processes,
Transport in Porous Media (2016)
C. Soulaine, F. Gjetvaj, C. Garing, S. Roman, A.Russian, P. Gouze and H. A. Tchelepi, The Impact of Sub-Resolution
Porosity of X-ray Microtomography Images on the Permeability, Transport in Porous Media (2016)
S. Roman, C. Soulaine, M. Abu AlSaud, T. Kovscek and H. A. Tchelepi, Particle velocimetry analysis of immiscible
two-phase flow in micromodels, Advances in Water Resources (2015)
C. Soulaine, M. Quintard, H. Allain, B. Baudouy, R. Van Weelderen, A PISO-like algorithm to simulate superfluid
helium flow with the two-fluid model, Computer Physics Communications (2014)
[email protected] 8
How to program equations?
OpenFOAM® initiation
●
The considered field (U) may be scalar, vector or tensor,
●
Operators discretization does not need to be specified at the stage of the solver programming,
●
The syntax is very closed to the mathematical formalism.
[email protected] 9
Where can I find help and documentation ?
●
2 official guides provided by OpenCFD (« user guide » and « programmer guide » )
(Most of the time, this documentation is not enough... )
●
Several reference thesis (Hrvoje Jasak 1996, Henrik Rusche 2001, …)
●
A tutorial per solver. Most of the time, it has a value of test-cases. (There is no public
validation..)
OpenFOAM® initiation
●
Direct access to source-code (however, there is very few comments in the code !!)
●
Paying for technical support
An active community !
- A discussion forum (www.cfd-online.com/Forums/openfoam/)
- A community-driven wiki (openfoamwiki.net)
- An annual Workshop (9th edition in 2014) (www.openfoamworkshop.org)
- Social network related to OpenFOAM (www.extend-project.de)
- A lot of tutorials, reports, presentations made by the community (search on Google)
[email protected] 10
Why should I use OpenFOAM?
OpenFOAM® initiation
• Completely free (No limitations due to licenses), • Need some time to learn,
• Direct access to source code (not a black-box), • Lack of documentation..
• An additional tool for code-to-code benchmarks, • There is no official GUI,
• Regular updates, • Unix command lines and C++
programing,
• A lot of out-of-the-box solvers and their tutorials,
• Too many forks…
• Ease to program partial differential equations,
• A reactive and important community (forum,
conference, summer schools…),
• …..
[email protected] 11
Some Unix commands
Navigation
pwd Tells you the name of the working directory.
Visualization
cat Outputs the contents of a specific file.
Manipulation of files
cp To copy a file. Use the -r option to copy a directory.
I/O redirection
> To redirect the output of an executable toward a file.
grep A filter to output every line that contains a specified pattern of characters.
[email protected] 12
General structure of an OpenFOAM case
$ cd
$ mkdir -p $FOAM_RUN
OpenFOAM® initiation
[email protected] 13
#1 – Heat diffusion (1/5)
Solver : laplacianFoam
573K
[email protected] 14
#1 – Heat diffusion (2/5)
$ run
$ cp –r $FOAM_TUTORIALS/basic/laplacianFoam/flange/ Exo1
$ cd Exo1
$ ls
OpenFOAM® initiation
$ paraFoam
1 - « apply »
[email protected] 16
#1 – Heat diffusion (4a/5)
$ gedit 0/T
Zero flux
[email protected] 17
#1 – Heat diffusion (4b/5)
$ gedit constant/transportProperties
OpenFOAM® initiation
[email protected] 18
#1 – Heat diffusion (4c/5)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 19
#1 – Heat diffusion (5/5)
Start the simulation
$ laplacianFoam
Look at the change in the directories: new folders appeared, they corresponds to the time steps
$ ls
View the results with ParaView
OpenFOAM® initiation
$ paraFoam
5 – Press play to
4 – Choose the
read all the time
field to display (T)
steps
3- Choose
« surface »
Exo1 bis :
DT = 1e-7 m²/s
Until steady state
2 - « apply »
1 – Choose
the field you
want to load
for viewing
[email protected] 20
#2 – Cavity (1/6)
Ux=1m/s Tutorial detailed in the official User Guide
movingWall
fixedWalls
OpenFOAM® initiation
y
fixedWalls
x
$ run
$ cp –r $FOAM_TUTORIALS/incompressible/icoFoam/cavity Exo2
$ cd Exo2
$ ls
[email protected] 21
#2 – Cavity (2/6)
blockMesh = pre-processing tool to design and mesh simple geometries
numerotation order
3
2
7 6
4
5
The numbering is of great importance !!
65 - « wireframe »
2 – To display
the patch names
on the geometry
1 – Choose the
elements you want
to visualize
[email protected] 23
#2 – Cavity (4a/6)
$ gedit constant/transportProperties
OpenFOAM® initiation
[email protected] 24
#2 – Cavity (4b/6)
$ gedit 0/U
OpenFOAM® initiation
[email protected] 25
#2 – Cavity (4c/6)
$ gedit 0/p
OpenFOAM® initiation
[email protected] 26
#2 – Cavity (4d/6)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 27
#2 – Cavity (5/6)
Start the simulation :
$ icoFoam
OpenFOAM® initiation
[email protected] 28
#2 – Cavity (6a/6)
To view the velocity vectors
We specify that the values are plotted at the
cell centers with the filter Cell Centers (by
default, ParaView plots the vector at the
face centers whereas OpenFOAM
calculates at the cell centers)
OpenFOAM® initiation
filters>alphabetical>Cell Centers>Apply
Number of vectors
plotted
Glyph
[email protected] 29
#2 – Cavity (6b/6)
To view the velocity vectors
OpenFOAM® initiation
[email protected] 30
#3 – Poiseuille flow (1/4)
Objectives:
Simulate a Poiseuille flow through a 2D pipe with symmetry plane condition
Steady-state solution of laminar incompressible Navier-Stokes equations with the
simpleFoam solver
OpenFOAM® initiation
symmetryPlane
outlet
inlet
y bottomWall
x
$ run
$ cp –r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily Exo3
$ cd Exo3
$ cp ../Exo2/system/blockMeshDict system/.
[email protected] 31
#3 – Poiseuille flow (2/4)
$ gedit system/blockMeshDict
symmetryPlane
3 2
inlet 7 outlet
6
OpenFOAM® initiation
y 0
z x 1
4
bottomWall
$ blockMesh
$ paraFoam
[email protected] 32
#3 – Poiseuille flow (3a/4)
$ gedit constant/turbulenceProperties $ gedit constant/transportProperties
OpenFOAM® initiation
[email protected] 34
#3 – Poiseuille flow (3c/4)
$ gedit system/controlDict $ gedit system/fvSolution
OpenFOAM® initiation
[email protected] 35
#3 – Poiseuille flow (4/4)
To start the simulation: $ simpleFoam
[email protected] 36
#4 – Drainage in a capillary tube (1/5)
Objectives:
non-wetting fluid wetting fluid Simulate a drainage (a non-wetting fluid pushing
(α=0) (α=1)
a wetting fluid) experiment in a simple 2D
capillary tube
Contact
angle θ
Example adapted fom the damBreak tutorial
detailed in the official user guide
OpenFOAM® initiation
$ run
$ cp –r $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak Exo4
$ cd Exo4
$ cp ../Exo3/system/blockMeshDict system/.
[email protected] 37
#4 – Drainage in a capillary tube (2/5)
$ gedit system/blockMeshDict
y
top (wall) x
right (inlet) z
3 2
left (outlet)
7 6
0 1
OpenFOAM® initiation
4
bottom (wall) 5
20%
The grid is regular in x and z directions,
but is refined near the walls in the y
direction. 20% of the total length near the
boundaries contain 30 % of the cells
refined with a factor 4 between the
closest to wall and the farthest.
60%
20%
$ blockMesh
[email protected] 38
#4 – Drainage in a capillary tube (3a/5)
$ gedit constant/transportProperties
Surface tension
[email protected] 39
#4 – Drainage in a capillary tube (3b/5)
$ gedit 0/U $ gedit 0/p_rgh
We use a hydrostatic
pressure
OpenFOAM® initiation
[email protected] 40
#4 – Drainage in a capillary tube (3c/5)
$ gedit 0/alpha.water.org
[email protected] 41
#4 – Drainage in a capillary tube (3d/5)
Specify that the simulation will be without gravity in a laminar flow regime
[email protected] 42
#4 – Drainage in a capillary tube (3e/5)
$ gedit system/controlDict
[email protected] 43
#4 – Drainage in a capillary tube (4/5)
Before we start the simulation, we are going to specify the initial phase distribution with setFields
$ cp 0/alpha.water.org 0/alpha.water
$ blockMesh
$ paraFoam
$ gedit system/setFieldsDict
$ setFields
$ paraFoam
OpenFOAM® initiation
BEFORE
AFTER
setFields overwrites 0/alpha.water. It is recommanded to make a backup before using it (that the
purpose of 0/alpha.water.org).
[email protected] 44
#4 – Drainage in a capillary tube (5/5)
Start the immiscible two-phase flow simulation:
$ interFoam
t=0.05s
t=0.10s
t=0.15s
t=0.20s
[email protected] 45
snappyHexMesh overview (1/2)
snappyHexMesh is an automatic and robust mesher able to grid any complex geometry
It is compatible with a lot of input formats resulting from CAD softwares or tomography
OpenFOAM® initiation
openfoam.com
openfoam.com
[email protected] 46
snappyHexMesh overview (2/2)
1 2
1
OpenFOAM® initiation
2 2
3
3
openfoam.com
[email protected] 47
#5 – Mesh a pore-space (1/6)
Objective:
– Mesh the void space of a porous medium with snappyHexMesh
Void space that needs to be
wall gridded
OpenFOAM® initiation
outlet
inlet
3 Detect the void space, remove the cells occupied by the solid and snap them to fit
as close as possible the initial surface object with snappyHexMesh.
[email protected] 48
#5 – Mesh a pore-space (2/6)
We are going to adapt the motorBike tutorial and use an existing stl file*
$ run
$ cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike/ Exo5
$ cd Exo5
Download Exo5.stl and copy it to the folder Exo5. To view the geometry,
OpenFOAM® initiation
$ paraview Exo5.stl
$ gedit system/blockMeshDict
OpenFOAM® initiation
$ blockMesh
$ paraFoam
$ mv Exo5.stl constant/triSurface/.
$ gedit system/snappyHexMeshDict
OpenFOAM® initiation
[email protected] 51
#5 – Mesh a pore-space (5/6)
The « castellated mesh » step Set up the refinement level at the vicinity of the object. Actually, this
feature only works for 3D geometry.
We can specify zero refinements with level (0 0), i.e. we only rely on
the background grid
$ snappyHexMesh
$ paraFoam
[email protected] 52
#5 – Mesh a pore-space (6/6)
The next step « snap » is the snapping stage to fit the STL surface as close as possible.
This stage will introduce some tetrahedral cells into the computational domain.
$ gedit system/snappyHexMeshDict
OpenFOAM® initiation
Eventually, we could have used the addLayers stage to add layers of cells around the
solid grains.
[email protected] 53
#6 – Scalar transport in the pore space (1/8)
Objectives:
– Solve the flow in the void space gridded in the previous exercise (#5)
– Estimate the permeability of the porous medium
– Solve a passive scalar transport in the void space
outlet
inlet
OpenFOAM® initiation
0.92 mm
The flow and the scalar transport are uncoupled. They can therefore be solved one
after the other.
The flow is obtained solving a Stokes problem with simpleFoam. The case can be setup
based on #3 (or $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily)
$ run
$ cp -r Exo3 Exo6a
$ cd Exo6a
The mesh from #3 is replaced by the grid of #5 and scaled to the actual size
$ rm -r constant/polyMesh 83/
$ cp -r ../Exo5/2/polyMesh constant/.
$ transformPoints -scale '(0.01 0.01 0.01)'
$ checkMesh | grep -i 'bounding box'
[email protected] 54
#6 – Scalar transport in the pore space (2a/8)
$ gedit 0/U $ gedit 0/p
OpenFOAM® initiation
[email protected] 55
#6 – Scalar transport in the pore space (2b/8)
$ gedit system/fvSolution
Setup the fluid properties
$ gedit constant/transportProperties The simulation will stop when these
residuals are reached.
OpenFOAM® initiation
[email protected] 56
#6 – Scalar transport in the pore space (2c/8)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 57
#6 – Scalar transport in the pore space (3/8)
It might be useful to plot the residuals on-the-fly to check the simulation convergence. This can be
achieved by redirecting the simulation log into a file and extracting the residual values with the
following gnuplot script :
$ gedit plotResiduals
OpenFOAM® initiation
$ gnuplot plotResiduals
Vvoid= 2.93x10-12 m3
OpenFOAM® initiation
V=Lx*Ly*Lz=5.15x10-12 m3
ε = 0.57
Kxx= 1.6x10-11 m2
Exo6a bis : Compare the residual convergence for other relaxation factors: 0.8 and 0.95
[email protected] 59
#6 – Scalar transport in the pore space (5/8)
Once the flow is solved, we can use the velocity profile to transport (advection-diffusion) a
scalar T with the solver scalarTransportFoam,
OpenFOAM® initiation
$ run
$ cp -r $FOAM_TUTORIALS/basic/scalarTransportFoam/pitzDaily Exo6b
$ cd Exo6b
$ rm -r constant/polyMesh
We retreive the mesh and the resulting velocity profile from the previous simulation #6a
$ cp -r ../Exo6a/constant/polyMesh/ constant/.
$ cp ../Exo6a/latestTime/U 0/U
[email protected] 60
#6 – Scalar transport in the pore space (6/8)
$ gedit 0/T $ gedit constant/transportProperties
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 61
#6 – Scalar transport in the pore space (7/8)
t=0.05s
Run the simulation
OpenFOAM® initiation
$ scalarTransportFoam
t=0.10s
$ paraFoam t=0.15s
t=0.20s
[email protected] 62
#6 – Scalar transport in the pore space (8/8)
To obtain a breakthrough curve (evolution of the concentration at the oulet), we look for
the average value at the outlet boundary for all time steps
$ patchAverage T right > log.patchAverage
Extract the values from the log file with the following command
$ cat log.patchAverage | grep -i 'right' | cut -d' ' -f12 > log.breakthrough
OpenFOAM® initiation
1,2
1
Exo6bis : Plot the breakthrough curves
0,8
for different values of the diffusivity
D5e-6 (D=5x10-6 m2/s and D=5x10-7 m2/s)
0,6
D1e-6
T
D5e-7
0,4
0,2
0
0 1 2 3 4 5 6
time (s)
[email protected] 63
Where is the source code of a solver?
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.
$ cd basic/laplacianFoam
$ ls
[email protected] 64
Behind laplacianFoam: laplacianFoam.C
$ gedit laplacianFoam.C
[email protected] 65
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
●
T will be written at each time step in the
corresponding folder (runTime.timeName())
●
This object also includes boundary conditions
that are specified in 0/T
[email protected] 66
General structure of an application
Source code
The file with the .C extension is the main file
OpenFOAM® initiation
$ cd $FOAM_APP/solvers/incompressible/icoFoam
$ ls
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] 67
#7 – Program a “Darcy” solver (1a/7)
Objective: develop a program that solves the velocity and pressure 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):
This equation is closed to the heat diffusion equation. Hence, we are going to program
our own solver on the basis of the existing laplacianFoam. To do so, we copy
laplacianFoam in our workspace.
$ cd $WM_PROJECT_USER_DIR/applications/solvers/
$ cp -r $FOAM_APP/solvers/basic/laplacianFoam darcyFoam
[email protected] 68
#7 – Program a “Darcy” solver (1b/7)
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 the flange tutorial or #3 with darcyFoam instead of laplacianFoam).
[email protected] 70
#7 – Program a “Darcy” solver (3/7)
$ gedit darcyFoam.C
$ rm write.H
$ wclean
$ wmake
[email protected] 71
#7 – Program a “Darcy” solver (4/7)
To prepare this « case » we are going to use the tutorial
laplacianFoam/flange. The setup will be relatively similar since this
Tip: The vertices can be
latter also solves a diffusion equation.
defined using variables
Lx, Ly, Lz. It saves time
to modify the size of the
domain $ run
$ cp -r $FOAM_TUTORIALS/basic/laplacianFoam/flange Exo7
$ cd Exo7
$ rm Allrun Allclean flange.ans
OpenFOAM® initiation
z x 10 m
$ cp $FOAM_TUTORIALS/icompressible/icoFoam/cavity/system/
blockMeshDict system/blockMeshDict
Faces orthogonal to y
$ gedit system/blockMeshDict
and z axis are defined as
«empty» to specify that
the simulation is 1D
The grid is generated using blockMesh
$ blockMesh
[email protected] 72
#7 – Program a “Darcy” solver (5a/7)
$ mv 0/T 0/p $ constant/transportProperties
$ gedit 0/p
OpenFOAM® initiation
[email protected] 73
#7 – Program a “Darcy” solver (5b/7)
$ gedit system/controlDict
OpenFOAM® initiation
[email protected] 74
#7 – Program a “Darcy” solver (5c/7)
$ gedit system/fvSchemes $ gedit system/fvSolution
OpenFOAM® initiation
[email protected] 75
#7 – Program a “Darcy” solver (6/7)
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
OpenFOAM® initiation
[email protected] 76
#7 – Program a “Darcy” solver (7/7)
Exo7Bis: Program a new solver for heterogeneous porous media (heterogeneousDarcyFoam) defining
the permeability as a volScalarField and assigning it different values with the utility setFields.
k = 5x10-9 m2 k = 10-9 m2
wall
OpenFOAM® initiation
inlet
outlet
6m
10 m
-10 2
k = 10 m k = 5x10-10 m2
k = 2x10-9 m2
$ cp $FOAM_UTILITIES/preProcessing/setFields/setFieldsDict system/.
[email protected] 77
#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
Objective 3: Change the discretization schemes
$ wclean
$ wmake [email protected] 78
#8 - Heat transfer in porous media (2a/7)
$ gedit createFields.H
$ wmake
[email protected] 79
#8 - Heat transfer in porous media (2b/7)
$ gedit createFields.H
OpenFOAM® initiation
$ wmake
[email protected] 80
#8 - Heat transfer in porous media (3/7)
$ gedit darcyTemperatureFoam.C
$ wmake
Compilation of darcyTemperatureFoam
[email protected] 81
#8 - Heat transfer in porous media (4/7)
Probe 3
Probe 1 Probe 2
OpenFOAM® initiation
P1
P0
10 m
Tin Zero heat flux
at the outlet
Porous medium with a permeability
k and a porosity eps
To save time, we can adapt the previous exercise (#7) 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] 82
#8 - Heat transfer in porous media (5a/7)
$ gedit 0/T $ gedit 0/p
OpenFOAM® initiation
[email protected] 83
#8 - Heat transfer in porous media (5b/7)
$ gedit constant/transportProperties $ gedit system/fvSchemes
OpenFOAM® initiation
$ gedit system/fvSolution
[email protected] 84
#8 - Heat transfer in porous media (5c/7)
$ gedit system/controlDict
[email protected] 85
#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] 86
#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] 87
#9 – Customize boundary conditions (1/4)
Objective: Create customized boundary conditions
By default, OpenFOAM can handled a lot of different boundary conditions. Their code source is
located in the following directory:
$ cd $FOAM_SRC/finiteVolume/fields/fvPatchFields
$ ls
OpenFOAM® initiation
All these conditions are derived from basic conditions like fixedValue (Dirichlet), fixedGradient
(Neumann) or mixed.
$ ls derived
To define boundary conditions that depends on time or on other variables, there are several
possibilities,
●
Hardcoding in the solver,
●
Program customized boundary conditions,
●
With an additional package such as swak4Foam (http://openfoamwiki.net/index.php/Contrib/swak4Foam)
[email protected] 88
#9 – Customize boundary conditions (2/4)
In the previous exercises(#7 and #8), the flow in porous media is evaluated from solving a partial
differential equation on the pressure. Therefore, boundary conditions for the pressure field have to
be specified. Sometime, however, it is more convenient to define an inlet velocity rather than a
pressure condition. This inlet condition for the velocity can be described in term of boundary
condition for the pressure using the relation:
OpenFOAM® initiation
We are going to create a new boundary condition, inspired by fixedFluxPressure itself derived
from fixedGradient
$ mkdir -p $WM_PROJECT_USER_DIR/boundary/
$ cd $WM_PROJECT_USER_DIR/boundary/
$ cp -r $FOAM_SRC/finiteVolume/fields/fvPatchFields/derived/fixedFluxPressure darcyGradPressure
$ cd darcyGradPressure
$ rename 's/fixedFluxPressure/darcyGradPressure/g' *.*
$ sed -i 's/fixedFluxPressure/darcyGradPressure/g' *.*
$ mkdir Make
$ wclean
$ wmake
[email protected] 89
#9 – Customize boundary conditions (3a/4)
$ gedit darcyGradPressureFvPatchScalarField.H
Declaration of constructors
[email protected] 90
#9 – Customize boundary conditions (3b/4)
Declaration of constructors
and constructors of copy.
OpenFOAM® initiation
[email protected] 91
#9 – Customize boundary conditions (4a/4)
$ gedit darcyGradPressureFvPatchScalarField.C
OpenFOAM® initiation
$ wclean
$ wmake
[email protected] 93
#10 - Two-equations model (1/6)
Objective n°1 : Solve heat transfer in porous media with a two
temperatures model (for the fluid and for the solid),
(1)
(2)
OpenFOAM® initiation
(3)
(4)
$ wclean
$ wmake
[email protected] 94
#10 - Two-equations model (2/6)
$ gedit createFields.H
phi is created by
calling createPhi.H
Declaration of
temperature fields for
the solid and the fluid
(do not write manually
but use copy/paste from
the former block
« volScalarField T ... »)
$ wclean
$ wmake
[email protected] 96
#10 - Two-equations model (4/6)
We want to estimate heat transfer in a 1D porous medium with a two temperatures model.
In this example, a porous medium initially at 573K is cooled down with the injection of a
fluid at 273K
OpenFOAM® initiation
$ run
$ cp –r Exo8 Exo10
$ cd Exo10
$ rm –r 0.* 1* 2* 3* 4* 5* 6* 7* 8* 9* postProcessing
$ mv 0/T 0/Tf
$ cp 0/Tf 0/Ts
$ cp 0/p 0/U
[email protected] 97
#10 - Two-equations model (5a/6)
$ gedit 0/U $ gedit 0/p
OpenFOAM® initiation
A fluid velocity is imposed at the domain inlet. This velocity is used to evaluate the
pressure gradient at the inlet with the boundary condition darcyGradPressure we
have developed in #9. To use this boundary condition, we must specify in
system/controlDict that we load the library, ldarcyGradPressure.so.
[email protected] 98
#10 - Two-equations model (5b/6)
$ gedit 0/Ts $ gedit 0/Tf
OpenFOAM® initiation
[email protected] 99
#10 - Two-equations model (5c/6)
$ gedit constant/transportProperties $ gedit system/controlDict
OpenFOAM® initiation
[email protected] 100
#10 - Two-equations model (5g/6)
$ gedit system/fvSolution $ gedit system/fvSchemes
OpenFOAM® initiation
[email protected] 101
#10 - Two-equations model (6/6)
We start the simulation: $ darcyTwoTemperaturesFoam
We then post-treat the evolution Ts and Tf with time for the 3 probes
OpenFOAM® initiation
Exo10Bis: Change the exchange coefficient value and re-do the simulation. For large values, we recover
the solution of #8.
[email protected] 102
Navier-Stokes with icoFoam (1/5)
Navier-Stokes equations are made of a continuity equation and a momentum
equation
(1)
(2)
OpenFOAM® initiation
We look for (U,p) solution of this problem. How can we solve this problem in a
segregated manner ? (one equation after the other) ?
[email protected] 103
Navier-Stokes with icoFoam (2a/5)
With the finite volume method in OpenFOAM®, the advection velocity in the divergence
operator is defined at the cell faces (phi). Since the fluid density is constant, the solved
pressure is in fact the actual pressure divided by rho:
OpenFOAM® initiation
[email protected] 104
Navier-Stokes with icoFoam (2b/5)
Or,
Diagonal coefficients of the Contains the off-diagonal coefficients and the source
matrix for the velocity U terms (body forces + half of the discretization of the
transient term)
OpenFOAM® initiation
Or,
Combining this equation with continuity equation leads to the pressure equation:
In this equation, aP et H(U) are evaluated from the velocity field of the previous
iteration or previous time step.
[email protected] 105
Navier-Stokes with icoFoam (3/5)
$ sol
$ cd incompressible/icoFoam
$ gedit icoFoam.C
2 U* is predicted solving implicitly the momentum equation (matrix UEqn) with the
pressure of the previous time step
[email protected] 106
Navier-Stokes with icoFoam (4a/5)
3 On entre dans la boucle PISO Update of aP from U freshly computed
4 At least 2 iterations are required. Then one exit the PISO loop and go to the next
time step. [email protected] 107
Navier-Stokes with icoFoam (4b/5)
Some additional details
[email protected] 108
Navier-Stokes with icoFoam (5/5)
Some variation (exercise):
• Write a PISO algorithm with the actual pressure
Bibliography:
• Solution of the Implicitly Discretised Fluid Flow Equations by Operator-Splitting, Issa, 1985
• Numerical Heat Transfer and Fluid Flow, Patankar, 1980
• Computational Methods for Fluid Dynamics, Ferziger and Peric, 2002
• Micro-continuum approach for pore-scale simulation of subsurface processes, Soulaine and Tchelepi, 2016
• A PISO-like algorithm to simulate superfluid helium flow with the two-fluid model, Soulaine et al., 2016
View publication stats
[email protected] 109