OpenFOAM v10
OpenFOAM v10
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
Editorial board:
Bahram Haddadi
Technische Universität Wien
Christian Jordan Institute of Chemical, Environmental
& Bioscience Engineering
Michael Harasek
Compatibility:
OpenFOAM® v10
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Preface
In this OpenFOAM® tutorial series, we have prepared fourteen case examples that are
designed to help users to learn the key utilities and features within OpenFOAM ®, including
mesh generation, multiphase modeling, turbulence modeling, parallel processing and
reaction modeling. The base tutorial examples can be imported directly from the
OpenFOAM® installation directory or downloaded from our webpage:
www.fluiddynamics.at.
The tutorials should be primarily used for OpenFOAM® v10 (Foundation version –
www.openfoam.org) but with slight differences, generally applicable to the other flavors of
OpenFOAM® such as ESI-version and foam-extend! The structure of each case example
follow the below general structure:
0. Background: an introduction about the key topics explored in the tutorial and the
relevant CFD theory
1. Pre-processing: instructions on how to set up the correct case structure for a given
problem using base case tutorials, with explanations on relevant dictionaries
2. Running simulation: instructions on running the solver and its associated
commands
3. Post-processing: examining the results in OpenFOAM®’s post-processing
application, ParaView V5.10.1
OpenFOAM® Basic Training
Table of Contents
Appendix D: ParaView
Tutorial One
Basic Case Setup
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial One
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial One
Background
1. What is CFD?
Computational fluid dynamics or CFD is the analysis of systems involving fluid
flow, heat transfer and associated phenomena such as chemical reactions by
means of computer-based simulation. The technique is very powerful and its
application spans a wide range of industrial and non-industrial areas.
The ultimate aim of developments in the CFD field is to provide a capability
comparable to other CAE (computer-aided engineering) tools such as stress
analysis codes. The main reason why CFD has lagged behind is the
tremendous complexity of the underlying behavior of fluid flows.
Although CFD has many advantages, it is not yet at the level where it can be
blindly used without a working knowledge of the physics involved, and despite
the increasing speed of computation available, CFD has not yet matured to a
level where it can be used for real time computation. Numerical analyses
require significant time to be set up and performed. CFD is still an aid to other
analysis and experimental tools like wind tunnel testing, and is used in
conjunction with them. So be careful!
The two most common types of CFD codes are:
open and free
closed source and commercial
We will be focusing on OpenFOAM®, which is a free, open source CFD code,
written in C++. In addition, its source code is accessible and modifiable by its
users. Therefore, you can even develop your own OpenFOAM® solver if you
wish to!
2. Workflow of CFD
A CFD procedure is structured around the numerical algorithms that can tackle
fluid flow problems, and the workflow mostly contains three main elements:
2.1. Pre-processing
Definition of the geometry of the region of interest: the computational
domain
Grid generation – the sub-division of the flow region into a number of
smaller, non-overlapping sub-domains: a grid (or mesh) of cells (or
control volumes or elements)
Selection of suitable models for the interesting physical and chemical
phenomena
Definition of fluid properties
Specification of the appropriate chemical and physical boundary
conditions at cells which coincide with or touch the domain boundary
OpenFOAM® Basic Training
Tutorial One
2.2. Solver
There are at least four distinct streams of numerical solution techniques: finite
difference, finite element, spectral methods and finite volume. We will only
focus on the finite volume method, as it is central to the most well established
CFD solvers. In outline, the finite volume method consists of the following steps:
Integration of the conservation of mass, energy and momentum
equations over all the control volumes in the domain
Discretization – conversion of the resulting integral equations into a
system of algebraic equations
Solution of the algebraic equations by an iterative method
The first step, the control volume integration, makes the finite volume method
different from all other CFD techniques. It makes sure that a general flow
variable, e.g. momentum or enthalpy, is conserved in each finite size cell. This
clear relationship between the numerical algorithm and the underlying
conservation principle makes finite volume method popular and much simpler
to understand.
2.3. Post-processing
This is where you look at the results and visualize them so that you can see
what happens in your model. Typical elements of post-processing are:
Definition of suitable cutting planes for visualization
Contour plots of properties/flow variables
Vector plots
Streamlines
Line plots
Balances
There are several post-processing tools; fluent built-in post-processing tool,
Ensight and TecPlot are some well-known commercial examples. There are
also some open source tools such as Paraview and SALOME.
3. icoFoam solver
icoFoam is an OpenFOAM® solver suitable for analyzing incompressible,
laminar flow of Newtonian fluids. It is based on the PISO algorithm (pressure-
implicit split-operator), which is essentially a pressure-velocity iterative
OpenFOAM® Basic Training
Tutorial One
procedure for transient problems. In each iterative step, PISO solves the
momentum equation using one predictor step, with two further corrector steps
for both velocity and pressure.
OpenFOAM® Basic Training
Tutorial One
icoFoam – elbow
Tutorial outline
Using icoFoam solver, simulate 75 s of flow in an elbow for the following
GAMBIT® meshes:
• Tri-mesh (comes with OpenFOAM® tutorial)
• Hex-mesh coarse (check GAMBIT® “elbow 2D” tutorial)
• 2 times finer hex-mesh (refined previous step mesh)
Objectives
• Basic case setup in OpenFOAM®
• Setting up initial values of p and U
• Ensuring proper boundary definitions (imported boundaries from
GAMBIT®, additional surfaces during conversion and boundaries definition in
OpenFOAM®)
Data processing
Import your simulation to ParaView, extract data to make two diagrams (using
spreadsheet calculators) of pressure and velocity magnitude along a line
between two tubes, do the same for all three simulations.
OpenFOAM® Basic Training
Tutorial One
1. Pre-processing
$FOAM_TUTORIALS/incompressible/icoFoam/elbow
Note: The ‘$’ sign allows the tutorial to be extracted from the installation
directory of OpenFOAM® under the current system environment.
>fluentMeshToFoam elbow.msh
Note: the ‘>’ sign is not part of the command. It is only used to show that the
command should be typed inside a terminal.
If the mesh was created in mm and is converted using the mentioned command
it will convert the mesh with wrong dimensions, since all the units in
OpenFOAM® are SI Units (International System of Units). There are different
flags included with most of OpenFOAM® tools, for checking them use the flag
-help after the command, e.g.:
>fluentMeshToFoam –help
The output gives an overview of available options of the tool and a short
description on how to use it:
Usage: fluentMeshToFoam [OPTIONS] <Fluent mesh file>
options:
-2D <thickness> use when converting a 2-D mesh (applied before scale)
-case <dir> specify alternate case directory, default is the cwd
-fileHandler <handler>
override the fileHandler
-libs <(lib1 .. libN)>
pre-load libraries
-noFunctionObjects
do not execute functionObjects
-scale <factor> geometry scaling factor - default is 1
-writeSets write cell zones and patches as sets
-writeZones write cell zones as zones
-srcDoc display source code in browser
-doc display application documentation in browser
-help print the usage
Using: OpenFOAM-10 (see https://openfoam.org)
Build: 10
OpenFOAM® Basic Training
Tutorial One
The -scale flag is used for converting the mesh dimensions from other units
to SI units, e.g. if the mesh was created in mm it will be converted to meter by
using -scale 0.001 and if the flag is omitted, uses 1:
There are three main directories (0, constant, system) in each case folder:
OpenFOAM® Basic Training
Tutorial One
1.4.1. 0 directory
The 0 directory includes the initial conditions for running the simulation. In each
file in this folder, the initial conditions for one property can be set. The files are
named after the property they are standing for, e.g. usually T file includes
temperature initial conditions. In the elbow example, there are only two files
inside the 0 directory, p and U. p stands for pressure and U stands for velocity.
Checking p:
>nano p
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
wall-4
{
type zeroGradient;
}
velocity-inlet-5
{
type zeroGradient;
}
velocity-inlet-6
{
type zeroGradient;
}
pressure-outlet-7
{
type fixedValue;
value uniform 0;
}
wall-8
{
type zeroGradient;
}
frontAndBackPlanes
{
type empty;
}
}
OpenFOAM® Basic Training
Tutorial One
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Tutorial One
the sake of space, the dictionary headers will not be included in this scope any
more):
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
6
(
wall-4
{
type wall;
inGroups List<word> 1(wall)
nFaces 100;
startFace 1300;
}
velocity-inlet-5
{
type patch;
nFaces 8;
startFace 1400;
}
…
frontAndBackPlanes
{
type empty;
inGroups List<word> 1(empty);
nFaces 1836;
startFace 1454;
}
)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Comparing the boundary names with the ones set in GAMBIT ®, they should be
the same. Starting cell number and number of each face cells can also be
checked here.
Note: However, in terms of boundary type, empty boundary condition does not
exist in GAMBIT®. All the faces perpendicular to the direction, which is not going
to be considered, are defined as a new boundary with type wall. After importing
the mesh to OpenFOAM®, modify that boundary in the file constant/polyMesh/
boundary, and change its type from wall to empty, and change inGroups
from wall to empty. In this case, after converting the mesh, the face
frontAndBackPlanes needs to be modified for both hex-mesh and finer hex-
mesh.
By opening the physicalProperties file, properties dimensions and the property
value can be found and edited, e.g.:
nu [ 0 2 -1 0 0 0 0 ] 0.01;
nu is the fluid kinematic viscosity, which is 0.01 m2/s for this example.
1.4.3. system directory
Solver and finite volume methods settings can be found and changed in this
directory. There are three main files in this directory:
- fvSchemes: The discretization scheme used for each term of the
equations are set in this file.
OpenFOAM® Basic Training
Tutorial One
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 75;
deltaT 0.05;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Note: This simulation continues from the last time step data, which is saved
(latestTime). If there was no saved data, it will start from start time
(startTime), which is zero in this case.
OpenFOAM® Basic Training
Tutorial One
2. Running simulation
The simulation can be run by typing the solver’s name and executing it:
>icoFoam
Note: For running the simulation, the solver command (e.g. icoFoam) should
be executed inside the copy of the tutorial main folder. For example: The
command should be executed in the elbow folder, if it was run at some
subfolders or somewhere else, the simulation will fail.
3. Post-processing
>foamToVTK
where VTK is the ParaView data format. This command should be also
executed in the case main directory, e.g. elbow. Here, ParaView is used as the
post-processing tool, for running it
>paraview &
Note: Another option to open the OpenFOAM® simulation results with ParaView
without converting them to VTK; Create an empty text file in the main case
directory, name it <someName>.foam (e.g. foam.foam), and execute the
following command. This method is good for fast evaluation of the data in the
middle of the simulation or with a decomposed case in parallel simulations:
Note: By putting & at the end of command, the command line will remain active
and ready for further inputs while that program is running.
Tutorial One
Pressure and velocity for different meshes at t=75 s, along the arc shown
OpenFOAM® Basic Training
Tutorial One
The comparison plots are along the line between points A (54 0 0) at the small
tube entrance and B (60 60 0) at the large tube exit part (length units are in
meter) for Tri-mesh, for other two meshes created using GAMBIT ® the points
are A (22 -33 0) and B (27 30 0).
Tri
Hex
Hex
Fine
Tutorial One
Note: For extracting data over a line, the line should be defined in ParaView
using “Plot Over Line”, then the data over this line can be exported by choosing
Save Data from File menu in ParaView.
Tutorial Two
Built in Mesh
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Two
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Two
Background
1. What is mesh?
The partial differential equations that describe fluid flow and heat transfer are
the conservation equations of mass, energy and momentum. However, we are
usually unable to solve them analytically, except in very simple cases. This is
when discretization comes in. The flow region is broken up into smaller sub-
regions, with the equations solved in each sub-region. One of the methods used
to solve the equations is the finite volume method, which we will cover in detail
below. The sub-regions are later on referred to as grid cells, with a collection of
grid cells forming a mesh.
= ∫ ∫ 𝒏 ∙ (𝛤∇𝜑) 𝑑𝐴𝑑𝑡 + ∫ ∫ 𝑆𝜑 𝑑𝑉 𝑑𝑡
∆𝑡 𝐴 ∆𝑡 𝐶𝑉
OpenFOAM® Basic Training
Tutorial Two
4. rhoPimpleFoam solver
rhoPimpleFoam is a transient solver. It solves trans-sonic/supersonic, turbulent
flow of a compressible gas/fluid.
OpenFOAM® Basic Training
Tutorial Two
rhoPimpleFoam – forwardStep
Tutorial outline
Using rhoPimpleFoam solver, simulate 10 s of flow over a forward step.
Objectives
• Understand blockMesh
• Define vertices via coordinates as well as surfaces and volumes via
vertices.
Data processing
Import your simulation into ParaView, and examine the mesh and the results in
detail.
OpenFOAM® Basic Training
Tutorial Two
1. Pre-processing
$FOAM_TUTORIALS/compressible/rhoPimpleFoam/laminar/forwar
dStep
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
OpenFOAM® Basic Training
Tutorial Two
In the thermoType, the models for calculating thermo physical properties of gas
are set:
- type: Specifies the underlying thermos-physical model.
- mixture: Is the model which is used for the mixture, whether it is a pure
mixture, a homogeneous mixture, a reacting mixture or ….
- transport: Defines the used transport model. In this example a
constant value is used.
- thermo: It defines the method for calculating heat capacities, e.g. in this
example constant heat capacities are used.
- equationOfState: Shows the relation which is used for the
compressibility of gases. Here ideal gas model is applied by selecting
perfectGas.
- energy: This key word lets the solver decide which type of energy
equation it should solve, enthalpy or internal energy.
After defining the models for different thermos-physical properties of gas, the
constants and coefficients of each model are defined in the sub-dictionary
mixture. E.g. molWeight shows the molecular weight of gas, Cp stands for
heat capacity, Hf is the heat of fusion, mu is the dynamic viscosity and Pr shows
the Prandtl number.
By opening the momentumProperties the appropriate turbulent mode can be
set (in this case it is laminar):
simulationType laminar;
>nano blockMeshDict
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
convertToMeters 1;
vertices
(
(0 0 -0.05)
(0.6 0 -0.05)
(0 0.2 -0.05)
(0.6 0.2 -0.05)
(3 0.2 -0.05)
(0 1 -0.05)
(0.6 1 -0.05)
(3 1 -0.05)
(0 0 0.05)
(0.6 0 0.05)
(0 0.2 0.05)
(0.6 0.2 0.05)
(3 0.2 0.05)
(0 1 0.05)
(0.6 1 0.05)
(3 1 0.05)
OpenFOAM® Basic Training
Tutorial Two
);
blocks
(
hex (0 1 3 2 8 9 11 10) (25 10 1) simpleGrading (1 1 1)
hex (2 3 6 5 10 11 14 13) (25 40 1) simpleGrading (1 1 1)
hex (3 4 7 6 11 12 15 14) (100 40 1) simpleGrading (1 1 1)
);
defaultPatch
{
type empty;
}
boundary
(
inlet
{
type patch;
faces
(
(0 8 10 2)
(2 10 13 5)
);
}
outlet
{
type patch;
faces
(
(4 7 15 12)
);
}
bottom
{
type symmetryPlane;
faces
(
(0 1 9 8)
);
}
top
{
type symmetryPlane;
faces
(
(5 13 14 6)
(6 14 15 7)
);
}
obstacle
{
type patch;
faces
(
(1 3 11 9)
(3 4 12 11)
);
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Tutorial Two
shows that the dimensions are in millimeter, and by multiplying them by 0.001
they are converted into meters.
In the vertices part, the coordinates of the geometry vertices are defined, the
vertices are stored and numbered from zero, e.g. vertex (0 0 -0.05) is
numbered zero, and vertex (0.6 1 -0.05) points to number 6.
In the block part, blocks are defined. The array of numbers in front each block
shows the block building vertices, e.g. the first block is made of vertices (0 1
3 2 8 9 11 10).
After each block, the mesh is defined in every direction. e.g. (25 10 1) shows
that this block is divided into:
- 25 parts in x direction
- 10 parts in y direction
- 1 part in z direction
As it was explained before, even for 2D simulations the mesh and geometry
should be 3D, but with one cell in the direction, which is not going to be solved,
e.g. here number of cells in z direction is one and it’s because of that it’s a 2D
simulation in x-y plane.
The last part, simpleGrading(1 1 1) shows the size function.
In the boundary part, each boundary is defined by the vertices it is made of,
and its type and name are defined.
Note: For creating a face, the vertices should be chosen clockwise when
looking at the face from inside of the geometry.
2. Running simulation
Before running the simulation, the mesh has to be created. In the previous step,
the mesh and the geometry data were set. For creating it, the following
command should be executed from the case main directory (e.g. forwardStep):
>blockMesh
After that, the mesh is created in the constant/polyMesh folder. For running the
simulation, type the solver name form case directory and execute it:
>rhoPimpleFoam
3. Post-processing
The mesh is presented in the following way in ParaView, and you can easily
see the three blocks, which were created.
OpenFOAM® Basic Training
Tutorial Two
Note: When a cut is created by default in ParaView, the program shows the
mesh on that plane as a triangular mesh even if it is a hex mesh. In fact,
ParaView changes the mesh to a triangular mesh for visualization, where every
square is represented by two triangles. For avoiding this when creating a cut in
ParaView in the Slice properties window, uncheck “Triangulate the Slice”.
The simulation results are as follows:
0.5 s
1s
10 s
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Three
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Three
Background
Tutorial Three
As it is obvious from the equation by decreasing the mesh size (i.e. ∆𝑥), the
time step size (∆𝑡) should also be adjusted (decreased) for reaching a stable
and convergent solution. Therefore the CFL condition is useful in helping us
choose a suitable time step size for our simulation. A common way of selecting
the time step size is to keep Courant number at 1, using the maximum possible
u and the smallest possible mesh size, a Δt that fits the criteria can be
calculated.
OpenFOAM® Basic Training
Tutorial Three
rhoPimpleFoam – shockTube
Tutorial outline
Use the rhoPimpleFoam solver; simulate 0.007 s of flow inside a shock tube,
with a mesh with 100, 1000 and 10000 cells in one dimension, for initial values
1 bar/0.1 bar and 10 bar/0.1 bar.
Objectives
To understand the setFields utility
Learn how to specify initial and boundary conditions
Investigate effect of grid resolution.
Data processing
Import your simulation into ParaView, and compare results.
OpenFOAM® Basic Training
Tutorial Three
1. Pre-processing
$FOAM_TUTORIALS/compressible/rhoPimpleFoam/laminar/shockT
ube
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
>blockMesh
>setFields
Then run:
>rhoPimpleFoam
OpenFOAM® Basic Training
Tutorial Three
Note: In the 10000 cell case with 10 bar and 0.1 bar, the simulation will crash
with the default deltaT (1e-5); after checking the same case with 1000 cells,
you will find that the maximum Co is around 0.6 (Time = 0.001):
Courant Number mean: 0.0508555 max: 0.589018
In the case with 10000 cells, the number of cells is increased by factor 10, so
the cell size is reduced by factor 10. For keeping the Courant number in the
same range (around 0.6), according to the “Background” section, deltaT
should be decreased by factor 10. After reducing it to 1e-6 the simulation will
run smoothly.
Note: After running setFields for the first time, the files in the 0 directory are
overwritten. If the mesh is changed these files are not compatible with the new
mesh and the simulation will fail. To solve this problem replace the files in the
0 directory with the files in the 0.orig or the files with suffix “.orig”, e.g. p.orig in
the 0 directory. In the OpenFOAM® files or directories with suffix “.orig”
(“original”) usually contain the backup files. If a command changes the original
files these files can be replaced.
3. Post-processing
The simulation results are as follows:
OpenFOAM® Basic Training
Tutorial Three
Velocity along tube axis for 10 bar/0.1bar and 10000 cells case at t = 0.007s
OpenFOAM® Basic Training
Tutorial Three
Pressure along tube axis for 10 bar/0.1bar and 10000 cells case at
t = 0.007s
OpenFOAM® Basic Training
Tutorial Three
Temperature along tube axis for 10 bar/0.1bar and 10000 cells case at
t = 0.007 s
Tutorial Four
Discretization – Part 1
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Four
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Four
Background
Where F is the mass flux through the face 𝑓 defined as 𝐹 = 𝒏 ∙ (𝐴𝜌𝒖)𝑓 . The
value 𝜑𝑓 on face f can be evaluated in a variety of ways, which will be covered
later in section 2. The subscript 𝑓 refers to a given face.
∫ 𝒏 ∙ (𝛤𝛻𝜑) 𝑑𝐴 = ∑ 𝛤𝑓 (𝒏 ∙ 𝛻𝑓 𝜑)𝐴𝑓
𝐴 𝑓
Tutorial Four
𝜑𝑁 − 𝜑𝑃
𝒏 ∙ 𝛻𝑓 𝜑 =
|𝒅|
This approximation is second order accurate when the vector 𝒅 between the
center of the cell of interest P and the center of a neighboring cell N is
orthogonal to the face plane, i.e. parallel to A. In the case of non-orthogonal
meshes, a correction term could be introduced which is evaluated by
interpolating cell centered gradients obtained from Gauss integration.
∫ 𝑆𝜑 𝑑𝑉 = 𝑆𝐼 𝑉𝑃 𝜑𝑃 + 𝑆𝐸 𝑉𝑃
𝑉
2. Discretization Schemes
Since the results of CFD simulations are typically stored at the cell centers, it is
important to interpolate the results from cell centers to the face centers, to
obtain the fluxes for the surface integrals in the transport equation. For each
term of the transport equation, there is a variety of discretization/interpolation
schemes available.
In general, interpolation needs a flux F through a general face f, and in some
cases, one or more parameters 𝛾. The face value 𝜑𝑓 can be evaluated from the
values in the neighboring cells using a variety of schemes. The flux satisfies
continuity constraints, which is prerequisite to obtaining the results.
Tutorial Four
2.3. QUICK
QUICK stands for Quadratic Upwind Interpolation for Convective Kinetics. In
the QUICK scheme 3 point upstream-weighted quadratic interpolation are used
for cell face values.
6 3 1
𝑊ℎ𝑒𝑛 𝐹𝑒 > 0, 𝜑𝑒 = 𝜑𝑃 + 𝜑𝐸 − 𝜑𝑊
8 8 8
6 3 1
𝑊ℎ𝑒𝑛 𝐹𝑤 > 0, 𝜑𝑤 = 𝜑𝑊 + 𝜑𝑃 − 𝜑𝑊𝑊
8 8 8
OpenFOAM® Basic Training
Tutorial Four
QUICK scheme
Similar expressions can be obtained for 𝐹𝑒 < 0 and 𝐹𝑤 < 0.
Now that you know a bit more about discretization schemes, we can move on
to the tutorial. In this tutorial, the scalarTransportFoam solver is used. More
explanation of this solver can be found below.
3. scalarTransportFoam solver
scalarTransportFoam is a basic solver which resolves a transport equation for
a passive scalar. The velocity field and boundary condition need to be provided
by the user. It works by setting the source term in the transport equation to zero
(see equation below), and then solving the equation.
𝜕(𝜌𝜑)
+ 𝛻 ∙ (𝜌𝜑𝒖) − 𝛻 ∙ (𝛤𝛻𝜑) = 0
𝜕𝑡
OpenFOAM® Basic Training
Tutorial Four
scalarTransportFoam – shockTube
Tutorial outline
Use the scalarTransportFoam solver, simulate 5 s of flow inside a shock tube,
with 1D mesh of 1000 cells (10 m long geometry from -5 m to 5 m). Patch with
a scalar of 1 from -0.5 to 0.5. Simulate following cases:
Set U to uniform (0 0 0). Vary diffusion coefficient (low, medium and high
value).
Set the diffusion coefficient to zero and also U to (1 0 0) and run the
simulation in the case of pure advection using following discretization
schemes:
- upwind
- linear
- linearUpwind
- QUICK
- cubic
Objectives
• Understanding different discretization schemes.
Data processing
Import your simulation into ParaView, and plot temperature along tube length.
OpenFOAM® Basic Training
Tutorial Four
1. Pre-processing
>mkdir shockTube
$FOAM_TUTORIALS/compressible/rhoPimpleFoam/laminar/shockT
ube
In the 0 directory, create a copy of T.orig and U.orig and rename them to T and
U respectively. In the constant directory delete the thermophysicalProperties
and turbulenceProperties files, and in the system directory delete all the files
except for blockMeshDict and setFieldsDict files.
From the following case:
$FOAM_TUTORIALS/basic/scalarTransportFoam/pitzDaily
Copy physicalProperties file from constant folder in the newly created case
constant folder. Copy controlDict, fvSchemes and fvSolution from the above
case system directory to the created case system directory.
Note: By setting the diffusion coefficient to zero, the case will be switched to a
pure advection simulation with no diffusion.
fieldValues
(
volScalarFieldValue T 1.0
OpenFOAM® Basic Training
Tutorial Four
);
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
gradSchemes
{
default Gauss linear;
}
divSchemes
{
default none;
div(phi,T) Gauss linearUpwind grad(T);
}
laplacianSchemes
{
default none;
laplacian(DT,T) Gauss linear corrected;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default corrected;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
For each type of operation a default scheme can be set (e.g. for divSchemes
is set to none, it means no default scheme is set). Also a special type of
discretization for each element can be assigned (e.g. div(phi,T) it is set to
linearUpwind). For each element, where a discretization method has not been
set, the default method will be applied. If the default setting is none, no scheme
is set for that element and the simulation will crash.
Note: In fvSchemes, the schemes for the time term of the general transport
equation are set in ddtSchemes sub-dictionary. divSchemes are responsible for
the advection term schemes and laplacianSchemes set the diffusion term
schemes.
Note: divSchemes should be applied like this: Gauss + scheme. The Gauss
keyword specifies the standard finite volume discretization of Gaussian
integration which requires the interpolation of values from cell centers to face
centers. Therefore, the Gauss entry must be followed by the choice of
interpolation scheme (www.openfoam.org).
OpenFOAM® Basic Training
Tutorial Four
2. Running simulation
>blockMesh
>setFields
>scalarTransportFoam
3. Post-processing
Tutorial Four
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Five
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Five
Background
1.1. Conservativeness
Integration of the convection–diffusion equation over a finite number of control
volumes yields a set of discretized conservation equations involving fluxes of
the transported property φ through control volume faces. To ensure
conservation of φ for the whole solution domain the flux of φ leaving a control
volume across a certain face must be equal to the flux of φ entering the adjacent
control volume through the same face. To achieve this flux through a common
face must be represented in a consistent manner – by one and the same
expression – in adjacent control volumes of each face.
1.2. Boundedness
Normally we use iterative numerical techniques to solve discretized equations
at each nodal point. The methods start with a guessed distribution of the initial
conditions of the variable φ and perform successive updates until a converged
solution is obtained.
The sufficient condition for a converged solution is:
∑|𝑎𝑛𝑏 | ≤ 1 𝑎𝑡 𝑎𝑙𝑙 𝑛𝑜𝑑𝑒𝑠
{
|𝑎᾿𝑃 | < 1 𝑎𝑡 𝑜𝑛𝑒 𝑛𝑜𝑑𝑒 𝑎𝑡 𝑙𝑒𝑎𝑠𝑡
Here 𝑎᾿𝑃 is the net coefficient of the central node P (i.e. 𝑎᾿𝑃 − 𝑆𝑃 ), 𝑎𝑛𝑏 are the
coefficient of the neighbouring nodes. If the condition is satisfied, the resulting
matrix of coefficients is diagonally dominant. We need the net coefficients to be
as large as possible; this means that 𝑆𝑃 should be always negative. If this is the
case, 𝑆𝑃 becomes positive due to the modulus sign and adds to 𝑎𝑃 .
1.3. Transportiveness
To understand transportiveness, one should look at a dimensionless number
called the Peclet number, 𝑃𝑒. It measures the relative strengths of convection,
𝑁𝑐𝑜𝑛𝑣 and diffusion, 𝑁𝑑𝑖𝑓𝑓 .
𝑁𝑐𝑜𝑛𝑣 𝐿𝑈
𝑃𝑒 = =
𝑁𝑑𝑖𝑓𝑓 𝐷
Tutorial Five
Let us consider the effect at a point P due to two constant sources of φ at nearby
points W and E on either side, in three cases.
1. When Pe = 0 (pure diffusion), the contours of φ are circles, as φ is spread
out evenly in all directions
2. As Pe increases, the contours become elliptical, as the values of φ are
influenced by convection
3. When Pe→∞, the countours become straight lines, since φ are stretched
out completely and affected only by upstream conditions
4. Transportiveness property
Conser- Trans-
Scheme Bounded Accuracy Remarks
vative portive
Less computationally
Unconditionally stable. Can give small
QUICK Yes Third order Yes
bounded undershoots and
overshoots
⃰ Pe should be less than 2.
OpenFOAM® Basic Training
Tutorial Five
Second-order
First-order upwind
upwind
8×8
64 × 64
Numerical diffusion
Tutorial Five
scalarTransportFoam – circle
Tutorial outline
Use the scalarTransportFoam solver, do simulate the movement of a circular
scalar spot region (radius = 1 m) at the middle of a 100 × 100 cell mesh (10 m
× 10 m), then move it to the right (3 m), to the top (3 m) and diagonally.
Objectives
• Choosing the best discretization scheme.
Data processing
Examine your simulation in ParaView.
OpenFOAM® Basic Training
Tutorial Five
1. Pre-processing
1.2. 0 directory
To move the circle to right change the internalField to (1 0 0) in the U file
for setting the velocity field towards the right. Modify U at suitable times, to
obtain a velocity field which will move the circle up and also diagonally.
vertices
(
(-5 -5 -0.01)
(5 -5 -0.01)
(5 5 -0.01)
(-5 5 -0.01)
(-5 -5 0.01)
(5 -5 0.01)
(5 5 0.01)
(-5 5 0.01)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (100 100 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
sides
{
type patch;
faces
(
(1 2 6 5)
(0 4 7 3)
(3 7 6 2)
(0 1 5 4)
);
}
empty
{
type empty;
faces
(
(5 6 7 4)
(0 3 2 1)
);
OpenFOAM® Basic Training
Tutorial Five
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
defaultFieldValues (volScalarFieldValue T 0 );
regions
(
cylinderToCell
{
p1 ( 0 0 -1 );
p2 ( 0 0 1 );
radius 0.5;
fieldValues
(
volScalarFieldValue T 1
) ;
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
>blockMesh
>setFields
>scalarTransportFoam
For running the further parts (moving the circle to top, and then diagonally)
change the velocity field in the last time step directory, i.e. change the velocity
in the time step directory 3 to (0 1 0) so the circle moves up, further change the
velocity in the directory 6 to (-1 -1 0) to move the circle diagonally back to the
original position.
After moving the circle to the right and changing the velocity field, the simulation
is resumed. It can be seen that the circle does not go up but moves to the right.
This occurs because OpenFOAM® used the previous time step fluxes (phi) to
OpenFOAM® Basic Training
Tutorial Five
do the calculations. We can solve this problem by deleting phi file from the latest
time step (of the previous part of simulation, e.g. 3). In this way, OpenFOAM ®
creates new fluxes based on the new velocity field that we just updated. So,
easily delete phi and enjoy!
3. Post-processing
The simulation results are as follows:
1s 2s 3s
4s 5s 6s
7s 8s 9s
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Six
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Six
Background
2. RANS-based models
The governing equations for a Newtonian fluid are:
Conservation of mass
𝜕𝜌
+ ∇ ∙ (𝜌𝒖
̃) = 0
𝜕𝑡
Conservation of momentum (Navier-Stokes equation)
𝜕(𝜌𝑢̃𝑖 ) 𝜕𝑝̃
+ ∇ ∙ (𝜌𝑢̃𝑖 𝒖
̃) = − + ∇ ∙ (𝜇∇𝑢̃𝑖 ) + 𝑆̃𝑀𝑖
𝜕𝑡 𝜕𝑥𝑖
Tutorial Six
One of the solutions to the problem is to reduce the number of scales (from
infinity to 1 or 2) by using the Reynolds decomposition. Any property (whether
a vector or a scalar) can be written as the sum of an average and a fluctuation,
i.e. 𝜑̃ = Φ + φ where the capital letter denotes the average and the lower case
letter denotes the fluctuation of the property. Using the Reynolds decomposition
in the Navier-Stokes equations, we obtain RANS or Reynolds Averaged Navier
Stokes Equations.
Average conservation of mass
𝜕𝜌
+ ∇ ∙ (𝜌𝐔) = 0
𝜕𝑡
Average conservation of momentum
𝜕(𝜌U𝑖 ) 𝜕𝑃 𝜕(𝜌𝑢𝑢
̅̅̅̅̅)
𝑖 𝜕(𝜌𝑣𝑢
̅̅̅̅̅)
𝑖 𝜕(𝜌𝑤𝑢
̅̅̅̅̅)
𝑖
+ ∇ ∙ (𝜌U𝑖 𝐔) = − + ∇ ∙ (𝜇U𝑖 ) − ( + + ) + S𝑀𝑖
𝜕𝑡 𝜕𝑥𝑖 𝜕𝑥 𝜕𝑦 𝜕𝑧
Tutorial Six
tutorial, we will move on to LES modeling and compare the results generated
from these two modeling types.
OpenFOAM® Basic Training
Tutorial Six
simpleFoam – pitzDaily
Tutorial outline
Use simpleFoam solver, run a steady state simulation with following turbulence
models:
kEpsilon (RAS)
kOmega (RAS)
Objectives
Understanding turbulence modeling
Understanding steady state simulation
Data processing
Show the results of U and the turbulent viscosity in two separate contour plots.
OpenFOAM® Basic Training
Tutorial Six
1. Pre-processing
$FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily
1.2. 0 directory
When a turbulent model is chosen, the value of its constants and its boundary
values should be set in the appropriate files. For example in kEpsilon model the
k and epsilon files should be edited. See below for the epsilon file (in the 0
folder):
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
dimensions [0 2 -3 0 0 0 0];
boundaryField
{
inlet
{
type fixedValue;
value uniform 14.855;
}
outlet
{
type zeroGradient;
}
upperWall
{
type epsilonWallFunction;
value uniform 14.855;
}
lowerWall
{
type epsilonWallFunction;
value uniform 14.855;
}
frontAndBack
{
type empty;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Note: Here is a list of files, which should be available at 0 directory and need to
be modified for each turbulence model:
laminar: no file
kEpsilon (RAS): k and epsilon
kOmega (RAS): k and omega
LRR (RAS): k, epsilon and R
Smagorinsky (LES): s
kEqn (LES): k and s
OpenFOAM® Basic Training
Tutorial Six
simulationType RAS;
RAS
{
// Tested with kEpsilon, realizableKE, kOmega, kOmegaSST, v2F,
// ShihQuadraticKE, LienCubicKE.
model kEpsilon;
turbulence on;
printCoeffs on;
viscosityModel Newtonian;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Note: For the laminar model, set turbulence and printCoeffs to off.
ddtSchemes
{
default steadyState;
}
gradSchemes
{
default Gauss linear;
}
divSchemes
{
default none;
OpenFOAM® Basic Training
Tutorial Six
laplacianSchemes
{
default Gauss linear corrected;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default corrected;
}
wallDist
{
Method meshWave;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
>blockMesh
>simpleFoam
Tutorial Six
3. Post-processing
The simulation results are as follows (all simulations scaled to the same range):
RAS
Velocity magnitude Turbulent viscosity
model
kEpsilon
kOmega
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Seven
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Seven
Background
resulting in
𝑢𝑖 = 𝑢̅𝑖 + 𝑢, 𝑖
Where 𝑢̅𝑖 is the resolvable scale part and 𝑢, 𝑖 is the subgrid-scale part. However,
most practical (and commercial) implementations of LES use the grid itself as
the filter and perform no explicit filtering. The filtered equations are developed
from the incompressible Navier-Stokes equations of motion:
𝜕𝑢𝑖 𝜕𝑢𝑖 1 𝜕𝑝 𝜕 𝜕𝑢𝑖
+ 𝑢𝑗 =− + (𝜐 )
𝜕𝑡 𝜕𝑥𝑗 𝜌 𝜕𝑥𝑖 𝜕𝑥𝑗 𝜕𝑥𝑗
We have assumed that the filtering operation and the differentiation operation
commute, which is not generally the case. It is thought that the errors
associated with this assumption are usually small, though filters that commute
with differentiation have been developed. The extra term 𝜕𝜏𝑖𝑗 /𝜕𝑥𝑗 arises from
the non-linear advection terms, because:
𝜕𝑢𝑖 𝜕𝑢̅𝑖
𝑢𝑗 ≠ 𝑢̅𝑗
𝜕𝑥𝑗 𝜕𝑥𝑗
and hence
𝜏𝑖𝑗 = 𝑢̅𝑖 𝑢̅𝑗 − 𝑢
̅̅̅̅̅
𝑖 𝑢𝑗
Similar equations can be derived for the sub grid-scale field. Sub grid-scale
turbulence models usually employ the Boussinesq hypothesis, and seek to
calculate (the deviatoric part of) the SGS stress using:
1
̅
𝜏𝑖𝑗 − τ𝑘𝑘 δ𝑖𝑗 = −2μ𝑡 𝑆𝑖𝑗
3
OpenFOAM® Basic Training
Tutorial Seven
2. Smagorinsky-Lilly model
A simple model for Sub grid-scale model is the Smagorinsky model, which can
be summarized as:
1
𝜏𝑖𝑗 − τ𝑘𝑘 δ𝑖𝑗 = −2(C𝑠 ∆)2 |𝑆̅|S𝑖𝑗
3
In the Smagorinsky-Lilly model, the eddy viscosity is modeled by
𝜇𝑠𝑔𝑠 = ρ(C𝑠 ∆)2 |𝑆̅|
𝑆̅ = √2𝑆𝑖𝑗 𝑆𝑖𝑗
Tutorial Seven
pisoFoam – pitzDaily
Tutorial outline
Use the pisoFoam solver, run a backward facing step case for 0.2 s with
different turbulence models:
Smagorinsky (LES)
kEqn (LES)
kEpsilon (RAS)
Objectives
• Understanding turbulence models
• Understanding the difference between transient and steady state
simulation
• Finding appropriate turbulence model
Data processing
Display the results of U and the turbulent viscosity in two separate contour plots
at three different time steps. Compare with steady state simulation (Tutorial
Six).
OpenFOAM® Basic Training
Tutorial Seven
1. Pre-processing
$FOAM_TUTORIALS/incompressible/pisoFoam/LES/pitzDaily
Also add the blockMeshDict file from following directory to your system
directory:
$FOAM_TUTORIALS/resources/blockMesh/pitzDaily
1.2. 0 directory
Set the proper turbulence model initial and boundary conditions and values.
Note: For different turbulent models, different files should be modified (check
Tutorial Six).
For kEpsilon model, the epsilon file need to be added and on the walls, for all
three properties: k, epsilon and nut, the wall-functions should be applied (based
on the y+ value) and proper initial values to be set. For more information:
https://www.openfoam.com/documentation/guides/latest/doc/guide-
turbulence.html
LES
{
LESModel kEqn;
turbulence on;
printCoeffs on;
delta cubeRootVol;
dynamicKEqnCoeffs
{
filter simple;
}
cubeRootVolCoeffs
{
deltaCoeff 1;
}
PrandtlCoeffs
{
delta cubeRootVol;
cubeRootVolCoeffs
{
OpenFOAM® Basic Training
Tutorial Seven
deltaCoeff 1;
}
smoothCoeffs
{
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
maxDeltaRatio 1.1;
}
Cdelta 0.158;
}
vanDriestCoeffs
{
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
smoothCoeffs
{
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
maxDeltaRatio 1.1;
}
Aplus 26;
Cdelta 0.158;
}
smoothCoeffs
{
delta cubeRootVol;
cubeRootVolCoeffs
{
deltaCoeff 1;
}
maxDeltaRatio 1.1;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
2. Running simulation
>blockMesh
>pisoFoam
3. Post-processing
The simulation results are as follows:
For the kEpsilon model after 0.2 s the results are similar to the steady state
simulation. Therefore, it can be assumed it has reached the steady state. Other
OpenFOAM® Basic Training
Tutorial Seven
models do not have a steady situation and are fluctuating all the time, so they
require averaging for obtaining steady state results.
kEpsilon and other RAS models use averaging to obtain the turbulence values,
but LES does not include any averaging by default. Therefore, LES simulations
should use a higher grid resolution (smaller cells) and smaller time steps (for
reasonable Co number). Contour plots or other LES results should be
presented time averaged over reasonable number of time steps (not done in
this tutorial).
OpenFOAM® Basic Training
Tutorial Seven
Smagorinsky
0.01 s
0.05 s
0.2 s
kEqn
0.01 s
0.05 s
0.2 s
kEpsilon
0.01 s
0.05 s
0.2 s
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Eight
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Eight
Background
In this tutorial, we are going to solve a problem of dam break using the
interFoam solver. The main feature of this problem is flow of water and air
separated by a sharp interface. Before starting, let us cover some of the basics
of multiphase flow.
1. Multiphase flow
Multiphase flow is simultaneous flow of materials in different phases. There can
be multiple components present in each phase. The common types of
multiphase flows are gas-liquid, gas-solid, liquid-solid, liquid-liquid and three-
phase flows.
Multiphase flow can be further categorized based on the visual appearance of
the flow into separated, mixed or dispersed flow. In dispersed flow, one phase
exist as a continuous fluid, while all other phases act as discontinuous particles
flowing through the continuous fluid. In mixed flow regions, dispersed particles
as well as semi-continuous interfaces exist together.
So why is multiphase flow important? Multiphase flow is present in many
industrial processes, such as bubble columns, absorption, adsorption and
stripping columns. Modeling of multiphase flow can help maximizing contact
between different phases, hence increasing the efficiency of the process.
2. Modeling approaches
Modeling of multiphase flow can be extremely complex, due to possible flow
regime transitions. To simplify the matter, different modeling approaches can
be adopted and they generally fall into two categories: lagrangian and Eulerian.
In the case of dispersed configuration, Lagrangian approach is more suitable.
This involves tracking individual point particles during its movement. The other
approach is the Eulerian approach, which observes fluid behavior in a given
control volume. Below we will cover some common modeling approaches of
multiphase flow.
Tutorial Eight
equation for the volume fraction is solved. Coupling between the phases is
achieved through a shared pressure and interphase exchange coefficients.
During that interaction, the fluid fluctuating velocity is kept constant and the
discrete particle is moved with respect to its equation of motion. Then a new
fluctuating fluid velocity is sampled and the process is repeated.
3. interFoam solver
interFoam is suitable for solving multiphase flow between 2 incompressible,
isothermal immiscible fluids. It is based on the Volume of Fluid (VOF) approach.
OpenFOAM® Basic Training
Tutorial Eight
interFoam – damBreak
Tutorial outline
Use the interFoam solver to simulate breaking of a dam for 2s.
Objectives
• Understanding how to set viscosity, surface tension and density for two
phases
Data processing
See the results in ParaView.
OpenFOAM® Basic Training
Tutorial Eight
1. Pre-processing
$FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak/dam
Break
1.2. 0 directory
In the 0 directory the following files exist:
alpha.water.orig p_rgh U
In the alpha.water.orig and p_rgh files, the initial values and boundary
conditions for water phase and pressure are set. Copy alpha.water.orig to
alpha.water (remember: the *.orig files are back up files, and solvers do not use
them). E.g. in alpha.water:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField
{
leftWall
{
type zeroGradient;
}
rightWall
{
type zeroGradient;
}
lowerWall
{
type zeroGradient;
}
atmosphere
{
type inletOutlet;
inletValue uniform 0;
value uniform 0;
}
defaultFaces
{
type empty;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Note: The inletOutlet and the outletInlet boundary conditions are used
when the flow direction is not known. In fact, these are derived types and are a
combination of two different boundary types.
OpenFOAM® Basic Training
Tutorial Eight
sigma 0.07;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
and sigma is the surface tension between two phases, in this example it is the
surface tension between air and water.
For each phase, there is a dedicated physicalProperties.fileName file, in which
the properties of the relevant phase can be set. E.g. the
physicalProperties.water file looks as following:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
viscosityModel constant;
nu 1e-06;
rho 1000;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
In both phases the coefficients for different models of viscosity are given, e.g.
nu and rho. Depending on which model is selected, the corresponding
coefficients are read. In this simulation, the selected model is constant
(representing Newtonian model), therefore only the nu coefficient is needed.
Checking the g file, the gravitational field and its direction are defined, it is
9.81 m/s2 in the negative y direction.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
dimensions [0 1 -2 0 0 0 0];
value ( 0 -9.81 0 );
OpenFOAM® Basic Training
Tutorial Eight
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
2. Running simulation
>blockMesh
>setFields
>interFoam
3. Post-processing
The simulation results are as follows (these are not the results for the original
mesh, but a 2x refined mesh):
OpenFOAM® Basic Training
Tutorial Eight
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Nine
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Nine
Background
In this tutorial, we will analyze compressible fluid flow in OpenFOAM®. Parallel
processing is utilized to speed up the simulation. In this introduction part, theory
behind compressible flow, solvers for compressible flow and parallel computing
will be explained in detail.
Tutorial Nine
3. Parallel computing
Imagine if we need to tackle a complex CFD problem that involves complex
geometry, multiphase flow, turbulence and reaction, how do we adopt a
methodical computational approach to save time and cost? This is when
parallel computing comes in. Parallel computing is defined as the simultaneous
use of more than one processor to execute a program. The geometry of the
domain will be partitioned into sub-domains, with each sub-domain assigned to
a single processor. Furthermore data and computational tasks will be
partitioned and divided amongst the processors. This step is known as domain
decomposition.
Parallel computing can be carried out in two ways. One is done on a single
computer with multiple internal processors, known as a Shared Memory
Multiprocessor. The other way is achieved through a series of computers
interconnected by a network, known as a Distributed Memory Multicomputer.
Tutorial Nine
compressibleInterFoam – depthCharge3D
Tutorial outline
Use the compressibleInterFoam solver, simulate the example case for 0.5 s.
Objectives
• Understanding the difference between incompressible and compressible
solvers
• Understanding parallel processing and different discretization methods
Data processing
Investigate the results in ParaView.
OpenFOAM® Basic Training
Tutorial Nine
1. Pre-processing
$FOAM_TUTORIALS/multiphase/compressibleInterFoam/laminar/
depthCharge3D
1.2. 0 directory
In the 0 directory copy the alpha.water.orig, p.orig and p_rgh.orig files to
alpha.water, p and p_rgh respectively.
pMin 10000;
sigma 0.07;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
method hierarchical;
simpleCoeffs
{
n ( 1 4 1 );
}
hierarchicalCoeffs
{
n ( 1 4 1 );
order xyz;
}
manualCoeffs
{
dataFile "";
}
OpenFOAM® Basic Training
Tutorial Nine
distributed no;
roots ( );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
>blockMesh
>setFields
For running the simulation in parallel mode the computing domain needs to be
divided into subdomains and a core should be assigned to each subdomain.
This is done by following command:
>decomposePar
Tutorial Nine
<No of cores> is the number of cores being used. solver is the solver for
this simulation. For example, if 4 cores are desired, and the solver is
compressibleInterFoam following command is used:
> log is the filename for saving the simulation status data, instead of printing
them to the screen. For checking the last information which is written to this file
the following command can be used during the simulation running:
>tail –f log
Note: Before running any simulation, it is important to run the top command
(type the ‘top’ command in the terminal), to check the number of cores currently
used on the machine. Check the load average. This is on the first line and
shows the average number of cores being used. There are three numbers
displayed, showing the load averages across three different time scales (one,
five and 15 minute respectively).
Add the number of cores you plan to use to this number – and you will get the
expected load average during your simulation. This number should be less than
the total number of cores in the machine – or the simulation will be slowed or
the machine will crash (if you run out of memory). If you are running on a multi
user server it is recommended to leave at least a few cores free, to allow for
any fluctuations in the machine load.
Note: top command execution can be interrupted by typing q (or ctrl+c)
The simulation can take several hours, depending on the size of the mesh and
time step size.
3. Post-processing
For exporting data for post processing, at first all the processors data should be
put together and a single combined directory for each time step was created.
By executing the following command all the cores data will be combined and
new directories for each time step will be created in the simulation main
directory:
>reconstructPar
>foamToVTK
Tutorial Nine
Using above commands without entering end time will do the reconstruction or
conversion from start time to the end of available data:
For reconstructing or converting only one time step the commands should be
used without end time and “:”:
Tutorial Nine
0s 0.05 s 0.1 s
0.3 s 0.5 s
0.4 s
Tutorial Nine
4. Manual method
>decomposePar –cellDist
1024000
(
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1 ...)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Note: If the above output is not displayed, but a stream of NUL characters, your
text editor is probably printing binary. To fix this, open system/controlDict, and
change the writeFormat field from binary to asci and rerun the previous
command.
The first number n after the header, but before the opening brackets, 1024000
in this example, refers to the number of points in the mesh. Within the brackets,
n lines follow. Each line contains one number between 0 and n-1, where n is
the number of cores to be used for the computation. This number refers to the
core being used to compute the corresponding cell in the points file in the
constant directory. For example, if the second line in the points file brackets
OpenFOAM® Basic Training
Tutorial Nine
numberOfSubdomains 4;
method manual;
simpleCoeffs
{
n ( 1 4 1 );
delta 0.001;
}
hierarchicalCoeffs
{
n ( 1 4 1 );
delta 0.001;
order xyz;
}
manualCoeffs
{
dataFile "manFile";
}
distributed no;
roots ( );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
Delete the old processor directories, decompose the case with the new
decomposition settings and run the simulation.
>cd processor<n>
OpenFOAM® Basic Training
Tutorial Nine
>foamToVTK
>paraview &
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Ten
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Ten
Background
In this tutorial, we will carry out Residence Time Distribution (RTD) analysis of
fluid flow through a T-junction pipe.
2. Tracer Analysis
It is clear from the above equation that the fraction of tracer molecules exiting
the reactor that have spent a time between 𝑡 and 𝑡 + 𝑑𝑡 in the process unit is
𝐸(𝑡)𝑑𝑡. Since all tracer elements will leave the unit at some point, RTD satisfies
the following relationship:
∞
∫ 𝐸(𝑡) 𝑑𝑡 = 1
0
OpenFOAM® Basic Training
Tutorial Ten
Tutorial outline
Use the simpleFoam and scalarTransportFoam to simulate the flow through a
square cross section T pipe and calculate RTD (Residence Time Distribution)
for both inlets using a step function injection:
• Inlet and outlet cross-sections: 1 × 1 m2
• Gas in the system: air at ambient conditions
• Operating pressure: 105 Pa
• Inlet 1: 0.1 m/s
• Inlet 2: 0.2 m/s
Objectives
• Understanding RTD calculation using OpenFOAM®
• Using multiple solvers for a simulation
Data processing
Plot the step response function and the RTD curve.
OpenFOAM® Basic Training
Tutorial Ten
1. Pre-processing
$FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily
1.2. 0 directory
Update p, U, nut, nuTilda, k and epsilon files with the new boundary conditions,
e.g. U:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
dimensions [0 1 -1 0 0 0 0];
boundaryField
{
inlet_one
{
type fixedValue;
value uniform (0.1 0 0)
}
inlet_two
{
type fixedValue;
value uniform (-0.2 0 0)
}
outlet
{
type zeroGradient;
}
walls
{
type fixedValue;
value uniform (0 0 0)
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
turbulence on;
printCoeffs on;
viscosityModel Newtonian;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
OpenFOAM® Basic Training
Tutorial Ten
vertices
(
(0 4 0) // 0
(0 3 0) // 1
(3 3 0) // 2
(3 0 0) // 3
(4 0 0) // 4
(4 3 0) // 5
(7 3 0) // 6
(7 4 0) // 7
(4 4 0) // 8
(3 4 0) // 9
(0 4 1) // 10
(0 3 1) // 11
(3 3 1) // 12
(3 0 1) // 13
(4 0 1) // 14
(4 3 1) // 15
(7 3 1) // 16
(7 4 1) // 17
(4 4 1) // 18
(3 4 1) // 19
);
blocks
(
hex (0 1 2 9 10 11 12 19) (10 30 10) simpleGrading (1 1 1)
hex (9 2 5 8 19 12 15 18) (10 10 10) simpleGrading (1 1 1)
hex (8 5 6 7 18 15 16 17) (10 30 10) simpleGrading (1 1 1)
hex (2 3 4 5 12 13 14 15) (30 10 10) simpleGrading (1 1 1)
);
boundary
(
inlet_one
{
type patch;
faces
(
(0 10 11 1)
);
}
inlet_two
{
type patch;
faces
(
(7 6 16 17)
);
}
outlet
{
type patch;
faces
(
(4 3 13 14)
);
}
walls
{
type wall;
faces
(
OpenFOAM® Basic Training
Tutorial Ten
(0 1 2 9)
(2 5 8 9)
(5 6 7 8)
(2 3 4 5)
(10 19 12 11)
(19 18 15 12)
(18 17 16 15)
(15 14 13 12)
(0 9 19 10)
(9 8 18 19)
(8 7 17 18)
(2 1 11 12)
(3 2 12 13)
(5 4 14 15)
(6 5 15 16)
);
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
In the controlDict file, remove the functions sections; this is the inline post-
processing function, for extracting the streamlines along the defined line (which
is not valid for this tutorial):
functions
{
#includeFunc streamlinesLine
(
funcName=streamlines,
start=(-0.0205 0.001 0.00001),
end=(-0.0205 0.0251 0.00001),
nPoints=10,
fields=(p k U)
)
#includeFunc writeObjects(kEpsilon:G)
}
2. Running simulation
>blockMesh
>simpleFoam
Wait for simulation to converge. After convergence, check the results to make
sure about physical convergence of the solution.
OpenFOAM® Basic Training
Tutorial Ten
>foamToVTK
The simulation results are as follows (results are on the cut plane in the middle):
3. RTD calculation
$FOAM_TUTORIALS/basic/scalarTransportFoam/pitzDaily
3.2. 0 directory
Delete the U file and replace it with the calculated velocity field from the first
part of the tutorial (use the latest time step velocity field from previous part of
simulation to calculate RTD for this geometry). There is no need to modify or
change it. The solver will use this field to calculate the scalar transportation.
Update T (T will be used as an inert scalar in this simulation) file boundary
conditions to match new simulation boundaries, to calculate RTD of the
inlet_one set the internalField value to 0, T value for inlet_one to 1.0
and T value for inlet_two to 0.
>blockMesh
>scalarTransportFoam
OpenFOAM® Basic Training
Tutorial Ten
>foamToVTK
5. Post-processing
>foamToVTK
Load the outlet VTK file into paraview using following path:
File > Open > VTK > outlet > outlet_..vtk > OK > Apply
Select T from variables menu, and then integrate the variables on the outlet:
Filters > Data Analysis > Integrate Variables > Apply
The values given in the opened window are integrated values in this specific
time step. By changing the time step values for different time steps are
displayed. As mentioned before, the average value of the property is needed.
Therefore, these values should be divided by outlet area to get average values
(1m 1m).
After finishing the RTD calculations for inlet_one, the same procedure should
be followed for calculating RTD of inlet_two, except T value for inlet_one
should be 0 and for inlet_two it should be 1.0.
OpenFOAM® Basic Training
Tutorial Ten
The average value of T for each outlet approaches a certain constant value,
which is the ratio of that scalar mass inlet to the whole mass inlet. For plotting
data over time “Plot Selection Over Time” option in ParaView can be used, in
the opened SpreadSheetView window (IntegrateVariables) select the set of
data which you want to plot over time and then:
Filters > Data Analysis > Plot Selection Over Time > Apply
Next, to obtain the RTD plots, export the data to a spreadsheet program (e.g.
Excel), calculate and plot the gradient of changes in average value of T on the
outlet from time 0 to 120s for both inlets.
OpenFOAM® Basic Training
Tutorial Ten
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Eleven
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Eleven
Background
There are two common approaches in modeling reactions:
Tutorial Eleven
Tutorial Eleven
reactingFoam – reactingElbow
Tutorial outline
Use the reactingFoam solver; simulate combustion of CH4 and O2 in a mixing
elbow:
• Use the two times finer Hex mesh from Example One
• Domain initially filled with N2
• velocity-inlet-5:
- Velocity: 1 m/s
- Mass fractions: 23 % O2, 77 % N2
- Temperature: 800 K
• velocity-inlet-6:
- Velocity: 3 m/s
- Mass fractions: 50 % CH4, 50 % N2
- Temperature: 293 K
• Operating pressure: 105 Pa
• Operating temperature: 298 K
• Isolated walls
Objectives
• Understanding multi-species and reaction modeling in OpenFOAM®
Data processing
Evaluate your results in ParaView.
OpenFOAM® Basic Training
Tutorial Eleven
1. Pre-processing
$FOAM_TUTORIALS/combustion/reactingFoam/laminar/counterFl
owFlame2D
Copy the GAMBIT® mesh from Tutorial One (two times finer mesh) to the case
main directory.
1.2. 0 directory
Update all the files in 0 directory with new boundary conditions, e.g. U:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
dimensions [0 1 -1 0 0 0 0];
boundaryField
{
wall-4
{
type fixedValue;
value uniform (0 0 0);
}
velocity-inlet-5
{
type fixedValue;
value uniform (1 0 0);
}
velocity-inlet-6
{
type fixedValue;
value uniform (0 3 0);
}
pressure-outlet-7
{
type zeroGradient;
}
wall-8
{
type fixedValue;
value uniform (0 0 0);
}
frontAndBackPlanes
{
type empty;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
The reaction taking place in this simulation CH4 combusting with O2 creating
CO2 and H2O. N2 is the non-reacting species. The boundary conditions and
OpenFOAM® Basic Training
Tutorial Eleven
initial value of all species should be defined in the 0 directory. These values are
mass fractions (between 0 and 1) and dimension less, e.g. CH4:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
boundaryField
{
wall-4
{
type zeroGradient;
}
velocity-inlet-5
{
type fixedValue;
value uniform 0; //no CH4 at this inlet
}
velocity-inlet-6
{
type fixedValue;
value uniform 0.5; //50% CH4 mass fraction at this inlet
}
pressure-outlet-7
{
type zeroGradient;
}
wall-8
{
type zeroGradient;
}
frontAndBackPlanes
{
type empty;
}
}
// ************************************************************************* //
Note: If the file for a species does not exist in the 0 directory, the values from
Ydefault will be used for that species.
inertSpecie N2;
#include "thermo.compressibleGas"
OpenFOAM® Basic Training
Tutorial Eleven
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
The mixture type is set to a multi-component mixture for calculating the mixture
properties and the heat capacities are calculated using “janaf polynomials”.
N2 is defines as inertSpecie. In reaction solvers in OpenFOAM® the inert
specie is calculated explicitly using the mass balance equation (to satisfy mass
conservation):
𝑚𝑎𝑠𝑠 𝑓𝑟𝑎𝑐𝑡𝑖𝑜𝑛 𝑜𝑓 𝑖𝑛𝑒𝑟𝑡 𝑠𝑝𝑒𝑐𝑖𝑒 = 1 − ∑ 𝑚𝑎𝑠𝑠 𝑓𝑟𝑎𝑐𝑡𝑖𝑜𝑛 𝑜𝑓𝑎𝑙𝑙 𝑜𝑡ℎ𝑒𝑟 𝑠𝑝𝑒𝑐𝑖𝑒𝑠
O2
{
specie
{
molWeight 31.9988;
}
thermodynamics
{
Tlow 200;
OpenFOAM® Basic Training
Tutorial Eleven
Thigh 5000;
Tcommon 1000;
highCpCoeffs ( 3.69758 0.00061352 -1.25884e-07 1.77528e-11 -
1.13644e-15 -1233.93 3.18917 );
lowCpCoeffs ( 3.21294 0.00112749 -5.75615e-07 1.31388e-09 –
8.76855e-13 -1005.25 6.03474 );
}
transport
{
As 1.67212e-06;
Ts 170.672;
}
}
…
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
application reactingFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 120;
deltaT 1e-6;
writeControl adjustableRunTime;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
adjustTimeStep yes;
maxCo 0.4;
OpenFOAM® Basic Training
Tutorial Eleven
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
2. Running simulation
>fluentMeshToFoam fineHex.msh
After converting the mesh, check the boundary file in the constant/polyMesh
directory and change the type and inGroups of boundary
frontAndBackPlanes from wall to empty (it is a 2D simulation).
>reactingFoam
>foamToVTK
3. Post-processing
The simulation results at 120 s are as follows:
OpenFOAM® Basic Training
Tutorial Eleven
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Twelve
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Twelve
Background
In this tutorial, we will familiarize ourselves with the snappyHexMesh tool in
OpenFOAM®. This utility generates 3D meshes containing hexahedra and split-
hexahedra. We will also introduce different types of meshes with complex
geometries and compare the snappyHexMesh tool with other mesh generation
tools.
2.1. GAMBIT®
GAMBIT® is a 3D unstructured tool, to specify the meshing scheme in it, two
parameters must be specified:
OpenFOAM® Basic Training
Tutorial Twelve
Elements
Type
The Elements parameter defines the shape(s) of the elements that are used to
mesh the object. The Type parameter defines the pattern of mesh elements on
the object. It has a single graphical user interface which brings geometry
creation and meshing together in one environment.
2.2. snappyHexMesh
In contrast to GAMBIT®, which incorporates both mesh generation and
refinement, the snappyHexMesh tool built within OpenFOAM® requires an
existing geometry base mesh to work with. The base mesh usually comes from
the blockMesh tool. This utility has the following key features:
allow parallel execution to speed up the process
supports geometry data from STL/OBJ files
addition of internal and wall layers
zonal meshing
The key steps involved when running snappyHexMesh are:
Castellation: The cells which are beyond a region set by a predefined
point are deleted
Snapping: Reconstructs the cells to move the edges from inside the
region to the required boundary
Layering: Creates additional layers in the boundary region.
The advantages of snappyHexMesh over the other mesh generation tools are
as follows:
No commercial software package is ultimately necessary. For the
meshing, the OpenFOAM® environment is sufficient and no further
software is necessary.
The geometry can be created with any CAD program like CATIA ®,
FreeCAD, etc. As the geometry is to be only surface data, the files need
to be in .stl, .nas or .obj. format.
The meshing process can be run in parallel mode. If high computational
capabilities are available, high quality meshes can be generated in little
time.
2.3. cfMesh
cfMesh is an open-source library for mesh generation implemented within the
OpenFOAM® framework (similar to snappyHexMesh). Currently cfMesh is
capable of producing mesh of Cartesian type in both 2D and 3D, tetrahedral
and polyhedral types.
OpenFOAM® Basic Training
Tutorial Twelve
The fundamental work-flow of the tool starts from a mesh template, then
followed by a mesh modifier. The modifier allows for efficient parallelization
using shared memory parallelization (SMP) and distributed memory
parallelization using MPI.
OpenFOAM® Basic Training
Tutorial Twelve
snappyHexMesh – flange
Tutorial outline
The procedure described in this tutorial is structured in the following order:
• Creation of the geometry data
• Meshing a geometry with one single region
• Run an OpenFOAM® simulation with the generated mesh using
scalarTransportFoam
Objectives
• The aim of the tutorial is to introduce single region meshing with the
meshing tool snappyHexMesh
• Understanding the advantages of snappyHexMesh
• Understanding the three basic steps of snappyHexMesh
Data processing
Import your simulation to ParaView and analyze the heat distribution in the
flange.
OpenFOAM® Basic Training
Tutorial Twelve
1. Pre-processing
$FOAM_TUTORIALS/mesh/snappyHexMesh/flange
$FOAM_TUTORIALS/resources/geometry/flange.stl.gz
Tutorial Twelve
with snappyHexMesh on these edges. All edges are marked, whose adjacent
surfaces normal are at an angle less than the angle specified in includedAngle
in the surfaceFeaturesDict. The extracted edges are written to
“*.extendedFeatureEdgeMesh” files in constant/extendedFeatureEdgeMesh
folder to be treated later in the meshing process.
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
Surfaces (“flange.stl”);
includedAngle 150;
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
Tutorial Twelve
1.4.1. CASTELLATING
In the castellating step based on the settings in the snappyHexMeshDict file the
created background mesh (in this case using blockMesh) cells are cut into sub-
cells and the unneeded part of the mesh will be deleted. The background mesh
is known as mesh “level 0”, by setting the “level” to 1 the background mesh at
the position of features or defined refinements will be cut into half in each
direction (creating 8 sub-cells for a 3D mesh). Therefor by each level of
refinement number of cells increases by factor 8!
features
(
{
file "flange.extendedFeatureEdgeMesh";
level 0;
OpenFOAM® Basic Training
Tutorial Twelve
}
);
refinementSurfaces
{
flange
{
level (2 2);
}
}
resolveFeatureAngle 30;
refinementRegions
{
refineHole
{
mode inside;
levels ((1E15 3));
}
locationInMesh (-9.23149e-05 -0.0025 -0.0025);
allowFreeStandingZoneFaces true;
}
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
Note: The locationInMesh point should never be on a face of the mesh, even
after refinement. It should always be inside a cell or the meshing will fail!
In the castellated step, the background mesh will be refined based on the
defined refinement levels at features, surfaces or regions and the unneeded
part of the mesh will be removed.
1.4.2. SNAPPING
Important parameters are number of mesh displacement iterations,
nSolveIter and the number of feature edge snapping iterations,
nFeatureSnapIter.
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
snapControls
{
nSmoothPatch 3;
tolerance 1.0;
nSolveIter 300;
nRelaxIter 5;
nFeatureSnapIter 10;
implicitFeatureSnap false;
explicitFeatureSnap true;
multiRegionFeatureSnap true;
}
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
1.4.3. LAYERING
The label for the layering is equal to the labeling of the Boundary surface in the
boundary file in the constant/polyMesh folder.
- nSurfaceLayers defines the number of surface layers
- expansionRatio defines the expansion ratio of the surface layers
- finalLayerThickness and minThickness define the min and the final
thickness of the surface layers
OpenFOAM® Basic Training
Tutorial Twelve
finalLayerThickness 0.3;
minThickness 0.25;
nGrow 0;
featureAngle 30;
nRelaxIter 5;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter 50;
nRelaxedIter 20;
}
meshQualityControls
{
#include "meshQualityDict"
relaxed
{
maxNonOrtho 75;
}
nSmoothScale 4;
errorReduction 0.75;
}
writeFlags
(
scalarLevels
layerSets
layerFields
);
mergeTolerance 1e-6;
// * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * //
Note: Only the relevant changes, which were used in the sample flange case,
are commented in the snappyHexMeshDict.
2. Running snappyHexMesh
The background mesh is created with the following command:
>blockMesh
According to the settings in the blockMeshDict, the mesh was created with 20
cells in x direction, 16 cells in y direction and with 12 cells in z direction.
OpenFOAM® Basic Training
Tutorial Twelve
>surfaceFeatures
>snappyHexMesh
Note: The meshing process with snappyHexMesh can also be run in parallel.
To run the command on several processors, refer to Tutorial Eight for more
information.
The command snappyHexMesh creates a folder with the mesh files for each
mesh step. If, for example, in the snappyHexMeshDict, only castellatedMesh
is set to true and snap and addLayers are set to false, only one folder is created.
If also snap is set to true, 2 folders are created and if also addLayers is set to
true, 3 folders with 3 polyMesh folders are created.
Tutorial Twelve
>snappyHexMesh –overwrite
>foamToVTK
Simply change the time in Paraview to see the effect of snappyHexMesh steps
on the mesh, i.e. time 1 corresponds to the mesh after castellating step, time 2
for the mesh after snapping step, time 3 for the mesh after the layering step.
Tutorial Twelve
Tutorial Twelve
>checkMesh
4. Running simulation
$FOAM_TUTORIALS/basic/scalarTransportFoam/pitzDaily
The flange mesh files need to be transferred to the running case directory. To
achieve this, copy the polyMesh folder from the latest time step file of the flange
folder into the constant directory of the pitzDaily folder. If the overwrite function
is activated when running snappyHexMesh, copy the polyMesh folder from
constant directory of the flange folder.
boundaryField
{
flange_patch1
{
type fixedValue;
value uniform 350;
}
OpenFOAM® Basic Training
Tutorial Twelve
flange_patch2
{
type fixedValue;
value uniform 293;
}
flange_patch3
{
type fixedValue;
value uniform 293;
}
flange_patch4
{
type fixedValue;
value uniform 350;
}
}
- Update the U file in the 0 directory so that the velocity in the entire flange
domain and at the boundaries is zero
- Update the controlDict file in the system directory by changing the endTime
to 0.0005, deltaT to 0.000001 and writeInterval to 100.
>scalarTransportFoam
4.4. Results
Convert the results to VTK files with
>foamToVTK
OpenFOAM® Basic Training
Tutorial Twelve
0.00004s 0.00005s
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Thirteen
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Thirteen
Background
2. chtMultiRegionFoam solver
This solver is developed to solve heat transfer problems between multiple
regions.
OpenFOAM® Basic Training
Tutorial Thirteen
snappyHexMesh - snappyMultiRegionHeater
Tutorial outline
The procedure described in this tutorial is structured in the following order:
• Creation of the geometry data
• Tutorial on Meshing a geometry with more than one region
• Run an OpenFOAM® simulation with the generated mesh using
chtMultiRegionFOAM
Objectives
• Understanding multi region meshing with the meshing tool
snappyHexMesh
Data processing
Import your simulation to ParaView. Analyze the flow field through the flange
and the heat distribution in the flange.
OpenFOAM® Basic Training
Tutorial Thirteen
1. Pre-processing
https://github.com/OpenFOAM/OpenFOAM-
5.x/tree/master/tutorials/heatTransfer/chtMultiRegionFoam/snappyMultiRegionHeater
Either by creating the folders and then downloading the files and place them in
relevant folders or using following webpage:
https://download-directory.github.io/
Rename the constant/triSurface directory to constant/geometry directory. In the
system directory, change the name of surfaceFeatureExtractDict to
surfaceFeaturesDict.
1.2. 0 directory
Unlike the single region simulations in the 0 directory an individual folder per
region exist which stores the files including initial and boundary conditions for
that region. Also in the 0 directory some files exists which are just dummy files
that will not be used in the simulations. The initial and boundary conditions for
each region are changed and updated using the changeDictionary utility, which
will be explained later.
thermoType
{
type heSolidThermo;
mixture pureMixture;
transport constIsoSolid;
thermo eConst;
equationOfState rhoConst;
OpenFOAM® Basic Training
Tutorial Thirteen
specie specie;
energy sensibleInternalEnergy;
}
mixture
{
specie
{
molWeight 12;
}
transport
{
kappa 80;
}
thermodynamics
{
Hf 0;
Cv 450;
}
equationOfState
{
rho 8000;
}
}
// ************************************************************************* //
Tutorial Thirteen
Note: For running the simulations in parallel, the decomposeParDict files for all
the regions should have the same settings as the main one in the system
directory. This is not valid for parallel meshing using snappyHexMesh while it
just uses the decomposeParDict file in the main system directory.
Update the surfaceFeaturesDict file as following:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //
// ************************************************************************* //
The files needed for creating a multi-region mesh are the same as the mesh for
single-region, except for slight differences in snappyHexMeshDict file:
locationInMesh: In a multi-region mesh this point is not used but it should be
defined just as a place holder.
refinementSurfaces: Different regions are defined in here. E.g. for the
region BottomAir all the faces and cells inside the bottomAir stl (each region stl
should be a closed volume) file are marked with bottomAir flag (in faceZone
and cellZone).
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *//
castellatedMeshControls
{
maxLocalCells 100000;
maxGlobalCells 2000000;
minRefinementCells 10;
nCellsBetweenLevels 2;
features
(
{
file "bottomAir.eMesh";
level 1;
}
…
{
file "topAir.eMesh";
level 1;
}
);
refinementSurfaces
{
bottomAir
{
level (1 1);
faceZone bottomAir;
cellZone bottomAir;
cellZoneInside inside;
}
OpenFOAM® Basic Training
Tutorial Thirteen
…
rightSolid
{
level (1 1);
faceZone rightSolid;
cellZone rightSolid;
cellZoneInside inside;
}
}
resolveFeatureAngle 30;
refinementRegions
{
}
locationInMesh (0.01 0.01 0.01);
allowFreeStandingZoneFaces false;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *//
After creation of the mesh and splitting to different regions, the initial and
boundary conditions for each region can be manually set in the relevant region
folders in 0 directory. This process can be also automated using the
changeDictionary utility. The dictionary file for this utility for each region is in the
relevant region folder in the system directory: changeDictionaryDict.
See below the changeDictionaryDict file for the heater region. In the boundary
sub-dictionary type of boundaries for minY, MinZ and maxZ are set to patch.
Then for T the internal field will be overwritten with uniform 300. In the next
step all the boundaries in the T file for heater region will be set to zeroGradient
(“.*” means all the boundaries with any name) and after that the bounadries
with the name “heater_to_.*” will be changed to
turbulentTemperatureCoupledBaffleMixed and minY will be changed to
fixedValue.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * *//
boundary
{
minY
{
type patch;
}
minZ
{
type patch;
}
maxZ
{
type patch;
}
}
T
{
internalField uniform 300;
boundaryField
{
“.*”
{
type zeroGradient;
value uniform 300;
}
OpenFOAM® Basic Training
Tutorial Thirteen
“heater_to_.*”
{
type compressible::turbulentTemperatureCoupledBaffleMixed;
Tnbr T;
knappaMethod solidThermo;
value uniform 300;
}
minY
{
type fixedValue;
value uniform 500;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * *//
to
#includeEtc “caseDicts/mesh/generation/meshQualityDict.cfg”
Note: Add the missing “;” to the fvSolution files for bottomAir and topAir regions:
“(rho|rhoFinal)”
{
solver PCG;
preconditioner DIC;
tolerance 1e-7;
relTol 0;
}
>blockMesh
Equal to the single region case, the command surfaceFeatures creates the
eMesh files from the stl files with the geometry data. Also the folder
extendedFeatureEdgeMesh is created in the constant directory. The creation
of eMesh files with the command surfaceFeatures is not obligatory. This step
is only necessary, if certain edges need to be refined.
>surfaceFeatures
OpenFOAM® Basic Training
Tutorial Thirteen
>decomposePar
>reconstructParMesh –constant
After this step, all the regions are meshed but the meshes are connected and
needs to be split. In the meshing step each region cells are marked with a flag
and this flag will be used in the next step to split the mesh. Mesh regions can
be split using the following command which split the mesh based on the flagged
cellZones and overwrite the old meshes in the polyMesh directories in the
region folders (if any exist):
With the mesh ready, the next step is to apply appropriate field values to each
region, according to the changeDictionaryDict. This command needs to be
repeated for each region, with the name of the region specified after the prefix
‘–region’.
Tutorial Thirteen
>chtMultiRegionFoam
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Tutorial Fourteen
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Tutorial Fourteen
Background
1. Introduction to sampling
This tutorial is an introduction to the OpenFOAM® sampling utility. With this
utility, one can extract sample data from certain selected surfaces or points in
ones simulation after or while running the simulation. If data is sampled while
running one can use sampling to observe the progress of the simulation and
the correctness of the solution without even reaching a write-interval.
Using a sample file in the system directory data can be sampled after the
simulation or by adding the needed functions to the controlDict it can be done
while running a simulation.
At the beginning of this tutorial the implementation for sampling using the
sample and the controlDict will be introduced and afterwards the different
sampling options in OpenFOAM® will be discussed.
OpenFOAM® Basic Training
Tutorial Fourteen
rhoPimpleFoam – shockTube
Tutorial outline
Simulate the flow along a shock tube for 0.007 s and use OpenFOAM ® sampling
utility for extracting the data along a line during the simulation and after the
simulation.
Objectives
• Understand the function of sampling and how to use the sampling utility
Data processing
Import your simulation to ParaView to visualize it and analyze the extracted
data with sampling tool.
OpenFOAM® Basic Training
Tutorial Fourteen
1. Pre-processing
$FOAM_TUTORIALS/compressible/rhoPimpleFoam/laminar/shockT
ube
type sets;
libs (“libsampling.so”)
interpolationScheme cellPoint;
setFormat raw;
sets
(
data
{
type lineUniform;
axis x;
start (-4.995 0 0);
end (4.995 0 0);
nPoints 1000;
}
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
In the type the type of data to be sampled is defined, e.g. sets or surfaces.
The different options for interpolationScheme and setFormat will be
discussed in a later section.
In the sets sub-dictionary each set of data should be given a name, which is
freely chosen by the user, in this case the name is simply ‘data’. In the bracket
for the set of data, we need to specify the following criteria:
- type: specifies the method of sampling. Here uniform was chosen to
make a sample on a line with equally distributed number of points.
- axis: to define how the point coordinates are written. In this case, x
means that only the x coordinate for each point will be written.
- Start/end: the endpoints of the line-sample are defined
- nPoints: number of points on our line
OpenFOAM® Basic Training
Tutorial Fourteen
Outside of the data and sets bracket in the fields we have to define which
fields we want to sample.
1.2.2. controlDict
To have the option to sample for each time step instead of each write-interval
or sampling while the solver is running; instead of the sample dictionary
additions in the controlDict are needed.
In this part one will change the controlDict of the shockTube tutorial so that our
line- sampling from before will be executed while running, and per time step.
Add the following code to the end of the function sub-dictionary in the
controlDict.
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * *//
…
functions
{
#includeFunc mag(U)
linesample
{
type sets;
functionObjectLibs (“libsampling.so”);
writeControl timeStep;
outputInterval 1;
interpolationScheme cellPoint;
setFormat raw;
sets
(
data
{
type uniform;
axis x;
start (-4.995 0 0);
end (4.995 0 0);
nPoints 1000;
}
);
linesample sub-dictionary includes the settings for the sampling tool. Any
arbitrary name can be chosen instead of linesample. The chosen name will
be the name of the folder in the postProcessing directory after running the
solver.
Inside our linesample sub-dictionary:
- type: sets or surfaces can be chosen. More types will be covered in a
later section.
- functionObjectLibs: provides the operations needed for the sampling
tasks.
OpenFOAM® Basic Training
Tutorial Fourteen
>blockMesh
>setFields
>sonicFoam
3. Post-processing
After sonicFoam solver finishes running, based on your sampling approach the
following steps should be performed:
A new folder will appear in your case directory named postProcessing and in it
a folder named sample. In this folder all the sampling data will be stored in
separate folders for each write-interval.
3.2. controlDict
The postProcessing directory and all its subdirectories have been generated
after the first time step. Now it can be seen that for every time step a folder is
generated instead of only every write interval.
OpenFOAM® Basic Training
Tutorial Fourteen
4.1. sets
All sets need a setFormat, for example csv, which needs to be included after
the interpolationScheme.
After that the sets sub-dictionary begins where a bracket with an arbitrary name
begins in which the sets sampling type and the geometrical location of the
sampling points will be chosen. In the following, a few of sampling types will be
discussed.
4.1.1. lineUniform
This one was used in the above example. A line from a start point to an end
point with a fixed number of points evenly distributed along it.
OpenFOAM® Basic Training
Tutorial Fourteen
axis determines what is written for the point coordinate in the output file.
distance means it will only write the distance between sampled point and start
point in the file.
lineX1
{
type lineUniform;
axis distance;
4.1.2. face
This type also samples along a line from a defined start to endpoint, but only
writes in the log file for every face the line cuts.
lineX2
{
type face;
axis x;
4.1.3. cloud
The cloud type samples data at specific points defined in the point’s bracket.
somePoints
{
type cloud;
axis xyz;
points ((0.049 0.049 0.00501)(0.051 0.049 0.00501));
}
4.1.4. patchSeed
The patchSeed sampling type is used for sampling patches of the type wall.
One can for example sample the surface adsorption on a wall with this type.
patchSeed
{
type patchSeed;
axis xyz;
patches (".*Wall.*");
maxPoints 100;
}
Please note that for patches only a patch of type wall can be used. If you choose
a wrong type, nothing will be sampled and you receive no error message.
4.2. surfaces
All surfaces need a surfaceFormat specified. Practical formats would be the
vtk format, which can be opened with paraview, and the raw format, which can
be used for gnuplots. Instead of the sets bracket now a surfaces bracket must
be used and the type is of course surfaces. Inside the surfaces brackets one
can now sample an arbitrary number of surfaces, each in its own inner brackets.
The different types of surface sampling like the plane in the example below will
be discussed in the next sections.
OpenFOAM® Basic Training
Tutorial Fourteen
type surfaces;
interpolationScheme cellPoint;
surfaceFormat vtk;
fields
(
U
);
surfaces
(
yoursurfacename
{
type plane;
basePoint (0.1 0.1 0.1);
normalVector (0.1 0 0);
triangulate false;
}
);
4.2.1. plane
The type plane creates a flat plane with an origin in the basePoint normal to
the normalVector. This normalvector starts in the origin, not in the
basePoint. To turn the triangulation of the surface off one has to add
triangulate false.
constantPlane
{
type plane; // always triangulated
basePoint (0.0501 0.0501 0.005);
normalVector (0.1 0.1 1);
One can also set a new origin for the basePoint and normalVector with
coordinateSystem
{
origin (0.0501 0.0501 0.005);
}
4.2.2. patch
A sampling of type patch can sample data on a whole patch. Please note that
while the syntax looks the same as in the patchSeed case, also patches that
are not of type wall work. Default option will triangulate the surface; this can be
turned off with triangulate false.
walls_interpolated
{
type patch;
patches ( ".*Wall.*" );
//interpolate true;
// Optional: whether to leave as faces (=default) or triangulate
// triangulate false;
}
4.2.3. patchInternalField
OpenFOAM® Basic Training
Tutorial Fourteen
Similar to the patch type, this type needs a patch on which it samples. It will
sample data that’s a certain distance away in normal direction ( offsetMode
normal). There is also the option to define the distance in other ways seen in
the commented section of the code.
Note: While the sampling happens not on the patch but a distance away from
it, the geometric position of the sampled values in the output file will be written
as the position of the patch.
Once again the default triangulation can be turned off with triangulate false.
nearWalls_interpolated
{
// Sample cell values off patch.
// Does not need to be the near-wall
// cell, can be arbitrarily far away.
type patchInternalField;
patches ( ".*Wall.*" );
interpolate true;
4.2.4. triSurfaceSampling
With the triSurfaceSampling type data can be sampled in planes which are
provided as a trisurface stl file. To create such a file one can use the command
below. The command will generate a .stl file of one (or more) of your patches.
Here your patch needs to be replaced with the name of one of your patches
defined in the constant/polyMesh/boundary file. Starting the command without
the patches option will generate a stl file of your whole mesh boundary. Next
make a directory in the constant folder named triSurface if it does not already
exist and copy the .stl file there. In the code, you now have to specify your stl
file as the surface. For the source, the use of boundaryFaces seems to be a
good option of the stl file is one of your patches.
triSurfaceSampling
{
// Sampling on triSurface
type sampledTriSurfaceMesh;
OpenFOAM® Basic Training
Tutorial Fourteen
surface integrationPlane.stl;
source boundaryFaces;
// What to sample: cells (nearest cell)
// insideCells (only triangles inside cell)
// boundaryFaces (nearest boundary face)
interpolate true;
}
Note: Most CAD software can export the surface of 3D drawings as stl files.
4.2.5. isoSurface
The isoSurface sampling type is quite different to what was discussed before
in this tutorial. Until now, all the sampling types had a constant position in space
and changing field values at that position were extracted. With the isoSurface
sampling, one tracks the position of a defined value in space. The example
below can be copied into the shocktube tutorials sample file (of course, it needs
all the other options needed for surface type sampling).
Using vtk for the surfaceFormat one can visualize the moving shockwave in
space. Note that both the vtk of the sampling and the whole shocktube case
can be opened together in paraview to compare the results.
Note that the isoField needs to be a scalarfield.
interpolatedIso
{
// Iso surface for interpolated values only
type isoSurface;
// always triangulated
isoField p;
isoValue 9e4;
interpolate true;
//zone ABC;
// Optional: zone only
//exposedPatchName fixedWalls;
// Optional: zone only
// regularise false;
// Optional: do not simplify
// mergeTol 1e-10;
// Optional: fraction of mesh bounding box
// to merge points (default=1e-6)
}
4.2.6. isoSurfaceCell
The isoSurfaceCell type is very similar to the one we discussed before, but
this one does not cross any cell with its surface and does not interpolate values.
constantIso
{
// Iso surface for constant values.
// Triangles guaranteed not to cross cells.
type isoSurfaceCell;
// always triangulated
isoField rho;
isoValue 0.5;
interpolate false;
regularise false;
// do not simplify
// mergeTol 1e-10;
// Optional: fraction of mesh bounding box
// to merge points (default=1e-6)
}
Appendix A
Linux Commands
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Appendix A
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Appendix A
cat, more, less File viewer with pure read function - in order of ease of operation. In less with
pagedown/pageup you can navigate within the file, with / and ? can look for
strings, q can be used for closing less. cat is back for universally available on
Unix.
cd, cd .. Changing the directory, cd .. goes one directory up and cd ~ moves to home
directory. Important to note is the space between cd and .. as opposed to DOS!
cp, cp -r Copying files or entire directory trees (with -r option). Caution: There is no
warning or prompt when overwriting existing files! The important thing is that a
target has to be always given, at least one . which means, copy to the current
directory.
ctrl+r Reverse search, for searching an already typed command in a terminal window.
du, du -s, Calculates the amount of space consumed in a directory. For safety reasons you
should use the -k option (output in kilobytes), since some systems provide the
du -k
space in blocks that include only 512 bytes ...
gedit Text editor with graphical user interface. When working with gedit some
temporary files (originalFileName~) are created, they can be deleted after
saving.
grep Search command for plain-text data sets for lines matching a regular expression.
kill, kill -9 Stopping processes. For this the process ID is required, which can be found with
top or ps. The Exit is irrevocable course - but you cannot shoot processes, if
you are not the "owner".
ls, ls –la Lists the contents of a directory, with option -la also hidden files are displayed,
as well as the file size and characteristics.
Appendix A
Nano, pico The command to run the nano text editor, a terminal based text editor.
| It is known as pipe and is used for merging two commands, redirecting one
command as input to another, e.g. less|grep searches a specified word in the
output of file opened with less.
ps, ps –A Lists all the processes that were started in the respective command window with
the options are all running processes on the system display.
ps waux
rm, CAUTION: Deletes files. The option -r will also remove directories and files recursively and
rm -fr delete directories, f (force) prevents any further inquiry. - Incorrectly applied, this
command can lead to irreversible loss of all (private) data. There is no undelete
or undo!
scp The copy command over the network - as secure FTP replacement. Also
dominates the -r (recursive) option. Usage: scp source file destination file with
source and the destination format can be USERNAME@
COMPUTER.DOMAIN:PATH/TO/FILE. Source or target can of course also be
created locally, then (your) user name and computer are not required.
tail, tail -f File viewer, the default outputs the last 10 lines of a file. With option -n XX can
spend the last XX lines, with the -f option, the command is running from those
lines, which are attached to a file. The command is therefore perfect for watching
log files.
OpenFOAM® Basic Training
Appendix A
top Displays a constantly updated list of all running processes, with process ID,
memory and CPU usage. For processes of one user top [username] should be
used, and for quitting q or ctrl+c should be applied.
vi, vim File editor. For forward searching use /, for backward searching use ?. For
exiting esc+:x. nano or pico are recommended for beginners, which are easier
to handle.
Appendix B
Running OpenFOAM®
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Appendix B
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Appendix B
>. ./bashrc
2.1. Windows:
Run PuTTY (search for: PuTTY windows).
Set the following:
Category>Session
Category>Connection>Data
1 Display number
2 Session ID
OpenFOAM® Basic Training
Appendix B
your password. The password is not echoed to the screen and the
passwords are case sensitive.
Immediately after entering your password, your computer will attempt to
establish a connection to your server. If it is your first time connecting to
that server, you will see a message asking you to confirm the identity of
the machine. Make sure you entered the address properly, and type
yes, followed by the return key, to proceed.
Change to etc directory in OpenFOAM® installation directory
Execute the following command:
>. ./bashrc
To log out use whatever command is used to logout from the server you
are logged into (typically ctrl + d).
>. ./bashrc
Appendix B
>. ./bashrc
If a new terminal in the VNC desktop is opened, the last two steps should be
done in that to activate OpenFOAM® in there.
Appendix C
Frequently Asked Questions
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Appendix C
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Appendix C
Q- How can I prevent typing long commands in the terminal for couple of times?
By using reverse search, use ctrl+r to search for previous commands typed in the
terminal, e.g. typing a part of command show the suggestions and you can navigate
through them.
A- Use command:
>vncviewer :[NUMBER OF LOCAL PORT, e.g. 1 or 2]
OpenFOAM® Basic Training
Appendix C
A- Make sure OpenFOAM® and ParaView are installed correctly. Check Appendix B for
starting OpenFOAM®.
A- Use command:
>foamToVTK -region[REGION NAME]
A- Yes, by choosing .ogv file format from “file/save animation” menu. The output will be
a video file with .ogv format. In the new ParaView versions (newer than 4.3.0) the
animation can also be saved using .avi format.
A- During creating the geometry in the preprocessing software, e.g. GAMBIT, create
volume zones, which you will need to patch later (see software user manual for
creating regions in each software). For converting the mesh to the OpenFOAM ®
mesh use the appropriate tool with “-writeZones” flag to import zones to
OpenFOAM®, e.g.:
>fluentMeshToFoam -writeZones <your mesh>
regions
(
zoneToCell
{
name air; // region name which you assigned in gambit
fieldValues
(
volScalarFieldValue alpha.water 0 // the value of property
//which you want to patch
);
}
);
Then after running setFields tool, it will assign the values to that region.
OpenFOAM® Basic Training
Appendix C
Q- How can I create a bash scripting file for executing couple of command in series?
Instead of typing command sequences one by one after each other and executing
A-
them. It is possible to put all those commands in a file and execute that file to run
them. This is known as “bash scripting”.
Bash scripting is typically used in the cases when the same simulation should be run
with identical settings a couple of times, but with a few changes. For bash scripting
create an empty file (e.g. using nano editor creating text file “go”):
> nano go
Add the commands to this file (e.g. commands for running blockMesh, setFields,
decomposePar, compressibleInterFoam in parallel mode and reconstructPar):
blockMesh
setFields
decomposePar
mpirun –np 4 compressibleInterFoam –parallel >log
reconstructPar
Exit the editor and save the file (ctrl+x , y, enter for nano editor).
For changing this file to an executable file, file permissions should be set. By using
this command file permissions are displayed:
>ls -la go
After executing the file, the commands added to the file will be executed one by one.
In most of the OpenFOAM® tutorials there are Allrun and Allclean files, which are
bash scripts for running the case and cleaning a case, respectively.
This offering is not approved or endorsed by ESI® Group, ESI-OpenCFD® or the OpenFOAM®
Foundation, the producer of the OpenFOAM® software and owner of the OpenFOAM® trademark.
OpenFOAM® Basic Training
Appendix D
ISBN 978-3-903337-02-2
Publisher: chemical-engineering.at
Available from: www.fluiddynamics.at
OpenFOAM® Basic Training
Appendix D
1. Introduction to ParaView
The post-processing application for OpenFOAM® is ParaView, which is a free,
open source program. In this tutorial, different features and tools available in
ParaView 5.10.1 will be explored.
ParaView Interface
The tree structure (“pipeline”) of ParaView helps the user to easily choose and
display suitable sub-models for creating the desired image or animation. Adding
a mesh or velocity vectors to a contour plot of pressure is an example of this
functionality.
For generation operations, use the OpenFOAM® command foamToVTK to
convert OpenFOAM® files into readable formats for ParaView. Then open the
.vtk file and press the green Apply button in the Properties panel. The reset
button is used for resetting the window and deleting the selected operation.
OpenFOAM® Basic Training
Appendix D
2. ParaView Interface
Properties panel
- Colouring
The drop-down menu for solid colour allows different field variables to be
chosen and viewed, for example, pressure and velocity magnitude.
The Rescale button allows the data range to be adjusted to fit the data, as
sometimes the max/min data range are not updated automatically.
- Scalar Coloring
The ‘Map Scalars’ option allows the scalar values to be mapped to a specific
colour using a lookup table.
Turning the option ‘Interpolate Scalars Before Mapping’ on or off will affect the
way the scalar data is visualized with colours. According to the ParaView
documentation, if it is turned on, scalars will be interpolated within polygons and
colour mapping will happen on a per-pixel basis; if off, color mapping occurs at
polygon points and colors are interpolated, which is generally less accurate[1].
- Styling
The opacity of the image can be set (1 = solid, 0 = invisible) in the Opacity
option.
- Lighting
There are two options for Interpolation, Gouraud or Flat. With Gouraud shading
enabled, normals are defined only per point and no face normal is needed. If
the Interpolation is changed to Flat, only the face normals will be computed and
used for lighting, note that this option is not suitable for objects with smooth
surfaces [2].
OpenFOAM® Basic Training
Appendix D
- Backface Styling
This is an advanced feature in ParaView that enables the backface style of a
wire frame object to be changed.
- Transforming
The Transform filter allows you to translate, rotate and change the size and the
origin of the data sets.
- Miscellaneous
By default ParaView triangulate the cells and shows them as triangles. For
disabling this uncheck the “Triangulate” option in the Miscellaneous section of
the Properties panel.
- Glyph Parameters
The Glyth Parameters filter generates a glyph, which can be arrow, cone, box,
cylinder, line, sphere or a 2D glyph. The glyth is generated at each point in the
input dataset[3]. Depending on the type of glyph chosen, different options are
available to orientate, scale and size the glyph.
- Orientation Axes
The Orientation Axes feature controls an axes icon in the image window (e.g.
to set the color of the axes labels x, y and z).
- Lights
The lighting controls options appear when clicking on the Edit button. For
producing images with strong bright colors (e.g. isosurface) Headlight of
strength 1 is appropriate.
- Background
The background color of the layout can be chosen from the drop-down menu,
with types Single color, Gradient and Image available.
Button toolbars
Pull-down menus at the top of the main window and the major panels, in the
toolbars below the main pull-down menus increase the functionality of
ParaView. The function of each button can be easily understood by its icon,
also any button description can be found in the Help menu (keeping the mouse
over an icon without clicking on it will also give a short explanation on its
functionality).
A feature worth mentioning is the drop-down menu next to the Reset button,
this provides the options of the different ways of presenting the mesh. To see
the structure of the mesh, use Surface with Edges; and to see both the cell
structure and the interior of the mesh, use Wireframe.
OpenFOAM® Basic Training
Appendix D
Appendix D
3.3. Streamlines
To create tracer lines, click on the Stream Tracer button in the Button Toolbars.
Tracer points can be along a line or points, and this can be chosen in the Seed
Type drop-down menu in the Seeds section of the Properties panel. Usually,
some trial and error is needed for achieving the desired streamlines. The length
of steps tracer takes can be changed in the Streamline Parameters section of
the Properties panel. A smaller length increases calculation time but increases
smoothness. For having high quality images Tubes filter can be used after
tracer lines have been created. There are different types of tubes, not only
cylindrical.
Appendix D
can be set, and by locking the aspect ratio, changing image resolution in one
direction cause change in its resolution in the other direction respectively. For
high quality images, a resolution of more than 1000 pixels is a good choice.
Appendix D