Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Assignment name- Simulation of Flow through a pipe in Open Foam

Objective-

  • To developed a program in MATLAB for file parsing
  • Simulation of open pipe (wedge boundary condition) and obtained the results

Some assumption and formula required for these assignments

Hydrodynamic entrance length- it is distance of flow travels in the pipe before it becomes fully developed. Entrance length refer length of entry region.

Hagen Poiseuille law -it is physical law gives pressure drop in an incompressible and Newtonian fluid in laminar flow

Detailed explanation Hagen Poiseuille law formula

MATLAB program for file parsing

clear all

close all

clc

%%%file preraising for openFoam in matlab

%%simulation of openpipe needed some information

%%flow is laminar

%%input Varibles

%Renoyled number

Re=2100;

%density of water(consider fluid is water)

rho=997;

%Diameter of pipe

D=0.02;

%Radius of pipe

R=D/2;

%entrance length

Le=0.06*Re*D;

%total length

L=Le+0.3;

%dynamic viscosity

dv=0.89e-3;

%kinematic viscosity

kv=dv/rho;

%average velocity

V_avg=(dv*Re)/(rho*D);

%maximum velocity

V_max=2*V_avg;

%wedge angle

theta=3;%(not consider value of theta greater than 5)

%%vertices of open pipe for blockmeshDict

v0=[0 0 0];

v1=[0 R*cosd(theta/2) -R*sind(theta/2)];

v2=[0 R*cosd(theta/2) R*sind(theta/2)];

v3=[L 0 0];

v4=[L R*cosd(theta/2) -R*sind(theta/2)];

v5=[L R*cosd(theta/2) R*sind(theta/2)];

% please take precaution I am using Captial V for velocity and small v for vertex)

%%calculating shear stress

r=linspace(0,(D/2),500);

for i=1:length(r)

tau(i)=2*dv*V_max*abs(r(i))/R^2;

end

figure(1)

plot(r,tau)

xlabel('Radius of pipe')

ylabel('shear sdtress')

title('shear stress')

legend('shear stress')

%header of script file

h1='/*--------------------------------*- C++ -*----------------------------------*\';

h2= '========= |';

h3= '\\ / F ield | OpenFOAM: The Open Source CFD Toolbox';

h4= '\\ / O peration | Website: https://openfoam.org';

h5= '\\ / A nd | Version: 9';

h6= '\\/ M anipulation |';

h7='\*---------------------------------------------------------------------------*/';

h8='FoamFile';

h9='{';

h10= 'format ascii;';

h11= 'class dictionary;';

h12 = 'object blockMeshDict;';

h13='}';

h14='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

%generated block mesh directory start file prasing

f1=fopen('blockmeshDict.txt','w');

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',h7);

fprintf(f1,'\n');

fprintf(f1,'%s\n',h8);

fprintf(f1,'\n');

fprintf(f1,'%s\n',h9);

fprintf(f1,'%s\n',h10);

fprintf(f1,'%s\n',h11);

fprintf(f1,'%s\n',h12);

fprintf(f1,'%s\n',h13);

fprintf(f1,'%s\n',h14);

fprintf(f1,'\n');

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

%vertices

fprintf(f1,'%s\n','vertices');

fprintf(f1,'\n');

fprintf(f1,'%s\n','(');

fprintf(f1,'\t(%d %d %d)\n',v0(1),v0(2),v0(3));

fprintf(f1,'\t(%d %d %d)\n',v1(1),v1(2),v1(3));

fprintf(f1,'\t(%d %d %d)\n',v2(1),v2(2),v2(3));

fprintf(f1,'\t(%d %d %d)\n',v3(1),v3(2),v3(3));

fprintf(f1,'\t(%d %d %d)\n',v4(1),v4(2),v4(3));

fprintf(f1,'\t(%d %d %d)\n',v5(1),v5(2),v5(3));

fprintf(f1,'%s\n',')');

%%blocks

fprintf(f1,'%s\n','blocks');

fprintf(f1,'\n');

fprintf(f1,'%s\n','(');

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

fprintf(f1,'%s\n',')');

%edges

fprintf(f1,'%s\n','edges');

