Week 8 - Simulation of a backward facing step in OpenFOAM
In this challenge, the main objective is to make a mesh of flowing fluid which is flowing from backward facing step geometry of given dimensions and to simulate some parameters like velocity and pressure of fluid inside the geometry.
When the laminar viscous flow enters in the geometry, it has a step, due to this, the fluid gets disturbed and get into turbulent form for some time and again when the geometry further becomes straight at bottom,the flow reattaches and achieves laminar viscous flow.
In openfoam,we have to perform three processes
Mesh generation
Simulation
Post processing.
We know that, in implicit schemes,we can take larger time steps.
In explicit scheme, we take smaller time steps.
open Foam prefers explicit scheme for unsteady problems and for steady state equations it refers implicit schemes.
Our problem comes under the category of unsteady problem because the flow is incompressible and also viscous. So we are going to use incompressible directory.
Icofoam has the time-dependent incompressible navier Stokes equation.
This equation defines or governs the flow flowing from backward facing straight geometry.
Given inputs
Number of cell along x direction is 200
Number of cells along y direction is 20
Mesh grading factor near the walls 0.2 in case 2.
Number of cells along z direction 1
Time step(delta t) = 0.00001 s(this time step keeps the courant number less than 1 which is mandatory for explicit scheme)
Inlet velocity = 0.5
Simulation time =0.5 s
Case setup
Open the terminal window.
Type ls(listing the folders),then it will show openfoam folder.
Type cd openfoam
Type 'cd $FOAM_TUTORIALS' and then ls,
So it will take into the tutorials folder of openfoam where there are subdirectories.
Type cd incompressible and then ls.
In incompressible directory,there will be solver folders like icofoam,pisofoam,porousSimplefoam and many more such solver folders.
'Type cd icoFoam' then ls
In this, two directories,cavity and flange exists.
copy the cavity directory into run folder
by typing 'cp -r/ $FOAM_RUN'
(Note -the simulation will execute only in run folder)
type cd $FOAM_RUN
Then type 'cd cavity' and ls
It will show the all run, allscript cavityclipped cavitygrade constant system
Type 'cd 0' then ls.
Set the pressure and velocity conditions.
Type 'cd .. ' to come one step back in the cavity folder.
Type 'cd system'
Edit the blockmeshDict,controlDict according to the given problem dimensions.
Come back to cavity folder and type 'blockMesh
Then type 'icoFoam'
Then type 'paraFoam'.
CASE 1
Main code(in this code,the mesh grading factor for x and y axis is 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) //0
(8 0 0) //1
(8 0.5 0) //2
(0 0.5 0) //3
(8 1 0) //4
(0 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
(8 1 0.1) //15
(0 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) (40 10 1) simpleGrading (1 1 1)
hex (3 2 4 5 14 13 15 16) (40 10 1) simpleGrading (1 1 1)
hex (2 7 6 4 13 18 17 15) (40 10 1) simpleGrading (1 1 1)
hex (1 8 7 2 12 19 18 13) (40 10 1) simpleGrading (1 1 1)
hex (10 9 8 1 21 20 19 12) (40 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)
);
}
noSlipWall
{
type wall;
faces
(
(5 16 15 4)
(4 15 17 6)
(0 1 12 11)
(10 21 12 1)
(10 9 20 21)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(3 5 4 2)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
(11 12 13 14)
(14 13 15 16)
(21 20 19 12)
(12 19 18 13)
(13 18 17 15)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
Controldict code (the code of for giving delta t)
/*--------------------------------*- 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 0.00001;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //
Boundary conditons
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;
}
noSlipWall
{
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 (0.5 0 0);
}
outlet
{
type zeroGradient;
}
noSlipWall
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Courant number stability

Basic executation at starting(i.e after giving the parafoam command)

Pressure simulation

Velocity simulation

Pressure plot over line

Velocity plot over line

CASE 2
Main code for finer mesh near the walls.
/*--------------------------------*- 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
(8 1 0) //4
(0 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
(8 1 0.1) //15
(0 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) (40 10 1) simpleGrading (0.2 1 1)
hex (3 2 4 5 14 13 15 16) (40 10 1) simpleGrading (0.2 1 1)
hex (2 7 6 4 13 18 17 15) (40 10 1) simpleGrading (0.2 1 1)
hex (1 8 7 2 12 19 18 13) (40 10 1) simpleGrading (0.2 1 1)
hex (10 9 8 1 21 20 19 12) (40 10 1) simpleGrading (0.2 0.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)
);
}
noSlipWall
{
type wall;
faces
(
(5 16 15 4)
(4 15 17 6)
(0 1 12 11)
(10 21 12 1)
(10 9 20 21)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(3 5 4 2)
(10 1 8 9)
(1 2 7 8)
(2 4 6 7)
(11 12 13 14)
(14 13 15 16)
(21 20 19 12)
(12 19 18 13)
(13 18 17 15)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
The controldict code, code for pressure and velocity condition is same as for CASE 1.
output
courant number stability

velocity plot over line

pressure plot over line

Both the cases takes more than 8 minutes to give the output after 'icoFoam' command because it checks the courant number stability at each cell.
In the code after simpleGrading there is bracket which represents simpleGrading (grading factor at x axis grading factor at y axis grading factor at z axis)
Mesh grading factor tells about size of end cell in respect with first cell.
Here, less the grading factor,finer is the mesh and high grading factor gives larger mesh.