pysdic.Mesh.from_meshio#

classmethod Mesh.from_meshio(mesh, element_type=None, load_properties=True)[source]#

Create a Mesh instance from a meshio.Mesh object.

The following fields are extracted:

  • mesh.points → vertices

  • mesh.cells[0].data → connectivity

  • mesh.point_data → vertices properties as arrays of shape (N, A)

  • mesh.cell_data → elements properties as arrays of shape (M, B)

See also

Parameters:
  • mesh (meshio.Mesh) – A meshio Mesh object to extract the first cell block and create the Mesh instance.

  • 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 meshio.Mesh object, by default True.

Returns:

A Mesh instance created from the meshio.Mesh object.

Return type:

Mesh

Raises:
  • TypeError – If the input is not a meshio.Mesh object. If element_type is not a string. If load_properties is not a boolean.

  • ValueError – If the mesh structure is invalid. If element_type is invalid or does not match the mesh structure.

Examples

Lets create a mesh using meshio.Mesh and convert it to a Mesh instance.

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)

Create a Mesh instance from the meshio.Mesh object.

1mesh3d = Mesh.from_meshio(mesh, element_type="triangle_3")
2print(mesh3d.vertices)
3# Output: PointCloud with 4 points [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]]