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/)
-   -   fieldAverage function object does not average over all time? (https://www.cfd-online.com/Forums/openfoam-post-processing/156982-fieldaverage-function-object-does-not-average-over-all-time.html)

pbachant July 16, 2015 12:25

fieldAverage function object does not average over all time?
 
I am running this on my case (2.4.x pimpleDyMFoam with rotating AMI region) using execFlowFunctionObjects:

Code:

    fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;
        outputControl      timeStep;
        outputInterval      1;
        resetOnRestart  false;
        resetOnOutput  false;

        fields
        (
            U
            {
                mean        on;
                prime2Mean  on;
                base        time;
            }
        );
    }

If I run this with the solver at run time the mean fields look reasonable, but doing this in post-processing, the mean field looks just like the instantaneous (written) fields. I've tried things like executing with -noFlow, and putting a readFields function object before the fieldAverage, but nothing seems to work.

I noticed that I get this in fieldAveragingProperties file in every time directory:

Code:

U
{
    totalIter      2;
    totalTime      0.004;
}

So it looks like it starts re-averaging each time step, rather than keeping the fields for all time. I've tried similar functionObjects with some pimpleFoam tutorials and they work fine after the case has run. I am totally stumped. What gives?

pbachant July 18, 2015 11:51

I reported a bug on the OpenFOAM Mantis, and apparently this is a known issue with moving meshes. Anyone have any idea how to fix up execFlowFunctionObjects to make it work?

wyldckat July 19, 2015 14:06

Greetings Pete,

I see that you've got 2 reports on this topic:
If I understand you correctly, you want to do a plain average of the fields over the existing time snapshots?

In addition, do you mean that the average results for a dynamic mesh are acceptable for doing an analysis? I ask this because there are regions in the mesh that probably stop existing on a specific location in 2 different time snapshots, which makes it somewhat impossible to do an actual average of the field :(

On the other hand, are you trying to do an average only on the static region?


I ask all of this because from what I can remember, the averaging mechanism needs to access the previous fields in time, which are usually created by the function object itself. But the "execFlowFunctionObjects" was designed for pretty much loading each time snapshot individually, which essentially "breaks the flow".

Therefore, if you can describe the exact averaging operation you want to perform, it might be easier to create a new application that helps you do this, hence my previous questions.

Best regards,
Bruno

pbachant July 19, 2015 14:17

Hi Bruno,

The two bug reports are somewhat different since the second one applies to static meshes as well. I don't think the second bug will affect the results, though, since my cases are written at a constant interval.

I do want to average over a specified amount of time directories, compute some mean gradients in the static region (wrote a custom coded functionObject for this), then plane-average these (using funkyDoCalc). I was trying to avoid re-running the case since it had to be done on a cluster. I don't think the results would be terribly affected by the "downsampling" from only using written directories for computing statistics.

I got the averaging to mimic what happens if you use fieldAverage at run-time by commenting out the part that reloads the functionObjects if the mesh changes, so that gets me somewhere, but writing every time step (one of my notes on the second bug) is going to take up a lot of disk space, though I may be able to afford it.

Thanks!

wyldckat July 19, 2015 15:05

So... the missing detail is that you need a new function object based on "fieldAverage" that uses the actual time step taken between 2 time snapshots.
From what I can see, in the file "src/postProcessing/functionObjects/field/fieldAverage/fieldAverage.C", you need to replace all occurrences of this:
Code:

obr_.time().deltaTValue()
with ... irgh, it'll be messy to do it through here.

OK, it's easier to do this in the "applications/utilities/postProcessing/miscellaneous/execFlowFunctionObjects/execFlowFunctionObjects.C" code, where after this line:
Code:

runTime.setTime(timeDirs[timeI], timeI);
you can add something like this:
Code:

if(timeI>0)
{
  runTime.setDeltaT(timeDirs[timeI]-timeDirs[timeI-1]);
}

Build and hope for the best ;)

pbachant July 19, 2015 15:20

Looks like the "-" operator is not implemented for Foam::instant, so I cannot do "timeI - 1".

wyldckat July 19, 2015 15:27

:confused: Well... then after this:
Code:

Foam::instantList timeDirs = Foam::timeSelector::select0(runTime, args);
Add this:
Code:

Foam::instant prevTimeI = timeDirs.start();
or:
Code:

