/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     scalarTransportFoam;

libs            ("libuqtopusPolicy.so");

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         30;

deltaT          0.01;

writeControl    timeStep;

writeInterval   300;

purgeWrite      0;

writeFormat     ascii;

writePrecision  8;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;

functions
{
    probes
    {
        type            probes;
        libs            ("libsampling.so");
        writeControl    timeStep;
        writeInterval   10;
        fields          (T);
        probeLocations  ((0.05 0.05 0.0008));
    }

    // Mean temperature over the plate, read by the policy as a RegistrySource under this name.
    // This registered name must match the C++ IOobject, the lookupObjectRef, and the policy specification.
    plateMean
    {
        type            coded;
        libs            ("libutilityFunctionObjects.so");

        codeInclude
        #{
            #include "uniformDimensionedFields.H"
        #};

        codeRead
        #{
            if (!mesh().foundObject<uniformDimensionedScalarField>("plateMean"))
            {
                uniformDimensionedScalarField* mean = new uniformDimensionedScalarField
                (
                    IOobject("plateMean", mesh().time().constant(), mesh()),
                    dimensionedScalar("plateMean", dimTemperature, 0)
                );
                mean->store();
            }
        #};

        codeExecute
        #{
            const volScalarField& T = mesh().lookupObject<volScalarField>("T");

            mesh().lookupObjectRef<uniformDimensionedScalarField>("plateMean").value() =
                gSum(T.primitiveField()*mesh().V())/gSum(mesh().V());
        #};
    }
}

{{ controller }}


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