Project

Simulation of Flow through a pipe in OpenFoam 1

objective

  • Reynolds number based on pipe diameter and inlet velocity should be 2100
  • Working fluid - water
  • to calculate the length of the pipe
    • to Calculate length of the pipe using the entry length formula for laminar flow through a pipe
    • to Show that entry length is sufficient to produce a fully developed flow and to compare velocity profiles at different positions along the length of the pipe.
  • Solver - icoFOAM

Hagen–Poiseuille Equation

The Hagen–Poiseuille Equation (or Poiseuille equation) is a fluidic law to calculate flow pressure drop in a long cylindrical pipe and it was derived separately by Poiseuille and Hagen in 1838 and 1839, respectively.

Consider a steady flow of an incompressible Newtonian fluid in a long rigid pipe. Using conservation equations and boundary conditions for cylindrical coordinates, the laminar flow has a parabolic profile from zero at the wall to a maximum velocity at the centerline

Longitudinal cutting view of a pipe with a laminar flow and parabolic velocity profile.

Vz=ΔPR24μL(1−r2R2)0≤r≤R\">Vz=ΔPR24μL(1−r2R2)0≤r≤R
Vmax=ΔPR24μL\">Vmax=ΔPR24μL

Considering the definition of average velocity in cylindrical coordinates and, the average velocity in the pipe

V¯=12Vmax\">V¯=12Vmax

The volumetric flow rate (Q) equals cross-section area multiplied by average velocity (Q=V¯A)\">(Q=V¯A), so

ΔP=8μLQπR4\">ΔP=8μLQπR4

octVE program

clear all
close all
clc
%datum
Re=2100;
D=0.004;
L=0.06*Re*D
L_p=L+0.7;
r=D/2;
theta=4;
mu=0.89e-3
rho=997
%formula
v_avg=(Re*mu)/(rho/D);
v_max=2*(v_avg);
del_p=(8*mu*L_p*v_avg)/(r^2);
kinematic_p=del_p/rho;
%calculating shear strss
R=linspace(0,(D/2),1000);
for i=1:length(R);
tau(i)=2*mu*v_max*(abs(R(i)))/(r^2);
end
plot(R,tau)
xlabel(\'radius\')
ylabel(\'shear stress\')
grid on
legend(\'shear stress\')




header1=\'/*--------------------------------*- C++ -*----------------------------------*\\\'
header2=\'| =========                 |                                                 |\'
header3=\'| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\'
header4=\'| \\\\    /   O peration     | Version:  2.2.1                                 |\'
header5=\' |  \\\\  /    A nd           | Web:      www.OpenFOAM.com                      |\'
header6=\'|    \\\\/     M anipulation  |                                                 |\'
header7=\'\\*---------------------------------------------------------------------------*/\'

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,\'FOamFile\\n{\\n\')
fprintf(f1,\'%12s\\t 2.0;\\n\',\'version\')
fprintf(f1,\'%12s\\t ascii;\\n\',\'format\')
fprintf(f1,\'%12s\\t dictionary;\\n\',\'class\')
fprintf(f1,\'%12s\\t blockMeshDict;\\n\',\'object\')
fprintf(f1,\'}\\n\')
header8=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\'
fprintf(f1,\'%s\\n\\n\',header8)


fprintf(f1,\'convertToMeters 1;\\n\\n\')

fprintf(f1,\'vertices\\n\')
fprintf(f1,\'(\\n\')
fprintf(f1, \'\\t (%d %d %d)\\n\',0,0,0)
fprintf(f1,\'\\t(%d %d %d)\\n\',0,r*cosd(theta/2),r*sind(theta/2))
fprintf(f1,\'\\t(%d %d %d)\\n\',0,r*cosd(theta/2),-r*sind(theta/2))
fprintf(f1,\'\\t(%d %d %d)\\n\',L_p,0,0)
fprintf(f1,\'\\t(%d %d %d)\\n\',L_p,r*cosd(theta/2),r*sind(theta/2))
fprintf(f1,\'\\t(%d %d %d)\\n\',L_p,r*cosd(theta/2),-r*sind(theta/2))
fprintf(f1, \');\\n\\n\')


fprintf(f1,\'blocks\\n\')
fprintf(f1,\'(\\n\')
fprintf(f1, \'\\t hex (0 3 5 2 0 3 4 1)(%d %d %d)\',300,30,1)
fprintf(f1,\'simpleGrading(1 0.1 1)\\n\\n\')
fprintf(f1,\');\\n\\n\')


fprintf(f1,\'boundary\\n\')
fprintf(f1,\'(\\n\')
fprintf(f1,\'\\t inlet\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type patch;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (0 1 2 0)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')



fprintf(f1,\'\\t outlet\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type patch;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (3 5 4 3)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')



fprintf(f1,\'\\t top\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type wall;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (1 4 5 2)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')



fprintf(f1,\'\\t front\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type wedge;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (0 3 4 1)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')



fprintf(f1,\'\\t back\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type wedge;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (0 2 5 3)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')



fprintf(f1,\'\\t axis\\n\')
fprintf(f1,\'\\t {\\n\')
fprintf(f1,\'\\t\\t type empty;\\n\')
fprintf(f1,\'\\t\\t faces\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t\\t\\t (0 3 3 0)\\n\')
fprintf(f1,\'\\t\\t(\\n\')
fprintf(f1,\'\\t}\\n\')
fprintf(f1,\')\\n\\n\')


fprintf(f1,\'mergePatchPairs\\n\')
fprintf(f1,\'(\\n\')
fprintf(f1,\');\\n\')
header9=\'// ************************************************************************* //\'
fprintf(f1,\'%s\\n\',header9)
fclose(f1)


blockmesh

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

convertToMeters 1;

vertices
(
	 (0 0 0)
	(0 0.00199878 6.9799e-005)
	(0 0.00199878 -6.9799e-005)
	(1.204 0 0)
	(1.204 0.00199878 6.9799e-005)
	(1.204 0.00199878 -6.9799e-005)
);

blocks
(
	 hex (0 3 5 2 0 3 4 1) (300 30 1) simpleGrading (1 0.1 1)

);
edges
(
	 arc 1 2 (0 2e-3 0)
	 arc 4 5 (1.204 2e-3 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
(
);
// ************************************************************************* //


velocity

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

boundaryField
{
   inlet
    {
        type           fixedValue;
	value 	uniform (0.4686 0 0); 
    }    
outlet
    {
        type            zeroGradient;
    }

   
    axis
    {
        type            empty;
    }
top
    {
        type            fixedValue;
	value 		uniform (0 0 0); 
    }    
front
    {
        type            wedge;
    } 
back
    {
        type            wedge;
    }    
}

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

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 1.0073;
    }

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

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

generated mesh and velocity profile

velocity plot at 1m from entry length

velocity plot at 2m from entry length

conclusion:

the octave program was created and the blockMesh was automatically created and the simuaktion as done the plots were plotted.

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.