SnappyHexMesh Tutorial

11
hydroniumion.de About Impressum February 8, 2009 15 snappyHexMesh Tutorial By Jens in General, OpenFOAM, Studies In order to use the automatic meshing tool snappyHexMesh, you have to create a raw background mesh. This can easily be achieved by using blockMesh of OpenFOAM. For this tutorial, I assume that you wish to compute the flow around a body, such as a ship’s hull. The user’s guide can be found here. Create (or copy) the blockMeshDict in $CASE_DIR/constant/polyMesh. It is not necessary to create a fine background mesh, since it will be refined by snappyHexMesh. 1. Basic case directory setup For the execution of blockMesh, the case folder has to be set up correctly. This can either be seen in the User Guide or in lots of tutorials, such as icoFoam/cavity. For the icoFoam solver, an example case-directory can be seen in the screenshot. Goto your case-directory and execute blockMesh This creates the background mesh. One has to mention, that is is necessary to dimension it sufficiently, in order to fit the hull into that mesh and suppress numerical errors, caused by a way to small mesh. 2. Assuming, that you’ve already exported your geometry as an STL-file, you’ve to copy that file to $CASE_DIR/constant/triSurface. For the following tutorial, I assume, that the filename is hull.stl. 3. snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme... 1 von 11 2012-01-20 16:55

Transcript of SnappyHexMesh Tutorial

Page 1: SnappyHexMesh Tutorial

hydroniumion.de

AboutImpressum

February 8, 2009 15

snappyHexMesh TutorialBy Jens in General, OpenFOAM, Studies

In order to use the automatic meshing tool snappyHexMesh, you have to create a rawbackground mesh. This can easily be achieved by using blockMesh ofOpenFOAM. For this tutorial, I assume that you wish to compute the flow arounda body, such as a ship’s hull. The user’s guide can be found here.

Create (or copy) the blockMeshDict in $CASE_DIR/constant/polyMesh. It is not necessaryto create a fine background mesh, since it will be refined by snappyHexMesh.

1.

Basic casedirectory setup

For the execution of blockMesh, the case folder has to be set up correctly. Thiscan either be seen in the User Guide or in lots of tutorials, such asicoFoam/cavity. For the icoFoam solver, an example case-directory can be seenin the screenshot. Goto your case-directory and execute

blockMesh

This creates the background mesh. One has to mention, that is is necessaryto dimension it sufficiently, in order to fit the hull into that mesh andsuppress numerical errors, caused by a way to small mesh.

2.

Assuming, that you’ve already exported your geometry as an STL-file,you’ve to copy that file to $CASE_DIR/constant/triSurface. For the following tutorial,I assume, that the filename is hull.stl.

3.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

1 von 11 2012-01-20 16:55

Page 2: SnappyHexMesh Tutorial

Mesh created byblockMesh

Create (or copy from a snappyHexMesh tutorial) the snappyHexMeshDict in$CASE_DIR/system and insert the standard header into that file:

FoamFile{ version 2.0; format ascii;

root ""; case ""; instance ""; local "";

class dictionary; object autoHexMeshDict;}

4.

Now we can start with creating the necessary dictionaries. First of all, tellsnappyHexMesh, what to do (in a global sense)

castellatedMesh true;snap true;addLayers true;

5.

Secondly, snappyHexMesh needs to know which geometry to use. You can simplyadd just one STL-file, or add add searchableBoxes etc. to this dictionary, ifyou either wish to create a geometry without an STL-file or you like tospecify a region in your mesh, that should be refined specifically. Trying tomap the wake field requires a specific refinement region.

geometry{ hull.stl { type triSurfaceMesh; name HULL; }};

6.

Now we have to configure the settings for the mesh, generated bysnappyHexMesh. This is done in the castellatedMeshControls sub-dictionary. Valid

7.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

2 von 11 2012-01-20 16:55

Page 3: SnappyHexMesh Tutorial

settings and options can be seen in the user-guide (table 5.8) or in thesnappyHexMesh tutorials. An example for that sub-dictionary is the following

castellatedMeshControls{ maxLocalCells 10000000; maxGlobalCells 2000000; minRefinementCells 0; nCellsBetweenLevels 1;

refinementSurfaces{

HULL{

level (4 5);}

}

resolveFeatureAngle 30;

refinementRegions{

HULL{

mode distance;levels ((0.1 5) (0.4 4) (1 2));

}}

locationInMesh (3.11 1.51 -1.1);}

Visualized levels ofregion refinement

The most important part for a working mesh refinement are locationInMesh,which specifies a point inside the mesh generated by blockMesh, but not insidethe geometry (in this case the hull). Secondly, the refinementSurfaces tellssnappyHexMesh, which surfaces are the ones to be refined. The level tag definesminimum and maximum refinement level. The refinementRegions tag sets thelevels of refinement in various distances to the body, this can be seen in thefigure.It doesn’t matter, how much refinementRegions are defined, but the scheme is

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

