/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | foam-extend: Open Source CFD                    |
|  \\    /   O peration     | Version:     4.1                                |
|   \\  /    A nd           | Web:         http://www.foam-extend.org         |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volVectorField;
    object      U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    inlet
    {
        type            codedFixedValue;
        name            pulse;
        value           uniform (0 0 0);

        code
        #{
            const fvMesh& mesh = patch().boundaryMesh().mesh();
            const scalar t = mesh.time().value();

            const scalar pi = constant::mathematical::pi;
            const scalar R  = 0.015;  // radius [m]
            const scalar R2 = R*R;
            const scalar area = pi * R2;  // area [m2]
            const scalar qmax = 2.75e-4;  // [m3/s]
            const scalar umax = 2.0*qmax/area;
            const scalar Ts = 0.4;  // systole time [sec]
            const scalar Td = 0.6;  // diastole time [sec]
            const scalar Tp = Ts + Td;  // cardiac cycle time [sec]

            const scalar tfrac = fmod(t,Tp);
//          const scalar factor = (tfrac>Ts ? 0.0 : umax*sin((2.0*pi)/(2.0*Ts)*tfrac));
            const scalar factor = (tfrac>Ts ? 0.0 : umax*sin(pi/Ts*tfrac));

            vectorField ans(patch().size(), Zero);
            forAll(ans, fi)
            {
                ans[fi].z() = umax * factor
                                  * (1.0 - (pow(patch().Cf()[fi].x(),2.0)
                                           +pow(patch().Cf()[fi].y(),2.0))/R2 );
            }
            operator==(ans);
        #};
    }

    outlet
    {
        type            zeroGradient;
    }

    walls
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }

}

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