Week 8 - Simulation of a backward facing step in OpenFOAM
Aim: Simulate an incompressible-laminar-viscous transient flow through the backward facing step geometry.
Given data:
Mesh specification
- Number of cells along the x direction (longer dimension) = 200
- Number of cells along the longer y direction = 20;
Boundary condition specification
The domain specifications are provided in the following figure.
Theory:
Mesh grading is a factor that is,
Grading factor=Size of the last cellSize of the first cell">Grading factor=`(Size of the l a st cell) / (Size of the first cell)`
Simulation Procedure:
Solver choosen:
Open the Ubuntu terminal window.
Type foam to take us to the openfoam folder
type ls to get the list of folders in the open foam folder

To go to the tutorials folder tybe tut
type ls to get the list of foldres in the tutorial folder

type cd incompressible/ to go to the incompressible folder

type ls, type cd icoFoam/ to solve the incompressible-laminar-viscous transient flow problem.

in icoFoam go to cavity folder,
In cavity folder, we can see another cavity folder, where we have to define our fluid domain and generate block mesh.
But we are not going to make any changes here in tutorial section. OpenFoam does no let anyone make any changes in their official tutorial and any changes with their official tutorials will corrupt my openFoam. hence we may need to reinstall open foam all over again.
So, we are going to copy this cavity folder using ‘cp -r cavity’ command and paste it in openFoam run folder by typing ‘cp -r cavity $FOAM_RUN/cavity_test’.
And then open run folder by typing ‘cd $FOAM_RUN’. where we can see cavity_test file.

