CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Quick How-To: Sample like in sampleDict during runtime (https://www.cfd-online.com/Forums/openfoam-post-processing/176584-quick-how-sample-like-sampledict-during-runtime.html)

HenningW August 22, 2016 04:29

Quick How-To: Sample like in sampleDict during runtime
 
Hi everyone,

I recently tried to sample various data during runtime. Since I never found a satisfying example on how to do it, here is my (commented) source code that I added at the end of my control dict. The example shows a surface and a line, but can be changed to almost anything that you can use in sampleDict as well.

Code:

libs (
    "libOpenFOAM.so"
);
functions
{

// ----------------- Samples a line with equidistant points ------------------

    pos_1250_300_test1 /* Any name you want - will be a subfolder in "postProcessing" */
    {
        functionObjectLibs ("libsampling.so"); /* Below this same structure as in sampleDict until the closing "}" - you have to define each sample for itself, if something differs (e.g. interpolation, otherwise you can use different values in sets*/
        type        sets;
        outputControl            timeStep;
        outputInterval            1;
        setFormat                raw;
        interpolationScheme cellPoint;
        fields
        (
            p U k omega
        );
        sets
        (
            line_plot_1250_300 /* Name of the first line */
            {
                type    uniform;
                axis    xyz;
                start  ( 1.25  0.3      -1.2);
                end    ( 1.25    0.3    1.2);
                nPoints 240;
            }
            line_plot_1250_200 /* Name of the second line */
            {
                type    uniform;
                axis    xyz;
                start  ( 1.25  0.2      -1.2);
                end    ( 1.25    0.2    1.2);
                nPoints 240;
            }
        )
    };


// ----------------- Sample for single point ------------------

    pos_1000_300_0 /* Example for a single point - hence in a new block you can change your properties */
    {
        type probes;
        functionObjectLibs ("libsampling.so");
        probeLocations
        (
            (1 0.3 0)
        );
        fields
        (
            p U
        );
        outputControl timeStep;
        outputInterval 100;
    }

// ----------------- Sample for a plane ------------------

    cuttingPlane
    {
        type            surfaces;
        functionObjectLibs
        (
            "libsampling.so"
        );
        outputControl    timeStep;
        outputInterval    4;
        surfaceFormat  foamFile;
        fields         
        (
            U
        );
        interpolationScheme cellPoint;
        surfaces
            (
                yNormal_OF /* First surface's name */
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    basePoint (0.5 0 0);
                    normalVector (1 0 0);
                }
                interpolate true;
                }
                someOtherSurface /* Second surface's name */
                {
                type cuttingPlane;
                planeType pointAndNormal;
                pointAndNormalDict
                {
                    basePoint (0.5 0 0);
                    normalVector (1 0 0);
                }
                interpolate true;
                }
            );
    }
}

I am not sure if its necessary to include libsampling.so everytime or if this is the most efficient way to do things, but it works for you.

I hope I was able to help you with this short code. Let me know if I messed something up, forgot something or if there is a better tutorial (case) somewhere out there =)

Henning

OlegSutyrin February 7, 2017 04:29

Exactly what I need, thanks!
I've used only line sampling in OF4.0 so far. Small error in the code: there should be semicolon after "sets(...)" inside "pos_1250_300_test1" function.

pvpnrao June 26, 2017 19:12

does it run in parallel?

HenningW July 10, 2017 08:04

Yes, it should run in parallel as well

pvpnrao May 28, 2018 07:55

Point cloud
 
Here is one more sampling function. It provides a point cloud where the points are arranged along Cartesian axes. The fields can be interpolated on these points. I found this function somewhere on OpenFOAMWiki.

I used it to generate data files which I can use in order average the flow-fields along a particular coordinate axes.

//-----3D array of points along Cartesian axes----------------------
my_point_cloud
{
functionObjectLibs ("libsampling.so");
type sets;
outputControl timeStep;
outputInterval 1;
setFormat raw;
interpolationScheme cellPoint;
fields
(
U D
);

sets
(
arrayA1
{
type array;
axis xyz;
coordinateSystem
{
e1 (1 0 0);
e2 (0 1 0);
origin (0 0 0);
}

pointsDensity (2500 200 100);
spanBox (3.5 0.1 0.25);
}
);

}


All times are GMT -4. The time now is 05:17.