Describe the bug
meshio can properly read scalar, vector, and tensorial quantities from cell_data blocks. However, when these are written again as VTK, the structure is different and the files cannot be loaded in ParaView:
ERROR: In C:\glr\builds\paraview\paraview-ci\build\superbuild\paraview\src\VTK\IO\Legacy\vtkDataReader.cxx, line 838
vtkUnstructuredGridReader (000002505AAA51C0): Unsupported cell attribute type: 0.0 for file: S:\tmp\bugreport_meshio_rewritten.vtk
To Reproduce
Here is a small VTK file that contains all three types of Cell Data:
Python 3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import meshio
>>> meshio.__version__
'5.3.5'
>>> mesh = meshio.read('bugreport_meshio.vtk')
>>> mesh.write('bugreport_meshio_rewritten.vtk', binary=False)
Warning: VTK ASCII files are only meant for debugging.
As you can see, the dimensions for the tensor is completely wrong.
It seems like, that even though the rest is also different (was that changed in newer VTK versions?) the only line that breaks paraview is actually the wrong dimension of the tensor. If I replace the 3 with 9, it loads.
As the input data is of shape (N, 3, 3), only the second dimension is checked while the third is never looked at.
I guess the fix here would be to add another elif that checks for tensors and writes the product of the dimensions? However, I'm not familiar with VTK 5 format - all my scripts still write v2 (as you can see above :D)
Diagnose
I may ask you to cut and paste the output of the following command.
pip freeze | grep meshio
meshio==5.3.5
Did I help?
If I was able to resolve your problem, consider sponsoring my work on meshio, or buy me a coffee to say thanks.
Describe the bug meshio can properly read scalar, vector, and tensorial quantities from cell_data blocks. However, when these are written again as VTK, the structure is different and the files cannot be loaded in ParaView:
To Reproduce
Here is a small VTK file that contains all three types of Cell Data:
Write the file again with meshio:
The new mesh looks like this:
As you can see, the dimensions for the tensor is completely wrong. It seems like, that even though the rest is also different (was that changed in newer VTK versions?) the only line that breaks paraview is actually the wrong dimension of the tensor. If I replace the
3
with9
, it loads.The problem seems to come from here: https://github.com/nschloe/meshio/blob/b2ee99842e119901349fdeee06b5bf61e01f450a/src/meshio/vtk/_vtk_51.py#L640-L643
As the input data is of shape
(N, 3, 3)
, only the second dimension is checked while the third is never looked at.I guess the fix here would be to add another elif that checks for tensors and writes the product of the dimensions? However, I'm not familiar with VTK 5 format - all my scripts still write v2 (as you can see above :D)
Diagnose I may ask you to cut and paste the output of the following command.
Did I help?
If I was able to resolve your problem, consider sponsoring my work on meshio, or buy me a coffee to say thanks.