pre processing

40
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: michael-briggs

Post on 12-Apr-2016

220 views

Category:

Documents


1 download

DESCRIPTION

OpenFoam-Introdction

TRANSCRIPT

Page 1: Pre Processing

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: Pre Processing

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;

“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: Pre Processing

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: Pre Processing

Salome is an Open Source Integration Platform for Numerical Simulations based on the Hierarchical Data Format (*.hdf)

● Geometry Module● Meshing Module● Post-processor Module (Paraview)● Mesh Adaptation Module● Mesh and field data model and associated tools● Supervision and Job Manager Module

http://www.salome-platform.org/

How to install: Universal binary package is a self-extracting archive. Just change the permissions

chmod a+x Salome-V7_3_0-LGPL-x86_64.run

and execute it to install SALOME. The installer supports options, run it with "-h" to see full list of available options.

What is Salome?

Page 5: Pre Processing

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;

“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 6: Pre Processing

In this tutorial we would like to create the geometry of a mixing elbow.

The steps are briefly summarized in the following slides and the whole procedure is shown in the attached video tutorials.

In this tutorial

Page 7: Pre Processing

In a nutshell: watch “mixingElbow-geometryGeneration.avi” to analyze the complete procedure

● Go to the Geometry Module;● File> Preferences> Origin & Base Vectors: tick Auto Create

(this option will be saved for the next sessions);● Create a Disk with radius 0.5;● Create the wire;● Extrude the disk along the wire;● Create a second Disk with radius 0.25;● Extrude the second disk along the Z vector;● Fuse the pipes into a unique shell;● Explode the shell into faces;● Group and rename the faces (walls, inlets, outlet);● Save as Hierarchical Data Format (HDF).

Geometry generation

Page 8: Pre Processing

Mesh generation

In a nutshell: watch “mixingElbow-meshGeneration.avi” to analyze the complete procedure

● Go to the Mesh Module;● Create Mesh of the main shell (Fuse_1);● Assign a set of Hypothesis with NETGEN algorithm (3D

automatic Tetrahedralization with viscous layer);● Create sub meshes if not satisfied from some sections;● Create groups of nodes (walls, inlets, outlet); ● Inspect the inside elements by clipping the mesh with a

section plane (from the mouse right-click menu);● Check the mesh quality parameters (Controls);● Export Mesh as I-DEAS Universal Format (UNV).

Viscous Layer hypothesis can be used with "Tetrahedron(Netgen)" and "Hexahedron (i,j,k)" algorithms only.

Page 9: Pre Processing

The expected result

Page 10: Pre Processing

Inside a folder where the “system” folder is already defined with its files run :

ideasUnvToFoam $MESH_NAME.unv

to create the following files:- constant/polymesh/boundary- constant/polymesh/faces- constant/polymesh/neighbour- constant/polymesh/owner- constant/polymesh/points

● Define the proper type of boundary in the newly created file “boundary” (patch is the default choice)

Export to OpenFOAM

“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 11: Pre Processing

The mesh is now ready to be used

● Run checkMesh in order to check that everything went smooth

● Create the proper initial conditions in the folder “0”

● Define the proper trasportProperties in “constant”

● Now you are ready to run icoFoam

Run the 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.”

Warning● Be aware that sometimes a mesh refinement is required to let the

mesh generation algorithms reach convergence: a too coarse mesh might not be created at all!

Page 12: Pre Processing

Be aware that assigning a predefined set of hypothesis with NETGEN might not be a good choice if a good quality mesh is required. A more detailed definition of the parameters may be necessary.

Netgen algorithm does not strictly follow the input parameters. The actual mesh can be more or less dense than required. There are several factors in it:

● NETGEN does not actually use "NbOfSegments" parameter for discretization of edge. This parameter is used only to define the local element size (size at the given point), so local sizes of adjacent edges influence each other.

● NETGEN additionally restricts the element size according to edge curvature.

● The local size of edges influences the size of close triangles.

Other warnings

“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 13: Pre Processing

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;

“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: Pre Processing

In this tutorial we would like to create a simple geometry of a bullet-like object and create the mesh around the bullet oriented to a supersonic simulation with shock waves.

The steps are briefly summarized in the following slides and the whole procedure is shown in the attached video tutorials.

In this tutorial

Page 15: Pre Processing

In this tutorial

The outer cone should be an internal face belonging to the fluid domain. The back of the bullet is a spherical cap with radius equal to the small cone apothem and centered in (0,0,0)

Page 16: Pre Processing

Guidelines to geometry generation

● Create 2 cones with the apex in (0,0,0) from Vertex + Vector definitions;

● Create a sphere centered in (0,0,0) with the proper radius● Create 2 cylinders:

- the outer domain (R=4, H=10),- a cylinder to be used as a tool to create the spherical cap from the sphere;

