pysdic.Mesh.from_npz#

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

Create a Mesh instance from a NPZ file.

This method uses numpy to read the NPZ file and then converts it to a Mesh instance.

See also

Parameters:
  • filename (str) – The path to the NPZ 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 NPZ file, by default True.

Returns:

A Mesh instance created from the NPZ 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
2from pysdic import Mesh
3
4points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
5cells = np.array([[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]])
6mesh = Mesh(vertices=points, connectivity=cells, element_type="triangle_3")
7mesh.save_npz("simple_mesh.npz")

Create a Mesh instance from the NPZ file.

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