Challenge

Week 10 - Simulation of Flow through a pipe in OpenFoam

AIM:

Applying the wedge boundary condition to simulate an axis-symmetric laminar flow through a pipe with a constant cross-section.
We used the Hagen-poiseuille equation to confirm our findings.



Theory:


Hagen-Poiseuille's law :

The Hagen-Poiseuille equation, often known as the Hagen-Poiseuille law, is a physical formula that describes the pressure drop in an incompressible Newtonian fluid moving through a long cylindrical conduit with a constant cross-section in nonideal fluid dynamics. The pressure decrease is calculated as follows:

ΔP = 32μLV⁄D²

where,

ΔPΔ� is the pressure drop.

μ� is the dynamic viscosity.

L is the length of the pipe.

V is the velocity.

The flow is considered to be in a hydrodynamic entry zone when the velocity profile progressively changes form from a straight line to a parabola. When the parabolic velocity profile stabilizes, the flow is considered to have completely developed. Normally, Hagen Poiseuille's Equation is applicable to a fully developed flow, allowing us to compute pressure loss.

Assumptions Made:

Geometry: axisymmetric.

Reynolds Number: 2100.

Working fluid: water.

The diameter of the pipe is 0.02 m.

Dynamic viscosity (μ) = 0.89x10^-3 Pas.

Kinematic viscosity (v) = 0.8927 x 10^-6 m^2/s.

theta=4

Equations:

1.Average velocity : Vavg=ReμρD����=����� m/s

2.Maximum velocity: Vmax=2⋅Vavg�max=2⋅���� m/s

3.Pressure drop : ΔP=32μLVD2Δ�=32����2 pa

4.kinematic pressure drop = ΔPρΔ��

PROCEDURE:

To initiate the simulation, the cavity file from the tutorial is copied to the FOAM_RUN folder. This folder serves as the workspace where all modifications to the simulation setup will be made, including adjustments to the blockMeshDict, pressure and velocity files, and controlDict files.

The first step involves creating the wedge geometry within OpenFOAM. This is achieved by modifying the blockMeshDict file to define the necessary block parameters, followed by executing the blockMesh command to generate the mesh.

Upon creating the wedge, boundary conditions are assigned to the geometry, ensuring that appropriate conditions are specified for each boundary face. Additionally, simulation parameters such as the end time and time-step are set in the controlDict file to ensure a Courant number below 0.5. The kinematic viscosity is also defined in the transportProperties file.

Subsequently, the simulation is launched using the icoFoam solver, with careful consideration given to the time required for the fluid to traverse from the inlet to the outlet.

Post-simulation, ParaView is utilized to visualize the flow within the wedge geometry. The "plot over line" command is employed to analyze velocity and shear stress variations at a specific point within the fully developed region of the fluid, beyond the hydrodynamic entry region.

Finally, Matlab is utilized to parse the blockMeshDict file, enabling the use of the same file for different wedge geometries. This facilitates flexibility and efficiency in conducting simulations with varying wedge configurations.

MATLAB code is used to generate the blockMeshDict file.

clear all
close all
clc

% inputs
D= 0.02;
r= D/2;
theta= 4;
Re= 2100;
L_h = 0.05*Re*D;
L_pipe= L_h ;
scale= 1;

%vertices
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_pipe 0 0];
v4= [L_pipe r*cosd(theta/2) r*sind(theta/2)];
v5= [L_pipe r*cosd(theta/2) -r*sind(theta/2)];

%number of cells along x,y and z axis
nx= 20;
ny= 1;
nz= 200;

%grading factors
gx= 1;
gy= 1;
gz= 1;

%writing to a file
f1 = fopen('blockMeshDict_45','w');

%header region
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:  8');
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,'\n');

%initial inputs
fprintf(f1,'%s','convertToMeters ');
fprintf(f1,'%g',scale);
fprintf(f1,'%s\n',';' );
fprintf(f1,'\n');
fprintf(f1,'%s\n','vertices');
fprintf(f1,'(\n');
fprintf(f1,'    (%d %d %d)\n',v0);
fprintf(f1,'    (%g %g %g)\n',v1);
fprintf(f1,'    (%g %g %g)\n',v2);
fprintf(f1,'    (%g %g %g)\n',v3);
fprintf(f1,'    (%g %g %g)\n',v4);
fprintf(f1,'    (%g %g %g)\n',v5);
fprintf(f1,');\n\n');

