This article explains how to create a mesh for OpenFOAM using the snappyHexMesh utility. snappyHexMesh is a utility for creating a hexagonal mesh from an STL file. It is possible to create an STL file of your favorite shape with CAD etc. and create a mesh of that shape. For the sake of explanation, let's set the working directory name to * cylinder * and create a mesh that flows around the cylinder.
I also explain it in the video. https://www.youtube.com/watch?v=bas-5wbHOoY
It is a completed image. The block dimensions are Lx = 0.28m, Ly = 0.12m, Lz = 0.1m, and the origin is the intersection of the central axis of the cylinder and the xy plane.
Details of the surface of the cylinder. Also cut the boundary layer.
The snappyHexMesh utility consists of three steps: castllatedMesh, snap, and addLayers, and the processing content is like removing outside the area, improving the accuracy of the boundary surface, and generating a mesh for the boundary layer. Image like below.
To execute it, you need to prepare two geometry files such as a hexahedral background mesh and stl format that is consistent with this. One example of a conflicting situation is that the geometry file is larger than the background mesh. The background mesh can be created with blockMesh, and the geometry file can be created with CAD. This article is created with FreeCAD.
This article does not explain all of snappyHexMesh, so if you want to know the detailed specifications, please refer to the following. https://cfd.direct/openfoam/user-guide/v7-snappyhexmesh/#x27-1970005.4
procedure
** Directory structure at the start of work **
Prepare directories and files as follows. With OpenFOAM v7 /opt/openfoam7/tutorials/mesh/snappyHexMesh If you select one from the sample directories in and copy and paste it, you do not have to edit controlDict, fvSchemes, fvSolution, meshQualityDict, so it is easy.
cylinder/
├── constant/
│ └── triSurface/
└── system/
├── blockMeshDict
├── controlDict
├── fvSchemes
├── fvSolution
├── meshQualityDict
└── snappyHexMeshDict
Edit * cylinder / system / blockMeshDict * as follows.
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(-0.08 -0.06 0)
( 0.2 -0.06 0)
( 0.2 0.06 0)
(-0.08 0.06 0)
(-0.08 -0.06 0.1)
( 0.2 -0.06 0.1)
( 0.2 0.06 0.1)
(-0.08 0.06 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (100 80 10) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
z_min
{
type patch;
faces ((0 3 2 1));
}
z_max
{
type patch;
faces ((4 5 6 7));
}
y_min
{
type patch;
faces ((0 1 5 4));
}
y_max
{
type patch;
faces ((2 3 7 6));
}
x_min
{
type patch;
faces ((0 4 7 3));
}
x_max
{
type patch;
faces ((1 2 6 5));
}
);
mergePatchPairs
(
);
// ************************************************************************* //
There are no particular restrictions on the patch name or the number of mesh divisions. After editing * blockMeshDict *, execute blockMesh.
cylinder$ blockMesh
You have now created a background mesh. The main body is located in * cylinder / constant / polymesh *.
Next, create a cylinder with FreeCAD. I am creating it on Windows.
The diameter is 0.04m. The height should not exceed Lz, so it should be 0.1m. However, if you export from FreeCAD in stl format, the size will increase 1000 times according to the specifications, so you need to create it on FreeCAD with a diameter of 0.04 mm and a height of 0.1 mm. snappyHexMesh has a specification that the coordinate system of the background mesh and the coordinate system of the CAD file match. If you want to control the position of the cylinder, you need to pay attention to the coordinate system.
Creation example
Output it as cylinder.stl and put it in * cylinder / constant / triSurface *.
Set * cylinder / system / snapyHexMeshDict * as follows.
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object snappyHexMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
castellatedMesh true;
snap true;
addLayers true;
geometry
{
cylinder
{
type triSurfaceMesh;
file "cylinder.stl";
}
};
castellatedMeshControls
{
maxLocalCells 100000;
maxGlobalCells 2000000;
minRefinementCells 2;
nCellsBetweenLevels 4;
resolveFeatureAngle 30;
locationInMesh (0.18 0.05 0.09); // Inside point
allowFreeStandingZoneFaces true;
features
(
);
refinementSurfaces
{
cylinder
{
level (2 2);
}
}
refinementRegions
{
}
}
snapControls
{
nSmoothPatch 3;
tolerance 1.0;
nSolveIter 300;
nRelaxIter 5;
nFeatureSnapIter 10;
implicitFeatureSnap false;
explicitFeatureSnap true;
multiRegionFeatureSnap true;
}
addLayersControls
{
relativeSizes true;
layers
{
"cylinder*"
{
nSurfaceLayers 5;
}
}
expansionRatio 1.2;
finalLayerThickness 0.3;
minThickness 0.25;
nGrow 0;
featureAngle 30;
nRelaxIter 5;
nSmoothSurfaceNormals 1;
nSmoothNormals 3;
nSmoothThickness 10;
maxFaceThicknessRatio 0.5;
maxThicknessToMedialRatio 0.3;
minMedianAxisAngle 90;
nBufferCellsNoExtrude 0;
nLayerIter 50;
nRelaxedIter 20;
}
meshQualityControls
{
#include "meshQualityDict"
relaxed
{
maxNonOrtho 75;
}
}
writeFlags
(
scalarLevels // write volScalarField with cellLevel for postprocessing
layerSets // write cellSets, faceSets of faces in layer
layerFields // write volScalarField for layer coverage
);
mergeTolerance 1E-6;
// ************************************************************************* //
Explaining all the parameters would be complicated, so I will briefly explain the parameters that I felt important in my experience (or rather, there are quite a few parameters that I have never touched).
CastellatedMesh, snap, and addLayers immediately after FoamFile are parameters that determine whether to execute each process. If you do not cut the boundary layer mesh, set addLayers to false. This time, the boundary layer mesh is also cut, so all are set to true.
In the geometry dictionary, specify the CAD file to read. The cylinder is the name of the boundary (patch) of the stl file, and you can name it as you like. In this case, the patch is the surface of the cylinder. The name given here will be used at the bottom. The type is triSurfaceMesh, and the file is cylinder.stl placed in triSurface.
castellatedMeshControls is a set dictionary of removal processing outside the calculation area. The larger the number of nCellsBetweenLevels, the higher the resolution around the surface. I set it to 3 ~ 4. locationInMesh sets the coordinates of some part of the area where you want to create a mesh. In other words, somewhere inside the background mesh and outside the cylinder. If you specify the inside of the cylinder, the mesh inside the cylinder will be created and the outside will be removed. refinementSurfaces is a parameter to set for each patch. Specify the minimum and maximum (min max) resolutions for each patch. I set both to about 2.
snapControls is a setting dictionary for snap processing, but I haven't touched it.
addLayersControl is a setting dictionary for addLayers processing. If relativeSizes is true, the grid width inside the boundary layer is calculated according to the grid outside the boundary layer. In the layers dictionary, specify the number of layers for each patch. The patch name is a wildcard with "cylinder *" because it will not be processed properly unless it is "[patch name specified in the geometry dictionary] *". It was a difficult part for an OpenFOAM beginner like me. expansionRatio is the grid width ratio between layers.
After editing, run snappyHexMesh.
cylinder$ snappyHexMesh
When finished, three new directories with numbers will be created. The polyMesh directory, which is the main body of the mesh that has been created, is contained in the directory with the largest number. Please copy and paste this directory into the * constant * directory of the job for fluid analysis.
the end.
Recommended Posts