Project

Symmetry vs Wedge vs HP equation in pipe flow using OpenFoam and Matlab

Symmetry vs Wedge equation in Pipe Flow simulation using OpenFoam:

Objective:

  • To create a matlab code to generate blockMeshDict file for openFoam with any given wedge angle.
  • To compare simulation results of flow of a fluid through a pipe using symmetry and wedge boundary conditions in openFoam and also the results obtained theoretically using the Hagen Poisuelle\'s equation.
  • To compare the effect on the results obtained while using symmetry boundary condition with different wedge angles of pipe section.

The fluid that is flowing through the pipe is considered to be water. Also, the pipe section wedge angle is assumed to be 5 degrees. The other values used for calculations for this project are mentioned below,

  • Wedge angle, `theta = 5` degrees
  • Diameter of pipe,d = 0.01 m
  • Radius,r = 0.005 m
  • Reynold\\\'s number, Re = 2100
  • Entrance length, Le = 0.06*Re*d = 1.26 m
  • Total pipe length, l = Le+0.3 = 1.56 m
  • Density, `rho` = 1000 `(kg)/m^3`
  • Kinematic viscosity of water,`nu` = 1.004*`10^-6` `m^2/s`
  • Dynamic viscosity of water ,`mu= 1.002*10^-3`
  • Velocity, `v = (Re*mu)/(rho*d)` = 0.21042 m/`
  • Maximum velocity = 2*v = 0.42084 m/s
  • Pressure drop,`p = (32*mu*l*v)/d^2` = 105.25 p`
  • Kinematic Pressure drop = p/`rho` = 0.10525 `m^2/s^-2`

Matlab Code:

The matlab code for generating BlockMeshDict file for any given theta angle is shown below. The code also includes calculations of initial values for solving.

The wedge angle value in the below code is, 10 degrees.

clear all
close all 
clc

%inputs
d = 0.01; %diameter in meters
r = d/2; %radius
Re = 2100; %Reynold\'s number
theta =10; %wedge angle
rho = 1000; %density
mu = 1.002*10^-3; %dynamic viscosity of water
nu = 1.004*10^-6 %kinematic viscosity of water
%calculations
%Hagen–Poiseuille Equation
%kine_p = (v*8*mu*l)/r^2
Le = 0.06*Re*d; %entrance length
l = (Le + 0.3); %total pipe length 
v= (Re*mu)/(rho*d); %velocity
v_max = 2*v %Max velocity, intial velocity
p = (32*mu*l*v)/d^2; %pressure drop
kine_p = p/rho %kinematic pressure drop

%defining vertices of pipe section 
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)];

