# Reading VTK file into C++ for analysis

I apologize in advance if this post is at all ignorant or elementary, I am a pure mathematician who is newly getting into the world of scientific computing.

For my research, my advisor would like me to analyze a few 3d numerical simulations in C++ all of which are in a VTK format. To be more specific, we are modeling fluid mixing and I am interested in obtaining data regarding the maximum height and width of certain fluid structures. I have been given separate VTK files, each detonating a separate parameter such as x velocity, y velocity, z velocity, pressure, and density.

Does anyone have any suggestions on how to get started with this? At the moment I am at a loss as to where to even begin.

Regards.

• You can get the data from the VTK files using the suitable reader (structured or unstructured grids) in the VTK library. You can do this in both C++ and Python. I suggest following [this example] (lorensen.github.io/VTKExamples/site/Cxx/IO/ReadUnstructuredGrid), Once you read the file into an object, you can extract the point/cell data. Refer to the VTK manual for details on extracting the data from the readers. – Chenna K Jul 22 '20 at 9:32
• @ChennaK Thank you. I will read through the link you provided and the VTK manual. Would I be able to read in multiple VTK files (as I mentioned I have different ones for different parameters, but all pertaining to the same simulation)? – WBSS Jul 22 '20 at 18:33
• If you are new to VTK, then I suggest against using the parallel API. If you are only interested in the maximum/minimum values in a data set, then the Range() function is good enough. vtk.org/doc/nightly/html/classvtkDataArray.html If you want to process the data in any other way, then you can loop over the VTK files and create STL vectors with copies of data from the VTK files. Once you get the data into STL vectors, then you can use STL algorithms for searching. This is quick; doesn't require searching through the vast VTK library. – Chenna K Jul 22 '20 at 20:57
• @ChennaK Thanks again for the reply. I am new to VTK so I will look into the parallel API. I also have very limited experience with C++, so this is amounting to quite the learning curve for me. To be more specific as to what I would like to do: I am analyzing fluid mixing in which bubble like structures arise. I would like to know the penetration height (and thus the local minimum) of each bubble, the position (so x,z coordinates), and width of each bubble. Would the libraries you suggested help with this or is there an easier way? – WBSS Jul 22 '20 at 23:31

• If you have many VTK files, use a for loop and a PartitionedDataSet. – user14717 Jul 22 '20 at 18:33