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

application     rheoFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         4;

deltaT          0.00005;

writeControl    runTime;

writeInterval   0.25;

purgeWrite      0;

writeFormat     ascii;

writePrecision  10;

writeCompression compressed;

timeFormat      general;

timePrecision   10;

graphFormat     raw;

runTimeModifiable yes;

adjustTimeStep off;

maxCo          0.1;

maxDeltaT      0.001;

functions
{

 // Monitor for convergence

    probes
    {
        // Where to load it from
        functionObjectLibs ( "libsampling.so" );

        type            probes;

        // Name of the directory for probe data
        name            probes;

        // Write at same frequency as fields
        writeControl   timeStep;
        writeInterval  50;

        // Fields to be probed
        fields
        (
            U
	    p
	    tau
        );

	probeLocations
        (
             (-0.0001 0.00015 -0.000015)
             (0 0.00015 -0.000015)
             (0.0001 0.00015 -0.000015)
        );
    }
    
    QField
    {
	type coded;
	libs            ("libutilityFunctionObjects.so");
        writeControl    writeTime;
        executeControl  writeTime;

	codeExecute
	#{
	    const volVectorField& U = mesh().lookupObject<volVectorField>("U");

            volTensorField gradU(fvc::grad(U));
            volSymmTensorField D(symm(gradU));
            volTensorField W(0.5*(gradU - gradU.T()));

            volScalarField DD(magSqr(D));
            volScalarField WW(magSqr(W));

            volScalarField Q
            (
                IOobject
                (
                    "Q",
                    mesh().time().timeName(),
                    mesh(),
                    IOobject::NO_READ,
                    IOobject::NO_WRITE,
                    false
                ),
                (DD - WW)/(DD + WW + dimensionedScalar("tiny", DD.dimensions(), SMALL))
            );
	    Q.write();
	#};
    }    

    #includeFunc residuals
}
// ************************************************************************* //
