CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Calculate fields and profiles for velocity time average and standard deviation

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 25, 2013, 15:18
Default Calculate fields and profiles for velocity time average and standard deviation
  #1
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Hi There,

I'm looking to post process a velocity field by computing mean and standard deviation, but it doesn't look like there is a built in utility for that. Can/should I use foamCalc? If so, how would I go about doing this?

After that, I'd like to plot mean and std cross-stream profiles at specified streamwise and vertical positions. It would be nice to parse the data with Python so I can generate plots with matplotlib. Is there any simple way to do this? pyFOAM perhaps?
pbachant is offline   Reply With Quote

Old   August 26, 2013, 13:02
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by pbachant View Post
Hi There,

I'm looking to post process a velocity field by computing mean and standard deviation, but it doesn't look like there is a built in utility for that. Can/should I use foamCalc? If so, how would I go about doing this?

After that, I'd like to plot mean and std cross-stream profiles at specified streamwise and vertical positions. It would be nice to parse the data with Python so I can generate plots with matplotlib. Is there any simple way to do this? pyFOAM perhaps?
No. PyFoam is not very good at reading full field files.

One alternative would be PythonFlu which is a Python-wrapper around the OpenFOAM-libraries. You could read the data files using that and then do your matplotlib-thing.

Another possibility would be swak4Foam. Just computing the mean (you mean the volume weighted average by that?) and standard-deviation (that depends on your definition of "mean") can be done with simple expressions. For more advance postprocessing I just recently pushed something to the publicly available development version: funkyPythonPostproc. That utility reads OF-data files, executes swak-functionObjects on those and hands over results (via global variables) to a python-script as numpy-arrays. And numpy is the de-facto-standary for scientific/numeric libraries in Python .... Only problem is that there is just one Example for that in the swak-distro, but I think it should be sufficient to understand how to do that yourself. Ah. And behaviour in parallel may still be subject to change. That's why it's not in a release yet.
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   September 1, 2013, 13:23
Default
  #3
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Quote:
Originally Posted by gschaider View Post
No. PyFoam is not very good at reading full field files.

One alternative would be PythonFlu which is a Python-wrapper around the OpenFOAM-libraries. You could read the data files using that and then do your matplotlib-thing.

Another possibility would be swak4Foam. Just computing the mean (you mean the volume weighted average by that?) and standard-deviation (that depends on your definition of "mean") can be done with simple expressions. For more advance postprocessing I just recently pushed something to the publicly available development version: funkyPythonPostproc. That utility reads OF-data files, executes swak-functionObjects on those and hands over results (via global variables) to a python-script as numpy-arrays. And numpy is the de-facto-standary for scientific/numeric libraries in Python .... Only problem is that there is just one Example for that in the swak-distro, but I think it should be sufficient to understand how to do that yourself. Ah. And behaviour in parallel may still be subject to change. That's why it's not in a release yet.
I do not have swak4Foam installed but will look into that. Numpy arrays are most preferable to me. Will swak4Foam work with OF 2.2.1? The wiki does not list it as compatible so I assume not.

It seems that it's also possible to export *.csv files and do Python scripting from ParaView. Would this be a reasonable approach as well? I'm not fully familiar with the capabilities.
pbachant is offline   Reply With Quote

Old   September 2, 2013, 19:34
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by pbachant View Post
I do not have swak4Foam installed but will look into that. Numpy arrays are most preferable to me. Will swak4Foam work with OF 2.2.1? The wiki does not list it as compatible so I assume not.
It compiles with 2.2.1. Dev version definitely. Released version I'm not 100% sure.

I just haven't updated that version compatibility in a long time

Quote:
Originally Posted by pbachant View Post
It seems that it's also possible to export *.csv files and do Python scripting from ParaView. Would this be a reasonable approach as well? I'm not fully familiar with the capabilities.
That might be a possibility (if your paraview is compiled with Python support). But beware: Paraview brings its own Python and Numpy which might give strange results if you try to use a library built on numpy (scipy) that is installed against your systems Python/Numpy

And I'm not a big fan of the graph-plots in Paraview. For that gnuplot or matplotlib might be more flexible for you (Your milage may vary)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   September 3, 2013, 04:55
Default
  #5
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
What about re-running the case with active fieldAverage functionObject, or maybe run the functionObject on the finished solution?

The mean velocity is straight forward and the prime2mean quantity may be related to the standard deviation, but don't nail me on that.


Code:
fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        outputControl   outputTime;
        fields
        (
            U1
            {
                 mean        on;
                 prime2Mean  off;
                 base        time;
            }
        );
    }
GerhardHolzinger is offline   Reply With Quote

