3D Cylinder Mesh Refinement Guide
3D Cylinder Mesh Refinement Guide
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
3
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh
• We are going to explore all features of snappyHexMesh.
4
snappyHexMesh guided tutorials
Case 1. 3D Cylinder – External flow mesh
Sharp angle/edges
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
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
{
...
...
...
...
...
...
} 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
{
...
...
...
...
...
...
} 9
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
angle
resolveFeatureAngle
10
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
angle
resolveFeatureAngle
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
...
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
{
...
...
...
...
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:
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
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)
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
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
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
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
Angle criterion
includedAngle 150;
to extract features
subsetFeatures
{ Keep non-manifold edges
nonManifoldEdges yes; (edges with more that 2
connected faces)
21
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
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)
22
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement
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
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
1. $> foamCleanTutorials
2. $> surfaceFeatures
3. $> blockMesh
6. $> paraFoam
26
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and 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:
...
...
...
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).
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
}
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.
addLayersControls addLayersControls
{ {
… …
… …
} }
32
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• 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
• 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
• 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
• 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
• 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
• 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
1. $> foamCleanTutorials
2. $> surfaceFeatures
3. $> blockMesh
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:
[m] [%]
• 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.
• 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
M1 M2
Quantity of interest
M3 M4
1 2 3 4
46
snappyHexMesh guided tutorials
Case 1. 3D Cylinder with edge refinement and boundary layer
• 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
• 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
Geometry width
FACE 1
• 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
constructFrom patch;
sourceCase “.”
sourcePatches (minZ); Name of source 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
1. $> foamCleanTutorials
2. $> blockMesh
4. $> extrudeMesh
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)
• 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
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
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
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
castellatedMeshControls
{
...
...
...
...
...
...
60
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces
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
1. $> cd geo
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
endsolid patch2
64
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces
1. $> foamCleanTutorials
2. $> surfaceFeatures
3. $> blockMesh
6. $> paraFoam
65
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces
66
snappyHexMesh guided tutorials
Case 3. 3D Cylinder with using a STL file with multiple surfaces
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