0% found this document useful (0 votes)
16 views67 pages

3D Cylinder Mesh Refinement Guide

Uploaded by

prajwolbohara12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views67 pages

3D Cylinder Mesh Refinement Guide

Uploaded by

prajwolbohara12
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

snappyHexMesh guided tutorials

3D Cylinder – External flow mesh

1
snappyHexMesh guided tutorials

Case 1
3D Cylinder – External flow mesh + edge
refinement + boundary layer

2
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh

• Our first case will be a mesh around a cylinder.


• This is a simple geometry, but we will use it to study all the meshing steps and introduce a few
advanced features.
• This case is located in the directory $TM/M1_cyl/

3
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh
• We are going to explore all features of snappyHexMesh.

Getting a basic mesh without resolving edges Resolving edges

Surface refinement and Region refinement and boundary layer meshing


curvature refinement control

4
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh

Sharp angle/edges

Sharp angle/edges No edge refinement Edge refinement

• In this case, the base geometry has sharp angles.


• It is extremely recommended to resolve these features.
• We will use this case to illustrate a basic setup with edge refinement.
5
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh

Sphere with no edge refinement Cylinder with edge refinement Cylinder with no edge refinement

• However, if the geometry does not have sharp angles, you do not need to do this extra step.
• In the end, it is up to you to decide if you want to resolve the sharp angles.
• However, it is extremely recommended to resolve sharp angles (if they exist).
• In the left figure there is no need to use edge refinement as there are no sharp angles.
• In the mid figure we used edge refinement to resolve the sharp angles.
• In the right figure we did not use edge refinement, therefore we did not resolve well the sharp
angles.
6
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh

• This case is located in the directory $TM/M1_cyl/C1


• In this case we are going to use edge refinement and different surface refinement levels.

7
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we enable edge refinement and control curvature refinement?
• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{

...
...
...

//Local curvature and


//feature angle refinement
resolveFeatureAngle 30; To control curvature refinement

...
...
...

//Explicit feature edge refinement


features
(
{
• To enable and control edge
file “[Link]";
refinement level
level 0;
} • This is equivalent to levels ((0 0))
); • Other example,
• level 2 is equivalent to
...
levels ((0 2))
...
...

} 8
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we enable edge refinement and control curvature refinement?
• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{

...
...
...

//Local curvature and


//feature angle refinement
resolveFeatureAngle 30; To control curvature refinement

...
...
...

//Explicit feature edge refinement


• It is also possible to control edge refinement features
using distance mode as follows, (
{
• levels ((distance level))
file “[Link]";
• Where distance specifies the distance from the levels ((0.1 5) (0.2 4));
feature and level specifies the refinement level. }
• For multiple refinement levels, the distances );
need to be specified in increasing distance and
decreasing refinement level, such as, ...
...
• levels ((0.1 5) (0.2 4));
...

} 9
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

How resolveFeatureAngle works?

angle < resolveFeatureAngle


If angle is more than resolveFeatureAngle
No curvature refinement
the adjacent STL faces will be marked for refinement

angle

resolveFeatureAngle

SOLID MODEL SIDE – STL FILE

0: mark the whole surface for refinement


180: do not mark any STL face for refinement

10
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

How resolveFeatureAngle works?

angle > resolveFeatureAngle


If angle is more than resolveFeatureAngle
Curvature refinement
the adjacent STL faces will be marked for refinement

angle

resolveFeatureAngle

SOLID MODEL SIDE – STL FILE

0: mark the whole surface for refinement


180: do not mark any STL face for refinement

11
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we control surface refinement?
• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
• You always need to define the {
surfaces.
...
• If you do not define the surfaces, ...
snappyHexMesh it will mesh
inside and outside the geometry
...

//Surface based refinement


refinementSurfaces
{
banana_stlSurface • To control surface refinement.
{ • The first digit controls the global
level (2 4); surface refinement level, and the
} second digit controls the curvature
refinement level, according to the
} angle set in the entry
resolveFeatureAngle
... • The second digit besides curvature
... refinement, it also controls
... refinement at intersection of
surfaces.
}

12
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we create refinement regions?
• In the file snappyHexMeshDict, look for the following entry:

