Week 8 - BlockMesh Drill down challenge
Aim:
To analyze and learn to use OpenFOAM and to solve the cavity problem for different grading factors and plot the velocity magnitude for the grading factor. To compare the velocity contour of the different grading factors.
Procedure:
- Install Ubuntu OS on the computer and install the OpenFOAM in it. It is very easy to use OpenFOAM in ubuntu then windows.
- Open the terminal and type 'tut' in the terminal it will direct it to tutorials of OpenFoam.Open the incompressible folder in the tutorial and then the IcoFoam folder by typing cd and name of the folder.
- Type 'ls' to view the contents in the folder. We can find the cavity folder.
- Copy that folder to run location of the OpenFOAM using the following command
- "cp -r cavity/ $FOAM_RUN/cavity"
- Now open the run directory using the command "cd $FOAM_RUN". List the contents using 'ls' command. Open the cavity folder and list the contents that will show the following
"0","Constant","system".
- Open the 0th folder, generally the initial condition of any problem stored in the 0th folder of that problem. Here the 0th folder contains the pressure and Velocity files.
- That means the pressure and velocity are the initial conditions of this problem.
- Edit the pressure and velocity files accordingly. To go back to the previous step we need to use the "cd .." command.
- Which will direct the cavity folder and open the system folder, in which we can find the blockMeshDict and ControlDict files.
- Make the necessary change blockMeshDict and ControlDict files by opening the notepad.
- Go to the previous directory and run the blockMesh Command.
- It will create the polyMesh folder in the constant.
- Run the solver by typing the name of the solver in the terminal.
- For this case"icoFoam"
- Once the simulation is completed. Open the paraFoam software by type it in the terminal.
- Finally, create the plot by using the "plot over line" command in the navigator box.
Code for the uniform grading:
1.BlockMeshDict file:
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 0 0.1) //4
(0.08 0 0.1) //5
(0.08 0.005 0.1) //6
(0 0.005 0.1) //7
(0 0.01 0) //8
(0.08 0.01 0) //9
(0 0.01 0.1) //10
(0.08 0.01 0.1) //11
(0.2 0.01 0.1) //12
(0.2 0.01 0) //13
(0.2 0.005 0) //14
(0.2 0.005 0.1) //15
(0.2 0 0.1) //16
(0.2 0 0) //17
(0.2 -0.01 0.1) //18
(0.2 -0.01 0) //19
(0.08 -0.01 0.1) //20
(0.08 -0.01 0) //21
);
blocks
(
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (1 1 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (1 1 1)
hex (2 14 13 9 6 15 12 11) (120 5 1)simpleGrading (1 1 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (1 1 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
(3 7 10 8)
);
}
outlet
{
type patch;
faces
(
(19 18 16 17)
(17 16 14 15)
(14 15 12 13)
);
}
Noslipwall
{
type wall;
faces
(
(11 10 8 9)
(12 11 9 13)
(18 20 21 19)
(1 21 20 5)
(5 1 0 4)
);
}
frontAndBack
{
type empty;
faces
(
(9 2 3 8) //1
(2 1 0 3) //2
(13 14 2 9) //3
(14 17 1 2) //4
(17 19 21 1) //5
(11 6 7 10) //6
(6 5 4 7) //7
(12 15 6 11) //8
(15 16 5 6) //9
(16 18 20 5) //10
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
2. Kinematic pressure
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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;
}
Noslipwall
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
3.Velocity file
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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;
}
Noslipwall
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
4.ControlDict file
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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.0001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Results for the uniform meshing in the block.
Mesh without grading:
Pressure Plot:
Velocity plot:
PLOT OVER LINE FOR THE MESH WITHOUT GRADING FOR VELOCITY:
PLOT OVER LINE FOR THE MESH WITHOUT GRADING FOR PRESSURE:
This plot gives the properties between the walls of the block we create for the simulation. The velocity plot shows that a gradual increase in the velocity for the boundary wall to the middle and a gradual decrease between the middle to the other boundary wall. This plot shows that our simulation is running correctly.
What are grading and the function of grading?
The grading factor is the special type of command used in the blockMesh Operation. The grading factor provides the better simulation results without actually increasing the mesh size. The advantage of the grading factor is to get better results by using the different sizes of the mesh elements without actually increase it. The grading factor is the ratio of the Last cell size to the first cell size. By doing the grading in mesh we can get the finer mesh in the required region and coarse mesh in the other regions.
In this part of the challenge, we need to get the Grading factor 0.2, 0.5, and 0.8.
This 3D plot of the blockMESH we are going to simulate in OpenFoam. Points in the figure are actually not used in my simulation. Actually, I have set different names for the points. In this simulation, the grading is not required in the z-direction. Block 1 and 2 has one face of each, which acts as the wall and inlet of the flow, so the grading for block 1&2 in the x-direction is not necessary. But in my case, I have given for the better observation of the flow.
This above plot gives the block 1 figure. In this lower faces is the wall, we have to find the mesh near the lower face of the block 1. To give that fine mesh we use the command
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (1 5 1) //Points may differ
Here, we want to give the grading ratio, in case the, if we give the 0.2 value it actually did the opposite thing that we want to do. Thereby giving the mesh grading for block 3 and the next step essential to do is give the grading for block 4. Because of the mesh consistency. Giving the grading in both directions for block 5. Apply the grading factor to all walls by calculating what we need to give. The following is for grading factor 0.2.
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (5 5 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (5 0.2 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (5 0.2 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (5 5 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (5 5 1)
The following are for grading factor 0.5
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (2 2 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (2 0.5 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (2 0.5 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (2 2 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (2 2 1)
The following is grading factor 0.8
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (1.25 1.25 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (1.25 0.8 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (1.25 0.8 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (1.25 1.25 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (1.25 1.25 1)
- After, we upgrade the grading factor. Next to run the blockMesh command.
- we need to define the deltaT (i.e., the time step for the simulation in the controlDict file). While defining the deltaT, we need to consider the courant's number(it should be less than one).
- The formula is given by `C=(dt*U)/dx`
- Where dx is cell distance and dt is the time step.
GradingFactor 0.2, 0.5, 0.8 as follow
Mesh for 0.2:
Mesh for 0.5:
Mesh for 0.8:
BLOCKMESHDICT FOR 0.2 GRADING FACTOR
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 0 0.1) //4
(0.08 0 0.1) //5
(0.08 0.005 0.1) //6
(0 0.005 0.1) //7
(0 0.01 0) //8
(0.08 0.01 0) //9
(0 0.01 0.1) //10
(0.08 0.01 0.1) //11
(0.2 0.01 0.1) //12
(0.2 0.01 0) //13
(0.2 0.005 0) //14
(0.2 0.005 0.1) //15
(0.2 0 0.1) //16
(0.2 0 0) //17
(0.2 -0.01 0.1) //18
(0.2 -0.01 0) //19
(0.08 -0.01 0.1) //20
(0.08 -0.01 0) //21
);
blocks
(
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (5 5 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (5 0.2 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (5 0.2 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (5 5 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (5 5 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
(3 7 10 8)
);
}
outlet
{
type patch;
faces
(
(19 18 16 17)
(17 16 14 15)
(14 15 12 13)
);
}
Noslipwall
{
type wall;
faces
(
(11 10 8 9)
(12 11 9 13)
(18 20 21 19)
(1 21 20 5)
(5 1 0 4)
);
}
frontAndBack
{
type empty;
faces
(
(9 2 3 8) //1
(2 1 0 3) //2
(13 14 2 9) //3
(14 17 1 2) //4
(17 19 21 1) //5
(11 6 7 10) //6
(6 5 4 7) //7
(12 15 6 11) //8
(15 16 5 6) //9
(16 18 20 5) //10
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
BLOCKMESHDICT FOR 0.5 GRADING FACTOR
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 0 0.1) //4
(0.08 0 0.1) //5
(0.08 0.005 0.1) //6
(0 0.005 0.1) //7
(0 0.01 0) //8
(0.08 0.01 0) //9
(0 0.01 0.1) //10
(0.08 0.01 0.1) //11
(0.2 0.01 0.1) //12
(0.2 0.01 0) //13
(0.2 0.005 0) //14
(0.2 0.005 0.1) //15
(0.2 0 0.1) //16
(0.2 0 0) //17
(0.2 -0.01 0.1) //18
(0.2 -0.01 0) //19
(0.08 -0.01 0.1) //20
(0.08 -0.01 0) //21
);
blocks
(
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (2 2 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (2 0.5 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (2 0.5 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (2 2 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (2 2 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
(3 7 10 8)
);
}
outlet
{
type patch;
faces
(
(19 18 16 17)
(17 16 14 15)
(14 15 12 13)
);
}
Noslipwall
{
type wall;
faces
(
(11 10 8 9)
(12 11 9 13)
(18 20 21 19)
(1 21 20 5)
(5 1 0 4)
);
}
frontAndBack
{
type empty;
faces
(
(9 2 3 8) //1
(2 1 0 3) //2
(13 14 2 9) //3
(14 17 1 2) //4
(17 19 21 1) //5
(11 6 7 10) //6
(6 5 4 7) //7
(12 15 6 11) //8
(15 16 5 6) //9
(16 18 20 5) //10
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
BLOCKMESHDICT FOR 0.8 GRADING FACTOR
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 7
\\/ 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 0 0.1) //4
(0.08 0 0.1) //5
(0.08 0.005 0.1) //6
(0 0.005 0.1) //7
(0 0.01 0) //8
(0.08 0.01 0) //9
(0 0.01 0.1) //10
(0.08 0.01 0.1) //11
(0.2 0.01 0.1) //12
(0.2 0.01 0) //13
(0.2 0.005 0) //14
(0.2 0.005 0.1) //15
(0.2 0 0.1) //16
(0.2 0 0) //17
(0.2 -0.01 0.1) //18
(0.2 -0.01 0) //19
(0.08 -0.01 0.1) //20
(0.08 -0.01 0) //21
);
blocks
(
hex (0 1 2 3 4 5 6 7) (80 5 1) simpleGrading (1.25 1.25 1)
hex (3 2 9 8 7 6 11 10) (80 5 1) simpleGrading (1.25 0.8 1)
hex (2 14 13 9 6 15 12 11) (120 5 1) simpleGrading (1.25 0.8 1)
hex (1 17 14 2 5 16 15 6) (120 5 1) simpleGrading (1.25 1.25 1)
hex (21 19 17 1 20 18 16 5) (120 10 1) simpleGrading (1.25 1.25 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
(3 7 10 8)
);
}
outlet
{
type patch;
faces
(
(19 18 16 17)
(17 16 14 15)
(14 15 12 13)
);
}
Noslipwall
{
type wall;
faces
(
(11 10 8 9)
(12 11 9 13)
(18 20 21 19)
(1 21 20 5)
(5 1 0 4)
);
}
frontAndBack
{
type empty;
faces
(
(9 2 3 8) //1
(2 1 0 3) //2
(13 14 2 9) //3
(14 17 1 2) //4
(17 19 21 1) //5
(11 6 7 10) //6
(6 5 4 7) //7
(12 15 6 11) //8
(15 16 5 6) //9
(16 18 20 5) //10
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
Pressure and velocity files:
Inlet and outlet are in type PATCH, a wall in z-plane is taken as EMPTY and all other wall is taken as "Noslipwall".The length of the x-axis is 200units, so it is divided into 200 cells and the same is done in the y-axis.
Pressure inlet is taken as ZeroGrandient at the inlet and at the fixed walls, and pressure outlet is open to the atmosphere.
Velocity at the inlet is taken as a fixed value (along the x-direction) and at the outlet is ZeroGradient.
Results and Discussion:
Plot Overline:
Plot over line command is used to give the properties along the lines we define.
Here, we want to get properties in the line at x=0.085m and parallel to y-axis between the -0.01 to 0.01, the variation is given by
PLOT 0.2 FOR PRESSURE AND VELOCITY:
Pressure Plot:
PLOT 0.5 FOR VELOCITY AND PRESSURE:
Pressure plot:
PLOT 0.8 FOR VELOCITY AND PRESSURE:
Pressure plot:
Comparing the above results, the 0.2 grading factor has captured more accurate results than the other two 0.5 and 0.8 because of the finer mesh near the walls. The velocity near the wall is low because of the boundary layer formation, due to the various factor like viscous force, etc., This is explained in detail in the following picture.
CONCLUSION:
- The velocity for all three gradings is almost `U=1.1m/s` at the distance of `x=0.085m`.
- The CFL Number also decreases with the decrease in the grading factor.
- As the step structure in the block, this decrease the flow velocity to a considerable amount.
- The velocity increase from the wall to the middle as the above show, this because of the viscous force and shear stress generation.
- The velocity at the wall is zero, because of the No-slip condition. The velocity is maximum at the middle of the block 4, it is confirmed by the plot.