Week 11 - Simulation of Flow through a pipe in OpenFoam
In this challenge,we will simulate an axi-symmetric 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. we can do a transient or steady state simulation and you will validate your results with the Hagen- Poiseuille's equations for the fully developed flow.
we will also write code in Matlab to automate the generation of blockMeshDict file. The code should take inputs like pipe length, diameter, wedge angle, etc and output a fully functional blockMeshDict file.
Hagen- Poiseuille's equations
Hagen–Poiseuille law, Poiseuille law or Poiseuille equation, is a physic law that gives the pressure drop in an incompressible and Newtonian fluid in laminar flow flowing through a long cylindrical pipe of constant cross section
The assumptions of the equation are that the fluid is incompressible and Newtonian; the flow is laminar through a pipe of constant circular cross-section that is substantially longer than its diameter; and there is no acceleration of fluid in the pipe. For velocities and pipe diameters above a threshold, actual fluid flow is not laminar but turbulent, leading to larger pressure drops than calculated by the Hagen–Poiseuille equation.

Δp is the pressure difference between the two ends,
L is the length of pipe,
μ is the dynamic viscosity,
Q is the volumetric flow rate,
R is the pipe radius
A is the cross section of pipe.

The above figure represents the flow through pipe
The layer in which the share viscous flow are significant is called boundary layer this boundary layer is important
concept its divide the flow pipe into two region boundary layer region and irrotational flow region
When the fluid just enter the pipe the thickness of a boundary layer gradually increases from zero moving in direction of flow and eventually reaches the pipe centre and fills the entire pipe the region from the entrance of the pipe to the point where the boundary layer covers the pipe is termed as a hydrodynamic region and length of a pipe in the region is termed as a hydro dynamic and length in this region the velocity profile develops and the floor is called hudrodynamically developing flow
Given
Reynolds number :2100
Working fluid :water
Fluid temperature :25celcus
Diameter of pipe :0.02
dynamic viscosity : 0.89*10^-3
kinematics viscosity :0.89*10^-6
difference between pressure :32*L*mu*avg velocity/D^2
Theta :4
length 2.25m
Analytical solution
average velocity :re*mu/rho*D = 0.09373
maximum velocity :2*avg velocity = 0.1874ms
pressure drop :16.187pa
kinematics pressure drop : delP/P = 0.0168m
By doing all this procedure copy the cavity fodder from the icoFoamr form and paste it from the separate folder and after the final editing of the block Marsh pressure and velocity parameters save the program and check the blocked my and the polymer has been created open paraview and run the simulation.
Matlab Code for creating blockmesh dic
clear all
close all
clc
%wedgeinput and angles
theta = input('Enter the value of wedge angle=');
Re = 2100;
D = 0.02;
L = 0.06*Re*D;
R = D/2;
mu = 0.89e-3;
rho = 997.0;
nu = mu/rho;
%pressure and velocity
v_avg = Re*mu/(D*rho);
v_max = 2*v_avg;
del_p = (32*mu*v_avg*L)/(D^2);
kin_p = del_p/rho;
n1 = 50
n2 = 1
n3 = 300
gfactor = 0.5
%vertices of the wedge
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)];
%Printing the containt of blockMesh File
string1='/*--------------------------------*- C++ -*----------------------------------*\';
string2=' ========= |';
string3=' \\ / F ield | OpenFOAM: The Open Source CFD Toolbox';
string4=' \\ / O peration | Website: https://openfoam.org';
string5=' \\ / A nd | Version: 9';
string6=' \\/ M anipulation |';
string7='\*---------------------------------------------------------------------------*/';
string8='FoamFile';
string9='{';
string10=' format ascii;';
string11=' class dictionary;';
string12=' object blockMeshDict;';
string13='}';
string14='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';
fpoint=fopen('blockMeshDict.txt','wt');
fprintf(fpoint,'%sn',string1);
fprintf(fpoint,'%sn',string2);
fprintf(fpoint,'%sn',string3);
fprintf(fpoint,'%sn',string4);
fprintf(fpoint,'%sn',string5);
fprintf(fpoint,'%sn',string6);
fprintf(fpoint,'%sn',string7);
fprintf(fpoint,'%sn',string8);
fprintf(fpoint,'%sn',string9);
fprintf(fpoint,'%sn',string10);
fprintf(fpoint,'%sn',string11);
fprintf(fpoint,'%sn',string12);
fprintf(fpoint,'%sn',string13);
fprintf(fpoint,'%sn',string14);
fprintf(fpoint,'%sn','convertToMeters 1;');
fprintf(fpoint,'%sn','vertices');
fprintf(fpoint,'%sn','(');
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V0(1),V0(2),V0(3));
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V1(1),V1(2),V1(3));
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V2(1),V2(2),V2(3));
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V3(1),V3(2),V3(3));
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V4(1),V4(2),V4(3));
fprintf(fpoint,'%s (%f %f %f) n',blanks(5),V5(1),V5(2),V5(3));
fprintf(fpoint,'%sn',');');
fprintf(fpoint,'n');
fprintf(fpoint,'%sn','blocks');
fprintf(fpoint,'%sn','(');
fprintf(fpoint,'%s %s n',blanks(5),'hex(0 1 2 0 3 4 5 3) (50 1 200) simpleGrading(0.5 1 1)');
fprintf(fpoint,'%sn','(');
fprintf(fpoint,'n');
fprintf(fpoint,'%sn','boundry');
fprintf(fpoint,'%sn','(');
fprintf(fpoint,'%s %s n',blanks(5),'inlet');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type patch;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(0 1 2 0)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s %s n',blanks(5),'outlet');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type patch;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(3 4 5 3)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s %s n',blanks(5),'front');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type wedge;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(0 3 5 2)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s %s n',blanks(5),'back');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type wedge;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(0 1 4 3)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s %s n',blanks(5),'pipe');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type wall;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(1 4 5 2)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s %s n',blanks(5),'axis');
fprintf(fpoint,'%s %s n',blanks(5),'{');
fprintf(fpoint,'%s %s n',blanks(10),'type empty;');
fprintf(fpoint,'%s %s n',blanks(10),'faces');
fprintf(fpoint,'%s %s n',blanks(10),'(');
fprintf(fpoint,'%s %s n',blanks(15),'(0 3 3 0)');
fprintf(fpoint,'%s %s n',blanks(10),');');
fprintf(fpoint,'%s %s n',blanks(5),'}');
fprintf(fpoint,'%s n',');');
fprintf(fpoint,'n');
fprintf(fpoint,'%s n','mergePatchPairs');
fprintf(fpoint,'%s n','(');
fprintf(fpoint,'%s n',');');
fprintf(fpoint,'n');
fprintf(fpoint,'%s n',string14);
fclose(fpoint);
****************************************************
Excuiting the code blockmeshDic
/*--------------------------------*- 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.000000 0.000000 0.000000)
(0.000000 0.009994 -0.000349)
(0.000000 0.009994 0.000349)
(2.520000 0.000000 0.000000)
(2.520000 0.009994 -0.000349)
(2.520000 0.009994 0.000349)
);
blocks
(
hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.5 1 1)
);
edges
(
arc 1 2 (0.000000 0.010000 0.000000)
arc 4 5 (2.520000 0.010000 0.000000)
);
boundary
(
inlet
{
type patch;
faces
(
(0 1 2 0)
);
}
outlet
{
type patch;
faces
(
(3 4 5 3)
);
}
front
{
type wedge;
faces
(
(0 3 5 2)
);
}
back
{
type wedge;
faces
(
(0 1 4 3)
);
}
pipe
{
type wall;
faces
(
(1 4 5 2)
);
}
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
);
mergePatchPairs
(
);
// ************************************************* //
/*--------------------------------*- 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 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************ //
/*--------------------------------*- 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]0.8926e-6;
/*--------------------------------*- 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 0 0);
boundaryField
{
inlet
{
type fixedValue;
value uniform (0.0937312 0 0);
}
outlet
{
type zeroGradient;
}
pipe
{
type noSlip;
}
axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************ //
/*--------------------------------*- 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;
}
pipe
{
type zeroGradient;
}
inlet
{
type zeroGradient;
}
outlet
{
type fixedValue;
value uniform 0.0168682;
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************
Hear you can notice that the velocity turns out zero at the wall it's mainly because of their is no slip condition as slow progress gradually the boundary layer develops and the adjacent there tends to slow down because the velocity of the centre increases centre because of the pressure difference obtained from the equation velocity profile matches with the help of Hagen- Poiseuille's equations.