geometry
{
...
...
...

refinementBox Name of refinement region


{
type searchableBox; Geometrical entity type.
min ( -2 -2 -2); This is the zone where we
max ( 2 2 2); want to apply the refinement
}

...
Dimensions of geometrical entity
...
...
};

13
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we create refinement regions?
• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{
...
...
...

refinementRegions
{ Name of the region
refinementBox created in the geometry section
{
mode inside; Refinement using inside mode.
level 1; Other options: distance, outside
}
}
Refinement level
...
...
...
}
14
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• How do we create refinement regions?
• In the file snappyHexMeshDict, look for the following entry:

• Distance mode is the preferred option if you want to apply


castellatedMeshControls surface refinement on a surface that is on top of another
{ surface.
... • Do not use surface refinement (refinementSurfaces), as it
might result in a wrong mesh.
...
...

refinementRegions
{ Name of the region
refinementBox created in the geometry section
{
mode distance; Refinement using distance mode.
levels ((0.1 1)); Other options: inside, outside
}
} Refinement level

...
Distance from the surface.
...
It works in a similar way to the levels option used with features
...
}
15
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

Effect of various parameters on edge capturing and surface refinement

Explicit feature edge refinement level 0 Explicit feature edge refinement level 0
resolveFeatureAngle 110 resolveFeatureAngle 60
Surface based refinement level (2 2) Surface based refinement level (2 2)

• To control edges capturing you can decrease the value of resolveFeatureAngle.


• Be careful, this parameter also controls curvature refinement, so if you choose a low value, you
also will be adding a lot of refinement on the surface.
16
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

Effect of various parameters on edge capturing and surface refinement

Explicit feature edge refinement level 0 Explicit feature edge refinement level 4
resolveFeatureAngle 60 resolveFeatureAngle 60
Surface based refinement level (2 2) Surface based refinement level (2 2)

• To control edges refinement level, you can change the value of the explicit feature edge
refinement level.

17
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

Effect of various parameters on edge capturing and surface refinement

Explicit feature edge refinement level 6 Explicit feature edge refinement level 0
resolveFeatureAngle 5 resolveFeatureAngle 5
Surface based refinement level (2 4) Surface based refinement level (2 4)

• To control edges refinement level, you can change the value of the explicit feature edge
refinement level.

18
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

Effect of various parameters on edge capturing and surface refinement

Explicit feature edge refinement level 0 Explicit feature edge refinement level 4
resolveFeatureAngle 60 resolveFeatureAngle 60
Surface based refinement level (2 4) Surface based refinement level (2 2)

• To control surface refinement level, you can change the value of the surface-based refinement
level.
• The first digit controls the global surface refinement level, and the second digit controls the
curvature refinement level.
19
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

Effect of various parameters on edge capturing and surface refinement

Explicit feature edge refinement level 0 Explicit feature edge refinement level 0
resolveFeatureAngle 60 resolveFeatureAngle 5
Surface based refinement level (2 4) Surface based refinement level (2 4)

• To control surface refinement due to curvature together with control-based surface refinement
level, you can change the value of resolveFeatureAngle, and surface-based refinement level

20
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

• Let us explore the dictionary surfaceFeaturesDict used by the utility surfaceFeatures.


• This utility will extract surface features (sharp angles) according to an angle criterion
(includedAngle).

Name of the STL. Features edges


surfaces (“[Link]”) The STL file is located
in constant/geometry

Angle criterion
includedAngle 150;
to extract features

subsetFeatures
{ Keep non-manifold edges
nonManifoldEdges yes; (edges with more that 2
connected faces)

Keep open edges


openEdges yes;
(edges with 1 connected face)
}
Features edges
If you want to save
writeObj yes;
the .obj files

21
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

• Let us explore the dictionary surfaceFeaturesDict used by the utility surfaceFeatures.


• This utility will extract surface features (sharp angles) according to an angle criterion
(includedAngle).

Name of the STL. If angle is less than includedAngle


surfaces (“[Link]”) The STL file is located this feature will be marked
in constant/geometry

angle
Angle criterion
includedAngle 150;
to extract features

