CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Time averaged fields on a defined time range (http://www.cfd-online.com/Forums/openfoam-post-processing/107610-time-averaged-fields-defined-time-range.html)

Yann October 2, 2012 12:44

Time averaged fields on a defined time range
 
Hi FOAMers,

Here is my problem : I have transient RANS simulations of a two-phase flow (using VOF method) and I would like to calculate the time averaged fields on a defined time range, let's say from t=50s to t=100s.
How can I do that ?

In paraView, the temporalStatistics filter achieve this task but only for all time steps and I cannot specify my own time range.

In OpenFOAM, I tried to use the fieldAverage utility from the fieldFunctionObjects library, using this code in my controlDict :

Code:

fieldAverage1
    {
        type                    fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled                true;
        outputControl        outputTime;
 
        fields
        (
            U
            {
                mean          on;
                prime2Mean  on;
                base          time;
            }
 
            alpha1
            {
                mean          on;
                prime2Mean  on;
                base          time;
            }
        );
    }

When I re-run a part of my simulation with this function enabled, it works well. In the "case/timeStep/uniform/fieldAveragingProperties" file, the "totalTime" corresponds to the time from the start of the function and it grows accordingly to time steps which is totally logical. The averaged fields seem ok too.

But my problem is to use this function on cases already done.
Using execFlowFunctionObjects with the -noFlow option, I am able to run it after the end of my simulation, but it seems the mean variables written on each time steps start over and don't use the previous values.
For each time step, i have the same "totalTime" values in the "fieldAveragingProperties".

Does anybody have already experienced that kind of problem ? Did I miss a trick somewhere ?

More generally, wanting an averaged field on a defined time range doesn't sound so exotic... Is there somebody who know how to do that in OpenFOAM or paraView ?

Thank you,
Yann

Bernhard October 3, 2012 01:58

I don't know which version of OpenFOAM you are using, but fieldAverage later got some additional options:
- resetOnOutput
- timeStart
- timeEnd

See also: http://www.openfoam.org/mantisbt/view.php?id=290

Yann October 3, 2012 10:00

Thank you Benhard for your reply. I'm using OF 2.1.0 and I wasn't aware of these additional options which are really useful to control run-time post-processing.

I tried to dig into this problem by testing some things on the damBreak case. I just ran it from 0 to 5s and I set a fieldAverage from 2s to the end thanks to the timeStart and timeEnd options. Here is an extract of my controlDict.

Code:

application    interFoam;
startFrom      startTime;
startTime      0;
stopAt          endTime;
endTime        5;
deltaT          0.001;
writeControl    adjustableRunTime;
writeInterval  0.1;

runTimeModifiable yes;
adjustTimeStep  on;

functions
    {

    fieldAverage1
        {
            type                    fieldAverage;
            functionObjectLibs ( "libfieldFunctionObjects.so" );
            enabled              true;
            outputControl      outputTime;
            timeStart            2;
            timeEnd              5;
            resetOnOutput    false;
               
            fields
            (
                U
                {
                    mean          on;
                    prime2Mean  on;
                    base          time;
                }

                alpha1
                {
                    mean          on;
                    prime2Mean  on;
                    base          time;
                }
            );
        }
    }

The fieldAverage works very well and the mean variables start to be calculated at t=2s, as expected.
Here is what I have in the fieldAveragingProperties of the last timestep :

Code:

U
{
    totalIter        275;
    totalTime      3.00798;
}

alpha1
{
    totalIter        275;
    totalTime      3.00798;
}

The mean variables of the last timestep are calculated on t=5-2=3s, which is exactly what I wanted.

Now, I run the same simulation without fieldAverage and I try to run it as a post-processing tool after the end of my simulation thanks to this command :

Code:

execFlowFunctionObjects -noFlow
The mean variables are actually calculated from t=2 to 5s, but there is something wrong with the calculation. If I look in the fieldAveragingProperties of the last timestep, I find that :

Code:

U
{
    totalIter      2;
    totalTime      0.0285714;
}

alpha1
{
    totalIter      2;
    totalTime      0.0285714;
}

The mean variables aren't calculated with the whole time range but only the last timesteps. As I have 30 saved timesteps from 2 to 5s, i would expect to have mean variables calculated on 30 iterations with a totalTime of 3s.

Am I having a wrong use of the execFlowFunctionObjects ? Should I use or don't use some options ? Or is the fieldAverage function unable to work after the simulation run ?

GerhardHolzinger October 3, 2012 10:36

Quote:

Originally Posted by Yann (Post 384572)
But my problem is to use this function on cases already done.

Hello,

to use functionObjects on cases already finished there is also this:

http://www.cfd-online.com/Forums/ope...revisited.html

However, this seems quite similar to execFlowFunctionsObjects.

Yann October 4, 2012 14:01

Thank you Gerhard.
I've run some tests with your utility and I still have an issue on my averaged fields compared to run-time post-processing with fieldAverage.

I run the damBreak case from t=0 to 5s.

For the first case, I use fieldAverage for run-time post-processing, starting from 0. Here is what is in the fieldAveragingProperties file of the last time step:

Code:

    location    "5/uniform";
    object      fieldAveragingProperties;

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

U
{
    totalIter      2249;
    totalTime      5.001;
}

alpha1
{
    totalIter      2249;
    totalTime      5.001;
}

Umean and alpha1Mean are indeed calculated on a time range of 5s, which is what I was expecting.

Now, if I run the same simulation without fieldAverage and if I use the postAverage utility for post-processing, the averaged fields aren't calculated on the whole time range of 5s :

Code:

    location    "5/uniform";
    object      fieldAveragingProperties;

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

U
{
    totalIter      51;
    totalTime      0.435901;
}

alpha1
{
    totalIter      51;
    totalTime      0.435901;
}

the totalIter is ok : 51 is the number of saved time step (every 0.1s from 0 to 5), but the totalTime doesn't seem ok as I would be expecting to find 5s as for the first case.
I don't understand why totalIter is ok and not totalTime.

To run the postAverage utility, I defined the fieldAverage function in the controlDict :

Code:

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

application    interFoam;

startFrom      startTime;

startTime      0;

stopAt          endTime;

endTime        5;

deltaT          0.001;

writeControl    adjustableRunTime;

writeInterval  0.1;

purgeWrite      0;

writeFormat    ascii;

writePrecision  6;

writeCompression uncompressed;

timeFormat      general;

timePrecision  6;

runTimeModifiable yes;

adjustTimeStep  on;

maxCo          0.2;
maxAlphaCo      0.2;

maxDeltaT      1;

functions
    {

    fieldAverage1
        {
            type            fieldAverage;
            functionObjectLibs ( "libfieldFunctionObjects.so" );
            enabled        true;
            outputControl  timeStep;
            timeStart        0.1;
            timeEnd            5;
   
            fields
            (
                U
                {
                    mean        on;
                    prime2Mean  on;
                    base        time;
                }

                alpha1
                {
                    mean        on;
                    prime2Mean  on;
                    base        time;
                }
            );
        }
    }



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

Then I run postAverage with this command :

Code:

postAverage -noZero
So it seems I've made a mistake somewhere or I don't use the utility properly.
Just to be sure : if I run the utility on all time steps, the mean values of the last time step should be the average of all time steps together no ?



Yann October 10, 2012 18:36

Hi all,

I finally solved my problem with another solution. As I'm unable to obtain what i want with OpenFOAM utilities, I just wrote a shell script to add underscores to the name of the time steps directories that I don't want to average.
So paraFoam just see the time steps I want and I can average them with the temporalStatistics filter.

It isn't an elegant way to do it, but it's doing the job so I'll go for that unless somebody has a better idea.

Thanks to Bernhard and GerhardHolzinger for their ideas and help.

eelcovv October 15, 2012 04:30

Hi Yann,

I struggeled with the same issue a while ago and wrote a utility for it. You can donwload it from the tread below. Probably needs some modification for you case (the fields to be averaged need to be hard coded), but that should be doable

Regards
Eelco

http://www.cfd-online.com/Forums/ope...rocessing.html

mwaqas November 19, 2014 09:52

Hello Everyone

I am beginner in OpenFoam, may be my question looks very busy, I am sorry for that.
I am using fieldAverage to get time-averaged of velocity. I get the time-averaged file in respective time step folder but I don't know how can I view this average field using paraview. When I load my case to paraview, it shows only entities which are present in "0" folder. It does not show averaged field i.e. UMean

Regards
Waqas


All times are GMT -4. The time now is 22:16.