Week 8 - Simulation of a backward facing step in OpenFOAM
# blockMeshDict in garding factor 0.2
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ 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.01) //11
(0.08 0 0.01) //12
(0.08 0.005 0.01) //13
(0 0.005 0.01) //14
(0.08 0.01 0.01) //15
(0 0.01 0.01) //16
(0.2 0.01 0.01) //17
(0.2 0.005 0.01) //18
(0.2 0 0.01) //19
(0.2 -0.01 0.01) //20
(0.08 -0.01 0.01) //21
);
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)
);
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
(
(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)
);
}
fixedWall
{
type wall;
faces
(
(5 16 15 4)
(0 1 12 11)
(4 15 17 6)
(10 9 20 21)
(10 21 12 1)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
# PRESSURE ( p )
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ 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;
}
fixedWall
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
In order to start the simulation process, First start terminal in Linux Operating system using ctrl+Alt+T button on the keyboard/right click > open terminal.
Now, we have to simulate our problem in OpenFOAM and we are going to solve our problem using tutorial present in openFOAM , so type 'tut' to open OpenFOAM tutorial directory. And type 'ls' to identify what kind of tutorial present inside the directory.
In the next line we can see number of solver , but we need to solve for incompressible flow simulation for this problem so i selected incompressible directry by typing 'cd incompressible' and again type 'ls' to explore folders in incompressible folders.
For the particular solver we need solver for laminar-viscous flow.so we choose 'icoFoam'. 'icoFoam is the solver in which openFoam which is use as transient solver for incompressible,laminar of Newtonian fluids.
Therefore i select icoFoam folder by typing 'cd icoFoam' and by typing 'ls' explore this folder in terminal.
So..Here we have two option cavity and elbow. i was select 'cavity' folder. 'cavity' use to create domain and black mesh.
In cavity, i am going to see cavity folder , where i have to define our fluid domain and generate block mesh.
but here i am not going to make any changes here in particular section. Firstly, OpenFoam does not let anyone make any changes in their official tutorial and secondly,any changes with their official tutorials corrupt OpenFoam. An in a bid to correct it, we may need to reinstall the openfoam all over again.
So, i am 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 open run folder by typing 'cd $Foam_Run'. where we can see that cavity_test file.
Now, we can make any changes to the cavity_test , which will never affect the OpenFoam official files.
There are 4 script file under the cavity_test folder any by opening blockMeshDict we can create domain and provide required specification for block mesh. So, open this file by typing 'gedit blockMeshDict'.
The blockMeshDict file is a script file that contain
information regarding all aspects of the geometry.
In this file 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 X,Y and Z direction.
Also we specify the faces as the inlet ,outlet, fixedwall and frontAndback.
The next step is to specify the simulation time as 0.5
Afterward,in codes,we provide list of vertices by providing x,y and z coordinates locations; its always starts from vertex (0,0,0) .
Next, i am going to define block for meshing , 'hex' which define type of mesh which is hexahedral mesh.
Then, again in paranthesis, we provide vertices number according to order which follows right hand thumb rule.
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.
Now, we have to define initial value for pressure and velocity. In order to do that , we have to go back in cavity_text directory using 'cd .. ' command and select folder name 'o' which stands for initial values . In this case initial values are pressure and velocity .
In this case i have to set initial boundary ccondition for pressure and velocity at each faces also update the name of the boundary same as we changed inlet outlet name in'blockMeshDict' script file.
Now, we can proceed to deploy mesh using 'blockMesh' command and then use 'checkMesh' command to check if there is any error in our mesh.
At this stage , we can check our mesh by using 'paraView' typing paraFoam command.
Conclusion - By changing the simple grading factor from value of 0.2 to 1 the mesh become finer and solution become very accurate.
Overall the change in the size of the simple grading factor (mesh size) the results remain the same as approximation. The execution time is lower for lower meshing grading factor.
# VELOCITY ( U )
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ 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);
}
outlet
{
type zeroGradient;
}
fixedWall
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
# blockMeshDict in grading factor 1
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ 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.01) //11
(0.08 0 0.01) //12
(0.08 0.005 0.01) //13
(0 0.005 0.01) //14
(0.08 0.01 0.01) //15
(0 0.01 0.01) //16
(0.2 0.01 0.01) //17
(0.2 0.005 0.01) //18
(0.2 0 0.01) //19
(0.2 -0.01 0.01) //20
(0.08 -0.01 0.01) //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
(
(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)
);
}
fixedWall
{
type wall;
faces
(
(5 16 15 4)
(0 1 12 11)
(4 15 17 6)
(10 9 20 21)
(10 21 12 1)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
# ControlDict
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //