CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [blockMesh] Cylinder in Openfoam blockMesh (https://www.cfd-online.com/Forums/openfoam-meshing/233224-cylinder-openfoam-blockmesh.html)

Enternald January 18, 2021 13:29

Cylinder in Openfoam blockMesh
 
2 Attachment(s)
Hi All,



I am trying to create an cylinder using blockMesh, I got 3/4 the way through and noticed that it does not line up properly (shown in the image below). Does anyone know why this is the case?
Code:

convertToMeters 0.01;

//..................................//

// Dimensions of the cylinder:
cx 5;
cy 5;
cz 1.0;

cylinderThickness 1.0;
r 0.5;

//..................................//

// Calculations for cylinder geometry:
h #calc "$cylinderThickness+$cz";
tph #calc "$cylinderThickness+$cz+$cz";

vx #calc "$cx+$r";
nvx #calc "$cx-$r";

vy #calc "$cy+$r";
nvy #calc "$cy-$r";

// Calculations for arcs:
c1 #calc "$cx + ($r*cos(45.0))"; //cosine in first quadrant
s1 #calc "$cy + ($r*sin(45.0))"; //sine in first quadrant

c2 #calc "$cx + ($r*cos(135.0))"; //cosine in first quadrant
s2 #calc "$cy + ($r*sin(135.0))"; //sine in first quadrant

c3 #calc "$cx + ($r*cos(225.0))"; //cosine in first quadrant
s3 #calc "$cy + ($r*sin(225.0))"; //sine in first quadrant

c4 #calc "$cx + ($r*cos(315.0))"; //cosine in first quadrant
s4 #calc "$cy + ($r*sin(315.0))"; //sine in first quadrant

vertices

//  Vertices for the cylinder :
//  x      y      z
    ($vx    $cy    $cz)         
    ($cx    $vy    $cz)         
    ($nvx    $cy    $cz)         
    ($cx    $nvy    $cz)         
   
    ($vx    $cy    $h)           
    ($cx    $vy    $h)           
    ($nvx    $cy    $h)           
    ($cx    $nvy    $h)             
    ($cx    $cy    $cz)         
    ($cx    $cy    $h)           
);

// These are all the 'blocks' in our geometry.
blocks
(
    hex ( 0 1 8 8 4 5 9 9 )      pores      ( 25  25  25 )    simpleGrading (1 1 1)
    hex ( 1 2 8 8 5 6 9 9 )      pores      ( 25  25  25 )    simpleGrading (1 1 1)
    hex ( 2 3 8 8 6 7 9 9 )      pores      ( 25  25  25 )    simpleGrading (1 1 1)
);

// Edges is a dictionary where we define arcs between vertices.
edges
(
    arc 0 1 ($c1 $s1 $cz)
    arc 1 2 ($c2 $s2 $cz)
    arc 2 3 ($c3 $s3 $cz)
   
    arc 4 5 ($c1 $s1 $h)
    arc 5 6 ($c2 $s2 $h)
    arc 6 7 ($c3 $s3 $h)
);

// Boundaries is where we define our boundary patches.
boundary
(
  wall
    {
        type wall;
        faces
        (
            (0 8 8 1)
            (1 8 8 2)
            (2 8 8 3)
        );
    }
    atmosphere
    {
        type patch;
        faces
        (
            (5 9 9 4)
            (6 9 9 5)
            (7 9 9 6)
        );
    }
    sides
    {
        type patch;
        faces
        (
            (0 1 5 4)
            (2 6 5 1)
            (3 7 6 2)
        );
    }
 
);

mergePatchPairs
(
);

Attachment 82172Attachment 82171

Lookid January 19, 2021 03:57

1 Attachment(s)
Your mesh does not load in Paraview for me.

What I can propose is just to make 1/4 of the cylinder and then mirror the mesh twice, it will avoid you the troubles of making 4 blocks.

Here is a blockMesh I found in this forum some time ago:

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  3.0.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

//========================
// CONTROLS

// number of cells
Nx  50;
NRinner  15;
NRouter  15;

// size ratio of cell at the wall to the free-stream one in the near-wall blocks
expRatWall  0.1; // for BL
expRatWall2  0.1; // pipe-axis direction

//========================

convertToMeters 0.001;

// all the vertices are in non-dimensional units
// pipe assumed to have length and radius of 1
vertices
(
    (0.00000e+00 0.00000e+00 0.00000e+00)
        (0.00000e+00 0.00000e+00 8.00000e-01)
        (0.00000e+00 0.00000e+00 1.00000e+00)
        (0.00000e+00 6.10535e-01 6.10532e-01)
        (0.00000e+00 8.00000e-01 0.00000e+00)
        (0.00000e+00 1.00000e+00 0.00000e+00)
        (0.00000e+00 7.07107e-01 7.07107e-01)

        (1 0.00000e+00 0.00000e+00)
        (1 0.00000e+00 8.00000e-01)
        (1 0.00000e+00 1.00000e+00)
        (1 6.10535e-01 6.10532e-01)
        (1 8.00000e-01 0.00000e+00)
        (1 1.00000e+00 0.00000e+00)
        (1 7.07107e-01 7.07107e-01)
);

