Project

Simulation of flow through a pipe

Objective:-

To write a program using octave and OpenFoam, and using Hagen\'s poiseuille\'s equation for simulation of flow through a pipe.

Hydrodynamic Length:-

\"\"

The hydrodynamic entrance region refers to the area of the pipe where fluid entering a pipe develop a velocity profile due to visocous force propogating from the interior wall of pipe as shown in figure. Due to visocus forces within the fluid, the layer in contact with the pipe surface resist the motion of adjacent layer of fluid down gradually forming a velocity profile as shown in figure.

Given data:-

The working fluid is water

Reynold\'s Number (Re) = 2100

Entry Length for laminar flow (Le) = `0.06 * Re*D`

Diameter of pipe (D) = 0.02

Radius of Pipe (r) = D/2

density of water at 25 degree C = 997 `frac{kg}{m^3}`

kinematic viscosity (`mu`) = 8.9e-4

Length of pipe (L) = 0.3 +Le

Hagen\'s Poiseuille flow equation:-

`v(avg)=frac{Re*mu}{rho*D}`

`v(max)=2*v(avg)`

`triangleP=frac{8*mu*L*v(avg)}{r^2}`

kinematic pressure `(triangleP(k))=frac{triangleP}{rho}`

`tau=frac{2*mu*v(max)*R}{r^2}`

Code:-

Ocatave code

clear all
close all
clc

% Reynold Number
Re=2100;
% Diameter of Pipe
D=0.02;
% Entry length of pipe
L_entry=0.06*Re*D;
% Length of pipe
L=0.3+L_entry;
% Radius of pipe
r=D/2;
% Dynamic viscosity
nu=0.89e-4;
% Density
rho=997;
% Radial Radius
R=linspace(0,(D/2),1000)

% Hagen poiseuille flow equation
v_avg=(Re*nu)/(rho*D);
v_max=2*v_avg;
delta_p=(8*nu*L*v_avg)/(r^2);
kin_p=delta_p/rho;

% Shear Stress
for i=1:length(R)
  tau(i)=(2*nu*v_max*(abs(R(i))))/r^2;
endfor

