Week 8 - Simulation of a backward facing step in OpenFOAM
Objective:-
- Open OpenFOAM tutorials and find the solver to solve incompressible-laminar-viscous flow problems.
- The next step is to copy the required file in the solver and paste it in the OpenFOAM run folder so that the official file of OpenFoam remains untouched.
- Find out the block mesh script file to create domain space and provide mesh specification.
- Find the ‘controlDict’ file to edit the start and end time for the simulation.
- In the initial folder ‘0’ edit the initial parameter for velocity and pressure according to the faces of the given domain.
- Use blockMesh command to generate mesh and checkMesh to verify it.
- Open the simulation file in ParaView and plot the velocity profile at point 0.085m from the inlet.
- Repeat the above procedure for grading factor 0.2 to check the differences in results.
- Write a detailed report explaining all the commands and codes used in a project.
Procedure:-
- First, we are creating the run folder in OpenFOAM in which we will be running our simulations.
- And then need to copy the cavity folder to the run folder so that we can make the changes in the blockMeshDict, controlDict, and pressure and velocity files as to run our required simulations, we copying the folder because we are not supposed to make any changes in the original folders in the OpenFOAM.
- Then will make the required changes in the blockMeshDict file that is naming the vertices for and then creating the blocks, in this case, there are 21 vertices and 5 blocks while creating blocks we also need to specify the number of mesh points needed along the x, y, and z-direction and also the simple grading should be done along the boundaries.
- then, we need to assign the boundary conditions here, we need to define all the faces in OpenFOAM refers to patches and giving them type that is the inlet and outlet will be the faces (type patch), for front and back type will be empty faces, for top and bottom which are the boundary conditions in this case type will be wall type and setting up these will constitute a particular boundary, then will save these changes in the blockMeshDict.
- Then, in the velocity and pressure files, we have to give the value of the velocity at the inlet type will be fixed value here we should assign some value as initial velocity and pressure will be zerogradient and at the outlet velocity type will be zerogradient and pressure will be type fixedvalue that value will be uniform 0, then at front and back velocity type empty and pressure, as well as type empty at the no slip boundaries that is top and bottom velocity, will be type noslip and pressure type empty. And in the transportProperties we can change the nu value in order to obtain the lower courant number.
- And in the controlDict file the simulation time and the time step need be assigned in the way that the courant number should be less than 0.5.
- and then creating the block mesh and then run the simulation using the respective solver after the completion of simulation open the paraview in the paraFoam and plot the velocity profile for the given value
Problem Statement:-
simulate an incompressible-laminar-viscous flow through the backward facing step geometry.
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 grading factor of 0.2. The cells should be finer near the walls (includig the step wall).
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.

Steps:
Step 1 In order to start the simulation process, First start the terminal in Linux Operating system using ctrl+alt+T buttons on keyboard or right-click -> Open Terminal. After starting terminal
Step 2 Now, we have to simulate our problem in OpenFOAM and we are going to solve our problem using tutorials present in OpenFOAM, therefore, just type ‘tut’ to open the OpenFOAM tutorial directory. And type ‘ls’ to identify what kind of tutorials are present inside this directory.
Step 3 We have to solve incompressible flow simulation for this problem so select the incompressible directory by typing ‘cd incompressible’ and then again type ls to explore folders in incompressible folders.
Step 4 we can see the plethora of solver folders. For this particular solver, we need a solver for laminar-viscous flow. So here we choose ‘icoFoam’
icoFoam is the solver in OpenFOAM which is used as a transient solver for incompressible, laminar flow of Newtonian fluids.
(Newtonian fluid is a fluid in which the viscous stress arising from its flow, at every point, is linearly correlated to the local strain rate - the rate of change of its deformation over time. Newtonian fluids are the simplest mathematical models of fluids that account for viscosity.)
Therefore, we will select the icoFoam folder by typing ‘cd icoFoam’ and by typing ‘ls’ we explore this folder in the terminal.
Step 5 Here, we have, again option, cavity and elbow. They both are part of the icoFoam solver and cavity section used to create a required domain and block mesh so select the ‘cavity’ folder.
Step 6 In the cavity, we are, again, going to see the 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 the tutorial section. First of all, OpenFoam does no let anyone make any changes in their official tutorial, and secondly, any changes to their official tutorials may corrupt OpenFOAM. In a bid to correct it, we may need to reinstall open foam all over again.
So, we are going to copy this cavity folder using the ‘cp -r cavity’ command and paste it in OpenFOAM run folder by typing ‘cp -r cavity $FOAM_RUN/cavity_test’.
And then open the run folder by typing ‘cd $FOAM_RUN’. where we can see the cavity_test file.
Step 7 Now, we can make any changes to the cavity_test file, which will never affect the OpenFOAM official files. Open the cavity_test folder. Here, we can provide specifications for our block mesh in the system folder.
Step 8 there is 4 script file system folder and by opening blockMeshDict, we can create a domain and provide a required specification for block mesh. So, open this file by typing ‘gedit blockMeshDict’.

