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

LinkBack  Thread Tools  Search this Thread  Display Modes 
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:
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() 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:


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) 

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:
Quote:


November 10, 2015, 16:28 

#7 
Member
Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13 

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 

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)) 

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:
Quote:


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:
Quote:
Last edited by Thomas pan; November 30, 2015 at 20:23. 

Tags 
export data, integral average 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
combining parabolic inlet velocity profile with time varying velocity vector values  jawapasu  OpenFOAM  3  July 10, 2023 05:41 
serial udf to parallel udf  radioss  Fluent UDF and Scheme Programming  10  January 19, 2019 08:56 
Volume Integral or Surface Integral for velocity  saharesobh  FLUENT  2  November 20, 2012 03:51 
calculate the average velocity of particles  robert  FLUENT  0  August 1, 2008 09:44 
Terrible Mistake In Fluid Dynamics History  Abhi  Main CFD Forum  12  July 8, 2002 09:11 