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

How to calculate depth averages in ParaView

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 3, 2019, 11:40
Default How to calculate depth averages in ParaView
  #1
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 12
wildfire230 is on a distinguished road
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.
wildfire230 is offline   Reply With Quote

Old   October 29, 2020, 17:14
Default
  #2
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
I am wondering if you found the way. Thanks.
Bodo1993 is offline   Reply With Quote

Old   October 29, 2020, 20:31
Default
  #3
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 12
wildfire230 is on a distinguished road
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.
wildfire230 is offline   Reply With Quote

Old   October 29, 2020, 21:02
Default
  #4
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
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).
Bodo1993 is offline   Reply With Quote

Old   October 30, 2020, 08:36
Default
  #5
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 12
wildfire230 is on a distinguished road
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.
wildfire230 is offline   Reply With Quote

Old   October 30, 2020, 08:47
Default
  #6
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
Quote:
Originally Posted by wildfire230 View Post
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.
Bodo1993 is offline   Reply With Quote

Old   October 30, 2020, 09:13
Default
  #7
Senior Member
 
Join Date: Jul 2013
Posts: 124
Rep Power: 12
wildfire230 is on a distinguished road
What I have done whenever I need a paraview macro is something like this:


1. Load your case (Apply).
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; }
wildfire230 is offline   Reply With Quote

Old   October 30, 2020, 09:18
Default
  #8
Senior Member
 
Join Date: Jul 2019
Posts: 148
Rep Power: 6
Bodo1993 is on a distinguished road
Thank you for your time. Much appreciated.
Bodo1993 is offline   Reply With Quote

Old   May 2, 2023, 11:36
Default Paraview Programmable Filter to depth-average
  #9
New Member
 
Kate Bradbrook
Join Date: Nov 2015
Posts: 12
Rep Power: 10
KateBradbrook is on a distinguished road
First use calculator on results dataset to get vel=mag(U)
Then use ResampleToImage with default 100x100x100
The select programmableFilter, click "Copy Arrays" and paste in following code:


# Code for 'Script'.
#Note click "Copy Arrays" option to keep alpha.water to plot surface contour later
import numpy as np
#RequestData (First calc mag(U)-> vel, then ResampleToImage 100x100x100)
input0=inputs[0]
#set up variables
dp = input0.PointData["p"]/9810
dv = input0.PointData["vel"]
da = input0.PointData["alpha.water"]

#Loop through x,y directions
for i in range(0, 100):
for j in range(0, 100):
#vertical averaging
dmax=0
vsum=0
asum=0
for k in range(0, 100):
id=(k*10000)+(j*100)+i
vsum=vsum+dv[id]*da[id]
asum=asum+da[id]
if dp[id]>dmax:
dmax=dp[id]
#assign vertical averages throughout depth
vAv = 0
if dmax>0:
vAv = vsum/asum
for k in range(0, 100):
id=(k*10000)+(j*100)+i
dp[id]=dmax
dv[id]=vAv
output.PointData.append(dp,"depth")
output.PointData.append(dv,"avVel")

#Now can use calculator to get Froude Number :-)
Attached Files
File Type: txt paraview_depth_averaging.txt (918 Bytes, 10 views)

Last edited by KateBradbrook; May 4, 2023 at 09:10. Reason: indents for code didn't copy properly
KateBradbrook is offline   Reply With Quote

Reply

Tags
depth-averages, paraview


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate field and patch averages in multiple zones, large mesh buffi OpenFOAM Post-Processing 2 July 21, 2022 05:45
[OpenFOAM] Paraview client/server does not work with ParaView 5.0.1 snak ParaView 0 October 17, 2016 10:22
a variable/expression to calculate water depth hmasenger CFX 3 January 31, 2015 16:46
Newbie: Install ParaView 3.81 on OF-1.6-ext/OpenSuse 11.2? lentschi OpenFOAM Installation 1 March 9, 2011 02:32
calculate average in Paraview alain Main CFD Forum 0 March 14, 2006 05:49


All times are GMT -4. The time now is 00:11.