/*--------------------------------*- C++ -*----------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | Multiphase Code Repository by HZDR
  ======   //   ||  || ===//   | Website: https://doi.org/10.14278/rodare.767
  ||  ||  //    ||  // || \\   | License: GPL-3.0-or-later
  ==  == ====== ====   ==  ==  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      generateFields;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

type            coded;

// Load the library containing the 'coded' functionObject
libs            ("libutilityFunctionObjects.so");

name            generateFields;

codeWrite
#{
    // Create coordinates
    const dimensionedVector dx(inv(dimLength), vector(1, 0, 0));
    const dimensionedVector dy(inv(dimLength), vector(0, 1, 0));

    const volScalarField x(mesh().C() & dx);
    const volScalarField y(mesh().C() & dy);

    // Read fields
    volScalarField p_rgh
    (
        IOobject
        (
            "p_rgh",
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh()
    );

    volVectorField Ugas1
    (
        IOobject
        (
            IOobject::groupName("U", "gas1"),
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh()
    );

    volVectorField Ugas2
    (
        IOobject
        (
            IOobject::groupName("U", "gas2"),
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh()
    );

    // Calculate fields
    p_rgh = -0.25*(cos(2*x) + cos(2*y))*dimensionedScalar(dimPressure, 1);

    Ugas1.replace(vector::X, cos(x)*sin(y));
    Ugas1.replace(vector::Y, -sin(x)*cos(y));

    Ugas2 = Ugas1;

    // Write Fields
    p_rgh.write();
    Ugas1.write();
    Ugas2.write();
#};

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