Challenge

Week 8 - BlockMesh Drill down challenge

BlockMesh drill down

Boundary condition specifications:

The given boundary has to be meshed and flow inside should be simulated in openFOAM.

The boundary is divided into 3 blocks as we can see in the figure below. The dimensions are as follows :

The width along the z-axis does not matter since the simulation we are doing is 2-D and we have considered it as shown in the figure above. The numbering in the figure below denotes the vertices and they are used to define the position and orientiation for the solver.

Inlet is given by joining vertices (0 4 7 3 )

Outlet is given by joining vertices (13 9 11 15)

point 0 is taken as origin (0,0,0)

line joining 0 and 1 gives the direction of positive x-axis.

line joining 0 and 3 gives the direction of positive y-axis.

line joining 0 and 4 gives the direction of positive z-axis.

All other points are located with respect to origin 0.

Given grading factors : 0.2 0.5 and 0.8

Steps to run the openFoam tutorial on the given problem

>Open terminal

>Navigate to tutorials/incompressible/icoFoam/cavity (icoFoam solves the incompressible laminar Navier-Stokes equations using the Pressure-Implicit with Splitting of Operators(PISO) algorithm. The code is inherently transient, requiring an initial condition and boundary conditions)

> Run the cavity file and save it under diffrent name conviniently

>Navigate to run/cavity_copy/system

>Edit blockMeshDict and controlDict as per requirement

>Give the suitable initial conditions in file 0 containing varying quantities.

>cavity_copy/blockMesh - creates the boundary and forms the mesh .

>check the mesh

>Run the simulation

>Open the simulation in paraview

BlockMeshDict for 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.001;

vertices
(
    (0 0 0) // 0
    (8 0 0) // 1
    (8 1 0) // 2
    (0 1 0) //3
    (0 0 0.5) //4
    (8 0 0.5) //5
    (8 1 0.5) ///6
    (0 1 0.5) //7 
    (8 -1 0) // 8
    (20 -1 0) // 9
    (20 0 0) // 10
    (20 1 0) // 11
    (8 -1 0.5) //12
    (20 -1 0.5) //13
    (20 0 0.5) // 14
    (20 1 0.5) //15

);

blocks
(
    hex (0 1 2 3 4 5 6 7) (80 10 1) simpleGrading (1 1 1)
    hex (1 10 11 2 5 14 15 6) (120 10 1) simpleGrading (1 1 1)
    hex (8 9 10 1 12 13 14 5) (120 10 1) simpleGrading (1 1 1)
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    
    outlet
    {
        type patch;
        faces
        (
            (9 10 14 13)
            (10 11 15 14)
        );
    }
    noslipwalls
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (0 1 5 4)
            (12 5 1 8)
            (11 2 6 15)
            (8 9 13 12)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
            (12 13 14 5)
            (5 14 15 6)
            (1 2 11 10)
            (8 1 10 9)
        );
    }
);

mergePatchPairs
(
);

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

In order to keep the cell width consistent through out, the first block with length of 0.8 gets 80 and 0.12 gets 120. It is said that along Y axis 10 grid points are to be taken

controlDict

In order to keep the flow stable the CFL number should be less than 0.5 and hence a lower value of `Deltat = 1*10^(-6)` is taken and a total run time of 0.5 seconds .

