Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tpgillam opened this issue Jun 12, 2024 · 1 comment
Open

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

tpgillam opened this issue Jun 12, 2024 · 1 comment

Comments

@tpgillam
Copy link

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
Copy link
Author

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"),
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant