OpenFOAM Course PDF
OpenFOAM Course PDF
net/publication/327594760
CITATIONS READS
0 3,522
1 author:
Jibran Haider
Swansea University
9 PUBLICATIONS 18 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Jibran Haider on 12 September 2018.
Jibran Haider
https://www.jibranhaider.weebly.com
12 th September 2018
Disclaimer
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
My background
Course details
OpenFOAM preliminaries
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
My background
Course details
OpenFOAM preliminaries
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
My background
Course details
OpenFOAM preliminaries
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Course details
Objectives
• Introduce the basics of OpenFOAM.
• Signify the advantages of using OpenFOAM.
• Utilise the power of Linux by extensive use of shell commands.
• By the end of the course, candidates should be able to run OpenFOAM simulations.
Desirable traits
• Basic level of programming in C++.
• Familiarization with Linux interface.
• Fundamentals of Computational Fluid Dynamics (CFD).
Outline
1 Introduction
My background
Course details
OpenFOAM preliminaries
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
What is OpenFOAM?
Summary
• An open source software package.
• Released under the GNU General Public License.
• Abbreviation of Open Field Operation And Manipulation.
• An efficient library of C++ modules.
• Based on the cell centered Finite Volume Method.
• Extensive CFD and Multi-physics capabilities.
kC e f k Ω0e
• Cross-platform installation.
e F CN e f
OpenFOAM forks
• OpenFOAM Foundation release (official standard release).
• OpenFOAM + (official development release).
• FOAM-extend (community driven development branch).
This blog post [link] provides plenty of free references available on the web which might be a good
starting point for learning OpenFOAM.
Template metaprogramming
• C++ provides template classes.
• General features of the template class are passed on to any other class created from it.
• This reduces code duplication.
Why OpenFOAM?
Commercial Software
OpenFOAM
(ANSYS, ABAQUS etc.)
1. Cost effectiveness X ×
2. Parallel computing X X
3. Source code X ×
4. Redistribution of code X ×
5. Collaborative development X ×
6. Documentation × X
7. GUI / user friendliness × X
X According to the GNU GPL v3, OpenFOAM is free to download, install, use, modify and distribute.
Development of OpenFOAM
1989 Project was initially started under the title of FOAM at Imperial college, London.
The idea was to create a simulation platform more powerful than FORTRAN. Due
to its object oriented features C++ was chosen as the programming language.
10th Dec 2004 OpenCFD Ltd was founded and first version (v1.0) of OpenFOAM was released
under the GNU GPL license.
8th Aug 2011 OpenCFD was acquired by Silicon Graphics International (SGI).
15th Aug 2012 OpenCFD became a wholly owned subsidiary of ESI group.
th
6 Aug 2018 OpenFOAM v6 was released.
Henry Weller and Hrvoje Jasak are the main initial contributors to its development.
Several developers from all over the globe have contributed to its development.
OPENFOAM
R
is a registered trade mark of OpenCFD Limited, producer and distributor of the
OpenFOAM software.
Simulation workflow
OpenFOAM terminologies
OpenFOAM_terminology
Commands on terminal
<< command_name
FOAM_SOLVERS= / o p t / openfoam6 / a p p l i c a t i o n s / s o l v e r s
FOAM_EXT_LIBBIN = / o p t / T h i r d P a r t y −6/p l a t f o r m s / linux64GccDPInt32 / l i b
FOAM_APPBIN= / o p t / openfoam6 / p l a t f o r m s / linux64GccDPInt32Opt / b i n
FOAM_TUTORIALS= / o p t / openfoam6 / t u t o r i a l s
.....
.....
62 a l i a s s r c = ’ cd $FOAM_SRC ’
63 a l i a s l i b = ’ cd $FOAM_LIBBIN ’
64 a l i a s app= ’ cd $FOAM_APP ’
.....
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Installation directory I
$WM_PROJECT_DIR
1. applications:
applications alias: app = ’cd $FOAM_APP’.
This directory contains the source files of all the
solvers executables created using the C++ libraries. It contains
the following directories:
test
1.1 solvers:
utilities alias: sol = ’cd $FOAM_SOLVERS’.
tutorials Source code to solve a particular continuum
mechanics problem.
src
1.2 test:
bin Sample codes to help understand the usage of
OpenFOAM libraries.
doc
1.3 Utilities:
etc alias: util = ’cd $FOAM_UTILITIES’.
Source code to perform pre- and post-processing
platforms tasks involving data manipulation and algebraic
manipulations.
wmake
Installation directory II
$WM_PROJECT_DIR
applications 2. tutorials:
alias: tut = ’cd $FOAM_TUTORIALS’.
tutorials Contains tutorials that demonstrate the usage of all
solvers and most of the utilities.
src
3. src:
finiteVolume alias: src = ’cd $FOAM_SRC’.
OpenFOAM It contains several subdirectories which include the
source code for all libraries. The important folders are:
turbulenceModels
3.1 finiteVolume:
... alias: foamfv = ’cd $FOAM_SRC/finiteVolume’.
bin Includes classes for finite volume space/time
discretisation, boundary conditions etc.
doc
3.2 OpenFOAM:
etc This core library includes important definitions.
4. bin:
This directory contains shell scripts such as paraFoam,
foamLog etc.
$WM_PROJECT_DIR
5. doc:
applications It contains all the documentation relevant to the version of
OpenFOAM including:
tutorials 5.1 User and Programmer’s guides
5.2 Doxygen generated documentation
src 5.3 OpenFOAM coding style guide
bin 6. etc:
It contains global OpenFOAM dictionaries and setup files.
doc
7. platforms:
etc
The binaries generated during the compilation of the
platforms applications and the dynamic libraries are stored here.
8. wmake:
wmake
Compiler settings are included in this directory including
optimisation flags. It also contains wmake, a special make
command which understands the OpenFOAM file structure.
/ home / j i b r a n / OpenFOAM / j i b r a n −6
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Directory structure
1. appName.C:
Contains the main source code of the application.
2. *.H:
<application>
The necessary header files needed to compile the application.
The solvers include createFields.H file which declares and
appName.C initialises the field variables.
*.H
3. Make:
Make This directory contains the compilation instructions and
includes the following files:
files 3.1 files:
List of source files (*.C) needed to compile the
options
application and the executable name.
3.2 options:
Specifies the directories to search for the included
header files (*.H) and libraries needed to link the
application against.
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
OpenFOAM solvers I
Solver Description
Incompressible flow
Solver Description
OpenFOAM solvers II
Compressible flow
Solver Description
Multiphase flow
Solver Description
Other solvers
Solver Description
icoFoam solver
.....
27 D e s c r i p t i o n
28 T r a n s i e n t s o l v e r f o r i n c o m p r e s s i b l e , l a m i n a r f l o w o f Newtonian f l u i d s .
.....
32 # i n c l u d e " fvCFD . H" / / Header f i l e w i t h a l l t h e FVM machinery
33 # i n c l u d e " p i s o C o n t r o l . H" / / F i l e s d e f i n i n g PISO c o n t r o l s
.....
37 i n t main ( i n t argc , char ∗argv [ ] ) / / Beginning o f t h e main program
38 {
39 # i n c l u d e " setRootCase . H" / / Set path and case d i r e c t o r i e s
40 # i n c l u d e " createTime . H" / / I n i t i a l i s e time v a r i a b l e
41 # i n c l u d e " createMesh . H" / / I n i t i a l i s e t h e mesh t o work w i t h
.....
52 while ( runTime . l o o p ( ) ) / / Time l o o p begins
53 {
.....
115 runTime . w r i t e ( ) ; / / Write r e s u l t s to time d i r e c t o r i e s
.....
120 } / / End t i m e l o o p
121
122 I n f o << " End \ n " << e n d l ;
123
124 return 0;
125 }
.....
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
OpenFOAM utilities I
Utility Description
Utility Description
OpenFOAM utilities II
Utility Description
Post-processing tools
Utility Description
Utility Description
Hands-on training:
Some useful OpenFOAM utilities (See page 91)
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
<tutorial>
constant
1. constant:
This directory contains the information which remains constant
polymesh
throughout the simulation. It contains the following:
... properties
1.2 ... properties:
Files which specify physical properties for a particular
system application eg. gravity, viscosity, thermal properties etc.
2. system:
This directory contains all the parameters associated with the
<tutorial> solution procedure. It contains at least the following files:
U 3. 0:
The ’0’ directory corresponds to zero time. It contains the
initial and boundary conditions for variables (ie. pressure p,
velocity U) in individual files.
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Meshing in OpenFOAM
Using blockMesh
• Simple mesh generator using blocks.
• Allows multiple blocks and curved edges.
• Not suitable to use for complex geometries.
Good practices
• Run ’checkMesh’ utility to monitor mesh quality.
• Check mesh in ParaView before starting the simulation using paraFoam command .
Hands-on training:
Meshing with blockMesh (See page 71)
Meshing with snappyHexMesh (See page 118)
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Procedure
• Copy a suitable tutorial (alias: tut) to your run directory (alias: run).
<< cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity/cavity $FOAM_RUN
• Understand the inputs of the solver by reading the dictionaries of the tutorial.
• Modify the tutorial accordingly including geometry, meshing and problem setup.
{
..... / / Keyword e n t r i e s
}
L i s t <Type> / / Type o f l i s t
<n> / / L i s t size
(
..... / / List entries
);
Initial conditions
Initial conditions must be specified for all variables inside ’0’ directory.
.....
17 dimensions [ 0 1 −1 0 0 0 0 ] ; / / Dimensions i n SI base u n i t s [ kg m s K mol A cd ]
18
19 i n t e r n a l F i e l d uniform (0 0 0) ; / / C e l l values
.....
Boundary conditions I
• Boundary conditions must also be specified for all variables inside ’0’ directory.
• Geometry is broken down into patches where boundary conditions are applied.
.....
21 b o u n d a r y F i e l d / / D i c t i o n a r y t o s p e c i f y boundary c o n d i t i o n s
22 {
23 movingWall / / Boundary patch name
24 {
25 type fixedValue ; / / Boundary c o n d i t i o n t y p e
26 value uniform (1 0 0) ; / / Boundary v a l u e s
27 }
28
29 fixedWalls
30 {
31 type noSlip ;
32 }
33
34 frontAndBack
35 {
36 type empty ; / / Boundary c o n d i t i o n t y p e f o r 2D s i m u l a t i o n s
37 }
38 }
.....
Boundary conditions II
• groovyBC library developed by B. Gschaider could be utilised without the need for programming.
• Custom boundary conditions can be programmed.
Time controls
controlDict dictionary
<< cat $FOAM_RUN/cavity/system/controlDict
Solver controls I
fvSchemes dictionary
<< cat $FOAM_RUN/cavity/system/fvSchemes
18 ddtSchemes
19 {
20 default Euler ; / / Time d i s c r e t i s a t i o n schemes
21 }
23 gradSchemes / / G r a d i e n t e v a l u a t i o n schemes
24 {
25 default Gauss l i n e a r ;
26 grad ( p ) Gauss l i n e a r ;
27 }
29 divSchemes / / D i s c r e t i s a t i o n o f t h e c o n v e c t i v e terms
30 {
31 default none ;
32 d i v ( phi , U) Gauss l i n e a r ;
33 }
35 laplacianSchemes / / D i s c r e t i s a t i o n o f t h e L a p l a c i a n term
36 {
37 default Gauss l i n e a r orthogonal ;
38 }
40 interpolationSchemes / / Method o f i n t e r p o l a t i o n
41 {
42 default linear ;
43 }
45 snGradSchemes / / Surface normal g r a d i e n t scheme
46 {
47 default orthogonal ;
48 }
Solver controls II
fvSolution dictionary
<< cat $FOAM_RUN/cavity/system/fvSolution
18 s o l v e r s
19 {
20 p
21 {
22 solver PCG; / / S o l v e r t o s o l v e t h e system
23 p r e c o n d i t i o n e r DIC ; / / Preconditioner type
24 tolerance 1e−06;
25 relTol 0.05;
26 }
28 pFinal
29 {
30 $p ;
31 relTol 0;
32 }
34 U
35 {
36 solver smoothSolver ;
37 smoother symGaussSeidel ;
38 tolerance 1e−05;
39 relTol 0;
40 }
41 }
42
43 PISO / / PISO c o n t r o l s
44 {
45 nCorrectors 2;
46 nNonOrthogonalCorrectors 0 ;
....
49 }
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Default procedure
• Copy OpenFOAM tutorial to you run directory.
<< cp -r <tutorial_directory> $FOAM_RUN
<< cd <tutorial_name>
Hands-on training:
Two phase flow problem (See page 82)
Outline
1 Introduction
3 OpenFOAM simulations
Tutorial directory structure
Meshing
Problem setup
Solving
Post-processing
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
ParaView toolbars
Main controls VCR controls Time controls
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Basic classes
X Basic classes in OpenFOAM have been derived from more fundamental C++ classes.
1. int/long label
3. string word
4. float/double scalar
5. — vector
GeometricField class I
The geometricField< Type > is renamed used typedef declarations to indicate where field variables are
stored:
1. volField<Type> −→ Field defined at cell centres.
2. surfaceField<Type> −→ Field defined at cell faces.
3. pointField<Type> −→ Field defined at cell vertices.
GeometricField class II
Equation mimicking
∂ρU
+ ∇ · (ρ UU) − µ∇2 U = −∇p + b
∂t
1. typedef - fvm:
Navier-Stokes equation in OpenFOAM
- Belongs the finiteVolumeMethod class.
solve
( - Performs an implicit evaluation and returns an
fvm : : d d t ( rho ,U) fvMatrix.
+ fvm : : d i v (U,U)
− fvm : : l a p l a c i a n (mu,U)
== 2. typedef - fvc:
− f v c : : grad ( p )
+ b - Belongs to the finiteVolumeCalculus class.
); - Performs an explicit calculation and returns a
geometricField.
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Dimensional compatibility
Dictionary in OpenFOAM
SI Base Units
Quantity
kg m s K mol A cd
1. Density 1 -3 0 0 0 0 0
2. Linear Momentum 1 -2 -1 0 0 0 0
3. Pressure 1 -1 -2 0 0 0 0
4. Force 1 1 -2 0 0 0 0
5. Lame’s Coefficients 1 -1 -2 0 0 0 0
6. Bulk Modulus 1 -1 -2 0 0 0 0
9. Thermal Conductivity 1 1 -3 -1 0 0 0
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Tensor operations
Product operations
1. Outer a∗b ≥ 1
2. Inner/dot a&b ≥ 1
3. Double inner/dot a && b ≥ 2
4. Cross aˆb = 1
Other operations
Tensor operations
1. Transpose A · T()
1. Square root sqrt (s)
2. Diagonal diag (A)
2. Exponential exp (s)
3. Trace tr (A)
3. Natural log log (s)
4. Symmetric part symm (A)
4. Log base 10 log10 (s)
5. Skew-symmetric part skew (A)
5. Sine sin (s)
6. Determinant det (A)
6. Cosine cos (s)
7. Cofactor cof (A)
7. Tangent tan (s)
8. Inverse inv (A)
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Mesh parameters
Coordinates
This blog post [link] contains useful mesh related information particularly mesh connectivities.
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
OpenFOAM classes
Dimensional compatibility
Mathematical operators
Mesh information
Code compilation
6 Conclusions
7 Appendix
Make directories
<< find $FOAM_SOLVERS -name Make | sort
<< cat -n
$FOAM_TUTORIALS/stressAnalysis/solidEquilibriumDisplacementFoam/Make/files
<< cat -n
$FOAM_TUTORIALS/stressAnalysis/solidEquilibriumDisplacementFoam/Make/options
Compilation
This is performed by executing the wmake command from the directory containing the Make folder.
<< wmake
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Copy tutorial
<< cp -r
$FOAM_TUTORIALS/stressAnalysis/solidEquilibriumDisplacementFoam/beamEndLoad/
$FOAM_RUN
<< cd $FOAM_RUN/beamEndLoad
<< tree
Generate mesh
<< blockMesh | tee log.blockMesh
63 boundingBox : ( 0 0 0 ) (30 1 1 )
64 n P o i n t s : 42
65 n C e l l s : 12
66 nFaces : 56
67 n I n t e r n a l F a c e s : 16
65 Checking geometry . . .
66 O v e r a l l domain bounding box ( 0 0 0 ) (30 1 1 )
67 Mesh has 2 g e o m e t r i c ( non−empty / wedge ) d i r e c t i o n s ( 1 1 0 )
68 Mesh has 2 s o l u t i o n ( non−empty ) d i r e c t i o n s ( 1 1 0 )
69 A l l edges a l i g n e d w i t h or p e r p e n d i c u l a r t o non−empty d i r e c t i o n s .
70 Boundary openness ( 0 0 0 ) OK.
71 Max c e l l openness = 0 OK.
72 Max aspect r a t i o = 10 OK.
73 Minimum f a c e area = 0 . 5 . Maximum f a c e area = 5 . Face area magnitudes OK.
74 Min volume = 2 . 5 . Max volume = 2 . 5 . T o t a l volume = 3 0 . C e l l volumes OK.
75 Mesh non−o r t h o g o n a l i t y Max : 0 average : 0
76 Non−o r t h o g o n a l i t y check OK.
77 Face pyramids OK.
78 Max skewness = 0 OK.
79 Coupled p o i n t l o c a t i o n match ( average 0 ) OK.
80
81 Mesh OK.
BlockMesh inputs I
19 v e r t i c e s 2 3
20 (
21 (0 0 0) // Vertex 0
22 (1 0 0) // Vertex 1 7 6
23 (0 1 0) // Vertex 2
24 (1 1 0) // Vertex 3
25 (0 0 1) // Vertex 4 y
26 (1 0 1) // Vertex 5 0
27 (1 1 1) // Vertex 6 x 1
z
28 (0 1 1) // Vertex 7
29 ) ;
4 5
BlockMesh inputs II
Defining cells
31 b l o c k s
32 (
33 hex ( 0 1 3 2 4 5 6 7 ) / / V e r t e x l i s t f o r c r e a t i o n o f a hexahedral c e l l
34 (5 5 5) / / No . o f c e l l s i n each d i r e c t i o n
35 simpleGrading ( 1 . 0 1 . 0 1 . 0 ) / / C e l l expansion r a t i o s
36 ) ;
38 edges
39 (
40 ) ;
81 mergePatchPairs
82 (
83 ) ;
61 boundingBox : ( 0 0 0 ) ( 0 . 0 0 1 0.001 0 . 0 0 1 )
62 n P o i n t s : 216
63 n C e l l s : 125
64 nFaces : 450
65 n I n t e r n a l F a c e s : 300
62 Checking geometry . . .
66 Boundary openness ( 9 . 4 8 5 e−17 9.485e−17 5.9557e−17) OK.
67 Max c e l l openness = 8.27181e−17 OK.
68 Max aspect r a t i o = 1 OK.
69 Minimum f a c e area = 4e−08. Maximum f a c e area = 4e−08. Face area magnitudes OK.
70 Min volume = 8e−12. Max volume = 8e−12. T o t a l volume = 1e−09. C e l l volumes OK.
71 Mesh non−o r t h o g o n a l i t y Max : 0 average : 0
72 Non−o r t h o g o n a l i t y check OK.
73 Face pyramids OK.
74 Max skewness = 3.68629e−15 OK.
75 Coupled p o i n t l o c a t i o n match ( average 0 ) OK.
76
77 Mesh OK.
FOAM e x i t i n g
Delete 0 directory
<< rm -r 0
Hint
• You can edit the blockMeshDict file using your favourite text editor (eg. vi, gedit, nano).
<< vi system/blockMeshDict
2 3
Add the following after the blocks definition
7 6
38 edges
39 (
40 arc 6 3 ( 1 . 3 1.3 0 . 5 )
y
41 ) ; 0
x 1
z
4 5
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Breaking of a dam
0.584 m
Problem description
Air
• Transient two phase flow
0.584 m
• Incompressible, isothermal flow
Water
• Immiscible fluids 0.292 m Column
0.024 m
0.048 m
0.1461 m 0.1459 m
interFoam solver
Description of solver
<< find $FOAM_SOLVERS -name interFoam.C | xargs cat -n | sed -n
"/Description/,/*/p"
27 Description
28 S o l v e r f o r 2 i n c o m p r e s s i b l e , i s o t h e r m a l i m m i s c i b l e f l u i d s using a VOF
29 ( volume o f f l u i d ) phase−f r a c t i o n based i n t e r f a c e c a p t u r i n g approach ,
30 w i t h o p t i o n a l mesh motion and mesh t o p o l o g y changes i n c l u d i n g a d a p t i v e
31 re−meshing .
interFoam solver
19 internalField uniform 0;
system
|− blockMeshDict
|− c o n t r o l D i c t
|− decomposeParDict
|− fvSchemes
|− f v S o l u t i o n
|− s e t F i e l d s D i c t
24 Description
25 Set v a l u e s on a s e l e c t e d s e t o f c e l l s / p a t c h f a c e s t h r o u g h a d i c t i o n a r y .
Initialise fields
18 defaultFieldValues
19 (
20 v o l S c a l a r F i e l d V a l u e alpha . water 0
21 );
22
23 regions
24 (
25 boxToCell
26 {
27 box ( 0 0 −1) ( 0 . 1 4 6 1 0.292 1 ) ;
28 fieldValues
29 (
30 v o l S c a l a r F i e l d V a l u e alpha . water 1
31 );
32 }
33 );
Solution
t = 0.0 s
Simulate the same scenario but with a refined mesh and save an animation.
Hint
• A utility "refineMesh" could be utilised.
• Time directories can be removed with << foamListTimes -rm.
• Please pay attention to the error messages displayed on your terminal.
The solution is always there!!!
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
How to use a mesh generated from ANSYS FLUENT for OpenFOAM simulations?
Cell labels
Mesh s i z e : 918
Before renumbering :
band : 735
profile : 103613
A f t e r renumbering :
band : 29
profile : 11753
<< tree
VTK
|− elbow_0 . v t k
|− elbow_1 . v t k
Renumber cells
<< renumberMesh -help
−o v e r w r i t e o v e r w r i t e e x i s t i n g mesh / r e s u l t s f i l e s
Visualise results
X Convert mesh from OpenFOAM to VTK format using the foamToVTK utility.
X Use renumberMesh utility to decrease bandwidth.
X Search for a particular text using ‘grep’ command.
X See usage of an OpenFOAM command using ‘-help’ option.
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Problem setup
Refine the mesh for better comparison of run times for serial and parallel simulations
Mesh refinement
<< mv damBreak damBreakFine_serial
<< cd damBreakFine_serial
<< gedit system/blockMeshDict
47 b l o c k s
48 (
49 hex (0 1 5 4 12 13 17 16) ( 70 15 1 ) simpleGrading ( 1 1 1 )
50 hex (2 3 7 6 14 15 19 18) ( 60 15 1 ) simpleGrading ( 1 1 1 )
51 hex (4 5 9 8 16 17 21 20) ( 70 120 1 ) simpleGrading ( 1 2 1 )
52 hex (5 6 10 9 17 18 22 21) ( 8 120 1 ) simpleGrading ( 1 2 1 )
53 hex (6 7 11 10 18 19 23 22) ( 60 120 1 ) simpleGrading ( 1 2 1 )
54 ) ;
<< blockMesh
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 100
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Serial run
Check mesh
<< checkMesh
O v e r a l l number o f c e l l s o f each t y p e :
hexahedra : 18510
<< paraFoam
Visualise results
<< paraFoam
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 101
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition I
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 102
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition II
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 103
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 104
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition IV
Initialise the problem
<< blockMesh
<< setFields
<< checkMesh
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 105
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Parallel run
Parallel run
<< foamJob -parallel -screen interFoam
<< gnome-system-monitor
Visualise results
<< ls
<< tree processor0
<< paraFoam -case processor0
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 106
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Reconstruct solution
reconstructPar utility can be used to reassemble the fields and mesh from the
decomposed parallel run.
Reconstruction of results
<< reconstructPar
Visualise results
<< ls
<< paraFoam
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 107
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Clean script
<< find $FOAM_TUTORIALS -name Allclean | sort
<< cp
$FOAM_TUTORIALS/stressAnalysis/solidDisplacementFoam/plateHole/Allclean .
<< ./Allclean
Parallel speedup
Tserial
Speedup ratio =
Tparallel
1. 1 ≈ 330 —–
2. 4 ≈ 108 3.055
3. 9 ≈ 80 4.125
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 108
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 109
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 110
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Problem description
• Two dimensional, steady state flow.
• Incompressible and turbulent flow.
• Newtonion fluid with viscosity ν = 1 × 10−5 m2 /s.
Case setup
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 111
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Hints
• Choose a relevant OpenFOAM solver.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 112
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Pressure distribution
Velocity vectors
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 113
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Velocity vectors
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 114
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 115
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 116
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Basics of snappyHexMesh I
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 117
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Basics of snappyHexMesh II
2. Snap to surface
3. Addition of layers
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 118
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Surface meshes I
Visualise geometry
<< paraview
File −→ Open −→ "constant/triSurface/motorBike.obj"
Display surface with edges.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 119
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Surface meshes II
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 120
Introduction Code Simulations Programming Tutorials Conclusions Appendix
View patches
<< surfaceConvert constant/triSurface/motorBike.obj
constant/triSurface/motorBike.vtk
<< paraview
File −→ Open −→ "constant/triSurface/motorBike.vtk"
Display region.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 121
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Castellated mesh I
Meshing using snappyHexMesh utility requires a base background mesh to start with.
Notes
• Must only consist of hexahedral cells.
• The aspect ratio of cells should be close to 1 for optimal snapping process.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 122
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Castellated mesh II
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 123
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 124
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Snapping I
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 125
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Snapping II
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 126
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 127
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 128
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 129
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Commands
Basics of OpenFOAM
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 130
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Meshing
Solving
Visualising
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 131
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
3 OpenFOAM simulations
4 Programming in OpenFOAM
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 132
Introduction Code Simulations Programming Tutorials Conclusions Appendix
• ls <directory>
• cd <directory> List contents of a directory.
Change to a directory location.
• tree
• cd Print the current directory structure.
Change to the home directory.
• clear
• cd .. Clears the terminal window.
Go one level up from current directory.
• ps / top
• cd ../.. Displays information about current running
Go two levels up from current directory. processes.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 133
Introduction Code Simulations Programming Tutorials Conclusions Appendix
• cp <directory1> <directory2>
Copy a directory from directory path 1 to 2.
• mv <file1> <file2>
Rename file1 to file2.
• vi <file>
Open a text file, press ’:i’ to insert text, ’:w’ to save, ’:q’ to quit, ’SHIFT+zz’ to save and quit.
• cat <file>
Print contents of the file..
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 134
Introduction Code Simulations Programming Tutorials Conclusions Appendix
• blockMesh -help
See usage of an OpenFOAM command.
View publication
Jibran Haider statsComputational Mechanics)
(PhD OpenFOAM course for beginners 135