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

// User parameters
scale    1;
refLevel 4;

// Geometric parameters
rInner  0.05;
rOuter  0.1;
xmin    -0.2;
xmax    2;
ymax    0.21;
zmin   -0.2;  // Back/front locations
zmax    0.21;

gradx  2.0;
gradr  2.0;

// Divisions: Radial, quarter circumference, outer region and z-directions.
nRadial       ${{ $refLevel * 5  }};
nQuarter      ${{ $refLevel * 5  }};
nxOuterLeft   ${{ $refLevel * 5  }};
nxOuterRight  ${{ $refLevel * 40 }};
nyOuter       ${{ $refLevel * 5  }};
nz            ${{ $refLevel * 15 }};

// ----------------

// Derived quantities
hRatio      0.952380952380952;
rInner45    ${{ $rInner * sqrt(0.5) }};
rOuter45    ${{ $rOuter * sqrt(0.5) }};

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

    code
    #{
        pointField points
        ({
            /* 0*/ { $rInner, 0, $zmin },
            /* 1*/ { $rOuter, 0, $zmin },
            /* 2*/ { $xmax, 0, $zmin },
            /* 3*/ { $xmax, $rOuter45, $zmin },
            /* 4*/ { $rOuter45, $rOuter45, $zmin },
            /* 5*/ { $rInner45, $rInner45, $zmin },
            /* 6*/ { $xmax, $ymax, $zmin },
            /* 7*/ { $rOuter45, $ymax, $zmin },
            /* 8*/ { 0, $ymax, $zmin },
            /* 9*/ { 0, $rOuter, $zmin },
            /*10*/ { 0, $rInner, $zmin },
            /*11*/ { -$rInner, 0, $zmin },
            /*12*/ { -$rOuter, 0, $zmin },
            /*13*/ { $xmin, 0, $zmin },
            /*14*/ { $xmin, $rOuter45, $zmin },
            /*15*/ { -$rOuter45, $rOuter45, $zmin },
            /*16*/ { -$rInner45, $rInner45, $zmin },
            /*17*/ { $xmin, $ymax, $zmin },
            /*18*/ { -$rOuter45, $ymax, $zmin }
        });

        // Duplicate z points for zmax
        {
            const label sz = points.size();
            points.resize(2*sz);
            for (label i = 0; i < sz; ++i)
            {
                const point& pt = points[i];
                points[i + sz] = point(pt.x(), pt.y(), $zmax);
            }
        }

        // Duplicate (x,y,z) points for the lower half plane
        {
            const label sz = points.size();
            const label newsz = 2*sz - 2*6;
            Info << newsz << nl;
            points.resize(newsz);
            label counter = 0;
            for (label i = 0; i < sz; ++i)
            {
                const point& pt = points[i];
                if (pt.y() != 0)
                {
                    points[sz + counter] = point(pt.x(), -$hRatio*pt.y(), pt.z());
                    counter++;
                }
            }
        }

        os  << points;
    #};
};

// Can remove unneeded variables
#remove ( "r(Inner|Outer).*"  "[xy](min|max)" )

blocks
(
    // block upper
    hex (5 4 9 10 24 23 28 29)    ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (0 1 4 5 19 20 23 24)     ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (1 2 3 4 20 21 22 23)     ($nxOuterRight $nQuarter $nz) simpleGrading ($gradx 1 1)
    hex (4 3 6 7 23 22 25 26)     ($nxOuterRight $nyOuter  $nz) simpleGrading ($gradx 1 1)
    hex (9 4 7 8 28 23 26 27)     ($nQuarter     $nyOuter  $nz) simpleGrading (1 1 1)
    hex (10 9 15 16 29 28 34 35)  ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (16 15 12 11 35 34 31 30) ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (13 12 15 14 32 31 34 33) ($nxOuterLeft  $nQuarter $nz) simpleGrading (1 1 1)
    hex (14 15 18 17 33 34 37 36) ($nxOuterLeft  $nyOuter  $nz) simpleGrading (1 1 1)
    hex (15 9 8 18 34 28 27 37)   ($nQuarter     $nyOuter  $nz) simpleGrading (1 1 1)
    // blocks lower
    hex (40 39 1 0 53 52 20 19)   ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (11 12 47 48 30 31 60 61) ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (39 38 2 1 52 51 21 20)   ($nxOuterRight $nQuarter $nz) simpleGrading ($gradx 1 1)
    hex (42 41 38 39 55 54 51 52) ($nxOuterRight $nyOuter  $nz) simpleGrading ($gradx 1 1)
    hex (46 47 12 13 59 60 31 32) ($nxOuterLeft  $nQuarter $nz) simpleGrading (1 1 1)
    hex (49 50 47 46 62 63 60 59) ($nxOuterLeft  $nyOuter  $nz) simpleGrading (1 1 1)
    hex (50 43 44 47 63 56 57 60) ($nQuarter     $nyOuter  $nz) simpleGrading (1 1 1)
    hex (43 42 39 44 56 55 52 57) ($nQuarter     $nyOuter  $nz) simpleGrading (1 1 1)
    hex (48 47 44 45 61 60 57 58) ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
    hex (45 44 39 40 58 57 52 53) ($nRadial      $nQuarter $nz) edgeGrading ($gradr $gradr $gradr $gradr 1 1 1 1 1 1 1 1)
);