● Create the spherical cap (Cut);● Create the bullet (Fuse);● Create the fluid domain (Cut);● Explode the curved surface from the big cone;● Create a partition of the fluid domain with the surface

extracted;● Create groups from New Entity > Group > Create Group

(inlet, outlet, freeSlip, refinedFace, walls)

Page 17: Pre Processing

Guidelines to mesh generation

● Create Mesh with NETGEN-1D2D3D, full parameters

● Set fineness to Very Fine● Set Max Mesh Size to 0.5● Define Local Sizes on the

bullet surface and on the refined surface to be respectively 0.05 and 0.15

● Compute the mesh

● Check the mesh quality in Controls menu (right click)● Create groups of boundary cells on Geometry Shapes● Export the mesh to *.unv file

Note: Second Order option should not be ticked (OpenFOAM®

and FVM in general does not support 2nd order cells)

“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 18: Pre Processing

The expected result

“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: Pre Processing

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 20: Pre Processing

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;

“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 21: Pre Processing

In order to learn Python commands for Salome go to:

● http://docs.salome-platform.org/salome_7_2_0/gui/GEOM/index.html● http://docs.salome-platform.org/salome_7_2_0/gui/SMESH/index.html● http://docs.salome-platform.org/salome_7_2_0/gui/NETGENPLUGIN/

for Geometry, Meshing and NETGEN module respectively. But, why scripting?

1) Salome has an .hdf based GUI (non-parametric). This means that you cannot modify a parent object without deleting forever all his children!

2) It is possible to generate a mesh using Salome in batch mode! 3) It is therefore possible to auto-generate meshes

with different parameters or for different geometries inside an automated optimization loop!

The Python shell in Salome: TUI

Page 22: Pre Processing

Create the bullet mesh via Python scripting

“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.”

So, let us create a simple script that is able to do:● Clean the OpenFOAM® case directory;● Create the mesh for the previously created bullet geometry with user-

defined parameters (angle of the bullet cone, position of the refined surface, incidence of the bullet);

● Export the mesh to *.unv;● Check the mesh quality;● Prepare the boundary file with the correct name of the patches;● Run the case.

A long shot? Not at all.....

Note the “-t” option whenSalome is called in batch mode

Now we “only” need to write down the bullet.py script....

Page 23: Pre Processing

Init and parameters definition

Import the libraries …......

…....and set up the parameters.

Please note that Python scripts before Salome 7.2 excluded shall begin with a snippet of code like:

import geompygeompy.init_geom(theStudy)

Page 24: Pre Processing

Create the cones and define the refinement face

Page 25: Pre Processing

Create a sphere and 3 cylinders

Page 26: Pre Processing

Compose everything together

Page 27: Pre Processing

Compose everything together

Page 28: Pre Processing

Create groups on geometries

Page 29: Pre Processing

Create the mesh (i.e. define methods and hyps.)

Note the “warning” symbol: the mesh has not been computed yet....

Page 30: Pre Processing

Compute, create BC and export

Setup the desired initial conditions in the folder “0” and the desired simulation parameters in “system” and you are now ready to run whole case...

Page 31: Pre Processing

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;

“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 32: Pre Processing

*.jpg import

“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.”

Let us import the Wolf Dynamics logo into Salome with the built in tools Import Picture in Viewer and Shape Recognition

Note that these tools are in development phase and might not provide the expected results. Use free tools (like Engauge Digitizer) that allow manual definition and healing of the recognized shape to import 2D images when the quality is not good enough.

Page 33: Pre Processing

Create the fluid domain

“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.”

● explode the end vertexes and the wire of the contour

● heal the geometry at the top right corner creating an additional edge.

● build a closed wire● build a face● create a rectangle

around the shape● cut the domain using

the wolf as a tool● create the groups of

boundaries

Page 34: Pre Processing

Create the 2D mesh

“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.”

We are now ready to switch to the mesh module.

● Create Mesh with NETGEN 2D-1D

● Set max size to 30● Set max size on local

edges to 1● Compute mesh● Define groups on filter● Extrude the mesh nodes

lying on geometry

Note the generated groups of faces:

When exported to *.unv the non defined faces will be set as default and shall be defined as empty

Page 35: Pre Processing

Assess the quality of the mesh

“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.”

Navigate to Control inside the right click menu and evaluate the mesh parameters:

● Skewness● Area● Aspect ratio

Refine the mesh if not satisfied

Page 36: Pre Processing

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;

“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 37: Pre Processing

Import an *.stl geometry and create the domain

“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.”

● Import the cylinder.stl navigating to File > Import

● A shell is created● Create a solid out of the

shell● Create the bounding box● Cut the box using the

solid as a tool● Explode the faces and

create groups

Page 38: Pre Processing

Import an *.stl geometry and create the domain

“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.”

● Switch to the mesh module

● Create Mesh with the desired refinement

● Create groups on geometry or on filter

Page 39: Pre Processing

Thank you for your attention

Page 40: Pre Processing

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.”