CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] Integral average of velocity values on a slice

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

Like Tree1Likes
  • 1 Post By Flowkersma

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 5, 2015, 15:56
Default Integral average of velocity values on a slice
  #1
New Member
 
Join Date: Oct 2015
Posts: 7
Rep Power: 10
cfdaddicted is on a distinguished road
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.
cfdaddicted is offline   Reply With Quote

Old   October 12, 2015, 08:09
Default
  #2
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
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:
  1. Calculate the radial distance (Calculator)
  2. Create one isocontour line with constant radial distance (Contour)
  3. Integrate (IntegrateVariables)
  4. 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.
Flowkersma is offline   Reply With Quote

Old   November 9, 2015, 17:58
Default
  #3
Member
 
Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
fportela is on a distinguished road
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 View Post
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:
  1. Calculate the radial distance (Calculator)
  2. Create one isocontour line with constant radial distance (Contour)
  3. Integrate (IntegrateVariables)
  4. 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
fportela is offline   Reply With Quote

Old   November 10, 2015, 05:25
Default
  #4
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
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?
Flowkersma is offline   Reply With Quote

Old   November 10, 2015, 05:36
Default
  #5
Member
 
Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
fportela is on a distinguished road
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 View Post
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?
fportela is offline   Reply With Quote

Old   November 10, 2015, 16:27
Default
  #6
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
Hmm.. can you try
Quote:
intData = ps.servermanager.Fetch(int)
instead of
Quote:
intData = pv.servermanager.Fetch(int)
Flowkersma is offline   Reply With Quote

Old   November 10, 2015, 16:28
Default
  #7
Member
 
Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
fportela is on a distinguished road
same problem :/

Quote:
Originally Posted by Flowkersma View Post
Hmm.. can you try

instead of
fportela is offline   Reply With Quote

Old   November 10, 2015, 16:31
Default
  #8
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
Can you share your data?
Flowkersma is offline   Reply With Quote

Old   November 10, 2015, 16:33
Default
  #9
Member
 
Felipe Alves Portela
Join Date: Dec 2012
Location: FR
Posts: 70
Rep Power: 13
fportela is on a distinguished road
sent you a pm

Quote:
Originally Posted by Flowkersma View Post
Can you share your data?
fportela is offline   Reply With Quote

Old   November 11, 2015, 05:24
Default
  #10
Senior Member
 
Mikko
Join Date: Jul 2014
Location: The Hague, The Netherlands
Posts: 243
Rep Power: 12
Flowkersma is on a distinguished road
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.
Flowkersma is offline   Reply With Quote

Old   November 18, 2015, 05:31
Default
  #11
New Member
 
Join Date: Oct 2015
Posts: 7
Rep Power: 10
cfdaddicted is on a distinguished road
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?
cfdaddicted is offline   Reply With Quote

Old   November 30, 2015, 02:11
Default
  #12
Member
 
pan
Join Date: May 2015
Posts: 30
Rep Power: 10
Thomas pan is on a distinguished road
Hi Felipe,

I follow your code to my case,but i get the following error:
Quote:
Traceback (most recent call last):
File "<string>", line 54, in <module>
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!
Thomas pan is offline   Reply With Quote

Old   November 30, 2015, 02:12
Default
  #13
Member
 
pan
Join Date: May 2015
Posts: 30
Rep Power: 10
Thomas pan is on a distinguished road
Hi Mikko,

I follow your code to my case,but i get the following error:
Quote:
Traceback (most recent call last):
File "<string>", line 54, in <module>
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.
Thomas pan is offline   Reply With Quote

Reply

Tags
export data, integral average

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


All times are GMT -4. The time now is 08:28.