vtk#

VTK file source for mesh pipelines.

Reads VTK-format files (.vtk, .vtp, .vtu, .vts, .vtm, .stl) from a local directory and converts each to a physicsnemo.mesh.Mesh (or, in domain-mesh mode, a physicsnemo.mesh.domain_mesh.DomainMesh).

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

The conversion supports multiple manifold dimensions (point clouds, lines, surfaces, volumes) and two point-source modes (vertices or cell centroids), each resolvable per file via path-glob rules. Data arrays can be filtered at the VTK reader level (include/exclude keyed by path glob) so unwanted fields are never materialised. Reading is delegated to the shared conversion core in physicsnemo_curator.domains.mesh.sources._vtk_convert, which supports both PyVista and a fast native Rust backend.

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'] | list[dict] = 'auto',
point_source: Literal['vertices', 'cell_centroids'] | list[dict] = 'vertices',
warn_on_lost_data: bool = True,
backend: physicsnemo_curator.domains.mesh.sources._vtk_convert.Backend = 'pyvista',
key_filters: list[dict] | None = None,
volume_pattern: str | None = None,
boundary_pattern: str | None = None,
boundary_name: str = 'vehicle',
boundary_generator: Any = None,
)#

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, {"auto"}, or list[dict]) –

    Target manifold dimension passed to the conversion:

    • "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).

    May also be a list of {"pattern": glob, "value": ...} rules to select the dimension per file (longest matching pattern wins), mirroring per-file-type defaults (e.g. volume_*.vtu -> 0).

  • point_source ({"vertices", "cell_centroids"} or list[dict]) –

    Controls what becomes the Mesh points (scalar or per-path rules):

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

    • "cell_centroids": cell centroids become points, cell_data is mapped to point_data.

  • warn_on_lost_data (bool) – If True (default), emit a warning when the PyVista conversion discards non-empty data arrays.

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

    VTK reading backend:

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

    • "rust": native Rust backend for faster reading of VTU/VTP; transparently falls back to PyVista when unsupported.

  • key_filters (list[dict] or None) – Per-path data-array filter rules. Each dict has path_pattern, mode ("include" / "exclude"), and keys. Applied at the reader level so dropped arrays are never materialised.

  • volume_pattern (str or None) – Filename glob identifying volume files for domain-mesh mode.

  • boundary_pattern (str or None) – Filename glob identifying boundary files for domain-mesh mode. When both volume_pattern and boundary_pattern are set, files are paired by parent directory into a DomainMesh per index; unpaired files fall back to standalone Mesh.

  • boundary_name (str) – Key under which the paired boundary mesh is stored in the DomainMesh (default "vehicle").

  • boundary_generator (object or None) – Optional boundary-condition generator applied to each assembled DomainMesh (domain-mesh mode). See physicsnemo_curator.domains.mesh.boundaries.

Examples

Local directory:

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

Domain-mesh mode (volume + boundary -> DomainMesh):

>>> source = VTKSource(
...     "./dataset/",
...     volume_pattern="volume_*.vtu",
...     boundary_pattern="boundary_*.vtp",
...     manifold_dim=[{"pattern": "**/volume_*", "value": 0}],
...     point_source=[{"pattern": "**/volume_*", "value": "cell_centroids"}],
... )

Note

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

Return parameter descriptors for the VTK source.

Returns:

Parameter list including file path, glob pattern, conversion options, array filters, and domain-mesh pairing patterns.

Return type:

list[Param]

relative_path(index: int) str#

Return the representative path of the index-th item relative to the root.

For standalone items this is the file itself; for volume/boundary pairs it is the volume file. Used by sinks (e.g. MeshSink) to resolve {relpath} and {stem} naming placeholders.

Parameters:

index (int) – Zero-based item 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, .stl) and convert to physicsnemo Mesh / DomainMesh'#
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