using the command gedit blockMeshDict we can open and edit the block mesh file.
Vertices of the backward step
(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.2 0.01 0) //6
(0.2 0.005 0) //7
(0.2 0 0) //8
(0.2 -0.01 0) //9
(0.08 -0.01 0) //10
(0 0 0.1) //11
(0.08 0 0.1) //12
(0.08 0.005 0.1) //13
(0 0.005 0.1) //14
(0.08 0.01 0.1) //15
(0 0.01 0.1) //16
(0.2 0.01 0.1) //17
(0.2 0.005 0.1) //18
(0.2 0 0.1) //19
(0.2 -0.01 0.1) //20
(0.08 -0.01 0.1) //21
To create the geometry as shown in the figure, we need edit the blockMeshDict file that is available in the system folder of the case setup.
Geometry Creation:
Let us consider creating the geometry using 5 blocks as shown in the figure below,
NOTE: We have demonstrated the geometry creation using 5 blocks and have indexed the vertices this way.
The Isometric View,
Now let’s, start indexing the Vertices on the Back side of the Blocks, Since openFoam uses C++ programming, we start the index from “0”. (The Numbering of the vertices can be varied according to your comfort)
Similarly, the indexing for the frontside of the Blocks are,
To View the Bigger Picture,
Finally, to define the blocks, we need to specify the right order of vertex indices
For example:
to create the 1st Block for this case,
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 (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (1 1 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1 1 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1)
hex: Type of mesh
(0 1 2 3 11 12 13 14): Faces of the Geometry
(200 20 1) No of cells in x, y and z directions.
Similarly proceed by defining the vertices of the other blocks in the Geometry.
To View geometry that you have created, clear out all the entries inside the boundary section of the blockMeshDict file and execute the blockMesh command in the terminal.
Now open paraview and view the geometry that you have created.
Meshing:
Now to mesh the geometry fill in the number of cells in x, y and z direction inside the second parenthesis of the Hex command,
i.e., hex(0 1 2 3 11 12 13 14) (10 10 1) simplegrading(1 1 1).
since this is a 2D problem, increasing the number of cells in the z direction, doesn’t make sense. To view the mesh in paraFoam, select the surface with edges option and view the mesh.
Similarly to refine the mesh near the walls of the geometry, you need to play around with the numbers in the third parenthesis. We leave that for you to figure out, how It can be done.
Boundary Conditions:
Before we run the simulations, we need to specify the initial and boundary conditions.
The given boundary conditions are,
1.Inlet: (Type patch)
The faces that contribute to inlet boundary are shown above. If we are looking at these faces from the outside, the definition of inlet boundary will be in counter-clockwise direction,
(0 11 14 3)
(3 14 16 5)
2.Outlet: (Type patch)
Similarly, we have 3 faces contributing to the outlet boundary condition. Since we are viewing the faces from outside, hence the definition of the outlet boundary will be in counter-clockwise direction,
(9 8 19 20)
(8 7 18 19)
(7 6 17 18)
Now for the other boundary look at the images below and repeat the steps to define the boundaries.
3.Front & Back: (Type empty)
(0 1 10 9 8 6 5)
(21 20 17 16 11 12)
4.No Slip walls: (Type wall)
(6 4 15 17)
(4 5 16 15)
(10 21 12 1)
(12 11 0 1)
(20 21 10 9)
After defining the boundaries correctly, to check if you have given defined them correctly, execute the blockMesh command in the terminal.Now open paraFoam, select all the patches and click apply. You will now be able to see the boundary conditions that have been applied to the geometry.
Case 1 - Simulate the flow without using any grading factor (i.e., GF = 1)
BlockMesh Dict File
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
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.2 0.01 0) //6
(0.2 0.005 0) //7
(0.2 0 0) //8
(0.2 -0.01 0) //9
(0.08 -0.01 0) //10
(0 0 0.1) //11
(0.08 0 0.1) //12
(0.08 0.005 0.1) //13
(0 0.005 0.1) //14
(0.08 0.01 0.1) //15
(0 0.01 0.1) //16
(0.2 0.01 0.1) //17
(0.2 0.005 0.1) //18
(0.2 0 0.1) //19
(0.2 -0.01 0.1) //20
(0.08 -0.01 0.1) //21
);
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 (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (1 1 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1 1 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1)
);
boundary
(
Inlet
{
type patch;
faces
(
(0 11 14 3)
(3 14 16 5)
);
}
Oulet
{
type patch;
faces
(
(9 8 19 20)
(8 7 18 19)
(7 6 17 18)
);
}
fixedWalls
{
type wall;
faces
(
(5 16 15 4)
(0 1 12 11)
(4 15 17 6)
(10 9 20 21)
(10 21 12 1)
);
}
frontAndBack
{
type empty;
faces
(
(11 12 13 14)
(14 13 15 16)
(13 18 17 15)
(12 19 18 13)
(21 20 19 12)
(0 3 2 1)
(3 5 4 2)
(2 4 6 7)
(1 2 7 8)
(10 1 8 9)
);
}
);
// ************************************************************************* //
Control Dict file
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 5;
deltaT 0.00001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Initial Conditions
Velocity
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
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);
}
Oulet
{
type zeroGradient;
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Pressure
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 10
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
Inlet
{
type zeroGradient;
}
Oulet
{
type fixedValue;
value uniform 0;
}
fixedWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Output in Paraview:
in the terminal type touch test.foam
open the test file , paraview opens click on apply and select surface with edges to display the mesh.

Velocity Distribution:

Pressure distribution

Case 2 - Simulate the flow with grading factor of 0.2. The cells should be finer near the walls (includig the step wall).
Graded Mesh

Velocity distribution

Desired output
Measure the velocity profile at 0.085 m from the inlet of the geometry for both case studies and compare. You can use the plot over line tool for this.
To generate the plot in paraview go to Filters> Data Analysis> Plot over Line> enter the coordinates and click on apply.
For Simple Graded mesh

For Graded mesh

Explain why Grading/Growth factor is essential for meshing.
The expansion ratio enables the mesh to be graded, or refined, in specified directions. The ratio is that of the width of the end cell
along one edge of a block to the width of the start cell
along that edge
It is essential since it allows us to refine the mesh at the desired locations thus saving the computational power and get the desired results.

