nschloe / meshio

:spider_web: input/output for many mesh formats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

tpgillam opened this issue · comments

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.

I believe this is the section that would need changing:

vtk_file = ET.Element(
"VTKFile",
type="UnstructuredGrid",
version="0.1",
# Use the native endianness. Not strictly necessary, but this simplifies things
# a bit.
byte_order=("LittleEndian" if sys.byteorder == "little" else "BigEndian"),
)