Project

Simulation of Flow through a pipe in OpenFoam

The main objective of this challenge is to write Matlab code for generating mesh for a wedge with an angle less than 5 degrees and solve using Icofoam solver for solving. Velocity profile at different positions are calculated throughout the pipe and measuring the distance from the inlet for a fully developed profile and verifying with the calculated distance for fully developed flow.

Parameters:

Working Fluid: Water

Reynolds Number(Re) : 2100

Wedge Angle: 2.5 degree

Diameter : 0.004m

Density : 997kg/m3

Absolute Viscosity(mu) : 1e-3

Calculation:

Kinematic Viscosity(nu) = Absolute Viscosity/(Density) = 1e-6

Length of Pipe for fully developed flow = `0.05*Diameter*Reynolds Number` = 0.41m

Average Velocity = `Re*nu/D` = 0.52658m/s

Maximum Velocity = 2*Average Velocity = 1.05319m/s

Pressure drop in pipe flow = `(32*mu*v_(avg)*L)/D^2`=442.327N/m2

Kinematic Pressure = Pressure Drop/Density = 0.4423658m2/s2

MATLAB CODE FOR BLOCKMESH FILE:

clear all 
close all
clc

%Inpit parameters
L = 0.5;
theta = 2.5;
d = 0.004;
r = d/2;
nx = 400;
ny = 50;
nz =1;


bd = fopen('blockMeshDictfinal','w');

fprintf(bd,'FoamFile\n{\n');
fprintf(bd,'%12s \t 2.0;\n','version');
fprintf(bd,'%11s \t ascii;\n','format');
fprintf(bd,'%10s \t dictionary;\n','class');
fprintf(bd,'%11s \t blockMeshDict;\n','object');
fprintf(bd,'}\n');
line8='// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //';
fprintf(bd,'%s\n\n',line8);

fprintf(bd,'convertToMeters 1;\n\n');

fprintf(bd,'vertices\n');
fprintf(bd,'(\n');
fprintf(bd,'\t (%d %d %d)\n',0,0,0); % point 0
fprintf(bd,'\t (%d %d %d)\n',0,r*cosd(theta/2),r*sind(theta/2)); % point 1
fprintf(bd,'\t (%d %d %d)\n',0,r*cosd(theta/2),-r*sind(theta/2)); % point 2
fprintf(bd,'\t (%d %d %d)\n',L,0,0);  % Pont 3
fprintf(bd,'\t (%d %d %d)\n',L,r*cosd(theta/2),r*sind(theta/2)); % point 4
fprintf(bd,'\t (%d %d %d)\n',L,(r*cosd(theta/2)),-r*sind(theta/2)); % point 5
fprintf(bd,');\n\n');

fprintf(bd,'blocks\n');
fprintf(bd,'(\n');
fprintf(bd,'     hex ( 0 3 5 2 0 3 4 1) (%d %d %d)',nx,ny,nz);
fprintf(bd, ' SimpleGrading (1 0.2 1)\n\n');
fprintf(bd,');\n\n');

fprintf(bd,'edges\n(\n\tarc %d %d (%d %d %d)\n',1,2,0,r,0);
fprintf(bd,'\tarc %d %d (%d %d %d)\n',4,5,L,r,0);
fprintf(bd,');\n\n');

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

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

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

fprintf(bd,'\t back\n');
fprintf(bd,'\t{\n');
fprintf(bd,'\t\t type wedge;\n');
fprintf(bd,'\t\t faces\n');
fprintf(bd,'\t\t (\n');
fprintf(bd,'\t\t\t (5 3 0 2)\n');
fprintf(bd,'\t\t );\n');
fprintf(bd,'\t}\n');

fprintf(bd,'\t front\n');
fprintf(bd,'\t{\n');
fprintf(bd,'\t\t type wedge;\n');
fprintf(bd,'\t\t faces\n');
fprintf(bd,'\t\t (\n');
fprintf(bd,'\t\t\t (3 4 1 0)\n');
fprintf(bd,'\t\t );\n');
fprintf(bd,'\t}\n');

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

fprintf(bd,'mergePatchPairs\n(\n');
fprintf(bd,');\n');

Obtained Mesh File:

FoamFile
{
     version 	 2.0;
     format 	 ascii;
     class 	 dictionary;
     object 	 blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(
	 (0 0 0)
	 (0 1.999524e-03 4.362977e-05)
	 (0 1.999524e-03 -4.362977e-05)
	 (5.000000e-01 0 0)
	 (5.000000e-01 1.999524e-03 4.362977e-05)
	 (5.000000e-01 1.999524e-03 -4.362977e-05)
);

blocks
(
     hex ( 0 3 5 2 0 3 4 1) (400 50 1) SimpleGrading (1 0.2 1)

);

edges
(
	arc 1 2 (0 2.000000e-03 0)
	arc 4 5 (5.000000e-01 2.000000e-03 0)
);

boundary
(
	 inlet
	{
		 type patch;
		 faces
		 (
			 (0 0 1 2)
		 );
	}
	 outlet
	{
		 type patch;
		 faces
		 (
			 (4 3 3 5)
		 );
	}
	 top 
	{
		 type wall;
		 faces
		 (
			 (5 2 1 4)
		 );
	}
	 back
	{
		 type wedge;
		 faces
		 (
			 (5 3 0 2)
		 );
	}
	 front
	{
		 type wedge;
		 faces
		 (
			 (3 4 1 0)
		 );
	}
	 axis
	{
		 type empty;
		 faces
		 (
			 (0 3 3 0)
		 );
	}
);

mergePatchPairs
(
);

CONTROL DICT FILE:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.0                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     icoFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         0.25;

deltaT          0.001;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

TRANSPORT PROPERTIES:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.0                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu              [0 2 -1 0 0 0 0] 1e-6;


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

INLET VELOCITY:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     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.52658 0 0);
    }

    outlet
    {
        type            zeroGradient;
    }

    
    axis
    {
        type            empty;
    }

    top
    {
       type            noSlip;
      
    }

    front
    {
        type            wedge;
    }

    back
    {
        type            wedge;
    }
}  

INLET PRESSURE:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  4.1                                   |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     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.44365;     
    }


    axis
    {
        type            empty;
    }

    top
    {
        type            zeroGradient;
    }

    front
    {
        type            wedge;
    }

    back
    {
        type            wedge;
    }
}  

RESULTS:

VELOCITY PROFILE AT 0.01m

VELOCITY PROFILE AT 0.05m

Hence the velocity profile becomes fully developed flow after calculated distance which satisfies Hagen Poiseuille Equation calculation. This method can be easily used to verify the flow development throughout the cylinder instead of using full setup. This drastically reduces the run time ( because of less than 5degree) of the total model but by the end of the results will be same as the full model because of the wedge.

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.