Week 11 - Simulation of Flow through a pipe in OpenFoam
# Simulation of a flow through pipe in OpenFoam #
Objective:-
1) Calculation of flow through pipe variables.
2) Generation of blockMeshDict file by using Wedge BC in MATLAB, which used to automated generated file used in OpenFoam.
3) Simulation the pipe flow in OpenFoam using IcoFoam Solver.
4) Make post-process shear stress and validate wall shear stress for fully developed flow by using 'Hagen-Poiseuilles' equation for the fully developed flow.
- Entrance Length(fluid Dynamics)
In fluid dynamics the entrance length is the distance of flow travels after a entering in pipe before the flow become fully developed. Entrance length occurs at the entry region of the pipe that area of pipe flow propagation as an expanding boundary layer(B.L.).
When B.L expands to fill the entire pipe, the developing flow becomes a fully developed flow, that flow characterstic no longer occurs with increase distance along the pipe.
- Hydrodynamic Entrance Length
Hydrodynamic entrance region means the area of pipe where the fluid entering a pipe developed a velocity profile due to viscous forces propagating from the interior of wall of pipe.
When a fliud enters in a pipe at a uniform velocity the fluid particle contact with the wall surface of pipe and flow becomes no slip condition.
Due to viscouse forces within the pipe surface slowly adjust with fluid surface then the velocity profile created between fluid and surface of pipe, then the conservation of mass occurs.
The velocity profile at the centre of the pipe is increases & reduces at the layer of the fluid near the pipe surface this developes the velocity gradient across the cross-section of the pipe. The velocity profile remains unchanged in the fully developed region.

