0% found this document useful (0 votes)
348 views110 pages

OPENFOAM FORMATION v5-1-EN

Uploaded by

Feishi Xu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
348 views110 pages

OPENFOAM FORMATION v5-1-EN

Uploaded by

Feishi Xu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 110

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/304511422

Introduction to computational fluid mechanics using the OpenFOAM®


technology « Simulation in porous media from pore to large scale »

Presentation · June 2016


DOI: 10.13140/RG.2.1.1376.9209

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

Reactive flow in porous media View project

All content following this page was uploaded by Cyprien Soulaine on 28 June 2016.

The user has requested enhancement of the downloaded file.


Introduction to computational fluid mechanics
using the OpenFOAM® technology

« Simulation in porous media from pore to large scale »

First simulations, first programs

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

numerous tricks I discovered during my personal usage of OpenFOAM®. It can


be seen as a long tutorial about flow and transport in porous media at different
scales. Besides the fact that it corresponds to my research area, this choice
allows the introduction of different OpenFOAM® features with a progressive
and pedagogical approach: it is easier to start understanding how a Darcy
solver works than tackling directly the programing of a PISO algorithm...

Today, I taught this class to more than a hundred of students, researchers,


engineers both in academia and industry. Their feedbacks helped me a lot to
improve this document. Feel free to send me your comments.

Cyprien Soulaine

[email protected] 2
Objectives

• Have an overview of the OpenFOAM® capabilities

• Be able to find help and documentation


OpenFOAM® initiation

• Know how to start and post-treat a simulation from existing tutorials

• Start your own simulation by modifying existing tutorials

• Understand what is behind solvers to identify the most suitable solver


for your specific problem

• Program your own solver by modifying an existing solver

• Join the OpenFOAM® adventure…

[email protected] 3
General introduction to the OpenFOAM® technology
What is OpenFOAM?
Where one can find help and documentation?

First simulations with OpenFOAM®


General structure of an OpenFOAM® case
#1 – Heat diffusion
OpenFOAM® initiation

#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® ?

= Open Field Operation And Manipulation


- Solve the Partial Differential Equations using the finite volumes method
OpenFOAM® initiation

- Multiphysic simulation platform mainly devoted to fluid flow


- Manage 3D geometries by default
- Open-source software developed in C++ (object-oriented programming)
- Can be freely download at www.openfoam.com
- Designed as a toolbox easily customisable
- Parallel computation implemented at lowest level
- Cross-platform installation (Linux preferred)

1989 : First development at Imperial College London


1996 : First release of FOAM
2004 : OpenFOAM release under GPL licence by OpenCFD Ltd.
2014 : version 3.0.1
[email protected] 5
The OpenFOAM® toolbox
OpenFOAM® = more than 200 programs (and not only 1 executable)

Pre-processing:
-
OpenFOAM® initiation

Meshing (blockMesh, snappyHexMesh…)


- Mesh conversion (Ansys, Salomé, ideas, CFX, Star-CD, Gambit, Gmsh…)

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

Horgue et al., 2011


Simulation examples

Horgue et al., 2014 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

L. Orgogozo, N. Renon, C. Soulaine, F. Hénon, S. K. Tomer, D. Labat, O. S. Pokrovsky, M. Sekhar, R. Ababou, M.


Quintard, An open source massively parallel solver for Richards equation: Mechanistic modelling of water fluxes at
OpenFOAM® initiation

the watershed scale, Computer Physics Communications 185 (2014) 3358–3371


http://cpc.cs.qub.ac.uk/summaries/AEUF_v1_0.html

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, Direct numerical simulation in fully saturated porous media


http://web.stanford.edu/~csoulain/PORE_SCALE/Chap2.pdf

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.

ls List the files in the working directory.

cd Change your working directory.


OpenFOAM® initiation

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.

mkdir Create a directory.

rm Delete a file. Use the -r option to remove a directory.

mv Move or rename a file/folder.

I/O redirection
> To redirect the output of an executable toward a file.

