Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Aim : To numerically validate the Hagen- Poiseuille's equation for the laminar flow through pipe.

Theory :

code of blockMeshDict file

/*--------------------------------*- 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;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(
    (0.00035 0 0) //0 
    (0.0007 0.0099 0) //1
    (0 0.0099 0) //2
    (0.00035 0 3) //3
    (0.0007 0.0099 3) //4
    (0 0.0099 3) //5
);

blocks
(
    hex (0 1 2 0 3 4 5 3) (40 1 250) simpleGrading (0.1 1 1)
);

edges
(	
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 2 1 0)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (3 4 5 3)
        );
    }
    upperWall
    {
        type wall;
        faces
        (
            (1 2 5 4)
        );
    }
    lowerWall
    {
        type wall;
        faces
        (
            (0 3 3 0)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 5 2)
            (0 1 4 3)
        );
    }
);

mergePatchPairs
(
);

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

code of blockMeshDict file using Matlab

close all
clear all
clc;

l = 3;
d = 0.02;
r = d/2;
angle = 4;
alpha = angle/2;

f1 = fopen('blockMeshDict.txt','w');


fprintf(f1,'/*--------------------------------*- C++ -*----------------------------------*/\n');
fprintf(f1,'  =========                 |\n');
fprintf(f1,'  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox\n');
fprintf(f1,'   \\    /   O peration     | Website:  https://openfoam.org\n');
fprintf(f1,'    \\  /    A nd           | Version:  8\n');
fprintf(f1,'     \\/     M anipulation  |\n');
fprintf(f1,'\*---------------------------------------------------------------------------*/\n');
fprintf(f1,'FoamFile\n');
fprintf(f1,'{\n');
fprintf(f1,'    version     2.0;\n');
fprintf(f1,'    format      ascii;\n');
fprintf(f1,'    class       dictionary;\n');
fprintf(f1,'    object      blockMeshDict;\n');
fprintf(f1,'}\n');
fprintf(f1,'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n');
fprintf(f1,'\nconvertToMeters 1;\n');
fprintf(f1,'\nvertices\n');
fprintf(f1,'(\n');
fprintf(f1,'    (%f',r*sind(alpha));
fprintf(f1,' 0 0) //0 \n');
fprintf(f1,'    (%f',2*r*sind(alpha)); 
fprintf(f1,' %f',r*cosd(alpha));
fprintf(f1,' 0) //1\n');
fprintf(f1,'    (0');
fprintf(f1,'  %f',r*cosd(alpha));
fprintf(f1,' 0) //2\n');
fprintf(f1,'    (%f',r*sind(alpha));
fprintf(f1,' 0 %f',l);
fprintf(f1,') //3\n');
fprintf(f1,'    (%f',2*r*sind(alpha));
fprintf(f1,' %f',r*cosd(alpha));
fprintf(f1,' %f',l); 
fprintf(f1,'//4\n');
fprintf(f1,'    (0 %f',r*cosd(alpha));
fprintf(f1,' %f',l);
fprintf(f1,'//5\n');
fprintf(f1,');\n');
fprintf(f1,'\nblocks\n');
fprintf(f1,'(\n');
fprintf(f1,'    hex (0 1 2 0 3 4 5 3) (40 1 250) simpleGrading (0.1 1 1)\n');
fprintf(f1,');\n');
fprintf(f1,'\nedges\n');
fprintf(f1,'(\n');
fprintf(f1,');\n');
fprintf(f1,'\nboundary\n');
fprintf(f1,'(\n');
fprintf(f1,'    inlet\n');
fprintf(f1,'    {\n');
fprintf(f1,'        type patch;\n');
fprintf(f1,'        faces\n');
fprintf(f1,'        (\n');
fprintf(f1,'            (0 2 1 0)\n');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,'    outlet\n');
fprintf(f1,'    {\n');
fprintf(f1,'        type patch;\n');
fprintf(f1,'        faces\n');
fprintf(f1,'        (\n');
fprintf(f1,'            (3 4 5 3)\n');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,'    upperWall\n');
fprintf(f1,'    {\n');
fprintf(f1,'        type wall;\n');
fprintf(f1,'        faces\n');
fprintf(f1,'        (\n');
fprintf(f1,'            (1 2 5 4)\n');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,'    lowerWall\n');
fprintf(f1,'    {\n');
fprintf(f1,'        type wall;\n');
fprintf(f1,'        faces\n');
fprintf(f1,'        (\n');
fprintf(f1,'            (0 3 3 0)\n');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,'    frontAndBack\n');
fprintf(f1,'    {\n');
fprintf(f1,'        type empty;\n');
fprintf(f1,'        faces\n');
fprintf(f1,'        (\n');
fprintf(f1,'            (0 3 5 2)\n');
fprintf(f1,'            (0 1 4 3)\n');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,');\n');
fprintf(f1,'\nmergePatchPairs\n');
fprintf(f1,'(\n');
fprintf(f1,');\n');
fprintf(f1,'// ************************************************************************* //\n');

code of pressure file

/*--------------------------------*- 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.02008;
    }
    upperWall
    {
        type            zeroGradient;
    }
    lowerWall
    {
        type            zeroGradient;
    }
    frontAndBack
    {
        type            empty;
    }
}

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

code of velocity file

/*--------------------------------*- 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 0 0.094);
    }

    outlet
    {
        type            zeroGradient;
    }

    upperWall
    {
        type            noSlip;
    }

    lowerWall
    {
        type            noSlip;
    }
    
    frontAndBack
    {
        type            empty;
    }
}

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

code of controlDict file

dt = 0.01 sec

end time = length/avg velocity = 30 sec (approx.)

/*--------------------------------*- 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         30;

deltaT          0.01;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

velocity profile at x = 0.2 m

velocity profile at x = 1 m

velocity profile at x = 2 m

velocity profile at x = 2.5 m

velocity profile at x = 2.8 m

fully developed velocity profile

pressure drop across the length

Shear-stress curve for pipe 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.