VTK#

Implementation for reading and writing VTK files.

Interface#

enum CellType#

The VTK cell types and the corresponding VTK integer type.

Values:

enumerator point#
enumerator line#
enumerator triangle#
enumerator quadrilateral#
enumerator tetrahedron#
enumerator pyramid#
enumerator wedge#
enumerator hex#
int get_num_vertices(CellType t)#

Map the VTK cell type to the expected number of vertices.

Parameters:

t – Cell type.

Returns:

Number of vertices.

struct UnstructuredCell#
#include <vtk.hpp>

Datatype for representing the data for a single cell.

Public Members

int num_points#

Number of points for the cell.

std::vector<double> points#

Coordinates of the points. This vector should be 3 doubles per point linearised into a single vector.

CellType cell_type#

Enum describing the shape type.

std::map<std::string, double> cell_data#

Map from a quantity name to a single value for the cell.

std::map<std::string, std::vector<double>> point_data#

Map from a quantity name to a vector of size num_points containing the values for each point in the order the vertices are described in the points array.

class VTKHDF#
#include <vtk.hpp>

The VTKHDF class facilitates reading and writing VTKHDF files by using HDF5.

Public Functions

inline void close()#

Close the HDF5 file. This must be called collectively on the communicator.

inline VTKHDF(
std::string filename,
MPI_Comm comm,
std::string dataset_type = "UnstructuredGrid"
)#

Create a new VTKHDF file. Must be called collectively on the communicator.

Parameters:
  • filename – Output filename. This filename should end with the extension .vtkhdf.

  • comm – MPI communicator to use.

  • dataset_type – The type of data the user will write to the file.

inline void write(
std::vector<UnstructuredCell> &data,
std::set<std::string> point_data_keys = {},
std::set<std::string> cell_data_keys = {}
)#

Write unstructured data to the file. Must be called collectively on the communicator.

Parameters:
  • data – Data to write to the file.

  • point_data_keys – Explicitly define the expected keys in the data for consistent loop ordering with multiple MPI ranks.

  • cell_data_keys – Explicitly define the expected keys in the data for consistent loop ordering with multiple MPI ranks.

inline void read(
const int num_cells,
std::vector<UnstructuredCell> &data,
std::set<std::string> point_data_keys,
std::set<std::string> cell_data_keys
)#

Read unstructured data from a VTKHDF file. It is assumed that the parallel decomposition is identical to the decomposition used to write the file. Must be called collectively on the communicator.

Parameters:
  • num_cells[in] Number of cells on this MPI rank.

  • data[inout] Output data read from file. Will be resized as needed.

  • point_data_keys[in] Specification of which point data to read.

  • cell_data_keys[in] Specification of which cell data to read.