Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Objective:

To simulate an axisymmetric flow by applying the wedge boundary condition. The flow is laminar and flows through a constant cross-section pipe at an inlet Reynold's number of 2100. To validate your results with the Hagen- Poiseuille's equations for the fully developed flow.

Flow condition:

Kinematic Viscosity: 8.9268 x 10^-7m2/s

Diameter of the pipe: 0.0015m

wedge angle: 4 degree

length of Pipe: 2.5m

Matlab Code:

clear all
close all
clc


%length
l = 2.5;
%angle
theta = 90-2;
%diameter
d = 15e-3;
%division
div_x = 2;
div_y = 2;
div_z = 1;
nodiv_z = linspace(0,l,div_z+1);
tot = div_x + div_y + div_z;

%computing vertices
d_lx = d;
d_lz = d;
a = 1;



for i = 1:length(nodiv_z)
    for j = 1: div_y+1
        
        if j == 1
        vertex(a,1:3) = [nodiv_z(i) 0 0];
    
        elseif j <= (div_y) && j > 1
        vertex(a,1:3) = [nodiv_z(i) d/2*sind(theta) d/2*cosd(theta)];
        d_lx = d_lx - d_lx/div_x;
        
        elseif j == 3
        d_lx = d;
        vertex(a,1:3) = [nodiv_z(i) d/2*sind(theta) -d/2*cosd(theta)];
            
            
        end
        
        a = a+1;
        
        
    end
    d_lx = d;
end

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

for i = 1:17
    A = fgetl(f1);
    h_line = convertCharsToStrings(A);
    fprintf(f2,'%s\n',h_line)
end

 
 fprintf(f2,'vertices\n(')
 
 for i = 1:length(vertex)
 fprintf(f2,'\n\t(%f %f %f)\n',vertex(i,1:3))
        
 end
fprintf(f2,');\n\n');

fprintf(f2,'blocks\n(\n\thex(0 3 5 2 0 3 4 1)(200 20 1)SimpleGrading(0 0.1 1)\n);')
fprintf(f2,'\nedges\n(\n\tarc 1 2(0 %f 0)\n\tarc 4 5(%f %f 0)\n\n',d/2,l,d/2)       
    
    
fprintf(f2, 'boundary\n(\n')
fprintf(f2,'\n\t\tinlet\n\t\t{\n\t\ttype patch;\n\t\tfaces\n\t\t(\n\t\t\t(0 1 2 0)\n\t\t);\n\t\t}')
fprintf(f2,'\n\t\toutlet\n\t\t{\n\t\ttype \tpatch;\n\t\tfaces\n\t\t(\n\t\t\t(3 5 4 3)\n\t\t);\n\t\t}\n')
fprintf(f2,'\n\t\ttop\n\t\t{\n\t\ttype \twall; \n\t\tfaces\n\t\t(\n\t\t\t(1 4 5 2)\n\t\t);\n\t\t}\n')
fprintf(f2,'\n\t\tfront\n\t\t{\n\t\ttype \twedge; \n\t\tfaces\n\t\t(\n\t\t\t(0 3 4 1)\n\t\t);\n\t\t}\n')
fprintf(f2,'\n\t\tback\n\t\t{\n\t\ttype \twedge; \n\t\tfaces\n\t\t(\n\t\t\t(0 2 5 3)\n\t\t);\n\t\t}\n')
fprintf(f2,'\n\t\taxis\n\t\t{\n\t\ttype \tempty; \n\t\tfaces\n\t\t(\n\t\t\t(0 3 3 0)\n\t\t);\n\t\t}\n')

fprintf(f2,');\n')
fprintf(f2,'mergePatchPairs\n')
fprintf(f2,'(\n);\n')

Blockmesh Dict:

/*--------------------------------*- 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 0 0)
	(0 7.495431e-03 2.617462e-04)
	(0 7.495431e-03 -2.617462e-04)
	(2.500000e+00 0 0)
	(2.500000e+00 7.495431e-03 2.617462e-04)
	(2.500000e+00 7.495431e-03 -2.617462e-04)
	);
blocks
	(
	hex (0 3 5 2 0 3 4 1) (200 20 1) SimpleGrading (1 0.1 1)
	);
edges
	(
	arc 1 2 (0 7.5e-03 0)
	arc 4 5 (2.500000e+00 7.5e-03 0)
	);
boundary
	(
		inlet
		{
			type patch;
		faces
		(
			(0 1 2 0)
		);
		}
		outlet
		{
			type patch;
		faces
		(
			(3 5 4 3)
		);
		}
		top
		{
			type wall;
		faces
		(
			(1 4 5 2)
		);
		}
		front
		{
			type wedge;
		faces
		(
			(0 3 4 1)
		);
		}
		back
		{
			type wedge;
		faces
		(
			(0 2 5 3)
		);
		}
		axis
		{
			type empty;
		faces
		(
			(0 3 3 0)
		);
		}
	);
mergePatchPairs
(
);
// ************************************************************************* //

ControlDict:

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

	deltaT 0.02;

	writeControl timeStep;

	writeInterval 20;

	purgeWrite 0;

	writeFormat ascii;

	writePrecision 6;

	writeCompression off;

	timeFormat general;

	timePrecision 6;

	runTimeModifiable true;


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

Pressure:

/*--------------------------------*- 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;
}
	axis
{
	type 	empty;
	
}
	top
{
	type 	zeroGradient;
}
	front
{
	type	wedge;
}
	back
{
	type	wedge;
}
}

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

Velocity:

/*--------------------------------*- 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.1190 0 0);
	}
	outlet
	{
		type
		zeroGradient;
	}
	axis
	{
		type empty;

	}
	top
	{
		type fixedValue;
		value uniform (0 0 0);
	}
	front
	{
	type	wedge;
	}
	back
	{
	type	wedge;
	}
}
// ************************************************************************* //

Results:

Mesh:

Pressure:

Pressure Inlet

Pressure Outlet

Velocity:

Velocity Inlet

Velocity outlet

Velocity variation at midpoint:

Pressure variation along the length of the wedge:

Pressure variation after fully developed flow:

Shear stress distribution at 2.5:

Parameter Theoretical Value Computed Value Percentage error
Maximum Velocity 0.2380 0.2353 1.13
Pressure drop (fully developed) 0.012086 0.012193 0.88
Shear Stress 0.05665 0.05505 2.82

Conclusion

Hagen Poisuille flow simulation was performed and the results were validated with the theoretical results

Initially, at the entrance of the pipe, a boundary layer is formed which has an effect on the velocity gradient, the length up to which the velocity profile varies is called the hydrodynamic entry length and reaches a point beyond which the velocity profile is the same at any point. Thus forms a fully developed 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.