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!
“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.