CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

runtime sample plan: how to get gradP

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   September 16, 2013, 05:22
Default runtime sample plan: how to get gradP
  #1
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 4
Sylv is on a distinguished road
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
Sylv is offline   Reply With Quote

Old   September 16, 2013, 05:48
Default
  #2
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   September 16, 2013, 08:21
Default
  #3
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 4
Sylv is on a distinguished road
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?
Sylv is offline   Reply With Quote

Old   September 16, 2013, 08:26
Default
  #4
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
I think you can access the runTime by something (untested!) like

Code:
const Time& runTime = mesh.time()
Bernhard is offline   Reply With Quote

Old   September 17, 2013, 03:31
Default
  #5
New Member
 
Marcel Vonlanthen
Join Date: Nov 2012
Location: Zurich, Switzerland
Posts: 28
Rep Power: 4
Sylv is on a distinguished road
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 ;-)...
Sylv is offline   Reply With Quote

Old   September 17, 2013, 03:35
Default
  #6
Senior Member
 
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 12
Bernhard is on a distinguished road
Isn't mesh() itself already a reference to the mesh that you need?
Bernhard is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in3D model processing mebinitap OpenFOAM 2 December 12, 2014 05:40
How to sample (with interpolation) at runtime ole OpenFOAM Programming & Development 4 December 14, 2010 13:57
How to sample ptot at runtime pad OpenFOAM Post-Processing 0 August 26, 2010 07:45
heat conducting in a solid domain Rogerio Fernandes Brito FLUENT 0 March 18, 2008 18:25
heat conducting in a solid domain Rogerio Fernandes Brito CFX 0 March 18, 2008 18:20


All times are GMT -4. The time now is 18:55.