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.


  • $\begingroup$ 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. $\endgroup$ – Chenna K Jul 22 '20 at 9:32
  • $\begingroup$ @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)? $\endgroup$ – WBSS Jul 22 '20 at 18:33
  • $\begingroup$ 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. $\endgroup$ – Chenna K Jul 22 '20 at 20:57
  • $\begingroup$ @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? $\endgroup$ – WBSS Jul 22 '20 at 23:31

You can use VTK-m to parse the files and they will automatically show up in a sensible data structure, ready for parallel processing. The learning curve is a bit steep, but the documentation is very legible. Here's a demo which reads a VTK file and uses it for particle advection.

  • $\begingroup$ Thank you for the reply. So if I understand correctly, I load the files into my C++ program using VTK-m? How would I do that if I have many VTK files? Thank you for the links, I will browse through them. $\endgroup$ – WBSS Jul 22 '20 at 18:32
  • $\begingroup$ If you have many VTK files, use a for loop and a PartitionedDataSet. $\endgroup$ – user14717 Jul 22 '20 at 18:33
  • $\begingroup$ I see, thank you again for the prompt reply. I'm assuming after I have them all loaded I will have to write a code that searches for the data I'm looking for? This is the part I am most concerned with. $\endgroup$ – WBSS Jul 22 '20 at 18:34
  • $\begingroup$ Yes; there is no way to avoid searching for the data you are interested in. $\endgroup$ – user14717 Jul 22 '20 at 18:45
  • $\begingroup$ Are you aware of any example code which is available that I can use as a reference? I am curious as to how one would implement an algorithm to search for variables such as fluid structure height, width, placement solely based off the 5 parameters I mentioned in the OP. $\endgroup$ – WBSS Jul 22 '20 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.