Foam::instant prevTimeI = timeDirs[0];
Then in the new "if" block:
Code:

if(timeI>0)
{
  runTime.setDeltaT(timeDirs[timeI]-timeDirs[prevTimeI]);
}

And before the end of the "forAll" loop:
Code:

prevTimeI = timeI;

pbachant July 19, 2015 21:04

That didn't quite work, but I got things going by creating a new Time object for the previous time: https://github.com/petebachant/OpenF...5ddee3dfb676e8

However, the outputControl of the fieldAverage is still not working correctly when used in post-processing. I may be able to deal with this so long as I don't run out of disk space.

wyldckat August 16, 2015 18:16

4 Attachment(s)
Hi Pete,

I was curious about this and this on my to-do list. From the look of the commits you have on your repository, it seemed that you had this mostly working.
As far as I can figure out, I think I've got it working, along with a test case.

Attached are the following files:
  • "execFlowFunctionObjectsMod24.tar.gz" - This is the modified execFlowFunctionObjects utility from OpenFOAM 2.4.x. I'll detail the changes after this list.
  • "movingCone24.tar.gz" - This case is based on the tutorial "incompressible/pimpleDyMFoam/movingCone" from OpenFOAM 2.4.x. It's modified to use the following boundary condition in the file "0/pointMotionUx":
    Code:

        movingWall
        {
            type            uniformFixedValue;
            //uniformValue    constant 1;
            uniformValue    table
            (
                (  0    0.0)
                (0.0005  1.0)
                (0.001  -1.0)
                (0.0015  1.0)
                (0.002  -1.0)
                (0.0025  1.0)
                (0.003  -1.0)
                (0.0035  1.0)
                (0.004  -1.0)
                (0.0045  1.0)
                (0.005  -1.0)
                (0.0055  1.0)
                (0.006  -1.0)
                (0.0065  1.0)
                (0.007  -1.0)
                (0.0075  1.0)
                (0.008  -1.0)
                (0.0085  1.0)
                (0.009  -1.0)
            );       
        }

    This makes it oscillate in a way that allows us to sample specific time snapshots where the cone is in the same position.
  • "Overview of animation controls.jpg" - This shows how I had to configure ParaView to render only the time shots that matter to us, because the attached case generates a lot of time snapshots.
  • "Detail of animation controls.jpg" - This is the zoomed in version of the "Animation View" widget, visible with through the menu "View -> Animation View". If this is not configured like this, then the case reader will try to load the field "UMean" for time snapshots that doesn't have the field, resulting in breaking the animation.
Regarding the changes in the code, the two big change are:
  • Setting deltaT, as I had originally suggested and then based on the implementation you did (i.e to use "value()"):
    Code:

            if(timeI==0)
            {
              runTime.setDeltaT(timeDirs[timeI].value());
            }
            else
            {
              runTime.setDeltaT(timeDirs[timeI].value()-timeDirs[timeI-1].value());
            }

    The first if statement refers to the fact that we cannot sample the first time step, i.e. time=0, otherwise deltaT would be zero and possibly result in a division by zero.
  • Commented out the function object update for dynamic meshes, the same way you did in your repository:
    Code:

            if (mesh.readUpdate() != polyMesh::UNCHANGED)
            {
                // Update functionObjectList if mesh changes
                //folPtr = readFunctionObjects(args, runTime, folDict);
            }

As for the case, it can be run with the following commands:
Code:

foamRunTutorials
rm */*Mean
rm */uniform/fieldAveragingProperties
execFlowFunctionObjectsMod -noFlow -time '0.00075,0.00175,0.00275,0.00375,0.00475,0.00575,0.00675,0.00775,0.00875'

  • The first command automatically runs blockMesh and pimpleDyMFoam;
  • the two rm commands are for removing the mean fields, because I didn't feel like having two "controlDict" files.
  • The execFlowFunctionObjectsMod command explicitly only runs for the time steps where the cone is at the right most position.
And I think that's all that's important to point out. Well, the settings in "controlDict" also help, because I made it write to disk every "5e-05" seconds, which is why I could select accurately each time step.


Adding this hack to OpenFOAM itself is too cumbersome and probably a pain to maintain in the future. Nonetheless, I'll leave a reference to this on the bug tracker: http://www.openfoam.org/mantisbt/view.php?id=1789


Best regards,
Bruno


All times are GMT -4. The time now is 04:36.