/*--------------------------------*- 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-6;

writeControl    timeStep;

writeInterval   100;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

Initial condition - U

The inlet condition is given below and the velocity at time = 0seconds is taken as 1m/s in x-direction only.

/*--------------------------------*- 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;
    }
}

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

Initial condition - P

The pressure conditions of the boundary at time = 0seconds is given below. It is noted that there in no pressure change along the walls and since it is a 3-D simulation, front and back is not taken into account.

/*--------------------------------*- 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
{
    noslipwalls
    {
        type            zeroGradient;
    }

    inlet
    {
        type            zeroGradient;
    }
    outlet
    {
    	type 		fixedValue;
    	value 		$internalField;
    }

    frontAndBack
    {
        type            empty;
    }
}

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

Grading factor 1 :

Mesh :

Velocity contour :

Velocity profile at a distance of 0.085 m from the origin

BlockMeshDict for Grading factor 0.2

We have considerd 3 blocks for this case. In order to get the mesh at the walls to given grading factors, the first block is divided into 2 along y-axis and is meshed as shown below. in order to continue the grading factor along the length even the 2nd block is meshed the same. to match the grading factor along x-axis, mesh is matched along y-axis for block 2 and block 3. Meshing is done as shown below:

/*--------------------------------*- 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.001;

vertices
(
    (0 0 0) // 0
    (8 0 0) // 1
    (8 1 0) // 2
    (0 1 0) //3
    (0 0 0.5) //4
    (8 0 0.5) //5
    (8 1 0.5) ///6
    (0 1 0.5) //7 
    (8 -1 0) // 8
    (20 -1 0) // 9
    (20 0 0) // 10
    (20 1 0) // 11
    (8 -1 0.5) //12
    (20 -1 0.5) //13
    (20 0 0.5) // 14
    (20 1 0.5) //15

);

blocks
(
    hex (0 1 2 3 4 5 6 7) (80 10 1) simpleGrading (0.2 ( (0.5 0.5 5) (0.5 0.5 0.2) ) 1)
    hex (1 10 11 2 5 14 15 6) (120 10 1) simpleGrading (5 ( (0.5 0.5 5) (0.5 0.5 0.2) ) 1)
    hex (8 9 10 1 12 13 14 5) (120 10 1) simpleGrading (5 5 1)
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    
    outlet
    {
        type patch;
        faces
        (
            (9 10 14 13)
            (10 11 15 14)
        );
    }
    noslipwalls
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (0 1 5 4)
            (12 5 1 8)
            (11 2 6 15)
            (8 9 13 12)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
            (12 13 14 5)
            (5 14 15 6)
            (1 2 11 10)
            (8 1 10 9)
        );
    }
);

mergePatchPairs
(
);

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

The mesh at the walls

BlockMeshDict for Grading factor 0.5

We have considerd 3 blocks for this case. In order to get the mesh at the walls to given grading factors, the first block is divided into 2 along y-axis and is meshed as shown below. in order to continue the grading factor along the length even the 2nd block is meshed the same. to match the grading factor along x-axis, mesh is matched along y-axis for block 2 and block 3. Meshing is done as shown below:

/*--------------------------------*- 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.001;

vertices
(
    (0 0 0) // 0
    (8 0 0) // 1
    (8 1 0) // 2
    (0 1 0) //3
    (0 0 0.5) //4
    (8 0 0.5) //5
    (8 1 0.5) ///6
    (0 1 0.5) //7 
    (8 -1 0) // 8
    (20 -1 0) // 9
    (20 0 0) // 10
    (20 1 0) // 11
    (8 -1 0.5) //12
    (20 -1 0.5) //13
    (20 0 0.5) // 14
    (20 1 0.5) //15

);

blocks
(
    hex (0 1 2 3 4 5 6 7) (80 10 1) simpleGrading (0.5 ( (0.5 0.5 2) (0.5 0.5 0.5) ) 1)
    hex (1 10 11 2 5 14 15 6) (120 10 1) simpleGrading (2 ( (0.5 0.5 2) (0.5 0.5 0.5) ) 1)
    hex (8 9 10 1 12 13 14 5) (120 10 1) simpleGrading (2 2 1)
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    
    outlet
    {
        type patch;
        faces
        (
            (9 10 14 13)
            (10 11 15 14)
        );
    }
    noslipwalls
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (0 1 5 4)
            (12 5 1 8)
            (11 2 6 15)
            (8 9 13 12)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
            (12 13 14 5)
            (5 14 15 6)
            (1 2 11 10)
            (8 1 10 9)
        );
    }
);

mergePatchPairs
(
);

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

BlockMeshDict for Grading factor 0.8

We have considerd 3 blocks for this case. In order to get the mesh at the walls to given grading factors, the first block is divided into 2 along y-axis and is meshed as shown below. in order to continue the grading factor along the length even the 2nd block is meshed the same. to match the grading factor along x-axis, mesh is matched along y-axis for block 2 and block 3. Meshing is done as shown below:

/*--------------------------------*- 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.001;

vertices
(
    (0 0 0) // 0
    (8 0 0) // 1
    (8 1 0) // 2
    (0 1 0) //3
    (0 0 0.5) //4
    (8 0 0.5) //5
    (8 1 0.5) ///6
    (0 1 0.5) //7 
    (8 -1 0) // 8
    (20 -1 0) // 9
    (20 0 0) // 10
    (20 1 0) // 11
    (8 -1 0.5) //12
    (20 -1 0.5) //13
    (20 0 0.5) // 14
    (20 1 0.5) //15

);

blocks
(
    hex (0 1 2 3 4 5 6 7) (80 10 1) simpleGrading (0.8 ( (0.5 0.5 1.25) (0.5 0.5 0.8) ) 1)
    hex (1 10 11 2 5 14 15 6) (120 10 1) simpleGrading (1.25 ( (0.5 0.5 1.25) (0.5 0.5 0.8) ) 1)
    hex (8 9 10 1 12 13 14 5) (120 10 1) simpleGrading (1.25 1.25 1)
    
);

edges
(
);

boundary
(
    inlet
    {
        type patch;
        faces
        (
            (0 4 7 3)
        );
    }
    
    outlet
    {
        type patch;
        faces
        (
            (9 10 14 13)
            (10 11 15 14)
        );
    }
    noslipwalls
    {
        type wall;
        faces
        (
            (3 7 6 2)
            (0 1 5 4)
            (12 5 1 8)
            (11 2 6 15)
            (8 9 13 12)
        );
    }
    frontAndBack
    {
        type empty;
        faces
        (
            (0 3 2 1)
            (4 5 6 7)
            (12 13 14 5)
            (5 14 15 6)
            (1 2 11 10)
            (8 1 10 9)
        );
    }
);

mergePatchPairs
(
);

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

Velocity comparison:

By exporting the values from the velocity contour plots for each mesh grading factor, we can take the peak velocity acheived

Grading Factor Peak Velocity
1 1.08076
0.2 1.08875
0.5 1.08666
0.8 1.08402

Conclusion:

As we can see that the finer the mesh near the step higher is the solution obtained but it can be observed that there is diffrence only after thousandths place. Approximating it to 2 digits after the decimal will not make any diffrence, hence choosing of mesh grade depends on the level of accuracy that is required. It also depends on the point or a location where the quantity has to be measured, for example:

>In case it is important to measure the change in quantity at the inlet and outlet surface, 0.2 mesh grading can be done as shown below

>In case it is important to measure the change in quantity at the step of the given boundary, 0.2 mesh grading can be done as shown below

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.