nschloe / meshio

:spider_web: input/output for many mesh formats
MIT License
1.96k stars 402 forks source link

[BUG] write fails on a read mesh #1306

Open dominik-kern opened 2 years ago

dominik-kern commented 2 years ago

Reading a mesh works (msh-file created with gmsh 4.8.4), but writing it fails. The problem occurs with meshIO==5.3.4, in previous versions there was no problem (using the same mesh).

Running

mesh = meshio.read(input_filename)
# there is no modification of mesh
meshio.write(output_filename, mesh)    

results in

Traceback (most recent call last):

  File "msh2vtu.py", line 231, in <module>
    meshio.write(output_basename + "_original.vtu", mesh, binary=not args.ascii)   # there seems to be a bug

  File "/home/dominik/.local/lib/python3.9/site-packages/meshio/_helpers.py", line 188, in write
    return writer(filename, mesh, **kwargs)

  File "/home/dominik/.local/lib/python3.9/site-packages/meshio/vtu/_vtu.py", line 644, in write
    mesh.cell_sets_to_data(key)

  File "/home/dominik/.local/lib/python3.9/site-packages/meshio/_mesh.py", line 328, in cell_sets_to_data
    arr[cc] = i

IndexError: index 1 is out of bounds for axis 0 with size 1

It is a simple mesh (unit_square)

<meshio mesh object>
  Number of points: 5
  Number of cells:
    line: 1
    line: 1
    line: 1
    line: 1
    triangle: 4
  Cell sets: unten, rechts, oben, links, Einheitsquadrat, gmsh:bounding_entities
  Point data: gmsh:dim_tags
  Cell data: gmsh:physical, gmsh:geometrical
  Field data: unten, rechts, oben, links, Einheitsquadrat
dominik-kern commented 2 years ago

for the sake of completeness, the geo-file

Point(1) = {0, 0, 0, 1.0};
Point(2) = {1, 0, 0, 1.0};
Point(3) = {1, 1, 0, 1.0};
Point(4) = {0, 1, 0, 1.0};

Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};

Line Loop(1) = {1, 2, 3, 4};
Plane Surface(1) = {1};

Physical Curve("unten") = {1};
Physical Curve("rechts") = {2};
Physical Curve("oben") = {3};
Physical Curve("links") = {4};
Physical Surface("Einheitsquadrat") = {1};