In laminar flow the entry length is given as approximately as `L_e cong 0.06*Re*D`.
Velocity Profile For Laminar Flow:
The velocity profile for a fully developed laminar flow in a pipe is parabolic with maximum at centre line and minimum at R = 0.
- `u(r) = R^2/(4mu)*((dp)/(dx))*(1-r^2/R^2)`------It is obtained for a fluide element at a radial distance from centre.
- `V_(avg) = R^2/(8mu)*((dp)/(dx))`------ This is average velocity.
- `u(r) = 2V_(avg)*(1-r^2/R^2)`----------This is the final expression for velocity profile.
- `u_(max) = 2*V_(avg)` -----------------The maximum velocity occurs at centre line and obtained from this equation (r=0 putting) in above eq.
Hagen Poiseulle's Law:
"It State that for a specified flow rate, the pressure drops and thus the required pumping power is proportional to the length of the pipe and the viscosity of the fluid, but it is inversely proportional to the fourth power of the radius (or diameter) of the pipe".
- Pressure Loss/Drop, `DeltaP = (32*mu*L*V_(avg))/D^2`
- Kinematic Pressure difference `DeltaP_k= DeltaP/rho`
- Sheare stress `tau = (2*mu*V_(max)*R)/r^2`
Given/Assuming Data:
Diameter, D=0.04
Radius, r = 0.02
Radial Distance, R = 0 to r
Dynamic Viscosity,`mu = 0.89*10^-3 N/m^2`
Density, `rho = 1000 (kg)/m^3`
Reynold Number,`R_e = 2100`
Matlab Program for blockMeshDict file.
clear
close all
clc
% Simulation Flow Through Pipe by using OpenFoam
% Given Data
Re = 2100; % Reynold Number
D = 0.04; % Dia of Pipe
rho = 1000; % Density of water
mu = 0.89*10^-3; % Dynamic Viscosity
Le = 0.06*Re*D; % Hydrodynamic entrance length of pipe
r = D/2 ; % Radius of pipe
theta =4; % Wedge Angle
L = Le+0.5; % Total Length of pipe
% Haugen Pausselies Equation
V_avg = (Re*mu)/(rho*D);
V_max = 2*V_avg;
del_p = (8*mu*L*V_avg)/(r^2);
kinematic_p = (del_p)/rho;
tau = (2*mu*V_max*r)/(r^2);
% Calculating Shear stress
l = linspace(0,r,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')
% Creating a blockMesh dict file for OpenFoam
f1 = fopen('blockMeshDict','w');
header1='/*-------------------*-C++-*-----------------------------------------*\';
header2='|========== | |';
header3='|\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |';
header4='| \\ / O peration | Version: 6.1 |';
header5='| \\ / A nd | Web:www.OpenFOAM.org |';
header6='| \\ / M anupulation | |';
header7='\*-------------------------------------------------------------------*/';
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,'%15s %11s\n','Version','6.0;');
fprintf(f1,'%15s %13s\n','format','ascii;');
fprintf(f1,'%15s %18s\n','Class','Dictionary;');
fprintf(f1,'%15s %21s\n','Object','blockMeshDict;');
fprintf(f1,'%3s\n','}');
fprintf(f1,'%3s\n\n','ConvertToMeter 1;');
header8='//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//';
fprintf(f1,'%s\n',header8);
fprintf(f1,'Vertices \n (\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',Le, 0, 0);
fprintf(f1,'\t (%d %d %d) \n',Le,r*cosd(theta/2),r*sind(theta/2));
fprintf(f1,'\t (%d %d %d) \n',Le,r*cosd(theta/2),-r*sind(theta/2));
fprintf(f1,');\n\n');
fprintf(f1,'blocks \n \n');
fprintf(f1,'(\n');
fprintf(f1,'\t hex (0 3 4 1 0 3 5 2) (%d %d %d)',200,20,1);
fprintf(f1,' SimpleGrading (1 0.1 1) \n\n');
fprintf(f1,');\n \n');
fprintf(f1,'edges \n \n');
fprintf(f1,'(\n');
fprintf(f1,'\t arc %d %d (%d %d %d) \n',1,2,0,r,0);
fprintf(f1,'\t arc %d %d (%d %d %d) \n',4,5,Le,r,0);
fprintf(f1,'); \n \n');
fprintf(f1,'boundary \n \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 4 5 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 empty type; \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);
blockMeshDict file:
/*--------------------------------*- 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;
}
convertToMeter 1;
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
vertices
(
(0 0 0)
(0 1.998782e-02 6.979899e-04)
(0 1.998782e-02 -6.979899e-04)
(5.040000e+00 0 0)
(5.040000e+00 1.998782e-02 6.979899e-04)
(5.040000e+00 1.998782e-02 -6.979899e-04)
);
blocks
(
hex (0 3 5 2 0 3 4 1) (200 20 1) simpleGrading (1 0.2 1)
);
edges
(
arc 1 2 (0 2.000000e-02 0)
arc 4 5 (5.040000e+00 2.000000e-02 0)
);
boundary
(
inlet
{
type patch;
faces
(
(0 1 2 0)
);
}
outlet
{
type patch;
faces
(
(3 4 5 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 file:
/*--------------------------------*- 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 125;
deltaT 0.08;
writeControl timeStep;
writeInterval 60;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Velocity B.C.
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0.04686 0 0);
boundaryField
{
inlet
{
type fixedValue;
value uniform (0.04686 0 0);
}
outlet
{
type zeroGradient;
}
axis
{
type empty;
}
top
{
type fixedValue;
value uniform (0 0 0);
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************************************* //
Pressure B.C.
/*--------------------------------*- 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; // Initial condition
boundaryField
{
inlet
{
type zeroGradient;
}
outlet
{
type zeroGradient;
value uniform 1.0073;
}
axis
{
type empty;
}
top
{
type zeroGradient;
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************************************* //
TransportProperties:
/*--------------------------------*- 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.9e-7;
// ************************************************************************* //
Result:-
ParaFoam with Mesh

The velocity distribution along the length of pipe.

The velocity distribution at the end of pipe.

Velocity Profile at L =0.05 m

Velocity Profile at L =1 m

Velocity Profile at L = 2.52 m

Shear Stress Distribution Profile

As we found in this profile the shear stress is maximum at wall side of pipe and minimum stress at the centre of the pipe. clearly shows in above graph.