/*--------------------------------*- C++ -*----------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | Multiphase Cases Repository by HZDR
  ======   //   ||  || ===//   | Website: https://doi.org/10.14278/rodare.811
  ||  ||  //    ||  // || \\   | License: Creative Commons Attribution 4.0
  ==  == ====== ====   ==  ==  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 0.001; // required for precision reasons

DPipe           #calc "1e3*${${FOAM_CASE}/caseParameterDict!mesh/DPipe}";
LPipe           #calc "1e3*${${FOAM_CASE}/caseParameterDict!mesh/LPipe}";
DOrifice        #calc "1e3*${${FOAM_CASE}/caseParameterDict!mesh/DOrifice}";
TFilm           #calc "1e3*${${FOAM_CASE}/caseParameterDict!mesh/TFilm}";

bottomElevation 0;

// Inner block properties
DiagSquare      #calc "1e3*${${FOAM_CASE}/caseParameterDict!mesh/DiagSquare}";
arcAngle        35;

// Number of cells for one outer block
azimuthalCells  ${${FOAM_CASE}/caseParameterDict!mesh/azimuthalCells};
radialCells1    ${${FOAM_CASE}/caseParameterDict!mesh/radialCells1};
radialCells2    ${${FOAM_CASE}/caseParameterDict!mesh/radialCells2};
radialCells3    ${${FOAM_CASE}/caseParameterDict!mesh/radialCells3};
axialCells      ${${FOAM_CASE}/caseParameterDict!mesh/axialCells};

// Cell grading
radialGrading1  0.5;
radialGrading2  0.6;
radialGrading3  0.1;
axialGrading    1;

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

vertices #codeStream
{
    codeInclude
    #{
        #include "pointField.H"
        #include "transformField.H"
    #};

    code
    #{
        const pointField initPoints
        ({
            point
            (
                $DiagSquare*0.5*cos(degToRad(45)),
                $DiagSquare*0.5*sin(degToRad(45)),
                $bottomElevation
            ),
            point
            (
                $DOrifice*0.5*cos(degToRad(45)),
                $DOrifice*0.5*sin(degToRad(45)),
                $bottomElevation
            ),
            point
            (
                ($DPipe-2*$TFilm)*0.5*cos(degToRad(45)),
                ($DPipe-2*$TFilm)*0.5*sin(degToRad(45)),
                $bottomElevation
            ),
            point
            (
                $DPipe*0.5*cos(degToRad(45)),
                $DPipe*0.5*sin(degToRad(45)),
                $bottomElevation
            ),
        });

        pointField points;

        // Rotate points around z-axis and append
        for (label i = 0; i < 4; i++)
        {
            points.append(transform(Rz(degToRad(i*90)), initPoints));
        }

        // Duplicate z points
        points.append(points + vector(0, 0, $bottomElevation + $LPipe));

        os  << points;
    #};
};

blocks
(
    // block0
    hex (0  4  8  12  16 20 24 28)
    ($azimuthalCells $azimuthalCells $axialCells)
    simpleGrading (1   1 $axialGrading)

    // block1
    hex (0  1  5  4  16 17 21 20)
    ($radialCells1 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading1 1 $axialGrading)

    // block2
    hex (4 5 9 8 20 21 25 24)
    ($radialCells1 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading1 1 $axialGrading)

    // block3
    hex (8 9 13 12 24 25 29 28)
    ($radialCells1 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading1 1 $axialGrading)

    // block4
    hex (12 13 1 0 28 29 17 16)
    ($radialCells1 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading1 1 $axialGrading)

    // block5
    hex (1 2 6 5 17 18 22 21)
    ($radialCells2 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading2 1 $axialGrading)

    // block6
    hex (5 6 10 9 21 22 26 25)
    ($radialCells2 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading2 1 $axialGrading)

    // block7
    hex (9 10 14 13 25 26 30 29)
    ($radialCells2 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading2 1 $axialGrading)

    // block8
    hex (13 14 2 1 29 30 18 17)
    ($radialCells2 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading2 1 $axialGrading)

    // block9
    hex (2 3 7 6 18 19 23 22)
    ($radialCells3 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading3 1 $axialGrading)

    // block10
    hex (6 7 11 10 22 23 27 26)
    ($radialCells3 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading3 1 $axialGrading)

    // block11
    hex (10 11 15 14 26 27 31 30)
    ($radialCells3 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading3 1 $axialGrading)

    // block12
    hex (14 15 3 2 30 31 19 18)
    ($radialCells3 $azimuthalCells $axialCells)
    simpleGrading ($radialGrading3 1 $axialGrading)
);

edges
(
    //Inner square arcs
    arc  0  4 $arcAngle (0 0 1)
    arc 12  0 $arcAngle (0 0 1)
    arc  8 12 $arcAngle (0 0 1)
    arc  4  8 $arcAngle (0 0 1)

    arc 16 20 $arcAngle (0 0 1)
    arc 28 16 $arcAngle (0 0 1)
    arc 24 28 $arcAngle (0 0 1)
    arc 20 24 $arcAngle (0 0 1)

    //Medium circle arcs
    arc  1  5 90        (0 0 1)
    arc 13  1 90        (0 0 1)
    arc  9 13 90        (0 0 1)
    arc  5  9 90        (0 0 1)

    arc 17 21 90        (0 0 1)
    arc 29 17 90        (0 0 1)
    arc 25 29 90        (0 0 1)
    arc 21 25 90        (0 0 1)

    //Second Medium circle arcs
    arc  2  6 90        (0 0 1)
    arc 14  2 90        (0 0 1)
    arc 10 14 90        (0 0 1)
    arc  6 10 90        (0 0 1)

    arc 18 22 90        (0 0 1)
    arc 30 18 90        (0 0 1)
    arc 26 30 90        (0 0 1)
    arc 22 26 90        (0 0 1)

    //Outer circle arcs
    arc  3  7 90        (0 0 1)
    arc 15  3 90        (0 0 1)
    arc 11 15 90        (0 0 1)
    arc  7 11 90        (0 0 1)

    arc 19 23 90        (0 0 1)
    arc 31 19 90        (0 0 1)
    arc 27 31 90        (0 0 1)
    arc 23 27 90        (0 0 1)
);

boundary
(
    inlet_air
    {
        type        patch;
        faces
        (
            ( 4  0 12  8)
            ( 4  5  1  0)
            ( 8  9  5  4)
            (12 13  9  8)
            ( 1 13 12  0)
            ( 5  6  2  1)
            ( 9 10  6  5)
            (13 14 10  9)
            ( 1  2 14 13)
        );
    }

    inlet_water
    {
        type        patch;
        faces
        (
            ( 6  7  3  2)
            (10 11  7  6)
            (14 15 11 10)
            ( 2  3 15 14)
        );
    }

    outlet
    {
        type    patch;
        faces
        (
            (20 16 28 24)
            (20 21 17 16)
            (24 25 21 20)
            (28 29 25 24)
            (16 17 29 28)
            (21 22 18 17)
            (25 26 22 21)
            (29 30 26 25)
            (17 18 30 29)
            (22 23 19 18)
            (26 27 23 22)
            (30 31 27 26)
            (18 19 31 30)
        );
    }

    wall_pipe
    {
        type    wall;
        faces
        (
            (15  3 31 19)
            ( 7 11 23 27)
            (11 15 27 31)
            ( 7  3 23 19)
        );
    }
);

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