Challenge

Week 8 - Simulation of a backward facing step in OpenFOAM

Objective:

The objective of this simulation is to model an incompressible-laminar-viscous flow through a backwards-facing step geometry and perform a transient simulation.

Case 1:

Simulate the flow without using any grading factor (GF = 1).

Case 2:

Simulate the flow with a grading factor of 0.2, where cells are finer near the walls, including the step wall.

Explanation:

Incompressible flow:

An incompressible flow is characterized by the absence of density changes within the fluid. Mathematically, it can be expressed as the divergence of velocity ((∇⋅u)) equal to zero. In this type of flow, the Reynolds number (Re) is calculated using the formula ({ρ⋅v⋅L}/{μ}), where (ρ) is the density, (v) is the velocity, (L) is a characteristic length, and (μ) is the dynamic viscosity.

∇⋅u=0

∇⋅u=0

∇⋅u=0Re=ρ⋅v⋅L / μ

Laminar flow:

Laminar flow refers to fluid motion where particles follow smooth, orderly paths without significant mixing. It is characterized by layers of fluid sliding smoothly past one another with little or no lateral mixing or turbulence. In laminar flow, particles near solid surfaces move in straight lines parallel to the surface, and there are no perpendicular cross-currents or eddies. This flow regime exhibits high-momentum diffusion and low-momentum convection.

For the simulation, we aim to accurately model the incompressible-laminar-viscous flow through the backward-facing step geometry in both of the specified cases. By considering the grading factor, we can refine the mesh near the walls to capture boundary layer effects more effectively, leading to more accurate results.

Reynolds number serves as a key parameter for distinguishing between laminar and turbulent flow regimes. Typically, flow in a pipe is considered laminar when the Reynolds number is below approximately 2,000, while values above 2,000 indicate turbulent flow.

Mathematically, Reynolds number represents the ratio of inertial forces to viscous forces within a fluid flow. It can be calculated using the formula:

Re=μρ⋅u⋅L​


​

Where:

( ρ ) is the density of the fluid (kg/m2).

( u ) is the flow speed (m/s).

( L ) is a characteristic linear dimension (m), and

(μμ ) is the dynamic viscosity of the fluid (Pa·s or N·s/m² or kg/(m·s)).

Viscous flow refers to a type of fluid motion characterized by continuous, steady particle motion where the velocity at a fixed point remains constant. This type of flow is also known as streamline flow, laminar flow, or steady flow.

In viscous flow, fluid motion occurs in layers, with the layer adjacent to the wall exhibiting zero velocity due to the no-slip condition. This condition results in frictional effects at the wall as well as between adjacent layers of fluid. The slower-moving layer tends to slow down the faster-moving layer, a phenomenon quantified by viscosity.

Mesh grading, often referred to as the grading factor, is a parameter used to control the distribution of cell sizes within a computational mesh. It is defined as the ratio of the size of the last cell to the size of the first cell.

Mathematically, the grading factor GF is calculated using the formula:

GF=Size of the first cellSize of the last cell​

The grading factor allows engineers and researchers to specify how the cell sizes change within the mesh domain. A grading factor greater than 1 indicates that the cell sizes increase from the first cell to the last cell, while a grading factor less than 1 indicates that the cell sizes decrease.

By adjusting the grading factor, users can control the mesh resolution and accuracy in different regions of the computational domain. Finer meshes (smaller cells) are typically used in areas where high gradients or complex flow phenomena are expected, while coarser meshes (larger cells) may be sufficient in regions with relatively uniform flow properties. This flexibility in mesh grading helps optimize computational resources and improve the accuracy of simulations.

PROCEDURE:

First, we create a run folder in OpenFOAM where we will execute our simulations.
The cavity folder must then be copied to the run folder so that we can make changes to the blockMeshDict, controlDict, and pressure and velocity files in order to run our required simulations. We are copying the folder because we are not allowed to make changes to the original folders in OpenFOAM.

Then, make the necessary adjustments in the blockMeshDict file that is naming the vertices for and then building the blocks; in this example, there are 21 vertices and 5 blocks. When generating blocks, we must define the number of mesh points required along the x, y, and z directions, as well as the basic grading of the borders.
then, we need to assign the boundary conditions here. We need to define all the faces in OpenFOAM, which refers to patches, and give them a type, that is, the inlet and outlet will be the faces (type patch); for the front and back, the type will be empty faces; and for the top and bottom, which are the boundary conditions in this case, the type will be wall. Setting them up will create a specific boundary, and the modifications will be saved in the blockMeshDict.

