Skip to content

Commit 1aaf91a

Browse files
authored
Merge pull request #1020 from nschloe/lagrange-read
Lagrange read
2 parents f85c3db + 7502386 commit 1aaf91a

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

meshio/vtu/_vtu.py

+36-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,19 @@ def _cells_from_data(connectivity, offsets, types, cell_data_raw):
5454
meshio_type = vtk_to_meshio_type[types[start]]
5555
except KeyError:
5656
raise ReadError("File contains cells that meshio cannot handle.")
57-
if meshio_type == "polygon":
57+
58+
# cells with varying number of points
59+
special_cells = [
60+
"polygon",
61+
"VTK_LAGRANGE_CURVE",
62+
"VTK_LAGRANGE_TRIANGLE",
63+
"VTK_LAGRANGE_QUADRILATERAL",
64+
"VTK_LAGRANGE_TETRAHEDRON",
65+
"VTK_LAGRANGE_HEXAHEDRON",
66+
"VTK_LAGRANGE_WEDGE",
67+
"VTK_LAGRANGE_PYRAMID",
68+
]
69+
if meshio_type in special_cells:
5870
# Polygons have unknown and varying number of nodes per cell.
5971
# IMPLEMENTATION NOTE: While polygons are different from other cells
6072
# they are much less different than polyhedral cells (for polygons,
@@ -893,10 +905,28 @@ def _polyhedron_face_cells(face_cells):
893905
for k, v in mesh.cells:
894906
# For polygon and polyhedron grids, the number of nodes is part of the cell
895907
# type key. This part must be stripped away.
896-
if k[:7] == "polygon":
897-
key_ = k[:7]
898-
elif k[:10] == "polyhedron":
899-
key_ = k[:10]
908+
special_cells = [
909+
"polygon",
910+
"polyhedron",
911+
"VTK_LAGRANGE_CURVE",
912+
"VTK_LAGRANGE_TRIANGLE",
913+
"VTK_LAGRANGE_QUADRILATERAL",
914+
"VTK_LAGRANGE_TETRAHEDRON",
915+
"VTK_LAGRANGE_HEXAHEDRON",
916+
"VTK_LAGRANGE_WEDGE",
917+
"VTK_LAGRANGE_PYRAMID",
918+
]
919+
key_ = None
920+
for string in special_cells:
921+
if k.startswith(string):
922+
key_ = string
923+
924+
if key_ is None:
925+
# No special treatment
926+
key_ = k
927+
928+
# further adaptions for polyhedron
929+
if k.startswith("polyhedron"):
900930
# Get face-cell relation on the vtu format. See comments in helper
901931
# function for more information of how to specify this.
902932
faces_loc, faceoffsets_loc = _polyhedron_face_cells(v)
@@ -908,9 +938,7 @@ def _polyhedron_face_cells(face_cells):
908938
assert faces is not None
909939
faces += faces_loc
910940
faceoffsets += faceoffsets_loc
911-
else:
912-
# No special treatment
913-
key_ = k
941+
914942
types_array.append(np.full(len(v), meshio_to_vtk_type[key_]))
915943

916944
types = np.concatenate(

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = meshio
3-
version = 4.3.8
3+
version = 4.3.9
44
author = Nico Schlömer et al.
55
author_email = [email protected]
66
description = I/O for many mesh formats

0 commit comments

Comments
 (0)