subsetFeatures
{ Keep non-manifold edges includedAngle
nonManifoldEdges yes; (edges with more that 2
SOLID MODEL SIDE – STL FILE
connected faces)

Keep open edges Mark edges whose adjacent surface normals


openEdges yes; are at an angle less than includedAngle
(edges with 1 connected face)
}
0: selects no edges
180: selects all edge
If you want to save
writeObj yes;
the .obj files

22
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

• Let us explore the dictionary surfaceFeaturesDict used by the utility surfaceFeatures.


• This utility will extract surface features (sharp angles) according to an angle criterion
(includedAngle).

To read multiple STL/OBJ files in a single line with same To read multiple STL/OBJ files in different blocks, each
parameters one with different parameters

surfaces ("[Link]" "[Link]"); surface1


{
includedAngle 150; surfaces ("[Link]") ;
includedAngle 130;
subsetFeatures ...
{ ...
nonManifoldEdges yes; ...
openEdges yes; }
}
surface 2
writeObj yes; {
surfaces ("[Link]") ;
includedAngle 170;
...
...
...
}

23
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

• If you want to have a visual representation of the feature edges, you can use
paraview/paraFoam.
• Just look for the filter Feature Edges.
• Have in mind that the angle you need to define in paraview/paraFoam is the complement of the
angle you define in the dictionary surfaceFeaturesDict

24
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
• In this case we are going to generate a body fitted mesh with edge refinement. This is an
external mesh.
• These are the dictionaries and files that will be used.
• system/snappyHexMeshDict
• system/surfaceFeaturesDict
• system/meshQualityDict
• system/blockMeshDict
• constant/geometry/[Link]
• constant/geometry/[Link]

• The file [Link] is generated after using the utility surfaceFeatures, which
reads the dictionary surfaceFeaturesDict.
• The utility surfaceFeatures, will save a set of *.obj files with the captured edges. These files
are located in the directory constant/extendedFeatureEdgeMesh. You can use paraview
to visualize the *.obj files.

25
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement

• Let us generate the mesh, in the terminal window type:

1. $> foamCleanTutorials

2. $> surfaceFeatures

3. $> blockMesh

4. $> snappyHexMesh –overwrite

5. $> checkMesh –latestTime

6. $> paraFoam

• In step 2 we extract the sharp angles from the geometry.


• In step 3 we generate the background mesh.
• In step 4 we generate the body fitted mesh. Have in mind that as we use the option –
overwrite, we are not saving the intermediate steps.
• In step 5 we check the mesh quality.

26
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• This case is located in the directory $TM/M1_cyl/C1


• In this case we are going to use edge refinement and we are going to add a prismatic layer (or
inflation layer) close to the cylinder surface to better resolve the boundary layer.

27
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• How do we enable boundary layer?
• In the file snappyHexMeshDict, look for the following entry:

castellatedMesh true; //or false


Set this parameter to snap true; //or false
true if you want to
enable boundary layer
addLayers true; //or false
meshing

...
...
...

28
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• How do we enable boundary layer?
• In the file snappyHexMeshDict, look for the section addLayersControls:

These options control how the boundary layer mesh grows from
addLayersControls
{ the surface into the domain. Possible combinations are:
//Global parameters • First layer thickness (firstLayerThickness) and overall
relativeSizes true; thickness (thickness).
expansionRatio 1.2;
finalLayerThickness 0.5; • First layer thickness (firstLayerThickness) and expansion
minThickness 0.1;
ratio (expansionRatio).
layers
{ • Final layer thickness (finalLayerThickness) and expansion
banana_stlSurface ratio (expansionRatio).
{
nSurfaceLayers 3; • Final layer thickness (finalLayerThickness) and overall
}
} thickness (thickness).

// Advanced settings • Overall thickness (thickness) and expansion ratio


(expansionRatio).
...
... • The option minThickness controls the minimum thickness of
...
the layers.
}

29
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• How do we enable boundary layer?
• In the file snappyHexMeshDict, look for the section addLayersControls:

addLayersControls
{

//Global parameters
relativeSizes true;
expansionRatio 1.2;
finalLayerThickness 0.5;
minThickness 0.1;

layers
{ Name of the surface or user-defined
banana_stlSurface patch where you want to add the
{ boundary layer mesh.
nSurfaceLayers 3;
}
}
Number of layers to add.
// Advanced settings
In this sub/dictionary you can also set local per patch
...
parameters. The local options overwrite the global
...
parameters.
...
You can use the same parameters as the one you use
}
in the global parameters, except for relativeSizes.

