Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Simulation of flow through pipe in OpenFoam

Objective:-

  • To generate blockMeshDict file in Matlab for given:-
    • Length
    • Diameter
    • Angle of wedge
    • Number of nodes and grading
  • Verification of velocity profile with Hagen Poiseuille's flow
  • To show fully developed velocity profile
  • Post process velocity and shear stress

BlockMeshDict file in Matalb:-

The file generates the necessary profile for the inputs mentioned above

close all
clear all
clc

L = 1.3;
R = 0.025;
theta = 3;
thetah =theta/2;
x_nodes =200;
y_nodes =50;
y_grading =0.1;
blockM = fopen('BlockMeshDict','w');
fprintf(blockM,'FoamFile\n');
fprintf(blockM, '{\n');
fprintf(blockM, '        version    2.0;\n');
fprintf(blockM, '        format     ascii;\n');
fprintf(blockM, '        class      dictionary;\n');
fprintf(blockM, '        object     blockMeshDict;\n');
fprintf(blockM, '}\n');
fprintf(blockM, '//******************************************************//\n');
fprintf(blockM, '\n');
fprintf(blockM, 'scale 1;\n');
fprintf(blockM, '\n');
fprintf(blockM, 'vertices\n');
fprintf(blockM, '(\n');
fprintf(blockM, '       (0 0 0)\n');
fprintf(blockM, '       (%5.5f 0 0)\n',L);
fprintf(blockM, '       (%5.5f %5.5f  %5.5f )\n',L,R*cosd(thetah),-R*sind(thetah));
fprintf(blockM, '       (0 %5.5f  %5.5f )\n',R*cosd(thetah),-R*sind(thetah));
fprintf(blockM, '       (%5.5f %5.5f  %5.5f )\n',L,R*cosd(thetah),R*sind(thetah));
fprintf(blockM, '       (0 %5.5f  %5.5f )\n',R*cosd(thetah),R*sind(thetah));
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'blocks\n');
fprintf(blockM, '(\n');
fprintf(blockM, '           hex (0 1 2 3 0 1 4 5) (%.0f %.0f 1) simpleGrading (1 %f 1)\n',x_nodes,y_nodes,y_grading);
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'edges\n');
fprintf(blockM, '(\n');
fprintf(blockM, '           arc 2 4 (%5.5f %5.5f 0)\n',L,R);
fprintf(blockM, '           arc 3 5 (0 %5.5f 0)\n',R);
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'boundary\n');
fprintf(blockM, '(\n');
fprintf(blockM, '      inlet\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type patch;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 5 3 0)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      front\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wedge;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (1 4 5 0)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      back\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wedge;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 3 2 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      top\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wall;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (3 5 4 2)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      outlet\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type patch;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (1 2 4 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      axis\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type empty;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 0 1 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'mergePatchPairs\n');
fprintf(blockM, '(\n');
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, '// *************************************************************************\n');
% FoamFile
% {
%     version     2.0;
%     format      ascii;
%     class       dictionary;
%     object      blockMeshDict;
% }
% // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
% 
% scale   1;
% 
% vertices
% (
%     (0 0 0)
%     (5 0 0)
%     (5 0.99905 -0.04362)
%     (0 0.99905 -0.04362)
%     (5 0.99905  0.04362)
%     (0 0.99905  0.04362)
% );
% 
% blocks
% (
%     hex (0 1 2 3 0 1 4 5) (50 10 1) simpleGrading (1 1 1)
% );
% 
% edges
% (
% arc 2 4 (5 1 0)
% arc 3 5 (0 1 0)
% );
% 
% boundary
% (
%     inlet
%     {
%         type patch;
%         faces
%         (
%             (0 5 3 0)
%         );
%     }
%     front
%     {
%         type wedge;
%         faces
%         (
%             (1 4 5 0)
%                        
%         );
% 	}
% 	back
%     {
%         type wedge;
%         faces
%         (
%             (0 3 2 1)
%                        
%         );	
%     }
%     top
%     {
%         type wall;
%         faces
%         (
%             (3 5 4 2)
%             
%         );
%     }
% 	outlet
%     {
%         type patch;
%         faces
%         (
%             (1 2 4 1)
%             
%             
%         );
%     }
% 	axis
%     {
%         type empty;
%         faces
%         (
%             (0 0 1 1)
%             
%             
%         );
%     }
% );
% 
% mergePatchPairs
% (
% );
% 
% // *************************************************************************

The above matlab code generated the below blockMeshDict file which has copied to the appropriate file in the Openfoam case folder.

close all
clear all
clc