3 von 11 2012-01-20 16:55

Page 4: SnappyHexMesh Tutorial

always the same.

levels((maxDistance refinementLevel)...)

After the specification of the general meshing and refinement parameters, itis essential to set up controls for the snapping process itself. (cp. [1] table5.9)

snapControls{ nSmoothPatch 3; tolerance 4.0; nSolveIter 30; nRelaxIter 5;}

8.

Patch name in anASCII STL file

The layer addition is controlled by the addLayersControls dictionary, whoseoptions can be seen in table 5.10 of the user guide (cp. [1]). These optionsare skipped for this tutorial, and sample values can be found in the userguide as well. Nevertheless, the layers sub-directory is important to talkabout. As stated in [1], it tells snappyHexMesh which patches “need” layersattached and the number of those layers. Since this is an mesh orientedoption, not the surface geometry has to be specified, but the patch name. Ifyou have an ASCII STL file, you can open simply open it with an texteditorof your choice and the word after solid is the patch name. In my case, thiswas OBJECT.

addLayersControls{ layers { HULL_OBJECT

{ nSurfaceLayers 1; } }}

9.

Finally, controlling the mesh’s quality is a crucial part of the whole meshing10.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

4 von 11 2012-01-20 16:55

Page 5: SnappyHexMesh Tutorial

process. Thus snappyHexMesh provides a dictionary to control the quality, whichis namely the meshQualityControls sub-dictionary. All options related to this canbe found in table 5.11 in the user guide [1].

