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

// scaling to desired chord length, 1.0 means Lchord = 1m
scale       1.0;

// max coordinate in the streamwise direction (relative to Lchord)
xMax        10;
    
// radial extent of domain (relative to Lchord)
rMax        10;

// anker points of aerofoil at leading and trailing edges
xLead       0;
zLead       0;
xTrail      1;
zTrail      0;

// anker points for middle block
xUpper      0.3;
zUpper      0.06;
xLower      0.3;
zLower      -0.06;

// spacings
dxLE        0.0005;   // at leading edge
dxMidUp     0.0025;   // at middle of aerofoil (upper surface)
dxMidLow    0.05;     // at middle of aerofoil (lower surface)
dxTE        0.002;    // at trailing edge
dzaerofoil  0.00002;  // near-wall spacing at airfoil
dy          $dxTE;    // spanwise spacing

// compute number of cells and total cell spacing in the radial direction (from aerofoil to far-field)
zCells      64; 
zGrading    82205.8;

// compute number of cells and total cell spacing in the streamwise direction 
// from leading edge to middle of aerofoil (upper surface)
xUUpCells   241;
leadUpGrading 0.2;

// compute number of cells and total cell spacing in the streamwise direction 
// from leading edge to middle of aerofoil (lower surface)
xULowCells  26; 
leadLowGrading 0.01;

// compute number of cells and total cell spacing in the streamwise direction 
// from trailing edge to middle of aerofoil (upper surface)
xMUpCells   312;
xMUpGrading 1.25;

// compute number of cells and total cell spacing in the streamwise direction
// from trailing edge to middle of aerofoil (lower surface)
xMLowCells  46;
xMLowGrading 25;

// compute number of cells and total cell spacing in the streamwise direction (from trailing edge to outlet, centreline)
xDCells     38;
xDGrading   831.626;

// compute total cell spacing in the streamwise direction
// from far-field inlet to middle of airfoil (lower surface)
xUffLowGrading 0.051377;

// compute total cell spacing in the streamwise direction
// from middle of airfoil to trailing edge (lower surface)
xMffLowGrading 7.54248;

// compute total cell spacing in the streamwise direction 
// from trailing edge to far-field outlet (upper surface)
xDffUpGrading 32.5263;

// compute total cell spacing in the streamwise direction
// from trailing edge to far-field outlet (lower surface)
xDffLowGrading 8.68445;

// min/max coordinates in the spanwise direction (relative to Lchord)
yMin        -0.002;
yMax        0.002;

// number of cells in the spanwise direction (y)
yCells      2;


geometry
{
    aerofoil
    {
        type   triSurfaceMesh;
        file   "NACA4412.stl";
    }
    cylinder
    {
        type   cylinder;
        point1 ($xTrail -1e3 0);
        point2 ($xTrail  1e3 0);
        radius $rMax;
    }
}

