Week 11 - Simulation of Flow through a pipe in OpenFoam
Aim:
- To simulate flow through a circular pipe in openFoam
- To write a MATLAB program to automate the generation of blockMeshDict filr for the circular pipe
- To validate the simulation results using Hagen-Poiseulle's equation for fully devoloped flow
Given Data & Assumed Data
Reynolds number (Re)=2100
Diameter(D)=8mm
Wedge Angle=2.5degree
Length(L)=200mm
Density(`rho`)=995kg/m^3
Viscocity(`mu`)=8.97e-4
Hagen-Poiseullis Equation: Poiseulli's equation describes about the pressure drop in the floe due to the viscosity of the fluid and
Assumption
- Incompressible flow
- Incompressible flow
- Newtonian fluid
- Laminar flow
- Steady flow
- Cylindrical Symmetry
- No gevitational Effect
- Fully Devoloped Flow
- No Roughness Facto
MatLab main code
clear all
close all
clc
L=200;
Re=2100;
D=8;
theta=2.5;
rho=997;
R=D/2;
mu=8.97e-4;
nx=50;
ny=1;
nz=500;
file = blockMesh(R,theta,L,nx,ny,nz);
Mat Lab function code
function [f1] = blockMesh(R,theta,L,nx,ny,nz)
f1 = fopen('blockMeshDict','W');
%introduction of the file
fprintf(f1, '/*--------------------------------*- C++ -*----------------------------------*\n' );
fprintf(f1,' ========= |n');
fprintf(f1,' \\ / F ield | OpenFOAM: The Open Source CFD Toolbox n');
fprintf(f1,' \\ / O peration | Website: https://openfoam.org n');
fprintf(f1,' \\ / A nd | Version: 8 n');
fprintf(f1,' \\/ M anipulation |n');
fprintf(f1,'\*---------------------------------------------------------------------------*/n');
fprintf(f1,'FoamFile n');
fprintf(f1,'{n');
fprintf(f1,' version 2.0; n');
fprintf(f1,'format ascii; n');
fprintf(f1,'class dictionary; n');
fprintf(f1,'object blockMeshDict;n');
fprintf(f1,'}n');
fprintf(f1,'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // n');
fprintf(f1,'n');
fprintf(f1,'convertToMeters 0.01;n');
fprintf(f1,'n');
fprintf(f1,'verticesn');
%Vertices of the wedge geometry
fprintf(f1,'(n');
fprintf(f1,' (0 0 0) // Vertex 0 n');
fprintf(f1,' (0 %f %f) // Vertex 1 n', R*cosd(theta/2),-R*sind(theta/2));
fprintf(f1,' (0 %f %f) // Vertex 2 n', R*cosd(theta/2),R*sind(theta/2));
fprintf(f1,' (%d 0 0) // Vertex 3 n', L);
fprintf(f1,' (%d %f %f) // Vertex 4 n', L,R*cosd(theta/2),-R*sind(theta/2));
fprintf(f1,' (%d %f %f) // Vertex 5 n', L,R*cosd(theta/2),R*sind(theta/2));
fprintf(f1,');n');
%BLOCKS
fprintf(f1,'blocks n');
fprintf(f1,'(n');
fprintf(f1,' hex(0 1 2 0 4 5 3)(%d %d %d)simle grading(0.1 1 10)n',nx,ny,nz);
fprintf(f1,');n');
%Edges
fprintf(f1,'n');
fprintf(f1,'edges n');
fprintf(f1,'(n');
fprintf(f1,' arc 1 2 (0 %d 0) n',R);
fprintf(f1,' arc 4 5 (%d %d 0) n',L,R);
fprintf(f1,');n');
%Boundary
fprintf(f1,'n');
fprintf(f1,'boundary n');
fprintf(f1,');n');
%Axis
fprintf(f1,'axis n');
fprintf(f1,'{ n');
fprintf(f1,' type empty; n');
fprintf(f1,' facesn');
fprintf(f1,'(n');
fprintf(f1,' (0 3 3 0) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
%Inlet
fprintf(f1,'inletn');
fprintf(f1,'{ n');
fprintf(f1,' type patch; n');
fprintf(f1,' faces n');
fprintf(f1,' (n');
fprintf(f1,' ( 0 0 2 1) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
%Wall
fprintf(f1,' wall n');
fprintf(f1,' {');
fprintf(f1,' type wall; n');
fprintf(f1,' faces n');
fprintf(f1,' (n');
fprintf(f1,' ( 2 5 4 1) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
%Outlet
fprintf(f1,' outlet n');
fprintf(f1,' {');
fprintf(f1,' type patch; n');
fprintf(f1,' faces n');
fprintf(f1,' (n');
fprintf(f1,' ( 3 4 5 3) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
%Front Side
fprintf(f1,' front n');
fprintf(f1,' {');
fprintf(f1,' type wedge; n');
fprintf(f1,' faces n');
fprintf(f1,' (n');
fprintf(f1,' ( 0 3 5 2) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
%Back
fprintf(f1,' back n');
fprintf(f1,' {');
fprintf(f1,' type wedge; n');
fprintf(f1,' faces n');
fprintf(f1,' (n');
fprintf(f1,' ( 0 1 4 23) n');
fprintf(f1,' );n');
fprintf(f1,' }n');
fprintf(f1,'n');
fprintf(f1,');n');
%End
fprintf(f1,'n');
fprintf(f1,'mergePatchPairs n');
fprintf(f1,'(n');
fprintf(f1,');n');
fprintf(f1,'n');
fprintf(f1,'// ************************************************************************* /');
end
blockMeshDict
/*--------------------------------*- 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;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.001;
vertices
(
(0 0 0)//Vertex0
(0 3.999048 -0.087260)//Vertex1
(0 3.999048 0.087260)//Vertex2
(200 0 0)//Vertex3
(200 3.999048 -0.087260)//Vertex4
(200 3.999048 0.087260)//Vertes5
);
blocks
(
hex (0 1 2 0 3 4 5 3) (50 1 500) simpleGrading (0.1 1 1)
);
edges
(
arc 1 2 (0 4 0)
arc 4 5 (200 4 0)
);
boundary
(
axis
{
type empty;
faces
(
(0 3 3 0)
);
}
inlet
{
type patch;
faces
(
(0 0 2 1)
);
}
wall
{
type wall;
faces
(
(2 5 4 1)
);
}
outlet
(
(3 4 5 3)
);
}
front
{
type wedge;
faces
(
(0 3 5 2)
);
}
back
{
type wedge;
faces
(
(0 1 4 3)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
ControlDict
/*--------------------------------*- 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 "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.2;
deltaT 0.00005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Boundary Condetion
/*--------------------------------*- 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
{
axis
{
type empty;
}
inlet
{
type zeroGradient;
}
wall
{
type zeroGradient;
}
outlet
{ type fixedValue;
value uniform 10;
}
front
{
type wedge;
}
back
type wedge;
}
}
// ************************************************************************* //
/*--------------------------------*- 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 (0.50929 0 0);
boundaryField
{
axis
{
type empty;
}
inlet
{
type fixedValue;
value uniform(0.50929 0 0 );
}
wall
{
type fixedvalue;
value uniform (0 0 0);
}
outlet
{
type inletOutlet;
inletValue uniform (0.50929 0 0);
value uniform (0.50929 0 0);
}
front
{
type wedge;
}
back
{
type wedge;
}
}
// ************************************************************************* //
Post Processing Results

velocity at inlet

Velocity at outlet

Pressure at inlet

Presuure at outlet