Challenge

Week 8 - Simulation of a backward facing step in OpenFOAM

* First start terminal in Linux Operating system using ctrl+alt+T buttons on key board or right click -> Open Terminal.

* we have to simulate our problem in openFOAM and we are going to solve our problem using tutorials present in openFOAM, therefore, just type ‘tut’ to open OpenFOAM tutorial directory. And type ‘ls’ to identify what kind of tutorials present inside this directory.

* To solve incopressible flow simulation for this problem so select incompressible directory by typing ‘cd incompressible’ and then again type ls to explore folders in incopressible folders.

* In above picture, we can see the plethora of solver folders. For this particular solver we need solver for laminar-viscous flow. So here we choose ‘icoFoam’

* icoFoam is the solver in openFoam which is use as transient solver for incopressible, laminar flow of Newtonian fluids.

* Newtonian fluid is a fluid in which the viscous stress arising from its flow, at every point, are linearly correlated to the local strain rate - the rate of change of its deformation over time. Newtonian fluids are the simplest mathematical models of fluids that account for viscosity.

* Therefore, we will select icoFoam folder by typing ‘cd icoFoam’ and by typing ‘ls’ we explore this folder in terminal.

* Here, we have, again to option, cavity and elbow. They both are part of the icoFoam solver and cavity section use to create required domain and black mesh so select ‘cavity’ folder.

* In cavity, we are, again, going to see cavity folder, where we have to define our fluid domain and generate block mesh.

* But we are not going to make any changes here in tutorial section. First of all, OpenFoam does no let anyone make any changes in their official tutorial and secondly, any changes with their official tutorials my corrupt openFoam. An in a bid to correct it, we may need to reinstall open foam all over again.

* So, we are 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 then open run folder by typing ‘cd $FOAM_RUN’. where we can see cavity_test file.

* Now, we can make any changes to the cavity test file, which will never affect the openFoam official files. Open cavity test folder. Here, we can provide specification for our block mesh in system folder.

* As we can see in above picture, there are 4 script file system folder and 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 contains information regarding all aspects of the geometry.

/*--------------------------------*- 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
(
   //vertices from points 0 to 10
    (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.2 0.01 0)
    (0.2 0.005 0)
    (0.2 0 0)
    (0.2 -0.01 0)
    (0.08 -0.01 0)
    
    //vertices from points 11 to 21
    (0 0 0.1)
    (0.08 0 0.1)
    (0.08 0.005 0.1)
    (0 0.005 0.1)
    (0.08 0.01 0.1)
    (0 0.01 0.1)
    (0.2 0.01 0.1)
    (0.2 0.005 0.1)
    (0.2 0 0.1)
    (0.2 -0.01 0.1)
    (0.08 -0.01 0.1)
);

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

edges
(
);
boundary
(
  outlet
  { 
    type patch;
    faces
  (
    (6 17 18 7)
    (8 7 18 19)
    (9 8 19 20)
  );
 }
  
  inlet
  { 
    type patch;
    faces
   ( 
    (11 14 3 0)
    (14 16 5 3)
   );
  } 
   
  top
  {     
    type wall;
    faces
   ( 
    (15 4 5 16)
    (15 17 6 4)
   );
  }  
  
  bottom
  { 
    type wall;
    faces
   ( 
    (11 0 1 12)
    (21 10 9 20)
   );
  }
  
   sidestep
  { 
   type wall;
   faces
   (
    (21 12 1 10)
   );
  }
  
  
   frontface
  {
   type empty; 
   faces
   (
     (13 15 16 14)
     (12 13 14 11)
     (20 19 12 21)
     (19 18 13 12)
     (18 17 15 13)
   );
   }
   
   backface
   {
    type empty;
    faces
    ( 
      (0 3 2 1)
      (3 5 4 2)
      (2 4 6 7)
      (1 2 7 8)
      (10 1 8 9)
     );
     } 
);


mergePatchPairs
(
);

controldict:

* This dict contains information about time, like start and end time and time step. edit all those values as per your choice. here start time is 0 and end time is 5s with time step dt of 0.001

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

deltaT          0.001;

writeControl    timeStep;

writeInterval   20;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;


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

Transport properties :

* Change value of viscosity to 0.0001, so that we get reynolds number for laminar flow.

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

nu              [0 2 -1 0 0 0 0] 1e-5;


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

Pressure - This dict is found inside 0 folder, define pressure conditions at all boundaries, for inlet and outlet we are using neumann boundary condition. In neumann boundary condition either velocity or pressure is defined for inlet or outlet.

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

    top
    {
        type            zeroGradient;
    }
    
    bottom
    {
        type            zeroGradient;
    }
    
    sidestep
    {
        type            zeroGradient;
    }
    

    frontface
    {
        type            empty;
    }
    
    backface
    {
        type            empty;
    }
    
    outlet
    {
      type            fixedValue;
      value           uniform 0;
    }  

Velocity:

* Define velocity parameters for all boundaries. top and bottom are no slip, inlet and outlet are neumann boundary condition and front and back faces are empty.

* Empty condition means they dont capture velocity and pressure changes this is is used when we want 2D simulation on 3dD geometry.

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

boundaryField
{
    inlet
    {
        type            fixedValue;
        value           uniform (0.2 0 0);
    }

    top
    {
        type            noSlip;
    }
    
    bottom
    {
        type            noSlip;
    }
    
    sidestep
    {
        type            noSlip;
    }

    frontface
    {
        type            empty;
    }
    
    backface
    {
        type            empty;
    }
    
    outlet
    {
        type            zeroGradient;
    }
}

MESH without grading:

Simulation with grading 0.2:

* In this simulation only grading values in block entries of blockMeshdict needs to be changed acording to grading on faces we want. In this case we want denser mesh at side step.

/*--------------------------------*- 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
(
   //vertices from points 0 to 10
    (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.2 0.01 0)
    (0.2 0.005 0)
    (0.2 0 0)
    (0.2 -0.01 0)
    (0.08 -0.01 0)
    
    //vertices from points 11 to 21
    (0 0 0.1)
    (0.08 0 0.1)
    (0.08 0.005 0.1)
    (0 0.005 0.1)
    (0.08 0.01 0.1)
    (0 0.01 0.1)
    (0.2 0.01 0.1)
    (0.2 0.005 0.1)
    (0.2 0 0.1)
    (0.2 -0.01 0.1)
    (0.08 -0.01 0.1)
);

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

edges
(
);
boundary
(
  outlet
  { 
    type patch;
    faces
  (
    (6 17 18 7)
    (8 7 18 19)
    (9 8 19 20)
  );
 }
  
  inlet
  { 
    type patch;
    faces
   ( 
    (11 14 3 0)
    (14 16 5 3)
   );
  } 
   
  top
  {     
    type wall;
    faces
   ( 
    (15 4 5 16)
    (15 17 6 4)
   );
  }  
  
  bottom
  { 
    type wall;
    faces
   ( 
    (11 0 1 12)
    (21 10 9 20)
   );
  }
  
   sidestep
  { 
   type wall;
   faces
   (
    (21 12 1 10)
   );
  }
  
  
   frontface
  {
   type empty; 
   faces
   (
     (13 15 16 14)
     (12 13 14 11)
     (20 19 12 21)
     (19 18 13 12)
     (18 17 15 13)
   );
   }
   
   backface
   {
    type empty;
    faces
    ( 
      (0 3 2 1)
      (3 5 4 2)
      (2 4 6 7)
      (1 2 7 8)
      (10 1 8 9)
     );
     } 
);


mergePatchPairs
(
);

MESH with grading:

Velocity plot for case 1 (no grading):

Velocity plot for case 2 (grading 0.2):

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.