CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Meshing & Mesh Conversion

[blockMesh] Cylinder in Openfoam blockMesh

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Lookid

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 18, 2021, 14:29
Default Cylinder in Openfoam blockMesh
  #1
New Member
 
Join Date: Nov 2020
Posts: 14
Rep Power: 6
Enternald is on a distinguished road
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
(
);
Screenshot from 2021-01-18 14-27-16.pngScreenshot from 2021-01-18 14-26-27.png
Enternald is offline   Reply With Quote

Old   January 19, 2021, 04:57
Default
  #2
Member
 
Lilian Chabannes
Join Date: Apr 2017
Posts: 58
Rep Power: 9
Lookid is on a distinguished road
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
blockmesh_example.png
mjavrincon likes this.
__________________
Feel free to join the OpenFOAM Discord https://discord.gg/P9p9eHn, a live chat about OpenFOAM
Lookid is offline   Reply With Quote

Old   October 10, 2022, 22:35
Default
  #3
Member
 
mactone hsieh
Join Date: Apr 2012
Location: Taiwan
Posts: 31
Blog Entries: 1
Rep Power: 14
mactone is on a distinguished road
You should add the arc for the fourth quarter as highlighted in red below

Quote:
Originally Posted by Enternald View Post
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)
    hex ( 3 0 8 8 7 4 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 3 0 ($c4 $s4 $cz)
     
     arc 4 5 ($c1 $s1 $h)
     arc 5 6 ($c2 $s2 $h)
     arc 6 7 ($c3 $s3 $h)
     arc 7 4 ($c4 $s4 $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
mactone is offline   Reply With Quote

Old   October 27, 2022, 17:39
Default
  #4
New Member
 
IIIIKEK
Join Date: Oct 2022
Posts: 6
Rep Power: 4
firestarter is on a distinguished road
I've tried to make cylinder channel, my experience tells me that this must be most smooth way but there is a singularity on centre. Is there easy way to fix it?
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Website:  https://openfoam.org                  |
|   \\  /    A nd           | Version:  9                                     |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.0002;

vertices
(
(0 -1 0)
(40 -1 0)
(40 0 -1)
(0 0 -1)
(0 0 0)
(40 0 0)
(40 0 0)
(0 0 0)
(0 0 1)
(40 0 1)
(0 0 0)
(40 0 0)
(40 1 0)
(0 1 0)
);

blocks
(
hex (0 1 2 3 4 5 6 7) (1 20 20) simpleGrading (1 1 1)
hex (0 1 5 4 8 9 6 7) (1 20 20) simpleGrading (1 1 1)
hex (7 6 11 10 8 9 12 13) (1 20 20) simpleGrading (1 1 1)
hex (3 2 12 13 7 6 11 10) (1 20 20) simpleGrading (1 1 1)
);

edges
(
arc 0 3 (0 -0.707107 -0.707107)
arc 1 2 (40 -0.707107 -0.707107)
arc 0 8 (0 -0.707107 0.707107)
arc 1 9 (40 -0.707107 0.707107)
arc 8 13 (0 0.707107 0.707107)
arc 9 12 (40 0.707107 0.707107)
arc 3 13 (0 0.707107 -0.707107)
arc 2 12 (40 0.707107 -0.707107)
);

boundary
(

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

mergePatchPairs
(
);

// ************************************************************************* //
firestarter is offline   Reply With Quote

Old   October 28, 2022, 06:28
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,207
Rep Power: 28
Yann will become famous soon enough
Hi,

This should be a good starting point: vertical, horizontal and dend cylinder

Regards,
Yann
Yann is offline   Reply With Quote

Old   October 29, 2022, 12:11
Default
  #6
New Member
 
IIIIKEK
Join Date: Oct 2022
Posts: 6
Rep Power: 4
firestarter is on a distinguished road
Quote:
Originally Posted by Yann View Post
Hi,

This should be a good starting point: vertical, horizontal and dend cylinder

Regards,
Yann
I've used five bodies method but it have artifacts on corner sections because of unsimmetrical cells volume change resulting in a worse consistency of solution. Radial symmetry cells have the best symmetry but they also have singularity destroying everything when all gets to stationary. I need to get the central cells out of calculation.
firestarter is offline   Reply With Quote

Reply

Tags
blockmesh, blockmesh cylinder, openfoam


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[blockMesh] cylinder blockMesh error tenichols19 OpenFOAM Meshing & Mesh Conversion 2 February 3, 2021 12:36
How to implement time-varying boundary conditions in an enclosed cylinder Alejandro-FA OpenFOAM Pre-Processing 0 May 14, 2020 07:29
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 04:18
Tube with cylinder inside in OpenFoam orxan.shibli OpenFOAM Running, Solving & CFD 1 September 6, 2015 12:53
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 07:25


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