Project

Simulation floiw through pipe in OpenFoam-part2

Objectices of the project:

1). Calculation of flow variables

2). Generation of blocMeshDict using the wedge boundry condition. Create the blockmesgdict file in Matlab such that the mesh is automatically created for various wedge angle.

3). Simulating the pipe flow in OpenFoam using icoFoam solver.

4). Post process the velocity profile

Indruduction:

In the last project, flow through a pipe was simulated and results were presented for wedge boundry conditions. In this project the working enviranment is kept the same as the previous one. Instead of the wedge boundry, the symmetry boundry is used in this project.

\"\"

MATLAB code for automatic generation of blockMeshDict file:

     clear all 
     close all 
     clc
 
   %% variable values
  diameter = 0.01;
  r = diameter/2;
  L = 1.2;
  theta = input(\'Enter the value of wedge angle = \');
  %% specifing string for header part 
  h1=\'/*----------------------*- C++ -*--------------------------------------*\\\';
  h2=\'| ==========                   |                                         |\';
  h3=\'| \\\\       /   F ield          | OpenFOAM:  The Open Source CFD Toolbox  |\';
  h4=\'|  \\\\     /    O peration      | Version:   4.0                          |\';
  h5=\'|   \\\\   /     A nd            | Web:       www.OpenFOAM.org             |\';
  h6=\'|    \\\\ /      M anipulation   |                                         |\';
  h7=\' \\*---------------------------------------------------------------------*/
  h8=\'FoamFile\';
  h9=\'{\';
  h10=\'    version     2.0;\';
  h11=\'    format      ascii;\';
  h12=\'    class       dictionary;\';
  h13=\'    object      blockMeshDict;\';
  h14=\'}\';
  h15=\'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\';
  conv=\'convertTometers 1;\';
  
  s1=blanks(5);
  s2=blanks(10);
  s3=blanks(15);
  
  v0=[0 0 0];
  v1=[r*sind(theta/2) r*cosd(theta/2) 0];
  v2=[-r*sind(theta/2) r*cosd(theta/2) 0];
  v3=[0 0 L];
  v4=[r*sind(theta/2) r*cosd(theta/2) L];
  v5=[-r*sind(theta/2) r*cosd(theta/2) L];
  
  block=\'hex (0 0 1 2 3 3 4 5) (1 50 200) SimpleGrading(1 0.5 1)\';
  edge1=\'arc 1 2\';
  edge2=\'arc 4 5\';
  
  e1=[0 r 0];
  e2=[0 r L];
  
  inlet=\'(0 0 2 1)\';
  outlet=\'(3 4 5 3)\';
  wedge1=\'(0 1 4 3)\';
  wedge2=\'(3 5 2 0)\';
  wall=\'(4 1 2 5)\';
  axis=\'(0 3 3 0)\';
  
  final=\'// ***************************************************************** //\';
  
  %% writting the blockMeshDict
  f1=fopen(\'blockMeshDict.txt\',\'w\');
  
  fprintf(f1, \'%s rn\',h1);
  fprintf(f1, \'%s rn\',h2);
  fprintf(f1, \'%s rn\',h3);
  fprintf(f1, \'%s rn\',h4);
  fprintf(f1, \'%s rn\',h5);
  fprintf(f1, \'%s rn\',h6);
  fprintf(f1, \'%s rn\',h7);
  fprintf(f1, \'%s rn\',h8);
  fprintf(f1, \'%s rn\',h9);
  fprintf(f1, \'%s rn\',h10);
  fprintf(f1, \'%s rn\',h11);
  fprintf(f1, \'%s rn\',h12);
  fprintf(f1, \'%s rn\',h13);
  fprintf(f1, \'%s rn\',h14);
  fprintf(f1, \'%s rn\',h15);
  fprintf(f1,\'% rn\');
  
  fprintf(f1, \'%s rn\',conv);
  fprintf(f1, \'rn\');
  
  fprintf(f1,\'% rn\',\'vertices\');
  fprintf(f1,\'% rn\',\'(\');
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v0(1),v0(2),v0(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v1(1),v1(2),v1(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v2(1),v2(2),v2(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v3(1),v3(2),v3(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v4(1),v4(2),v4(3));
  fprintf(f1,\'%s (%f %f %f) rn\',s1,v5(1),v5(2),v5(3));
  fprintf(f1,\'% rn\',\');\');
  fprintf(f1,\'rn\');
  
  fprintf(f1,\'% rn\',\'blocks\');
  fprintf(f1,\'% rn\', \'(\');
  fprintf(f1,\'% %s rn\',s1,block);
  fprintf(f1,\'%s rn\', \');\');
  fprintf(f1,\'% rn\');
  
  fprintf(f1,\'%s rn\', \'boundry\');
  fprintf(f1,\'%s rn\',\'(\');
   
  fprintf(f1,\'%s %s rn\', s1,\'inflow\'); 
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type patch;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,inlet);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'front\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wedge;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wedge1);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'back\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wedge;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wedge2);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'wall\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type wall;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,wall);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s %s rn\', s1,\'axis\');
  fprintf(f1,\'%s %s rn\', s1,\'{\');
  fprintf(f1,\'%s %s rn\', s2,\'type empty;\');
  fprintf(f1,\'%s %s rn\', s2,\'faces\');
  fprintf(f1,\'%s %s rn\', s2,\'(\');
  fprintf(f1,\'%s %s rn\', s3,axis);
  fprintf(f1,\'%s %s rn\', s2,\');\');
  fprintf(f1,\'%s %s rn\', s1,\'}\');
  
  fprintf(f1,\'%s rn\', \');\');
  fprintf(f1,\'rn\');
  
  fprintf(f1,\'%s rn\', \'mergePatchPairs\');
  fprintf(f1,\'%s rn\',\'(\');
  fprintf(f1,\'%s rn\',\');\');
  fprintf(f1,\'rn\');
  fprintf(f1,\'%s rn\',final);
  
  fclose(f1);
  
  
  
  
  
  
  
  
  
  
  

blockMeshDict file generated for wedge angle =10

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

convertToMeters 1;

vertices
(
    (0.000000 0.000000 0.000000)
    (0.000436 0.004981 0.000000)
    (-0.000436 0.004981 0.000000)
    (0.000000 0.000000 1.200000)
    (0.000436 0.004981 1.200000)
    (-0.000436 0.004981 1.200000)

);

blocks
(
    hex (0 0 1 2 3 3 4 5) (1 50 200) simpleGrading (1 0.5 1)
   
);

edges
(
   arc 1 2 (0.000000 0.005000 0.000000)
   arc 4 5 (0.000000 0.005000 1.200000)
);

boundary
(
    inflow
    {
        type patch;
        faces
        (
            (0 0 2 1)
          
        );
    }
    outflow
    {
        type symmetry;
        faces
        (
            (0 1 4 3)
           
        );
    }
    back
    {
        type symmetry;
        faces
        (
            (3 5 2 0)
            
        );
    }
        Wall
    {
        type wall;
        faces
        (
            (4 1 2 5)
            
        );
    }
    axis
    {
        type empty;
        faces
        (
            (0 3 3 0)
           
        );
    }
);

mergePatchPairs
(
);

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

Pressure boundry condition:

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

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

internalField   uniform 0;

boundaryField
{
    inflow
    {
        type            zeroGradient;
    }

    outflow
    {
        type            fixedValue;
        value           uniform 0.063874;
    }

    Wall
    {
        type            zeroGradient;
    }

    front
    {
        type            symmetry;
    }

    Back
    {
        type            symmetry;
     }
    axis
    {
        type            empty;
    }
}

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

Velocity Boundry condition:

/*--------------------------------*- C++ -*----------------------------------*\\
| =========                 |                                                 |
| \\\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\\\    /   O peration     | Version:  4.1                                   |
|   \\\\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\\\/     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
{
    inflow
    {
        type            fixedValue;
        value           uniform (0 0 0.1869);
    }

    outflow
    {
        type            zeroGradient;
    }

    Wall
    {
        type            noSlip;
    }

    front
    {
        type            symmetry;
    }

    Back
    {
        type            symmetry;
   }
    axis
    {
        type            empty;
    }
}

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

\"\"

\"\"

\"\"

\"\"

\"\"

\"\"

\"\"

\"\"

\"\"

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.