Challenge

Week 8 - BlockMesh Drill down challenge

# Aim of the challenge is to simulate the flow through a backward facing step.

The backward facing step used in this challenge is of following dimensions:

above single block is divided into 5 blocks as shown below.

In 3d as follows along with the vertices.

above shown block is created in the openfoam by editing the blockmeshdict file of cavity case setup of icoFoam solver.

Setting up the simulation for the above case involves following steps:

1. Creating the geometry:

To create the above geometry we have to edit the blockMeshDict file of the above case setup. BlockMeshDict file can be found in the system folder.

Below is the blockMeshDict file for the above block creation:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

vertices
(
(0 0 0)
(0.08 0 0)
(0.08 0.005 0)
(0 0.005 0)
(0.08 0.01 0)
(0 0.01 0)
(0.20 0.01 0)
(0.20 0.005 0)
(0.20 0 0)
(0.20 -0.01 0)
(0.08 -0.01 0)
(0 0 0.01)
(0.08 0 0.01)
(0.08 0.005 0.01)
(0 0.005 0.01)
(0.08 0.01 0.01)
(0 0.01 0.01)
(0.20 0.01 0.01)
(0.20 0.005 0.01)
(0.20 0 0.01)
(0.20 -0.01 0.01)
(0.08 -0.01 0.01)
);

blocks
(
hex (0 1 2 3 11 12 13 14) (200 10 1) simpleGrading (0.2 1.2 1)
hex (3 2 4 5 14 13 15 16) (200 10 1) simpleGrading (0.2 0.2 1)
hex (2 7 6 4 13 18 17 15) (200 10 1) simpleGrading (1.2 0.2 1)
hex (1 8 7 2 12 19 18 13) (200 10 1) simpleGrading (1.2 1.2 1)
hex (10 9 8 1 21 20 19 12) (200 10 1) simpleGrading (1.2 1.2 1)
);

edges
(
);

boundary
(
inletwall
{
type patch;
faces
(
(3 0 11 14)
(5 3 14 16)
);
}
outletwall
{
type patch;
faces
(
(17 18 7 6)
(18 19 8 7)
(19 20 9 8)
);
}
Noslipwalls
{
type wall;
faces
(
(4 5 16 15)
(6 4 15 17)
(1 12 11 0)
(9 20 21 10)
(1 10 21 12)
);
}
frontAndBack
{
type empty;
faces
(
(16 14 13 15)
(14 11 12 13)
(15 13 18 17)
(13 12 19 18)
(12 21 20 19)
(4 2 3 5)
(2 1 0 3)
(6 7 2 4)
(7 8 1 2)
(8 9 10 1)
);
}
);

mergePatchPairs
(
);

// ************************************************************************* //

* Vertices from [0] to [21] is defined

* after definng vertices blocks are defined (using right hand thumb rule), along with deifining the blocks the number of cells in x, y, z direction is also defined, here it is 200 along x direction 10 along y direction and only 1 along z direction (only one along along z direction because its a 2d simulation).

* After defining the cells Grading factor is defined, grading factor F is given as follow,

F = Size of the last cell/Size of the first cell.

Grading factor of 0.2, 0.5, 0.8 are set near the walls.

Keeping the above condition in mind grading factor is given to each block. Above file has a grading factor of 0.2 given.

* After defining the blocks and its concerned parameters next all the patches (faces) are defined along with its type.

4 types of faces are defined viz inlet, outlet, front and back, noslipwalls.

Once all the above is done we can execute blockMesh command in the terminal and hence generate the blockmesh, generated blockmesh can be visualised in paraFoam.

2. Defining the initial conditions for pressure and velocity:

This can be done by giving right initial conditions on pressure and velocity files present in the 0 folder of the case setup.

% velcoity file:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ 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
{
inletwall
{
type fixedValue;
value uniform (1.5 0 0);
}

outletwall
{
type zeroGradient;
}

Noslipwalls
{
type noSlip;
}

frontAndBack
{
type empty;
}
}

// ************************************************************************* //

Here inlet velocity of 1.5 m/s is set since velocity is a vector quantity, values are defined in all 3 directions. Also in the dimension of the veocity is set.

% Pressure file:

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions [0 2 -2 0 0 0 0];

internalField uniform 0;

