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

read mixed XDMF 2 #600

Closed
gdmcbain opened this issue Dec 19, 2019 · 6 comments
Closed

read mixed XDMF 2 #600

gdmcbain opened this issue Dec 19, 2019 · 6 comments

Comments

@gdmcbain
Copy link
Contributor

In #599, distinguishing between how Polylines are written in XDMF depending on whether they're in TopologyType Polyline or Mixed, a simple test XDMF file generated by ParaView could not be read by meshio.

To reproduce: first generate the VTK

from numpy import array
from meshio import Mesh, write

mesh =  Mesh(array([[0., 0., 0.],
                    [1., 0., 0.],
                    [1., 1., 0.],
                    [0., 1., 0]]),
             {'line': array([[0, 1],
                             [2, 3],
                             [3, 0]]),
              'quad': array([[0, 1, 2, 3]])})
write('mixed.vtk', mesh)

then open and Save Data in ParaView (here 5.6.0). This gives:

<?xml version="1.0" ?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf xmlns:xi="http://www.w3.org/2003/XInclude" Version="2.2">
  <Domain>
    <Grid GridType="Uniform">
      <Topology TopologyType="Mixed" Dimensions="4">
        <DataItem Dimensions="17" NumberType="Int" Precision="8" Format="XML">
2 2 0 1 2 2 2 3 2 2 
3 0 3 0 1 2 3 
</DataItem>
      </Topology>
      <Geometry GeometryType="XYZ">
        <DataItem Dimensions="4 3" NumberType="Float" Precision="8" Format="XML">
0 0 0 
1 0 0 
1 1 0 
0 1 0 
</DataItem>
      </Geometry>
    </Grid>
  </Domain>
</Xdmf>

Attempting to read this XDMF in meshio raises a KeyError.

 File "/home/geordie/.local/share/miniconda3/envs/scikit-fem/lib/python3.7/site-packages/meshio/_helpers.py", line 67, in read
    return reader_map[file_format](filename)
  File "/home/geordie/.local/share/miniconda3/envs/scikit-fem/lib/python3.7/site-packages/meshio/xdmf/main.py", line 27, in read
    return XdmfReader(filename).read()
  File "/home/geordie/.local/share/miniconda3/envs/scikit-fem/lib/python3.7/site-packages/meshio/xdmf/main.py", line 48, in read
    return self.read_xdmf2(root)
  File "/home/geordie/.local/share/miniconda3/envs/scikit-fem/lib/python3.7/site-packages/meshio/xdmf/main.py", line 150, in read_xdmf2
    meshio_type = xdmf_to_meshio_type[c.attrib["TopologyType"]]
KeyError: 'Mixed'
@gdmcbain
Copy link
Contributor Author

This issue is not to be confused with #553; that was also entitled ‘read mixed XDMF’ but turned out to be related to the prefixing of Polylines with two twos in a mixed topology #599 rather than the mixed topology as such.

@gdmcbain
Copy link
Contributor Author

Ah. This example is XDMF 2.2, generated by ParaView 5.6.0; the examples in #553 were XDMF 3.0, generated by meshio.

@gdmcbain
Copy link
Contributor Author

ParaView 5.7.0 (Microsoft Windows 10) optionally saves XDMF 3.0 (mixed3.tar.gz) and that is correctly read by meshio.

Thus it looks like this issue only concerns TopologyType="Mixed" in XDMF 2.

gdmcbain added a commit to gdmcbain/meshio that referenced this issue Dec 19, 2019
gdmcbain added a commit to gdmcbain/meshio that referenced this issue Dec 19, 2019
@gdmcbain
Copy link
Contributor Author

I made a start on this (4e478eb) but it looks to me as though, in the example XDMF 2.2 generated above by ParaView 5.6.0, the DataItem for the connectivity of the 'quad' is incorrectly coded as the last five integers,

3 0 1 2 3

in which the last four are correctly the vertices but the first is the code for a Polygon. It should be 5 for a Quadrilateral. If it were a Polygon, it should be immediately followed by the number of vertices. There is an example of encoding a four-sided polygon as

3   4   4 5 6 7

in the Xdmf2 Modal and Format Archive.

As this is a legacy version of a format, and this latest bug concerns ParaView rather than meshio, I might deprioritize this in favour of #599.

@gdmcbain gdmcbain changed the title read mixed XDMF read mixed XDMF 2 Dec 19, 2019
@gdmcbain
Copy link
Contributor Author

Indeed, ParaView 5.6.0 fails to reread the quadrilateral. It doesn't raise an error and does count it as a cell but presumably as a Polygon with 0 vertices.

On the other hand, if the 3 is manually emended to 5, meshio on branch 600-read-mixed-xdmf2 at
4e478eb does successfully read the file.

@nschloe
Copy link
Owner

nschloe commented Dec 19, 2019

Fixed by #601.

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

2 participants