Challenge

Simulation of Flow through a pipe in OpenFoam Part 2

AIM

The main objective of this project is to simulate the laminar flow over a pipe

OBJECTIVES

The objectives of the project are

  • Writing a matlab code for creating blockmeshdict file for various wedge angles
  • post process velocity and shear stress profiles for the wedge angles
  • comparison between symmetry, wedge and Hagen Poiseuille equation

IMPORTANT NOTE

This project is the continuation of "Simulation of Flow through a pipe in OpenFoam" for which the link for the first part is given below

https://skill-lync.com/projects/week-11-simulation-of-flow-through-a-pipe-in-openfoam-11

MATLAB CODE FOR BLOCKMESHDICT

clear all;
close all;
clc;

% 
Re=2100; 
rho=1000; 
D=0.02; 
R=D/2;
L_ent=0.06*Re*D;
mu=0.00089; 
nu=mu/rho; 
thetha=10;

%boundary conditions
v_avg= Re*nu/D;
v_max=2*v_avg;
L=L_ent+0.3;
deltap= (8*v_avg*mu*L)/R^2;


% Vertices co-ordinates in the local cordinate system
v0=[0 0 0]; 
v1=[0 R*cosd(thetha/2) -R*sind(thetha/2)]
v2=[0 R*cosd(thetha/2) R*sind(thetha/2)]
v3=[L 0 0]
v4=[L R*cosd(thetha/2) -R*sind(thetha/2)]
v5=[L R*cosd(thetha/2) R*sind(thetha/2)]

grading=0.2;
b1=50;
b2=1;
b3=200;

%creating blockmesh dict file for mesh generation of the wedge

h1='/*--------------------------------*- C++ -*----------------------------------*\';
h2='| =========                 |                                                 |';
h3='| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |';
h4='|  \\    /   O peration     | Version:  4.1                                   |';
h5='|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |';
h6='|    \\/     M anipulation  |                                                 |';
h7='\*---------------------------------------------------------------------------*/';

h8='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

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

fprintf(f1,'%s\n',h1);
fprintf(f1,'%s\n',h2);
fprintf(f1,'%s\n',h3);
fprintf(f1,'%s\n',h4);
fprintf(f1,'%s\n',h5);
fprintf(f1,'%s\n',h6);
fprintf(f1,'%s\n \n',h7);

fprintf(f1,'FoamFile \n {\n');
fprintf(f1,'%16s %10s\n','version',' 2.0;');
fprintf(f1,'%16s %12s\n','format',' ascii;');
fprintf(f1,'%16s %17s\n','class','dictionary;');
fprintf(f1,'%16s %20s\n','object','blockMeshDict;');
fprintf(f1,'%2s\n','}');

fprintf(f1,'%2s\n\n','// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //');
fprintf(f1,'%2s\n\n','converToMeters 1;');
fprintf(f1,'vertices \n (\n');
fprintf(f1, '\t(%d %d %d)\n',v0);
fprintf(f1, '\t(%d %d %d)\n',v1);
fprintf(f1, '\t(%d %d %d)\n',v2);
fprintf(f1, '\t(%d %d %d)\n',v3);
fprintf(f1, '\t(%d %d %d)\n',v4);
fprintf(f1, '\t(%d %d %d)\n',v5);
fprintf(f1,' %2s\n\n', ');')

fprintf(f1,'blocks \n (\n');
fprintf(f1,' \t %s (%d %d %d) %s (%d 1 1) \n','hex (0 1 2 0 3 4 5 3)',b1,b2,b3,'simpleGrading',grading);
fprintf(f1,' %2s\n\n', ');');

fprintf(f1,'edges \n (\n');
fprintf(f1,'\t %s (0 %d 0)\n','arc 1 2',R);
fprintf(f1,'\t %s (%d %d 0)\n','arc 4 5',L,R);
fprintf(f1,' %2s\n\n', ');')

fprintf(f1,'boundary \n (\n');
fprintf(f1,' \t %5s \n','axis','{');
fprintf(f1,'\t %13s %s\n',' type','empty;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 3 3 0)',');','}');

fprintf(f1,' \t %5s \n','wall','{');
fprintf(f1,'\t %13s %s\n',' type','wall;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(2 5 4 1)',');','}');

fprintf(f1,' \t %5s \n','inlet','{');
fprintf(f1,'\t %13s %s\n',' type','patch;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 0 2 1)',');','}');

