Hi all
I’m almost new in Paraview (basic use of the graphical interface), and this is the first time i’m trying to use vtk library, so sorry if my questions are very basic. Of course i’m looking for answers into internet, but the documentation is quite huge, and sometimes i’m lost.
Context: i need to analyse dozens of vtu files (from finite elements analyses) and i’m want to do it using python (and the vtk library); for now, I can get most of the arrays (type, connectivity, offsets, cellsData, etc), but i cannot get points ids and cells ids, so i’m wondering:
- is ids implicit?
- in other wiords, have nodes arrays implicitely sorted from from 0 to N (where N is the number of points): [0, 1, 2, … N]
- same things for the cells?
- when there are several types of elements (type 12, 13, 14, etc), i feel that all elements have been gathered by type (for optimization purposes), am i right?
Here after my “notes”: do not hesitate to link my a documentation that help me to better understand on how to extract data outside paraview.
Thanks for your help
Paul
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(os.path.join(path, vtuName))
reader.Update()
obj = reader.GetOutput()
# https://vtk.org/doc/nightly/html/classvtkCellArray.html
# Internally, the connectivity table is represented as two arrays: Offsets and Connectivity.
# Offsets is an array of [numCells+1] values indicating the index in the Connectivity array where each cell's points start. The last value is always the length of the Connectivity array.
# The Connectivity array stores the lists of point ids for each cell.
getNumberofCells = int(obj.GetCells().GetNumberOfCells()) # explicit => ok
cellOffsets = np.asarray(obj.GetCells().GetOffsetsArray()) # dim = numb of cells +1 =>ok
cellConnectivity = np.asarray(obj.GetCells().GetConnectivityArray()) # connectivity (to be analysed)
getCellType = np.asarray(obj.GetCellTypesArray()) # explicit => ok
cellConnectivityIds = np.asarray(obj.GetCells().GetNumberOfConnectivityIds()) # number
cellData = list(obj.GetCellData()) # list of available data => ok
cells = np.asarray(obj.GetCells().GetData()) # per element => seems number of points + connectivity (to be confirmed)
pointsData = list(obj.GetPointData()) # list of nodes results => ok
# https://vtk.org/doc/nightly/html/classvtkPoints.html
points = np.asarray(obj.GetPoints().GetData()) # nodes coordinates
numberPoints = int(obj.GetPoints().GetNumberOfPoints()) # explicit => ok
Ids = 0
specificpointscoordinates = np.asarray(obj.GetPoints().GetPoint(Ids)) # provide node coordinates from specified ids