vertices
(
    // all vertices on yMin-plane
            (
                #eval{$xTrail - sin(degToRad((1.0-$xLower)*90))*$rMax}
                $yMin
                #eval{$zTrail - cos(degToRad((1.0-$xLower)*90))*$rMax}
            )   // v 0
            ($xTrail                  $yMin #eval{ $zLead - $rMax })              // v 1
            (#eval{ $xTrail + $xMax } $yMin #eval{ $zLead - $rMax })              // v 2
    project (#eval{ $xLead-$rMax }    $yMin $zLead                 ) (cylinder)   // v 3
    project ($xLead                   $yMin $zLead                 ) (aerofoil)   // v 4
    project ($xTrail                  $yMin $zTrail                ) (aerofoil)   // v 5
            (#eval{ $xTrail + $xMax } $yMin $zTrail                )              // v 6
    project ($xLower                  $yMin $zLower                ) (aerofoil)   // v 7
    project ($xUpper                  $yMin $zUpper                ) (aerofoil)   // v 8
            (
                #eval{$xTrail - sin(degToRad($xMUpCells*90/($xUUpCells+$xMUpCells)))*$rMax} 
                $yMin 
                #eval{$zTrail + cos(degToRad($xMUpCells*90/($xUUpCells+$xMUpCells)))*$rMax}
            )   // v 9
    project ($xTrail                  $yMin #eval{ $zLead + $rMax }) (aerofoil)   // v 10
            (#eval{ $xTrail + $xMax } $yMin #eval{ $zLead + $rMax })              // v 11

    // all vertices on yMax-plane
            (
                #eval{$xTrail - sin(degToRad((1.0-$xLower)*90))*$rMax}
                $yMax
                #eval{$zTrail - cos(degToRad((1.0-$xLower)*90))*$rMax}
            )   // v 12
            ($xTrail                  $yMax #eval{ $zLead - $rMax })              // v 13
            (#eval{ $xTrail + $xMax } $yMax #eval{ $zLead - $rMax })              // v 14
    project (#eval{ $xLead-$rMax }    $yMax $zLead                 ) (cylinder)   // v 15
    project ($xLead                   $yMax $zLead                 ) (aerofoil)   // v 16
    project ($xTrail                  $yMax $zTrail                ) (aerofoil)   // v 17
            (#eval{ $xTrail + $xMax } $yMax $zTrail                )              // v 18
    project ($xLower                  $yMax $zLower                ) (aerofoil)   // v 19
    project ($xUpper                  $yMax $zUpper                ) (aerofoil)   // v 20
            (
                #eval{$xTrail - sin(degToRad($xMUpCells*90/($xUUpCells+$xMUpCells)))*$rMax}
                $yMax
                #eval{$zTrail + cos(degToRad($xMUpCells*90/($xUUpCells+$xMUpCells)))*$rMax}
            )   // v 21
    project ($xTrail                  $yMax #eval{ $zLead + $rMax }) (aerofoil)   // v 22
            (#eval{ $xTrail + $xMax } $yMax #eval{ $zLead + $rMax })              // v 23
);

blocks
(
    // block 0
    hex ( 7 4 16 19 0 3 15 12)
    ($xULowCells $yCells $zCells)
    edgeGrading
    (
        $leadLowGrading $leadLowGrading $xUffLowGrading $xUffLowGrading
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )
 
    // block 1
    hex ( 5 7 19 17 1 0 12 13)
    ($xMLowCells $yCells $zCells)
    edgeGrading
    (
        $xMLowGrading $xMLowGrading $xMffLowGrading $xMffLowGrading
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )

    // block 2
    hex ( 17 18 6 5 13 14 2 1)
    ($xDCells $yCells $zCells)
    edgeGrading
    (
        $xDGrading $xDGrading $xDffLowGrading $xDffLowGrading
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )

    // block 3
    hex ( 20 16 4 8 21 15 3 9)
    ($xUUpCells $yCells $zCells)
    edgeGrading
    (
        $leadUpGrading $leadUpGrading 1 1
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )

    // block 4
    hex ( 17 20 8 5 22 21 9 10)
    ($xMUpCells $yCells $zCells)
    edgeGrading
    (
        $xMUpGrading $xMUpGrading 1 1
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )

    // block 5
    hex ( 5 6 18 17 10 11 23 22)
    ($xDCells $yCells $zCells)
    edgeGrading
    (
        $xDGrading $xDGrading $xDffUpGrading $xDffUpGrading
        1 1 1 1
        $zGrading $zGrading $zGrading $zGrading
    )
);

edges
(
    project 4  7  (aerofoil)
    project 7  5  (aerofoil)
    project 4  8  (aerofoil)
    project 8  5  (aerofoil)

    project 16 19 (aerofoil)
    project 19 17 (aerofoil)
    project 16 20 (aerofoil)
    project 20 17 (aerofoil)

    project 3  0  (cylinder)
    project 3  9  (cylinder)
    project 15 12 (cylinder)
    project 15 21 (cylinder)

    project 0  1  (cylinder)
    project 9  10 (cylinder)
    project 12 13 (cylinder)
    project 21 22 (cylinder)
);

boundary
(
    aerofoil
    {
        type wall;
        faces
        (
            (4 7 19 16)
            (7 5 17 19)
            (5 8 20 17)
            (8 4 16 20)
        );
    }

    inlet
    {
        type patch;
        faces
        (
            (3 0 12 15)
            (0 1 13 12)
            (1 2 14 13)
            (11 10 22 23)
            (10 9 21 22)
            (9 3 15 21)
        );
    }

    outlet
    {
        type patch;
        faces
        (
            (2 6 18 14)
            (6 11 23 18)
        );
    }

    yPeriodic_half0
    {
        type            cyclic;
        neighbourPatch  yPeriodic_half1;
        faces
        (
            (3 4 7 0)
            (7 5 1 0)
            (5 6 2 1)
            (3 9 8 4)
            (9 10 5 8)
            (10 11 6 5)
        );
    }

    yPeriodic_half1
    {
        type            cyclic;
        neighbourPatch  yPeriodic_half0;
        faces
        (
            (15 16 19 12)
            (19 17 13 12)
            (17 18 14 13)
            (15 16 20 21)
            (20 17 22 21)
            (17 18 23 22)
        );
    }
);


// Cleanup
#remove ( domain aerofoil )

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