introductory openfoam from 17th to 21st february, 2014 ... · matteo bargiacchi...

22
Matteo Bargiacchi [email protected] “This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM ® and OpenCFD ® trade marks.” Introductory OpenFOAM ® Course From 17th to 21st February, 2014

Upload: trancong

Post on 26-Apr-2018

222 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Matteo [email protected]

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Introductory OpenFOAM® Course

From 17th to 21st February, 2014

Page 2: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Today’s lecture

1. Post-processing tools: paraFoam and Paraview, differences and basic commands;

2. How to export animations from Paraview;3. More on post-processing complex flow patterns;4. Python scripting in Paraview 4.1.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 3: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Acknowledgements

These slides and the tutorials presented are based upon personal experience, OpenFOAM® source code, OpenFOAM® user guide, OpenFOAM® programmer’s guide, and presentations from previous OpenFOAM® training sessions and OpenFOAM® workshops.

We gratefully acknowledge the following OpenFOAM® users for their consent to use their material:• Hrvoje Jasak. Wikki Ltd.• Hakan Nilsson. Department of Applied Mechanics, Chalmers University of

Technology.• Eric Paterson. Applied Research Laboratory Professor of Mechanical

Engineering, Pennsylvania State University.• Tommaso Lucchini. Department of Energy, Politecnico di Milano.• Rupert Fisch. Technische Universitaet Muenchen.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 4: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Today’s lecture

1. Post-processing tools: paraFoam and Paraview, differences and basic commands;

2. How to export animations from Paraview;3. More on post-processing complex flow patterns;4. Python scripting in Paraview 4.1.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 5: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Paraview and paraFoam

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

● Paraview is a post-processing environment able to read and process a vast variety of formats.

● ParaFoam is a specific version of Paraview (3.14) able to directly read the output produced by OpenFOAM® without intermediate conversion

● The differences are few:- paraFoam is able to manage results from different processors without reconstruction- paraview needs the domain to be reconstructed (otherwise each single processor should be singly opened) and converted to a readable file format

reconstructParfoamToVTK

- paraview from version 4.1 onwards has a very instructive Start Trace-Stop Trace tool

Page 6: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

A simple cavity 3D case

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

● Open the cavity simulation folder and runparaFoam

or

● Open the blended wing body simulation folder and runFoamToVTK

● Run paraview and import the *.vtk files

Page 7: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Hands-on session

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

● Open the Blended Wing Body simulation folder and runparaFoam

or

● Open the blended wing body simulation folder and runFoamToVTK

● Run paraview and import the *.vtk files

Page 8: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Group slices and plot a velocity profile

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 9: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Show Mach threshold and streamlines

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 10: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Hands-on session

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

In the course’s directory ($ptofc) you will find many tutorials (which are different from those that come with the OpenFOAM® installation), let us try to go through each one to understand and get functional using OpenFOAM®.

If you have a case of your own, let me know and I will try to do my best to help you to setup your case. But remember, the physics is yours.

Page 11: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Today’s lecture

1. Post-processing tools: paraFoam and Paraview, differences and basic commands;

2. How to export animations from Paraview;3. More on post-processing complex flow patterns;4. Python scripting in Paraview 4.1.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 12: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Hands-on session

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

● Open the cylinder2D simulation folder and runparaFoam

or

● Open the blended wing body simulation folder and runFoamToVTK

● Run paraview and import the *.vtk files

Page 13: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Today’s lecture

1. Geometry and Mesh generation using Salome: a mixing elbow created inside the GUI;

2. Hands on to create a simple geometry inside the GUI;3. Learn how to program in python to create script for

Salome and automatize the pre-processing phase;4. Import 2D images and create 2D meshes for OpenFOAM®;

5. Import geometries and create a meshed domain of computation;

6. Post-processing tools: paraFoam and Paraview, differences and basic commands;

7. How to export animations from Paraview;8. More on post-processing complex flow patterns;9. Python scripting in Paraview 4.1.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 14: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

The Q-criterion was named after the second invariant of the velocity gradient tensor u by Hunt [1988] (see also Dubrief [2000])∇

Visualize flow patterns: The Q criterion

where

positive Q isosurfaces isolate areas where the strength of rotation overcomes the strain, thus making those surfaces eligible as vortex envelopes

Page 15: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Q-criterion and streamlines

Northrop YF17: iso-surfaces of Q=10^5 colored according to pressure and streamlines colored according to velocity magnitude

Page 16: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Q-criterion and streamlines

Open /Day2/paraview/yf17Run foamToVTK or directly run paraFoam

Launch paraview and open vtk files

Create a streamTracer filter with the parameters:

● Point source: (-3.55, 0.55, 0.55)● Number of Points: 20● Radius: 0.1

Create a Gradient Of Unstructured Data Set filter computing Vorticity and Q-criterion from the velocity field

Create a Contour filter with positive Q iso-surfaces (choose a value around 10'000)

Page 17: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

The Calculator Filter

Let us calculate the Density field from Pressure and Temperature distributions.

Set a Calculator filter and define the following expression with the Result Array Name “density”:

p/(287.3*T)

Set another Calculator filter to check the post-processed field “density” against the calculated field “rho” with the following expression:

(density-rho)/rho

Page 18: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Today’s lecture

1. Post-processing tools: paraFoam and Paraview, differences and basic commands;

2. How to export animations from Paraview;3. More on post-processing complex flow patterns;4. Python scripting in Paraview 4.1.

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

Page 19: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

The Python Shell

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”

The Python shell in paraview is a powerful plugin to automatize post-processing phases.

From version 4.0 onwards a Start Trace / Stop Trace utility is available

Unfortunately paraFoam (running on version 3.14) is not compatible with different versions. In order to use version 4.1 the environment variable should be cleaned in the following way:

● comment # source $HOME/OpenFOAM/OpenFOAM-2.2.x/etc/bashrc● Log Out and Log In again

Otherwise take advantage of the paraview module inside Salome 7.3.0

Page 20: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Trace an action and run a *.py script

From Tools menu click on Start Trace

DO ONE SIMPLE THING...

...and Stop Trace.

Understand the output visualized in a pop-up window and copy only the relevant snippets in your *.py script beginning with:

from paraview.simple import *

From Tools menu, click on Python Shell;Then Run Script ;

Page 21: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Thank you for your attention

Page 22: Introductory OpenFOAM From 17th to 21st February, 2014 ... · Matteo Bargiacchi bargiacchi@wolfdynamics.com ... • Hrvoje Jasak. Wikki Ltd. • Hakan Nilsson. Department of Applied

Disclaimer

“This offering is not approved or endorsed by OpenCFD Limited, the producer of the OpenFOAM software and owner of the OPENFOAM® and OpenCFD® trade marks.”