I have a vtk file and I need to extract from it a three-dimensional velocity vector. I have never used one so I do not really know what it contains and how to extract informations from it.
In stack overflow I found this question Save an array of data from a VTK in Python, which helped, and I was able to extract my data.
This is the script I used:
import vtk as v
import numpy as np
Filename = 'filename.vtk'
reader = v.vtkUnstructuredGridReader()
reader.SetFileName(Filename)
reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
pa = v.vtkPassArrays()
pa.SetInputConnection(reader.GetOutputPort())
pa.AddArray(0, 'velocity_magnitude' )
print(pa)
writer = v.vtkDataSetWriter()
writer.SetFileName('test.vtk')
writer.SetInputConnection(pa.GetOutputPort())
writer.Update()
writer.Write()
And this is the file I ended up with:
# vtk DataFile Version 4.2
vtk output
ASCII
DATASET UNSTRUCTURED_GRID
FIELD FieldData 6
Nek_SpectralElementData 1 4 int
8 8 8 512
avtOriginalBounds 1 6 double
0 6.283185482 -1 1 0 3.141592741
VolumeDependent 1 1 bit
0
MeshName 1 1 string
mesh
CYCLE 1 1 int
1000
TIME 1 1 double
20
POINTS 262144 float
0 -1 1.5708 0.0503675 -1 1.5708 0.160339 -1 1.5708
0.310507 -1 1.5708 0.474891 -1 1.5708 0.625059 -1 1.5708
0.735031 -1 1.5708 0.785398 -1 1.5708 0 -0.997435 1.5708
0.0503675 -0.997435 1.5708 0.160339 -0.997435 1.5708 0.310507 -0.997435 1.5708
.
.
.
CELLS 175616 1580544
8 0 1 9 8 64 65 73 72
8 64 65 73 72 128 129 137 136
8 128 129 137 136 192 193 201 200
8 192 193 201 200 256 257 265 264
8 256 257 265 264 320 321 329 328
.
.
.
CELL_TYPES 175616
12
12
12
12
.
.
.
POINT_DATA 262144
VECTORS velocity float
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0.0113612 1.21843e-05 0.000552347
0.0115553 1.12597e-05 0.000419801 0.0121388 6.55409e-06 -0.000110149 0.0128729 -5.02466e-06 -0.000602613
So, doing some research I understood that in the first part I have the coordinates of the points, but why are they 9 per row? Then I understood that the points are connected by hexahedronal cells, there are 175616 of them, each one with 8 points, and next we have the positions of the corners of them, but I do not know how they are written. In the last part I finally have my velocity vector, but again, why 9 components per row? And how are the points arranged? To which point does the velocity of the first line relate to? And for the second, or third?
If you know some guide where I can read how to understand this file, you will help a lot.
Thank you very much!