OpenFOAM SnappyHexMesh Tutorial

download OpenFOAM SnappyHexMesh Tutorial

of 44

Transcript of OpenFOAM SnappyHexMesh Tutorial

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    1/44

    Mesh Generation with snappyHexMesh

    Jukka-Pekka Keskinen,

    Ville Vuorinen & Martti Larmi

    Aalto University

    School of Science and Technology

    Internal Combustion Engine Research Group

    Finnish OpenFOAM Users Day22nd April 2010

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    2/44

    Our Motivation for Using snappyHexMesh

    Wall resolved LES: large amount of cells needed close to thewalls.

    Simulation of internal combustion engines: plenty of walls,complex geometries.

    snappyHexMesh has the ability to produce finer grids in areaswhere they are needed: savings in cell numbers.

    Some contacts at KTH have been very happy with snappy.

    Its open, its free and it comes with OpenFOAM.

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    3/44

    Contents of the Presentation

    Before snappyHexMesh

    Cell Splitting

    Snapping

    Surface Layers

    Some Problems with snappyHexMesh

    Comments & Discussion

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    4/44

    Input Needed by snappyHexMesh

    A background mesh: The mesh to be refined in the process

    snappyHexMeshDict dictionary: Located in the system sub-directory of the case Contains keywords for controlling the process

    Some surface to snap: A surface in STL format in constant/triSurface

    sub-directory One of the available generic surface types (sphere, cylinder,

    box, plane and plate) Combination of the two mentioned types

    decomposeParDict dictionary and constant/triSurface

    sub-directory Have to exist even if not needed!

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    5/44

    Background Mesh

    The background mesh defines the extent of the computationaldomain

    Can be created with e.g. blockMesh

    Requirements for the background mesh: Fill the full area of interest Must consist purely of hexahedra Cell aspect ratio should be close to 1 Other aspect ratios might cause convergence problems with

    the algorithm The cell edges must intersect with the input surface

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    6/44

    Background Mesh, View of the XY-Plane

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    7/44

    Background Mesh, A View from an Angle

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    8/44

    Cell Splitting (castellatedMesh)

    The cell splitting procedure of snappyHexMesh is enabled withby setting castellatedMesh true;

    The splitting is controlled with castellatedMeshControlsand some given surface(s) in refinementSurfaces.

    After the splitting is done, cells inside/outside the surface areremoved.

    Additional areas for refinement can be assigned withrefinementRegions and the refinement can be specified tohappen inside, outside or near the given region.

    Different areas can be selected to have different level of cell

    refinement. The changes in the refinement level within themesh will change continuously with a modifiable buffer layer.

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    9/44

    Region Inside the Cylinder is Discarded

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    10/44

    Region Inside the Cylinder is Discarded

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    11/44

    The Mesh After the Cell Splitting Phase, View ofXY-Plane

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    12/44

    The Mesh After the Cell Splitting Phase, A Viewfrom an Angle

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    13/44

    Snapping (snap)

    The snapping phase is activated by setting snap true;

    The snapping phase is controlled with the entries of

    snapControls. In this phase of the process the mesh is deformed to follow the

    input surface.

    A number of cells will be deformed and some of the

    right-angles will not be preserved. Snapping is done iteratively:

    1. Vertices close to the input surface are moved to the surface.2. Relaxation of the internal mesh is computed.3. If the quality parametres are violated, the displacement of the

    violating vertices is reduced.4. Repeat from 2 until quality parametres are satisfied or until setiteration limits are reached.

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    14/44

    The Mesh After the Snapping Phase, View ofXY-Plane

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    15/44

    The Mesh After the Snapping Phase, A Viewfrom an Angle

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    16/44

    Surface Layers (doLayers)

    If one is not satisfied with the mesh after the snapping phase,additional surface layers can be added.

    Surface layer phase of the process is activated by settingdoLayers true;

    The process is controlled with the entries ofaddLayersControls.

    The layers will be added only to a specified patch(es).Different levels of layer addition can be done to differentpatches. The earlier phases of SHM will have created patches from the

    input geometries so these can be used.

    In the example case the surface pipe has spawned a patchnamed pipe_region0.

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    17/44

    Surface Layers (doLayers) The added surface layers are (supposedly) hexahedral. The inserted layer thickness can be specified in absolute units

    or relative to local undistorted cell size. Set withrelativeSize true/false;

    As earlier, this phase too is done iteratively broadly in thefollowing way:

    1. The mesh is projected back from the specified surface patch

    according to the specified thickness.2. Relaxation of the internal mesh is solved.3. If the quality criteria is not met, the projected thickness is

    reduced. Then continue from 2. If quality criteria is satisfied,proceed to 4.

    4. Mesh layers are inserted.5. Another mesh quality check. If the check fails, inserted layers

    are removed and the process is returned to 2.

    h li d i h h dd d

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    18/44

    The Cylinder with Three Added Layers

    Th C li d i h Th Add d L O l

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    19/44

    The Cylinder with Three Added Layers, OnlyAdded Cells Displayed

    3D Vi f h Add d L

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    20/44

    3D View of the Added Layers

    P bl ti Sit ti ith H M h

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    21/44

    Problematic Situations with snappyHexMesh

    Edges (with right angles) do not usually right.

    Extending the input surface past the boundaries of thebackground mesh seems to prevent this on edges located atthe boundaries of the computational domain.

    Making the cell size smaller close to the problematic edgesmight be a way to reduce problems caused by the bad edge

    behaviour. The problematic edge behaviour causes unwanted cell features

    to adjanced cell. In the test case the depth of the perturbationwas about two original cell sizes.

    This is considered to be a major problem with snappyHexMesh.A problem solving software seems to be on sale.

    Th E d f th C li d (E t d d I t S f )

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    22/44

    The End of the Cylinder (Extended Input Surface)

    Th End f th C lind (SHM N l

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    23/44

    The End of the Cylinder (SHM NormalBehaviour)

    Problematic Situations with snappyHexMesh

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    24/44

    Problematic Situations with snappyHexMesh(Continued)

    Layer addition does not work properly near the limits of theinput surface. Border cells will have improperly small surface layer or none at

    all. Take this in consideration when visually examining the mesh as

    a slice is needed to see added layers (paraFoam).

    ParaFoam has a problem with polyhedra. This might makesome cubes look like collection of pyramids.

    According to checkMesh, max non-orthogonality is 36.7 aftercell splitting and 43.6 in the final mesh. This number seems

    too large. Can one trust all mesh statistics?

    Problematic Layer Addition Results Near the End

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    25/44

    Problematic Layer Addition Results Near the Endof the Domain

    The Mesh After the Cell Splitting Phase View of

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    26/44

    The Mesh After the Cell Splitting Phase, View ofXY-Plane

    Close up of One of the Non Cube Looking Cells

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    27/44

    Close-up of One of the Non-Cube Looking Cells

    Final Comments on snappyHexMesh

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    28/44

    Final Comments on snappyHexMesh

    + Able to produce meshes for complex geometries with smalleffort

    + Plenty of controls to play with

    + Open and free

    - Poor documentation and thus the effects of some controlsremain unclear

    - Difficulties with sharp edges

    Bibliography Sources Additional Material and

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    29/44

    Bibliography, Sources, Additional Material andMore Information on SnappyHexMesh

    OpenFOAM User Guide, pp. U-140 U-148. Tutorials in tutorials/mesh/snappyHexMesh/.

    Discussion forums at CFD Online:http://www.cfd-online.com/

    Forums/openfoam-meshing-snappyhexmesh/ Thanks to Ville Tossavainen and Esko Jrvinen for helpful

    comments and suggestions.

    Files etc. used in the presentation are available on request:

    [email protected]

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    30/44

    Part II

    Some Additional Slides

    An Example of a More Dense Grid Done with

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    31/44

    An Example of a More Dense Grid Done withsnappyHexMesh (1 050 040 Cells)

    The End of the Cylinder (Inserted Surface Layers)

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    32/44

    The End of the Cylinder (Inserted Surface Layers)

    Controlling the Mesh Quality

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    33/44

    C g Q y(meshQualityControls)

    The last snappyHexMesh control entry,

    meshQualityControls, contains generic mesh qualitysettings.

    If any of the undoable phase produces violating cells, thephase will be undone.

    Some information given on the entries in the OF manual. Most of the descriptions are poor. Testing of the effects of the quality controls is difficult. Disabling of the controls is well explained.

    Too strict controls might prevent some or all meshing phases.

    Visual inspection is recommended despite the use of thequality controls.

    Some Effects of Quality Controls (in the Case

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    34/44

    Q y (Under Consideration)

    The maximum non-orthogonality of a cell: maxNonOrtho When set to 0, only the cell splitting phase is performed. When set to the interval [4, 12], cell splitting and snapping

    phases are performed but snapping produces poor results. When set to the interval [13, 43], cell splitting and snapping

    phases are performed with reasonable results. When set to [44, 180], all of the phases are performed. The

    quality control is disabled when set to 180.

    Maximum face skewness: maxBoundarySkewness andmaxInternalSkewness

    Highest values that still allow surface layer addition are 1.10

    and 0.45 respectively.

    Some Statistics (Acquired with checkMesh

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    35/44

    ( q

    Mesh Splitting Snapping LayersNo. of cells 1 280 8 880 8 880 13 896

    Hex cells 1 280 7 680 7 680 11 808

    Prism cells 0 0 0 800

    Polyhedral cells 0 1 200 1 200 1 288

    Min. vol. (m3) 3.91103 6.10105 6.10105 4.14105

    Max. vol. (m3) 3.91103 3.91103 3.91103 3.69103

    Tot. vol. (m3) 5.00 4.06 3.92 3.91

    NB: The volume of the input cylinder is 3.93 m3

    .

    The Used blockMeshDict, part 1

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    36/44

    p

    convertToMeters 1;

    vertices

    (

    ( 0 0 0 ) ( 1 0 0 ) ( 1 1 0 ) ( 0 1 0 )

    ( 0 0 5 ) ( 1 0 5 ) ( 1 1 5 ) ( 0 1 5 )

    );

    blocks(

    hex (0 1 2 3 4 5 6 7) (8 8 20) simpleGrading (1 1 1)

    );

    edges

    ();

    The Used blockMeshDict, part 2

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    37/44

    patches

    (

    patch in ( (0 1 2 3) )

    patch out ( (7 6 5 4) )

    wall right ( (2 6 5 1) )

    wall left ( (3 7 4 0) )

    wall up ( (2 6 7 3) )wall down ( (4 5 1 0) )

    );

    mergePatchPairs

    ();

    Geometry Entries

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    38/44

    geometry {

    pipe {

    type searchableCylinder;point1 (0.5 0.5 -1);

    point2 (0.5 0.5 6);

    radius 0.5; }

    innerPipe {

    type searchableCylinder;

    point1 (0.5 0.5 0);

    point2 (0.5 0.5 5);

    radius 0.1; }};

    Entries ofcastellatedMeshControls

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    39/44

    castellatedMeshControls {

    maxLocalCells 1000000;

    maxGlobalCells 2000000;minRefinementCells 0;

    nCellsBetweenLevels 1;

    refinementSurfaces {

    pipe { level (2 1); } }

    refinementRegions {innerPipe {

    mode inside;

    levels ((1 2)); } }

    resolveFeatureAngle 20;

    locationInMesh (0.54 0.52 0.16);

    features (); }

    The used snapControls entry

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    40/44

    snapControls

    {

    nSmoothPatch 6;

    tolerance 10;

    nSolveIter 60;nRelaxIter 10;

    }

    The Used addLayersControls Entry

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    41/44

    relativeSizes true;

    layers { "pipe_region0" {

    nSurfaceLayers 3; } }expansionRatio 2;

    finalLayerThickness 0.5;

    minThickness 0.05;

    nGrow 1;

    featureAngle 60;nRelaxIter 5;

    nSmoothSurfaceNormals 1;

    nSmoothNormals 3;

    nSmoothThickness 10;

    maxFaceThicknessRatio 0.5;

    maxThicknessToMedialRatio 0.3;

    minMedianAxisAngle 130;

    nBufferCellsNoExtrude 0;

    nLayerIter 50;

    The Used meshQualityControls Entry

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    42/44

    meshQualityControls

    { maxNonOrtho 65;

    maxBoundarySkewness 20;maxInternalSkewness 4;

    maxConcave 80;

    minFlatness 0.5;

    minVol -1e13;

    minArea -1;minTwist 0.05;

    minDeterminant 0.001;

    minFaceWeight 0.05;

    minVolRatio 0.01;

    minTriangleTwist -1;

    nSmoothScale 4;

    errorReduction 0.75; }

    A Slice of the Cylinder at 2 Original Cell Lengths

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    43/44

    (0.5 m) from the End

    A Slice of the Cylinder at 1/5 Original Cellh ( ) f h d

  • 8/21/2019 OpenFOAM SnappyHexMesh Tutorial

    44/44

    Lengths (0.05 m) from the End