%printing BlockMeshDict file data
bmd = fopen( \'BlockMeshDict.txt\',\'w\');
fprintf(bmd, \'%s\\n\', \'/*--------------------------------*- C++ -*----------------------------------*\\\');
fprintf(bmd, \'%s\\n\', \'| =========                 |                                                 |\');
fprintf(bmd, \'%s\\n\', \'| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |\');
fprintf(bmd, \'%s\\n\', \'|  \\\\    /   O peration     | Version:  2.1.0                                 |\');
fprintf(bmd, \'%s\\n\', \'|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |\');
fprintf(bmd, \'%s\\n\', \'|    \\\\/     M anipulation  |                                                 |\');
fprintf(bmd, \'%s\\n\', \'\\*---------------------------------------------------------------------------*/\');
fprintf(bmd, \'%s\\n\', \'FoamFile\');
fprintf(bmd, \'%s\\n\', \'{\');
fprintf(bmd, \'%s\\n\', \'    version         2.0;\');
fprintf(bmd, \'%s\\n\', \'    format          ascii;\');
fprintf(bmd, \'%s\\n\', \'    class           dictionary;\');
fprintf(bmd, \'%s\\n\', \'    object          blockMeshDict;\');
fprintf(bmd, \'%s\\n\', \'}\');
fprintf(bmd, \'%s\\n\\n\', \'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\');
fprintf(bmd, \'%s\\n\\n\', \'convertToMeters 1;\');

fprintf(bmd, \'%s\\n\', \'vertices\');
fprintf(bmd, \'%s\\n\', \'(\');
fprintf(bmd, \'\\t(%d %d %d)\\n\', v0(1), v0(2), v0(3));
fprintf(bmd, \'\\t(%d %d %d)\\n\', v1(1), v1(2), v1(3) );
fprintf(bmd, \'\\t(%d %d %d)\\n\', v2(1), v2(2), v2(3));
fprintf(bmd, \'\\t(%d %d %d)\\n\', v3(1), v3(2), v3(3));
fprintf(bmd, \'\\t(%d %d %d)\\n\', v4(1),  v4(2), v4(3));
fprintf(bmd, \'\\t(%d %d %d )\\n\', v5(1), v5(2), v5(3));
fprintf(bmd, \'%s\\n\\n\', \');\'); 
fprintf(bmd, \'%s\\n\', \'blocks\');
fprintf(bmd, \'%s\\n\', \'(\');
fprintf(bmd, \'\\thex (0 1 2 0 3 4 5 3) (%d %d %d) simpleGrading (0.2 1 1)\\n\', 25, 1, 500);
fprintf(bmd, \'%s\\n\\n\', \');\');
fprintf(bmd, \'%s\\n\', \'edges\');
fprintf(bmd, \'%s\\n\', \'(\');
fprintf(bmd, \'\\tarc %d %d (%d %d %d)\\n\', 1, 2, 0, r, 0);
fprintf(bmd, \'\\tarc %d %d (%d %d %d)\\n\', 4, 5, l, r, 0);
fprintf(bmd, \'%s\\n\\n\', \');\');
fprintf(bmd, \'%s\\n\', \'boundary\');
fprintf(bmd, \'%s\\n\', \'(\');
fprintf(bmd, \'\\tinlet\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype patch;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(0 2 1 0)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \'\\toutlet\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype patch;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(3 4 5 3)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \'\\tfront\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype wedge;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(0 3 5 2)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \'\\tback\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype wedge;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(0 1 4 3)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \'\\ttop\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype wall;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(1 2 5 4)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \'\\taxis\\n\\t{\\n\');
fprintf(bmd, \'\\t\\ttype empty;\\n\');
fprintf(bmd, \'\\t\\tfaces\\n\\t\\t(\\n\');
fprintf(bmd, \'\\t\\t\\t(0 3 3 0)\\n\');
fprintf(bmd, \'\\t\\t);\\n\\t}\\n\');
fprintf(bmd, \');\\n\\n\');
fprintf(bmd, \'mergePatchPairs\\n(\\n);\\n\\n\');
fprintf(bmd, \'// ************************************************************************* //\');
fclose(bmd) 
  • BlockMeshDict file:
/*--------------------------------*- C++ -*----------------------------------*\\
| =========                 |                                                 |
| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\\\    /   O peration     | Version:  2.1.0                                 |
|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\\\/     M anipulation  |                                                 |
\\*---------------------------------------------------------------------------*/
FoamFile
{
    version         2.0;
    format          ascii;
    class           dictionary;
    object          blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(
	(0 0 0)
	(0 0.00498097 -0.000435779)
	(0 0.00498097 0.000435779)
	(1.56 0 0)
	(1.56 0.00498097 -0.000435779)
	(1.56 0.00498097 0.000435779 )
);

blocks
(
	hex (0 1 2 0 3 4 5 3) (25 1 500) simpleGrading (0.2 1 1)
);

edges
(
	arc 1 2 (0 0.005 0)
	arc 4 5 (1.56 0.005 0)
);

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

mergePatchPairs
(
);

// ************************************************************************* //
  • Initial pressure conditions
/*--------------------------------*- 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       volScalarField;
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    inlet
    {
        type            zeroGradient;
    }

    outlet
    {
        type            fixedValue;
        value           uniform 0.10525;  
    }

    front
    {
        type            symmetry;
    }

    back
    {
        type            symmetry;
    }
    top
    {
        type            zeroGradient;
    }
    axis
    {
        type            empty;
    }
}

// ************************************************************************* //
  • Intial velocity conditions:
/*--------------------------------*- 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       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (0.42084 0 0);
    }

    outlet
    {
        type            zeroGradient;
    }

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

// ************************************************************************* //
  • ControlDict 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;

    location    \"system\";

    object      controlDict;

}

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



application     icoFoam;



startFrom       startTime;



startTime       0;



stopAt          endTime;



endTime         1;



deltaT          0.0005;



writeControl    timeStep;



writeInterval   20;



purgeWrite      0;



writeFormat     ascii;



writePrecision  6;



writeCompression off;



timeFormat      general;



timePrecision   6;



runTimeModifiable true;





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

Results:

The results obtained from simulations using symmetry boundary condition with different wedge angles are shown below;

  • Wedge angle= 10 degrees

\"\"

Fully developed velocity plot:

\"\"

  • Wedge angle= 25 degrees

\"\"

Fully developed velocity plot:

\"\"

  • Wedge angle= 45 degrees

\"\"

Fully developed velocity plot:

\"\"

  • Wedge Boundary condition with angle = 5 degreess

\"\"

Fully developed velocity plot:

\"\"

Comparison of results obtained:

\"\"

It can be observed that as the wedge angle of the pipe section is increased, the simulation run time is also increasing.

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.