0% found this document useful (0 votes)
8 views

Applied CFD 1 Lecture 08

Applied Computational Dynamics 8

Uploaded by

Mila Rd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Applied CFD 1 Lecture 08

Applied Computational Dynamics 8

Uploaded by

Mila Rd
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Universität Stuttgart

Block 8

Introduction to OpenFOAM

Applied Computational Fluid


Dynamics 1
Universität Stuttgart

▪ While our MATLAB code implements everything we need to perform fluid


simulations, there are a lot of limitations
▪ Simple/structures meshes
▪ Bad performance
▪ No multi-physics capabilities. But basic principles are the same!

▪ Therefore, we will now look at a real industry-standard CFD Code: OpenFOAM


and see how we can apply the knowledge from our MATLAB implementation
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

− OpenFOAM: Open Source Field Operation and Manipulation

− Open-source toolbox for CFD and multi-physics problems written in


C++ under the General Public License (GNU/GPL) using the finite
volume method

− Developed by OpenCFD Ltd at ESI Group:


https://www.openfoam.com/
− And by the OpenFOAM Foundation:
https://www.openfoam.org/
− And by the Foam Extend-Project
https://sourceforge.net/projects/foam-extend/

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

Adjoint sensitivities for drag


Applied Computational
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

− The source code can be found in the OpenFOAM installation directory, or


online here: https://develop.openfoam.com/Development/openfoam/-
/tree/master/applications/solvers/basic/laplacianFoam?ref_type=heads
− We will take a more detailed look in the coming weeks

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

OpenFOAM C++ code Our MATLAB code

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

− Or: Looking at the pressure correction in pimpleFoam


− https://develop.openfoam.com/Development/openfoam/-
/blob/master/applications/solvers/incompressible/pimpleFoam/pEqn.H?ref_t
ype=heads

Calculate rA and HbyA

Set up the pressure correction equation

fvm: implicit
Correct the velocities
fvc: explicit

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

OpenFOAM Case Structure

How to run a simulation

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

MATLAB: 20x20 cells OpenFOAM: 100x100 cells

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

− Each OpenFOAM case consists of three directories


− A time directory (usually for the initial time t = 0 s)
− A system directory (containing all numerical information)
− A constant directory (containing information about the mesh and physical
models)

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;

boundaryField Initial condition


{
right
{
type zeroGradient;
}
left
{
type fixedValue; boundaries
value uniform 300;
}
// …
Applied Computational
Fluid Dynamics 1
} Thorsten Zirwes
Universität Stuttgart

− The constant directory contains the information about the computational


mesh in polyMesh (automatically generated) and additional files
containing the physical model (depends on the chosen solver/problem)

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

How to generate the mesh


(discussed in Applied CFD II)
How to run the simulation

How to discretize derivatives

How to solve equation

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

deltaT 500; Time step

writeControl runTime;
Write the simulation results to
writeInterval 5000; the hard drive every 5000 s

So in this example, we take one time step of 1 s, then stop


the simulation and write out the temperatures at t = 1 s

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

How to discretize the different terms of each equation

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

How to discretize the different terms of each equation

ddtSchemes
{
ddt(T) Euler;
}
laplacianSchemes
{
laplacian(DT,T) Gauss linear corrected;
}

The second entry determines how the diffusion term is discretized

Gauss means: apply Gauss’ theorem: ∫ ∇ ⋅ 𝐷𝑇 ∇𝑇 d𝑉 → ∫ 𝐷𝑇 ∇𝑇 𝑓 d𝐴 → ෍ 𝐷𝑇 ∇𝑇 𝑓 Δ𝐴𝑓


𝑓
linear means: Use linear interpolation to compute 𝐷𝑇 at the cell faces

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

How to solve the system of linear equations 𝐴 𝑥Ԧ = 𝑏

In MATLAB, we used the command x = A\b


In OpenFOAM, we have more control over which algorithm is used to
solve the system of linear equations

Solvers
{
T Name of the variable
{
solver PCG;
preconditioner DIC; Linear solver settings
tolerance 1e-06;
relTol 0; Tolerances for the numerical solution
}
}

Here, we are using a preconditioned conjugate gradient solver (PCG)


Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

− 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

Difference between the two is deltaT

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

Visualization of simulations with Paraview

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

pvpytho ParaWe CustomAp


Client n
Catalyst
b p

Qt Widgets, Python Wrappings

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

• The workflow in Paraview consists of three steps


– Read in data
– Apply filters
• Generate features
• Extract features
• Derive Features

– Rendering data to get an image


• Texture
• Shadow
• Reflection
• Refraction

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Graphical user interface
Universität Stuttgart

Toggle on and off the toolbars: View>Toolbars

Menu bar
access the majority
of features
Toolbars
Quick access to most
commonly used features

Pipeline Browser advanced toggle


Pipeline: manages Shows and hides
reading and filtering. advance controls
3D
Pipeline browser allows view
to view the structure and
select objects.
Present data:
• view
Properties panel • interact
View and change • explore
parameters of the
current pipeline
object.
Properties are by
default coupled with
an Information tab Information panel

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Camera Movement
Universität Stuttgart

• Manipulate the 3D view

• Drag the mouse over the view

– left mouse button: rotate, pan

– middle mouse button: move

– right mouse button: zoom

• By default differences between 2D and


3D mode

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

Various file formats are available

• Case data can be loaded by opening the case.foam in the working


directory

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Filters
Universität Stuttgart

• Data can be analyzed using filters


• Filters can be applied on
– Data sources
– Data reader
– Filtered data

• Using a filter
– Activate data object in the Pipeline Browser
– Select filter
– Apply filter

• Filtered data is added to the visualization pipeline

Slice applied to
Visibility second case
Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart
Filters

• Frequently used filters


– Listed in menu Filters > Common
– Also available in toolbar Common

• For an overview of available filters select Alphabetical in the Filters menu


• Grayed out filters work only on specific type of data
• Input restrictions are listed in the Paraview user guide

https://www.paraview.org/Wiki/ParaView/Users_Guide/List_of_filters

Applied Computational
Fluid Dynamics 1 Thorsten Zirwes
Universität Stuttgart

− Working with Linux

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

one can navigate into the Tutorial folder via:


cd /home/user/OpenFOAM/OpenFOAM-v2306/run/Tutorials (absolute path)
Switching to the folder below can be done via:
cd /home/user/OpenFOAM/OpenFOAM-v2306/run/ (absolute path) or
Applied Computational cd .. (relative path)
Fluid Dynamics 1 Thorsten Zirwes
Linux shell/terminal environment
Universität Stuttgart Basic commands
− ls : list contents of a folder (has many additional flags)
− touch filename : create an (empty) file (or: update its modification date)
− mkdir / rmdir foldername : make/delete a folder (rmdir: only empty
folders)
− cp filename copyname : copy a (single) file
− cp -r foldername copyname : copy a folder
− mv arg1 arg2 :
a) rename arg1 (a file/folder) to arg2 (another file/folder)
b) move arg1 (a file/folder) to location arg2 (i.e. copy and delete the original)
− rm filename : delete a file (Caution, NO trash, the file will be GONE)
− rm -r foldername : delete a folder and all its sub-folders (CAUTION!!!)
− find : find things…try this out!
− grep / fgrep : search in text files…crucial for programming…try this out!
− nautilus . : open a file browser in the current folder
− gedit filename : open a text file in a simple editor

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

You might also like