vtk#

VTK file source for mesh pipelines.

Reads VTK-format files (.vtk, .vtp, .vtu, .vts, .vtm) from a local directory and converts each to a physicsnemo.mesh.Mesh using physicsnemo.mesh.io.from_pyvista().

File discovery uses pathlib.Path.glob() with an optional pattern, filtering to recognised VTK extensions.

The conversion supports multiple manifold dimensions (point clouds, lines, surfaces, volumes) and two point-source modes (vertices or cell centroids). See physicsnemo.mesh.io.from_pyvista() for full details.

Attributes#

Classes#

VTKSource

Read local VTK files and yield Mesh objects.

Module Contents#

class physicsnemo_curator.domains.mesh.sources.vtk.VTKSource(
input_path: str,
file_pattern: str = '**/*',
*,
manifold_dim: int | Literal['auto'] = 'auto',
point_source: Literal['vertices', 'cell_centroids'] = 'vertices',
warn_on_lost_data: bool = True,
backend: Backend = 'pyvista',
)#

Bases: physicsnemo_curator.core.base.Source[physicsnemo.mesh.Mesh]

Read local VTK files and yield Mesh objects.

File discovery uses pathlib.Path.glob() with an optional file_pattern, filtering to recognised VTK extensions. Only local paths are supported; for remote datasets use a domain-specific source such as DrivAerMLSource.

Parameters:
  • input_path (str) – Path to a local directory containing VTK files, or a single VTK file.

  • file_pattern (str) – Glob pattern for filtering files inside a directory. Defaults to "**/*" which recursively discovers all VTK files. Use "*" for flat (non-recursive) discovery, or a custom pattern such as "timestep_*" for selective matching.

  • manifold_dim (int or {"auto"}) –

    Target manifold dimension passed to from_pyvista:

    • "auto" (default): detect from cell types.

    • 0: point cloud (vertices only, no cells).

    • 1: line mesh (edge cells).

    • 2: surface mesh (triangulated).

    • 3: volume mesh (tetrahedralized).

  • point_source ({"vertices", "cell_centroids"}) –

    Controls what becomes the Mesh points:

    • "vertices" (default): mesh vertices become points, point_data is preserved.

    • "cell_centroids": cell centroids become points, cell_data is mapped to point_data. Only manifold_dim 0 and 1 are valid in this mode.

  • warn_on_lost_data (bool) – If True (default), emit a warning when the conversion discards non-empty data arrays (e.g. cell data lost during dimension reduction).

  • backend ({"pyvista", "rust"}) –

    VTK reading backend:

    • "pyvista" (default): use PyVista for full-featured reading.

    • "rust": use the native Rust backend for faster reading. Note: The Rust backend only supports ASCII VTU/VTP files and does not support manifold_dim or point_source options.

Examples

Local directory:

>>> source = VTKSource("./cfd_results/")
>>> len(source)
42
>>> mesh = next(source[0])

Custom glob pattern:

>>> source = VTKSource("./data/", file_pattern="timestep_*")

Using the fast Rust backend:

>>> source = VTKSource("./cfd_results/", backend="rust")

Note

classmethod params() list[physicsnemo_curator.core.base.Param]#

Return parameter descriptors for the VTK source.

Returns:

Parameter list including file path, glob pattern, and from_pyvista conversion options.

Return type:

list[Param]

relative_path(index: int) str#

Return the path of the index-th file relative to the root.

This is used by sinks (e.g. MeshSink) to resolve {relpath} and {stem} naming placeholders.

Parameters:

index (int) – Zero-based file index.

Returns:

POSIX-style relative path (e.g. "subdir/mesh.vtu").

Return type:

str

description: ClassVar[str] = 'Read VTK files (.vtk, .vtp, .vtu, .vts, .vtm) and convert to physicsnemo Mesh'#
name: ClassVar[str] = 'VTK Reader'#
property root: pathlib.Path#

Return the root directory of this source.

Returns:

The root directory containing the discovered VTK files.

Return type:

pathlib.Path

physicsnemo_curator.domains.mesh.sources.vtk.Backend#