%Defining the wedge block
fprintf(f1,'%s\n','blocks');
fprintf(f1,'(\n');
fprintf(f1,'    %s (%g %g %g %g %g %g %g %g)','hex (0 2 1 0 3 5 4 3)');
fprintf(f1,'%g %g %g)',nx,ny,nz); 
fprintf(f1,' %s (%g %g %g)\n','simpleGrading',gx,gy,gz);
fprintf(f1,');');
fprintf(f1,'\n\n');

%edges (if needed to add arc, etc.)
fprintf(f1,'%s\n','edges');
fprintf(f1,'(\n');
fprintf(f1,'	%s (%g %g %g)\n','arc 1 2' ,0 ,r, 0);
fprintf(f1,'	%s (%g %g %g)\n','arc 1 2' ,L_pipe ,r, 0);
fprintf(f1,');\n\n');

%Boundary Conditions
fprintf(f1,'%s\n','boundary');
fprintf(f1,'(\n');

%Inlet
fprintf(f1,'    %s\n','inlet');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type patch;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(0 1 2 0)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');

%Outlet 
fprintf(f1,'    %s\n','outlet');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type patch;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(3 4 5 3)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');

%Front wall
fprintf(f1,'    %s\n','front');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type wedge;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(2 5 3 0)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');

%Back wall
fprintf(f1,'    %s\n','Back');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type wedge;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(0 3 4 1)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');

%Top wall
fprintf(f1,'    %s\n','pipe');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type wall;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(1 4 5 2)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');

%Bottom wall
fprintf(f1,'    %s\n','axis');
fprintf(f1,'    {\n');
fprintf(f1,'        %s\n','type empty;');
fprintf(f1,'        %s\n','faces');
fprintf(f1,'        (\n');
fprintf(f1,'            %s\n','(0 3 3 0)');
fprintf(f1,'        );\n');
fprintf(f1,'    }\n');
fprintf(f1,');\n\n');

%Merging Patch pairs
fprintf(f1,'%s\n','mergePatchPairs');
fprintf(f1,'(\n');
fprintf(f1,');\n\n');
fprintf(f1,'%s','// ************************************************************************* //');






fclose(f1)
blockMeshDict file.

/*--------------------------------*- 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 1;

vertices
(
    (0 0 0)
    (0 0.0099390827 0.000348994967)
    (0 0.0099390827 -0.000348994967)
    (2.52 0 0)
    (2.52 0.0099390827 0.000348994967)
    (2.52 0.0099390827 -0.000348994967)  
);

blocks
(
    hex (0 2 1 0 3 5 4 3) (20 1 200) simpleGrading (1 1 1)
);

edges
(
    arc 1 2 (0 0.01 0)
    arc 4 5 (2.52 0.01 0)
);

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

mergePatchPairs
(
);

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

P file.

/*--------------------------------*- 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.01687;
   
    }
    front
    {
        type            wedge;
    }
    Back
    {
        type            wedge;
    }
    pipe
    {
        type            zeroGradient;
    }
    axis
    {
        type            empty;
    }
}

// ************************************************************************* //
U file.

/*--------------------------------*- 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 0 0);

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (0.09373 0 0);
    }
    outlet
    {
        type            zeroGradient;
       
    }

    pipe
    {
        type            noSlip;
    }

    front
    {
        type           wedge;
    }
    Back
    {
        type           wedge;
    }
    axis
    {
        type           empty;
    }
}

// ************************************************************************* //
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         8;

deltaT          0.001;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

CONCLUSION:

Shear stress in the wedge.

Pressure flows in the wedge for fully developed flow.

Velocity contour diagram.

Plot for shear stress:

Plot for pressure drop :

Velocity profile at the length of x=0.01

Velocity profile at the length of x=2.52 at the fully developed flow region.

Comparison between the analytical and numerical solution.

variables Analytical solution Numerical solution

Velocity 0.18 0.17

shear stress 0.03 0.03

Hydrodynamic length is calculated to be 2.52 units when the velocity profile is completely established.

The velocity profile increases progressively from input to exit. It remains consistent once the flow has been fully established.

The analytical velocity profile and velocity recorded in openfoam match quite well, with velocity being highest in the center and decreasing parabolically toward the wall.

Shear stress is 0 in the middle of the pipe and grows linearly toward the wall; the graph derived from openfoam is similar to the analytical finding.

The maximum velocity and pressure drop values are obtained for fully developed flows.

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.