/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  6
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0";
    object      k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField   uniform 0;

boundaryField
{
    INLET
    {
        type            codedFixedValue;
        value           uniform 0; //default value
        name            linearTBC_k; //name of new BC type
        code
        #{
            const fvPatch& inletPatch = this->patch();
            
            scalarField& vf = *this; 
            forAll(vf, i)
            { 
                scalar z = inletPatch.Cf()[i].y(); //inletPatch.Cf()[i].y();
                scalar uStar = 0.7486;
                scalar z0 = 0.1;
				scalar zg = 1.2;
                scalar Coriolis = 0.0000558;
				scalar z0_mod = z0*zg/(uStar/6/Coriolis);
				scalar Coriolis_mod = uStar/(6*zg);
				

       
				if(z <= zg)
				{
					scalar para_eta =  1-6*Coriolis_mod*z/uStar;
					scalar para_p = pow(para_eta,16);
					scalar sigma_u = uStar*7.5*para_eta*pow(0.538+0.09*log(z/z0_mod),para_p)/(1+0.156*log(uStar/(Coriolis_mod*z0_mod)));
					scalar sigma_w = sigma_u*(1-0.45*pow(cos(0.5*M_PI*z/zg),4));
					scalar sigma_v = sigma_u*(1-0.22*pow(cos(0.5*M_PI*z/zg),4));
					vf[i] = 0.5*(pow(sigma_u,2)+pow(sigma_w,2)+pow(sigma_v,2));
					//vf[i].y() = -1*cos(3.1416/180*AOA)*uStar/kappa*log((z+z0)/z0);
					//vf[i].z() = 0.0;
				}
				else
				{
					vf[i] = 0
					//vf[i].y() = -1*cos(3.1416/180*AOA)*uStar/kappa*log((z+z0)/z0);
					//vf[i].z() = 0.0;
				}	
			
			}
        #}; 
    }

    OUTLET
    {
        type            zeroGradient;
    }
    TOP
    {
        type            symmetry;
    }
    BOTTOM
    {
        type            kqRWallFunction;
        value           $internalField;
    }
    frontAndBackPlanes
    {
        type            empty;
    }
}


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