L = 1.3;
R = 0.025;
theta = 3;
thetah =theta/2;
x_nodes =200;
y_nodes =50;
y_grading =0.1;
blockM = fopen('BlockMeshDict','w');
fprintf(blockM,'FoamFile\n');
fprintf(blockM, '{\n');
fprintf(blockM, '        version    2.0;\n');
fprintf(blockM, '        format     ascii;\n');
fprintf(blockM, '        class      dictionary;\n');
fprintf(blockM, '        object     blockMeshDict;\n');
fprintf(blockM, '}\n');
fprintf(blockM, '//******************************************************//\n');
fprintf(blockM, '\n');
fprintf(blockM, 'scale 1;\n');
fprintf(blockM, '\n');
fprintf(blockM, 'vertices\n');
fprintf(blockM, '(\n');
fprintf(blockM, '       (0 0 0)\n');
fprintf(blockM, '       (%5.5f 0 0)\n',L);
fprintf(blockM, '       (%5.5f %5.5f  %5.5f )\n',L,R*cosd(thetah),-R*sind(thetah));
fprintf(blockM, '       (0 %5.5f  %5.5f )\n',R*cosd(thetah),-R*sind(thetah));
fprintf(blockM, '       (%5.5f %5.5f  %5.5f )\n',L,R*cosd(thetah),R*sind(thetah));
fprintf(blockM, '       (0 %5.5f  %5.5f )\n',R*cosd(thetah),R*sind(thetah));
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'blocks\n');
fprintf(blockM, '(\n');
fprintf(blockM, '           hex (0 1 2 3 0 1 4 5) (%.0f %.0f 1) simpleGrading (1 %f 1)\n',x_nodes,y_nodes,y_grading);
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'edges\n');
fprintf(blockM, '(\n');
fprintf(blockM, '           arc 2 4 (%5.5f %5.5f 0)\n',L,R);
fprintf(blockM, '           arc 3 5 (0 %5.5f 0)\n',R);
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'boundary\n');
fprintf(blockM, '(\n');
fprintf(blockM, '      inlet\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type patch;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 5 3 0)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      front\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wedge;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (1 4 5 0)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      back\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wedge;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 3 2 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      top\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type wall;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (3 5 4 2)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      outlet\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type patch;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (1 2 4 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, '      axis\n');
fprintf(blockM, '      {\n');
fprintf(blockM, '        type empty;\n');
fprintf(blockM, '        faces\n');
fprintf(blockM, '        (\n');
fprintf(blockM, '            (0 0 1 1)\n');
fprintf(blockM, '        );\n');
fprintf(blockM, '      }\n');
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, 'mergePatchPairs\n');
fprintf(blockM, '(\n');
fprintf(blockM, ');\n');
fprintf(blockM, '\n');
fprintf(blockM, '// *************************************************************************\n');
% FoamFile
% {
%     version     2.0;
%     format      ascii;
%     class       dictionary;
%     object      blockMeshDict;
% }
% // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
% 
% scale   1;
% 
% vertices
% (
%     (0 0 0)
%     (5 0 0)
%     (5 0.99905 -0.04362)
%     (0 0.99905 -0.04362)
%     (5 0.99905  0.04362)
%     (0 0.99905  0.04362)
% );
% 
% blocks
% (
%     hex (0 1 2 3 0 1 4 5) (50 10 1) simpleGrading (1 1 1)
% );
% 
% edges
% (
% arc 2 4 (5 1 0)
% arc 3 5 (0 1 0)
% );
% 
% boundary
% (
%     inlet
%     {
%         type patch;
%         faces
%         (
%             (0 5 3 0)
%         );
%     }
%     front
%     {
%         type wedge;
%         faces
%         (
%             (1 4 5 0)
%                        
%         );
% 	}
% 	back
%     {
%         type wedge;
%         faces
%         (
%             (0 3 2 1)
%                        
%         );	
%     }
%     top
%     {
%         type wall;
%         faces
%         (
%             (3 5 4 2)
%             
%         );
%     }
% 	outlet
%     {
%         type patch;
%         faces
%         (
%             (1 2 4 1)
%             
%             
%         );
%     }
% 	axis
%     {
%         type empty;
%         faces
%         (
%             (0 0 1 1)
%             
%             
%         );
%     }
% );
% 
% mergePatchPairs
% (
% );
% 
% // *************************************************************************

Boundary conditions:-

The boundary conditions and fluid properties were so decided that the resulting flow would be laminar.

Length, L= 0.9 m

Diameter, D = 0.05 m

Viscosity, = 1e-2 Pa-sec

Density, = 1000 kg/m3

Reynolds number, Re= 200

Entrance Length = 0.06 Re*D = 0.6m

`V_(avg)=(Reμ)/(ρD)=0.04m/s`

Pressure drop = 32**V*L/(D^2)

Velocity

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (0.04 0 0);
    }

    outlet
    {
        type            zeroGradient;
    }

    front
    {
        type            wedge;
    }
    top
    {
        type            noSlip;
    }
    back
    {
        type            wedge;
    }
    axis
    {
    	type 		empty;
    }
    
}

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

Pressure

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    inlet
    {
        type            zeroGradient;
    }

    outlet
    {
        type            fixedValue;
        value	         uniform 0;
    }

    top
    {
        type            zeroGradient;
    }
    front
    {
        type            wedge;
    }
    back
    {
    	type            wedge;
    }
    axis
    {
    	type 		empty;
    }
  
}

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

ControlDict

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  8
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     icoFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         25;

deltaT          0.01;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;
//////////////////////////////////
functions
{
#includeFunc residuals
}
//////////////////////////////////

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

Results

Geometry:-

Mesh:-

The mesh shows a grading effect where more number of cells are concentrated at the wall(top) region.

Contours of Velocity Magnitude:-

The contours are plotted with reflect command to give full view of the plane. The max velocity shown here matches the analytical max of 0.08m/s

Contours of Pressure Magnitude:-

The pressure drop across the pipe doesnt match the analytical results as Hagen Poiseulle equation gives pressure drop for a fully developed laminar flow and thus the variation of pressure is linear in the pipe. In our case the pressure drop is not linear as shown by the below image

Velocity profile accros the pipe

The plot over line command is used over the reflect command thus we get full velocity profile.Velocity profile development is observed across the pipe. The profile gets fully developed at approx 0.8m from the inlet.

Shear stress at outlet

Shear stress at outlet is captured. The variation in shear stress is linear and minimum at axis. Thus the trend matches with Hagen Poiseuille's flow.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.