Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Aim

To 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. You 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.

Expected Results

  1. Validate Hydro-dynamic length with the numerical result
  2. Validate the fully developed flow velocity profile with its analytical profile
  3. Validate maximum velocity and pressured drop for fully developed flow
  4. Post-process Shear stress and validate wall shear stress for fully developed flow

Hagen Poiseuille's Equation

In non ideal Fluid dynmics, the Hagen poiseuille's equation also know s the Hagen poiseuille's law, is a physical 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 Hagen poiseuille's equation describes the relation between pressure, fluid resistance and flow rate, analogous to voltage, resistance and current, respectively, in Ohms law for electrical circuits.

The assumptions of the equation are that the fluid is incompressible and Newtonian, the flow is laminar through a pipe of the constant circular cross-section that is substantially longer than its diameter, and there is no acceleration of the fluid in the pipe. For velocities and pipe diameters above the threshold, the actual flow is not laminar but turbulent, leading to larger pressure drops than calculated by Hagen Poieuille's Equation.

Hydrodynamic Entrance Length

Consider a fluid entering a circular pipe at constant velocity. Because of the no-slip condition, the fluid particles in the layer in contact with the wall of the pipe come to a complete stop. This layer also causes the fluid particles in the adjacent layer to slow down gradually as a result of friction. To make up for the velocity friction, the velocity of the fluid at the midsection of the pipe has to increase to keep the mass flow rate through the pipe constant. As a result, the velocity gradient develops through the pipe.

The region from the pipe inlet to the point at which the velocity profile is fully developed is called the hydrodynamic entrance region and the length of the region is called hydrodynamic entrance length.

Boundary Condition

Here, the wedge BC is used in CFD to define an axisymmetric situation, for. eg Cylinder. The model and flow must be axisymmetric along a central line such that all physical variables of the flow have the same value and distribution at a given radius for all angles.

Matlab program to create blockMesh.dict file

clear all
close all
clc

%wedge angle taken
theta=4;

%Reynold's Number
Re = 2100;

%Diameter
D= 0.01;

%Radius
R = D/2;

%Hydro dynamic entrance length
Le = 0.05*Re*D;

%Total Length
L = Le+0.4;

%Temperature = 25 degree celsius

%Dynamic Viscosity of water
mu = 8.90*10^-4;

%Density
rho = 997;

%Kinematic Viscosity
nu = 8.9267*10^-7;

%average velocity
V_avg =(Re*mu)/(rho*D);

%maximum velocity
V_max =2*V_avg;

%pressure drop
delta_p =(32*mu*L*V_avg)/(D^2);

%kinematic pressure
kinematic_pressure =delta_p/rho;

%Vertices
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)];


%Creating the blockMeshDict File

%Writing the blockMesh dict file header

header1 ='/*--------------------------------*- C++ -*----------------------------------*';
header2 =' ========= |';
header3 =' \ / F ield | OpenFOAM: The Open Source CFD Toolbox';
header4 =' \ / O peration | Website: https://openfoam.org';
header5 =' \ / A nd | Version: 9';
header6 =' \/ M anipulation |';
header7 ='*---------------------------------------------------------------------------*/';
header8 ='FoamFile';
header9 ='{';
header10 =' format ascii;';
header11 =' class dictionary;';
header12 =' object blockMeshDict;';
header13 ='}';
header14 ='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';

% creating a text file for blockMeshDict

f1 = fopen('blockMeshDict.txt','w');


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,'%s\n',header8);

fprintf(f1,'%s\n',header9);

fprintf(f1,'%s\n',header10);

fprintf(f1,'%s\n',header11);

fprintf(f1,'%s\n',header12);

fprintf(f1,'%s\n',header13);

fprintf(f1,'%s\n',header14);

fprintf(f1,'\n');

fprintf(f1,'%s\n','convertToMeters 1;');
fprintf(f1,'\n');

fprintf(f1,'%s\n','vertices');
fprintf(f1,'%s\n','(');

fprintf(f1,'\t(%f %f %f)\n',v0(1),v0(2),v0(3));
fprintf(f1,'\t(%f %f %f)\n',v1(1),v1(2),v1(3));
fprintf(f1,'\t(%f %f %f)\n',v2(1),v2(2),v2(3));
fprintf(f1,'\t(%f %f %f)\n',v3(1),v3(2),v3(3));
fprintf(f1,'\t(%f %f %f)\n',v4(1),v4(2),v4(3));
fprintf(f1,'\t(%f %f %f)\n',v5(1),v5(2),v5(3));

