Week 11 - Simulation of Flow through a pipe in OpenFoam
Aim: Simulation of flow through a pipe in open Foam
Objectives:
- Calculation of flow variables.
- Generation of Block Mesh Dict using the Wedges of Boundary Conditions, to create the Block Mesh Dict file in octave such that the mesh is automatically created for any wedge angle.
- Simulating the pipe flow in open foam using icoFoam solver.
- Post process the velocity profile and shear stress and compare the simulation results.
Note: Consider the cylindrical pipe with the working fluid water entering the pipe with the laminar flow.
Assumption Made:
- Steady flow , incompressible and laminar flow
- Flow is two dimensional ( Flow WRT theta is ignored)
- Constant fluid properties (Velocity, Density ...etc.)
Introduction to the laminar flow through pipe:
In this project we aim to simulate a section of pipe (Wedge shaped geometry) to understand various aspects of flow through a pipe. The fluid chosen is water and the flow is laminar and incompressible. Also we chosen to neglect any changes in cross section. The specified Reynolds number Re is specified as 2100.
Internal flow occurs when the fluid is filled entirely in a conduit and it is driven primarily by a pressure difference
Fluid Velocity in a pipe changes from zero at the surface because of the no-slip boundary condition to a maximum at the pipe center .The average velocity remains constant in a compressible flow when the cross section of the pipe is constant.

Reynolds number (Re):
The transition from the laminar flow to turbulent flow occurs from laminar
to transition
to turbulent
for smooth pipe with no viscous dissipation .It depends on the geometry, face roughness, flow velocity, surface temperature etc.., Reynolds number is an important non-dimensional number which is the ratio of inertia force to viscous force and is expressed for internal flow in a circular pipe as 
Hydrodynamic entry length:
The region from the pipe inlet to the point at which the velocity boundary layer merges at the center line is called the hydrodynamic entrance region. The region beyond the entrance region in which the velocity profile is fully developed is called the fully developed region

In laminar flow the entry length is given approximately as 
Velocity Profile: The velocity profile for a fully developed laminar flow in a pipe is parabolic with a maximum at the centerline and minimum at R=0.
It is obtained for a fluid element at a radial distance from the center. The average velocity can be written as:

Hence the final expression for the velocity profile can be written as:

Hagen Poiseuilie’s equation:
In non-ideal fluid dynamics, the Hagen-poiseuilies equation is also known as Hagen-Poiseuilies law, is an incompressible and Newtonian fluid flowing through a long cylindrical cross section .The pressure drop is given as

For a pipe with a laminar flow there are basically two regions, Entrance length developing region where the flow is not fully developed and the laminar flow layers are at equal velocity to each other whereas is fully developed region the flow is fully developed and follow the Hagen-Poiseuille law.
Assumptions:


Analytical Solution:

