/*--------------------------------*- C++ -*----------------------------------*\
  ==  == ====== ====   ====    |
                    \\     ||  | Multiphase Cases Repository by HZDR
  ======   //   ||  || ===//   | Website: https://doi.org/10.14278/rodare.811
  ||  ||  //    ||  // || \\   | License: Creative Commons Attribution 4.0
  ==  == ====== ====   ==  ==  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    object      generateFields;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

type            coded;

libs            ("libutilityFunctionObjects.so");

name            generateFields;

codeWrite
#{
    #include <cmath>

    // Create coordinates
    const dimensionedVector ex(inv(dimLength), vector(1, 0, 0));
    const dimensionedVector ey(inv(dimLength), vector(0, 1, 0));

    const volScalarField x(mesh().C() & ex);
    const volScalarField y(mesh().C() & ey);

    const volScalarField r = sqrt(x*x + y*y);

    // Read fields
    volVectorField UGasC
    (
        IOobject
        (
            IOobject::groupName("U", "gasC"),
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh()
    );

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

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

    const volScalarField alphaGasC
    (
        IOobject
        (
            IOobject::groupName("alpha", "gasC"),
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        ),
        mesh()
    );

    const volScalarField alphaLiquidC
    (
        IOobject
        (
            IOobject::groupName("alpha", "liquidC"),
            mesh().time().name(),
            mesh(),
            IOobject::MUST_READ,
            IOobject::NO_WRITE
        ),
        mesh()
    );

    // Calculate fields
    UGasC.replace
    (
        vector::Z,
        alphaLiquidC*(-18086515*r*r + 236891*r - 772)
      + alphaGasC*(58-1270053*r*r)
    );
    ULiquidC = UGasC;
    ULiquidD = UGasC;

    // Write Fields
    UGasC.write();
    ULiquidC.write();
    ULiquidD.write();
#};

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