Week 11 - Simulation of Flow through a pipe in OpenFoam
DESCRIPTION:
In this challenge,we create a simulation of laminar flow for a cross-section of a pipe by writting the parse file in Matlab which generates the blockMesh file in openFoam to conduct the simulation.
The various properties that are associated with this simulation are
- Water at 25 degrees C
- Reynold's no:2100
- Wedge angle=5 degrees
- Diameter=0.02
- Dynamic viscosity=0.00089
- Water density=997
The Hagen-Poiseullie equation describes the parabolic velocity profile of frictional , laminar pipe flows of incompressible, Newtonian fluids.When a fluid is moving through a pipe, velocity will be varying in the radial direction in a particular manner.This is due to the presence of fluid boundary friction. We know that as the fluid moves downstream , the boundary layer gets thickened and finally, at a particular location ,it fills the entire pipe.Downstream of this point velocity profile will be parabolic.
The entrance length can be defined as the distance between the above mentioned point and the inlet of the pipe.
From the above figure it is very clear that the flow is developing in the entrance region and after the entrance region is fully developed and thereafter there are no changes in the velocity profile.
Viscous forces are responsible for the velocity profiles.
Entrance Length of Laminar flow pipe is calculated by the equation(Le/D)=(0.06.Re)
We can find the following values using the formula
1)Entrance Length(Le)=Re*0.06*D=2.52 m
2)Total Length(L)=Le+0.02=2.72 m
3)Mean Velocity(Vmean)=(Re*μ/ρ*D)=0.0937314 m/s
4)Maximum Velocity(Vmax)=2*Vmean=0.1874628 m/s
5)Pressure drop(△P)=(32*μ*Vmean*(L-Le))/D^2=0.2669 Pa
6)Kinematic Pressure (Pk)=△P/ρ=2.701*10-7
A matlab code is generated which will receive the wedge angle and grading parameters from the user and gives the blockMesh Dict for the openFoam simulation.
MATLAB CODE:
clear all
close all
clc
%inputs
Re=2100;
D=0.02;
r=D/2;
theta=5;%input('enter the wedge angle:');
mu=0.89e-3;
rho=997;
nu=mu/rho;
%computing analytical pressure and the velocity
%entrance length
Le=0.06*Re*D;
%total length
l=Le+0.3;
%average velocity
vavg=(Re*mu)/(rho*D);
%max velocity
vmax=2*vavg;
%drop in pressure
delP=(32*mu*vavg*l)/(D^2);
%kinematic pressure
Kp=delP/rho;
%finding the 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)];
%creating the blockMesh file
f1=fopen('blockMeshDict.txt','w');
fprintf(f1,'%s\n','/*--------------------------------*- C++ -*----------------------------------*\');
fprintf(f1,'%s\n',' ========= |');
fprintf(f1,'%s\n',' \\ / F ield | OpenFOAM: The Open Source CFD Toolbox');
fprintf(f1,'%s\n',' \\ / O peration | Website: https://openfoam.org');
fprintf(f1,'%s\n',' \\ / A nd | Version: 7');
fprintf(f1,'%s\n',' \\/ M anipulation |');
fprintf(f1,'%s\n','\*---------------------------------------------------------------------------*/');
fprintf(f1,'%s\n','FoamFile');
fprintf(f1,'%s\n','{');
fprintf(f1,'%s\n',' version 2.0;');
fprintf(f1,'%s\n',' format ascii;');
fprintf(f1,'%s\n',' class dictionary;');
fprintf(f1,'%s\n',' object blockMeshDict;');
fprintf(f1,'%s\n','}');
fprintf(f1,'%s\n','// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //');
fprintf(f1,'%s\n','');
fprintf(f1,'%s\n','convertToMeters 1;');
b1=blanks(5);
b2=blanks(8);
b3=blanks(6);
b4=blanks(4);
b10=blanks(10);
%finding veretices
fprintf(f1,'%s\n','vertices');
fprintf(f1,'%s\n','(');
fprintf(f1,b4,'%s\n','');
v_0=fprintf(f1,'(%f %f %f)\n',v0(1),v0(2),v0(3));
fprintf(f1,b4,'%s\n','');
v_1=fprintf(f1,'(%f %f %f)\n',v1(1),v1(2),v1(3));
fprintf(f1,b4,'%s\n','');
v_2=fprintf(f1,'(%f %f %f)\n',v2(1),v2(2),v2(3));
fprintf(f1,b4,'%s\n','');
v_3=fprintf(f1,'(%f %f %f)\n',v3(1),v3(2),v3(3));
fprintf(f1,b4,'%s\n','');
v_4=fprintf(f1,'(%f %f %f)\n',v4(1),v4(2),v4(3));
fprintf(f1,b4,'%s\n','');
v_5=fprintf(f1,'(%f %f %f)\n',v5(1),v5(2),v5(3));
fprintf(f1,'%s\n',')');
%creating the blocks
fprintf(f1,'%s','');
fprintf(f1,'%s\n','blocks');
fprintf(f1,'%s\n','(');
fprintf(f1,'%s\n',' hex (0 3 4 1 0 3 5 2) (200 50 1) simpleGrading (1 1 1)');
fprintf(f1,'%s\n',');');
fprintf(f1,'%s\n','edges');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' arc 1 2 (0 1.270000e-02 0)');
fprintf(f1,'%s\n',' arc 4 5 (3.500400e+00 1.270000e-02 0)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n','boundary');
fprintf(f1,'%s\n','(');
fprintf(f1,'%s\n',' inlet');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type patch;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (0 2 1 0)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',' outlet');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type patch;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (3 4 5 3)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',' front');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type symmetry;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (0 3 5 2)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',' back');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type symmetry;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (0 1 4 3)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',' wall');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type wall;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (1 2 5 4)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',' axis');
fprintf(f1,'%s\n',' {');
fprintf(f1,'%s\n',' type empty;');
fprintf(f1,'%s\n',' faces');
fprintf(f1,'%s\n',' (');
fprintf(f1,'%s\n',' (0 3 3 0)');
fprintf(f1,'%s\n',' );');
fprintf(f1,'%s\n',' }');
fprintf(f1,'%s\n',');');
fprintf(f1,'%s\n','');
fprintf(f1,'%s\n','mergePatchPairs');
fprintf(f1,'%s\n','(');
fprintf(f1,'%s\n',');');
fprintf(f1,'%s\n','// ************************************************************************* //');
BlockMeshDict file:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(0.000000 0.000000 0.000000)
(0.000000 0.009990 -0.000436)
(0.000000 0.009990 0.000436)
(2.820000 0.000000 0.000000)
(2.820000 0.009990 -0.000436)
(2.820000 0.009990 0.000436)
)
blocks
(
hex (0 3 4 1 0 3 5 2) (200 50 1) simpleGrading (1 1 1)
);
edges
(
arc 1 2 (0 1.270000e-02 0)
arc 4 5 (3.500400e+00 1.270000e-02 0)
);
boundary
(
inlet
{
type patch;
faces
(
(0 2 1 0)
);
}
outlet
{
type patch;
faces
(
(3 4 5 3)
);
}
front
{
type symmetry;
faces
(
(0 3 5 2)
);
}
back
{
type symmetry;
faces
(
(0 1 4 3)
);
}
wall
{
type wall;
faces
(
(1 2 5 4)
);
}
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
TransportProperties:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 8
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 8.7e04;
// ************************************************************************* //
Velocity:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 8
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (1e-100 0 0);
boundaryField
{
inlet
{
type fixedValue;
value uniform (3e-100 0 0);
}
outlet
{
type zeroGradient;
}
front
{
type symmetry;
}
back
{
type symmetry;
}
wall
{
type noSlip;
}
axis
{
type empty;
}
}
// ************************************************************************* //
Pressure:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 8
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
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;
}
front
{
type symmetry;
}
back
{
type symmetry;
}
wall
{
type zeroGradient;
}
axis
{
type empty;
}
}
// ************************************************************************* //
- Now that the mesh file is complete we use the blockMesh command.
- After the blockMesh command is completed,we initiate the icoFoam command.
- The system starts computing.
- After computation, we use the paraFoam command in order to open paraview.
- After the paraview is open we apply the object (wedge).
- Then we use the slice command to slice the wedge.
- Then we find the minimum and maximum pressure and velocity values of the profile.
OUTPUT:
Profile:

Profile with mesh:

Velocity Profile:

Maximum velocity= 4e-34 m/s
Pressure:

Maximum Pressure = 1.2e-38 Pa