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

scale   0.001;

vertices
(
    (  0 28   0)   // 0
    (252 28   0)   // 1
    (252 85   0)   // 2
    (  0 85   0)   // 3

    (  0 28 126)   // 4
    (252 28 126)   // 5
    (252 85 126)   // 6
    (  0 85 126)   // 7
);

blocks
(
    hex (0 1 2 3 4 5 6 7) (200 160 80) simpleGrading (1 ((0.5 0.5 100)(0.5 0.5 0.01)) 1)
);



edges #codeStream
{
    codeInclude
    #{
        #include "pointField.H"
        #include "mathematicalConstants.H"
    #};

    code
    #{
        const scalar xMin = 0;
        const scalar xMax = 252;
        const label nPoints = 1000;
        const scalar dx = (xMax - xMin)/scalar(nPoints - 1);

        os  << "(" << nl << "spline 0 1" << nl;
        pointField profile(nPoints, Zero);

        for (label i = 0; i < nPoints; ++i)
        {
            scalar x = xMin + i*dx;
            profile[i].x() = x;
            if (x > 198) x = 252 - x;

            if (x >= 0 && x < 9)
            {
                profile[i].y() =
                    28
                  + 6.775070969851E-03*x*x
                  - 2.124527775800E-03*x*x*x;
            }
            else if (x >= 9 && x < 14)
            {
                profile[i].y() =
                    25.07355893131
                  + 0.9754803562315*x 
                  - 1.016116352781E-01*x*x 
                  + 1.889794677828E-03*x*x*x;
            }
            else if (x >= 14 && x < 20)
            {
                profile[i].y() =
                    2.579601052357E+01
                  + 8.206693007457E-01*x
                  - 9.055370274339E-02*x*x
                  + 1.626510569859E-03*x*x*x;
            }
            else if (x >= 20 && x < 30)
            {
                profile[i].y() =
                    4.046435022819E+01
                  - 1.379581654948E+00*x
                  + 1.945884504128E-02*x*x
                  - 2.070318932190E-04*x*x*x;
            }
            else if (x >= 30 && x < 40)
            {
                profile[i].y() =
                    1.792461334664E+01
                  + 8.743920332081E-01*x
                  - 5.567361123058E-02*x*x
                  + 6.277731764683E-04*x*x*x;
            }
            else if (x >= 40 && x < 54)
            {
                profile[i].y() =
                    max
                    (
                        0,
                        5.639011190988E+01
                      - 2.010520359035E+00*x
                      + 1.644919857549E-02*x*x
                      + 2.674976141766E-05*x*x*x
                    );
            }
            profile[i].z() = 0;
        }
        os << profile << nl;

        os << "spline 4 5" << nl;
        profile.replace(2, 126);
        os << profile << nl;

        os  << ");" << nl;
    #};
};

boundary
(
    inlet
    {
        type            cyclic;
        neighbourPatch  outlet;
        faces
        (
            (0 4 7 3)
        );
    }
    outlet
    {
        type            cyclic;
        neighbourPatch  inlet;
        faces
        (
            (1 2 6 5)
        );
    }
    top
    {
        type            wall;
        faces
        (
            (3 7 6 2)
        );
    }
    hills
    {
        type            wall;
        faces
        (
            (1 5 4 0)
        );
    }
    front
    {
        type            cyclic;
        neighbourPatch  back;
        faces
        (
            (0 3 2 1)
        );
    }
    back
    {
        type            cyclic;
        neighbourPatch  front;
        faces
        (
            (4 5 6 7)
        );
    }
);

mergePatchPairs
(
);

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