/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     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
{
    top
    {
        type            codedFixedValue;
		value           uniform (0 0 0);           // Initial value
		name            codedPathBC;               // Custom name for the boundary condition
		
		code
		#{
			const scalar minX = 0.0;  // Minimum x-coordinate of the patch
			const scalar maxX = 1.0;  // Maximum x-coordinate of the patch
			// Looping through each face of the boundary patch
			forAll(this->patch().Cf(), faceI) 
			{
				// x-coordinate of the face center
				const scalar x = this->patch().Cf()[faceI].x();
				scalar velocity_linear  = (x - minX) / (maxX - minX);  // Linear variation
				vector U(velocity_linear , 0, 0);  // Velocity vector
				// Assign the velocity to the boundary face
				operator[](faceI) = U;
			}
		#};
    }
    bottom
    {
        type            noSlip;
    }
    leftAndright
    {
        type            noSlip;
    }
    frontAndBack
    {
        type            empty;
    }
}

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