Challenge

Simulation of a backward facing step in OpenFOAM

AIM:-

To use OpenFoam to simulate incompressible-viscous-laminar flow through a backward-facing step with the mesh being created using blockMesh. The effect of the grading factor is also analysed.

THEORY:-

OpenFoam is an open-source CFD software that uses C++ code and blockMesh is a mesh generator in OpenFoam. The backward-facing step is shown below and is to be divided into 200 elements along the x-direction and 10 elements along the y-direction.

METHOD:-

The Backward Facing step is simulated using the icoFoam solver which is suitable for incompressible laminar-viscous flows. The backward-facing step is split into 5 blocks as shown below:

This geometry is created in the blockMeshDict.C file in the system folder of the icoFoam tutorial folder. The points for the blocks are numbered as shown:

The blockMeshDict code starts with defining the points as shown above and then the blocks are defined using the defined points and the no of elements and grading within each block is also individually specified. Then the faces are classified and named into no-slip walls, inlet, outlet, and in order to make the blocks into a 2D domain, the front and back faces are classified as empty. Then the mesh is implemented by running blockMesh command in the main folder.

Then the boundary conditions need to be implemented. This is done in the 0 folder (located in the main folder) which contains the pressure (p) and velocity (U) files where the boundary conditions for both fields are applied.

Once this is done, the simulation is started using the icoFoam (which is the name of the solver) command in the main folder. Once the simulation is done the results are visualized using ParaView which can be opened using the paraFoam command in the command line.

CASE 1 - Without any Grading Factor

The edited blockMeshDict file is as follows:

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

vertices
(
    (0 0 0) // point 0
    (8 0 0) // point 1
    (8 0.5 0) // point 2
    (0 0.5 0) // point 3
    (8 1 0) // point 4
    (0 1 0) // point 5
    (20 1 0) // point 6
    (20 0.5 0) // point 7
    (20 0 0) // point 8
    (20 -1 0) // point 9
    (8 -1 0) // point 10
    
    (0 0 0.1) // point 11
    (8 0 0.1) // point 12
    (8 0.5 0.1) // point 13
    (0 0.5 0.1) // point 14
    (8 1 0.1) // point 15
    (0 1 0.1) // point 16
    (20 1 0.1) // point 17
    (20 0.5 0.1) // point 18
    (20 0 0.1) // point 19
    (20 -1 0.1) // point 20
    (8 -1 0.1) // point 21
    
    
);

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

edges
(
);

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

);

mergePatchPairs
(
	
);

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

The controlDict file which contains the values of constants for the simulation is shown below. This remains the same for both cases:

/*--------------------------------*- 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.0001;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

The boundary conditions for

pressure (in the p file in the 0 folder)

/*--------------------------------*- 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;
    }
    noSlipWalls
    {
        type            zeroGradient;
    }

    frontAndBack
    {
        type            empty;
    }
}

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

velocity (U file in the 0 folder)

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

    noSlipWalls
    {
        type            noSlip;
    }

    frontAndBack
    {
        type            empty;
    }
}

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

CASE 1 - RESULTS

The mesh created is as shown with 200 elements along the x-direction and 20 elements along the y-direction

The final velocity distribution

The final pressure distribution

The velocity profile at the cross-section where x = 0.085

CASE 2 - With Grading Factor = 0.2

The grid factor is used to make the mesh finer near the walls.

The blockMeshDict code is as follows:

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

vertices
(
    (0 0 0) // point 0
    (8 0 0) // point 1
    (8 0.5 0) // point 2
    (0 0.5 0) // point 3
    (8 1 0) // point 4
    (0 1 0) // point 5
    (20 1 0) // point 6
    (20 0.5 0) // point 7
    (20 0 0) // point 8
    (20 -1 0) // point 9
    (8 -1 0) // point 10
    
    (0 0 0.1) // point 11
    (8 0 0.1) // point 12
    (8 0.5 0.1) // point 13
    (0 0.5 0.1) // point 14
    (8 1 0.1) // point 15
    (0 1 0.1) // point 16
    (20 1 0.1) // point 17
    (20 0.5 0.1) // point 18
    (20 0 0.1) // point 19
    (20 -1 0.1) // point 20
    (8 -1 0.1) // point 21
    
    
);

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

edges
(
);

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

);

mergePatchPairs
(
	
);

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

The other code like controlDict and the boundary conditions U and p are the same as in Case 1.

CASE 2 - RESULTS

The mesh created is as shown with 200 elements along the x-direction and 20 elements along the y-direction and with a grading factor of 0.2 to make the mesh finer at the walls

The velocity distribution

The pressure distribution

The velocity profile at x = 0.085

INFERENCE:-

The grading factor helps with meshing because it allows us to get a finer mesh in specifically required regions without increasing the overall number of elements significantly. If grading was not possible the overall number of elements would be needed to be increased across the entire domain to get the required level of fineness at the specific regions and this would increase the computation time significantly.

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.