# [General] Integral average of velocity values on a slice

 Register Blogs Members List Search Today's Posts Mark Forums Read

 October 5, 2015, 15:56 Integral average of velocity values on a slice #1 New Member   Join Date: Oct 2015 Posts: 7 Rep Power: 10 I need to evaluate the integral average of velocity values on a slice in ParaView 4.3.1. I want to obtain a plot of the axial velocity of water as a function of radial position in a cylinder. Is it possible to perform this in ParaView or not? If I need to export the data, how could I automate the process of slice selection along the axial direction? Thank you in advance.

 October 12, 2015, 08:09 #2 Senior Member   Mikko Join Date: Jul 2014 Location: The Hague, The Netherlands Posts: 243 Rep Power: 12 Hi, Everything is possible with ParaView However, I'm not sure if I understand your question. If you have a cross section of a pipe and you want to get the average velocity over radial distance try following: Calculate the radial distance (Calculator) Create one isocontour line with constant radial distance (Contour) Integrate (IntegrateVariables) Calculate average and save the result For different radial distances, just change the isocontour value. Here is an example code for a pipe which axis is in z-direction: Code: ```import numpy as np import matplotlib.pyplot as plt from paraview import numpy_support as ns # Result arrays U = [] R = [] # Build a pipeline slice = GetActiveSource() calc = Calculator(slice, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2)') contour = Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0]) int = IntegrateVariables(contour) # Loop over different radial distances and save the results for r in np.arange(0.05,0.5,0.05): contour.Isosurfaces = [r] intData = servermanager.Fetch(int) L = ns.vtk_to_numpy(intData.GetCellData().GetArray('Length'))[0] U.append(ns.vtk_to_numpy(intData.GetPointData().GetArray('U'))[0][2]/L) R.append(r) #plot with matplotlib plt.plot(U,R) plt.show()``` Regards, Mikko Last edited by Flowkersma; November 9, 2015 at 05:36.

November 9, 2015, 17:58
#3
Member

Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
Hi Mikko,

I've been trying your suggestion below (as you suggested in another thread) but I keep getting a segmentation fault at the "servermanager.Fetch" stage. Any idea why this may be happening? I'm running version 4.3.1 btw

Quote:
 Originally Posted by Flowkersma Hi, Everything is possible with ParaView However, I'm not sure if I understand your question. If you have a cross section of a pipe and you want to get the average velocity over radial distance try following: Calculate the radial distance (Calculator) Create one isocontour line with constant radial distance (Contour) Integrate (IntegrateVariables) Calculate average and save the result For different radial distances, just change the isocontour value. Here is an example code for a pipe which axis is in z-direction: Code: ```import numpy as np import matplotlib.pyplot as plt from paraview import numpy_support as ns # Result arrays U = [] R = [] # Build a pipeline slice = GetActiveSource() calc = Calculator(slice, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2)') contour = Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0]) int = IntegrateVariables(contour) # Loop over different radial distances and save the results for r in np.arange(0.05,0.5,0.05): contour.Isosurfaces = [r] intData = servermanager.Fetch(int) L = ns.vtk_to_numpy(intData.GetCellData().GetArray('Length'))[0] U.append(ns.vtk_to_numpy(intData.GetPointData().GetArray('U'))[0][2]/L) R.append(r) #plot with matplotlib plt.plot(U,R) plt.show()``` Regards, Mikko

 November 10, 2015, 05:25 #4 Senior Member   Mikko Join Date: Jul 2014 Location: The Hague, The Netherlands Posts: 243 Rep Power: 12 Hi Felipe, I haven't encountered segmentation fault there. Have you succeeded to fetch data before? Have you checked your RAM consumption? Can you share your script?

November 10, 2015, 05:36
#5
Member

Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
Well, tbh this is my first go at using python scripts in ParaView so I guess I have never succeeded to fetch data before x)

I load a .csv file and convert it to points using the TableToPoints filter, then I generate a volume by using the Delaunay3D filter, then I want to compute the integral over several surfaces (which seems to work when I manually generate the contours)

As for the memory, nothing weird seems to happen... I tried both on a mac and a linux machine and the same thing happens on both!

The script I used for the integration is this (adapted from the one you posted):

Code:
```import numpy as np
from paraview import numpy_support as ns
import paraview as pv
import paraview.simple as ps

# Result arrays

U = []
R = []

# Build a pipeline

slice = ps.GetActiveSource()
calc = ps.Calculator(slice, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2+coordsZ^2)')
contour = ps.Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0])
int = ps.IntegrateVariables(contour)

# Loop over different radial distances and save the results

for r in np.arange(0.1,1.5,0.1):
contour.Isosurfaces = [r]

intData = pv.servermanager.Fetch(int)
L = ns.vtk_to_numpy(intData.GetCellData().GetArray('Length'))[0]

U.append(ns.vtk_to_numpy(intData.GetPointData().GetArray('U'))[0][2]/L)
R.append(r)```
Quote:
 Originally Posted by Flowkersma Hi Felipe, I haven't encountered segmentation fault there. Have you succeeded to fetch data before? Have you checked your RAM consumption? Can you share your script?

November 10, 2015, 16:27
#6
Senior Member

Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Hmm.. can you try
Quote:
 intData = ps.servermanager.Fetch(int)
