Challenge

Week 8 - Simulation of a backward facing step in OpenFOAM

A simulation of an incompressible laminar viscous flow through a backward facing step 2d geometry using blockmesh methodology and icoFoam solver is employed in this problem. The geometry is subdivided into 5 blocks and each block is identified with their respective vertex coordinate points. The mesh along the x and y directions are individually defined for each block. The inlet velocity is set at 1m/s and the initial pressure at the outlet is set at zero gradient. A no-slip condition is applied to the top and the bottom walls including the backward facing step wall. The simulation is carried out under 2 cases which are with and without grading.

Case 1: Without Grading

Grading factor is defined as the ratio of size of last cell in a given direction to the size of first cell in the same direction. Since grading or refinement of the cells is not present, it can be ssen that the cells are uniform throughout along the X and Y directions.

/*--------------------------------*- 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.08 0 0)
    (0.08 0.005 0)
    (0 0.005 0)
    (0.08 0.01 0)
    (0 0.01 0)
    (0.2 0.01 0)
    (0.2 0.005 0)
    (0.2 0 0)
    (0.2 -0.01 0)
    (0.08 -0.01 0)
    
    (0 0 0.0001)
    (0.08 0 0.0001)
    (0.08 0.005 0.0001)
    (0 0.005 0.0001)
    (0.08 0.01 0.0001)
    (0 0.01 0.0001)
    (0.2 0.01 0.0001)
    (0.2 0.005 0.0001)
    (0.2 0 0.0001)
    (0.2 -0.01 0.0001)
    (0.08 -0.01 0.0001)
);

blocks
(
    hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (1 1 1)
    hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (1 1 1)
    hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1)
    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)
);

edges
(
);

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

mergePatchPairs
(
);

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

The above code generates the blocks using vertices as its identifiers, meshes the blocks and also assigns the boundary conditions over the entire geometry.In this case, the grading along all 3 directions in space is set at 1, which results in a uniform grid size thorughout the geometry.

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

deltaT          0.0005;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

The start and end time along with the number of timesteps is defined by the controlDict file as given above. The magnitude of timestep is tweaked such that the Courant number remains belows 1 and the simulation is executed in a stable manner.

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

    fixedWalls
    {
        type            zeroGradient;
    }

    frontAndBack
    {
        type            empty;
    }
}

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

    fixedWalls
    {
        type            noSlip;
    }

    frontAndBack
    {
        type            empty;
    }
}

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

The above the code snippets are used to define the initial conditons for the values of Pressure and Velocity at various bundary locations and it is the same for both cases of grading.

The velocity of the flow along the Y-Direction at x = 0.085 from the inlet, just ahead of the backward facing step is given by the lineplot as shown above.

Case 2 : With Grading

/*--------------------------------*- 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.08 0 0)
    (0.08 0.005 0)
    (0 0.005 0)
    (0.08 0.01 0)
    (0 0.01 0)
    (0.2 0.01 0)
    (0.2 0.005 0)
    (0.2 0 0)
    (0.2 -0.01 0)
    (0.08 -0.01 0)
    
    (0 0 0.0001)
    (0.08 0 0.0001)
    (0.08 0.005 0.0001)
    (0 0.005 0.0001)
    (0.08 0.01 0.0001)
    (0 0.01 0.0001)
    (0.2 0.01 0.0001)
    (0.2 0.005 0.0001)
    (0.2 0 0.0001)
    (0.2 -0.01 0.0001)
    (0.08 -0.01 0.0001)
);

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

edges
(
);

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

mergePatchPairs
(
);

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

The cells nearer to the wall are made finer by using a grading factor of 10 and 0.1 wherever applicable. The timestep in the controlDict file is modified to satisfy the Courant's conditon and is given below.

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

deltaT          0.000005;

writeControl    timeStep;

writeInterval   50;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

The initial conditons of p and U are same as the previous case.

Mesh Grading/Refinement is an important tool for editing finite element meshes in order to increase the accuracy of the solution.

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.