Week 11 - Simulation of Flow through a pipe in OpenFoam
Aim:-
To run the simulation of fluid flow through a pipe.
Validate the fully developed flow velocity profile with its analytical profile
Hydrodynamic entry length:-
For a laminar flow, hydrodynamic entry length
`L_h = 0.05ReD`
where Re = Reynolds number.
D = characteristic length(m).
To create a geometry we need to edit the blockmeshDict file
Here, this can be done by using MATLAB file parsing.
Flow of water at 25 degree celsius entering pipe of diameter 0.02 m at a velocity 0.05 m/s is considered for the simulation.
Matlab code for Blockmeshdict file:-
clear all
close all
clc
Re = 2100; %reynolds number
D =0.02; %Dia of pipe
l =0.06*Re*D; %length of pipe
mu = 0.89e-3; %dynamic viscosity
rho = 997; %Density
nu = mu/rho; %Kinematic viscosity
r = D/2;
theta=3;
%Calculation of pressure and velocity
v_avg = Re*mu/(D*rho); %avg velocity
v_max = 2*v_avg; %max velocity
del_p = (32*mu*v_avg*l)/(D^2); %pressure drop
kin_p = del_p/rho; %Kinematic pressure drop
nx=250;
ny=25;
nz=1;
l1 = '/*-----------------------------------*C++*----------------------------*\';
l2 = '| _________ |';
l3 = '| \\ / F ield | openFOAM: The open source CFD Toolbox |';
l4 = '| \\ / O peration | version : 4.2 |';
l5 = '| \\ / A nd | web : www.openFoam.org |';
l6 = '| \\/ M anipulation | |';
l7 = '\*--------------------------------------------------------------------*/';
f1 = fopen('blockMeshDict','w')
fprintf(f1,'%s\n',l1);
fprintf(f1,'%s\n',l2);
fprintf(f1,'%s\n',l3);
fprintf(f1,'%s\n',l4);
fprintf(f1,'%s\n',l5);
fprintf(f1,'%s\n',l6);
fprintf(f1,'%s\n',l7);
fprintf(f1,'Foamfile\n{\n');
fprintf(f1, '%12s\t 2.0;\n','version');
fprintf(f1,'%11s\t ascii;\n','format');
fprintf(f1,'%10s\t dictionary;\n','class');
fprintf(f1,'%11s\t blockMeshDict;\n','object');
fprintf(f1,'}\n');
l8='//****************************************************//';
fprintf(f1, '%s\n\n',l8);
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,0,0);
fprintf(f1,'\t (%d %d %d)\n',l,r*cosd(theta/2),r*sind(theta/2));
fprintf(f1,'\t (%d %d %d)\n',l,r*cosd(theta/2),-r*sind(theta/2));
fprintf(f1,');\n\n');
fprintf(f1,'blocks\n');
fprintf(f1,'(\n');
fprintf(f1,' hex(0 3 5 2 0 3 4 1) (%d %d %d)',nx,ny,nz);
fprintf(f1, ' simpleGrading (1 0.1 1)\n\n');
fprintf(f1,');\n\n');
fprintf(f1,'edges\n(\n\tarc %d %d (%d %d %d)\n', 1,2,0,r,0);
fprintf(f1,'\tarc %d %d (%d %d %d)\n', 4,5,l,r,0);
fprintf(f1,');\n\n');
fprintf(f1,'boundary\n(\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 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 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 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(\n');
fprintf(f1,');\n');
fprintf(f1,'%s\n',l8);
fclose(f1)
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 1;
}
top
{
type zeroGradient;
}
back
{
type wedge;
}
front
{
type wedge;
}
axis
{
type empty;
}
}
// ************************************************************************* //
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.05 0 0);
}
outlet
{
type zeroGradient;
}
top
{
type noSlip;
value uniform 0;
}
back
{
type wedge;
}
front
{
type wedge;
}
axis
{
type empty;
}
}
// ************************************************************************* //
blockmesh:-
/*--------------------------------*- 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 1.999315e-03 6.970e-05)
(0 1.999315e-03 -6.970e-05)
(1.12 0 0)
(1.12 1.999315e-03 6.970e-05)
(1.12 1.999315e-03 -6.970e-05)
);
blocks
(
hex (0 3 5 2 0 3 4 1) (250 25 1) simpleGrading (1 0.1 1)
);
edges
(
//arc 1 2 (0 2.000000e-03 0)
//arc 4 5 (1 2.000000e-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)
);
}
back
{
type wedge;
faces
(
(0 2 5 3)
);
}
front
{
type wedge;
faces
(
(0 3 4 1)
);
}
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.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
transport
/*--------------------------------*- 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 "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 0.893e-6;
// ************************************************************************* //
Velocity inlet:-

velocity outlet:-

At 0.25m:-

At 0.75 m:-

At 1.25m:-

At 1.75m:-

At 2.25m:-