Quote:
 intData = pv.servermanager.Fetch(int)

November 10, 2015, 16:28
#7
Member

Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
same problem :/

Quote:
 Originally Posted by Flowkersma Hmm.. can you try instead of

 November 10, 2015, 16:31 #8 Senior Member   Mikko Join Date: Jul 2014 Location: The Hague, The Netherlands Posts: 243 Rep Power: 12 Can you share your data?

November 10, 2015, 16:33
#9
Member

Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
sent you a pm

Quote:
 Originally Posted by Flowkersma Can you share your data?

 November 11, 2015, 05:24 #10 Senior Member   Mikko Join Date: Jul 2014 Location: The Hague, The Netherlands Posts: 243 Rep Power: 12 Resulting script which opens a CSV file, creates grid with Delaunay triangulation, calculates average of a scalar over spherical planes and finally saves the results to a file. Code: ```import numpy as np from paraview import numpy_support as ns import paraview.simple as pv # Path to file filename = 'data.csv' # Result arrays data = [] R = [] area = [] # Build a pipeline reader = pv.OpenDataFile(filename) reader.UpdatePipeline() ttp = pv.TableToPoints(reader, XColumn='x', YColumn='y', ZColumn='z') delaunay = pv.Delaunay3D(ttp) calc = pv.Calculator(delaunay, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2+coordsZ^2)') contour = pv.Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0]) int = pv.IntegrateVariables(contour) # Loop over different radial distances and save the results for r in np.linspace(0.01,1,100): contour.Isosurfaces = [r] intData = pv.servermanager.Fetch(int) A = ns.vtk_to_numpy(intData.GetCellData().GetArray('Area'))[0] data.append(ns.vtk_to_numpy(intData.GetPointData().GetArray('data'))[0]/A) area.append(A) R.append(r) np.savetxt('output.txt',zip(data,R,area))``` fportela likes this.

 November 18, 2015, 05:31 #11 New Member   Join Date: Oct 2015 Posts: 7 Rep Power: 10 The script works fine for a single slice, but how could I extend it to evaluate an average over all the slices along the axial direction?

November 30, 2015, 02:11
#12
Member

pan
Join Date: May 2015
Posts: 30
Rep Power: 10
Hi Felipe,

I follow your code to my case,but i get the following error:
Quote:
 Traceback (most recent call last): File "", line 54, in File "/usr/lib/python2.7/dist-packages/paraview/numpy_support.py", line 198, in vtk_to_numpy typ = vtk_array.GetDataType() AttributeError: 'NoneType' object has no attribute 'GetDataType'
My code is:
Quote:
 import numpy as np import matplotlib.pyplot as plt from paraview import numpy_support as ns import paraview.simple as pv # Result arrays p0 = [] R = [] # Build a pipeline slice = pv.GetActiveSource() calc = pv.Calculator(slice, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2)') contour = pv.Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0]) int = pv.IntegrateVariables(contour) # Loop over different radial distances and save the results for span in np.arange(0,1,0.05): contour.Isosurfaces = [span] intData = pv.servermanager.Fetch(int) # L = ns.vtk_to_numpy(intData.GetCellData().GetArray('Le ngth'))[0] L = ns.vtk_to_numpy(intData.GetCellData().GetArray('ra dius'))[0] p0.append(ns.vtk_to_numpy(intData.GetPointData().G etArray('p'))[0]) R.append(span) #plot with matplotlib plt.plot(p0,R) plt.show()
can you tell me what's wrong?Thank you very much!

November 30, 2015, 02:12
#13
Member

pan
Join Date: May 2015
Posts: 30
Rep Power: 10
Hi Mikko,

I follow your code to my case,but i get the following error:
Quote:
 Traceback (most recent call last): File "", line 54, in File "/usr/lib/python2.7/dist-packages/paraview/numpy_support.py", line 198, in vtk_to_numpy typ = vtk_array.GetDataType() AttributeError: 'NoneType' object has no attribute 'GetDataType'
My code is:
Quote:
 import numpy as np import matplotlib.pyplot as plt from paraview import numpy_support as ns import paraview.simple as pv # Result arrays p0 = [] R = [] # Build a pipeline slice = pv.GetActiveSource() calc = pv.Calculator(slice, ResultArrayName = 'radius', Function = 'sqrt(coordsX^2+coordsY^2)') contour = pv.Contour(calc,ContourBy = ['POINTS','radius'],Isosurfaces = [0]) int = pv.IntegrateVariables(contour) # Loop over different radial distances and save the results for span in np.arange(0,1,0.05): contour.Isosurfaces = [span] intData = pv.servermanager.Fetch(int) # L = ns.vtk_to_numpy(intData.GetCellData().GetArray('Le ngth'))[0] L = ns.vtk_to_numpy(intData.GetCellData().GetArray('ra dius'))[0] p0.append(ns.vtk_to_numpy(intData.GetPointData().G etArray('p'))[0]) R.append(span) #plot with matplotlib plt.plot(p0,R) plt.show()
Can you tell me what's wrong?Thank you very much!

Last edited by Thomas pan; November 30, 2015 at 20:23.

 Tags export data, integral average