Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Project Title Simulation of flow through pipe using OpenFoam.

Description: In engineering is facinated with fluid flows having lamimar and turbulent flows. Fundamentally we can corrrelate the the pipe flow with laminar and turbulent nature. We defined non dimensional number called Reynolds Number.

`Re=(rho*v*d)/(mu)`

where `rho=density`

`d=diameter`

`mu=(dynamic-vis cosity)`

when Re>2300 flow becomes turbulent.

`Re <= 2100` Flow is Laminar

Velocity Variation along Pipe

`V_(r)=1/(4(mu))*((dp)/dx)*(R^2-r^2)`

So from above relation the velocity is varying in parabolic Nature.

and It will be maximum at center of pipe.

According Hagen poiseuille's equation the pressure drop is given by

`Deltap=(32 mu*Vavg*L)/(D^2)`

Pipe flow velocity and boundary layer formation according to mathematical model

So for this problem `Re=2100`

diamter=0.01

`mu=0.00089 Pa S`

`rho=1000 (Kg)/(m^3)`

So our average velocity is

`2100=(1000*Vavg*0.01)/(0.00089)`

`Vavg=0.1869 m/sec`

To determine length of Pipe for laminar flow for Fully Developed condition

`L=0.05*(Re*D)`

`L=0.05*2100*0.01`

`L=1.05 m` now assuming `L=1.2 m`

Now

`DeltaP=(32 *0.00089 *0.1869*1.2)/(0.01^2)`

`DeltaP=63.87 Pa`

For OpenFoam Simulation we can take following inputs

`L=1.2 m`

`D=0.01 m`

`mu=0.00000089 m^2/sec`

`Velocity at entry =0.1869 m/sec`

`(Pressure)/(rho)=(63.87/1000) m^2/sec^2``=0.06387 m^2/sec^2`

Generation of BlockMeshDict File

By inputing various wedge angle the blockmesh file can be generated.

Commonly %s and %f symbols are used.

File can be written as f2=fopen(f2,'blockMeshDict.c','w')

clc
clear all
close all

%Input the following Data
theta=input('enter the value of the wedge angle thea=');
diameter=0.01;
radius=(diameter)/2;
length=1.2;
conv='convertToMeters';
b='blocks';
e='edges';
b1='boundary'
v='vertices';
m='mergePatchPairs'

x1=blanks(5);
x2=blanks(8);

%........................OpenFOAM................blockMeshDict.................

h1='/*––––––––––––––––––––––––––––––--*- C++ -*–––––––––––––––––––––––––––––––––-*\ ';
h2='| =========                 |                                                   ';
h3='| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox             ';
h4='|  \\    /   O peration     | Version:  4.0                                     ';
h5='|   \\  /    A nd           | Web:      www.OpenFOAM.org                        ';
h6='|    \\/     M anipulation  |                                                   ';
h7=' \*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/ ';
h8='FoamFile'
h9='{';
h10='    version     2.0;'
h11='    format      ascii;'
h12='    class       dictionary;'
h13='    object      blockMeshDict;'
h14='}';
h15='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

%...............................................................................................
h18='// ************************************************************************* //'
%......................Assigning Vertices.........................
v0=[0 0 0];
v1=[radius*sind(theta/2) radius*cosd(theta/2) 0];
v2=[-radius*sind(theta/2) radius*cosd(theta/2) 0];
v3=[0 0 length];
v4=[radius*sind(theta/2) radius*cosd(theta/2) length];
v5=[-radius*sind(theta/2) radius*cosd(theta/2) length];

block=' hex (0 0 1 2 3 3 4 5) (1 50 250) simpleGrading (1 0.2 1)';

edge1='arc 1 2';
edge2='arc 4 5';

e1=[0 radius 0];
e2=[0 radius length];

inflow='(0 1 2 0)';
outflow='(3 5 4 3)';
wedge1='(0 3 4 1)';
wedge2='(0 2 5 3)';
wall='(1 4 5 2)';
axis='(0 3 3 0)';

f2=fopen('blockMeshDict.C','w')
fprintf(f2,'%s   \n',h1);
fprintf(f2,'%s   \n',h2);
fprintf(f2,'%s   \n',h3);
fprintf(f2,'%s   \n',h4);
fprintf(f2,'%s   \n',h5);
fprintf(f2,'%s   \n',h6);
fprintf(f2,'%s   \n',h7);
fprintf(f2,'%s   \n',h8);
fprintf(f2,'%s   \n',h9);
fprintf(f2,'%s   \n',h10);
fprintf(f2,'%s   \n',h11);
fprintf(f2,'%s   \n',h12);
fprintf(f2,'%s   \n',h13);
fprintf(f2,'%s   \n',h14);
fprintf(f2,'%s   \n',h15);
fprintf(f2,'%s  %d  %s \n',conv,1,';');
fprintf(f2,'%s   \n',v);
fprintf(f2,'%s   \n','(');
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v0(1),v0(2),v0(3));
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v1(1),v1(2),v1(3));
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v2(1),v2(2),v2(3));
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v3(1),v3(2),v3(3));
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v4(1),v4(2),v4(3));
fprintf(f2,'%s  (%6.7f %6.7f %6.7f)\n', x1,v5(1),v5(2),v5(3));
fprintf(f2,'%s   \n',');');

