Simulation of laminar flow over a Backward Facing Step using the icoFoam solver in OpenFOAM to show the effect of different Mesh Grading Factor on the Boundary Layer Separation
SIMULATION OF LAMINAR FLOW OVER A BACKWARD FACING STEP USING THE icoFoam SOLVER IN OpenFOAM TO SHOW THE EFFECT OF DIFFERENT MESH GRADING FACTOR ON THE SOLUTION
PROBLEM SPECIFICATION:
Problem Statement: By using the icoFoam solver in OpenFOAM, simulate the flow through a Backward Facing Step, and compare the results for different mesh grading factor. The geometry profile (dimensions are in meter, ‘m’) and boundary condition are shown below,
Mesh Specification:
- Number of cells along the x-direction (longer dimension)=200
- Number of cells along the y-direction=10
- Use a graded mesh
Desired Output:
- How does the velocity magnitude profile changes as a function of mesh grading factor? Use factors: 0.2, 0.5, 0.8
- Measure the velocity profile at 0.085m from the inlet of the geometry
- The plot must be a line plot
- Compare the velocity magnitude contours near the step region for the above-mentioned grading factors.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
THEORY:
This project investigates the effect of mesh grading factor in the simulation of flow over a backward face step. We perform the necessary simulations for this study using icoFoam solver in OpenFOAM and post-processed in ParaView. In this work, we have taken different grading factors as the element size near walls has a significant effect on the accuracy of the solution. Fine mesh near the walls could improve the accuracy of results, but on the same hand, it increases the computational time required to do the simulation. Coarse mesh leads to inconsistent results and can cause convergence problems during the simulation process. However, the time required to complete the simulation is less due to the coarse meshing. So, for both finer or coarser mesh, there are some advantages and disadvantages. Here comes the role of mesh grading factor, which helps by allocating finer mesh near-wall regions or the regions where the most prominent changes w.r.t. flow parameters are going on; without sacrificing with the results. Also, the time required to complete the simulation will be less.
The grading factor is given as the ratio of the size of the end cell to the size of the starting cell. It basically refers to the technique called ‘mesh stretching’. In this technique, the mesh is stretched to one side of the wall and is very helpful for computing efficiency.
Grading factor, `f=`(size of the end cell)/(size of the starting cell)
For example, if we choose the grading factor, `f=1`; then it means that the size of the end cell is equal to the size of the starting cell.
To find out the effect of different mesh grading factors on the solution; we’ll measure and plot the velocity magnitude profile at a distance of 0.085m from the inlet of the geometry. Also, we’ll compare the velocity magnitude and pressure gradient contours near the step region for different grading factors, namely; 0.2, 0.5, 0.8, and 1.
SIMULATION STEPS:
- Open the ‘terminal’ window in any Linux operating system (here we’re using ubuntu).
- Type ‘tut’ which will direct to the inbuilt tutorial directory in OpenFOAM.
- Type ‘ls’ (list) to view the contents in the tutorials directory. Among the list of contents, we need to choose ‘incompressible’. To get into ‘incompressible’ directory type ‘cd incompressible’.
- Type ‘ls’ (list) to see the solvers inside the incompressible directory. Among the solvers displayed we need to select ‘icoFoam’ solver for this challenge.
- By typing ‘ls’ (list) we can see the directory inside the icoFoam solver. We have to select the ‘cavity’ directory. Type ‘cd cavity’ to get into the cavity directory.
- Type ‘ls’ (list) to view the files inside the cavity directory. We will find another directory with the name of the ‘cavity’. To edit and run our simulation, we need to copy this ‘tutorial’ to $FOAM_RUN directory.
- To copy, type ‘cd –r cavity/ $FOAM_RUN/backward_facing_step_project’. This command copies the cavity files and pastes in the run directory. ‘$FOAM_RUN’ is the directory that OpenFOAM used to run and save the simulations and that is where we are running our simulation. Here, I have renamed the cavity file as ‘backward_facing_step_project’.
- To get into the run directory, type the command ‘run’; which will take you inside the run directory. Further, type ‘ls’ (list) to see the files inside the run folder and we will see the ‘backward_facing_step_project’ file also.
- Type ‘cd backward_facing_step_project’ to get inside the ‘backward_facing_step_project’ directory. Further type ‘ls’ to see the files inside this directory.
- We can see files like ‘0’,’blockMeshDict’, ‘controlDict’, ‘fvschemes’, ‘fvSolution’. We need to edit these files according to our problem specification.
- First, we will start editing the ‘blockMeshDict’ file. To edit this file, type ‘gedit blockMeshDict’, which will open the text editor window. Here we have to specify geometry, meshing, and boundary conditions for our problem. We’ll start with mesh grading factor, `f=1`.
- In the same manner, we have to edit the ‘controlDict’ file and provide the values like start time, end time, delta t, time interval, etc. The value of ‘delta t’ should be chosen in such a way that the Courant number should be less than 1.
- After editing both the files come back to our ‘backward_facing_step_project’ directory. Now we have to go inside the ‘0’ directory by typing ‘cd 0’ (which is our initial conditions directory). We will find ‘p’ and ‘U’ text files; we need to edit them according to our problem and save them.
- For this problem as a fluid we're choosing air; we have to edit 'transportProperties' file inside the 'constant' directory.
- After completion of all the editing part for our problem, we need to get back to the ‘backward_facing_step_project’ directory and type ‘blockMesh’ to get the desired geometry with mesh and boundary conditions. To check our mesh for any errors, we can type ‘checkMesh’ command.
- If the ‘checkMesh’ command runs with no error then we can confirm that mesh is good and stable.
- Since we’re using ‘icoFoam’ solver for this problem; to run the simulation we have to just type the ‘icoFoam’.
- After the completion of simulation, type ‘paraFoam’ to launch ParaView for post-processing.
- Measure the velocity profile at 0.085m from the inlet of geometry. We get the plot for velocity by using the ‘plot over line’ option, which can be found in the ‘filters’.
- Repeat the above steps for other grading factors such as 0.2, 0.5, and 0.8.
- After having all the line plots and velocity magnitude contours for the different grading factors; we can easily compare the results and locate the differences.
Program for ‘blockMeshDict’: (mesh 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 0.01;
vertices
(
(0 0 0) //vertex 0
(8 0 0) //vertex 1
(8 0.5 0) //vertex 2
(0 0.5 0) //vertex 3
(8 1 0) //vertex 4
(0 1 0) //vertex 5
(20 1 0) //vertex 6
(20 0.5 0) //vertex 7
(20 0 0) //vertex 8
(20 -1 0) //vertex 9
(8 -1 0) //vertex 10
(0 0 0.1) //vertex 11
(8 0 0.1) //vertex 12
(8 0.5 0.1) //vertex 13
(0 0.5 0.1) //vertex 14
(8 1 0.1) //vertex 15
(0 1 0.1) //vertex 16
(20 1 0.1) //vertex 17
(20 0.5 0.1) //vertex 18
(20 0 0.1) //vertex 19
(20 -1 0.1) //vertex 20
(8 -1 0.1) //vertex 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 (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1 1 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1 1 1)
hex (10 9 8 1 21 20 19 12) (120 10 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)
(3 5 4 2)
(2 4 6 7)
(1 2 7 8)
(10 1 8 9)
(11 12 13 14)
(14 13 15 16)
(13 18 17 15)
(12 19 18 13)
(21 20 19 12)
);
}
NoSlipWalls
{
type wall;
faces
(
(16 15 4 5)
(15 17 6 4)
(10 21 12 1)
(11 0 1 12)
(21 10 9 20)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
NOTE: All the coding will be the same as the above program for ‘blockMeshDict’ except ‘simpleGrading’ part; where we apply different grading factors (0.8, 0.5, and 0.2, respectively).
Program for ‘blockMeshDict’: (mesh grading factor=0.8)
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.8 1.25 1)
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.8 0.8 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (1.25 0.8 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (1.25 1.25 1)
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (1.25 1.25 1)
);
Program for ‘blockMeshDict’: (mesh grading factor=0.5)
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.5 2 1)
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.5 0.5 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (2 0.5 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (2 2 1)
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (2 2 1)
);
Program for ‘blockMeshDict’: (mesh grading factor=0.2)
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.2 5 1)
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.2 0.2 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (5 0.2 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (5 5 1)
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (5 5 1)
);
Program for ‘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 0.5;
deltaT 1e-04;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Program for ‘0’: (Initial conditions at time, t=0)
Pressure, p:
/*--------------------------------*- 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;
}
NoSlipWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Velocity, U:
/*--------------------------------*- 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;
}
NoSlipWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Program for 'transportProperties': kinematic viscosity of air (`nu=1.81e-05`) has been chosen as a fluid
/*--------------------------------*- 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] 1.81e-05;
// ************************************************************************* //
RESULTS & DISCUSSIONS:
Plots and Contours: Grading Factor=1
Plots and Contours: Grading Factor=0.8
Plots and Contours: Grading Factor=0.5
Plots and Contours: Grading Factor=0.2
CONCLUSION:
We can not observe much difference in plots and contours at first glance, but as we dive deeper; it is noticeable that as the mesh grading factor decreases (mesh is getting finer) it exhibits a better boundary layer separation. This is because as the mesh becomes finer–more data is captured–resulting in more detailed and accurate results. The details of the flow within the boundary layer are very important for many problems. That's why it is advisable to have a lower mesh grading factor (finer mesh) at the areas of importance (for e.g.- areas near the surface of an object).