using fieldAverage library to average postprocessing
Dear programming experts,
I am stuggelling with the following: I want to obtain the average of the fields already create in the time directories (i.e., during postprocessing). During runtime, this can be done via the functions in the controlDict by adding libfieldFunctionObjects.so No I want to do the same as a postprocessing step. My starting point was the postChannel application, that loops over the fields and collaps the field data that is assemed to by homogeneous. This tools requires Umean to be present. I want to create the Umean fields by a similar postprocessing tool called for instance postAverage This new tool (if it has been developped yet, please tell me) should read the controlDict dictionary, and than read the averaging information I took out all the functionality of postChannel (the collapsing of the fields) and I changed the line Code:
However, if I run this I get the complaint From function Foam::fieldAverage::initialize() in file fieldAverage/fieldAverage/fieldAverage.C at line 102. Of course this makes sence, because I do not do an explicit creation of the fields. Now the simple solution would be: explicity create the field U in the postAverage. However, this would make the utility less generic. I want it automatically to create the field that are defined in controlDict function fieldAverage. My idea was to include the fieldobject and reuse the code for creating fieldAverageItem. Unfortunately, I can not add or reuse the library in an external code, and therefore I can not reuse this functionality. I am relatively new to C++, but I that the power of it lies in reusing code, therefore I am quite sure this must be possible (I moreover, is desirable) Hopefully there is an OpenFoam programming expert out there who could give me a hint how to do tackle this problem. Or, which would be even better: is there somebody of has written a postprocessing utility to do the averaging of the time steps over a certain time range? Any hints very much appreciated! Regards, Eelco |
well,
It seems there are not many users dealing with the same issue. Let me refrase the my quest: I want to write a program that loops of the time directories, reads the fieds, and than writes an average field in the last directory. In this way, averaging can be done after the run as a postprocessing step, so that the first time steps can easily be left out if the start up is not stationary yet. Ideally, I would like to use for instance the existing foamCalc utility and combine that the the fieldAverage library so that during the loop the controlDict is used to do the job. I dug into the code, but can not find how I should modify it. I am too inexperience in C++, so I leave this to the real programming experts maybe with the next release (I can imagine that I am not the only user who'd like to have this functionality) Today I have spend my whole day digging into all the utilities to try to come up with my own solution. It is an ugly solution, in terms of proper C++ programming, but it is a start, and it works!. I am adding the code here. I would appreciate very much if somebody could comment on the most ugly construction I have used (see comments in the code). Probably there are better ways, but I just can not find how at the moment Code:
/*---------------------------------------------------------------------------*\ for instance foamTimeAverage Ux -time 300: gives the time average Ux_mean field from the time steps 300 to the end. Please free to use it or come with improvements Regards Eelco |
1 Attachment(s)
If anybody is interested in post-processing field averaging (I can hardly imagine nobody ever needs it), here an improved version thanks to a hint of Bernard Gschaider I was able to force to read the fieldAverage library in the controlDict using the runTime.functionObjects().execute() statement. In this way, all the functionality of the library is available.
The code of postAverage.C looks like Code:
/*---------------------------------------------------------------------------*\ Code:
Info<< "Reading field p\n" << endl; postAverage -time:300 The field averaging parameters should be given in the controlDict. The only important thing is that the outputControl is set on timeStep, e.g Code:
/*--------------------------------*- C++ -*----------------------------------*\ Thanks Eelco ps: the code is attached below |
I'm searching for this utility function. I'll try it firstly.
|
Hi Eelco,
thanks a lot for this very helpful tool /Andreas |
Hi guys
I want to do field averaging of Reynolds stress tensor (R) during running my code. It seems that the fieldaveraging library do the averaging just for U and P. How can I do the same thing for R? I would be so appreciated if you can help me Thanks |
Dear eelcovv,
<If anybody is interested in post-processing field averaging (I can hardly imagine nobody ever needs it), here an improved version thanks to a hint of Bernard <Gschaider I was able to force to read the fieldAverage library in the controlDict using the runTime.functionObjects().execute() statement. In this way, all the <functionality of the library is available. > Thank you very much for the very important code you supplied here. But when I execute the code postAverage (including the code i added in the system/controDict file), i realize that nothing changed. Can you give me a hint? Should a new variable be generated Umean or the averaged calculation is still saved as U? thank you once more! Alex |
Sorry for the late reply, I only see this post now.
Please make sure that you have in you field average dictionary outputControl outputTime; and make sure that you write interval is equal to the write interval of the original simulation. If that is not the case, nothing is written indeed. Good luck Regards eelco |
Quote:
|
Thank you!
This tool is very helpful indeed. Thank you very much, Eelcovv!!
:) |
hi, the unility is very helpful, and I want ask what is UPrime2mean, the computational formula of it and transient k is the same, but do they the same in real physical meanings?
|
My utility just makes a call to the averaging libraries developed by Bernard sgnaider, so don't pin me on it. But I think uprime2mean does the following. The velocity in general can be writen as U=<U>+u', where <...> indicates the ensemble average and u' is the deviation on it. The purpose at the start of the calculation is to calculate <u'^2>=<(U-<U>)^2>, i.e. the <u'^2> mean which is indeed related to k. During the run, however, <U> is not known, because you still need to average it in time. Therefore, it does not give you <u'^2>, but <U^2>. Both of them are related according to <u'^2>=<(U-<U>)^2>=<U^2> - <2*U*<U>> + <U>^2 = <U^2>-<U>^2. In other words, you can obtain the <u'^2> by subtracting the Umean squared from the Uprime2mean
|
Quote:
Could you explain how it is determined where the averaged field is written to? The code iterates over all my time steps but the effect of setting outputInterval to 2, 3, 10, 100, 1000 does not yield my desired result. (which is: save in every 2nd time step folder, every 3rd, 10th, 100th, 1000th) Basically, I just want to have the averaged field written into the last timestep folder. |
Hi hanzo,
without testing it I would say play with writeControl adjustableRuntTime; writeInterval 100; Where 100 now is not a interval in iterations but in time step and take you last time step only. The averaging is done by fieldAverage functionobject list, so the setting is control by this lib good luck |
Quote:
Thanks for the code. I tried running it many times with the instructions in this thread - but the code reads the fields at all the times and doesnt save the mean data anywhere. Am I missing something? Here is my controldict file: Code:
Thanks a lot. I have a lot of data to be averaged :confused: |
Quote:
Set outputInterval 1; or outputInterval 2; in fieldAverage1. Then output is written to every / every second data folder. Then I copy the Mean files from the last timestep to some other place. The next step is to erase all *Mean files in the data folders. When you have to do it only once or twice, I think it is okay to live with it. |
execFlowFunctionObjects
Thank you very much for this tool, it works well for my purposes.
I have a question however. Can the same thing be done with the 'execFlowFunctionObjects' utility? Is there an advantage to this code, or do they work about the same? If anyone knows the clarification would help. Thanks! |
Hi eelcovv
Thank you very much for the code, which is really handy and useful. Quote:
Thanks jiejie |
Quote:
Just got a quick question regarding to calculating <u'^2>. There are 6 values in the UPrime2Mean, which are xx,yy,zz,xy,yz,xz. Since the postAverage UPrime2Mean gives <U^2> instead of <U'^2>. Should I use the first 3 columns from postAverage's UPrime2Mean takes away UMean^2 to get the <U'^2>? Assume the above was correct, I calculated the <U'^2>. However, I found it looks almost the same as UMean instead? My other question is whether the UPrime2Mean is the variance of the velocity field? ( Please see this link: http://www.cfd-online.com/Forums/ope...n-etc-les.html) Many thanks. jiejie |
Quote:
U-prime, squared and averaged = <u'^2>. To check this, you can compute u' using U and <U> , calculate u'^2 and average it manually. I did this for a series of data sets and when I compared UPrime2Mean with manually generated <u'^2> they turned out to be the same. Another hint is the magnitude. In my computations, the biggest components of UMean_X are around 0.97 and UPrime2Mean_XX of 0.0025. UPrime2Mean cannot be U^2 |
All times are GMT -4. The time now is 14:44. |