Week 8 - Simulation of a backward facing step in OpenFOAM
SIMULATION OF A BACKWARD-FACING STEP IN OpenFOAM
Case - 1:- Simulate the flow without using any grading factor
Case - 2:- Simulate the flow with a grading factor of 0.2
Mesh Specification:-
Number of cells along the x-direction = 200
Number of cells along with the y-direction = 20
Desired Output:-
- Measure the velocity profile at 0.085m from the inlet of the Geometry for both case studies and compare.
- Explain why the Grading/Growth factor is essential for Meshing.
Case-1(without any grading factor):-
1. Selection of Solver
For the Incompressible Laminar-Flow-Viscous, the 'icoFoam' solver is selected. The icoFoam used as the Transient solver for incompressible, laminar flow of Newtonian fluids.
2. Copy the 'cavity' file from the Tutorial directory to the Run directory
- Open a new terminal.
- Enter 'tut' command to navigate the tutorial directory.
- cp -r incompressible/icoFoam/cavity/ $FOAM_RUN/cavity_test
- And enter 'cd $FOAM_RUN' to navigate the Run folder.
3. Splitting the geometry into 5 blocks.


4. Edit the blockMeshDict file for the geometry.
/*--------------------------------*- 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) //0
(8 0 0) //1
(8 0.5 0) //2
(0 0.5 0) //3
(0 1 0) //4
(8 1 0) //5
(20 1 0) //6
(20 0.5 0) //7
(20 0 0 ) //8
(20 -1 0) //9
(8 -1 0) //10
(0 0 0.1) //11
(8 0 0.1) //12
(8 0.5 0.1) //13
(0 0.5 0.1) //14
(0 1 0.1) //15
(8 1 0.1) //16
(20 1 0.1) //17
(20 0.5 0.1) //18
(20 0 0.1) //19
(20 -1 0.1) //20
(8 -1 0.1) //21
);
blocks
(
hex (0 1 2 3 11 12 13 14) (80 10 1) simpleGrading (1 1 1) //block 1
hex (3 2 5 4 14 13 16 15) (80 10 1) simpleGrading (1 1 1) //block 2
hex (2 7 6 5 13 18 17 16) (120 10 1) simpleGrading (1 1 1) //block 3
hex (1 8 7 2 12 19 18 13) (120 10 1) simpleGrading (1 1 1) //block 4
hex (10 9 8 1 21 20 19 12) (120 20 1) simpleGrading (1 1 1) //block 5
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 11 14 3)
(3 14 15 4)
);
}
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 4 5 2)
(2 5 6 7)
(1 2 7 8)
(10 1 8 9)
(11 12 13 14)
(14 13 16 15)
(13 18 17 16)
(12 19 18 13)
(21 20 19 12)
);
}
NoSlipWalls
{
type wall;
faces
(
(16 5 4 15)
(17 6 5 16)
(0 1 12 11)
(1 10 21 12)
(10 9 20 21)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
- Define the block by vertex label and the number of cells within it. The Hexahedron cell type is used in the simulation.
- And enter the boundary condition for inlet, outlet, frontAndBack, and NoSlipWalls in the directory.
- The Mesh is generated by running blockMesh on this blockMeshDict file.
5. Editing the 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.2;
deltaT 0.0001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
In this file, the endTime and deltaT should be changed as
endTime = 0.2;
deltaT = 0.0001;
6. Editing the 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;
}
NoSlipWalls
{
type zeroGradient;
}
}
// ************************************************************************* //
- The inlet and NoslipWalls are zerogradient. Because there is no pressure in the inlet and NoSlipwalls.
- The frontAndBack type is empty.
- The Outlet is the fixed value
7. Editing the Velocity(U) 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 (1 0 0);
}
outlet
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
NoSlipWalls
{
type fixedValue;
value uniform (0 0 0);
}
}
// ************************************************************************* //
In the velocity boundary field,
- The inlet type is fixedvalue and u=1 m/s through the x-axis. The y- axis and z-axis are zero. so, it defines as (1 0 0)
- The Outlet type is zerogradient because the velocity at an outlet is zero.
- And the frontAndBack type is empty same as the pressure.
- The NoSlipWalls type is fixedvalue. On all the axis the noslip is zero(0 0 0) because on the walls there is no velocity on the boundary.
8. transportProperties file in the control directory:-
/*--------------------------------*- 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] 0.000001002;
// ************************************************************************* //
- In the file, the nu value indicates the Kinematic viscosity of the Fluid.
- For the water, at 20°C the Kinematic viscosity is 0.000001002 `m^2/s`.
9. Run the Simulation:-
After entering all the values for the geometry run the simulation by entering the solver name 'icoFoam' to start the simulation. And check the mesh is uniform in paraview by entering the command in terminal 'paraFoam'.
MeshGrid;

10. Plotted Graph:-
- Velocity Distribution

- Pressure Distribution

- Velocity Profile

Case 2(Grading factor 0.2):-
With the Grading Factor, the geometry of each block cell should be graded for meshing.
Grading Factor = Width of the end cell / Width of the Start cell
The simpleGrading should be calculated on the x-axis and y-axis for the given geometry.
blocks
(
hex (0 1 2 3 11 12 13 14) (80 10 1) simpleGrading (0.2 0.2 1) //block 1
hex (3 2 5 4 14 13 16 15) (80 10 1) simpleGrading (0.2 5 1) //block 2
hex (2 7 6 5 13 18 17 16) (120 10 1) simpleGrading (5 5 1) //block 3
hex (1 8 7 2 12 19 18 13) (120 10 1) simpleGrading (5 0.2 1) //block 4
hex (10 9 8 1 21 20 19 12) (120 20 1) simpleGrading (5 5 1) //block 5
);
To check the Meshing in paraview by entering the command in terminal 'paraFoam'.
MeshGrid;
For this case, the only simplegrading is changed in the blockMeshDict file and the other file are the same as in the above case 1.
1. blockMeshDict 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;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.01;
vertices
(
(0 0 0) //0
(8 0 0) //1
(8 0.5 0) //2
(0 0.5 0) //3
(0 1 0) //4
(8 1 0) //5
(20 1 0) //6
(20 0.5 0) //7
(20 0 0 ) //8
(20 -1 0) //9
(8 -1 0) //10
(0 0 0.1) //11
(8 0 0.1) //12
(8 0.5 0.1) //13
(0 0.5 0.1) //14
(0 1 0.1) //15
(8 1 0.1) //16
(20 1 0.1) //17
(20 0.5 0.1) //18
(20 0 0.1) //19
(20 -1 0.1) //20
(8 -1 0.1) //21
);
blocks
(
hex (0 1 2 3 11 12 13 14) (80 10 1) simpleGrading (0.2 0.2 1) //block 1
hex (3 2 5 4 14 13 16 15) (80 10 1) simpleGrading (0.2 5 1) //block 2
hex (2 7 6 5 13 18 17 16) (120 10 1) simpleGrading (5 5 1) //block 3
hex (1 8 7 2 12 19 18 13) (120 10 1) simpleGrading (5 0.2 1) //block 4
hex (10 9 8 1 21 20 19 12) (120 20 1) simpleGrading (5 5 1) //block 5
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 11 14 3)
(3 14 15 4)
);
}
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 4 5 2)
(2 5 6 7)
(1 2 7 8)
(10 1 8 9)
(11 12 13 14)
(14 13 16 15)
(13 18 17 16)
(12 19 18 13)
(21 20 19 12)
);
}
NoSlipWalls
{
type wall;
faces
(
(16 5 4 15)
(17 6 5 16)
(0 1 12 11)
(1 10 21 12)
(10 9 20 21)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
2. 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.2;
deltaT 0.0001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
3. Pressure(p) 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;
}
NoSlipWalls
{
type zeroGradient;
}
}
// ************************************************************************* //
4. Velocity(u) 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 (1 0 0);
}
outlet
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
NoSlipWalls
{
type fixedValue;
value uniform (0 0 0);
}
}
// ************************************************************************* //
5. transportProperties 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 "constant";
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu [0 2 -1 0 0 0 0] 0.000001002;
// ************************************************************************* //
6. Run the Simulation:-
- To check the Meshing by entering the command in terminal 'checkMesh'.
- To run the simulation by entering the solver name 'icoFoam' to start the simulation. And check the mesh is uniform in paraview by entering the command in terminal 'paraFoam'.
MeshGrid;

7. Plotted Graph:-
- Velocity Distribution

- Pressure Distribution

- Velocity Profile

Conclusion:-
Case - 1 Case - 2


- A smaller grading factor produces a more accurate uniform mesh.
- From the plotted graph, the velocity profile for case-2 is more accurate than case-1. In both the graphs, the velocity decrease at the point of 0.014. But the case-2 reaches the point at 0.9m/s and case-1 reaches the point at 1.2m/s.
- The case-2 reaches the point faster than the other because of the grading factor.
- So we can conclude that when the grading factor decrease, the mesh becomes finer and get a velocity profile good and less in time.