Challenge

Week 11 - Simulation of Flow through a pipe in OpenFoam

Aim: Simulation of Flow through a pipe in OpenFoam

objective:

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.

You will also write code in Matlab to automate the generation of blockMeshDict file. The code should take inputs like pipe length, diameter, wedge angle, etc and output a fully functional blockMeshDict file.

theory

In nonideal fluid dynamics, the Hagen–Poiseuille equation, also known as the Hagen–Poiseuille law, Poiseuille law or Poiseuille equation, 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. It can be successfully applied to air flow in lung alveoli, or the flow through a drinking straw or through a hypodermic needle.

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

Poiseuille's equation describes the pressure drop due to the viscosity of the fluid; other types of pressure drops may still occur in a fluid .For example, the pressure needed to drive a viscous fluid up against gravity would contain both that as needed in Poiseuille's law plus that as needed in Bernoulli's equation, such that any point in the flow would have a pressure greater than zero (otherwise no flow would happen).

pressuredrop across end is given by

`nablap=-(8*mu*L*U)/r^2`

where

mu is dydnamic viscosity

L is length of pipe

U is avrge velocity of fluid flow in pipe

r is radius of pipe

case set up

matlab program to gerenate blockMeshDict file

close all;
clear all;
clc;
theta=2; %sectore angle
L=100;%length in m x coordinate
r=5;%radius in m
y=r*cosd(theta/2);% y coordinate of sector
z=r*sind(theta/2);% z coordinate os sector

f1=fopen('blockmeshdict.txt','wt');%txt file ceated in name blockMeshdict.txt

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: 10\n');
fprintf (f1,' \\/ M anipulation |\n');
fprintf(f1, '')
fprintf(f1,'\*---------------------------------------------------------------------------*/\n');
fprintf(f1,'FoamFile\n{\n')
fprintf(f1,'format ascii;\n');
fprintf(f1,' class dictionary;\n');
fprintf(f1,' object blockMeshDict;\n}\n');

fprintf(f1,'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n');
fprintf(f1,'convertToMeters 0.01;\n');
fprintf(f1,'vertices\n');
fprintf(f1,'(\n');
fprintf(f1,' (0 0 0)\n')
fprintf(f1,' (0 %g -%g)\n',y,z)
fprintf(f1,' (0 %g %g)\n',y,z)
fprintf(f1,' (%g 0 0)\n',L)
fprintf(f1,' (%g %g -%g)\n',L,y,z)
fprintf(f1,' (%g %g %g)\n',L,y,z)
fprintf(f1,');\n');
fprintf(f1,'blocks\n');
fprintf(f1,'(\n');
fprintf(f1,' hex (0 1 2 0 3 4 5 3) (100 1 40) simpleGrading (1 1 1)\n')
fprintf(f1,');\n');
fprintf(f1,'edges\n');
fprintf(f1,'(\n');
fprintf(f1,' arc 1 2 (0 %g 0)\n',r)
fprintf(f1,' arc 4 5 (%g %g 0)\n',L,r)
fprintf(f1,');\n');
fprintf(f1,'boundary\n');
fprintf(f1,'(\n');
fprintf(f1,'inlet\n {\n');
fprintf(f1,' type patch;\n');
fprintf(f1,' faces\n(\n');
fprintf(f1,' (0 2 1 0)\n);\n }\n');
fprintf(f1,'outlet\n{\n');
fprintf(f1,' type patch;\n');
fprintf(f1,' faces\n (\n');
fprintf(f1,' (3 4 5 3)\n);\n}\n');
fprintf(f1,'upperWall\n{\n');
fprintf(f1,' type wall;\n');
fprintf(f1,' faces\n (\n');
fprintf(f1,' (1 2 5 4)\n);\n}\n');
fprintf(f1,'axis\n{\n');
fprintf(f1,' type empty;\n');
fprintf(f1,' faces\n(\n');
fprintf(f1,' (0 3 3 0)\n);\n}\n');
fprintf(f1,'front\n{\n');
fprintf(f1,' type wedge;\n');
fprintf(f1,' faces\n(\n');
fprintf(f1,' (0 3 5 2)\n);\n}\n');
fprintf(f1,' Back\n{\n');
fprintf(f1,' type wedge;\n');
fprintf(f1,' faces\n(\n');
fprintf(f1,' (0 1 4 3)\n);\n}\n);\n');
fprintf(f1,'mergePatchPairs\n(\n);\n');

open foam set up

now open openFoam apllication and copy a tutrial gile with files 0 constant and system

in thtat file naviget to system file and open blockMeshDict file and paste the matlab excuted text file copy and save

then navigaete to 0 file and open U file the enter the boundary condtion and saame for p file

the boundary condtions are shown here

0/U file

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  10
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField   uniform (0.021 0 0);

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (0.021 0 0);
    }
    outlet
    {
        type            zeroGradient;
    }
    upperWall
    {
        type            noSlip;
    }
    axis
    {
        type            empty;
    }

    front
    {
        type            wedge;
    }
    Back
    {
        type            wedge;
    }
}

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

0/p file

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  10
     \\/     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;
    }
    upperWall
    {
        type            zeroGradient;
    }
    axis
    {
        type            empty;
    }

    front
    {
        type            wedge;
    }
    Back
    {
        type            wedge;
    }
}

system/blockMeshDict file

/--------------------------------- C++ -----------------------------------
=========                |
\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 \    /   O peration     | Website:  https://openfoam.org
    \  /    A nd           | Version:  10
     \/     M anipulation  |
FoamFile
{
format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.01;
vertices
(
    (0 0 0)
    (0 4.99924 -0.087262)
    (0 4.99924 0.087262)
    (100 0 0)
    (100 4.99924 -0.087262)
    (100 4.99924 0.087262)
);
blocks
(
    hex (0 1 2 0 3 4 5 3) (100 1 40) simpleGrading (1 1 1)
);
edges
(
    arc 1 2 (0 5 0)
    arc 4 5 (100 5 0)
);
boundary
(
inlet
   {
     type patch;
     faces
(
      (0 2 1 0)
);
   }
outlet
{
     type patch;
     faces
   (
     (3 4 5 3)
);
}
upperWall
{
       type wall;
      faces
   (
      (1 2 5 4)
);
}
axis
{
       type empty;
      faces
(
      (0 3 3 0)
);
}
front
{
       type wedge;
      faces
(
      (0 3 5 2)
);
}
   Back
{
       type wedge;
      faces
(
       (0 1 4 3)
);
}
);
mergePatchPairs
(
);

system/controlDict file

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

application     icoFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         1;

deltaT          0.01;

writeControl    timeStep;

writeInterval   5;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

after all this mesh using block mesh utiity and run the simulation using icoFome solver

Result

pressure drop across end using

Hagen- Poiseuille's equation

close all 
clear all
clc
Re=2100;
mu=10^-3;
rho=1000;
D=0.1;
r=D/2;
L=0.1;
U=Re*mu/(D*rho);
dp=-8*mu*L*U/(r^2);

U=0.021m/s

dp=-0.0067pa

openFoam results

mesh

boundary layer

pressure drop

velocity profile

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.