nschloe/meshio

[BUG] Xdmf TimeSeriesWriter creates a Xdmf file in which static mesh is duplicated

amit112amit opened this issue · 0 comments

Describe the bug
The XDMF TimeSeriesWriter creates a Xdmf file in which the static mesh is present in a <Grid Name='mesh'> tag as a child of the <Domain> tag. The <Geometry> and <Topology> tags are included in the temporal collection via xpointer. This leads to duplication of the static mesh.

To Reproduce

import meshio
import numpy as np

points = [
    [0.0, 0.0, 0.0],
    [1.0, 2.0, 0.0],
    [2.0, 0.0, 0.0],
    [1.0, -2., 0.0]
]

cells = {
    'triangle': [[2, 1, 0], [3, 2, 0]]
}

with meshio.xdmf.TimeSeriesWriter('Test.xdmf') as writer:
    writer.write_points_cells(points, cells)
    for t in [0.0, 0.1]:
        displ = np.array([
                             [0.0, 0.0, 10*t],
                             [0.0, 0.0, 0.0],
                             [0.0, 0.0, 10*t],
                             [0.0, 0.0, 0.0]
                         ])
        writer.write_data(t, point_data={"Displacement": displ})

The above code creates the following Test.xdmf file:

<Xdmf xmlns:ns0="http://www.w3.org/2003/XInclude" Version="3.0">
    <Domain>
        <Grid Name="TimeSeries_meshio" GridType="Collection" CollectionType="Temporal">
            <Grid>
                <ns0:include xpointer="xpointer(//Grid[@Name=&quot;mesh&quot;]/*[self::Topology or self::Geometry])" />
                <Time Value="0.0" />
                <Attribute Name="Displacement" AttributeType="Vector" Center="Node">
                    <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data2</DataItem>
                </Attribute>
            </Grid>
            <Grid>
                <ns0:include xpointer="xpointer(//Grid[@Name=&quot;mesh&quot;]/*[self::Topology or self::Geometry])" />
                <Time Value="0.1" />
                <Attribute Name="Displacement" AttributeType="Vector" Center="Node">
                    <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data3</DataItem>
                </Attribute>
            </Grid>
        </Grid>
        <Grid Name="mesh" GridType="Uniform">
            <Geometry GeometryType="XYZ">
                <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data0</DataItem>
            </Geometry>
            <Topology TopologyType="Triangle" NumberOfElements="2">
                <DataItem DataType="Int" Dimensions="2 3" Format="HDF" Precision="8">Test.h5:/data1</DataItem>
            </Topology>
        </Grid>
    </Domain>
</Xdmf>

If we open this file in ParaView, use WarpByVector with the Displacement vector, and move to the last time step, we can see both the static and deformed mesh as shown in the screenshot below

image

The problem can be resolved if the static mesh tag is moved out of the <Domain> tag as in the below Test.xdmf file:

<Xdmf xmlns:ns0="http://www.w3.org/2003/XInclude" Version="3.0">
    <Domain>
        <Grid Name="TimeSeries_meshio" GridType="Collection" CollectionType="Temporal">
            <Grid>
                <ns0:include xpointer="xpointer(//Grid[@Name=&quot;mesh&quot;]/*[self::Topology or self::Geometry])" />
                <Time Value="0.0" />
                <Attribute Name="Displacement" AttributeType="Vector" Center="Node">
                    <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data2</DataItem>
                </Attribute>
            </Grid>
            <Grid>
                <ns0:include xpointer="xpointer(//Grid[@Name=&quot;mesh&quot;]/*[self::Topology or self::Geometry])" />
                <Time Value="0.1" />
                <Attribute Name="Displacement" AttributeType="Vector" Center="Node">
                    <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data3</DataItem>
                </Attribute>
            </Grid>
        </Grid>        
    </Domain>
    <Grid Name="mesh" GridType="Uniform">
          <Geometry GeometryType="XYZ">
              <DataItem DataType="Float" Dimensions="4 3" Format="HDF" Precision="8">Test.h5:/data0</DataItem>
          </Geometry>
          <Topology TopologyType="Triangle" NumberOfElements="2">
              <DataItem DataType="Int" Dimensions="2 3" Format="HDF" Precision="8">Test.h5:/data1</DataItem>
          </Topology>
     </Grid>
</Xdmf>

Now in Paraview, the static mesh is not duplicated

image

Diagnose

pip freeze | grep meshio

gives

meshio==5.3.4

Did I help?

If I was able to resolve your problem, consider sponsoring my work on meshio, or buy me a coffee to say thanks.