30
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• How do we control boundary layer collapsing?
• In the file snappyHexMeshDict, look for the section addLayersControls:

addLayersControls
{

...
...
...

// Advanced settings
nGrow 0;
Increase this value to avoid BL collapsing
featureAngle 130; The maximum value should not be greater than 330

Increase this value to avoid BL collapsing


maxFaceThicknessRatio 0.5; The maximum value should not be greater than 1
...
...
...

}
31
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• Regarding the inflation layer parameters (addLayersControls), in our experience the most
important parameters are featureAngle and featureAngle.
• To set these values, you can follow the same guidelines as the ones we defined for
snapControls.
• It is important to stress that we are referring to the control parameters related to the mesh
quality and iterative relaxation.
• The parameters related to the inflation layer thickness are much more important.
• We will demonstrate this using an excel worksheet.

Recommended values Improved values (advised maximum values)

addLayersControls addLayersControls
{ {
… …

featureAngle 130; featureAngle 330;


maxFaceThicknessRatio 0.5; maxFaceThicknessRatio 1;

… …
} }

32
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

relativeSizes true relativeSizes false


expansionRatio 1.2 expansionRatio 1.2
finalLayerThickness 0.5 firstLayerThickness 0.025
minThickness 0.1 minThickness 0.01
featureAngle 130 featureAngle 130
nSurfaceLayers 3 nSurfaceLayers 3
Surface based refinement level (2 4) Surface based refinement level (2 4)

• The option finalLayerThickness controls the thickness of the final layer, whereas the option
minThickness controls the minimum thickness of the first layer.
• The actual thickness of the layers depends on the keyword relativeSizes. 33
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

• When the option relativeSizes is true, the boundary layer meshing is done relative to the size
of the cells next to the surface.
• This option requires less user intervention but can not guarantee a uniform boundary layer.
• Also, it is quite difficult to set a desired thickness of the first layer.
34
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

• When the option relativeSizes is false, we give the actual thickness of the layers.
• This option requires a lot user intervention, but it guarantees a uniform boundary layer and the
desired layer thickness. 35
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

relativeSizes true relativeSizes true


expansionRatio 1.2 expansionRatio 1.2
finalLayerThickness 0.5 finalLayerThickness 0.5
minThickness 0.1 minThickness 0.1
featureAngle 130 featureAngle 130
nSurfaceLayers 3 nSurfaceLayers 3
Surface based refinement level (2 4) Surface based refinement level (2 2)

• When the option relativeSizes is true and in order to have a uniform boundary layer, we need
to have a uniform surface refinement.
• Nevertheless, we still do not have control on the desired thickness of the first layer. 36
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

relativeSizes true relativeSizes true


expansionRatio 1.2 expansionRatio 1.2
finalLayerThickness 0.5 finalLayerThickness 0.5
minThickness 0.1 minThickness 0.1
featureAngle 130 featureAngle 30
nSurfaceLayers 3 nSurfaceLayers 3
Surface based refinement level (2 2) Surface based refinement level (2 2)

• To avoid boundary layer collapsing close to the corners, we can increase the value of the
boundary layer parameter featureAngle. 37
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

Effect of different parameters on the boundary layer meshing

relativeSizes false relativeSizes false


nSurfaceLayers 6 nSurfaceLayers 6
Refinement region at the stl surface:
mode distance;
levels ((0.05 4))

• The disadvantage of setting relativeSizes to false, is that it is difficult to control the expansion
ratio from the boundary layer meshing to the far mesh.
• To control this transition, we can add a refinement region at the surface with distance mode.
38
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• In this case we are going to generate a body fitted mesh with edge refinement and boundary
layer meshing. This is an external mesh.
• These are the dictionaries and files that will be used.

• system/snappyHexMeshDict
• system/surfaceFeaturesDict
• system/meshQualityDict
• system/blockMeshDict
• constant/geometry/[Link]
• constant/geometry/[Link]

• The file [Link] is generated after using the utility surfaceFeatures, which
reads the dictionary surfaceFeaturesDict.

