Project

Simulation of Flow through a pipe in OpenFoam

  • Density of water = 998 kg/m3
  • Dynamic viscosity of water = 8.90 *10-4 Pa. s
  • Reynolds no = 2100
  • Let the Diameter = 0.01 m
  • Inlet velocity = 0.1874 m/s

Entry length for a laminar pipe is = L = 0.05*Re*D = 1.05 m

Therefore for the simulation, a length of 1.5 m has been taken which is greater than the entry length.

According to Hagen-Poiseuille theory,

According to Hagen-Poiseuille theory,

Uavg = (Re*μ)/(ρ*D) = 0.1874 m/s

Umax = 2* Uavg = 0.3748 m/s

Pressure drop = (32* μ* Uavg*L) / D2 = 80.06 Pa

Kinetic pressure drop = 80.06/998 = 0.0802 m2s-2

Matlab Code to generate blockMesh file:

clear all
close all
clc

%% Inputs
L = 1.5;
theta = 3;
r = 0.005;
a = 1;
b = 0.2;
c = 1;
nx = 200;
ny = 20;
nz =1;

%% 
line1=\'/*--------------------------------*- C++ -*----------------------------------*\\\';
line2=\' =========               |                                                     \';
line3=\' \\\\      / F ield        | OpenFOAM: The Open Source CFD Toolbox               \';
line4=\'  \\\\    /  O peration    | Version: 4.1                                        \';
line5=\'   \\\\  /   A nd          | Web: www.OpenFOAM.org                               \';
line6=\'    \\\\/    M anipulation |                                                     \';
line7=\'\\*---------------------------------------------------------------------------*/\';
line8=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//\';
line9=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//\';

bmd = fopen(\'blockMeshDict\',\'wt\')

fprintf(bmd,\'%s\\n\',line1);
fprintf(bmd,\'%s\\n\',line2);
fprintf(bmd,\'%s\\n\',line3);
fprintf(bmd,\'%s\\n\',line4);
fprintf(bmd,\'%s\\n\',line5);
fprintf(bmd,\'%s\\n\',line6);
fprintf(bmd,\'%s\\n\',line7);


fprintf(bmd,\'FoamFile\\n{\\n\');
fprintf(bmd,\'%18s \\t 2.0;\\n\',\'version\');
fprintf(bmd,\'%18s \\t ascii;\\n\',\'format\');
fprintf(bmd,\'%18s \\t dictionary;\\n\',\'class\');
fprintf(bmd,\'%18s \\t blockMeshDict;\\n\',\'object\');
fprintf(bmd,\'}\\n\');

fprintf(bmd, \'%s\\n\\n\',line8);

%% Vertices and blocks
fprintf(bmd, \'convertToMeters 1; \\n\\n\');
fprintf(bmd, \'vertices\\n(\\n\');
fprintf(bmd, \'\\t (%d %d %d)\\n\', 0,0,0);
fprintf(bmd, \'\\t (%d %d %d)\\n\', L,0,0);
fprintf(bmd, \'\\t (%d %d %d)\\n\', L, r*cosd(theta/2), r*sind(theta/2));
fprintf(bmd, \'\\t (%d %d %d)\\n\', 0, r*cosd(theta/2), r*sind(theta/2));
fprintf(bmd, \'\\t (%d %d %d)\\n\', 0, r*cosd(theta/2), -r*sind(theta/2));
fprintf(bmd, \'\\t (%d %d %d)\\n\', L, r*cosd(theta/2), -r*sind(theta/2));
fprintf(bmd, \');\\n\\n\');

fprintf(bmd, \'blocks\\n(\\n\');
fprintf(bmd,\'\\t hex (0 1 5 4 0 1 2 3)(%d %d %d)\', nx,ny,nz);
fprintf(bmd, \'simplegrading (%d %d %d)\\n\',a,b,c);
fprintf(bmd, \');\\n\\n\');
fprintf(bmd, \'edges\\n(\\n\\t arc %d %d (%d %d %d)\\n\',4,3,0,r,0);
fprintf(bmd, \'\\t arc %d %d (%d %d %d)\\n\',5,2,L,r,0);
fprintf(bmd, \');\\n\\n\');

fprintf(bmd, \'boundary\\n(\\n\');
%% Inlet patch
fprintf(bmd, \'\\t inlet\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type patch;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 0,0,3,4);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');

%% Outlet : patch
fprintf(bmd, \'\\t outlet\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type patch;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 1,5,2,1);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');

%% Front surface: wedge 1
fprintf(bmd, \'\\t front\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type wedge;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 0,1,2,3);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');

%% Back Surface : wedge 2
fprintf(bmd, \'\\t back\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type wedge;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 0,4,5,1);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');

%% Axis : empty
fprintf(bmd, \'\\t axis\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type empty;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 0,1,1,0);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');

%% Pipe Wall : wall 
fprintf(bmd, \'\\t pipewall\\n\');
fprintf(bmd, \'\\t{\\n\');
fprintf(bmd, \'\\t\\t type wall;\\n\');
fprintf(bmd, \'\\t\\t faces\\n\');
fprintf(bmd, \'\\t\\t ( \\n\');
fprintf(bmd, \'\\t\\t\\t (%d %d %d %d)\\n\', 3,2,5,4);
fprintf(bmd, \'\\t\\t ); \\n\');
fprintf(bmd, \'\\t } \\n\');
fprintf(bmd, \');\\n\');

%%
fprintf(bmd, \'mergePatchPairs\\n(\\n\');
fprintf(bmd, \');\\n\');
fprintf(bmd, \'%s \\n\', line9);

fclose (bmd)

Generated BlockMeshDict file:

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

convertToMeters 1; 

vertices
(
	 (0 0 0)
	 (1.500000e+00 0 0)
	 (1.500000e+00 4.998287e-03 1.308847e-04)
	 (0 4.998287e-03 1.308847e-04)
	 (0 4.998287e-03 -1.308847e-04)
	 (1.500000e+00 4.998287e-03 -1.308847e-04)
);

blocks
(
	 hex (0 1 5 4 0 1 2 3)(200 20 1)simplegrading (1 2.000000e-01 1)
);

edges
(
	 arc 4 3 (0 5.000000e-03 0)
	 arc 5 2 (1.500000e+00 5.000000e-03 0)
);

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

Pressure Boundary Condition:

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

    axis
    {
        type            empty;
    }

    front
    {
        type            wedge;
    }

    back
    {
        type            wedge;
    }

    pipewall
    {
        type            zeroGradient;
    }
}

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

Velocity Boundary Condition:

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

    outlet
    {
        type            zeroGradient;
    }

    axis
    {
        type            empty;
    }

    front
    {
        type            wedge;
    }

    back
    {
        type            wedge;
    }

    pipewall
    {
        type            fixedValue;
	value		uniform (0 0 0);
    }
}

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

ControlDict:

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

deltaT          0.000005;

writeControl    timeStep;

writeInterval   300;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

Meshing:

Velocity Field from inlet to outlet:

Initially, velocity will not be fully developed. Later it will go on developing. So initially at 0.005 m the velocity profile has been shown here. As the developing length is 1.05m, another profile has also been shown at 1.2 meter from the entrance and this shows that flow has become fully developed. The axes have not been shown in the snipped curves. Y axis is velocity magnitude. x- axis is the transverse length at specific positions of the pipe.

At 0.005 m:

At 1.2 m:

Change of pressure has also been shown throughout the pipe length.

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.