fprintf(f1,' \t %5s \n','outlet','{');
fprintf(f1,'\t %13s %s\n',' type','patch;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(3 4 5 3)',');','}');

fprintf(f1,' \t %5s \n','wedgeFront','{');
fprintf(f1,'\t %13s %s\n',' type','symmetry;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 3 5 2)',');','}');

fprintf(f1,' \t %5s \n','wedgeBack','{');
fprintf(f1,'\t %13s %s\n',' type','symmetry;');
fprintf(f1,'\t %14s\n %18s\n','faces','(');
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n %s\n\n','(0 1 4 3)',');','}',');');

fprintf(f1,'mergePatchPairs \n (\n );\n');
fprintf(f1,'%2s\n\n','// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //');

fclose(f1);

Now the matlab code is similar to the part one of this simulation, only changes that have been incorporated into the code is that the boundary conditions has been changed to symmetry boundary condition. For the blockmeshdict file generation we can see the output files for all the wedge angles of 10,25 and 45 degrees.

BLOCKMESH FILE FOR 10 DEGREES

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

converToMeters 1;

vertices 
 (
	(0 0 0)
	(0 0.00996195 -0.000871557)
	(0 0.00996195 0.000871557)
	(2.82 0 0)
	(2.82 0.00996195 -0.000871557)
	(2.82 0.00996195 0.000871557)
 );

blocks 
 (
 	 hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1) 
 );

edges 
 (
	 arc 1 2 (0 0.01 0)
	 arc 4 5 (2.82 0.01 0)
 );

boundary 
 (
 	  axis 
 	     { 
	          type empty;
	          faces
                  (
	 	       (0 3 3 0)
                  );

              }

 	  wall 
 	     { 
	          type wall;
	          faces
                  (
	 	       (2 5 4 1)
                  );

              }

 	 inlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (0 0 2 1)
                  );

              }

 	 outlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (3 4 5 3)
                  );

              }

 	 wedgeFront 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 3 5 2)
                  );

              }

 	 wedgeBack 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 1 4 3)
                  );

              }

 );

mergePatchPairs 
 (
 );
// * * * * * * * * * * * * * * * * * *

BLOCKMESH FILE FOR 25 DEGREES

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

converToMeters 1;

vertices 
 (
	(0 0 0)
	(0 0.00976296 -0.0021644)
	(0 0.00976296 0.0021644)
	(2.82 0 0)
	(2.82 0.00976296 -0.0021644)
	(2.82 0.00976296 0.0021644)
 );

blocks 
 (
 	 hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1) 
 );

edges 
 (
	 arc 1 2 (0 0.01 0)
	 arc 4 5 (2.82 0.01 0)
 );

boundary 
 (
 	  axis 
 	     { 
	          type empty;
	          faces
                  (
	 	       (0 3 3 0)
                  );

              }

 	  wall 
 	     { 
	          type wall;
	          faces
                  (
	 	       (2 5 4 1)
                  );

              }

 	 inlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (0 0 2 1)
                  );

              }

 	 outlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (3 4 5 3)
                  );

              }

 	 wedgeFront 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 3 5 2)
                  );

              }

 	 wedgeBack 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 1 4 3)
                  );

              }

 );

mergePatchPairs 
 (
 );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

BLOCKMESH FILE FOR 45 DEGREES

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

converToMeters 1;

vertices 
 (
	(0 0 0)
	(0 0.0092388 -0.00382683)
	(0 0.0092388 0.00382683)
	(2.82 0 0)
	(2.82 0.0092388 -0.00382683)
	(2.82 0.0092388 0.00382683)
 );

blocks 
 (
 	 hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1) 
 );

edges 
 (
	 arc 1 2 (0 0.01 0)
	 arc 4 5 (2.82 0.01 0)
 );

boundary 
 (
 	  axis 
 	     { 
	          type empty;
	          faces
                  (
	 	       (0 3 3 0)
                  );

              }

 	  wall 
 	     { 
	          type wall;
	          faces
                  (
	 	       (2 5 4 1)
                  );

              }

 	 inlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (0 0 2 1)
                  );

              }

 	 outlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (3 4 5 3)
                  );

              }

 	 wedgeFront 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 3 5 2)
                  );

              }

 	 wedgeBack 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 1 4 3)
                  );

              }

 );

mergePatchPairs 
 (
 );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ///*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
 
FoamFile 
 {
         version       2.0;
          format       ascii;
           class       dictionary;
          object       blockMeshDict;
 }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