39
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• To generate the mesh, in the terminal window type:

1. $> foamCleanTutorials

2. $> surfaceFeatures

3. $> blockMesh

4. $> snappyHexMesh -overwrite

5. $> checkMesh –latestTime

6. $> paraFoam

40
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• At the end of the meshing process, you will get the following information regarding the boundary
layer meshing:

patch faces layers overall thickness

[m] [%]

----- ----- ------ --- ---

banana_stlSurface 4696 3 0.0569 95.9

Layer mesh : cells:48577 faces:157942 points:61552

• This is a general summary of the boundary layer meshing.


• Pay particular attention to the overall and thickness information.
• Overall is roughly speaking the thickness of the whole boundary layer.
• Thickness is the percentage of the patch that has been covered with the boundary layer mesh.
• A thickness of 100% means that the whole patch has been covered (a perfect BL mesh).
41
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• If you want to visualize the boundary layer thickness, you can enable writeFlags in the
snappyHexMeshDict dictionary,

...
...
...

writeFlags
(
scalarLevels; // write volScalarField with cellLevel for postprocessing
layerSets; // write cellSets, faceSets of faces in layer
layerFields; // write volScalarField for layer coverage
);

...
...
...

42
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• Then you can use paraview/paraFoam to visualize the boundary layer coverage.

Boundary layer thickness and number of layers

The yellow surface represent the BL coverage


43
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• After creating the mesh and if you do not like the inflation layer or you want to try different layer
parameters, you do not need to start the meshing process from scratch.
• To restart the meshing process from a saved state you need to save the intermediate steps
(castellation and snapping), and then create the inflation layers starting from the snapped mesh.
• That is, do not use the option snappyHeshMesh -overwrite.
• Also, in the dictionary controlDict remember to set the entry startFrom to latestTime or the
time directory where the snapped mesh is saved (in this case 2).

• Before restarting the meshing, you will need to turn off the castellation and snapping options and
turn on the boundary layer options in the snappyHexMeshDict dictionary.

44
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• Remember, before restarting the meshing you will need to modify the snappyHexMeshDict
dictionary as follows:

castellatedMesh false;
snap false;
addLayers true;

• At this point, you can restart the meshing process by typing in the terminal,
• $> snappyHexMesh

• By the way, you can restart the boundary layer mesh from a previous mesh with a boundary
layer.
• So, in theory, you an add one layer at a time, this will give you more control, but it will require
more manual work and some scripting.

45
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• How do I know if my mesh is OK?


• If your goal is to predict the forces at the walls, you should have a surface mesh and
boundary layer mesh fine enough to resolve well the forces.
• Also, if there is transition to turbulence you should resolve very well the boundary layer.
• To have an idea is you are resolving well the forces, you can do a grid refinement study.
• Have in mind that these studies can be really expensive and are not based on the physics
or turbulent scales.

M1 M2

Quantity of interest
M3 M4

1 2 3 4

Mesh number or refinement level

46
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• How do I know if my mesh is OK?


• To avoid smearing gradients close to the walls, remember to control the transition from the
boundary layer mesh to the far field mesh.

• And also, you will need to have a mesh fine enough to resolve the flow features far from
the body.

47
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer

• How do I know if my mesh is OK?


• If your goal is to predict the forces at the walls, you should have a surface mesh and
boundary layer mesh fine enough to resolve well the forces.
• Also, if there is transition to turbulence you should resolve very well the boundary layer.
• To have an idea is you are resolving well the forces, you can do a grid refinement study.
• Have in mind that these studies can be really expensive and are not based on the physics
or turbulent scales.
• To avoid smearing gradients close to the walls, remember to control the transition from the
boundary layer mesh to the far field mesh.
• And also, you will need to have a mesh fine enough to resolve the flow features far from
the body.

• Be aware that these guidelines are based on reducing the truncation error of the
approximations by using finer meshes.
• These guidelines do not take into account modeling errors which should be evaluated in
a different way.

48
snappyHexMesh guided tutorials

Case 2
2D Cylinder

49
snappyHexMesh guided tutorials
Case 2. 2D Cylinder

From 3D To 2D

• This case is located in the directory $TM/C2


