/*--------------------------------*- 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;
libs            ("libutilityFunctionObjects.so");

name            generateFields;

codeWrite
#{
    // Create coordinates
    const dimensionedVector ex(dimless, vector(1, 0, 0));
    const dimensionedVector ey(dimless, vector(0, 1, 0));
    const dimensionedVector ez(dimless, vector(0, 0, 1));

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

    const volScalarField rSqr(x*x + y*y + z*z);

    volScalarField potential
    (
        IOobject
        (
            "potential",
            mesh().time().name(),
            mesh(),
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh(),
        dimensionedScalar(dimless, 0)
    );

    potential = 1 - rSqr/max(rSqr);

    potential.write();
#};

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