Then, in the velocity and pressure files, we have to give the value of the velocity at the inlet type, which will be a fixed value. Here, we should assign some value as initial velocity and pressure will be zero gradient and at the outlet velocity type, which will be zero gradient and pressure will be a type fixed value, that value will be uniform 0, then at the front and back velocity types, empty and pressure, as well as type empty at the no slip boundaries, that is, top and bottom velocity, will be And in transport properties, we may adjust the nu value to get the lower courant number.

In the controlDict file, the simulation time and time step must be provided in such a way that the current number is smaller than 0.5.
After generating the block mesh, run the simulation using the appropriate solver. Once the simulation is complete, open the paraview in the paraFoam and plot the velocity profile for the provided value. Rephrase or paraphrase the following, but keep in mind that the plagiarism checker is on.

CODE:

BLOCKMESHDICT 

For without applying grading factor

/*--------------------------------*- 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)
    (8 0 0)
    (8 0.5 0)
    (0 0.5 0)
    (8 1 0)
    (0 1 0)
    (20 1 0)
    (20 0.5 0)
    (20 0 0)
    (20 -1 0)
    (8 -1 0)
       
    (0 0 0.6)
    (8 0 0.6)
    (8 0.5 0.6)
    (0 0.5 0.6)
    (8 1 0.6)
    (0 1 0.6)
    (20 1 0.6)
    (20 0.5 0.6)
    (20 0 0.6)
    (20 -1 0.6)
    (8 -1 0.6)
   


   
   
);

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

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)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (11 12 13 14)
            (3 5 4 2)
            (13 15 16 14)
            (2 4 6 7)
            (13 18 17 15)
            (1 2 7 8)
            (12 19 18 13)
            (10 1 8 9)
            (21 20 19 12)
           
           
        );
    }
   
        noslipwall
    {
        type wall;
        faces
        (
            (4 5 16 15)
            (4 15 17 6)
            (0 1 12 11)
            (9 20 21 10)
            (1 10 21 12)
           
        );
    }
                                         
);

mergePatchPairs
(
             
);

// ************************************************************************* //
With the applied 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;

vertices
(
    (0 0 0)
    (8 0 0)
    (8 0.5 0)
    (0 0.5 0)
    (8 1 0)
    (0 1 0)
    (20 1 0)
    (20 0.5 0)
    (20 0 0)
    (20 -1 0)
    (8 -1 0)
       
    (0 0 0.6)
    (8 0 0.6)
    (8 0.5 0.6)
    (0 0.5 0.6)
    (8 1 0.6)
    (0 1 0.6)
    (20 1 0.6)
    (20 0.5 0.6)
    (20 0 0.6)
    (20 -1 0.6)
    (8 -1 0.6)
   


   
   
);

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

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)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (11 12 13 14)
            (3 5 4 2)
            (13 15 16 14)
            (2 4 6 7)
            (13 18 17 15)
            (1 2 7 8)
            (12 19 18 13)
            (10 1 8 9)
            (21 20 19 12)
           
           
        );
    }
   
        noslipwall
    {
        type wall;
        faces
        (
            (4 5 16 15)
            (4 15 17 6)
            (0 1 12 11)
            (9 20 21 10)
            (1 10 21 12)
           
        );
    }
                                         
);

mergePatchPairs
(
             
);

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

 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         3;

deltaT          1e-3;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

 PRESSURE 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;
    }

    frontAndBack
    {
        type            empty;
    }
    noslipwall
    {
        type            zeroGradient;
    }
}

// ************************************************************************* //
 VELOCITY 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.066 0 0);
    }

    outlet
    {
        type            zeroGradient;
    }

    frontAndBack
    {
        type            empty;
    }
    noslipwall
    {
        type            noSlip;
    }
}

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

TRANSPORT PROPERTIES

/*--------------------------------*- 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    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

nu              [0 2 -1 0 0 0 0] 1e-6;


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

OUTPUT:

The velocity plot at 0.085 without grading the fcator is shown below:

The plot for the velocity at 0.085 for the specified grading factor of 0.2 is shown below.

With no grading factor, the block mesh is as shown below.

for grading factor 0.2

The velocity flow figure has no grading factor.

The velocity flow fig. for grading factor 0.2

The pressure flow figure has no grading factor.

The pressure flow fig. for grading factor 0.2

CONCLUSION.


By increasing the simple grading factor from 0.2 to 1, the mesh grows finer and the solution becomes more precise.

Overall, the size of the basic grading component (mesh size) changes, but the outcomes stay essentially the same.

Lower meshing grading factors result in shorter execution times.

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.