blocks
(
    hex (0 7 11 4 1 8 10 3) ($Nx $NRinner $NRinner) simpleGrading ($expRatWall2 1 1)
    hex (4 11 12 5 3 10 13 6) ($Nx $NRouter $NRinner) simpleGrading ($expRatWall2 $expRatWall 1)
    hex (3 10 13 6 1 8 9 2) ($Nx $NRouter $NRinner) simpleGrading ($expRatWall2 $expRatWall 1)
);

edges
(
        BSpline 1 3 (
                //(0.00000e+00 0.00000e+00 8.00000e-01)
                (0.00000e+00 1.12269e-01 7.92025e-01)
                (0.00000e+00 2.22463e-01 7.62587e-01)
                (0.00000e+00 3.26692e-01 7.24996e-01)
                (0.00000e+00 4.21177e-01 6.86516e-01)
                (0.00000e+00 5.02076e-01 6.52300e-01)
                (0.00000e+00 5.66526e-01 6.25913e-01)
                (0.00000e+00 6.10535e-01 6.10532e-01)
        )
       
        BSpline 3 4 (
                (0.00000e+00 6.10532e-01 6.10535e-01)
                (0.00000e+00 6.25913e-01 5.66526e-01)
                (0.00000e+00 6.52300e-01 5.02076e-01)
                (0.00000e+00 6.86516e-01 4.21177e-01)
                (0.00000e+00 7.24996e-01 3.26692e-01)
                (0.00000e+00 7.62587e-01 2.22463e-01)
                (0.00000e+00 7.92025e-01 1.12269e-01)
                //(0.00000e+00 8.00000e-01 0.00000e+00)
        )
        BSpline 8 10 (
                //(1 0.00000e+00 8.00000e-01)
                (1 1.12269e-01 7.92025e-01)
                (1 2.22463e-01 7.62587e-01)
                (1 3.26692e-01 7.24996e-01)
                (1 4.21177e-01 6.86516e-01)
                (1 5.02076e-01 6.52300e-01)
                (1 5.66526e-01 6.25913e-01)
                (1 6.10535e-01 6.10532e-01)
        )
       
        BSpline 10 11 (
                (1 6.10532e-01 6.10535e-01)
                (1 6.25913e-01 5.66526e-01)
                (1 6.52300e-01 5.02076e-01)
                (1 6.86516e-01 4.21177e-01)
                (1 7.24996e-01 3.26692e-01)
                (1 7.62587e-01 2.22463e-01)
                (1 7.92025e-01 1.12269e-01)
                //(1 8.00000e-01 0.00000e+00)
        )
       
        arc 2 6 (0 0.38268343236508978 0.92387953251128674)
        arc 6 5 (0 0.92387953251128674 0.38268343236508978)
       
        arc 9 13 (1 0.38268343236508978 0.92387953251128674)
        arc 13 12 (1 0.92387953251128674 0.38268343236508978)
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (1 2 6 3)
            (3 6 5 4)
            (0 1 3 4)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (11 10 8 7)
            (12 13 10 11)
            (13 9 8 10)
        );
    }
    wall
    {
        type wall;
        faces
        (
            (9 13 6 2)
            (13 12 5 6)
        );
    }
    symmetryVer
    {
        type symmetryPlane;
        faces
        (
            (2 9 8 1)
            (1 8 7 0)
        );
    }
    symmetryHor
    {
        type symmetryPlane;
        faces
        (
            (11 4 0 7)
            (12 5 4 11)
        );
    }
);

mergePatchPairs
(
);

// ************************************************************************* //

It will generate the mesh 1 which has a radius and length of 1mm. Then you can run the following commands to scale the mesh to give it the dimensions you want, mirror it to obtain full cylinder and place it where you want to give mesh 2.

Code:

blockMesh

transformPoints -scale "(55 5.5 5.5)"

sed -i "s/normalVector.*;/normalVector (0 0 1);/g" system/mirrorMeshDict
mirrorMesh -overwrite
sed -i "s/normalVector.*;/normalVector (0 1 0);/g" system/mirrorMeshDict
mirrorMesh -overwrite

# if direction of flow is : z+
transformPoints -rollPitchYaw "(0 -90 0)" # z+
#transformPoints -rollPitchYaw "(0 90 0)" # z-

transformPoints -translate "(0 0 -0.0553)"

# renumber to optimise parallel running
renumberMesh -overwrite

Attachment 82185


All times are GMT -4. The time now is 05:05.