meshQualityControls{ //Insert your options here}

Model's positioncompared to thebackground mesh

It is essential to get your model into the right position withinyour background mesh, created with blockMesh. You can easily check this bycomparing both, the mesh and the model, with paraFoam or paraview. If youare on a linux machine, simply type

paraFoam & // & to run paraFoam in background

If you calculate on a linux machine and do the postprocessing on e.g. a mac,you have to convert your mesh by

foamToVTK

and then open paraview and your VTK file manually. After that, load yourSTL model into paraview/paraFoam as well. To simplify the orientationwithin the mesh, you should enable the option show cube axes for the mesh.If you have a symmetry plane, it is beneficial to highlight this as well. Afterthat, the picture you get should be in a way similar to mine.

11.

Move the mesh until the model is inside and in its desired position. Thecoordinates are obtained from paraFoam/paraview and the axes shown inthere. Moving the mesh is kind of easy

transformPoints -translate "(x y z)"

One has to state that the coordinates have to be specified in dashes asshown, otherwise the bash will skrew up on that command.

12.

Look again at the model’s position in the mesh. If it is not correct, move it13.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

5 von 11 2012-01-20 16:55

Page 6: SnappyHexMesh Tutorial

again.Now it’s time to execute snappyHexMesh by moving to your case directory andexecute

snappyHexMesh

14.

After having run the meshing without any errors, three new timestepfolders appear in your case directory. The naming differs, depending onyour deltaT in your system/controlDict, but always reflects the first threetimesteps. Opening the case using paraFoam gives a good niceunderstanding, how snappyHexMeshworks. The first timestep (folder 0) shows thebackground mesh, without any refinements. Timestep 1 shows the refinedmesh as well as no faces, that are “snapped” to the geometry. The finalresult is provided by timestep 2.

timestep 0: simplythe backgroundmesh

timestep 1: Refinedmesh, but nosnapped faces

timestep 2: finalresult withsnapped faces

15.

If running the solver, the improved mesh will not be used, because the oldmesh is still written in constant/polyMesh. Hence the folder "lastTimeStep"/polyMeshhas to be copied to constant/polyMesh.

16.

Run your solver17.

[Update]Have a look to the second part of the snappyHexMesh tutorial!

[1] OpenFOAM – The Open Source CFD Toolbox – User Guide, Version 1.5

Tags: CFD, OpenFOAM, snappyHexMesh

iRhino STL exportMan gönnt sich ja sonst nichts

15 Responses to “snappyHexMesh Tutorial”

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

6 von 11 2012-01-20 16:55

Page 7: SnappyHexMesh Tutorial

John says:8. April 2009 at 20:02

Thank you very much about this tutorial! I’m just starting to learnOpenFoam and this tutorial is a big help.

Reply

1.

Jens says:12. May 2009 at 12:34

Thanks alot, John. I’m glad, that I the tutorial was a help to you.

Reply

2.

Ted says:25. October 2009 at 20:07

Thanks for the tutorial! I’ve been playing around with snappyHexMesh to dosome CFD on a design I’m working on. I was curious if you could elaborateon what the “levels” mean under the castellatedMeshControls. Does higherlevels just mean more refinement so going from 2 to 3 just means runningan extra iteration of refinement?

Thanks

Reply

Jens says:26. October 2009 at 09:43

Hi Ted,You are completely right. A higher refinement level means morerefinement in that area. To be honest: I actually don’t usesnappyHexMesh any more, since it does not work that good for my caseof application.

Reply

3.

peter says:28. February 2010 at 19:40

how i can define the integrate the geometry in a project, maybe thishull-project by you ?the problem here is for me that i cant imagine how here has something to goinside and outside, a where this system know from what is what ?thank you for answer

4.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

7 von 11 2012-01-20 16:55

Page 8: SnappyHexMesh Tutorial

(i am a newbie)gruss

Reply

brunno says:15. March 2010 at 22:31

Thank you so much for this tutorial !How did you solve the problem with the edges ? You implemented *.eMeshfile into snappyHexMesh ?

Thanks again

Reply

5.

marine says:20. April 2010 at 17:38

Hello!

I was wondering if you have some experience with the “addlayer” part ofsnappy, I’m meshing a hull just as you did but I’m having a really hard timeto set the parameters of the boundary layer. If you have any advice it wouldbe welcome!thank you!

Marine

Reply

6.

Salome mesh with NETGEN 1D-2D-3D for OF -- CFD Online DiscussionForums says:13. June 2010 at 14:18

[...] giving snappyHexMesh a try. Thanks for the hint. Is there a goodtutorial for it? I found this one: http://www.hydroniumion.de/allgemein…mesh-tutorial/ Is there a possibility to define edges/surfaces inSalome (e.g. with groups) that will be refined [...]

Reply

7.

Ulisses says:14. June 2010 at 23:11

Thanks for the tutorial!!!! You help me a lot!!!

Reply

8.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

8 von 11 2012-01-20 16:55

Page 9: SnappyHexMesh Tutorial

Jens says:7. July 2010 at 17:37

First of all, I need to apologize for the immense delay time. I somehow lostthis blog out of sight.

@peter: I’m not sure if I get your question correctly. You want to know, howsnappy knows which cells are inside the domain and which are not? This isdone by the locationInMesh entry in your snappyHexMeshDict.

@brunno: I did not solve the issue with snappy, that edges cannot beresolved with a sharp line. AFAIK, the *.eMesh file is not implemented (yet).

@marine: Yes, I have some experience with the addLayers. What are yourproblems with the boundary layer construction?

Reply

9.

snappyHexMesh Tutorial Part 2 | hydroniumion.de says:8. July 2010 at 18:35

[...] first snappyHexMesh tutorial is more or less a little extended listing ofthe information gained from the OpenFOAM User's Guide. [...]

Reply

10.

Tomislav says:1. December 2010 at 14:02

:p I found the explanation to the “locationInMesh”! Thanks!

Reply

11.

Ali says:27. January 2011 at 18:05

Can anyone please desribe what does refinement level mean in refinementregions?

Reply

12.

Jens says:27. January 2011 at 18:09

The refinementLevel describes how many times each edge of a cell is slicedinto two parts. For a hexahedral cell, a refinementLevel of 1 gives 8 cells (2times 2 times 2) and so on.

13.

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

9 von 11 2012-01-20 16:55

Page 10: SnappyHexMesh Tutorial

Reply

Justin says:10. May 2011 at 22:35

Thank you very much! It helps a lot!

Reply

14.

Leave a Reply

Name (required)

Mail (will not be published) (required)

Website

Submit Comment

Categories

Apple (11)General (21)Me (28)OpenFOAM (8)Studies (12)Travel (12)Web (14)Windsurfing (8)

Tags

Affen Amazon Ansys Apple BibDesk Braii CFD DST Excel FEM Fundstück Gardenroute Gewinnspiel

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

10 von 11 2012-01-20 16:55

Page 11: SnappyHexMesh Tutorial

gnuplot Gravis I am Legend iPod JBL Kapstadt LaTeX Leopard linux Literatur Long

Street MacBook Air MikTeX nur so Octave OpenFOAM Ostern OS X Photoshop Pinguine

portable Quatsch Schelde sed snappyHexMesh Software Spots Strauß StudienarbeitV&A Waterfront Windsurfing Zubehör

Archives

November 2010 (1)October 2010 (1)September 2010 (1)July 2010 (3)November 2009 (3)July 2009 (1)February 2009 (2)January 2009 (3)December 2008 (2)November 2008 (1)October 2008 (1)September 2008 (1)August 2008 (1)July 2008 (1)May 2008 (1)April 2008 (4)March 2008 (2)January 2008 (8)December 2007 (4)November 2007 (7)October 2007 (8)September 2007 (5)August 2007 (8)

Top RSS HomeFifty Fifth Street theme by Tammy Hart DesignsPowered by WordPress

snappyHexMesh Tutorial | hydroniumion.de http://www.hydroniumion.de/general/snappyhexme...

11 von 11 2012-01-20 16:55