Unable to read VTK files of version 2.2."

Hello everyone, I saved a temperature field as a VTK file:

vtkFile = io.VTKFile(MPI.COMM_WORLD, f"Temperature/1/contact/f1.pvd", "w")
vtkFile.write_function(Delta_Tf)
vtkFile.close()

Now I want to modify the coordinate data in the VTK file, so I used the following code to read the file, but an error occurred:

import meshio
import math

m = meshio.read("Temperature/1/contact/f1_p0_000000.vtu")    
coords = m.points  
x = 1
y = 2

for i in range(len(coords)):
    coords[i][0] += x
    coords[i][1] += y
m.points= coords
meshio.write("Temperature/1/contact/f1_p0_000000.vtu", m)
Error: Couldn't read file Temperature/1/contact/f1_p0_000000.vtu as vtu
Unknown VTU file version '2.2'.

The problem seems to be that this reading code does not support VTK files of version 2.2. Currently, the solution I know is to manually change the version of the VTK file to 1.0, and then it can be read correctly. However, this method is not suitable for batch processing, as manually modifying the version of every VTK file is quite time-consuming. Is there a simpler way, or could I save the result as an XDMF file instead? What would be the corresponding code to read and modify the coordinate data in an XDMF file? I would appreciate any help. Thank you!

This is a meshio question: meshio/src/meshio/vtu/_vtu.py at main · nschloe/meshio · GitHub (as that is how you are reading in the data).

Have you tried to use pyvista to read in the vtu data?

“I haven’t used PyVista. If I were to use PyVista, could you please let me know what the equivalent code would be (to read and modify coordinate data)?”

Alternatively, is it possible to specify the version when saving a VTK file? If it can be set to 1.0 instead of the default generated version 2.2, that would also solve the problem.

I don’t think we support VTK datafile 1.0, as that format is quite old: https://vtk.org/wp-content/uploads/2015/04/file-formats.pdf, as already in 2015 the VTK Datafile version was 3.0.

The VTK Datafile 1.0 is an ascii based format (which we do not have implemented, as it is very restrictive in parallel: VTKData/Data/hello.vtk at master · naucoin/VTKData · GitHub)

See: pyvista.get_reader — PyVista 0.44.2 documentation

I tried using PyVista and successfully implemented the mentioned functionality. Thank you!