Input/Outputs

vtkIO module of geos-mesh package contains generic methods to read and write different format of VTK meshes.

geos.mesh.io.vtkIO module

Input and Output methods for various VTK mesh formats. Supports reading: .vtk (legacy), .vtu, .vts, .vti, .vtp, .vtr, .pvtu, .pvts, .pvti, .pvtp, .pvtr Supports writing: .vtk, .vtu, .vts Uses vtkXMLGenericDataObjectReader for automatic XML format detection.

class geos.mesh.io.vtkIO.PVDReader(filename, logger=None)[source]

Bases: object

PVD Reader class.

Parameters:
  • filename (str) – PVD filename with full path.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

getAllTimestepsValues()[source]

Get the list of all timesteps values from the PVD.

Returns:

List of timesteps values.

Return type:

list[float]

getDataSetAtTimeIndex(timeIndex)[source]

Get the dataset corresponding to requested time index.

Parameters:

timeIndex (int) – Time index

Returns:

Dataset

Return type:

vtkDataSet

class geos.mesh.io.vtkIO.VtkFormat(value)[source]

Bases: Enum

Enumeration for supported VTK file formats and their extensions.

PVTI = '.pvti'
PVTP = '.pvtp'
PVTR = '.pvtr'
PVTS = '.pvts'
PVTU = '.pvtu'
VTI = '.vti'
VTK = '.vtk'
VTP = '.vtp'
VTR = '.vtr'
VTS = '.vts'
VTU = '.vtu'
class geos.mesh.io.vtkIO.VtkOutput(output, isDataModeBinary=True)[source]

Bases: object

Configuration for writing a VTK file.

isDataModeBinary = True
output
geos.mesh.io.vtkIO.createPVD(outputDir, pvdFilename, outputFiles, logger=None)[source]

Create PVD collection file.

Parameters:
  • outputDir (Path) – Output directory

  • pvdFilename (str) – Output PVD filename

  • outputFiles (list[tuple[int, str]]) – List containing all the filenames of the PVD files

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

geos.mesh.io.vtkIO.readMesh(filepath)[source]

Reads a VTK file, automatically detecting the format.

Uses vtkXMLGenericDataObjectReader for all XML-based formats (.vtu, .vts, .vti, .vtp, .vtr and their parallel variants) and vtkUnstructuredGridReader for legacy .vtk format.

Parameters:

filepath (str) – The path to the VTK file.

Raises:
  • FileNotFoundError – If the input file does not exist.

  • ValueError – If no suitable reader can be found for the file.

Returns:

The resulting mesh data.

Return type:

vtkPointSet

geos.mesh.io.vtkIO.readUnstructuredGrid(filepath)[source]

Reads a VTK file and ensures it is a vtkUnstructuredGrid.

This function uses the general readMesh to load the data and then validates its type.

Parameters:

filepath (str) – The path to the VTK file.

Raises:
  • FileNotFoundError – If the input file does not exist.

  • ValueError – If no suitable reader can be found for the file.

  • TypeError – If the file is read successfully but is not a vtkUnstructuredGrid.

Returns:

The resulting unstructured grid data.

Return type:

vtkUnstructuredGrid

geos.mesh.io.vtkIO.writeMesh(mesh, vtkOutput, canOverwrite=False, logger=None)[source]

Writes a vtkPointSet to a file.

The format is determined by the file extension in VtkOutput.output.

Parameters:
  • mesh (vtkPointSet) – The grid data to write.

  • vtkOutput (VtkOutput) – Configuration for the output file.

  • canOverwrite (bool, optional) – If False, raises an error if the file already exists. Defaults to False.

  • logger (Union[Logger, None], optional) – A logger to manage the output messages. Defaults to None, an internal logger is used.

Raises:
  • FileExistsError – If the output file exists and canOverwrite is False.

  • ValueError – If the file extension is not a supported write format.

  • RuntimeError – If the VTK writer fails to write the file.

Returns:

Returns 1 on success, consistent with the VTK writer’s return code.

Return type:

int