[LINUX] How to create a flow mesh around a cylinder with snappyHexMesh

Introduction

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. screenshot.105.jpg 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. screenshot.106.jpg

Overview of snappyHexMesh

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.

screenshot.113.jpg

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

  1. Create a background mesh with blockMesh
  2. Create a CAD file for the cylinder
  3. Create a mesh with snappyHexMesh

** 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

1. Create a background mesh with blockMesh

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 *.

2. Create a CAD file for the cylinder

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 6_完成.jpg

Output it as cylinder.stl and put it in * cylinder / constant / triSurface *.

3. Create a mesh with snappyHexMesh

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

How to create a flow mesh around a cylinder with snappyHexMesh
How to create a multi-platform app with kivy
How to create a submenu with the [Blender] plugin
[Python] How to create a 2D histogram with Matplotlib
How to create a Conda package
How to create a virtual bridge
How to create a Dockerfile (basic)
How to create a config file
How to create a heatmap with an arbitrary domain in Python
How to create a label (mask) for segmentation with labelme (semantic segmentation mask)
How to write a docstring to create a named tuple document with sphinx
How to create a serverless machine learning API with AWS Lambda
How to create a git clone folder
How to add a package with PyCharm
How to create a repository from media
3. Natural language processing with Python 1-2. How to create a corpus: Aozora Bunko
How to create sample CSV data with hypothesis
How to read a CSV file with Python 2/3
How to send a message to LINE with curl
How to create a Python virtual environment (venv)
How to draw a 2-axis graph with pyplot
How to create a function object from a string
How to develop a cart app with Django
How to create a JSON file in Python
How to make a dictionary with a hierarchical structure.
Steps to create a Twitter bot with python
How to create a shortcut command for LINUX
[Note] How to create a Ruby development environment
How to create a Kivy 1-line input box
How to create a Rest Api in Django
Create a cylinder with open3d + STL file output
[Note] How to create a Mac development environment
How to create random numbers with NumPy's random module
[Python] How to create a local web server environment with SimpleHTTPServer and CGIHTTPServer
Read the Python-Markdown source: How to create a parser
How to convert / restore a string with [] in python
I tried to create a table only with Django
[Python] How to draw a line graph with Matplotlib
Try to dynamically create a Checkbutton with Python's Tkinter
How to get a logged-in user with Django's forms.py
How to convert a class object to a dictionary with SQLAlchemy
[Go] How to create a custom error for Sentry
How to create a local repository for Linux OS
I want to manually create a legend with matplotlib
How to create a simple TCP server / client script
How to create a kubernetes pod from python code
[Python] How to draw a scatter plot with Matplotlib
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
How to make a Cisco Webex Teams BOT with Flask
How to put a hyperlink to "file: // hogehoge" with sphinx-> pdf
How to install NPI + send a message to line with python
How to kill a process instantly with Python's Process Pool Executor
I tried to automatically create a report with Markov chain
How to convert an array to a dictionary with Python [Application]
How to output a document in pdf format with Sphinx
Create a Mastodon bot with a function to automatically reply with Python
How to call a function
Probably the easiest way to create a pdf with Python3
Create a homepage with django
How to print characters as a table with Python's print function
How to update with SQLAlchemy?