Old   September 3, 2013, 06:07
Default
  #6
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by GerhardHolzinger View Post
What about re-running the case with active fieldAverage functionObject, or maybe run the functionObject on the finished solution?

The mean velocity is straight forward and the prime2mean quantity may be related to the standard deviation, but don't nail me on that.


Code:
fieldAverage1
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        outputControl   outputTime;
        fields
        (
            U1
            {
                 mean        on;
                 prime2Mean  off;
                 base        time;
            }
        );
    }
Depends on what you mean with "average and standard deviation". The fieldAverage-FO calculates mean and standard-Deviation in every cell over time. My assumption was that he wants the average and standard deviation over all cells at a specific time
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   September 3, 2013, 12:43
Default
  #7
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Depends on what you mean with "average and standard deviation". The fieldAverage-FO calculates mean and standard-Deviation in every cell over time. My assumption was that he wants the average and standard deviation over all cells at a specific time
Nope, I am looking for time statistics at each cell. It would be nice to specify a time-window over which the average and standard deviation are computed as well. The end game here is comparison with experiments.

If I use prime2mean, this will compute the variance, correct? If I could then take the square root I'd have my standard deviation, but I'm still left with the question of how to get the cell values into Numpy arrays.
pbachant is offline   Reply With Quote

Old   September 3, 2013, 16:01
Default
  #8
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by pbachant View Post
Nope, I am looking for time statistics at each cell. It would be nice to specify a time-window over which the average and standard deviation are computed as well. The end game here is comparison with experiments.
Sorry. You should have been more specific in your initial question

Quote:
Originally Posted by pbachant View Post
If I use prime2mean, this will compute the variance, correct? If I could then take the square root I'd have my standard deviation, but I'm still left with the question of how to get the cell values into Numpy arrays.
Various possibilities:
- pythonFlu
- From the field file strip off the stuff before and after the internalField and read it directly with numpy
- Maybe I'm obnoxious. But with the development version of swak (it's not yet in a release) something like this is possible: http://sourceforge.net/p/openfoam-ex...ythonPostproc/ (Just preload the fields generated by fieldAverage and pass them to the python-code)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   September 4, 2013, 15:09
Default
  #9
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Quote:
Originally Posted by gschaider View Post
Sorry. You should have been more specific in your initial question



Various possibilities:
- pythonFlu
- From the field file strip off the stuff before and after the internalField and read it directly with numpy
- Maybe I'm obnoxious. But with the development version of swak (it's not yet in a release) something like this is possible: http://sourceforge.net/p/openfoam-ex...ythonPostproc/ (Just preload the fields generated by fieldAverage and pass them to the python-code)
You are far from being obnoxious -- quite helpful in fact! Believe me, I am fully planning on digging into swak. I'm still learning OpenFOAM, so I will get there eventually. Thanks for developing and giving support for the additional tools.
pbachant is offline   Reply With Quote

Old   June 28, 2019, 07:09
Default
  #10
Member
 
Philipp Conen
Join Date: Apr 2019
Location: GER, NRW
Posts: 35
Blog Entries: 2
Rep Power: 7
pconen is on a distinguished road
Dear Pete,

did you get a solution for this task?
I am also interested in calcuating mean and standard deviation. According to the mixing quality I dont need a field of velocity, but a field of concentration.
Can you give me some hints on this problem?
__________________
Greetings

Philipp Conen
pconen is offline   Reply With Quote

Old   June 28, 2019, 09:20
Default
  #11
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 173
Rep Power: 14
pbachant is on a distinguished road
Quote:
Originally Posted by pconen View Post
Dear Pete,

did you get a solution for this task?
I am also interested in calcuating mean and standard deviation. According to the mixing quality I dont need a field of velocity, but a field of concentration.
Can you give me some hints on this problem?
Using the fieldAverage and sample function objects (included with OpenFOAM) are the easiest way I've found. If you have sample write to CSV it's very easy to load into Python with Pandas.

Here is a case that does that, with some extra code for parameterization via Python: https://github.com/petebachant/UNH-RVAT-turbinesFoam
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   August 16, 2019, 07:24
Default
  #12
Member
 
Philipp Conen
Join Date: Apr 2019
Location: GER, NRW
Posts: 35
Blog Entries: 2
Rep Power: 7
pconen is on a distinguished road
Dear Pete,

I was not able to fix my problem in this kind of way.
I was glad to find anothere way to determinate the mixing quality.
If someone else has trouble with this you can find the solution here.

https://www.cfd-online.com/Forums/bl...ity-index.html
__________________
Greetings

Philipp Conen
pconen is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



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