Applied CFD 1 Lecture 08
Applied CFD 1 Lecture 08
Block 8
Introduction to OpenFOAM
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
OpenFOAM
Universität Stuttgart
▪ Pros:
▪ Free
▪ open-source (access to source code, easy to implement new
features, interesting for academic users and researchers)
▪ Large and active user base (might be largest open-source CFD tool)
▪ Supports many types of multi-physics models
▪ Supports large-scale parallel simulations
▪ Unstructured meshes with arbitrary cell shapes
▪ Many built-in pre and postprocessing tools
▪ Industry-standard tool
▪ Cons:
▪ No graphical user interface
▪ Steep learning curve
▪ Less documentation compared to commercial tools
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
OpenFOAM in industry
Universität Stuttgart
• Automotive industry
• Chemical engineering
• Amazon
• …
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
https://www.youtube.com/watch?v=cSsbcuZvO1I
Fluid Dynamics 1 Thorsten Zirwes
Examples
Universität Stuttgart
OpenFOAM offers
many different
solvers
https://www.openfoa
m.com/documentation
/guides/latest/doc/ope
nfoam-guide-
applications-
solvers.html
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
− Quick outlook for the next weeks: a first look at the source code. Example:
laplacianFoam
− Look at the documentation:
https://www.openfoam.com/documentation/guides/latest/doc/guide-
applications-solvers-basic-laplacianFoam.html
− This solver solves the general transport equation for some scalar T without
convective term
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
fvm: implicit
Correct the velocities
fvc: explicit
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
▪ Let’s start with a simple case and recreate the heat conduction
case from one of the previous tutorials in OpenFOAM
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
− The time directory must contain one file for each variable that we solve an
equation for (in this case, only “T”)
Each file for each variable must contain the following information:
dimensions [0 0 0 1 0 0 0];
Unit
internalField uniform 300;
DT 1e-05;
constant/transportProperties
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
− Unit examples:
− dimensions [0 0 0 0 0 0 0]; means: dimension less
− dimensions [0 1 0 0 0 0 0]; means: [m]
− dimensions [0 0 2 0 0 0 0]; means: [s²]
− dimensions [0 2 -1 0 0 0 0]; means: [m²/s]
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
− The system directory contains the numerical settings for the simulation
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Initial time is t = 0 s
startFrom startTime; (directory “0” must exist)
startTime 0;
stopAt endTime;
endTime 100000; Solver stops at t = 100000 s
writeControl runTime;
Write the simulation results to
writeInterval 5000; the hard drive every 5000 s
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
ddtSchemes
{
ddt(T) Euler;
}
laplacianSchemes
{
laplacian(DT,T) Gauss linear corrected;
}
The first entry means: for the time derivative, use a first-order Euler scheme
𝜕𝑇 𝑇 𝑛+1 − 𝑇 𝑛
≈
𝜕𝑡 Δ𝑡
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
ddtSchemes
{
ddt(T) Euler;
}
laplacianSchemes
{
laplacian(DT,T) Gauss linear corrected;
}
corrected means: Use optional corrections for non-perfect meshes when computing ∇𝑇
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
− Many other options available. When typing a name that does not exist,
OpenFOAM will give an error but also a list of available options (“banana
trick”)
ddtSchemes
{
ddt(T) Euler;
}
laplacianSchemes
{
laplacian(DT,T) Gauss banana corrected;
}
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Solvers
{
T Name of the variable
{
solver PCG;
preconditioner DIC; Linear solver settings
tolerance 1e-06;
relTol 0; Tolerances for the numerical solution
}
}
− The simulation is started by going into the directory of the case (where the
three directories 0, system, constant are located) and typing the name of the
solver laplacianFoam
− When running the simulation, the following output appears in the terminal
The current time How long the solver has been running for
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Which equation is solved (in this case, only one equation for T)
Residual: before solving the system of linear
equations, how well does the temperature from the
previous time step solve the system of equations
from the current time step
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Solvers
Which algorithm is used to solve {
T
the system of linear equations {
solver PCG;
Most algorithms solve the system of linear preconditioner DIC;
equations iteratively. In this case, it took 37 tolerance 1e-06;
relTol 0;
iterations of the PCG solver to reduce the }
residuals below 1e-06 }
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
• Paraview
– Collaboration between Kitware Inc. and Los Alamos National Laboratory
– Visualizes 2D and 3D data
– Usable on single-processor workstations, workstation clusters and
multiple-processor distributed-memory supercomputers
– Processing of structured and unstructured cells
Paraview Server
Visualization Toolkit Open-source C++ library
provides basic visualization
(VTK) and rendering algorithms
OpenGL MPI IceT Etc.
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Graphical user interface
Universität Stuttgart
Menu bar
access the majority
of features
Toolbars
Quick access to most
commonly used features
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Camera Movement
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Load data with a reader
Universität Stuttgart
• Load data
– From menu bar item File>Open…
– Or toolbar icon
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Filters
Universität Stuttgart
• Using a filter
– Activate data object in the Pipeline Browser
– Select filter
– Apply filter
Slice applied to
Visibility second case
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Filters
https://www.paraview.org/Wiki/ParaView/Users_Guide/List_of_filters
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Linux shell/terminal environment
Universität Stuttgart Navigation basics
− Modern Linux operating systems work similarly to Microsoft Windows, where
most programs/applications can be accessed and run with a mouse via a file
browser and its GUI (graphical user interface), without much manual keyboard
typing involved.
− The underlying operating system is based on sets of instruction commands,
which can still be typed into a “shell” or “terminal” window to control file
operations. An example terminal window on Ubuntu Linux may look like this:
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Linux shell/terminal environment
Universität Stuttgart Navigation basics
− The Linux file system is structured as a tree.
− The basic folder is the root directory ‘/’ upon which all other folders
are assembled to form the tree.
− The current folder can be accessed via ‘.’
− The folder below (closer to root) can be accessed via ‘..’
− The current folder can be changed by using the cd (change directory)
command.
− For example if the files are structured like this
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Linux shell/terminal environment
Universität Stuttgart Basic commands
− General help for Linux commands:
command -help (--help)
man command
Or: Search for the command in Google!
− Linux commands are case-sensitive: cd ≠ cD ≠ Cd ≠ CD !!!
− Use auto-completion (tab key)!
− Wildcards (“joker signs”):
− * : all files starting/ending w/, e.g. ls *.dat (list all files ending w/ “.dat”)
− ? : look for a fixed pattern, where character ? could change, e.g.
ls *.?at (list all files ending w/ “Xat”, where X can be any single character)
− Check out the following websites for more Linux info:
− A Linux tutorial and more commands: http://linuxcommand.org/
− A Unix/Linux introduction tutorial from a computer science class
https://aaronbloomfield.github.io/pdr/tutorials/01-intro-unix/index.html
https://aaronbloomfield.github.io/pdr/tutorials/03-04-more-
unix/index.html
− Linux “Cheat Sheet”: https://files.fosswire.com/2007/08/fwunixref.pdf
Applied Computational
Fluid Dynamics 1 − There are many, many more useful websites… Thorsten Zirwes