Week 11 - Simulation of Flow through a pipe in OpenFoam
OBJECTIVE
Simulate an axi-symmetric flow across a pipe, applying wedge boundary condition with following parameters:
- `R_e = 2100`
- Wedge Angle < 5 degress
- Pipe Diameter can be assumed
Validate the simulation using Hagen-Poiseuille's equations for fully developed flow.
Use MATLAB script to calculate relevant parameters and generate blockMeshDict file accordingly.
THEORY:
Hagen-Poiseuille Equation:
It is a physical law which gives the value of the pressure drop as a fluid in laminar flow, flows along a long cylindrical pipe of constant cross-section. It has the following assumptions:
- The fluid is compressible and newtonian.
- The flow is laminar
- The pipe length of pipe is substabntially greater than its constant cross-section
- There is no acceleration of fluid in pipe
Mathematically,

CODE:
Assuming Pipe Dia = 10mm, and Wedge Angle = 3 Degrees. Water at room temperature will be used as working fluid
Calculating Pre-requisite Parameters:
%% Pre-requisites:
% Given:
Re = 2100; % Reynolds Number
theta = 3; % Wedge Angle(Degrees)
% Taking Water as Working Fluid,
% Water Properties at room temperature:
rho = 997.13; % Density (Kg/m^3)
mu = 8.91e-4; % Dynamic Viscosity
nu = mu/rho; % Kinematic Viscoity
% Since the flow is Laminar, L/D = 0.06Re:
D = 10e-3; % Assuming Pipe Dia = 10 mm
L = (0.06*Re*D)+0.1; % Pipe Length with 0.1m buffer
r = D/2;
% Computing Velocity:
v = Re*nu/L;
% Flow Throw Time:
T = D/v;
% Pressure DIfference (Hagen-Poiseuille):
Q = v_max*pi*r^2;
delp = (8*mu*L*Q)/(pi*r^4);
% Shear Stress:
tau = mu*(v_max/r)