converToMeters 1;

vertices 
 (
	(0 0 0)
	(0 0.0092388 -0.00382683)
	(0 0.0092388 0.00382683)
	(2.82 0 0)
	(2.82 0.0092388 -0.00382683)
	(2.82 0.0092388 0.00382683)
 );

blocks 
 (
 	 hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1) 
 );

edges 
 (
	 arc 1 2 (0 0.01 0)
	 arc 4 5 (2.82 0.01 0)
 );

boundary 
 (
 	  axis 
 	     { 
	          type empty;
	          faces
                  (
	 	       (0 3 3 0)
                  );

              }

 	  wall 
 	     { 
	          type wall;
	          faces
                  (
	 	       (2 5 4 1)
                  );

              }

 	 inlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (0 0 2 1)
                  );

              }

 	 outlet 
 	     { 
	          type patch;
	          faces
                  (
	 	       (3 4 5 3)
                  );

              }

 	 wedgeFront 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 3 5 2)
                  );

              }

 	 wedgeBack 
 	     { 
	          type symmetry;
	          faces
                  (
	 	       (0 1 4 3)
                  );

              }

 );

mergePatchPairs 
 (
 );
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

CONTROLDICT FILE

/*--------------------------------*- 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.001;

writeControl    timeStep;

writeInterval   200;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

BOUNDARY CONDITIONS

P FILE

/*--------------------------------*- 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
{
    axis
    {
        type            empty;
    }

    inlet
    {
        type            zeroGradient;
    }

    outlet
    {
        type            fixedValue;
        value           uniform 0.018;
    }
    wall
    {
       type            zeroGradient;
    }
    wedgeFront
    {
       type            symmetry;
    }
    wedgeBack
    {
       type            symmetry;
    }
}

U FILE

/*--------------------------------*- 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.09345 0 0);

boundaryField
{
    axis
    {
        type            empty;
    }
    inlet
    {
        type            fixedValue;
        value           uniform (0.09345 0 0);
    }
    outlet
    {
        type            zeroGradient;
    }
    wall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }

    wedgeFront
    {
        type            symmetry;
    }

    wedgeBack
    {
        type            symmetry;
    }
}

TRANSPORT PROPERTIES

/*--------------------------------*- 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    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu              [0 2 -1 0 0 0 0] 1e-6;


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

RESULTS

Velocity Distribution

Velocity Profile

The velocity profile becomes smoother and more parabolic in nature as we travel along the hydrodynamic length of the pipe. When we cut any section of the pipe to view the nature of the velocity profile we see that there is a parabolic variation or the gradients of the velocity.

PRESSURE PROFILE

We can observe the pressure drop across the length of the pipe where we are seeing the kinematic pressure variation across the length of the pipe. There is a parabolic decrease in kinematic pressure and then the curve linearizes for a linear pressure drop. the pressure in hydrodynamic region is parabolic variation whereas after the hydrodynamic length it is a linear variation in the pressure drop.

SHEAR STRESS PROFILES

Shear stress profiles look in the form of step formation as there is a fully developed flow. The shear stress at the walls is maximum and is almost zero in the axis region where it should be zero but in the profile we see there is a stress present near the axis.

COMPARITIVE STUDY BETWEEN SYMMETRY AND WEDGE BOUNDARY CONDITIONS

Velocity comparision

Wedge Angles/Boundary Conditions maximum velocity in simulation (m/s) maximum velocity in from HP equation(m/s) percentage error
2/Wedge BC 0.178081 0.1896 0.879
10/symmetry BC 0.178086 0.1896 1.154
25/symmetry BC 0.179093 0.1896 1.057
45/symmetry BC 0.181169 0.1896 0.843

Kinematic Pressure Comparision

Wedge Angles/Boundary Conditions kinematic pressure in simulation(m^2/s^2) kinematic pressure from HP equation Percentage Error
2/Wedge BC 0.018153 0.01876 0.0607
10/Symmetry BC 0.018024 0.01876 0.0736
25/Symmetry BC 0.018114 0.01876 0.0646
45/Symmetry BC 0.018126 0.01876 0.0634

CONCLUSION

  1. The simulation results for symmetry boundary conditions is more accurate compared to the wedge boundary conditions
  2. it is also concluded that time taken for symmetry boundary condition is more than wedge boundary condition.
  3. The results obtained from symmetry and wedge are almost the same including the plots
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.