/*--------------------------------*- 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      generateAlphas;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

type            coded;

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

name            generateAlphas;

codeWrite
#{
    const dimensionedVector dx(dimless/dimLength, vector(0, 1, 0));

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

    const scalar x0 = 0.1, x1 = 0.4, x2 = 0.6, x3 = 0.9;

    const volScalarField x01((x - x0)/(x1 - x0));
    const volScalarField x23((x - x3)/(x2 - x3));

    const volScalarField f
    (
        pos(x - x0)*pos(x1 - x)*(-2.0*pow3(x01) + 3.0*sqr(x01))
      + pos(x - x1)*pos(x2 - x)
      + pos(x - x2)*pos(x3 - x)*(-2.0*pow3(x23) + 3.0*sqr(x23))
    );

    volScalarField airC
    (
        IOobject
        (
            IOobject::groupName("alpha", "airC"),
            mesh().time().name(),
            mesh(),
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mesh(),
        dimensionedScalar(dimless, Zero)
    );
    airC = 0.9*f;
    airC.write();

    volScalarField waterC
    (
        IOobject
        (
            IOobject::groupName("alpha", "waterC"),
            mesh().time().name(),
            mesh(),
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mesh(),
        dimensionedScalar(dimless, Zero)
    );
    waterC = 1.0 - 0.9*f;
    waterC.write();
#};

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