% For Plot
plot(R,tau)
xlabel(\'Radial Radius\')
ylabel(\'Shear Stress\')

% For BlockMesh File
fprintf(\'Enter the theta value of 2,3,4 degree for wedge angle \\n\')
theta=input(\'Enter the wedge angle in degree\');

% Calculation of vertices
v1=[0 0 0]; %/0
v2=[0 r*cosd(theta/2) -r*sind(theta/2)]; %/1
v3=[0 r*cosd(theta/2) r*sind(theta/2)]; %/2
v4=[L 0 0]; %/3
v5=[L r*cosd(theta/2) -r*sind(theta/2)]; %/4
v6=[L r*cosd(theta/2) r*sind(theta/2)]; %/5

% For BlockMesh Header Format
header1=\'/*--------------------------------*- C++ -*----------------------------------*\\\';
header2=\'  =========                 |\';
header3=\'  \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox\';
header4=\'   \\\\    /   O peration     | Website:  https://openfoam.org\';
header5=\'    \\\\  /    A nd           | Version:  6\';
header6=\'     \\\\/     M anipulation  |\';
header7=\'\\*---------------------------------------------------------------------------*/\';

% For BlockMesh Directory Format
directory1=\'version     2.0;\';
directory2=\'format      ascii;\';
directory3=\'class       dictionary;\';
directory4=\'object      blockMeshDict;\';
directory5=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\';

conv=\'ConvertToMeters 1;\';
vertices1=\'vertices\';
block1=\'hex (0 3 4 1 0 3 5 2) (350 50 1) simpleGrading (1 0.1 1)\';
footer=\'//*********************************//\';

% Creating the BlockMesh file for OpenFOAM
f1=fopen(\'blockMeshDict.txt\',\'w\');
fprintf(f1,\'%s \\n\',header1);
fprintf(f1,\'%s \\n\',header2);
fprintf(f1,\'%s \\n\',header3);
fprintf(f1,\'%s \\n\',header4);
fprintf(f1,\'%s \\n\',header5);
fprintf(f1,\'%s \\n\',header6);
fprintf(f1,\'%s \\n\',header7);
fprintf(f1,\'%s \\n{\\n \\t\',\'Foamfile\');
fprintf(f1,\'%s \\n\\t\',directory1);
fprintf(f1,\'%s \\n\\t\',directory2);
fprintf(f1,\'%s \\n\\t\',directory3);
fprintf(f1,\'%s \\n\\t\',directory4);
fprintf(f1,\'%s \\n\\t\',directory5);
fprintf(f1,\'%s \\n\\n\',conv);
fprintf(f1,\'%s \\n(\\t\\t\',vertices1);
fprintf(f1,\'(%f %f %f)\\n\\t\',v1(1),v1(2),v1(3));
fprintf(f1,\'(%f %f %f)\\n\\t\',v2(1),v2(2),v2(3));
fprintf(f1,\'(%f %f %f)\\n\\t\',v3(1),v3(2),v3(3));
fprintf(f1,\'(%f %f %f)\\n\\t\',v4(1),v4(2),v4(3));
fprintf(f1,\'(%f %f %f)\\n\\t\',v5(1),v5(2),v5(3));
fprintf(f1,\'(%f %f %f)\\n\\t\',v6(1),v6(2),v6(3));

% Printing the block1
fprintf(f1,\'\\nblock\\n\');
fprintf(f1,\'(\\n\\t\');
fprintf(f1,\'%s\\n);\\n\',block1);

% Printing edge
fprintf(f1,\'\\nedge\\n(\\n\');
fprintf(f1,\'\\tarc 1 2 (0 %f 0)\\n\',r);
fprintf(f1,\'\\tarc 4 5 (0 %f %f)\\n);\\n\',L,r);

% Printing the boundary
fprintf(f1,\'\\nboundary\\n(n\');
fprintf(f1,\'\\naxis\\n\\t{\\n\\ttype empty;\\n\');
fprintf(f1,\'\\t\\tfaces\\n\\t\\t(\\n\\t\\t\\t(0 3 3 0)\\n\\t\\t);\\n\\t}n;\');

fprintf(f1,\'\\twall\\n\\t{\\n\');
fprintf(f1,\'\\t\\ttype wall;\\n\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(f1,\'\\t\\t\\t(2 5 4 1)\\n\\t\\t);\\n\\t}\\n\');

fprintf(f1,\'\\tinlet\\n\\t{\\n\');
fprintf(f1,\'\\t\\ttype patch;\\n\\t\\tfaces\\n\');
fprintf(f1,\'\\t\\t(\\n\\t\\t\\t(0 1 2 0)\\n\\t\\t);\\n\\t}\\n\');

fprintf(f1,\'\\toutlet\\n\\t{\\n\');
fprintf(f1,\'\\t\\ttype patch;\\n\\t\\tfaces\\n\');
fprintf(f1,\'\\t\\t(\\n\\t\\t\\t(3 4 5 3)\\n\\t\\t);\\n\\t}\\n\');

fprintf(f1,\'\\tfront\\n\\t{\\n\');
fprintf(f1,\'\\t\\ttype wedge;\\n\\t\\tfaces\\n\');
fprintf(f1,\'\\t\\t(\\n\\t\\t\\t(0 3 5 2)\\n\\t\\t);\\n\\t}\\n\');

fprintf(f1,\'\\tback\\n\\t{\\n\');
fprintf(f1,\'\\t\\ttype wedge;\\n\\t\\tfaces\\n\');
fprintf(f1,\'\\t\\t(\\n\\t\\t\\t(0 1 4 3)\\n\\t\\t);\\n\\t}\\n);\\t\');

fprintf(f1,\'\\nmergePatchPairs \\n(\\n);\\n\');
fprintf(f1,\'\\n%s\',footer);

\"\"

BlockMesh File

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

convertToMeters 1;

vertices
(
    (0.000000 0.000000 0.000000) //0
    (0.000000 0.009996 -0.000261) //1
    (0.000000 0.009996 0.000261) //2
    (2.520000 0.000000 0.000000) //3
    (2.520000 0.009996 -0.000261) //4
    (2.520000 0.009996 0.000261) //5
);

blocks
(
    hex (0 3 4 1 0 3 5 2) (350 50 1) simpleGrading (1 0.1 1)
);

edges
(
    arc 1 2 (0.000000 0.010000 0.000000)
    arc 4 5 (0.000000 2.820000 0.010000)
);

boundary
(
    axis
    {
        type empty;
        faces
        (
            (0 3 3 0)
        );
    }
    wall
    {
        type wall;
        faces
        (
            (2 5 4 1)
        );
    }
    inlet
    {
        type patch;
        faces
        (
            (0 1 2 0)
        );
    }
    outlet
    { 
        type patch;
        faces
        (
            (3 4 5 3)
        );
    }
    front
    {
        type wedge;
        faces
        (
            (0 3 5 2)
        );
    }
    back
    {
        type wedge;
        faces
        (
            (0 1 4 3)
        );
    }
);

mergePatchPairs
(
);

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

control file

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

application     icoFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         10;

deltaT          1e-3;

writeControl    timeStep;

writeInterval   10;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

p

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

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

internalField   uniform 0;

boundaryField
{
    axis
    {
        type            empty;
    }

    wall
    {
        type            zeroGradient;
    }

    inlet
    {
        type            zeroGradient;
    }
    
    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }
   
    front
    {
        type            wedge;
    }
 
    back
    {
        type            wedge;
    }
}

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

U

/*--------------------------------*- C++ -*----------------------------------*\\
  =========                 |
  \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\\\    /   O peration     | Website:  https://openfoam.org
    \\\\  /    A nd           | Version:  6
     \\\\/     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
{
    axis
    {
        type            empty;
    }

    wall
    {
        type            noSlip;
    }

    inlet
    {
        type            fixedValue;
        value           uniform (0.0973 0 0);
    }

    outlet
    {
        type            zeroGradient;
    }
 
    front
    {
        type            wedge;
    }
 
    back
    {
        type            wedge;
    }
}

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

transportProperties

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

nu              [0 2 -1 0 0 0 0] 8e-7;


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

Model:-

\"\"

Generating of Model

\"\"

Generating Mesh

\"\"

velocity Profile

Plot:-

At point 0m

\"\"

At point 0.5m

\"\"

At point 2.55m

\"\"

However at the distance 2.52m the velocity profile is completed.

Shear Stress:-

  • When a fluid is in a motion, shear stress are developed due to particle in the fluid moving relative to one another.
  • For a fluid flowing in a pipe, fluid velocity will be zero the pipe wall. Velocity will increase while moving toward the centre of pipe shear force are normally present because adjacent layer of the fluid move with different velocities compared to each other.

\"\"

Hence, Shear Stress are maximum at the wall and minimum at the centre of pipe.

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.