• To generate a 2D mesh using snappyHexMesh, we need to start from a 3D. After all,
snappyHexMesh is a 3D mesher.
• To generate a 2D mesh (and after generating the 3D mesh), we use the utility extrudeMesh.
• The utility extrudeMesh works by projecting a face into a mirror face.
• Therefore, the faces need to parallel. 50
snappyHexMesh guided tutorials
Case 2. 2D Cylinder

Geometry width
FACE 1

The utility extrudeMesh works by


projecting FACE 1 into FACE 2.
Therefore, the faces need to be
parallel.

FACE 2 Background mesh width

• At most, the input geometry and the background mesh need to have the same width.
• If the input geometry is larger than the background mesh, it will be automatically cut by the faces
of the background mesh.
• In this case, the input geometry will be cut by the two lateral patches of the background mesh.
• If you want to take advantage of symmetry in 3D, you can cut the geometry in half using one of
the faces of the background mesh.
• When dealing with 2D
• Extracting the features edges is optional for the 2D geometry extremes, but it is recommended if
there are internal edges that you want to resolve. 51
snappyHexMesh guided tutorials
Case 2. 2D Cylinder

• How do we create the 2D mesh?


• After generating the 3D mesh, we use the utility extrudeMesh.
• This utility reads the extrudeMeshDict,

constructFrom patch;

sourceCase “.”
sourcePatches (minZ); Name of source patch

exposedPatchName maxZ; Name of the mirror patch

extrudeModel linearNormal
Number of layers to use in the linear extrusion.
nLayers 1;
As this is a 2D case we must use 1 layer

linearNormalCoeffs
{
Thickness of the extrusion.
thickness 1;
It is highly recommended to use a value of 1
}

mergeFaces false;
52
snappyHexMesh guided tutorials
Case 2. 2D Cylinder

• To generate the mesh, in the terminal window type:

1. $> foamCleanTutorials

2. $> blockMesh

3. $> snappyHexMesh –overwrite

4. $> extrudeMesh

5. $> checkMesh –latestTime

6. $> paraFoam

• Remember, the utility extrudeMesh (step 4) reads the dictionary extrudeMeshDict, which is
located in the directory system.
• Also remember to set the empty patches in the dictionary boundary and in the boundary
conditions.

53
snappyHexMesh guided tutorials

Case 3
3D Cylinder with using a STL file with
multiple surfaces

54
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

STL visualization with a single surface using paraview (the STL visualization with multiple surfaces using paraview (each
single surface in represented with a single color) color corresponds to a different surface)

• This case is located in the directory $TM/M1_cyl/C3


• When you use a STL with multiple surfaces, you have more control over the meshing process.
• By default, STL files are made up of one single surface.
• If you want to create the multiple surfaces you will need to do it in the solid modeler.
• Alternatively, you can split the STL manually or using the utility surfaceAutoPatch.
• Loading multiple STLs is equivalent to using a STL with multiple surfaces. 55
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• When you use a STL with multiple surfaces, you have more control over the meshing process.
• In this case, we were able to use different refinement parameters in the lateral and central
surface patches of the cylinder. 56
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• How do we assign different names to different surface patches?


• In the file snappyHexMeshDict, look for the following entry:

geometry
{
stlSurface
{
type triSurfaceMesh;
file "[Link]";

regions
{
patch0 Named region in the STL file
{
name surface0; • User-defined patch name
} • This is the name you need to use when setting the
boundary layer meshing.
patch1 • To avoid confusion, it is recommended to use the same
{ name (named region in STL and patch name).
name surface1;
}
patch2
{
name surface2;
}
}
}
...
...
...
} 57
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• How do we refine user defined surface patches?


• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{
...
...
...
refinementSurfaces
{
level (2 2); Global refinement level
regions
{
patch0 Local surface patch (Named region in the STL file)
{
level (2 2); Local refinement level
patchInfo
{
type wall; Type of the patch.
} This information is optional
}
...
...
...
}
}
...
...
...
}
58
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• How do we control curvature refinement on surface patches?


• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{
...
...
...
refinementSurfaces
{
level (2 2); Global refinement level
regions
{
patch0 Local surface patch (Named region in the STL file)
{
level (2 4); Local curvature refinement (in red)
patchInfo
{
type wall;
}
}
...
...
...
}
}
...
...
...
}
59
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• How do we control curvature refinement on surface patches?


