July 8, 2010 7

snappyHexMesh Tutorial Part 2

By in OpenFOAM, Studies

Series snappyHexMesh

  1. snappyHexMesh Tutorial
  2. snappyHexMesh Tutorial Part 2
  3. Snap edges with snappyHexMesh

The first snappyHexMesh tutorial is more or less a little extended listing of the information gained from the OpenFOAM User’s Guide. This tutorial gives a brief view on how to setup the background mesh and how refinement regions should be configured. As an example, a container vessel is meshed within this tutorial. No prismatic boundary layer will be used for this tutorial.

Update 26.01.2012:
You can download the geometry of the KRISO Container Vessel (KCS) as STL from here. Thanks to Abe for reminding me to make the download available.

0. Prerequisities

Before we start, we need to take some prerequisities

  1. Check the quality of the STL file. The surface needs to be as smooth as possible, without any humps.
  2. Check the orientation of the STL file. Are the coordinate axes aligned correctly?
  3. Check the position of the STL file. Is the origin of the STL file located, where it is supposed to be?
  4. Check the scaling of the STL file. Guess…
  5. Check the format of the STL file. It should be ASCII and not binary. You can have multiple surface groups in your STL file, but the naming should be without whitespaces, such as
     solid OBJECT
        facet normal 1 -0 0
        [...]

Not all features of snappyHexMesh are described within this article. Either have a look into the tutorials, that come with OpenFOAM, or read the first snappyHexMesh tutorial.

1. Background mesh

Since the entire mesh depends on the background mesh, some thoughts should be spent on the its design. As stated in [1]

The cell aspect ratio should be approximately 1, at least near surfaces at which the subsequent snapping procedure is applied [...]OpenFOAM User’s Guide [1]

Even though one can achieve convergence during the meshing process, if the backgroundmesh does not fullfill this requirement, maintaining the aspect ratio gives notable speedup to the meshing process. Depending on the layout of the computational domain, the number of final cells can be easily adjusted by tweaking the number of cells in the background mesh. Using the levels inside snappyHexMesh often leads to a massive increase of cells, even if the level is increased by only one. But more on this later.

Closup of the background mesh

The layout of the background mesh for the container vessel has been choosen as such, that there is no special refinement region and no grading. The last three cells (upstream of the outlet boundary) have a small grading and a different aspect ratio in x-direction, than all other cells, in order to damp wave before they may be reflected at the outlet. Unfortunately, this cannot be seen easily at this stage of the meshing process. Due to the spatial limits in vertical direction, the ascpect ratio of 1 could not be maintained.

2. snappyHexMeshDict

The next step is to adjust the snappyHexMeshDict, where multiple subdictionaries need to be edited and extended.

2.1 Geometry definition

As the first step, the geometry dictionary need to be updated. Since our ship is stored in a file called kcs.stl, we need to specify this.

kcs.stl
{
     type triSurfaceMesh;
     name hull;
}

Line 3 tells snappyHexMesh, that the STL file contains a triangulated surface mesh and a proper name for that geometry is assigned in line 4, which is used from now on to assign properties to that geometry.

If you need to take multiple phases into account, which is the case for a ship, the area where the free surface is expected needs an additional refinement, in order to resolve the free surface properly. A refinement region is used for this purpose. Several of the so called searchableObjects are implemented in snappyHexMesh, such as

  • searchableSphere
  • searchableBox
  • searchableCylinder
  • searchablePlate

For this tutorial, a searchableBox is used exclusively and defined reading

waterlineBox
{
    type searchableBox;
    min (-50 -20 -0.1);
    max (50 20 0.1);
}

2.2 castellatedMeshControls

Up to now, snappyHexMesh does only know the location and dimensions of some surface and volume objects. For the meshing process, the level of refinement and the direction relative to the surfaces/volumes need to be specified, which is done in the castellatedMeshControls subdictionary.

The refinement levels for the STL surfaces need to be specified. There is no theoretical nessecity to specify two different levels. But since the container vessel has lots of areas where the curvature does not change, larger cells can be applied there. SnappyHexMesh does this automatically. For this example, refinement levels for the ship between 4 and 5 have been choosen.

 refinementSurfaces
{
    hull
    {
         level (4 5);
    }
}
resolveFeatureAngle 60;

