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

application     buoyantSimpleFoam;

startFrom       latestTime;

startTime       0;

stopAt          endTime;

endTime         8000;

deltaT          1;

writeControl    timeStep;

writeInterval   2000;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable true;

functions
{
    setDeltaT
    {
        type coded;
        libs            ("libutilityFunctionObjects.so");

        code
        #{
        #};

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

            const fvPatchList& patches = mesh().boundary();

            forAll(patches, patchi)
            {
                const fvPatch& currPatch = patches[patchi];

                if (mesh().time().value() == 8000)
                {
                    if (currPatch.name() == "downwall")
                    {
                        scalarField nus = T.boundaryField()[patchi];

                        scalar L = 0.014231;
                        scalar Tref = 309.1;
                        scalar Timp = 347.6;
                        
                        nus = T.boundaryField()[patchi].snGrad()*L/(Timp - Tref);
                        //Info<< T.boundaryField()[patchi].snGrad() << nl;

                        forAll(T.boundaryField()[patchi], facei)
                        {
                            Pout << mesh().C().boundaryField()[patchi][facei].x()/0.014231
                                 << " " << nus[facei] << nl;
                        }
                    }
                }
            }

            //const Time& runTime = mesh().time();
            //if (runTime.timeToUserTime(runTime.value()) >= -15.0)
            //{
            //    const_cast<Time&>(runTime).setDeltaT
            //    (
            //        runTime.userTimeToTime(0.025)
            //    );
            //}
        #};
    }
}


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