pysdic.Mesh.from_meshio#
- classmethod Mesh.from_meshio(mesh, element_type=None, load_properties=True)[source]#
Create a Mesh instance from a
meshio.Meshobject.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
Mesh.to_meshio()for the reverse operation.meshio documentation for more information.
Meshfor more information on the Mesh class and element types.
- 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) – IfTrue, properties are extracted from themeshio.Meshobject, by defaultTrue.
- Returns:
A Mesh instance created from the
meshio.Meshobject.- Return type:
- Raises:
TypeError – If the input is not a
meshio.Meshobject. 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.Meshand convert it to aMeshinstance.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
Meshinstance from themeshio.Meshobject.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]]