CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Continuing fieldAverage on restart? (

juho March 22, 2009 06:14

Continuing fieldAverage on restart?

I'm using the fieldAverage function object to calculate average fields. The averaging works fine if the simulation is completed in a single run. However if the simulation is interrupted and restarted the averages calculated so far are reset. The averages are also reset if prime2Mean calculation is turned on in middle of a run.

Looking at /src/postProcessing/fieldAverage/fieldAverage/fieldAverageTemplates.C
it would seem that this should not be the case? If the mean field is present it should be read and not reset?

Excerpt from fieldAverageTemplates.C:
================================================== ======

Info<< "Reading/calculating field " << meanFieldName << nl << endl;

if (obr_.foundObject<fieldType>(meanFieldName))
meanFieldList[fieldi] = meanFieldName;
else if (obr_.found(meanFieldName))
Info<< "Cannot allocate average field " << meanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging." << nl << endl;
meanFieldList[fieldi] = word::null;
const fieldType& baseField =

fieldType* fPtr = new fieldType

// Store on registry

meanFieldList[fieldi] = meanFieldName;

================================================== ======

================================================== ======
// Type of functionObject
type fieldAverage;

// Where to load it from (if not already in solver)
functionObjectLibs ("");

// Fields to be averaged - runTime modifiable
mean on;
prime2Mean on;
base time;

================================================== ======

I'm using a couple of days old 1.5.x from GIT.

Continuing the averages would be very important for me, as the simulations take a quite a bit of time and interrupting the simulation is sometimes necessary. Am I doing something wrong or what?

Thank you for reading and any input is appreciated!


juho March 25, 2009 17:53

I ended up coding the averaging directly into the solver, which is fine as I would have had to do it eventually anyway. Although a function object would be a more elegant way to handle it. Whether it's the standard stuff or something else.

I would still appreciate comments on the fieldAverage function object. Is it supposed to work like I described in the above post, or did I do something wrong?

fs82 June 5, 2009 08:43

Due to your post I was a bit afraid of using the averaging function and I tested the problem you mentioned. I started from zero, performed one step, restarted the calculation and performed again one step. For me everything looks fine. The averages are correct after each time step and after a restart OpenFoam reads the previous averages successfully and continues averaging. I use OpenFoam 1.5. So I could reproduce your problem.

leonardo.morita June 5, 2009 09:38

Hi Fabian,

Are you sure the values you used could not have tricked you? I remember having tested a simple case too, but I verified that the start time of averaging is startTime from each time the simulation was paused and resumed, averaging was reset.


fs82 June 5, 2009 10:01

1 Attachment(s)
Allright, I hope not :-D
The plot I attached hopefully explain what I mean. This is a simple channel with constant volume force acting in streamwise direction. The initial conditon for Ux is 0. You could see that Ux after one timestep (Ux(0) in plot, red line is behind the blue one) is about 0.0025. The average value Uxm(0) is about 0.00125 which is correct ((0+0.0025)/2).
After that timestep I aborted the run and restart it. If you have a look at the yellow line showing you one time step after the restart, namely Ux(1), you see the velocity increases to 0.005. If you now look at Uxm(1) you will find it about 0.0025 which is only correct if he uses the avarages from before the restart: (0 + 0.0025 + 0.005)/3 = 0.0025. Without using this files from before the restart you will get: (0.0025+0.005)/2 = 0.00375.

leonardo.morita June 5, 2009 10:35

Well, I've tested some new cases and I found the same results you did Fabian...however it seems to me there's still something unclear...
Actually, it would be much more interesting for me too if averaging was always cumulative, but Juho's results are bizarre, aren't they?
Did somebody else have problems with averaging?

flying June 5, 2009 13:56

Hey juho!

If you post the error informaiton, I think it will be more helpful.

fs82 June 8, 2009 02:43

May be I understand something wrong, but Juho is complaining about that the averages are reset after a restart. But my test and his excerpt from source code did not confirm his assumption. For me the averaging function works correct. But I will continue testing with my full turbulent channel and see what happens ...

flying June 8, 2009 08:09

Me too, I also think the average field function has no problem

make February 27, 2010 09:23

I have problems doing the averaging as well. Everytime I restart my simulation totalIter and totalTime are resetted despite the mean fields are present.
I simply tried the pitzDaily tutorial case as well to check if it is my setup. So I set startFrom to latestTime and stopAt to nextWrite in the controlDict and restarted a few times. After every run totalIter is 11 and totalTime 0.00011. So it clearly did not use the correct weighting for the averages.
Did I misunderstood anything?
I came to that point after I sadly run a huge LES in three restart steps and wondered why my averages did not proceed after every run. Nevertheless due to resource managment on our cluster system I am forced to restart.

Help would be so appreciated!!!

Regards and have a nice weekend,

make February 27, 2010 09:24

Ups, forgot to mention that I am still using OpenFOAM-1.5.x

make March 1, 2010 09:23

I figured out that when it calls the readAveragingProperties() function in fieldAverage.C the fieldAveragingProperties file of the requested time step of the restart is found but claimed to be empty. Nevertheless, the file is present and not empty! I then checked the fieldAverage of OF-1.6.x and it works. So I copied the OF-1.6.x version to OF-1.5.x installation and replaced the write() function in fieldAverage.C by the write function of OF-1.5.x so that in does not write out the mean fields every time step (exec() is not yet known for function objects in OF-1.5.x). This seems to work properly and is a valid workaround for me.
However I didn't find out what the issue in OF-1.5.x is exactly. So if anybody finds out please let me know.


All times are GMT -4. The time now is 13:33.