fprintf(f1,'%s\n',');');
fprintf(f1,'\n');

%blocks
fprintf(f1,'%s\n','blocks');
fprintf(f1,'%s\n','(');
fprintf(f1,'\t%s\n','hex (0 3 5 2 0 3 4 1) (200 50 1) simpleGrading (1 0.3 1)');
fprintf(f1,'%s\n',');');
fprintf(f1,'\n');

%edges
fprintf(f1,'%s\n','edges');
fprintf(f1,'%s\n','(');
fprintf(f1,'\t%s\n','arc 1 2 (0.000000 0.005 0.000000)');
fprintf(f1,'\t%s\n','arc 4 5 (1.450000 0.005 0.000000)');
fprintf(f1,'%s\n',');');
fprintf(f1,'\n');

%boundary
fprintf(f1,'%s\n','boundary');
fprintf(f1,'%s\n','(');
fprintf(f1,'\t%s\n','inlet');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type patch;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(0 1 2 0)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'\t%s\n','outlet');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type patch;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(3 4 5 3)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'\t%s\n','axis');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type empty;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(0 3 3 0)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'\t%s\n','front');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type wedge;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(0 2 5 3)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'\t%s\n','back');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type wedge;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(0 3 4 1)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'\t%s\n','top');
fprintf(f1,'\t%s\n','{');
fprintf(f1,'\t\t%s\n','type wall;');
fprintf(f1,'\t\t%s\n','faces');
fprintf(f1,'\t\t%s\n','(');
fprintf(f1,'\t\t\t%s\n','(1 2 5 4)');
fprintf(f1,'\t\t%s\n',');');
fprintf(f1,'\t%s\n','}');
fprintf(f1,'\n');

fprintf(f1,'%s\n',')');

fprintf(f1,'%s\n','mergePatchPairs');
fprintf(f1,'%s\n','(');
fprintf(f1,'%s\n',');');


fclose(f1);

BlockMeshDict Code

/*--------------------------------*- 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.004997 0.000174)
(0.000000 0.004997 -0.000174)
(1.450000 0.000000 0.000000)
(1.450000 0.004997 0.000174)
(1.450000 0.004997 -0.000174)
);

blocks
(
hex (0 3 5 2 0 3 4 1) (200 50 1) simpleGrading (1 0.3 1)
);

edges
(
arc 1 2 (0.000000 0.005 0.000000)
arc 4 5 (1.450000 0.005 0.000000)
);

boundary
(
inlet
{
type patch;
faces
(
(0 1 2 0)
);
}

outlet
{
type patch;
faces
(
(3 4 5 3)
);
}

axis
{
type empty;
faces
(
(0 3 3 0)
);
}

front
{
type wedge;
faces
(
(0 2 5 3)
);
}

back
{
type wedge;
faces
(
(0 3 4 1)
);
}

top
{
type wall;
faces
(
(1 2 5 4)
);
}

)
mergePatchPairs
(
);

Control Dict. Code

/*--------------------------------*- 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.005;

writeControl timeStep;

writeInterval 20;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression off;

timeFormat general;

timePrecision 6;

runTimeModifiable true;


// ************************************************************************* //

Pressure (BC)

/*--------------------------------*- 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
{
inlet
{
type zeroGradient;
}

outlet
{
type fixedValue;
value uniform 0;
}

axis
{
type empty;
}

front
{
type wedge;
}

back
{
type wedge;
}

top
{
type zeroGradient;
}

}

// ************************************************************************* //

Velocity (BC)

/*--------------------------------*- 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.1875 0 0);
}

outlet
{
type zeroGradient;
}

axis
{
type empty;
}
front
{
type wedge;
}
back
{
type wedge;
}
top
{
type noSlip;
}
}

// ************************************************************************* //

Transport Properties

/*--------------------------------*- 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.9267e-7;


// ************************************************************************* //

OutPut Results

Pressure

Pressure after the Hydrodynamic entrance length

Plot over line

Point 1 = 1.05

point = 1.45

Velocity

Velocity at 1.45 meters

Velocity at Inlet

Plot over line

Point 1 = 0

Point 1 = 0

Shear Stress

Plot over line

Point 1 =1.45

Point 2 = 1.45

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.