| A pipeline to connect multiple commands together.

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

Simulation setup (choice of the linear solvers, of the


discretization schemes, of the time steps, the output
files...)

Everything regarding constant values (tranport


properties, thermodynamic properties, turbulence model,
etc...)

All the information related to the grid

One folder per time step. Each folder includes as many


files as computed fields (T, U, p, Yi, k, Omega…)
Initial conditions are specified in the « 0 » directory.

[email protected] 13
#1 – Heat diffusion (1/5)

Tini = 273K Example from tutorials provided


with OpenFOAM
273K
Geometry and grid generated
with Ansys
OpenFOAM® initiation

Mesh conversion using the utility


ansysToFoam

Solution of the heat transfer


equation

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

Initial and boundary conditions for the


temperature field T

Value of the diffusion coefficient (m2/s)

Simulation parameters (time steps, output


time...)

Discretization of the different operators (div,


laplacian, ddt, grad…)

Set up of the linear solvers

Scripts to automatically start and clean the


tutorial
Grid generated with Ansys
[email protected] 15
#1 – Heat diffusion (3/5)
Convert the mesh from Ansys to OpenFOAM (with a scale factor)
$ ansysToFoam flange.ans -scale 0.001
polyMesh contains all the
information related to the
Look at the change in the directory
grid: list of points, faces,
$ ls constant neighbors, boundaries...
$ ls constant/polyMesh
Visualize the grid with ParaView
OpenFOAM® initiation

$ paraFoam

2 - Choose « surface with edge»

1 - « apply »

[email protected] 16
#1 – Heat diffusion (4a/5)
$ gedit 0/T

Definition of initial and boundary


conditions
Dimensions (units) of the field T
[kg m s K kgmol A cd]
OpenFOAM® initiation

Uniform initial temperature (T=273K) in


the solid bulk

Boundary conditions for t=0s

Zero flux

Fixed value (T=273K)

Fixed value (T=573K)

[email protected] 17
#1 – Heat diffusion (4b/5)
$ gedit constant/transportProperties
OpenFOAM® initiation

The dimensions of the diffusivity DT are m2/s

