Challenge

Week 12 - Validation studies of Symmetry BC vs Wedge BC in OpenFOAM vs Analytical H.P equation

Content

Sr No Topic
1 Introduction
2 Given data
MATLAB code
3 Setting up simulation
3.1 Creating geometry
3.2 Creating files
OpenFoam Result
4 Simulation results
4.1 `10^o`
4.2 `25^o`
4.3 `45^o`
5 Comment on the result
6 Conclusion

1) Introduction: As OpenFoam provides flexibility in setting up simulations, it can be noted that the boundary conditions alco provide a good understanding of the problem and give insigt into the simulation. Here, we will be testing two such senarios where we will test angle of the pipe and compare Symmetry and Wedge boundary conditions.

2) Given data: As setting up the problem is necessay we can take the help of the data avialable to us from week 11. For this task we will be inputting the same data and compare for the boundary conditions.

The analytical solution is givena as:

Sr No. Properties Values
1 Le (entry length) 2.1m
2 L (totla length) 2.5m
3 Velocity (averaged) 0.0935 m/s
4 Velocity (maximum) 0.1870 m/s
5 Pressure Drop 16.6430 Pa
6 Kainamatic pressure drop 0.0166 Pa
7 Shear stress 0.033 Pa
-------------------------------------------------------------------

3) Setting up the simulation: As major aspect of setting up the simulation is creating individual files for the geometry, initial and boundary conditions. A MALTAB program is created to give the necessary files in one go as mentioned below:

3.1) Creating Geometry.
function [points_t, points_b, x_arc, y_arc, zl] = new_bmd(ang, l, r);
%a function that reurns the co-ordinate points and co-ordinate of arc.

    %inputs
    
    zo = 0;
    zl = l;
    %creating the arrays for x, y co-ordinates
    x = linspace(0, r, 10);
    y = linspace(0, r, 10);

    %origin points
    xo = x(1);
    yo = y(1);
    
    %The points at the edge of wedge.
    xr = r*sind(ang);
    yr = r*cosd(ang);
    
    %Finding the points of the arc.
    ang_1 = linspace(0, ang, ang);
    for i = 1:length(ang_1)
        if ang_1(i) == 0
            x_arc = r*sind(ang_1(i));
            y_arc = r*cosd(ang_1(i));
        end
    end
    
    x_arc = x_arc;
    y_arc = y_arc;
    
    xl = -xr;
    yl = yr;
    
    %array that compiles the x, y, z co-ordinates
    a = [xo, yo, zo, xr, yr, zo, xl, yl, zo];
    b = [xo, yo, zl, xr, yr, zl, xl, yl, zl];


    arc = zeros(3, 3);
    arc_f = zeros(3,3);
    
    %Converting the points into an array and the length of the wedge is
    %along x-axis.
    for p = 1:length(a)
        arc(p) = a(p);
    end
    points_t = zeros(3, 3);
    points_t(1, :) = arc(3, :);
    points_t(2, :) = arc(2, :);
    points_t(3, :) = arc(1, :);
    
    for q = 1:length(b)
        arc_f(q) = b(q);
    end
    points_b = zeros(3, 3);
    
    points_b(1, :) = arc_f(3, :);
    points_b(2, :) = arc_f(2, :);
    points_b(3, :) = arc_f(1, :);
end
3.2) Creating files for simulation.
angle = [10, 25, 45];

