pysdic.Mesh.from_vtk#

classmethod Mesh.from_vtk(filename, element_type=None, load_properties=True)[source]#

Create a Mesh instance from a VTK file (Only for 3D embedding dimension meshes \(E=3\)).

This method uses meshio to read the VTK file and then converts it to a Mesh instance.

See also

Warning

This method is only compatible with meshes having an embedding dimension of 3.

Parameters:
  • filename (str) – The path to the VTK file.

  • element_type (Optional[str], optional) – The expected type of elements in the mesh, by default None.

  • load_properties (bool, optional) – If True, properties are extracted from the VTK file, by default True.

Returns:

A Mesh instance created from the VTK file.

Return type:

Mesh

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

  • ValueError – If the file format is not supported or the mesh structure is invalid.

Examples

Create a simple meshio.Mesh object.

1import numpy as np
2import meshio
3from pysdic import Mesh
4
5points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
6cells = [("triangle", np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]]))]
7
8mesh = meshio.Mesh(points=points, cells=cells)

Save the meshio Mesh object to a VTK file.

1mesh.write("simple_mesh.vtk", file_format="vtk")

Create a Mesh instance from the VTK file.

1mesh3d = Mesh.from_vtk("simple_mesh.vtk")
2print(mesh3d.vertices)
3# Output: PointCloud with 4 points [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]