edges
(
    // Inner cylinder (top)
    arc  0  5 origin (0 0 $zmin)
    arc  5 10 origin (0 0 $zmin)
    arc  1  4 origin (0 0 $zmin)
    arc  4  9 origin (0 0 $zmin)
    arc 19 24 origin (0 0 $zmax)
    arc 24 29 origin (0 0 $zmax)
    arc 20 23 origin (0 0 $zmax)
    arc 23 28 origin (0 0 $zmax)
    // Intermediate cylinder (top)
    arc 11 16 origin (0 0 $zmin)
    arc 16 10 origin (0 0 $zmin)
    arc 12 15 origin (0 0 $zmin)
    arc 15  9 origin (0 0 $zmin)
    arc 30 35 origin (0 0 $zmax)
    arc 35 29 origin (0 0 $zmax)
    arc 31 34 origin (0 0 $zmax)
    arc 34 28 origin (0 0 $zmax)
    // Inner cylinder (bottom) 
    arc  0 40 origin (0 0 $zmin)
    arc 40 45 origin (0 0 $zmin)
    arc  1 39 origin (0 0 $zmin)
    arc 39 44 origin (0 0 $zmin)
    arc 19 53 origin (0 0 $zmax)
    arc 53 58 origin (0 0 $zmax)
    arc 20 52 origin (0 0 $zmax)
    arc 52 57 origin (0 0 $zmax)
    // Intermediate cylinder (bottom)
    arc 11 48 origin (0 0 $zmin)
    arc 48 45 origin (0 0 $zmin)
    arc 12 47 origin (0 0 $zmin)
    arc 47 44 origin (0 0 $zmin)
    arc 30 61 origin (0 0 $zmax)
    arc 61 58 origin (0 0 $zmax)
    arc 31 60 origin (0 0 $zmax)
    arc 60 57 origin (0 0 $zmax)
);

boundary
(
    bottom
    {
        type wall;
        faces
        (
            (49 50 63 62)
            (50 43 56 63)
            (43 42 55 56)
            (42 41 54 55)
        );
    }
    outlet
    {
        type patch;
        faces
        (
            (2 3 22 21)
            (3 6 25 22)
            (2 38 51 21)
            (38 41 54 51)
        );
    }
    top
    {
        type wall;
        faces
        (
            (7 8 27 26)
            (6 7 26 25)
            (8 18 37 27)
            (18 17 36 37)
        );
    }
    inlet
    {
        type patch;
        faces
        (
            (14 13 32 33)
            (17 14 33 36)
            (13 46 59 32)
            (46 49 62 59)
        );
    }
    cylinder
    {
        type wall;
        faces
        (
            (10 5 24 29)
            (5 0 19 24)
            (16 10 29 35)
            (11 16 35 30)
            (11 48 61 30)
            (48 45 58 61)
            (45 40 53 58)
            (40 0 19 53)
        );
    }
    backAndFront
    {
        // type empty; // 2D
        type wall; // 3D
        faces
        (
            // front
            (1 2 3 4)
            (4 3 6 7)
            (9 4 7 8)
            (15 9 8 18)
            (14 15 18 17)
            (13 12 15 14)
            (12 11 16 15)
            (16 10 9 15)
            (10 5 4 9)
            (5 0 1 4)
            (39 38 2 1)
            (42 41 38 39)
            (43 42 39 44)
            (50 43 44 47)
            (49 50 47 46)
            (46 47 12 13)
            (47 48 11 12)
            (47 44 45 48)
            (44 39 40 45)
            (40 39 1 0)
            // back
            (20 21 22 23)
            (23 22 25 26)
            (28 23 26 27)
            (34 28 27 37)
            (33 34 37 36)
            (32 31 34 33)
            (31 30 35 34)
            (35 29 28 34)
            (29 24 23 28)
            (24 19 20 23)
            (52 51 21 20)
            (55 54 51 52)
            (56 55 52 57)
            (63 56 57 60)
            (62 63 60 59)
            (59 60 31 32)
            (60 61 30 31)
            (60 57 58 61)
            (57 52 53 58)
            (52 20 19 53)
        );        
    }
);

mergePatchPairs
(
);


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