By tweaking the resolveFeatureAngle parameter, the areas between the surface refinement levels can be changed indirectly.

Cells that ‘see’ multiple intersections where the intersections make an angle > resolveFeatureAngle get refined up to the maximum level. snappyHexMeshDict from motorBike tutorial

Things to keep in mind:

  • The refinement level of the surface should be as high as the highes refinement of the adjoining volume mesh.
  • The surface mesh should be as homogeneous as possible. Large face size gradiens need to be avoided.

Since we are trying to obtain a volume mesh, we need to specify the refinement for the in section 1 defined volume regions. For our setup, we can specify multiple types of refinements:

  1. Refinement normal to the surface of the geometry. Using this refinement, the mesh resolution near the geometry can be fine. Unfortunately this type of refinement may result in lots of fine cells in areas where we are not interested in, such as above the deck of the ship.
  2. Refinement inside or outside of searchable objects. This type of refinement can be adjusted quite precisely to the special needs.

For this example the volume around the hull is refined using the distance method and the waterlineBox, which has been defined previously, is refined inside that box. Regardless of the method or mode, the refinement levels are specified in the same manner. The first number is the distance from the particular surface and the second number specifies the level, that the enclosed volume is refined up to. It is possible and sometimes practical to define multiple steps of refinement, say a high refinement (level 5) up to one meter away from the hull and a coarser refinement (level 4)  up to 2 meters way from the hull. To achieve this, you have to nest the levels sorted from low distances to high distances.

The inside mode needs a distance as well, but since we want to refine the entire box, a quite high value for this distance can be choosen.

 refinementVolumes
{
    hull
    {
        mode distance;
        levels ((4.5 4));
        //levels ((1 5)(2 4));   // Nested refinement
    }
    waterlineBox
    {
        mode inside;
        levels ((1e4 4));
    }
}

The usage of the locationInMesh parameter is pretty much self-explanatory, but that point must not be placed on a cell face of the background mesh and – of course – inside the mesh.

If snappyHexMesh has finished this meshing step, the refinements are more or less in place and all cells, that are inside the geometry and not inside the desired volume mesh, are removed. But not a single face has been snapped to the surface of the STL file. This happens in the next step

2.3 snapControls

Again, the snap controls are pretty much self explanatory, if you’ve read the tutorial provided by OpenFOAM

3. Survey the result

After having executed snappyHexMesh on a proper background mesh, you obtain up to three time step folders in your case. If you have three, snappyHexMesh has created a prismatic boundary layer on some of the surfaces. This will be covered by an additional tutorial. Since you need to examine your mesh, you should run checkMesh. If you are tweaking some parameters, you should send the output of checkMesh through a pipe into a file. After that run, change the parameters and run snappyHexMesh + checkMesh again, but save the checkMesh output into a different file. Now you can do a diff to figure out the differences.

snappyHexMesh
checkMesh -latestTime > run1
 
snappyHexMesh
checkMesh -latestTime > run2
diff run1 run2

Furtheron the mesh needs to be analyzed in paraFoam, especially the surface of the hull and the region close to that surface.

[1] OpenFOAM User’s Guide v.1.5

Related posts:

  1. snappyHexMesh Tutorial

Tags: , ,

7 Responses to “snappyHexMesh Tutorial Part 2”

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

  2. Jan Theron says:

    Jens

    Awesome site, great info. Where can I get more info on what you do with OpenFOAM and ship hydrodynamics?

    Jan

  3. Jan says:

    Jens

    Canoe, kayak, sailing boat hydrodynamics. Already joined the SIG.

    Jan

    • Jens says:

      And what are you trying to simulate? Is it just ship resistance, or do you wish to account for the ship motion as well?

  4. Abe says:

    Jens:

    I’m trying to follow the tutorials you posted, however, I couldn’t find any link where I can download hull.stl or kcs.stl files. Could you let me know where I can get those files so that I can go through your tutorials?

    • Jens says:

      Hi Abe,

      Thanks for reminding me to make the geometry files available. I’ve added a link to the geometry files in the particular tutorials. I hope, this helps.

      Jens

Leave a Reply