Publications-2018.pdf - The Australasian Society for Classical ...
[Haider-2018-OpenFOAM_course] OpenFOAM for beginners.pdf
-
Upload
khangminh22 -
Category
Documents
-
view
2 -
download
0
Transcript of [Haider-2018-OpenFOAM_course] OpenFOAM for beginners.pdf
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM course for beginners:Hands-on training
Jibran Haider
Zienkiewicz Centre for Computational Engineering (ZCCE),College of Engineering, Swansea University, UK
https://www.jibranhaider.weebly.com
12 th September 2018
September 12, 2018Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 1
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Disclaimer
“This offering is not approved or endorsed by
OpenCFD Limited, producer and distributor of the
OpenFOAM software and owner of the
OPENFOAM R© and OpenCFD R© trade marks.”
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 2
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 3
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 IntroductionMy backgroundCourse detailsOpenFOAM preliminaries
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 4
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 IntroductionMy backgroundCourse detailsOpenFOAM preliminaries
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 5
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Experience in computational mechanics
Year Topic Software Institution
[2009] CFD and experimental study of flow overcylindrical fins.
FLUENT NUST
[2012] Numerical simulation of sloshingphenomena in complex tanks.
FLOW-3D Universität Stuttgart & DLR
[2013]Modeling of phase change phenomenathrough a liquid-vapor interface inmicrogravity.
OpenFOAM Universität Stuttgart & DLR
[2014] A first order hyperbolic framework for largestrain fast solid dynamics.
OpenFOAM Swansea University & UPC
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 6
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 IntroductionMy backgroundCourse detailsOpenFOAM preliminaries
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 7
Introduction Code Simulations Programming Tutorials Conclusions 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).
During this course we will be using
• OpenFOAM Foundation release (version 6).
• ParaView (version 5.4.0).
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 8
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 IntroductionMy backgroundCourse detailsOpenFOAM preliminaries
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 9
Introduction Code Simulations Programming Tutorials Conclusions 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.
• Cross-platform installation.
OpenFOAM forks
• OpenFOAM Foundation release (official standard release).
• OpenFOAM + (official development release).
• FOAM-extend (community driven development branch).
e FCNe f
‖Ce f‖ Ωe0
This blog post [link] provides plenty of free references available on the web which might be a goodstarting point for learning OpenFOAM.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 10
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Key features of OpenFOAM
OpenFOAM is a C++ library of highest quality of programming for solving
computational continuum mechanics problems utilising all the features of
Objected Oriented Programming (OOP).
Key features of OOP
• Abstraction
• Inheritance
• PolymorphismObjects of different classes respond differently to functions of the same name.Also includes operator overloading.
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.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 11
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Why OpenFOAM?
OpenFOAMCommercial Software
(ANSYS, ABAQUS etc.)
1. Cost effectiveness X ×2. Parallel computing X X3. Source code X ×4. Redistribution of code X ×5. Collaborative development X ×6. Documentation × X7. GUI / user friendliness × X
X Motivates collaborative and project-driven development.
X According to the GNU GPL v3, OpenFOAM is free to download, install, use, modify and distribute.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 12
Introduction Code Simulations Programming Tutorials Conclusions Appendix
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. Dueto 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 releasedunder 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.
6th 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 theOpenFOAM software.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 13
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Simulation workflow
- blockMesh- snappyHexMesh
- Gmsh- Engrid
- Netgen- Tetgen
- SALOME - Blender
- ANSYS- Star-CCM+- SOLIDWORKS
Preprocessing Solver Postprocessing
- Incompressible- Compressible- Multiphase- Combustion- Heat transfer
- Molecular dynamics- Electromagnetics- Solid mechanics
- OpenFOAM utilities
- ParaView- OpenDX- SALOME
- VISIT- Netfabb- Gnuplot
- ANSYS- Tecplot- EnSight
- FieldView
OpenFOAM Other open source Commercial
- OpenFOAM utilities
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 14
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Conventions used in this presentation
OpenFOAM terminologiesOpenFOAM_terminology
OpenFOAM command for applicationsOpenFOAM_application
Commands on terminal<< command_name
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 15
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Environment variables & aliases
Environment variables are preconfigured to important OpenFOAM directories.
<< env | grep ˆFOAM_
FOAM_SOLVERS=/ opt / openfoam6 / a p p l i c a t i o n s / so lve rsFOAM_EXT_LIBBIN=/ opt / Th i rdPar ty −6/p la t fo rms / l inux64GccDPInt32 / l i bFOAM_APPBIN=/ opt / openfoam6 / p la t fo rms / l inux64GccDPInt32Opt / b inFOAM_TUTORIALS=/ opt / openfoam6 / t u t o r i a l s. . . . .
Aliases make use of environment variables to navigate inside OpenFOAM sources.
<< cat $WM_PROJECT_DIR/etc/config.sh/aliases
. . . . .62 a l i a s src= ’ 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 ’. . . . .
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 16
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM codeCode structureApplicationsSolversUtilities
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 17
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM codeCode structureApplicationsSolversUtilities
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 18
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Installation directory I
$WM_PROJECT_DIR
applications
solvers
test
utilities
tutorials
src
bin
doc
etc
platforms
wmake
1. applications:alias: app = ’cd $FOAM_APP’.This directory contains the source files of all theexecutables created using the C++ libraries. It containsthe following directories:
1.1 solvers:alias: sol = ’cd $FOAM_SOLVERS’.Source code to solve a particular continuummechanics problem.
1.2 test :Sample codes to help understand the usage ofOpenFOAM libraries.
1.3 Utilities:alias: util = ’cd $FOAM_UTILITIES’.Source code to perform pre- and post-processingtasks involving data manipulation and algebraicmanipulations.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 19
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Installation directory II
$WM_PROJECT_DIR
applications
tutorials
src
finiteVolume
OpenFOAM
turbulenceModels
. . .
bin
doc
etc
platforms
wmake
2. tutorials:alias: tut = ’cd $FOAM_TUTORIALS’.Contains tutorials that demonstrate the usage of allsolvers and most of the utilities.
3. src:alias: src = ’cd $FOAM_SRC’.It contains several subdirectories which include thesource code for all libraries. The important folders are:
3.1 finiteVolume:alias: foamfv = ’cd $FOAM_SRC/finiteVolume’.Includes classes for finite volume space/timediscretisation, boundary conditions etc.
3.2 OpenFOAM:This core library includes important definitions.
3.3 turbulenceModels:Contains libraries for turbulence models.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 20
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Installation directory III
$WM_PROJECT_DIR
applications
tutorials
src
bin
doc
etc
platforms
wmake
4. bin:This directory contains shell scripts such as paraFoam,foamLog etc.
5. doc:It contains all the documentation relevant to the version ofOpenFOAM including:5.1 User and Programmer’s guides5.2 Doxygen generated documentation5.3 OpenFOAM coding style guide
6. etc:It contains global OpenFOAM dictionaries and setup files.
7. platforms:The binaries generated during the compilation of theapplications and the dynamic libraries are stored here.
8. wmake:Compiler settings are included in this directory includingoptimisation flags. It also contains wmake, a special makecommand which understands the OpenFOAM file structure.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 21
Introduction Code Simulations Programming Tutorials Conclusions Appendix
User’s working directory
The path to user’s working directory is stored in $WM_PROJECT_USER_DIR.
Check the path of working directory
<< echo $WM_PROJECT_USER_DIR
/ home / j i b r a n /OpenFOAM/ j i b r a n−6
Create the run directory
<< mkdir -p $FOAM_RUN
Check the path of ’run’ directory
<< echo $FOAM_RUN
/ home / j i b r a n /OpenFOAM/ j i b r a n −6/run
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 22
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM codeCode structureApplicationsSolversUtilities
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 23
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Directory structure
<application>
appName.C
*.H
Make
files
options
1. appName.C:Contains the main source code of the application.
2. *.H:The necessary header files needed to compile the application.The solvers include createFields.H file which declares andinitialises the field variables.
3. Make:This directory contains the compilation instructions andincludes the following files:
3.1 files:List of source files (*.C) needed to compile theapplication and the executable name.
3.2 options:Specifies the directories to search for the includedheader files (*.H) and libraries needed to link theapplication against.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 24
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM codeCode structureApplicationsSolversUtilities
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 25
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM solvers I
X Over 70+ OpenFOAM solvers.
Basic CFD solvers
Solver Description
1. laplacianFoam Solves a Laplace equation.
2. potentialFoam Solves for potential flow.
Incompressible flow
Solver Description
1. icoFoam Transient solver for incompressible, laminar flow of Newtonian fluids.
2. simpleFoam Steady state solver for incompressible, turbulent flow.
3. pisoFoam Transient solver for incompressible flow.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 26
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM solvers II
Compressible flow
Solver Description
1. rhoCentralFoamDensity based compressible flow solver based on cen-tral upwind scheme.
2. sonicFoamTransient solver for trans-sonic/supersonic, laminar/tur-bulent flow of a compressible gas.
Multiphase flow
Solver Description
1. interFoamSolver for 2 incompressible, isothermal and immis-cible fluids based on the VOF method.
2. interPhaseChangeFoamSolver for 2 incompressible, isothermal and immis-cible fluids with a phase change model.
3. multiPhaseEulerFoamSolver for multiple compressible fluid phases withheat transfer.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 27
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM solvers III
Other solvers
Solver Description
1. solidDisplacementFoamTransient solver for linear-elastic, small-strain solver de-formation of a solid body.
2. mdFoam Molecular dynamics solver for fluids.
3. buoyantSimpleFoamSteady state solver for buoyant, turbulent flow of com-pressible fluids.
Solver names describe their functionality
simple: SIMPLE algorithm used in steady-state solvers.
piso: PISO algorithm used in transient solvers αCFL < 1.
pimple: PIMPLE algorithm used in transient solvers.
DyM: Supports dynamic mesh (eg. mesh refinement, moving meshes).
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 28
Introduction Code Simulations Programming Tutorials Conclusions Appendix
icoFoam solver
Main solver file<< find $FOAM_SOLVERS -name icoFoam.C | xargs cat -n
. . . . .27 Desc r i p t i on28 Trans ien t so l ve r for incompress ib le , laminar f low of Newtonian f l u i d s .. . . . .32 # inc lude " fvCFD .H" / / Header f i l e w i th a l l the FVM machinery33 # inc lude " p isoCon t ro 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 the main program38 39 # inc lude " setRootCase .H" / / Set path and case d i r e c t o r i e s40 # inc lude " createTime .H" / / I n i t i a l i s e t ime v a r i a b l e41 # inc lude " createMesh .H" / / I n i t i a l i s e the mesh to work w i th. . . . .52 while ( runTime . loop ( ) ) / / Time loop begins53 . . . . .115 runTime . w r i t e ( ) ; / / Wr i te r e s u l t s to t ime d i r e c t o r i e s. . . . .120 / / End t ime loop121122 In fo << "End \ n " << endl ;123124 return 0;125 . . . . .
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 29
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM codeCode structureApplicationsSolversUtilities
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 30
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM utilities I
X Over 80+ OpenFOAM utilities.
Mesh generation tools
Utility Description
1. blockMesh Multiblock mesh generator.
2. snappyHexMeshAutomatic split hexahedral mesher which refines and snaps tosurface producing hexahedral dominant cells.
Mesh conversion to OpenFOAM format
Utility Description
1. ansysToFoam ANSYS input mesh file exported from I-DEAS.
2. gambitToFoam GAMBIT mesh file.
3. gmshToFoam Reads .msh GMSH file.
4. ideasUnvToFoam I-DEAS unv format (eg. SALOME mesh).
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 31
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM utilities II
Mesh manipulation tools
Utility Description
1. checkMesh Checks the quality of the mesh by providing a detailed output.2. renumberMesh Renumbers the cell list to reduce the bandwidth.3. refineMesh Refines mesh in multiple directions.4. autoRefineMesh Refines cells near to a surface.5. refineHexMesh Refines a hexahederal mesh by 2x2x2 cell splitting.
Post-processing tools
Utility Description
1. patchAverage Calculates average of a field over a patch.2. patchIntegrate Calculates integral of a field over a patch.3. probeLocations Outputs the field value at a particular location.4. foamCalc Utility for simple field calculations at specified times.5. writeCellCentres Output cell centres as a volScalarField.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 32
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM utilities III
Parallel processing tools
Utility Description
1. decomposeParDecomposes a mesh and fields of a case for parallelexecution.
2. reconstructParMeshReconstructs the decomposed mesh after parallel ex-ecution using only the geometric information.
Hands-on training:Some useful OpenFOAM utilities (See page 91)
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 33
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 34
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 35
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Tutorial directory structure I
<tutorial>
constant
polymesh
points
faces
owner
neighbour
boundary
... properties
system
0
1. constant :This directory contains the information which remains constantthroughout the simulation. It contains the following:
1.1 polymesh:Contains all the mesh information including:
(a) points → nodal positions
(b) faces → face connectivities
(c) owner → owner cell labels
(d) neighbour → neighbour cell labels
(e) boundary → boundary information
1.2 ... properties:Files which specify physical properties for a particularapplication eg. gravity, viscosity, thermal properties etc.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 36
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Tutorial directory structure II
<tutorial>
constant
system
controlDict
fvSchemes
fvSolution
0
p
U
2. system:This directory contains all the parameters associated with thesolution procedure. It contains at least the following files:
2.1 controlDict :Specifies the run control parameters such as start/endtime, time step, write interval etc.
2.2 fvSchemes:Contains the finite volume discretisation schemes usedfor the solution procedure such as spatial and temporaldiscretisations.
2.3 fvSolution:Contains equation solvers, algorithm controls andtolerances for the implicit solvers.
3. 0:The ’0’ directory corresponds to zero time. It contains theinitial and boundary conditions for variables (ie. pressure p,velocity U) in individual files.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 37
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 38
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Meshing in OpenFOAM
• OpenFOAM only supports three dimensional meshes !!!
• 1D & 2D simulations are carried out by using appropriate ’empty ’ boundary conditions.
• Supports arbitrary polyhedral cells bounded by arbitrary polygonal faces.
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)
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 39
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 40
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Selection of an appropriate OpenFOAM solver
Procedure
• Select an appropriate OpenFOAM solver (alias: sol) for the problem:<< ls $FOAM_SOLVERS
• 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.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 41
Introduction Code Simulations Programming Tutorials Conclusions Appendix
OpenFOAM tutorial file syntax
A sub-dictionary is characterised by curly brackets ...
. . . . . / / Keyword e n t r i e s
A list is characterised by round brackets (...);
L i s t <Type> / / Type of l i s t<n> / / L i s t s i ze(. . . . . / / L i s t e n t r i e s) ;
A dimensionSet is characterised by square brackets [...]
[0 1 −1 0 0 0 0] / / [ Mass Length Time Temp. Quant i ty Current Luminos i ty ]
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 42
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Initial conditions
Initial conditions must be specified for all variables inside ’0’ directory.
Standard initial conditions<< cat $FOAM_RUN/cavity/0/U
. . . . .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 ]1819 i n t e r n a l F i e l d uni form (0 0 0) ; / / Ce l l values. . . . .
Non standard initial conditions
• setFields utility could also be utilised to initialise fields in OpenFOAM.
• The dictionary setFieldsDict provides the necessary inputs.
• funkySetFields utility of the swak4Foam library by B. Gschaider could also be utilised.
<< find $FOAM_TUTORIALS -name setFieldsDict
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 43
Introduction Code Simulations Programming Tutorials Conclusions Appendix
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.
Initial and boundary conditions<< cat $FOAM_RUN/cavity/0/U
. . . . .21 boundaryFie ld / / D i c t i o n a r y to spec i f y boundary cond i t i ons22 23 movingWall / / Boundary patch name24 25 type f ixedVa lue ; / / Boundary c o n d i t i o n type26 value uni form (1 0 0) ; / / Boundary values27 2829 f i xedWa l l s30 31 type noSl ip ;32 3334 frontAndBack35 36 type empty ; / / Boundary c o n d i t i o n type f o r 2D s imu la t i ons37 38 . . . . .
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 44
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Boundary conditions II
Basic boundary conditions
BC type Data Example
1. fixedValue value U = (5, 10, 0)
2. fixedGradient gradient ∂T∂n = 3.5
3. zeroGradient _ ∂p∂n = 0
Non standard boundary conditions
• groovyBC library developed by B. Gschaider could be utilised without the need for programming.
• Custom boundary conditions can be programmed.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 45
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Time controls
controlDict dictionary<< cat $FOAM_RUN/cavity/system/controlDict
18 a p p l i c a t i o n icoFoam ; / / Name of so l ve r1920 star tFrom star tT ime ; / / Usefu l f o r r e s t a r t s imu la t i ons2122 s ta r tT ime 0; / / S t a r t i n g t ime2324 stopAt endTime ; / / Stopping c r i t e r i a2526 endTime 0 . 5 ; / / End t ime2728 de l taT 0.005; / / Time stepping ( De fau l t value o f 1 f o r steady s ta te so lve rs )2930 w r i t e C o n t r o l t imeStep ; / / C r i t e r i a f o r w r i t i n g r e s u l t s3132 w r i t e I n t e r v a l 20; / / I n t e r v a l f o r w r i t i n g r e s u l t s3334 purgeWri te 0 ; / / Disable r e w r i t i n g over t ime d i r e c t o r i e s3536 wr i teFormat a s c i i ; / / Format f o r w r i t i n g r e s u l t s3738 w r i t e P r e c i s i o n 6 ; / / P rec i s ion f o r w r i t i n g r e s u l t s3940 writeCompression o f f ; / / Disable compression f o r wr t i ng r e s u l t s4142 timeFormat general ; / / Format f o r w r i t i n g t ime d i r e c t o r i e s4344 t imePrec is ion 6 ; / / P rec i s ion f o r w r i t i n g t ime d i r e c t o r i e s4546 runTimeModi f iab le true ; / / Al lows m o d i f i c a t i o n o f s e t t i n g s dur ing the run
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 46
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Solver controls I
fvSchemes dictionary<< cat $FOAM_RUN/cavity/system/fvSchemes
18 ddtSchemes19 20 defaul t Euler ; / / Time d i s c r e t i s a t i o n schemes21 23 gradSchemes / / Gradient eva lua t i on schemes24 25 defaul t 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 the convect ive terms30 31 defaul t none ;32 d iv ( 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 the Laplac ian term36 37 defaul t Gauss l i n e a r or thogonal ;38 40 in terpo la t ionSchemes / / Method of i n t e r p o l a t i o n41 42 defaul t l i n e a r ;43 45 snGradSchemes / / Surface normal g rad ien t scheme46 47 defaul t or thogonal ;48
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 47
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Solver controls II
fvSolution dictionary<< cat $FOAM_RUN/cavity/system/fvSolution
18 so lve rs19 20 p21 22 so l ve r PCG; / / Solver to so lve the system23 p recond i t i one r DIC ; / / P recond i t i one r type24 to le rance 1e−06;25 r e l T o l 0 .05 ;26 28 pF ina l29 30 $p ;31 r e l T o l 0 ;32 34 U35 36 so l ve r smoothSolver ;37 smoother symGaussSeidel ;38 to le rance 1e−05;39 r e l T o l 0 ;40 41 4243 PISO / / PISO c o n t r o l s44 45 nCorrec tors 2 ;46 nNonOrthogonalCorrectors 0 ;. . . .49
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 48
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 49
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Running an OpenFOAM tutorial
Default procedure
• Copy OpenFOAM tutorial to you run directory.<< cp -r <tutorial_directory> $FOAM_RUN
<< cd <tutorial_name>
• Create mesh by using the blockMesh command.<< blockMesh
• Run simulation by using name of an OpenFOAM solver (eg. pisoFoam).<< pisoFoam
Procedure for complex tutorialsSome tutorials require an Allrun script to run and Allclean script to clear the tutorial directory.<< find $FOAM_TUTORIALS -name Allrun
Hands-on training:Two phase flow problem (See page 82)
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 50
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulationsTutorial directory structureMeshingProblem setupSolvingPost-processing
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 51
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Post-processing OpenFOAM results
• OpenFOAM comes with builtin support for ParaView.
• ParaView is an open-source, multi-platform data analysis and visualisation application.
• Also possible to visualise OpenFOAM results with third-party applications.
• OpenFOAM results can be visualised using the paraFoam utility.<< paraFoam
ParaView toolbars
Main controls
Common filters
VCR controls Time controls
Active variable controls
Camera controls Axes control
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 52
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 53
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 54
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Basic classes
X Basic classes in OpenFOAM have been derived from more fundamental C++ classes.
X OpenFOAM classes are more advanced and have more functionality.
Some OpenFOAM classes
C++ class OpenFOAM class
1. int/long label
2. bool switch - Accepts true/false, on/off and yes/no.
3. string word
4. float/double scalar
5. — vector
6. — tensor - 3× 3 tensor with algebra
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 55
Introduction Code Simulations Programming Tutorials Conclusions Appendix
GeometricField class I
GeometricField class is templated around 3 arguments:
GeometricField < Type, PatchField, GeoMesh >
A ’Field ’ refers to a list of tensors along with a mesh.
• typedef is an alias for a class to improve readability.
• Used extensively in OpenFOAM particularly in relation to template classes.
The geometricField< Type > is renamed used typedef declarations to indicate where field variables arestored:
1. volField<Type> −→ Field defined at cell centres.
2. surfaceField<Type> −→ Field defined at cell faces.
3. pointField<Type> −→ Field defined at cell vertices.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 56
Introduction Code Simulations Programming Tutorials Conclusions Appendix
GeometricField class II
(a) volField (b) surfaceField (c) pointField
Internal field:Defined at cell centersDefined at internal faces centersDefined at nodes
Boundary field:
Defined at boundary face centers
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 57
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Equation mimicking
Classical incompressible Navier-Stokes equation
∂ρU∂t
+∇ · (ρUU)− µ∇2U = −∇p + b
Navier-Stokes equation in OpenFOAM
solve(
fvm : : ddt ( rho ,U)+ fvm : : d i v (U,U)− fvm : : l a p l a c i a n (mu,U)==− f vc : : grad ( p )+ b
) ;
1. typedef - fvm:
- Belongs the finiteVolumeMethod class.
- Performs an implicit evaluation and returns anfvMatrix .
2. typedef - fvc:
- Belongs to the finiteVolumeCalculus class.
- Performs an explicit calculation and returns ageometricField .
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 58
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 59
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Dimensional compatibility
X OpenFOAM is fully dimensional.
X Fields and properties have dimensions associated with them.
X Dimensional checking is performed to avoid meaningless operations.
X Units are defined using the dimensionSet class.
Dictionary in OpenFOAM
FoamFile
vers ion 2 . 0 ;format a s c i i ;class d i c t i o n a r y ;ob jec t t r a n s p o r t P r o p e r t i e s ;
/ / Thermal d i f f u s i v i t yDT DT [0 2 −1 0 0 0 0] 0 .01 ;
Sample OpenFOAM code
dimensionedTensor sigma(
" sigma " ,dimensionSet (1 ,−1 ,−2 ,0 ,0 ,0 ,0) ,tensor (1e6 ,0 ,0 ,0 ,10e6 ,0 ,0 ,0 ,5 e6 )
) ;
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 60
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Standard dimensional units
QuantitySI Base Units
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
7. Young’s Modulus of Elasticity 1 -1 -2 0 0 0 0
8. Specific Heat Capacity 0 2 -2 -1 0 0 0
9. Thermal Conductivity 1 1 -3 -1 0 0 0
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 61
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 62
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Tensor operations
• Tensor operations available to all OpenFOAM tensor classes
Product operations
Product operator OpenFOAM notation Rank of a & b
1. Outer a ∗ b ≥ 12. Inner/dot a & b ≥ 13. Double inner/dot a && b ≥ 24. Cross aˆb = 1
Other operations
Product operator OpenFOAM notation
1. Magnitude mag (a)2. Square of magnitude magSqr (a)3. Square sqr (a)4. Power pow (a, n)
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 63
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Tensor operations
Operations exclusive to tensors of rank 2
Operator OpenFOAM notation
1. Transpose A · T()
2. Diagonal diag (A)
3. Trace tr (A)
4. Symmetric part symm (A)
5. Skew-symmetric part skew (A)
6. Determinant det (A)
7. Cofactor cof (A)
8. Inverse inv (A)
Operations exclusive to tensors of rank 0
Operator OpenFOAM notation
1. Square root sqrt (s)
2. Exponential exp (s)
3. Natural log log (s)
4. Log base 10 log10 (s)
5. Sine sin (s)
6. Cosine cos (s)
7. Tangent tan (s)
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 64
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 65
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Mesh parameters
Important mesh parameters
Description Access function Data type
1. Total number of cells mesh.nCells() scalar
2. Total number of internal faces mesh.nInternalFaces() scalar
3. Cell volumes mesh.V() volScalarField
4. Face area normal vectors mesh.Sf() surfaceVectorField
5. Face area magnitudes mesh.magSf() surfaceVectorField
Coordinates
Coordinates Access function Data type
1. Cell center mesh.C() volVectorField2. Face center mesh.Cf() surfaceVectorField3. Nodal mesh.points() pointField
This blog post [link] contains useful mesh related information particularly mesh connectivities.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 66
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAMOpenFOAM classesDimensional compatibilityMathematical operatorsMesh informationCode compilation
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 67
Introduction Code Simulations Programming Tutorials Conclusions Appendix
wmake compilation tool
X OpenFOAM uses its own compilation tool wmake.
X OpenFOAM applications and libraries require a Make directory.
X The Make directory contains the files and options files.
Make directories<< find $FOAM_SOLVERS -name Make | sort
<< cat -n$FOAM_TUTORIALS/stressAnalysis/solidEquilibriumDisplacementFoam/Make/files
<< cat -n$FOAM_TUTORIALS/stressAnalysis/solidEquilibriumDisplacementFoam/Make/options
CompilationThis is performed by executing the wmake command from the directory containing the Make folder.<< wmake
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 68
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 69
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 70
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Mesh creation using blockMesh utility
Find blockMesh files<< find $FOAM_TUTORIALS -name *blockMesh*
Arrange files according to size<< find $FOAM_TUTORIALS -name *blockMesh* | sort
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 nPoints : 4265 nCel ls : 1266 nFaces : 5667 nIn terna lFaces : 16
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 71
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Mesh quality using checkMesh utility
Check the mesh quality<< checkMesh > log.checkMesh
<< cat -n log.checkMesh
65 Checking geometry . . .66 Overa l l domain bounding box (0 0 0) (30 1 1)67 Mesh has 2 geometr ic ( 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 igned wi th or perpend icu la r to 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 face area = 0 . 5 . Maximum face area = 5. Face area magnitudes OK.74 Min volume = 2 . 5 . Max volume = 2 . 5 . To ta l volume = 30. Ce l l volumes OK.75 Mesh non−o r t h o g o n a l i t y Max : 0 average : 076 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 po in t l o c a t i o n match ( average 0) OK.8081 Mesh OK.
Visualise the mesh<< paraFoam
Display the mesh using surface with edges option.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 72
Introduction Code Simulations Programming Tutorials Conclusions Appendix
BlockMesh inputs I
Inputs for creating a mesh using blockMesh requires a blockMeshDict file
located in the system directory.
Study blockMeshDict file<< cat -n system/blockMeshDict
Modify blockMeshDict file to create a cube<< gedit system/blockMeshDict
17 convertToMeters 0.001; / / Sca l ing f o r convers ion to m i l l i m e t e r s
19 v e r t i c e s20 (21 (0 0 0) / / Vertex 022 (1 0 0) / / Vertex 123 (0 1 0) / / Vertex 224 (1 1 0) / / Vertex 325 (0 0 1) / / Vertex 426 (1 0 1) / / Vertex 527 (1 1 1) / / Vertex 628 (0 1 1) / / Vertex 729 ) ;
x
y
z0 1
2 3
4 5
67
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 73
Introduction Code Simulations Programming Tutorials Conclusions Appendix
BlockMesh inputs II
Defining cells
31 blocks32 (33 hex (0 1 3 2 4 5 6 7) / / Vertex l i s t f o r c rea t i on o f a hexahedral c e l l34 (5 5 5) / / No . o f c e l l s i n each d i r e c t i o n35 simpleGrading (1 .0 1.0 1 .0 ) / / Ce l l expansion r a t i o s36 ) ;
Ordering of vertices is critical when defining blocks!
33 hex ( 0 1 3 2 4 5 6 7 )
Plane 1 Plane 2
xyz
x
y
z0 1
2 3
4 5
67
Delete unused entries
38 edges39 (40 ) ;
81 mergePatchPairs82 (83 ) ;
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 74
Introduction Code Simulations Programming Tutorials Conclusions Appendix
BlockMesh inputs III
Modify boundary definition
38 boundary / / Contains d e f i n i t i o n o f boundary patches39 (40 s ides / / Boundary patch name41 42 type patch ;43 faces44 (45 (4 0 2 7) / / Boundary face d e f i n i t i o n s46 (1 5 6 3)47 (0 1 3 2)48 (4 5 6 7)49 ) ;50 51 bottom52 53 type patch ;54 faces55 (56 (0 1 5 4)57 ) ;58 59 top60 61 type patch ;62 faces63 (64 (2 3 6 7)65 ) ;66 67 ) ;
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 75
Introduction Code Simulations Programming Tutorials Conclusions Appendix
blockMesh and checkMesh utilities
Generate mesh<< blockMesh > log.blockMesh
<< cat -n log.blockMesh
61 boundingBox : (0 0 0) (0.001 0.001 0.001)62 nPoints : 21663 nCel ls : 12564 nFaces : 45065 nIn terna lFaces : 300
Check the mesh quality<< checkMesh > log.checkMesh
<< cat -n log.checkMesh
62 Checking geometry . . .66 Boundary openness (9.485e−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 face area = 4e−08. Maximum face area = 4e−08. Face area magnitudes OK.70 Min volume = 8e−12. Max volume = 8e−12. To ta l volume = 1e−09. Ce l l volumes OK.71 Mesh non−o r t h o g o n a l i t y Max : 0 average : 072 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 po in t l o c a t i o n match ( average 0) OK.7677 Mesh OK.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 76
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Post-processing with paraFoam utility
Visualise (or try to visualise) the mesh<< paraFoam
−−> FOAM FATAL IO ERROR:Cannot f i n d pa tchF ie ld en t ry for s ides
f i l e : / home / j i b r a n /OpenFOAM/ j i b r a n −6/run / beamEndLoad / 0 / p . boundaryFie ld from l i n e 25 to l i n e 49.
From f u n c t i o n void Foam : : Geometr icField <Type , PatchFie ld , GeoMesh> : : Boundary : : readF ie ld ( constFoam : : DimensionedField <TypeR , GeoMesh>&, const Foam : : d i c t i o n a r y &) [ w i th Type = double ; PatchFie ld= Foam : : f vPa tchF ie ld ; GeoMesh = Foam : : volMesh ]
i n f i l e / home / ubuntu /OpenFOAM/OpenFOAM−6/src /OpenFOAM/ l n I n c l u d e / Geometr icBoundaryField .C at l i n e 191.
FOAM e x i t i n g
Delete 0 directory<< rm -r 0
Visualise the mesh<< paraFoam
Display the mesh using surface with edges option.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 77
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise I: Meshing with blockMesh I
Increase the mesh density to 10×10×10 cells.
Hint
• You can edit the blockMeshDict file using your favourite text editor (eg. vi, gedit, nano).
<< vi system/blockMeshDict
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 78
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise I: Meshing with blockMesh II
Connect points 6 and 3 with an arc instead of a line.
Add the following after the blocks definition
38 edges39 (40 arc 6 3 (1 .3 1.3 0 .5 )41 ) ;
x
y
z0 1
2 3
4 5
67
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 79
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this tutorial?
X Mesh generation using blockMesh utility.
X Understand the structure of blockMeshDict file.
X Modify blockMeshDict file to our requirements.
X Determine the quality of mesh with checkMesh utility.
X Visualise the mesh with paraFoam utility.
X Understand OpenFOAM error messages displayed on the terminal.
X Use of tee command to simultaneously display and write output to a file.
X Use of the standard output stream < to redirect output to a file.
X Use of cat command to print and vi to modify contents of a file.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 80
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 81
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Breaking of a dam
Simulate breaking of a dam using the two-phase flow solver in OpenFOAM.
The interFoam solver is based on the Volume Of Fluid interface capturing approach.
Problem description
• Transient two phase flow
• Incompressible, isothermal flow
• Immiscible fluids 0.292 m
0.584 m
0.584 m
0.1461 m 0.1459 m
0.024 m
0.048 m
WaterColumn
Air
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 82
Introduction Code Simulations Programming Tutorials Conclusions Appendix
interFoam solver
Description of solver<< find $FOAM_SOLVERS -name interFoam.C | xargs cat -n | sed -n"/Description/,/*/p"
27 Desc r i p t i on28 Solver for 2 incompressib le , i so therma l immisc ib le f l u i d s using a VOF29 ( volume of f l u i d ) phase−f r a c t i o n based i n t e r f a c e cap tu r ing approach ,30 wi th o p t i o n a l mesh motion and mesh topology changes i n c l u d i n g adapt ive31 re−meshing .
Find solver location<< locate interFoam.C
/ opt / openfoam6 / a p p l i c a t i o n s / so lve rs / mul t iphase / interFoam / interFoam .C
Copy damBreak tutorial<< cp -r $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak/damBreak/$FOAM_RUN
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 83
Introduction Code Simulations Programming Tutorials Conclusions Appendix
interFoam solver
Change to damBreak directory<< cd $FOAM_RUN/damBreak
Study contents of tutorial<< tree
Generate mesh and view in ParaView<< blockMesh
<< checkMesh
<< paraFoam
Solve and view results<< interFoam
<< paraFoam
Display the mesh using surface with edges option.Select phase fraction (alpha.water) field to display.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 84
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Check problem setup
Initial phase fraction field<< cat 0/alpha.water.orig
19 i n t e r n a l F i e l d uni form 0;
Study contents of tutorial<< tree system
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
Description of setFields utility<< find $FOAM_UTILITIES -name setFields.C | xargs cat -n | sed -n"/Description/,/*/p"
24 Desc r i p t i on25 Set values on a se lec ted set o f c e l l s / patchfaces through a d i c t i o n a r y .
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 85
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Initialise fields
Display contents of setFieldsDict<< cat -n system/setFieldsDict
18 de fau l tF ie l dVa lues19 (20 vo lSca la rF ie ldVa lue alpha . water 021 ) ;2223 reg ions24 (25 boxToCell26 27 box (0 0 −1) (0.1461 0.292 1) ;28 f i e l d V a l u e s29 (30 vo lSca la rF ie ldVa lue alpha . water 131 ) ;32 33 ) ;
Run setFieldsDict utility<< setFields
<< tree 0
<< head -50 0/alpha.water
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 86
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Solution
Run the solver again<< interFoam
<< paraFoam
t = 0.0 s
t = 0.15 s t = 0.30 s t = 1.0 s
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 87
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise II: Breaking of a dam
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!!!
t = 0.15 s t = 0.30 s t = 1.0 s
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 88
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this tutorial?
X Running an OpenFOAM solver.
X Use find command to search description of OpenFOAM solvers and utilities.
X Use setFields utility to initialise fields.
X Output OpenFOAM solver data to a log file.
X Use refineMesh utility to increase mesh density.
X Understand OpenFOAM errors displayed on the terminal.
X Clear tutorial time directories with foamListTimes -rm.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 89
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 90
Introduction Code Simulations Programming Tutorials Conclusions Appendix
In this tutorial we will learn about the usage of some useful
OpenFOAM utilities.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 91
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Alternative mesh formats I
How to use a mesh generated from ANSYS FLUENT for OpenFOAM simulations?
Search for a fluent mesh tutorial<< grep -r fluent $FOAM_TUTORIALS
/ opt / openfoam6 / t u t o r i a l s / incompress ib le / icoFoam / elbow / A l l r u n : r unApp l i ca t i on fluentMeshToFoam elbow .msh/ opt / openfoam6 / t u t o r i a l s / incompress ib le / icoFoam / elbow / A l l c l e a n : rm −r f f l u e n t I n t e r f a c e
Copy ’elbow’ tutorial<< cp -r $FOAM_TUTORIALS/incompressible/icoFoam/elbow/ $FOAM_RUN
<< cd $FOAM_RUN/elbow
<< tree
Convert FLUENT mesh to OpenFOAM format<< fluentMeshToFoam elbow.msh
<< checkMesh
<< paraFoam
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 92
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Alternative mesh formats II
Other supported mesh formats<< ls $FOAM_UTILITIES/mesh/conversion
ansysToFoam foamMeshToFluent ideasUnvToFoam plot3dToFoam vtkUnstructuredToFoamcfx4ToFoam foamToStarMesh kivaToFoam sammToFoam writeMeshObjdatToFoam foamToSurface mshToFoam star3ToFoamfluent3DMeshToFoam gambitToFoam netgenNeutralToFoam star4ToFoamfluentMeshToFoam gmshToFoam Opt iona l tetgenToFoam
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 93
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Cell labels
Convert to ParaView’s VTK format<< foamToVTK
<< tree
Read mesh in paraview<< paraview
File −→ Open −→ ’VTK/elbow_0.vtk’.Display the mesh using surface with edges.Color by cell ID.
X High bandwidth slows the performance of matrix solvers.
X Renumbering of cell labels can reduce the bandwidth in a solution matrix.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 94
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Renumber cell labels
Use ’renumberMesh’ utility<< renumberMesh
Mesh s ize : 918Before renumbering :
band : 735p r o f i l e : 103613
A f t e r renumbering :band : 29p r o f i l e : 11753
Wr i t i ng mesh to " 0.05 "
<< tree
VTK|− elbow_0 . v tk|− elbow_1 . v tk
Renumber cells<< renumberMesh -help
−ove rwr i t e ove rwr i t e e x i s t i n g mesh / r e s u l t s f i l e s
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 95
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Visualise results
Display new cell labels<< foamToVTK
<< paraview&
File −→ Open −→ "VTK/elbow_1.vtk"Display the mesh using surface with edges and color by cell ID.
(a) Before (b) After
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 96
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this tutorial?
X Convert mesh from FLUENT to OpenFOAM compatible format using thefluentMeshToFoam utility.
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.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 97
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 98
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Compare the performance of a parallel run against a serial run
in OpenFOAM.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 99
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Problem setup
Copy damBreak tutorial<< run
<< cp -r $FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak/damBreak/ .
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 blocks48 (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
Overa l l number o f c e l l s o f each type :hexahedra : 18510
<< paraFoam
Duplicate case setup for parallel run<< cp -r $FOAM_RUN/damBreakFine_serial $FOAM_RUN/damBreakFine_parallel
Run the problem<< setFields
<< interFoam | tee log.serial
ExecutionTime = 330.7 s ClockTime = 331 s
Visualise results<< paraFoam
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 101
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition I
• OpenFOAM uses domain decomposition for parallel runs.
• Geometry is broken down and allocated to separate processors.
• Decomposition requires a system/decomposeParDict file.
• Decomposition process is initiated by using the decomposePar utility.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 102
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition II
Check contents of decomposeParDict<< cd $FOAM_RUN/damBreakFine_parallel
<< cat -n system/decomposeParDict
18 numberOfSubdomains 4 ; / / No . o f subdomains f o r decomposit ion1920 method simple ; / / Method of decomposit ion2122 simpleCoef fs / / C o e f f i c i e n t s f o r s imple method23 24 n (2 2 1) ; / / Domain s p l i t i n x , y , z d i r e c t i o n s25 de l t a 0 .001; / / Ce l l skew f a c t o r ( De fau l t value = 0.001)26 2728 h i e r a r c h i c a l C o e f f s / / C o e f f i c i e n t s f o r h i e r a r c h i c a l method29 30 n (1 1 1) ;31 de l t a 0 .001;32 order xyz ; / / Order i n which the decomposit ion i s done33 3435 manualCoeffs36 37 da taF i l e " " ;38 3940 d i s t r i b u t e d no ; / / I f data i s d i s t r i b u t e d over severa l d isks4142 roo ts ( ) ;
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 103
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Domain decomposition III
Find available processors<< nproc -all
16
Modify decomposeParDict if necessary<< gedit system/decomposeParDict
Modify the ’numberOfSubdomains’ and the domain split ’n’ accordingly:
18 numberOfSubdomains 9 ; / / No . o f subdomains f o r decomposit ion1920 method simple ; / / Method of decomposit ion2122 simpleCoef fs / / C o e f f i c i e n t s f o r s imple method23 24 n (3 3 1) ; / / Domain s p l i t i n x , y , z d i r e c t i o n s25 de l t a 0 .001; / / Ce l l skew f a c t o r ( De fau l t value = 0.001)26
Some decomposition methodologies1. simple −→ Used for simple geometries by using geometric decomposition.2. hierarchical −→ Similar to simple but with order of direction split.3. scotch −→ Used for complex geometries by minimising the number of processor boundaries.4. manual −→ User specified decomposition for each cell.
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
Decompose domain for parallel execution<< decomposePar
<< tree
<< paraFoam -case processor0
(a) Processor 0 (b) Processor 1
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 105
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Parallel run
• OpenFOAM uses the public domain openMPI implementation of the standardMessage Passing Interface (MPI).
• Syntax for parallel execution on a single node is as follows:<< mpirun -np <no_of_processors> <solver_name> -parallel
Parallel run<< foamJob -parallel -screen interFoam
<< gnome-system-monitor
Visualise results<< ls
<< tree processor0
<< paraFoam -case processor0
Simulation time for parallel run<< tail log
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 thedecomposed 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
Exercise III: Parallel performance
Analyse parallel performance of the interFoam solver.
Clean script<< find $FOAM_TUTORIALS -name Allclean | sort
<< cp$FOAM_TUTORIALS/stressAnalysis/solidDisplacementFoam/plateHole/Allclean .
<< ./Allclean
Parallel speedup
Speedup ratio =Tserial
Tparallel
No. of processors Simulation time (s) Speedup
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
What have we learnt in this tutorial?
X Setup decomposeParDict with appropriate number of processors.
X Use decomposePar utility to decompose to domain.
X Launch a parallel run on a single node using mpirun with ’-parallel’ option.
X Use reconstructPar utility to reassemble decomposed fields and mesh.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 109
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 110
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise IV: Selection of an OpenFOAM solver
Simulate the problem using an appropriate OpenFOAM solver.
Problem description
• Two dimensional, steady state flow.
• Incompressible and turbulent flow.
• Newtonion fluid with viscosity ν = 1× 10−5m2/s.
Case setup
InletU = 10 m/s
Oulet
p = 0 Pa
∂U∂n = 0
WallU = 0 m/s
2.06 m 0.84 m0.206 m
0.508 m 0.332 m
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 111
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise IV: Selection of an OpenFOAM solver
Hints
• Choose a relevant OpenFOAM solver.
• Select an appropriate tutorial as a starting point.
• Don’t start writing input files from scratch.
• Please pay attention to the error messages displayed on your terminal.
• Remember to define the problem variables correctly.
Geometry and meshing
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 112
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise IV: Selection of an OpenFOAM solver
Pressure distribution
Velocity vectors
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 113
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise IV: Selection of an OpenFOAM solver
Increase the initial velocity to [10, 10, 0] m/s
Velocity vectors
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 114
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this tutorial?
X Select an OpenFOAM solver based on the problem definition.
X Understand additional OpenFOAM errors displayed on the terminal.
X Modify parameters in the input files according to our needs.
X Create input files by copying an already existing similar file.
X Use the glyph filter in ParaView to plot vectors.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 115
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training sessionMeshing with blockMeshTwo-phase flow problemOpenFOAM utilitiesParallel computingSteady state flow problemMeshing with snappyHexMesh
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
Steps for creating a snappyHexMesh
1. Creation of a castellated mesh
(a) Background mesh (b) Refinement initiated
(c) Refinement completed (d) Cell removal
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
(e) Region refinement (f) Snapping
3. Addition of layers
(g) Layer addition
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 118
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Surface meshes I
Copy the motorbike tutorial<< run
<< cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike .
<< cd motorike
<< tree constant
Obtain motorbike geometry<< cp $FOAM_TUTORIALS/resources/geometry/motorBike.obj.gzconstant/triSurface
<< gunzip motorBike.obj.gz
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
OpenFOAM utilities for surfaces<< surface[TAB][TAB]
surfaceAdd sur faceFea tu reEx t rac t surfaceMeshExport sur faceSp l i tByPatchsurfaceAutoPatch sur faceFeatures surfaceMeshImport sur faceSpl i tByTopo logysurfaceBooleanFeatures sur faceFind surfaceMeshInfo sur faceSp l i tNonMan i fo ldssurfaceCheck surfaceHookUp surfaceMeshTr iangulate surfaceSubsetsurfaceClean s u r f a c e I n e r t i a su r faceOr ien t surfaceToPatchsurfaceCoarsen surfaceLambdaMuSmooth surfacePointMerge sur faceTransformPointssur faceConver t surfaceMeshConvert su r faceRed is t r i bu teParsur faceFeatureConver t surfaceMeshConvertTest ing surfaceRefineRedGreen
Surface mesh information<< surfaceMeshInfo -help
<< surfaceMeshInfo constant/triSurface/motorBike.obj
nPoints : 132871nFaces : 331653area : 12.1486
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 120
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Surface meshes III
Extract surface features from the geometry<< surfaceFeatureExtract
<< tree
View patches<< surfaceConvert constant/triSurface/motorBike.objconstant/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.
Create background mesh<< blockMesh
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 122
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Castellated mesh II
Run snappyHexMesh in parallel<< decomposePar
<< foamJob -parallel -screen snappyHexMesh
<< less system/snappyHexMeshDict
Local mesh refinement
(a) Level 0 (b) Level 1 (c) Level 2 (d) Level 4
Reconstruct decomposed mesh<< reconstructParMesh -time 1
<< checkMesh
<< tree
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 123
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Castellated mesh III
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 124
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Snapping I
Cell faces are projected down onto the surface geometry.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 125
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Snapping II
Check the quality of snapping process.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 126
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise V: Run motorBike tutorial I
• Clean tutorial: << ./Allclean
• Run tutorial: << ./Allrun
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 127
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Exercise V: Run motorBike tutorial II
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 128
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 129
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this course?
Commands
X Effective usage of bash shell commands.
X Navigate through important directories by using environment variables and aliases.
Basics of OpenFOAM
X Understand the organisation of OpenFOAM installation directory structure.
X Understand the tutorial directory structure of OpenFOAM.
X A brief introduction to programming in OpenFOAM.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 130
Introduction Code Simulations Programming Tutorials Conclusions Appendix
What have we learnt in this course?
Meshing
X Use blockMesh utility to generate simple meshes.
X Use snappyHexMesh utility for generating complex meshes.
X Use mesh conversion utilities in OpenFOAM to use meshes from external software.
Solving
X Use OpenFOAM solvers to run simulations.
X Use various OpenFOAM utilities for parallel simulations.
Visualising
X Use ParaView for post-processing results.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 131
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Outline
1 Introduction
2 The OpenFOAM code
3 OpenFOAM simulations
4 Programming in OpenFOAM
5 Hands-on training session
6 Conclusions
7 Appendix
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 132
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Basic Linux commands I
• cd <directory>
Change to a directory location.
• cd
Change to the home directory.
• cd ..
Go one level up from current directory.
• cd ../..
Go two levels up from current directory.
• mkdir <directory>
Create a directory.
• rm -r <directory>
Remove directory with all its contents.
• pwd
Print the present working directory path.
• ls <directory>
List contents of a directory.
• tree
Print the current directory structure.
• clear
Clears the terminal window.
• ps / topDisplays information about current runningprocesses.
• kill <PID>
Kills a process ID.
• <command> -help
See help for a particular command.
• man <command>
Manual for a particular command, press ’q’to quit.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 133
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Basic Linux commands II
• 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..
• head -10 <file>
Print first 10 lines of a file.
• tail -50 <file>
Print last 50 lines of a file.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 134
Introduction Code Simulations Programming Tutorials Conclusions Appendix
Useful Linux commands for OpenFOAM
• blockMesh -help
See usage of an OpenFOAM command.
• find $FOAM_TUTORIALS -name sampleDict
Search sampleDict file in ’$FOAM_TUTORIALS’ directory.
• find $FOAM_SRC -type f | xargs grep -l "::findNearestCell"
Search the definition of ’findNearestCell’ function in ’$FOAM_SRC’ directory.
• find $FOAM_SRC -type l | xargs grep -l typedef | xargs grep -l"volScalarField;"
Find the typedef , ’volScalarField ’ in ’$FOAM_SRC’ directory.
• find $FOAM_SOLVERS -name "*FvPatch*"
Find solver specific boundary conditions in ’$FOAM_SOLVERS’ directory.
• find $FOAM_SOLVERS -name *.C | xargs grep -l incompressible | xargs grep -lmultiphase
Find ’*.C’ files in ’$FOAM_SOLVERS’ directory which contain the words ’incompressible’ and’multiphase’.
Jibran Haider (PhD Computational Mechanics) OpenFOAM course for beginners 135