boundaryField
{
inletwall
{
type zeroGradient;
}

outletwall
{
type fixedValue;
value uniform 0;
}

Noslipwalls
{
type zeroGradient;
}

frontAndBack
{
type empty;
}
}

// ************************************************************************* //

here pressure value at the outlet is set to 0, i.e atmospheric pressure.

It has to be taken care to give the same name given for patches in blockMeshDict file in these pressure and velocity file.

3. Setting the start time, end time and dt:

To set all the above parameters we need to edit the controlDict file present in the system folder, below is the controlDict file used for this simulation.

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 6
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application icoFoam;

startFrom startTime;

startTime 0;

stopAt endTime;

endTime 0.4;

deltaT 0.00001;

writeControl timeStep;

writeInterval 20;

purgeWrite 0;

writeFormat ascii;

writePrecision 6;

writeCompression off;

timeFormat general;

timePrecision 6;

runTimeModifiable true;


// ************************************************************************* //

# Here start time is set to zero and end time is set to 0.4 sec. End time is set, like the fluid should complete 2 passes

velocity = dispalcement/time,

we have a inlet velocity of 1.5 m/s and to have a displacement of 0.2 meters it takes 0.2/1.5 sec

i.e, 0.133 sec, so this is the time taken by the fluid to have a single pass

so to have 2 passes it will take almost 0.3 sec, so in our case end time is set to 0.4 sec.

so the condition of 2 passes is very much satisfied.

# Coming to deltaT (dt) it is set using the courant number (C)

Courant number , C = (dt/dx)*velocity

dx - it is the length of the smallest cell in the direction of flow, in this case direction of flow is x and hence it is calculated using the grading factor.

courant number is taken as 1 and velocity = 1.5 m/s

dt obtained from the above calculation cannot be taken fixed, because the flow velocity varies, it wont be the same as the inlet velocity 1.5 m/s, so dt has to be set in a trial and error manner.

* Once all the above 3 steps are done then we can execute the icoFoam command n the terminal and can run the simulation.

Below are the blockmesh, velocity profiles obtained for different grading factors:

1. Grading factor of 0.2:

# BlockMesh

# Velcoity contour plot along x-direction:

# Line plot of velocity along x-direction:

This plot is obtained by placing the 2 points of the line probe along x - direction and the co-ordinates of the points as follows:

point1 - (0, 0.005, 0)

point2 - (0.2,0.005,0)

when placed it will look as follow:

plot obtained by above positioning of the line probe as follows

# Line plot of velocity obtained at a distance of 0.085 meters from the inlet:

legend for the above graph : x -axis = length of block mesh, y - axis = magnitude of velocity

2. Grading factor of 0.5:

To achieve this we only need to modify the grading factor defined in the blocks section of the blockMeshDict file. Screenshot of the same is shown below:

Blockmesh:

# Velocity contour plot along x- direction:

# Line plot of velocity along x-direction:

This plot is obtained by placing the 2 points of the line probe along x - direction and the co-ordinates of the points as follows:

point1 - (0, 0.005, 0)

point2 - (0.2,0.005,0)

when placed it will look as follow:

plot obtained by above positioning of the line probe as follows:

# Line plot of velocity obtained at a distance of 0.085 meters from the inlet:

3. Grading factor of 0.8:

To achieve this we only need to modify the grading factor defined in the blocks section of the blockMeshDict file. Screenshot of the same is shown below:

Blockmesh:

# Velocity contour plot along x - direction:

# Line plot of velocity along x-direction:

This plot is obtained by placing the 2 points of the line probe along x - direction and the co-ordinates of the points as follows:

point1 - (0, 0.005, 0)

point2 - (0.2,0.005,0)

when placed it will look as follow:

plot obtained by above positioning of the line probe as follows:

# Line plot of velocity obtained at a distance of 0.085 meters from the inlet:

# Explaination about the plots:

* From the velocity contour plots it is very much clear that as the fluid flow through the block maximum velocity is in the middle, near the walls velocity is zero. This is exactly how a fluid behaves when it flows over a plate or through a closed channel, the velocity profile will be parabolic with least velocity near the walls and max at the center.

* By observing the plots of velocity at a distance of 0.085 m from the inlet for different grading factor it is clear that the magnitude of velocity does not depend on the grid size, hence we can conclude that the magnitude of velocity is grid independent.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.