Here for solving the problem numerically we will use icoFoam solver with the cavity tutorial make the geometry along with the mesh and make the blockMesh Dict with the help of Octave as shown below.
CODE FOR BLOCKMESH USING OCTAVE:
% To generate blockmesh Dict file for a wedge angle
clear all
close all
clc
% wedge angle and inputs
theta=input('Enter the value of wedge angle=');
Re=2100;
% Dia of the pipe
D=0.02;
% Length of the pipe
L=0.06*Re*D;
R=D/2;
% Dynamic viscosity @ 25 degree C
mu=0.89e-3;
% Density of water @ 25 degree C
rho=997.0;
% Kinematic viscosity @ 25 degree C
nu=mu/rho;
% pressure and Velocity
% Average Velocity
v_avg=Re*mu/(D*rho);
% maximum velocity
v_max=2*v_avg;
% pressure drop
del_p=(32*mu*v_avg*L)/(D^2);
% Kinematic pressure drop
kin_P=del_p/rho;
% Number of cells along the pipe
n1=50;
% Number of cells radially
n2=1;
% Number of cells on the curve
n3=300;
gfactor=0.5;
% Vertices of the wedge
v0=[0 0 0];
v1=[0 R*cosd(theta/2) -R*sin(theta/2)];
v2=[0 R*cosd(theta/2) R*sin(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)];
grading=0.2;
b1=50;
b2=1;
b3=200;
% creating blockmesh dict file for openfoam
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='//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';
f1=fopen('blockMeshDict','wt')
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 \n',h7);
fprintf(f1,'FoamFile \n {\n');
fprintf(f1,'%16s %10s\n','Version',' 2.0;')
fprintf(f1,'%16s %12s\n','format',' ascii;')
fprintf(f1,'%16s %17s\n','class','dictionary;')
fprintf(f1,'%16s %20s\n','object','blockMeshDict;')
fprintf(f1,'%2s\n','}')
fprintf(f1,'%2s\n\n','//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //')
fprintf(f1,'%2s\n\n','convertToMeters 1;')
fprintf(f1,'vertices \n (\n')
fprintf(f1, '\t(%d %d %d)\n',v0)
fprintf(f1, '\t(%d %d %d)\n',v1)
fprintf(f1, '\t(%d %d %d)\n',v2)
fprintf(f1, '\t(%d %d %d)\n',v3)
fprintf(f1, '\t(%d %d %d)\n',v4)
fprintf(f1, '\t(%d %d %d)\n',v5)
fprintf(f1,'%2s\n|n', ');')
fprintf(f1,'blocks \n (\n')
fprintf(f1,' \t %s (%d %d %d) %s (%d 1 1) \n','hex (0 1 2 0 3 4 5 3)',b1,b2,b3,'simpleGrading',grading)
fprintf(f1,' %2s\n\n', ');')
fprintf(f1,'edges \n (\n')
fprintf(f1,'\t %s (0 %d 0)\n','arc 1 2',R)
fprintf(f1,'\t %s(%d %d 0)\n','arc 4 5',L,R)
fprintf(f1,' %2s\n\n', ');')
fprintf(f1,'boundary \n (\n')
fprintf(f1,' \t %5s \n','axis','{')
fprintf(f1,'\t %13s %s\n',' type','empty;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 3 3 0)',');','}')
fprintf(f1,' \t %5s \n','Wall','{')
fprintf(f1,'\t %13s %s\n',' type','Wall;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(2 5 4 1)',');','}')
fprintf(f1,' \t %5s \n','inlet','{')
fprintf(f1,'\t %13s %s\n',' type','patch;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 0 2 1)',');','}')
fprintf(f1,' \t %5s \n','outlet','{')
fprintf(f1,'\t %13s %s\n',' type','patch;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(3 4 5 3)',');','}')
fprintf(f1,' \t %5s \n','wedgeFront','{')
fprintf(f1,'\t %13s %s\n',' type','wedge;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 3 5 2)',');','}')
fprintf(f1,' \t %5s \n','wedgeBack','{')
fprintf(f1,'\t %13s %s\n',' type','wedge;')
fprintf(f1,'\t %14s\n %18s\n','faces','(')
fprintf(f1,'\t \t %15s\n %19s\n\n %14s\n\n','(0 1 4 3)',');','}')
fprintf(f1,'mergePatchPairs \n (\n);\n')
fprintf(f1,'%2s\n\n','//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //')
fclose(f1);
BLOCKMESH DICT FILE:
/*--------------------------------*- C++ -*----------------------------------*\
|* ========= | |
$s
|* \\ / O peration | Website: https://openfoam.org |
|* \\ / A nd | Version: 9 |
|* \\/ M anipulation | |
\*----------------------------------------------------------------------------*/
FoamFile
{
Version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(0 0 0)
(0 0.00999657 -0.000261769)
(0 0.00999657 0.000261769)
(2.52 0 0)
(2.52 0.00999657 -0.000261769)
(2.52 0.00999657 0.000261769)
);
blocks
(
hex (0 1 2 0 3 4 5 3) (50 1 200) simpleGrading (0.2 1 1)
);
edges
(
arc 1 2 (0 0.01 0)
arc 4 5 (2.52 0.01 0)
);
boundary
(
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
wall
{
type wall;
faces
(
(2 5 4 1)
);
}
inlet
{
type patch;
faces
(
(0 0 2 1)
);
}
outlet
{
type patch;
faces
(
(3 4 5 3)
);
}
wedgeFront
{
type wedge;
faces
(
(0 3 5 2)
);
}
wedgeBack
{
type wedge;
faces
(
(0 1 4 3)
);
}
);
mergePatchPairs
(
);
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
CONTROL DICT 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 50;
deltaT 0.01;
writeControl timeStep;
writeInterval 200;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
TRANSPORT PROPERTIES 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 "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 1e-6;
// ************************************************************************* //
PRESSURE 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 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;
}
wedgeFront
{
type wedge;
}
wedgeBack
{
type wedge;
}
}
// ************************************************************************* //
VELOCITY 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 volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0.0937312 0 0);
boundaryField
{
axis
{
type empty;
}
inlet
{
type fixedValue;
value uniform (0.0937312 0 0);
}
outlet
{
type zeroGradient;
}
wall
{
type fixedvalue;
value uniform (0 0 0);
}
wedgeFront
{
type wedge;
}
wedgeBack
{
type wedge;
}
}
// ************************************************************************* //
PRESSURE DISTRIBUTION ALONG THE LENGTH:

VELOCITY DISTRIBUTION ALONG ITS LENGTH:

Graph for velocity Distribution
