Challenge

Week 8 - Simulation of a backward facing step in OpenFOAM

Objective : To simulate an incompressible-laminar-viscous flow through the backward facing step geometry using icoFoam solver. The domain specifications are as per the following figure

Conditions

Mesh specification

  1. Number of cells along the x direction (longer dimension) = 200
  2. Number of cells along the longer y direction = 20

Use of different grading factor for mesh with finer mesh near the walls.

Grading factor (GF)

Grading factor is the ratio of size of last cell to first cell. Grading factor > 1 indicates that mesh is finer at the start whereas grading factor <1 indicates that mesh is finer at the end. The grading factor is selected in such a way that finer mesh elements are near the walls and at sharp edges. Mesh element for different grading factor are as follows :

Grading Factor = 0.2

Grading Factor = 0.5

Grading factor = 1

blockMeshDict file

In this file, geometry and mesh are created for the required condition. The vertices for the domain are defined as per the requirement of the problem. The vertices are defined for 5 blocks. The meshes are distributed appropriately in x, y and z directions. The grading factor for meshes are provided so that finer mesh elements are near the walls and at sharp edges.

blockMeshDict code for various grading factors are as folllows :

Grading factor = 0.2

/*--------------------------------*- 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.01; // units: cm

vertices
(
    (0 0 0) //vertex0
    (8 0 0) //vertex1
    (8 0.5 0) //vertex2
    (0 0.5 0) //vertex3
    (8 1 0) //vertex4
    (0 1 0) //vertex5
    (20 1 0) //vertex6
    (20 0.5 0) //vertex7
    (20 0 0) //vertex8
    (20 -1 0) //vertex9
    (8 -1 0) //vertex10
    (0 0 0.01) //vertex11
    (8 0 0.01) //vertex12
    (8 0.5 0.01) //vertex13
    (0 0.5 0.01) //vertex14
    (8 1 0.01) //vertex15
    (0 1 0.01) //vertex16
    (20 1 0.01) //vertex17
    (20 0.5 0.01) //vertex18
    (20 0 0.01) //vertex19
    (20 -1 0.01) //vertex20
    (8 -1 0.01) //vertex21
    
);

blocks
(
    hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.2 5 1) //0
    hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.2 0.2 1) //1
    hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (5 0.2 1) //2
    hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (5 5 1)
    hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (5 5 1) //4
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 11 14 3)
            (3 14 16 5)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (9 8 19 20)
            (8 7 18 19)
            (7 6 17 18)
        );
    }
    walls
    {
        type wall;
        faces
        (
            (16 15 4 5)
            (15 17 6 4)
            (10 9 20 21)
            (10 21 12 1)
            (0 1 12 11)
        );
    }
);

mergePatchPairs
(
);

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

Grading factor = 0.5

/*--------------------------------*- 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.01; // units: cm

vertices
(
    (0 0 0) //vertex0
    (8 0 0) //vertex1
    (8 0.5 0) //vertex2
    (0 0.5 0) //vertex3
    (8 1 0) //vertex4
    (0 1 0) //vertex5
    (20 1 0) //vertex6
    (20 0.5 0) //vertex7
    (20 0 0) //vertex8
    (20 -1 0) //vertex9
    (8 -1 0) //vertex10
    (0 0 0.01) //vertex11
    (8 0 0.01) //vertex12
    (8 0.5 0.01) //vertex13
    (0 0.5 0.01) //vertex14
    (8 1 0.01) //vertex15
    (0 1 0.01) //vertex16
    (20 1 0.01) //vertex17
    (20 0.5 0.01) //vertex18
    (20 0 0.01) //vertex19
    (20 -1 0.01) //vertex20
    (8 -1 0.01) //vertex21
    
);

blocks
(
    hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.5 2 1) //0
    hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.5 0.5 1) //1
    hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (2 0.5 1) //2
    hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (2 2 1) //3
    hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (2 2 1) //4
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 11 14 3)
            (3 14 16 5)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (9 8 19 20)
            (8 7 18 19)
            (7 6 17 18)
        );
    }
    walls
    {
        type wall;
        faces
        (
            (16 15 4 5)
            (15 17 6 4)
            (10 9 20 21)
            (10 21 12 1)
            (0 1 12 11)
        );
    }
);

mergePatchPairs
(
);

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

Grading factor = 1

/*--------------------------------*- 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.01; // units: cm

vertices
(
    (0 0 0) //vertex0
    (8 0 0) //vertex1
    (8 0.5 0) //vertex2
    (0 0.5 0) //vertex3
    (8 1 0) //vertex4
    (0 1 0) //vertex5
    (20 1 0) //vertex6
    (20 0.5 0) //vertex7
    (20 0 0) //vertex8
    (20 -1 0) //vertex9
    (8 -1 0) //vertex10
    (0 0 0.01) //vertex11
    (8 0 0.01) //vertex12
    (8 0.5 0.01) //vertex13
    (0 0.5 0.01) //vertex14
    (8 1 0.01) //vertex15
    (0 1 0.01) //vertex16
    (20 1 0.01) //vertex17
    (20 0.5 0.01) //vertex18
    (20 0 0.01) //vertex19
    (20 -1 0.01) //vertex20
    (8 -1 0.01) //vertex21
    
);

blocks
(
    hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (1 1 1) //0
    hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (1 1 1) //1
    hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1) //2
    hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1 1 1)
    hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (1 1 1) //4
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 11 14 3)
            (3 14 16 5)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (9 8 19 20)
            (8 7 18 19)
            (7 6 17 18)
        );
    }
    walls
    {
        type wall;
        faces
        (
            (16 15 4 5)
            (15 17 6 4)
            (10 9 20 21)
            (10 21 12 1)
            (0 1 12 11)
        );
    }
);

mergePatchPairs
(
);

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

controlDict file

This file consists of time variables. The time step for the problem is taken as 0.0005. While defining time step, CFL number condition should be taken into account.

controlDict code

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

deltaT          0.00005;

writeControl    timeStep;

writeInterval   200;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

Initial and boundary conditions

The initial and boundary conditions for pressure and velocity are designated as P and U files. They are located in 0 folder. The inlet velocity is taken as 1m/s

U (velocity) code

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

    outlet
    {
        type            zeroGradient;
    }

    walls
    {
        type            noSlip;
        value           uniform (0 0 0);
    }
}

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

P (pressure) code

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

    walls
    {
        type            zeroGradient;
    }
}

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

Results :

The velocity contours in the domain and velocity profile at x = 0.085 for each of the grading factor are as follows :

Grading factor = 0.2

Grading factor = 0.5

Grading factor = 1

From the above velocity profiles, it can be seen that velocity curve becomes smoother with increase in grading factor. This happens because mesh with low grading factor is able to give more accurate results due to finer mesh elements at a particular location (x = 0.085).

A graded mesh is useful in determining the mesh density in every region of the domain based on the complexity of the geometry. Complex geometry with sharp cuts and turns should have higher mesh elements to accurately determine the variation in properties. The variation in velocity is more at sharp edges and near the walls due to no slip condition. Hence, finer mesh are used near walls and at sharp edges to capture the variation in velocity accurately.

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.