Now, make the following changes in the blockMeshDict script file.
The blockMeshDict file is a script file that contains information regarding all aspects of the geometry.
When we open this file, first, we are going to see header information in the form of a comment which is not executable.
Then, we will see the file identifier by which openFoam reads to understand the type of file reading in this case it is ‘blockMeshDict’. it contains information in the dictionary format, means, key, and value format. As we can see, version is the key and ‘2.0’ is its value, that’s why it's called key-value pair. And here we don’t have to make any changes, so we keep it as it is. Next,
we set units in meters, by converting all types of lengths into meters.
convertToMeters 0.01;
Mesh generation without any grading factor
In the same blockMesh file go to the lines where we 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 the X, Y and Z directions.

The next step is to navigate to the controlDict folder and specify the simulation time as 200 seconds.The script file looks as follows.
Vertices:-
Afterward, in codes, we provide list of vertices by providing x,y,and z coordinates locations; its always start from vertex (0,0,0). so we have to create following geometry.

To create the above geometry, let us consider creating the geometry using 5 blocks as exhibited in below figure.

Now, we are going to provide vertices for each block by referring following sketch.

Next, we are going to define block for meshing. If we look at he mesh format first letter, in block parenthesis, is ‘hex’ which define type of mesh which is hexahedral mesh.
Then, again in parenthesis, we provide vertices number according to order which follow right hand thumb rule, meaning, thumb is the z axis and order of vertices follow rotational order of our other finger.
Then comes, number of mesh grid that we want to divide along x, y, and z length. We define it as (nx,ny,nz) format.
Given mesh specification:
- Number of cells along the x direction(longer dimension) = 200
- Number of cells along the longer y direction = 20
Lastly, we give simple grading which is cell expansion ratios
Grading factor or expansion ratios:-
The expansion ratios enables the mesh to be graded, or refined, in specified directions. The ratio is that of the width of the end cell `δ_e` along one edge of a block to the width of the start cell `δ_ s` along the edge as shown in below figure.

