CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   How to calculate depth averages in ParaView (https://www.cfd-online.com/Forums/openfoam-post-processing/217993-how-calculate-depth-averages-paraview.html)

 wildfire230 June 3, 2019 11:40

How to calculate depth averages in ParaView

Hi All,

Suppose I have output velocity/pressure from an OpenFOAM simulation. Is it possible to use ParaView to calculate the depth-averaged velocities? I do not have any experience with the custom filters.

For example, suppose I modify the cavity tutorial to be 3D, and then I want to look at the depth-averaged velocity profile. How can I do that with ParaView?

Thanks so much

Edit: I'm sorry, I just saw that there is a separate ParaView forum, but I am unable to delete or move this thread.

 Bodo1993 October 29, 2020 17:14

I am wondering if you found the way. Thanks.

 wildfire230 October 29, 2020 20:31

I never found a way to do this. I'm guessing with a simple regular grid you could just program it in the python filter.

 Bodo1993 October 29, 2020 21:02

Thanks for the reply. I have been looking into this for a while and could not get any useful answer. In my case, I have 2D domain (x-y plane) and I want to average the phase fraction at every y and repeat the process at each time step. The mesh I am using is rectangular, but it is non-uniform. I normally do my postprocessing with MATLAB; however, I find it difficult to do the area weighted average on the interpolated data which I extract from OpenFOAM (i.e. no information on the area of each cell).

 wildfire230 October 30, 2020 08:36

One thing you could possibly try is to use a slice filter at each x value, and use the integrate variables filter to find the average for that x. Then you can write a macro that changes the x values of the slice filter and records the corresponding average.

 Bodo1993 October 30, 2020 08:47

Quote:
 Originally Posted by wildfire230 (Post 786370) One thing you could possibly try is to use a slice filter at each x value, and use the integrate variables filter to find the average for that x. Then you can write a macro that changes the x values of the slice filter and records the corresponding average.
Thank you for the suggestion. Right, I did it for one slice. Unfortunately, I do not know how to write programmable macros (i.e. I am not a python user). I should look into that. I would appreciate any references if you are aware of any useful ones.

 wildfire230 October 30, 2020 09:13

What I have done whenever I need a paraview macro is something like this:

2. Then you want to record a macro where you manually setup the filters and such that you need. In my version of paraview this starts with Tools -> Start Trace. Go with "only *user-modified* properties" in the trace.

3. After that be careful because everything you do will be recorded in the macro, so you only want the necessary commands. Click the slice filter and set it in the correct plane and the correct starting position and then apply it.
4. Then add the integrate variables filter and apply.
5. Then switch to the slice filter and change the x coordinate and apply again.
6. Change the x coordinate and apply again.
7. Change the x coordinate and apply again.
8. Then go to Tools -> Stop trace
9. Then you should save the python code that is generated as a macro.
10. Next, you will need to try to understand the python code it generated. The most important parts will be going near the end of the code there will be probably a line like this " slice1.SliceType.Origin = [-7.0, 0.0, 0.004999999888241291]" Probably you will have multiple of those lines for each time you changed the origin of the slice filter. You will need to learn enough python to write a for loop to iterate over the positions you need, for you I think this is the x-coordinate. The other thing you will need to learn, which I do not know about, is how to access the value of the integrated variables, and then output that value along with the x value into probably a csv file for your data. Sorry that I can't help with this step, but hopefully by trying to understand the code produced in the python trace you will get some hints that will help you google about this.

Once you have edited your macro, you can just click it to run the macro again, but make sure your current "state" in paraview is identical to when you started recording the macro. You have to delete all the filters and such before you run the macro again. Also, one thing to note, when I have done something like this before, it was important to set the x values and the dx exactly such that I was cutting through the center of the cells. If you try to take multiple values within a single cell for instance, you might get some small oscillations happening.

p, li { white-space: pre-wrap; }

 Bodo1993 October 30, 2020 09:18

Thank you for your time. Much appreciated.

 All times are GMT -4. The time now is 05:43.