[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

Design and meshing of the geometry with the


utility blockMesh
fixedWalls

fixedWalls
OpenFOAM® initiation

Solution of the laminar incompressible Navier-


Stokes equations with the icoFoam solver

y
fixedWalls
x

Post-processing with ParaView

$ 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

Geometry and grid are defined in the file blockMeshDict


Vertices definition
$ gedit system/blockMeshDict

Definition of the hexahedral


The geometry is always defined in 3D since OpenFOAM
block. Pay attention to the only considers 3D geometry
OpenFOAM® initiation

numerotation order
3
2

7 6

Definition of the grid (Regular


mesh 20x20, only one cell in the y
z direction because the
0
z x 1
simulation will be 2D)

4
5
The numbering is of great importance !!

Boundaries may be of different types:


-patch (generic type)
Definition of boundary of
-wall (for solid wall condition, useful for turbulence)
the domain to apply -cyclic (for cyclic simulations)
boundary conditions. -symmetryPlane (for symmetry plane)
-empty (to specify that the simulation will be 2D or 1D)
Faces normal to Oz are -wedge (for axi-symmetric simulations)
«empty» to specify that
the simulation is 2D
-processor (for parallel computation, automatically defined during
the decomposition domain process)
[email protected] 22
#2 – Cavity (3/6)
Generate the grid mesh: $ blockMesh Creation of constant/polyMesh and
the files related to the grid.
Check the mesh quality: $ checkMesh

View the mesh : $ paraFoam


OpenFOAM® initiation

65 - « wireframe »

4 – Remove the perspective


3 - « Apply »

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

The flow is laminar, so it fullfills the


icoFoam assumptions

[email protected] 24
#2 – Cavity (4b/6)
$ gedit 0/U
OpenFOAM® initiation

[email protected] 25
#2 – Cavity (4c/6)
$ gedit 0/p
OpenFOAM® initiation

Be careful with the units! In


OpenFOAM incompressible
solvers, the solved pressure is

[email protected] 26
#2 – Cavity (4d/6)
$ gedit system/controlDict
OpenFOAM® initiation

Management of the time discretization


(start, end, time steps...)

Management of the output files

[email protected] 27
#2 – Cavity (5/6)
Start the simulation :
$ icoFoam
OpenFOAM® initiation

Post-processing with ParaView : $ paraFoam

[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

The vector length is scaled with the


velocity magnitude

We then apply the Glyph filter to plot the


velocity vector:

Number of vectors
plotted

Glyph
[email protected] 29
#2 – Cavity (6b/6)
To view the velocity vectors
OpenFOAM® initiation

Display> color by > U

[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

Untick U and p in the fields to view


before you click on « apply »

[email protected] 32
#3 – Poiseuille flow (3a/4)
$ gedit constant/turbulenceProperties $ gedit constant/transportProperties
OpenFOAM® initiation

We specify that the simulation is laminar. All the


references to RANS model are no longer
necessary (discretization schemes, files 0/nut,
0/k ...)
$ rm 0/epsilon
$ rm 0/f This step is not mandatory, the files will
$ rm 0/k be simply not considered during the
simulation
$ rm 0/nut
$ rm 0/nuTilda
$ rm 0/omega
$ rm 0/v2
[email protected] 33
#3 – Poiseuille flow (3b/4)
$ gedit 0/U $ gedit 0/p
OpenFOAM® initiation

[email protected] 34
#3 – Poiseuille flow (3c/4)
$ gedit system/controlDict $ gedit system/fvSolution
OpenFOAM® initiation

simpleFoam is a steady-state solver


that uses an iterative
algorithm called SIMPLE: the
pressure field and the velocity
matrix are under-relaxed to ease The simulation stops when the
the convergence. Hence, in this residual are below this criteria.
case, the “time-step” refers to the
iteration number (see
system/fvSolution for convergence
criteria)

Remove the “functions” block. It is not


necessary in this exercise, and will cause
problems since it is a laminar simulation

[email protected] 35
#3 – Poiseuille flow (4/4)
To start the simulation: $ simpleFoam

To view the results: $ paraFoam

1 – Filters>Data Analysis>Plot Over Line


OpenFOAM® initiation

3 – Deselect the viewing of


the pressure field p

2 – We are going to plot the velocity profile


in the vertical cross-section at the middle of
the pipe

[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

inlet outlet Use of an interface capturing solver (interFoam,


VoF)

Use of the setFields utility to initialize the phase


distribution

$ 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

Name of the wetting phase (here « water » ) and of the non-


wetting phase (here « oil »). On the computational grid, the two
phases are differentiated with the phase indicator alpha.water
( =1 for the wetting phase, =0 for the non-wetting phase)
OpenFOAM® initiation

Mind the space between “phases” and “(“ !

Properties of the “water”


phase

Properties of the “oil” phase

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

The patches « top » and « bottom »


have the same boundary conditions

[email protected] 40
#4 – Drainage in a capillary tube (3c/5)
$ gedit 0/alpha.water.org

alpha.water represents the wetting/non-


wetting phase distribution in the
computational domain. (alpha=0 for the
OpenFOAM® initiation

non-wetting, alpha=1 for the wetting)

Definition of the contact angle at the solid boundaries.


Here theta=45 degrees

limit gradient to limit the wall-gradient such that alpha


remains bounded on the wall.

[email protected] 41
#4 – Drainage in a capillary tube (3d/5)

Specify that the simulation will be without gravity in a laminar flow regime

$ gedit constant/g $ gedit constant/turbulenceProperties


OpenFOAM® initiation

[email protected] 42
#4 – Drainage in a capillary tube (3e/5)
$ gedit system/controlDict

Set the writeControl parameter to adjustableRunTime


OpenFOAM® initiation

when using an adjustable time step. The output files


will be written every writeInterval seconds.

If yes value, then it means that the controlDict file can


be modified on the fly.

Switch on the automatic time step management according to


the Courant Numbers value (maxCo for the pressure/velocity
coupling and maxAlphaCo for the explicit transport of alpha).

maxDeltaT restricts the maximum value of the time step.

[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

theta=45 degrees theta=20 degrees


OpenFOAM® initiation

t=0.05s

t=0.10s

t=0.15s

t=0.20s

Exo4bis : Same exercise with a contact angle of 20 degrees

[email protected] 45
snappyHexMesh overview (1/2)

snappyHexMesh is an automatic and robust mesher able to grid any complex geometry

Mesh a region inside or/and around an object described by a surface mesh

It is compatible with a lot of input formats resulting from CAD softwares or tomography
OpenFOAM® initiation

imaging (*.stl, *.obj, *.vtk …)

Maximize the number of hexahedral cells

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

Solid grains defined by a


wall
surface mesh file

1 Generate the surface mesh (here the solid grain).

2 Create a suitable background mesh with blockMesh. It needs to be fine enough to


have at least 10 cells in the pore-throat thickness.

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

* This file can be downloaded at: http://web.stanford.edu/~csoulain/OF_Training/Exo5/Exo5.stl


[email protected] 49
#5 – Mesh a pore-space (3/6)
The next step consists in creating a background mesh with blockMesh. The size of this background
domain depends on the bounding box of the surface object. It can be obtained using the surfaceCheck
tool,
$ surfaceCheck Exo5.stl | grep –i 'bounding box'

$ gedit system/blockMeshDict
OpenFOAM® initiation

The grid has to be fine enough in order to


capture all the details of the pore-space.

$ blockMesh
$ paraFoam

To superimpose the background grid and the


surface mesh file, in ParaView:

Specify the boundaries top, bottom, left, right, frontAndBack file>open>Exo5.stl


(see page 32) [email protected] 50
#5 – Mesh a pore-space (4/6)
The void space is going to be meshed with snappyHexMesh, based on the background grid.
snappyHexMesh needs an input dictionary located in the system folder and the object file (Exo5.stl)
located in constant/triSurface,

$ mv Exo5.stl constant/triSurface/.
$ gedit system/snappyHexMeshDict
OpenFOAM® initiation

The three different stages of the meshing can be performed


separately or simultaneously:
- castellatedMesh: detects the intersections between the surface
object and the background grid. It can eventually refine the
background grid at the vicinity of the object. Then it removes either the
inside or the outside of the object.
- snap: Introduces tetrahedral cells at the object boundary to match
the actual geometry.
- addLayers: Add layers of cells on the boundaries.

Insertion of the surface mesh object. Several objects may be inserted


at the same times.

The solid boundaries will be named “fixedWalls”

[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

Point a location where there is void space. All


cells outside the void space will be removed.
OpenFOAM® initiation

$ snappyHexMesh
$ paraFoam

The mesh is created in a new time step (« 1 »)


directory. In order to view it, in ParaView, you have
to go to the time « 1 »

[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

The mesh is created in another time step (« 2 ») folder.


You have to select the time step « 2 » in ParaView to
view it.
$ snappyHexMesh
$ paraFoam

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

Switch off the turbulence model


$ gedit constant/turbulenceProperties

Relaxation factors for the SIMPLE algorithm. The


value 0.9 for U is faster for Stokes flows.

[email protected] 56
#6 – Scalar transport in the pore space (2c/8)
$ gedit system/controlDict
OpenFOAM® initiation

Since we have specified convergence criteria in


system/fvSolution, the simulation may stop before
endTime. In that case, the latest simulated time step
will be automatically written.

[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

Run the simulation and make it write out a log-file

$ simpleFoam > log &

Plot the residuals convergence with gnuplot

$ gnuplot plotResiduals

(Ctrl + C to quit gnuplot) [email protected] 58


#6 – Scalar transport in the pore space (4b/8)
$ paraFoam The porosity (ε) is the volume of the mesh (Vvoid) over
the volume (V) of the bounding box:

$ checkMesh | grep -i 'volume'

Vvoid= 2.93x10-12 m3
OpenFOAM® initiation

$ checkMesh | grep -i 'bounding box'

V=Lx*Ly*Lz=5.15x10-12 m3
ε = 0.57

The permeability Kxx is defined as:

The velocity can be integrated directly from


ParaView with the filter:
filters>Data Analysis>integrateVariables

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

For that purpose, we adapt the tutorial scalarTransportFoam/pitzDaily

$ 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

Visualize the results

$ 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

Plot the breakthrough curve


$ gnuplot
gnuplot> plot 'log.breakthrough' with lines lw 4

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?

OpenFOAM can be seen as an easily customisable toolbox.

1 solver = 1 program
(for instance, the heat equation is solved using the program laplacianFoam)
OpenFOAM® initiation

Where are the solvers in OpenFOAM?


$ cd $FOAM_APP/solvers
$ ls

The solvers are organized by type (basic, heat transfer, combustion, incompressible,
multiphase….). Note that the tutorials have a similar organisation.

For example, laplacianFoam is in /basic

$ cd basic/laplacianFoam
$ ls

[email protected] 64
Behind laplacianFoam: laplacianFoam.C
$ gedit laplacianFoam.C

Call the OpenFOAM


librairies
OpenFOAM® initiation

Creation of the matrix


fvm:: implicit terms
fvc:: explicit terms
the variable T and DT are
declared in createFields.H

[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

The dictionary transportProperties is loaded from


the input file constant/transportProperties

Declaration of the variable DT

Its value and dimensions are defined in the input


file constant/transportProperties

[email protected] 66
General structure of an application
Source code
The file with the .C extension is the main file
OpenFOAM® initiation

List of files that will be compiled

Link towards the OpenFOAM librairies used in this


program

Example of the icoFoam solver

$ 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

List of the files to compile (only the .C files)


OpenFOAM® initiation

Name of the new program

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).

It is recommanded to use wmake as often as possible during the programming stage.


[email protected] 69
#7 – Program a “Darcy” solver (2/7)
$ gedit createFields.H

Declaration of the pressure field p


• It is an instance of the object volScalarField (scalar field
defined at the cells center),
• The file «p» must be read at the frist time step to satisfy the
constructor. The initial values and boundary conditions are
defined during the loading of 0/p.
OpenFOAM® initiation

• The file « p » will be written at every output times.

Declaration of the velocity vector field U


• It is an instance of the object volVectorField (vectpr field
defined at the cells center),
• U is not read from a file (even if 0/U exist)
• To satisfy the constructor of the object volVectorField,
units and initial values are defined with an additional
arguement. By default, the boundary conditions are
zeroGradient,
• The file « U » will be written at every output times.

Declaration of the fluid viscosity mu and the permeability k.


They will be loaded from « constant/transportProperties »

[email protected] 70
#7 – Program a “Darcy” solver (3/7)
$ gedit darcyFoam.C

The pressure field p is solved implicitly


by a diffusion equation
OpenFOAM® initiation

The velocity vector U is deduced from


the pressure field using the Darcy's
law.

$ rm write.H
$ wclean
$ wmake

The useless files are removed and the


darcyFoam executable is then compiled.

[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

We are going to simulate flow in an 1D porous medium:


Mesh definition (homogeneous grid with a
single cell in the y and z axis since the 3
2
simulation is 1D) inlet 7 6 outlet
0
1
y 4 5

z x 10 m

To save time, we can pick up and modify an existing blockMeshDict

$ 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

A pressure drop is imposed between the


inlet and the outlet of the computational
domain

[email protected] 73
#7 – Program a “Darcy” solver (5b/7)

$ gedit system/controlDict
OpenFOAM® initiation

Since darcyFoam is a steady-state solver


without relaxation factor, only one time step
is necessary.

[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

Run the sample tool:


$ sample

Plot the pressure field with Gnuplot :


$ 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“

[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

We can get setFieldsDict from #4 or:

$ cp $FOAM_UTILITIES/preProcessing/setFields/setFieldsDict system/.
[email protected] 77
#8 - Heat transfer in porous media (1/7)

Objective 1: Develop a program that solves heat transfer in a porous medium


where the velocity and pressure obey Darcy’s law.

(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

This solver will be based on darcyFoam (#7)


$ cd $WM_PROJECT_USER_DIR/applications/solvers/
$ cp –r darcyFoam darcyTemperatureFoam
$ cd darcyTemperatureFoam
$ mv darcyFoam.C darcyTemperatureFoam.C
$ gedit Make/files

$ wclean
$ wmake [email protected] 78
#8 - Heat transfer in porous media (2a/7)
$ gedit createFields.H

Declaration of the velocity flux phi.


– It is a surface field (U is projected onto the face of each cell of the grid)
– It is necessary when using the divergence opereator (fvm::div(phi,T) )
– Can also be declared using #include ‘’createPhi.H
OpenFOAM® initiation

Declaration of the temperature field T. (Do not copy everything


manually: copy/paste the declaration of volScalarField p and
replace p by T)

$ wmake

[email protected] 79
#8 - Heat transfer in porous media (2b/7)

$ gedit createFields.H
OpenFOAM® initiation

Beside the viscosity mu and the permeability k of the porous


medium, we also declare the thermal conductivity DT, the
porosity eps and the heat capacities rhoCps and rhoCpf. They
are loaded from the file « constant/transportProperties »

$ wmake

[email protected] 80
#8 - Heat transfer in porous media (3/7)
$ gedit darcyTemperatureFoam.C

The surface flux phi is updated from the new


value of the velocity profile U.
OpenFOAM® initiation

Solve the advection/diffusion equation for the


temperature transport

$ wmake

Compilation of darcyTemperatureFoam

[email protected] 81
#8 - Heat transfer in porous media (4/7)

We want to estimate the temperature evolution in a 1D porous medium

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

The probes are functions that are executed on-the-fly


during the simulation.
OpenFOAM® initiation

They allow to record the temperature evolution vs time


at the probe location.

You can specify as many probes as you want.

[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

$ gnuplot –persist plot_probes

[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.

More benchmarks on OpenFOAM numerical schemes :


http://www.holzmann-cfd.de/index.php/en/numerical-schemes

[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

The string « fixedFluxPressure » is replaced by « darcyGradPressure » within all the


files of the directory

$ gedit Make/files $ gedit Make/options

$ wclean
$ wmake
[email protected] 89
#9 – Customize boundary conditions (3a/4)
$ gedit darcyGradPressureFvPatchScalarField.H

This boundary condition derives from


the class fixedGradient
OpenFOAM® initiation

Name of the new type of boundary


condition that will be specified in files 0/p

Declaration of constructors

[email protected] 90
#9 – Customize boundary conditions (3b/4)

Declaration of constructors
and constructors of copy.
OpenFOAM® initiation

Declaration of the function updateCoeffs(). It


is in this function that the expression of the
boundary condition is defined.

Declaration of the function write() that


writes the value at the boundaries in
the files timeDirectory/p.

[email protected] 91
#9 – Customize boundary conditions (4a/4)
$ gedit darcyGradPressureFvPatchScalarField.C
OpenFOAM® initiation

Definition of the constructors and copy constructors


[email protected] 92
#9 – Customize boundary conditions (4b/4)

We recover the value of U at the


boundary The viscosity and permeability values are
read in the file transportProperties
OpenFOAM® initiation

The pressure gradient is evaluated at the


boundary with the formula:

mu.value() allows the access of the value of the


object mu declared as a dimensionedScalar

patch().nf() returns the normal vector to the


patch

$ wclean
$ wmake

The librairy ldarcyGradPressure.so is now


compiled and available for all the solvers.

[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)

Objective n°2 : Use customized boundary conditions

This solver will be based on darcyTemperatureFoam (#8)


$ cd $WM_PROJECT_USER_DIR/applications/solvers/
$ cp –r darcyTemperatureFoam darcyTwoTemperaturesFoam
$ cd darcyTwoTemperaturesFoam
$ mv darcyTemperatureFoam.C darcyTwoTemperaturesFoam.C
$ gedit Make/files

$ wclean
$ wmake
[email protected] 94
#10 - Two-equations model (2/6)
$ gedit createFields.H

The field U is now


initialized from 0/U, which
allows us to defined
boundary condition for U
OpenFOAM® initiation

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 ... »)

The model constants are loaded


from the file
constant/transportProperties.
(Again, do not write manually
everything ! use copy/paste!)
[email protected] 95
#10 - Two-equations model (3/6)
$ gedit darcyTwoTemperaturesFoam.C

The matrix for the pressure pEqn is declared as a fvScalarMatrix and


constructed from the discretization with the finite volume method of the
laplacian operator. This type of declaration offers more flexibility than
solve( fvm::laplacian(…)..). The matrix is inversed with pEqn.solve()

The flux of velocity at the cell face is directly updated


OpenFOAM® initiation

from the new coefficients of the matrix pressure.

U is calculated pointwise with Darcy’s law. The boundary


conditions may have been altered and do not correspond to
what was specified in 0/U. This function means that the
boundary conditions have to be those specified in 0/U.

Solve the temperature in the fluid.


The laplacian discretization scheme
is specified in system/fvSchemes in
front of the keyword
« laplacian(DT,T) ». A part of the
exchange term is treated implicitly,
the other part explicitly.

Solve the temperature in the solid.

$ 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

Porous medium (permeability k


Inlet velocity Uin and porosity eps)
P0

Fluid temperature imposed Free heat flux (fluid and


at the inlet Tfin solid) at the oulet

To set up the simulation, we use #8

$ 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

We specify that we load the library


ldarcyGradPressure.so in order to use the
customized boundary condition darcyGradPressure.

[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) ?

• First, we derive a pressure equation combining (1) and (2),


• Then, we use a predictor/corrector strategy to solve this system (ex : PISO for
transient solutions, SIMPLE for steady-state simulations, PIMPLE which is a mix
of these two algorithms allows larger time steps),
• In this section, we learn how to solve NS with the PISO algorithm implemented in
icoFoam

[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

To derive a pressure equation, we write the former equation is a semi-discretized


formulation :

Discretization of the convective and


the diffusive terms.

It can be recast into

[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

1 Beginning of the time loop


OpenFOAM® initiation

2 U* is predicted solving implicitly the momentum equation (matrix UEqn) with the
pressure of the previous time step

Construction of the matrix UEqn. The convective


term is linearized with phi evaluated at the previous
time step.

U* is predicted from the pressure field 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

Update of H/ap or “H by A” from the U freshly computed


OpenFOAM® initiation

Projection of H/aP over the cell faces to


calculate the divergence div(HbyA)

Here, we recover the right value of the flux velocity

Velocity corrector stage:

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

Insure mass conservation by adjusting the in-coming


OpenFOAM® initiation

and out-coming flux if the boundary conditions are ill-


defined (no fixedValue for p for instance)

If there is no fixedValue among the pressure BCs, then


the value of p at the cell with the reference pRefCell is
fixed to pRefValue.

At the previous line U has been calculated point-wise


from p. The BCs do no longer correspond to the ones
in 0/U. This function means that the boundary
conditions of U must be the ones precised in 0/U.

[email protected] 108
Navier-Stokes with icoFoam (5/5)
Some variation (exercise):
• Write a PISO algorithm with the actual pressure

• Write a PISO algorithm with a body source term :


OpenFOAM® initiation

• Write a PISO algorithm with a mass source term:

• Write a PISO algorithm for a Darcy-Brinkman system:

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

You might also like