In a simple format,
Expansion ratio = (size of end cell) / (size of starting cell)
The simple description specifies uniform expansion in the local `x_1,x_2 and x_3` directions respectively with only a 3 expansion ratio. For the first case, we are not going to provide any grading for our problem.
So here, we have 5 blocks so we have to define hex mesh for 5 blocks.
Next, define the boundary of the problem, in this, we have to define faces of the our 3d block this should be in order according to the right-hand thumb rule. So set faces for this problem following way.
CODE:
BLOCKMESHDICT :
blockMeshDict: (for Gradient factor of 1)
/*--------------------------------*- 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 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.1)
(8 0 0.1)
(8 0.5 0.1)
(0 0.5 0.1)
(8 1 0.1)
(0 1 0.1)
(20 1 0.1)
(20 0.5 0.1)
(20 0 0.1)
(20 -1 0.1)
(8 -1 0.1)
);
blocks
(
hex (0 1 2 3 11 12 13 14) (50 5 1) simpleGrading (1 1 1)
hex (3 2 4 5 14 13 15 16) (50 5 1) simpleGrading (1 1 1)
hex (2 7 6 4 13 18 17 15) (150 5 1) simpleGrading (1 1 1)
hex (1 8 7 2 12 19 18 13) (150 5 1) simpleGrading (1 1 1)
hex (10 9 8 1 21 20 19 12) (150 5 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)
);
}
fixedWalls
{
type Wall;
faces
(
(4 5 16 15)
(6 4 15 17)
(0 1 12 11)
(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)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
blockMeshDict: (for Gradient factor of 0.2)
/*--------------------------------*- 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 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.1)
(8 0 0.1)
(8 0.5 0.1)
(0 0.5 0.1)
(8 1 0.1)
(0 1 0.1)
(20 1 0.1)
(20 0.5 0.1)
(20 0 0.1)
(20 -1 0.1)
(8 -1 0.1)
);
blocks
(
hex (0 1 2 3 11 12 13 14) (50 5 1) simpleGrading (0.2 0.2 1)
hex (3 2 4 5 14 13 15 16) (50 5 1) simpleGrading (0.2 0.2 1)
hex (2 7 6 4 13 18 17 15) (150 5 1) simpleGrading (5 0.2 1)
hex (1 8 7 2 12 19 18 13) (150 5 1) simpleGrading (5 0.2 1)
hex (10 9 8 1 21 20 19 12) (150 5 1) simpleGrading (5 0.2 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)
);
}
fixedWalls
{
type Wall;
faces
(
(4 5 16 15)
(6 4 15 17)
(0 1 12 11)
(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)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
After, editing of blockMeshDic file save it and close it.
Furthermore, we are going to edit the ‘controlDict’ file to provide time limits - start time and end time. Also to represent deltat. While the selection of deltat CFL value should be less than 1. otherwise, the solution could be stopped forcibly or it may diverge at the time of converging. So make the following changes in the ‘controlDict’ file.
ControlDict 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 0.5;
deltaT 0.0001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
After, editing of controlDict file save it and close it. Then, we have to go back to the cavity_test directory using the ‘cd ..’ command and select the folder named ‘constant’, which stands for the physicalproperties file.
update [0 2 -1 0 0 0 0] 1e-5;
Physicalproperties 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 "constant";
object physicalProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 1e-5;
// ************************************************************************* //
After, editing of physicalProperties file save it and close it. Then, we have to define the initial value for pressure and velocity. In order to do that, we have to go back to the cavity_test directory using the ‘cd ..’ command and select the folder named ‘0’, which stands for initial values. In this case initial value for pressure and velocity. In this case, we have to set the initial boundary conditions for pressure and velocity at each face and also update the name of the boundary same as we changed the inlet-outlet name in the ‘blockMeshDict’ script file
Pressure (p) 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 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;
}
}
// ************************************************************************* //
Velocity (U) 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 volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
inlet
{
type fixedValue;
value uniform (40 0 0);
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
outlet
{
type zeroGradient;
}
}
// ************************************************************************* //
blockMesh

CheckMesh

After checking the mesh we get the following confirmation At this stage, we can check whether our mesh is as per requirement or not by using ParaView and typing the paraFoam command.
IcoFoam

After deploying mesh, now we are ready to run the simulation. The simulation that we selected was icoFoam. Hence, just type ‘icoFoam’ and the simulation will start.
Results:
From Grading Factor 1
Mesh grid:-

Velocity Distribution along the domain area:-

Plot of variation of velocity: at a distance 0.085m with GF =1

Results:
From Grading Factor 0.2
Mesh grid:-

Velocity Distribution along the domain area:-

Plot of variation of velocity: at a distance 0.085m with GF =0.2

Conclusion:
By changing the simple grading factor from the value of 0.2 to 1 the mesh becomes finer and the solution becomes very accurate.
Overall the change in the size of the simple grading factor (mesh size) the results remain the same as approximately.
The execution time is lower for a lower meshing grading factor.