nschloe / meshio

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

[BUG] Writing a VTU uses version 0.1 rather than 1.0 #1472

Open tpgillam opened 3 months ago

tpgillam commented 3 months ago

Describe the bug Writing an unstructure grid to VTU specifies file version as 0.1, when I think it should be 1.0.

To Reproduce

import tempfile
from pathlib import Path

import meshio

print(f"{meshio.__version__=}")
print()

mesh = meshio.Mesh([[0, 0, 0], [1, 0, 0], [0, 1, 0]], [("triangle", [[0, 1, 2]])])

# Workaround: mesh.write doesn't support a buffer, only a path to a file.
with tempfile.TemporaryDirectory() as temp_dir:
    out_file = Path(temp_dir) / "moo.vtu"
    mesh.write(out_file, "vtu")
    print(out_file.read_text())

Gives the output (curtailed for brevity):

meshio.__version__='5.3.5'

<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian" compressor="vtkZLibDataCompressor">
<!--This file was created by meshio v5.3.5-->
<UnstructuredGrid>
<Piece NumberOfPoints="3" NumberOfCells="1">
<Points>
...

The problem is that version="0.1" here should, I think, be version="1.0".

The unofficial wiki states that the VTKFile attribute is only supported in version 1.0 of the spec. We include this attribute.

In practice, this bug causes incompatibilities with other readers. For example, for reading VTU files in Julia, ReadVTK.jl has an assertion for version being 1.0 or greater.

tpgillam commented 3 months ago

I believe this is the section that would need changing: https://github.com/nschloe/meshio/blob/b2ee99842e119901349fdeee06b5bf61e01f450a/src/meshio/vtu/_vtu.py#L647-L654