• In the file snappyHexMeshDict, look for the following entry:

castellatedMeshControls
{

...
...
...

//Local curvature and


//feature angle refinement The default value is 30.
resolveFeatureAngle 60; Using a higher value will capture
less features.

...
...
...

60
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• How do we control boundary layer meshing on the surface patches?


• In the file snappyHexMeshDict, look for the following entry:

addLayersControls
{

//Global parameters
relativeSizes true;
expansionRatio 1.2;
Global BL parameters
finalLayerThickness 0.5;
minThickness 0.1;
layers
{
“surface.*” • User-defined patch name
{ • POSIX wildcards are permitted
nSurfaceLayers 5;
}
surface0 Local surface patch
{
nSurfaceLayers 3;
expansionRatio 1.0; Local BL parameters
finalLayerThickness 0.25;
minThickness 0.1;
}
}

//Advanced settings
...
...
...
} 61
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• In this case we are going to generate a body fitted mesh with edge refinement and boundary
layer meshing. This is an external mesh.
• These are the dictionaries and files that will be used.

• system/snappyHexMeshDict
• system/surfaceFeaturesDict
• system/meshQualityDict
• system/blockMeshDict
• constant/geometry/[Link]
• constant/geometry/[Link]

• The file [Link] is generated after using the utility surfaceFeatures, which
reads the dictionary surfaceFeaturesDict.

62
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• Let us first create the STL file with multiple surfaces.


• In the directory geo, you will find the original STL file.
• In the terminal type:

1. $> cd geo

2. $> surfaceAutoPatch [Link] [Link] 130

3. $> cp [Link] ../constant/geometry/[Link]

4. $> cd ..

5. $> paraview

• The utility surfaceAutoPatch will read the original STL file ([Link]), and it will find the
patches using an angle criterion of 130 (similar to the angle criterion used with the utility
surfaceFeatures). It writes the new STL geometry in the file [Link].
• By the way, it is better to create the STL file with multiple surfaces directly in the solid modeler.
• FYI, there is an equivalent utility for meshes, autoPatch. So, if you forgot to define the
patches, this utility will automatically find the patches according to an angle criterion. 63
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• If you open the file [Link], you will notice that there are three surfaces defined in the
STL file. The different surfaces are defined in by the following sections:

solid patch0
… Surface patch 1 • The name of the solid sections are
automatically given by the utility
endsolid patch0
surfaceAutoPatch.

solid patch1
• The convention is as follows: patch0,
… Surface patch 2
patch1, pathc2, … patchN.
endsolid patch1

• If you do not like the names, you can


solid patch2
change them directly in the STL file.
… Surface patch 3

endsolid patch2

64
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• The new STL file is already in the constant/geometry directory.


• To generate the mesh, in the terminal window type:

1. $> foamCleanTutorials

2. $> surfaceFeatures

3. $> blockMesh

4. $> snappyHexMesh -overwrite

5. $> checkMesh –latestTime

• To visualize the mesh, in the terminal window type:

6. $> paraFoam

65
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• This case is ready to run using the solver incompressibleFluid.


• But before running, you will need to set the boundary and initial conditions.
• You will need to modify the file constant/polyMesh/boundary, you can do it manually or
you can use the utility createPatch., foamDictionary, or a Linux utility (e.g., sed)
• Remember:
• Base type boundary conditions are defined in the file boundary located in the directory
constant/polyMesh.
• Primitive or numerical type boundary conditions are defined in the field variables files
located in the directory 0 or the time directory from which you want to start the simulation
(e.g., U, p).
• The name of the base type boundary conditions and numerical type boundary conditions
needs to be the same.
• Also, the base type boundary condition needs to be compatible with the numerical type
boundary condition.

66
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces

• This case is ready to run with foamRun.


• To run the case (mesh and simulation), type in the terminal,

1. $> sh run_all.sh

• Feel free to open the files run_mesh.sh (meshing steps) and run_solver.sh (simulation
steps) to get an idea of all steps used.
• The most critical step is to give the right name and type to the boundary patches, this is done in
the file boundary and the input files located in the directory 0 (boundary conditions and initial
conditions).

67

You might also like