Week 8 - Simulation of a backward facing step in OpenFOAM
OBJECTIVE: Simulation of a backward-facing step in OpenFOAM.
- Simulate an incompressible-laminar-viscous flow through the backward-facing step geometry.
- perform a transient simulation.
- Choose the solver based on the described physics of the flow.
- Explain the entire simulation procedure ( how you set up the case).
- After that perform 2 case studies as described below and compare the results.
- case 1 - Simulate the flow without using any grading factor (i.e. GF = 1).
- case 2 - Simulate the flow with a grading factor of 0.2. The cells should be finer near the walls.
Mesh specification:
- Number of cells along the x-direction ( longer dimension ) = 200
- Number of cells along with the longer y-direction = 20;
Boundary condition specification
The domain specifications are provided in the following figure.

Desired output
- Measure the velocity profile at 0.085 m from the inlet of the geometry for both case studies and compare.
SOLUTION:
To solve this particular problem, our first objective is to choose a solver, selecting a solver tutorial to create geometry and mesh. After creating the geometry and meshing then we can set up the case, assigning boundary conditions and initial conditions. After that, we can post-processing the results then we can plot the results.
As there are some assumptions in the problem that the flow is incompressible-laminar-viscous flow.
- In order to choose the solver, First, start the terminal in the Linux Operating system using the ctrl+alt+T buttons.
- Here we are going to solve our problem using tutorials present in OpenFOAM, therefore, just type 'tut' to open the OpenFOAM tutorial directory.
- Type 'ls' to identify what kind of tutorials present inside the directory.
- As we are solving incompressible flow simulation for this problem so select the incompressible directory by typing 'cd incompressible' and then type 'ls' to explore in incompressible folders.
- As we are solving incompressible-laminar-viscous flow, we need a solver for laminar-viscous flow. so here we choose 'icoFoam'.
- To select icoFoam directory by typing 'cd icoFoam' we can. then by typing 'ls', we explore this folder in the terminal.
- Here, we have two options, cavity, and elbow. they both are part of the icoFoam solver. here we select cavity by typing 'cd cavity'.
- Then we are again going to see some more folders in it. there is one more cavity folder where we have to define our fluid domain and generate the block mesh.
- we can not make any changes here in the tutorial section. changes with their official tutorials may corrupt OpenFOAM. So we are going to copy this cavity folder and paste it in the OpenFOAM run folder by using 'cp -r cavity $FOAM_RUN/cavity_test'. here cavity_test we are giving a name for the cavity folder in the OpenFOAM run folder.
- Now we can make any changes to the cavity_test file, which will never affect the OpenFOAM official files.
- Now we open the cavity_test file by opening the run folder, for this type 'cd $foam_run' and then ls to explore the run folder.
- then we can see here the cavity_test folder is available. then type 'cd cavity_test' to select that file. then type 'ls' to explore the cavity_test file in the terminal.
- As we can see there are four script file system folders and by opening blockMeshDict, we can create the domain and provide the required specification for block mesh. so open this file by typing 'gedit blockMeshDict'.
- when we open this file we are going to see header information in the form of comments which is not executable.
- Then we will see the file identifier by which OpenFOAM reads to understand the type of file. in this case, it is blockMeshDict. it contains information in the directory format, means, key, and value format. Here we don't have to make any changes, so keep it as it is.
- Then we set units in the meter, by converting all types of length into the meter.
- Then we provide a list of vertices by providing x, y, and z coordinates locations; it always starts from the vertex (0,0,0).
- we will create the following geometry.

To create the above geometry we consider 5 blocks as in the below figure.

Now we provide vertices for each block by referring to the following sketch.

