Project

2D simulation of flow over a square obstacle using openfoam

Aim : To calculate velocity contour and dragforce on a square obstacle placed in the air field and to automate the simulation process in openfoam

Geometry :

The geometry is created by blockMeshDict file in Openfoam.

Input data :

velocity at inlet = 10 m/sec

Temperature at inlet = 25 deg c

Reynolds number= Re = density*velocity*charecterstic length / dynamic viscosity

At 25 deg

dynamic viscosity of air =1.849 * 10 ^-05

density of air = 1.184

Re= 6.403 * 10^5

So renolds number is greater than 5 * 10^5

Flow is clearly turbulent. In order to capture the turbulence accurately RANS K-epsillon model is used.

BlockmeshDict file :

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


vertices
(
(0 0 -0.5)
(3.5 0 -0.5)
(4.5 0 -0.5)
(10 0 -0.5)
(10 1.5 -0.5)
(10 2.5 -0.5)
(10 4 -0.5)
(4.5 4 -0.5)
(3.5 4 -0.5)
(0 4 -0.5)
(0 2.5 -0.5)
(0 1.5 -0.5)
(3.5 1.5 -0.5)
(4.5 1.5 -0.5)
(4.5 2.5 -0.5)
(3.5 2.5 -0.5)

(0 0 0.5)
(3.5 0 0.5)
(4.5 0 0.5)
(10 0 0.5)
(10 1.5 0.5)
(10 2.5 0.5)
(10 4 0.5)
(4.5 4 0.5)
(3.5 4 0.5)
(0 4 0.5)
(0 2.5 0.5)
(0 1.5 0.5)
(3.5 1.5 0.5)
(4.5 1.5 0.5)
(4.5 2.5 0.5)
(3.5 2.5 0.5)
);

blocks
(
hex (0 1 12 11 16 17 28 27) (10 15 1) simpleGrading (1 1 1)
hex (11 12 15 10 27 28 31 26) (10 10 1) simpleGrading (1 1 1)
hex (10 15 8 9 26 31 24 25) (10 15 1) simpleGrading (1 1 1)
hex (15 14 7 8 31 30 23 24) (20 15 1) simpleGrading (1 1 1)
hex (1 2 13 12 17 18 29 28) (20 15 1) simpleGrading (1 1 1)
hex (14 5 6 7 30 21 22 23) (20 15 1) simpleGrading (1 1 1)
hex (13 4 5 14 29 20 21 30) (20 15 1) simpleGrading (1 1 1)
hex (2 3 4 13 18 19 20 29) (20 15 1) simpleGrading (1 1 1)
);

edges
(
);

boundary
(
pressure-outlet
{
type patch;
faces
(
(3 4 20 19)
(4 5 21 20)
(5 6 22 21)
);
}

velocity-inlet
{
type patch;
faces
(
(11 0 16 27)
(10 11 27 26)
(9 10 26 25)
);
}

upper-wall
{
type symmetryPlane;
faces
(
(6 7 23 22)
(7 8 24 23)
(8 9 25 24)
);
}

lower-wall
{
type symmetryPlane;
faces
(
(0 1 17 16)
(1 2 18 17)
(2 3 19 18)

);
}

obstacle-wall
{
type wall;
faces
(
(15 12 28 31)
(14 15 31 30)
(12 13 29 28)
(13 14 30 29)
);
}


);

mergePatchPairs
(
);

	
	
	


           

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

ControlDict File :

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

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         1;

deltaT          1e-4;

writeControl    timeStep;

writeInterval   200;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

THe solver used here is simpleFoam solver and the simulation is run for one sec with time step of 1e-4.

Transport properties :

/*--------------------------------*- 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    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

transportModel  Newtonian;

nu              [0 2 -1 0 0 0 0] 1.56165e-05;

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

kinematic viscosity at 25 degree of temperature is taken

Turbulent file:

/*--------------------------------*- 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    "constant";
    object      momentumTransport;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType  RAS;

RAS
{
    model           kEpsilon;

    turbulence      on;

    printCoeffs     on;
}

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

Here KEpsilon model is selected.

The emperical correlations required to find the turbulent properties are

where I is the Intensity

so k and w properties are calculated by using the above emperical relations.

Boundary condtions:

velocity :

/*--------------------------------*- 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 (10 0 0);

boundaryField
{
    velocity-inlet
    {
        type            fixedValue;
        value           uniform (10 0 0);
    }

    pressure-outlet
    {
        type             zeroGradient;
    }

    upper-wall
    {
        type            symmetryPlane;
    }
    
    lower-wall
    {
        type            symmetryPlane;
    }

    obstacle-wall
    {
        type            noSlip;
    }
}

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

pressure :

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

    pressure-outlet
    {
        type            fixedValue;
        value           uniform 0;
    }

    upper-wall
    {
        type            symmetryPlane;
    }
    
    lower-wall
    {
        type            symmetryPlane;
    }

    obstacle-wall
    {
        type            zeroGradient;
    }
}

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

k file :

/*--------------------------------*- 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;
    location    "0";
    object      k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField   uniform 0.13574;

boundaryField
{
    velocity-inlet
    {
        type            fixedValue;
        value           uniform 0.13574;
    }
  
   pressure-outlet
   { 
        type            zeroGradient;
   }

    upper-wall
    {
        type            symmetryPlane;
    }
  
    lower-wall
    {
        type            symmetryPlane;
    }
    
     obstacle-wall
    {
        type            kqRWallFunction;
        value           uniform 0.13574;
    }
    
}


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

epsilon :

/*--------------------------------*- 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;
    location    "0";
    object      epsilon;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

internalField   uniform 0.117167;

boundaryField
{
    velocity-inlet
    {
        type           fixedValue;
        value          uniform 0.117167;
    }

    pressure-outlet
    {
        type           zeroGradient;
    }

    upper-wall
    {
        type          symmetryPlane;
    }

    lower-wall
    {
        type           symmetryPlane;
    }

    obstacle-wall
    {
        type            epsilonWallFunction;
        value           uniform 0.117167;
    }
    
}


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

The simpleFoam solver is called and the equations are solved in parallel computing method.

Mesh :

output files:

velocity contour :

velocity vector field:

Drag force calculation :

The obstacle is to be removed from the surface seperately by using ExtractBlock tool

Then the surface is generated by SurfaceExtract

normal vectors should be generated to find the x normals and y normals

now calculator is opened in paraview the product of p*x-Normal is stored as drag

Now its is integrated to obtain the Drag force.

Mesh-refinement strategy:

The mesh can be refined at the obstacle surface by changing the mesh grading factor in the blockMeshDict file. The cell volume is formed according to the grading factor given in that file.

Reduction of Computational time:

The simulation time can be reduced by performing renumberMesh and a proper time scale is to be selected so as to satisfy the courant number criteria.

Automated Allrun file:

 #!/bin/sh
cd ${0%/*} || exit 1    # Run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
application=$(getApplication)

runApplication $application

paraFoam
#------------------------------------------------------------------------------

It can be further automated by using function codes.

Conclusion:

simulation is performed sucessfully by using Openfoam

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.