Week 11 - Simulation of Flow through a pipe in OpenFoam
The following is the simulation of a laminar flow of an incompressible fluid through the pipe in OpenFoam.
The following figure depicts the physical situation of the flow.

For a laminar flow, the hydrodynamic length, `L_h=0.06*D*Re_D`, where `D` is pipe diameter, and `Re_D` is Reynolds number based on diameter.
Flow parameters:
`D` = 20 mm, `L` (pipe length) = 3000 mm, and `Re_D` = 2100. Fluid is the water of density (`rho`) = 996.59 `(kg)/m^3` and viscosity (`mu`) = 0.000852 `(kg)/(m-s)`. The inlet velocity (`V`) is determined as `V` = `(Re_D*mu)/(rho*D)` = 0.089766102 `m/s`.
Transient analysis of flow is performed using the icoFoam solver. The fluid domain for the simulation is prepared using blockMesh as follows. The wedge angle used is `3^0`.

A MATLAB file (attached below) is created to write the blockMesh file for different flow parameters.
scale=0.001;
R=10; % In mm
theta=3; % In degrees
x=3000; % Length of pipe in mm
y=R*cos((theta/2)*pi/180); % y coordinate of corner points in mm
z=R*sin((theta/2)*pi/180); % z coordinate of corner points in mm
nx=3000; % no of cells along pipe length
ny=40; % no of cells along radial direction
gradef=0.1; % grading factor in radial direction
f=fopen('blockMeshDict.txt','w');
fprintf(f,'%s','/*--------------------------------*- C++ -*----------------------------------*\');
fprintf(f,'\n%s','| ========= | |');
fprintf(f,'\n%s','| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |');
fprintf(f,'\n%s','| \\ / O peration | Version: v2012 |');
fprintf(f,'\n%s','| \\ / A nd | Website: www.openfoam.com |');
fprintf(f,'\n%s','| \\/ M anipulation | |');
fprintf(f,'\n%s','\*---------------------------------------------------------------------------*/');
fprintf(f,'\n%s','FoamFile');
fprintf(f,'\n%s','{');
fprintf(f,'\n%s',' version ');
fprintf(f,'%.1f',2.0);
fprintf(f,'%s',';');
fprintf(f,'\n%s',' format ');
fprintf(f,'%s','ascii;');
fprintf(f,'\n%s',' class ');
fprintf(f,'%s','dictionary;');
fprintf(f,'\n%s',' object ');
fprintf(f,'%s','blockMeshDict;');
fprintf(f,'\n%s','}');
fprintf(f,'\n%s','// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //');
fprintf(f,'\n');
fprintf(f,'\n%s','scale ');
fprintf(f,'%.3f%s',scale,';');
fprintf(f,'\n');
fprintf(f,'\n%s','vertices');
fprintf(f,'\n%s','(');
fprintf(f,'\n%s%d %d %d%s',' (',0,0,0,')');
fprintf(f,'\n%s%d %.8f %.9f%s',' (',0,y,-1*z,')');
fprintf(f,'\n%s%d %.8f %.9f%s',' (',0,y,z,')');
fprintf(f,'\n%s%d %d %d%s',' (',x,0,0,')');
fprintf(f,'\n%s%d %.8f %.9f%s',' (',x,y,-1*z,')');
fprintf(f,'\n%s%d %.8f %.9f%s',' (',x,y,z,')');
fprintf(f,'\n%s',');');
fprintf(f,'\n');
fprintf(f,'\n%s','blocks');
fprintf(f,'\n%s','(');
fprintf(f,'\n %s','hex (');
fprintf(f,'%d %d %d %d %d %d %d %d%s',0,3,4,1,0,3,5,2,')');
fprintf(f,' %s%d %d %d%s','(',nx,ny,1,')');
fprintf(f,' %s','simpleGrading');
fprintf(f,' %s%d %.1f %d%s','(',1,gradef,1,')');
fprintf(f,'\n%s',');');
fprintf(f,'\n');
fprintf(f,'\n%s','edges');
fprintf(f,'\n%s','(');
fprintf(f,'\n %s','arc ');
fprintf(f,'%d %d',1,2);
fprintf(f,' %s%d %d %d%s','(',0,R,0,')');
fprintf(f,'\n %s','arc ');
fprintf(f,'%d %d',4,5);
fprintf(f,' %s%d %d %d%s','(',x,R,0,')');
fprintf(f,'\n%s',');');
fprintf(f,'\n');
fprintf(f,'\n%s','boundary');
fprintf(f,'\n%s','(');
fprintf(f,'\n %s','inlet');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type patch;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',0,2,1,0,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n %s','wall');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type wall;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',1,2,5,4,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n %s','axis');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type empty;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',0,3,3,0,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n %s','front');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type wedge;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',0,3,5,2,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n %s','back');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type wedge;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',0,1,4,3,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n %s','outlet');
fprintf(f,'\n %s','{');
fprintf(f,'\n %s','type patch;');
fprintf(f,'\n %s','faces');
fprintf(f,'\n %s','(');
fprintf(f,'\n %s%d %d %d %d%s','(',3,4,5,3,')');
fprintf(f,'\n %s',');');
fprintf(f,'\n %s','}');
fprintf(f,'\n%s',');');
fprintf(f,'\n');
fprintf(f,'\n%s','mergePatchPairs');
fprintf(f,'\n%s','(');
fprintf(f,'\n%s',');');
fprintf(f,'\n');
fprintf(f,'\n%s','// ************************************************************************* //');
fprintf(f,'\n');
fclose(f);
The blockMesh file generated is as follows.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scale 0.001;
vertices
(
(0 0 0)
(0 9.99657325 -0.261769483)
(0 9.99657325 0.261769483)
(3000 0 0)
(3000 9.99657325 -0.261769483)
(3000 9.99657325 0.261769483)
);
blocks
(
hex (0 3 4 1 0 3 5 2) (3000 40 1) simpleGrading (1 0.1 1)
);
edges
(
arc 1 2 (0 10 0)
arc 4 5 (3000 10 0)
);
boundary
(
inlet
{
type patch;
faces
(
(0 2 1 0)
);
}
wall
{
type wall;
faces
(
(1 2 5 4)
);
}
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
front
{
type wedge;
faces
(
(0 3 5 2)
);
}
back
{
type wedge;
faces
(
(0 1 4 3)
);
}
outlet
{
type patch;
faces
(
(3 4 5 3)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
Boundary conditions are as follows.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 101.6717005;
boundaryField
{
inlet
{
type zeroGradient;
}
wall
{
type zeroGradient;
}
axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
outlet
{
type fixedValue;
value uniform 101.6717005;
}
}
// ************************************************************************* //
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ 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.089766102 0 0);
}
wall
{
type noSlip;
}
axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
outlet
{
type zeroGradient;
}
}
// ************************************************************************* //
The controlDict is as follows.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2012 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 40;
deltaT 0.005;
writeControl runTime;
writeInterval 2;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
The simulation reached a steady state at the time, `t` = 26 s.
Analytically, the hydrodynamic length, `L_h` = 0.06*2100*0.02 = 2.52 `m`.
The velocity (magnitude) distribution along the axial direction at steady state is obtained as follows.

From the above plot, the velocity profile is fully developed approximately at x = 2.5 m.
Radial distributions of velocity at x = 2.8 m.

Radial distributions of velocity at x = 3 m.

At the inlet, velocity is mentioned. At outlet, pressure is mentioned.
Maximum velocity (at the centerline) through simulation is 0.1784 `m/s` while the analytical value is 0.1795 `m/s`.