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

python VTK help

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ginop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 4, 2018, 06:48
Default python VTK help
  #1
New Member
 
Gino Parisella
Join Date: Mar 2017
Location: Perth, Western Australia
Posts: 22
Rep Power: 9
ginop is on a distinguished road
I would like to use foamToVTK generated files for simulation post-process in python.

At the moment, I have difficulties in getting cell centers. I read the vtk file, and get the data arrays for each cell. BUT how do I get the cell centers/points list?

I am a bit lost getting cell IDs, points, connectivities really...

So I do:
Code:
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName(filepath)
reader.ReadAllFieldsOn()
reader.ReadAllVectorsOn()
reader.ReadAllScalarsOn()
reader.Update()

vtkdata = reader.GetOutput()
celldata = vtkdata.GetCellData()
And that's okay for the actual data (U, p, etc.).

Then I tried
Code:
cells = vtkdata.GetCells()
but still Icould not manage to get point IDs/coords for each cell?

From the VTK user manual, it's not completely clear to me (haven't gone through the whole thing though...).
I hope someone can give me some light on this.

Cheers,
Gino
manuc likes this.
ginop is offline   Reply With Quote

Old   May 4, 2018, 22:31
Default
  #2
New Member
 
Gino Parisella
Join Date: Mar 2017
Location: Perth, Western Australia
Posts: 22
Rep Power: 9
ginop is on a distinguished road
Found a solution thanks to this post

The code extension should look like:
Code:
cells = vtkdata.GetCells()
cellpoints = vtk_to_numpy(cells.GetData())
i=0
cell_point_id = list()
while i < cells.GetSize():
    pts = cellpoints[i]
    cell_point_id.append(cellpoints[i+1:i+pts+1])
    i += pts + 1
ginop is offline   Reply With Quote

Reply


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
[General] Generating isosurface from vtk file with python script Leios ParaView 1 March 26, 2018 12:33
[General] Paraview.simple python module and loading legacy vtk file timeseries awa5114 ParaView 2 July 17, 2017 08:40
[General] How can I use python script to generate animation from 2000 frames of vtk datasets LieyuShi ParaView 3 March 10, 2016 13:37
get Bounds of VTK in python Eloise OpenFOAM Post-Processing 1 June 26, 2014 09:42
[General] VTK API: Working with values inside the python shell Thoma ParaView 4 January 10, 2013 14:35


All times are GMT -4. The time now is 09:54.