# Depth-averaged quantities in ParaView (interFOAM simulation)

**URL:** https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643
**Category:** ParaView Support
**Created:** [September 27, 2019, 6:22pm UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643 "2019-09-27T18:22:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![arhabib](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@arhabib](https://discourse.paraview.org/u/arhabib)
#### Post date: [September 27, 2019, 6:22pm UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643/1 "2019-09-27T18:22:47Z")

</div>

Hi,

How can one generate maps of depth-averaged velocity in ParaView.  
I am post-processing a VOF simulation (air/water) done in interFOAM.  
What I am looking for is a 2D map of depth-averaged quantities such as velocity in the entire domain. Just integrating/averaging over a vertical line won’t work (I need this done in the entire domain).

Thanks

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [September 30, 2019, 2:46am UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643/2 "2019-09-30T02:46:20Z")

</div>

ProgrammableFilter should be able to do this.

you will have to implement the algorithm in Python though.

---

<div class="post-metadata">

### Author: ![arhabib](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@arhabib](https://discourse.paraview.org/u/arhabib)
#### Post date: [October 30, 2019, 11:46pm UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643/3 "2019-10-30T23:46:12Z")

</div>

Thanks for your response.  
Could you please provide some more info (e.g. sample code)?  
That will be greatly helpful.  
Thanks.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [October 31, 2019, 8:13am UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643/4 "2019-10-31T08:13:12Z")

</div>

[https://www.paraview.org/Wiki/Python\_Programmable\_Filter](https://www.paraview.org/Wiki/Python_Programmable_Filter)

---

<div class="post-metadata">

### Author: ![katebradbrook](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/e56c9b/32.png) [@katebradbrook](https://discourse.paraview.org/u/katebradbrook)
#### Post date: [May 4, 2023, 12:51pm UTC](https://discourse.paraview.org/t/depth-averaged-quantities-in-paraview-interfoam-simulation/2643/5 "2023-05-04T12:51:45Z")

</div>

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 (but you may have to sort out identation - it doesn’t seem to show up properly):

```auto
# 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 :-)

```