for f  = 1:length(angle)
    piy = fopen(sprintf('blockMeshDict_sym%d.txt', f), 'wt');

    [points_t, points_b, x_arc, y_arc, zl] = new_bmd(angle(f), 2.5, 0.01);

    h = ["/*--------------------------------*- 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"];


        for i = 1:length(h)
            fprintf(piy, '%s\n', h(i));
        end
        fprintf(piy, '(\n');



        for j = 1:3
            fprintf(piy, '\t(%d %d %d)\n', points_t(1:3, j)');
        end
        fprintf(piy, '\n');
        for k = 1:3
            fprintf(piy, '\t(%d %d %d)\n', points_b(1:3, k)');
        end
        fprintf(piy, ');\n\n');
        fprintf(piy, 'blocks\n(\n');
        fprintf(piy, '\thex (%d %d %d %d %d %d %d %d) (500 20 1) simpleGrading (1 0.1 1)\n);\n', [0 3 5 2 0 3 4 1]);
        fprintf(piy, 'edges\n(\n\tarc 1 2 (%d %d %d)\n\tarc 4 5 (%d %d %d)\n);\n\n', [x_arc y_arc 0 zl y_arc 0]);
        fprintf(piy, 'boundary\n(\n\tinlet\n\t{\n\t\ttype patch;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 1 2 0]);
        fprintf(piy, '\toutlet\n\t{\n\t\ttype patch;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [3 5 4 3]);
        fprintf(piy, '\ttop\n\t{\n\t\ttype wall;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [1 4 5 2]);
        fprintf(piy, '\tfront\n\t{\n\t\ttype symmetry;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 3 4 1]);
        fprintf(piy, '\tback\n\t{\n\t\ttype symmetry;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 2 5 3]);
        fprintf(piy, '\taxis\n\t{\n\t\ttype empty;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n);\n', [0 3 3 0]);
        fprintf(piy, 'mergePatchPairs\n(\n);\n');
        fprintf(piy, '%s', "// ************************************************************************* //");
        fclose(piy);
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        %pressure_symmetry
        press_sym = fopen(sprintf('p_sym.txt'), 'wt');
        P_s = ["/*--------------------------------*- 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";
        "{";
        "    inlet";
        "    {";
        "        type            zeroGradient;";
        "    }";

        "    outlet";
        "    {";
        "        type            fixedValue;";
        "        value	         uniform 0;";
        "    }";

        "    top";
        "    {";
        "        type            zeroGradient;";
        "    }";

        "    front";
        "    {";
        "        type            symmetry;";
        "    }";
        "    back";
        "    {";
        "        type            symmetry;";
        "    }";
        "    axis";
        "    {";
        "        type            empty;";
        "    }";
        "}";

        "// ************************************************************************* //"]
        for p = 1:length(P_s)
            fprintf(press_sym, '%s\n', P_s(p));
        end
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        %velocity_symmetry
        vel_sym = fopen('U_sym.txt', 'wt');
        V_s = ["/*--------------------------------*- 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.0935 0 0);";

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

        "    outlet";
        "    {";
        "        type            zeroGradient;";

        "    }";

        "    top";
        "    {";
        "        type            fixedValue;";
        "        value		 uniform (0 0 0);";

        "    }";

        "    axis";
        "    {";
        "        type            empty;";
        "    }";

        "    front";
        "    {";
        "        type            symmetry;";
        "    }";
        "    back";
        "    {";
        "        type            symmetry;";
        "    }";
        "}";

        "// ************************************************************************* //"]
    
        for v = 1:length(V_s)
            fprintf(vel_sym, '%s\n', V_s(v)); 
        end

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        piy = fopen(sprintf('blockMeshDict_wed%d.txt', f), 'wt');
        h1 = ["/*--------------------------------*- 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"];


        for i = 1:length(h1)
            fprintf(piy, '%s\n', h1(i));
        end
        fprintf(piy, '(\n');



        for j = 1:3
            fprintf(piy, '\t(%d %d %d)\n', points_t(1:3, j)');
        end
        fprintf(piy, '\n');
        for k = 1:3
            fprintf(piy, '\t(%d %d %d)\n', points_b(1:3, k)');
        end
        fprintf(piy, ');\n\n');
        fprintf(piy, 'blocks\n(\n');
        fprintf(piy, '\thex (%d %d %d %d %d %d %d %d) (500 20 1) simpleGrading (1 0.1 1)\n);\n', [0 3 5 2 0 3 4 1]);
        fprintf(piy, 'edges\n(\n\tarc 1 2 (%d %d %d)\n\tarc 4 5 (%d %d %d)\n);\n\n', [x_arc y_arc 0 zl y_arc 0]);
        fprintf(piy, 'boundary\n(\n\tinlet\n\t{\n\t\ttype patch;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 1 2 0]);
        fprintf(piy, '\toutlet\n\t{\n\t\ttype patch;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [3 5 4 3]);
        fprintf(piy, '\ttop\n\t{\n\t\ttype wall;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [1 4 5 2]);
        fprintf(piy, '\tfront\n\t{\n\t\ttype wedge;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 3 4 1]);
        fprintf(piy, '\tback\n\t{\n\t\ttype wedge;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n', [0 2 5 3]);
        fprintf(piy, '\taxis\n\t{\n\t\ttype empty;\n\t\tfaces\n\t\t(\n\t\t\t(%d %d %d %d)\n\t\t);\n\t}\n);\n', [0 3 3 0]);
        fprintf(piy, 'mergePatchPairs\n(\n);\n');
        fprintf(piy, '%s', "// ************************************************************************* //");
        fclose(piy);
        
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        
        %pressure wedge
        press_wed = fopen(sprintf('p_wed.txt'), 'wt');
        P_w = ["/*--------------------------------*- 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";
        "{";
        "    inlet";
        "    {";
        "        type            zeroGradient;";
        "    }";

        "    outlet";
        "    {";
        "        type            fixedValue;";
        "        value	         uniform 0;";
        "    }";

        "    top";
        "    {";
        "        type            zeroGradient;";
        "    }";

        "    front";
        "    {";
        "        type            wedge;";
        "    }";
        "    back";
        "    {";
        "        type            wedge;";
        "    }";
        "    axis";
        "    {";
        "        type            empty;";
        "    }";
        "}";

        "// ************************************************************************* //"]
        for p_w = 1:length(P_w)
            fprintf(press_wed, '%s\n', P_w(p_w));
        end
        
        
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
        %velocity wedge
        vel_wed = fopen('U_wed.txt', 'wt');
        V_w = ["/*--------------------------------*- 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.0935 0 0);";

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

        "    outlet";
        "    {";
        "        type            zeroGradient;";

        "    }";

        "    top";
        "    {";
        "        type            fixedValue;";
        "        value		 uniform (0 0 0);";

        "    }";

        "    axis";
        "    {";
        "        type            empty;";
        "    }";

        "    front";
        "    {";
        "        type            wedge;";
        "    }";
        "    back";
        "    {";
        "        type            wedge;";
        "    }";
        "}";

        "// ************************************************************************* //"]
    
        for v_w = 1:length(V_w)
            fprintf(vel_wed, '%s\n', V_w(v_w)); 
        end

end
----------------------------------------------------------------

4) Simulation results:

Comparing the simulation:

4.1)

`10^o` Symmetry Wedge
Velocity
Pressure
Shear

4.2)

`25^o` Symmetry Wedge
Velocity
Pressure
Shear

4.3)

`45^o` Symmetry Wedge
Velocity
Pressure ----Same as above----
Shear ----Same as above----
-------------------------------------------------------------------

5) Comments on the results:

As it can be seen from above there is no substantial difference between the 2 BC's. Except the error given by the wedgeBC for 45degree, This is because the wedge condition is converting 3D to 2D which in case of 45 degree becomes difficult as the volume of cells at the center to the volume of cells at the wall becomes relatively larger. In this case symmetry BC gives results.

Although, there is no large difference between the 2, it is worth noting that even though the accuracy of symmetry BC can be doubtful at smaller wedge angles it is fairly reliable for larger angles.

6) Conclusion:

The comparision between Boundary conditions is done and has given substantial insight into the working of them as well as 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.