Generating BlockMeshDict:
%% Parameters for BlockMeshDict:
% Header:
header = "/*--------------------------------*- C++ -*----------------------------------*\ \n\
========= |\n\
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\n\
\\ / O peration | Website: https://openfoam.org\n\
\\ / A nd | Version: 10\n\
\\/ M anipulation |\n\
\*---------------------------------------------------------------------------*/\n\
FoamFile\n\
{\n\
format ascii;\n\
class dictionary;\n\
object blockMeshDict;\n\
}\n\
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //";
% Unit Converter:
unit = 1;
% Geometry Vertices:
v0 = [0 0 0];
v1 = [r*sind(theta/2) r*cosd(theta/2) 0];
v2 = [-r*sind(theta/2) r*cosd(theta/2) 0];
v3 = [0 0 L];
v4 = [r*sind(theta/2) r*cosd(theta/2) L];
v5 = [-r*sind(theta/2) r*cosd(theta/2) L];
% Meshing and Local Coordinate System:
block ='hex (0 0 1 2 3 3 4 5) (1 50 200) simpleGrading (1 0.5 1)';
arc1 ='arc 1 2';
arc2 ='arc 4 5';
% Boundary Flagging:
inlet = '(0 0 2 1)';
outlet = '(3 4 5 3)';
front = '(0 1 4 3)';
back = '(3 5 2 0)';
wall =' (4 1 2 5)';
axis =' (0 3 3 0)';
% BlockMeshDict Footer:
footer = '// ************************************************************************************************************************************************** //';
%% WRITING BLOCKMESHDICT:
% Open file:
fid = fopen('/home/cb/OpenFOAM/cb-10/run/pipeFlow/system/blockMeshDict','w');
% Write Header:
fprintf(fid,'%s\n\n',header);
% Write Unit Conversion:
fprintf(fid,'convertToMeters %d;\n\n',unit);
% Write Vertex Coordinates:
fprintf(fid,'vertices\n(\n');
fprintf(fid,'\t(%f %f %f)\n',v0);
fprintf(fid,'\t(%f %f %f)\n',v1);
fprintf(fid,'\t(%f %f %f)\n',v2);
fprintf(fid,'\t(%f %f %f)\n',v3);
fprintf(fid,'\t(%f %f %f)\n',v4);
fprintf(fid,'\t(%f %f %f)\n',v5);
fprintf(fid,');\n\n');
% Write Blocks:
fprintf(fid,'blocks\n(\n');
fprintf(fid,'\t%s\n',block);
fprintf(fid,');\n\n');
% Write Arcs:
fprintf(fid,'edges\n(\n');
fprintf(fid,'\tarc 1 2(%f %f %f)\n',[0 r 0]);
fprintf(fid,'\tarc 4 5(%f %f %f)\n',[L r 0]);
fprintf(fid,');\n\n');
% Write Boundaries:
fprintf(fid,'boundary\n(\n');
% inlet
fprintf(fid,'\t%s\n','inlet');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type patch;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',inlet);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t%s\n','}');
% outlet
fprintf(fid,'\t%s\n','outlet');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type patch;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',outlet);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t%s\n','}');
% axis
fprintf(fid,'\t%s\n','axis');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type empty;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',axis);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t%s\n','}');
% wall
fprintf(fid,'\t%s\n','pipewall');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type wall;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',wall);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t%s\n','}');
% front wedge:
fprintf(fid,'\t%s\n','front');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type wedge;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',front);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t%s\n','}');
% back wedge
fprintf(fid,'\t%s\n','back');
fprintf(fid,'\t%s\n','{');
fprintf(fid,'\t\t%s\n','type wedge;');
fprintf(fid,'\t\t%s\n','faces');
fprintf(fid,'\t\t%s\n','(');
fprintf(fid,'\t\t\t%s\n',back);
fprintf(fid,'\t\t%s\n',');');
fprintf(fid,'\t}\n);\n')
% Footer:
fprintf(fid,'%s \n','mergePatchPairs');
fprintf(fid,'%s \n','(');
fprintf(fid,'%s \n',');');
fprintf(fid,'\n');
fprintf(fid,'%s \n',footer);
% Close File:
fclose(fid);
OPENFOAM INPUTS:
BlockMeshDict:
/*--------------------------------*- C++ -*----------------------------------*
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 10
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(0.000000 0.000000 0.000000)
(0.000131 0.004998 0.000000)
(-0.000131 0.004998 0.000000)
(0.000000 0.000000 1.270000)
(0.000131 0.004998 1.270000)
(-0.000131 0.004998 1.270000)
);
blocks
(
hex (0 0 1 2 3 3 4 5) (1 50 200) simpleGrading (1 0.5 1)
);
edges
(
arc 1 2(0.000000 0.005000 0.000000)
arc 4 5(1.270000 0.005000 0.000000)
);
boundary
(
inlet
{
type patch;
faces
(
(0 0 2 1)
);
}
outlet
{
type patch;
faces
(
(3 4 5 3)
);
}
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
pipewall
{
type wall;
faces
(
(4 1 2 5)
);
}
front
{
type wedge;
faces
(
(0 1 4 3)
);
}
back
{
type wedge;
faces
(
(3 5 2 0)
);
}
);
mergePatchPairs
(
);
// ************************************************************************************************************************************************** //
ControlDict:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 1e-2;
writeControl timeStep;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
physicalProperties:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "constant";
object physicalProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 8.9356e-07;
// ************************************************************************* //
U:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ 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 0 0.1879);
}
outlet
{
type zeroGradient;
}
pipewall
{
type noSlip;
}
axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************************************* //
P:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
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 0;
}
pipewall
{
type zeroGradient;
}
axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************************************* //
RESULTS:
Velocity Profile:

Pressure:

Shear Stress:

COMPARISON OF RESULTS:
| RESULTS | Pressure | Max Velocity | Shear Stress |
| Analytical Results | 0.1460 | 0.3758 | 0.1570 |
| Simulation Results | 0.11 | 0.28 | 0.2 |
CONCLUSION:
We see certain deviation from the analytical results which is typical for such a simplified case. The Hagen-Poiseuille flow has been successfully studied.