fprintf(f2,'%s   \n',b);
fprintf(f2,'%s   \n','(');
fprintf(f2,'%s %s  \n',x1,block);
fprintf(f2,'%s   \n',');');

fprintf(f2,'%s   \n',e);
fprintf(f2,'%s   \n','(');
fprintf(f2,'%s %s (%6.7f %6.7f %6.7f)\n', x1,edge1,e1(1),e1(2),e1(3));
fprintf(f2,'%s %s (%6.7f %6.7f %6.7f)\n', x1,edge2,e2(1),e2(2),e2(3));
fprintf(f2,'%s   \n',');');

fprintf(f2,'%s   \n',b1);
fprintf(f2,'%s   \n','(');


fprintf(f2,'%s %s    \n',x1,'inlet');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type patch;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,inflow);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');

fprintf(f2,'%s %s    \n',x1,'outlet');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type patch;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,outflow);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');

fprintf(f2,'%s %s    \n',x1,'front');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type wedge;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,wedge1);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');

fprintf(f2,'%s %s    \n',x1,'back');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type wedge;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,wedge2);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');

fprintf(f2,'%s %s    \n',x1,'wall');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type wall;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,wall);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');

fprintf(f2,'%s %s    \n',x1,'axis');
fprintf(f2,'%s %s    \n',x1,'{');
fprintf(f2,'%s %s    \n',x2,'type empty;');
fprintf(f2,'%s %s    \n',x2,'faces');
fprintf(f2,'%s %s    \n',x2,'(');
fprintf(f2,'%s %s    \n',x2,axis);
fprintf(f2,'%s %s    \n',x2,');');
fprintf(f2,'%s %s    \n',x1,'}');
fprintf(f2,'%s   \n',');');

fprintf(f2,'%s   \n',m);
fprintf(f2,'%s   \n','(');
fprintf(f2,'%s   \n',');');

fprintf(f2,'%s   \n',h18);

fclose(f2);

After running above Code with wedge angle `2 ^(0)`

The blockMesh file is generated as below.

Mainly axisymmetric pipe is modelled for this case

/*––––––––––––––––––––––––––––––--*- C++ -*–––––––––––––––––––––––––––––––––-*\    
| =========                 |                                                      
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox                
|  \\    /   O peration     | Version:  4.0                                        
|   \\  /    A nd           | Web:      www.OpenFOAM.org                           
|    \\/     M anipulation  |                                                      
 \*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/    
FoamFile   
{   
    version     2.0;   
    format      ascii;   
    class       dictionary;   
    object      blockMeshDict;   
}   
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //   
convertToMeters  1  ; 
vertices   
(   
       (0.0000000 0.0000000 0.0000000)
       (0.0000873 0.0049992 0.0000000)
       (-0.0000873 0.0049992 0.0000000)
       (0.0000000 0.0000000 1.2000000)
       (0.0000873 0.0049992 1.2000000)
       (-0.0000873 0.0049992 1.2000000)
);   
blocks   
(   
       hex (0 0 1 2 3 3 4 5) (1 50 250) simpleGrading (1 0.2 1)  
);   
edges   
(   
      arc 1 2 (0.0000000 0.0050000 0.0000000)
      arc 4 5 (0.0000000 0.0050000 1.2000000)
);   
boundary   
(   
      inlet    
      {    
         type patch;    
         faces    
         (    
         (0 1 2 0)    
         );    
      }    
      outlet    
      {    
         type patch;    
         faces    
         (    
         (3 5 4 3)    
         );    
      }    
      front    
      {    
         type wedge;    
         faces    
         (    
         (0 3 4 1)    
         );    
      }    
      back    
      {    
         type wedge;    
         faces    
         (    
         (0 2 5 3)    
         );    
      }    
      wall    
      {    
         type wall;    
         faces    
         (    
         (1 4 5 2)    
         );    
      }    
      axis    
      {    
         type empty;    
         faces    
         (    
         (0 3 3 0)    
         );    
      }    
);   
mergePatchPairs   
(   
);   
// ************************************************************************* //   

Now generate blockMesh is OpenFoam.

Set 0 folder with initial comditions such as

Pressure

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


    wall
    {
        type            zeroGradient;
    }

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

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

Insert Velocity Conditions

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

    wall
    {
        type            noSlip;
        value           uniform (0 0 0);
    }

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

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

Now Set ControlDict As below

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

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

Now Run icoFoam

Results and Discussions

  • Its observed that maximum velocity is around 0.37 m/sec around centreline of pipe
  • From analytical calculation its 2*Vavg so its around 0.3738 m/sec
  • So simulation results are matching perfectly with analytical calculations. So we can validate our results

Velocity Comparison

  • Maximum velocity is obseved in wedge 4 degree case.
  • The results are validated with analytical results.
  • By simulation Vmax=0.37 m/sec and by analytical calaculation Vmax=0.3738 m/sec.
  • Deviation of 1% which is in acceptable limits.
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.