19. After proving vertices for each block, we can below further the word hex can be found. That is the line where we specify the faces of the blocks and also the number of cells in x, y, and z directions. we studying two cases one with grading factor 1 and one with grading factor 0.2. we will make changes one by one in the blockMeshDict file for the grading factor.
20. Also we specify the boundary conditions, the faces as the inlet, outlet, font, and back, and fixed walls.
21. Inlet faces, which serve as the inlet. Outlet faces, which serve as the outlet. fixed walls where the no-slip condition is applicable.
blockMeshDict: After making changes in the script file.
For 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 1;
vertices
(
(0 0 0) //0
(0.08 0 0) //1
(0.08 0.005 0) //2
(0 0.005 0) //3
(0.08 0.01 0) //4
(0 0.01 0) //5
(0.20 0.01 0) //6
(0.20 0.005 0) //7
(0.20 0 0) //8
(0.20 -0.01 0) //9
(0.08 -0.01 0) //10
(0 0 0.001) //11
(0.08 0 0.001 ) //12
(0.08 0.005 0.001) //13
(0 0.005 0.001) //14
(0.08 0.01 0.001) //15
(0 0.01 0.001) //16
(0.20 0.01 0.001) //17
(0.20 0.005 0.001) //18
(0.20 0 0.001) //19
(0.20 -0.01 0.001) //20
(0.08 -0.01 0.001) //21
);
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (1 1 1) // block1
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (1 1 1) // block2
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1) // block3
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1 1 1) // block4
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (1 1 1) // block5
);
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)
(3 5 4 2)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
(11 12 13 14)
(14 13 15 16)
(21 20 19 12)
(12 19 18 13)
(13 18 17 15)
);
}
fixedWalls
{
type wall;
faces
(
(15 4 5 16)
(17 6 4 15)
(1 10 21 12)
(0 1 12 11)
(10 9 20 21)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
22. The next step is to navigate to the controlDict folder and specify the simulation time, and time step. So we change the time step and end time in the controlDict file. rest of the conditions are kept default.
23. To set initial conditions for pressure and velocity at each faces also update the name of the boundary same as we changed the inlet and outlet name in the 'blockMeshDict' file.
24. Then for the initial conditions we type 'cd 0' here we will see two script file p and U. by typing 'gedit p', we make changes in the p file for initial pressure and by typing 'gedit U' we make changes in the U file for the initial velocity.
25. Here we can see again there is the header information which is non-executable. here we can see the dimensional formula. Specification of the inlet boundary condition, velocity along the x-direction: 0.666 m/s. this value is formed by (0.20/0.3) = 0.666, where 0.20 is the domain length and 0.3 is the end time.
26. at this point, our problem statement is set, we can now proceed to deploy mesh using 'blockMesh' command and then use the 'checkMesh' command to check if there is an error in our mesh.
27. After deploying the mesh, now we are ready to run the simulation. The simulation that we selected was icoFoam. Hence just type 'icoFoam' the simulation will start.
28. Now see the results in ParaView by using the 'paraFoam' command.
For grade factor 1:
Mesh generated


The above code is written in the blockMeshDict file for mesh generation with a grading factor of 1.
Velocity distribution along with the domain:

Pressure distribution along with the domain:

Velocity plot at a distance 0.085 m from inlet:

For 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 1;
vertices
(
(0 0 0) //0
(0.08 0 0) //1
(0.08 0.005 0) //2
(0 0.005 0) //3
(0.08 0.01 0) //4
(0 0.01 0) //5
(0.20 0.01 0) //6
(0.20 0.005 0) //7
(0.20 0 0) //8
(0.20 -0.01 0) //9
(0.08 -0.01 0) //10
(0 0 0.001) //11
(0.08 0 0.001 ) //12
(0.08 0.005 0.001) //13
(0 0.005 0.001) //14
(0.08 0.01 0.001) //15
(0 0.01 0.001) //16
(0.20 0.01 0.001) //17
(0.20 0.005 0.001) //18
(0.20 0 0.001) //19
(0.20 -0.01 0.001) //20
(0.08 -0.01 0.001) //21
);
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.2 5 1) // block1
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.2 0.2 1) // block2
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (5 0.2 1) // block3
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (5 5 1) // block4
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (5 5 1) // block5
);
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)
(3 5 4 2)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
(11 12 13 14)
(14 13 15 16)
(21 20 19 12)
(12 19 18 13)
(13 18 17 15)
);
}
fixedWalls
{
type wall;
faces
(
(15 4 5 16)
(17 6 4 15)
(1 10 21 12)
(0 1 12 11)
(10 9 20 21)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
For grade factor 0.2:
Mesh generated

Velocity distribution along with the domain:

Pressure distribution along with the domain:

Velocity plot at a distance 0.085 m from inlet:

ControlDict 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;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.3;
deltaT 0.00003;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
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.666 0 0);
}
outlet
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
fixedWalls
{
type noSlip;
}
}
// ************************************************************************* //
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;
}
fixedWalls
{
type zeroGradient;
}
}
// ************************************************************************* //
Conclusions:
- For different grading factors, as the mesh becomes finer at 0.2 we can see the velocity drop curve.
- Overall the velocity magnitude profiles give similar results in general but with mesh grading factor it is observed that finer results can be obtained with the finer mesh and more accuracy can be aimed in solution.