CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   runtime sample plan: how to get gradP (http://www.cfd-online.com/Forums/openfoam-programming-development/123552-runtime-sample-plan-how-get-gradp.html)

Sylv September 16, 2013 05:22

runtime sample plan: how to get gradP
 
Dear Foamer,

for a LES run, I would like to extract sample planes of gradP during runtime. For this, I'm using this tool:http://www.openfoam.com/features/run...processing.php. It works perfectly for U or p, but not for gradP, as this variable doesn't exist at runtime. So until now I simply modified pimpleFoam and add the following lines:
Code:

volVectorField gradP
    (
        IOobject
        (
            "gradP",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        fvc::grad(p)
    );

This trick works fine, I can access gradP with the sampling tool during runtime. But as it's not very flexible, I'm wondering if I can use a codeStream in the sample tool? I try the following code, but it did not work. In fact, I don't know the type which codestream should return. a List<word> maybe?
Code:

    type                      surfaces;
    functionObjectLibs        ("libsampling.so");
    outputControl            timeStep;
    outputInterval            1;
    surfaceFormat            vtk;
    fields                    #codeStream 
        code
        #{
            volVectorField gradP
            (
                IOobject
                (
                    "gradP",
                    runTime.timeName(),
                    mesh,
                    IOobject::READ_IF_PRESENT,
                    IOobject::AUTO_WRITE
                ),
                fvc::grad(p)
            );
           
            const wordList sampleFields = ("gradP"); //is that correct?
            os << sampleFields;//is that correct?
        #}
    interpolationScheme      cellPointFace;

Cheers,
Marcel

Bernhard September 16, 2013 05:48

What do you mean with: "it doesn't work"

I think you need to use a coded functionobject to create the field, and then use it in the sampling functionobject.

Sylv September 16, 2013 08:21

Hi Berhnard,

Thanks for your post, it gave me new ideas

As example, I use OF221 and the LES tutorial case "pitzDaily", located in the foam tutorials folder: $FOAM_TUTORIALS/incompressible/pisoFoam/les/pitzDaily

Replace the controlDict by this one:
Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application    pisoFoam;
startFrom      startTime;
startTime      0;
stopAt          endTime;
endTime        0.1;
deltaT          1e-05;
writeControl    timeStep;
writeInterval  100;
purgeWrite      0;
writeFormat    ascii;
writePrecision  6;
writeCompression off;
timeFormat      general;
timePrecision  6;
runTimeModifiable true;

functions
{
    gradP
    {
        functionObjectLibs ("libutilityFunctionObjects.so");
        type coded;
        redirectType average;
        outputControl timeStep;
        code
        #{
            const volScalarField& p = mesh().lookupObject<volScalarField>("p");
            const volVectorField gradP = fvc::grad(p);
            Info << "gradP[0] =" << gradP[0] << endl;
            Info << "gradP[5] =" << gradP[5] << endl;
        #};
    }

    surfaceSampling
    {
        type surfaces;
        functionObjectLibs  ("libsampling.so");
        enabled            true;
        outputControl      timeStep;
        interpolationScheme cellPoint;
        surfaceFormat      foamFile;
        fields              (p gradP);
        surfaces
        (
            plane01
            {
                type                cuttingPlane;
                planeType          pointAndNormal;
                pointAndNormalDict
                {
                    basePoint      (0.001 0.001 0);
                    normalVector    (0 1 0);
                }
                interpolate        true;
            }
        );
    }
}

Then, run pisoFoam for a few timestep. The codeStream Is compiled without errors and writes out the values of gradP[0] and gradP[5]. So, now gardP exists during the run. Nevertheless, the sample tool does not create a cutting plane from gradP. So I remplace the controlDict by this one:
Code:

FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application    pisoFoam;
startFrom      startTime;
startTime      0;
stopAt          endTime;
endTime        0.1;
deltaT          1e-05;
writeControl    timeStep;
writeInterval  100;
purgeWrite      0;
writeFormat    ascii;
writePrecision  6;
writeCompression off;
timeFormat      general;
timePrecision  6;
runTimeModifiable true;
functions
{
    gradP
    {
        functionObjectLibs ("libutilityFunctionObjects.so");
        type coded;
        redirectType average;
        outputControl timeStep;
        code
        #{
            const volScalarField& p = mesh().lookupObject<volScalarField>("p");
            volVectorField gradP
            (
                IOobject
                (
                    "gradP",
                    runTime.timeName(),
                    mesh,
                    IOobject::READ_IF_PRESENT,
                    IOobject::AUTO_WRITE
                ),
                fvc::grad(p)
            );
            Info << "gradP[0] =" << gradP[0] << endl;
            Info << "gradP[5] =" << gradP[5] << endl;
        #};
    }

    surfaceSampling
    {
        type surfaces;
        functionObjectLibs  ("libsampling.so");
        enabled            true;
        outputControl      timeStep;
        interpolationScheme cellPoint;
        surfaceFormat      foamFile;
        fields              (p gradP);
        surfaces
        (
            plane01
            {
                type                cuttingPlane;
                planeType          pointAndNormal;
                pointAndNormalDict
                {
                    basePoint      (0.001 0.001 0);
                    normalVector    (0 1 0);
                }
                interpolate        true;
            }
        );
    }
}

But this codeStream does not compile properly: the object "runTime" of class "Time" does not not exist. I tried to access the existing "runTime" with a kind of lookup function (like for p), but it does not works.

How could I generate the volVectorField gradP, which can be used by the sample tool?

Bernhard September 16, 2013 08:26

I think you can access the runTime by something (untested!) like

Code:

const Time& runTime = mesh.time()

Sylv September 17, 2013 03:31

Hi Foamer,

So Bernhard, I add your line of code:
Code:

const Time& runTime = mesh().time();
which gave me access to the runTime object, so I can call runTime.timeName() for the IOobject. But I still missing the "mesh" object of class "fvMesh". So I tried somthing like:
Code:

const fvMesh& mesh = mesh().lookup("mesh");
or
Code:

const fvMesh& mesh = mesh().Mesh
But both compile with error. So I tried this (copy paste from the solver...):
Code:

fvMesh mesh
            (
                IOobject
                (
                    fvMesh::defaultRegion,
                    runTime.timeName(),
                    runTime,
                    IOobject::MUST_READ
                )
            );

Which compiles without error, but the sample tool cannot generate the gardP slice. It's not really a surprise, because I'm recreating the mesh object without using the existing one created by the solver. So If somebody knows how to access by reference to the mesh object, that could be cool ;-)...

Bernhard September 17, 2013 03:35

Isn't mesh() itself already a reference to the mesh that you need?


All times are GMT -4. The time now is 01:28.