fprintf(f1,'\n');

fprintf(f1,'%s\n','(');

fprintf(f1,'\t arc 1 2 (%d %d %d)\n',0,R,0);

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

fprintf(f1,'%s\n',')');

%%boundary

fprintf(f1,'%s\n','boundary');

fprintf(f1,'\n');

fprintf(f1,'%s\n','(');

%axis

fprintf(f1,'\n');

fprintf(f1,'\t axis\n\t{\n');

fprintf(f1,'\t type empty;\n');

fprintf(f1,'\t faces\n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',0,3,3,0);

fprintf(f1,'\t \t);\n\t}\n');

%top wall

fprintf(f1,'\n');

fprintf(f1,'\t wall\n\t{\n');

fprintf(f1,'\t type wall;\n');

fprintf(f1,'\t faces\n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',1,4,5,2);

fprintf(f1,'\t \t);\n\t}\n');

%inlet

fprintf(f1,'\n');

fprintf(f1,'\t inlet\n\t{\n');

fprintf(f1,'\t type patch;\n');

fprintf(f1,'\t faces\n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',0,1,2,0);

fprintf(f1,'\t\t);\n\t}\n');

%outlet

fprintf(f1,'\n');

fprintf(f1,'\t outlet\n\t{\n');

fprintf(f1,'\t type patch;\n');

fprintf(f1,'\t faces\n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',3,5,4,3);

fprintf(f1,'\t\t);\n\t}\n');

%frontAndback

fprintf(f1,'\n');

fprintf(f1,'\t front\n \t{\n');

fprintf(f1,'\t type wedge;\n');

fprintf(f1,'\t faces \n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',0,3,4,1);

fprintf(f1,'\t\t);\n\t}\n');

fprintf(f1,'\n');

fprintf(f1,'\t back\n\t{\n');

fprintf(f1,'\t type wedge;\n');

fprintf(f1,'\t faces \n\t (\n');

fprintf(f1,'\t(%d %d %d %d)\n',0,2,5,3);

fprintf(f1,'\t\t);\n\t}\n');

% all boundary condition is given

fprintf(f1,'\n');

fprintf(f1,'%s\n','meargePatchPair;');

fprintf(f1,'\t(\n\t\t);\n');

fprintf(f1,'// ************************************************************************* //');

fclose(f1);

Pressure directory

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

}
front
{
type wedge;
}
back
{
type wedge;
}
}

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

Velocity directory

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 1 -1 0 0 0 0];

internalField uniform (0.0937 0 0);

boundaryField
{
axis
{
type empty;
}
inlet
{
type fixedValue;
value uniform (0.0937 0 0);
}

outlet
{
type zeroGradient;
}
wall
{
type fixedValue;
value uniform (0 0 0);
}

front
{
type wedge;
}
back
{
type wedge;
}
}

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

block Mesh directory

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

convertToMeters 1;

vertices
(
(0 0 0)
(0 9.996573e-03 -2.617695e-04)
(0 9.996573e-03 2.617695e-04)
(2.820000e+00 0 0)
(2.820000e+00 9.996573e-03 -2.617695e-04)
(2.820000e+00 9.996573e-03 2.617695e-04)
);

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

edges
(
arc 1 2 (0 1.000000e-02 0)
arc 4 5 (2.820000e+00 1.000000e-02 0)
);

boundary
(
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
wall
{
type wall;
faces
(
(1 4 5 2)
);
}

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

mergePatchPairs
(

);
// ************************************************************************* //

controlDict directory

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application icoFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 10;

deltaT 0.01;

writeControl timeStep;

writeInterval 10;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression off;

timeFormat general;

timePrecision 6;

runTimeModifiable true;


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

Transport properties directory

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu [0 2 -1 0 0 0 0] 8.917e-7;


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

Outputs…

Velocity profile

Some screenshot after post processing

Shear stress graph using MATLAB

Shear stress graph using open foam

For Basic knowledge for reader

Conclusions-

  • Form graphs obtained we will conclude that shear stress is maximum at the walls and zero at the centre of pipe
  • Velocity profile is parabolic in nature
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.