Visualization of cell tags with Paraview (XDMF)

Hi all,

I’m having problem visualizing meshtags in Paraview (version 5.13.1). In the following MWE I build a simple mesh and define meshtags (0 and 1) as a MeshTags object (named mesh_tags) and as a ("DG", 0) function (named tagfun). Then I export them as an xdmf file with the commands write_meshtags and write_function.

from mpi4py import MPI
from dolfinx import mesh, fem
from dolfinx.fem import Function, functionspace
from dolfinx.io import XDMFFile
from dolfinx.mesh import locate_entities, meshtags, MeshTags, create_unit_square, CellType
import numpy as np

def Omega_0(x):
    return x[1] <= 0.5
def Omega_1(x):
    return x[1] >= 0.5

mesh = create_unit_square(MPI.COMM_WORLD, 10, 10, CellType.triangle)
cells_0 = locate_entities(mesh, mesh.topology.dim, Omega_0)
cells_1 = locate_entities(mesh, mesh.topology.dim, Omega_1)
sorted_cells = np.sort(np.concatenate((cells_0, cells_1)))
tags = np.zeros_like(sorted_cells)
tags[np.isin(sorted_cells, cells_0)] = 0
tags[np.isin(sorted_cells, cells_1)] = 1
cell_tags = meshtags(mesh, mesh.topology.dim, sorted_cells, tags)

Q = functionspace(mesh, ("DG", 0))
tagfun = Function(Q, name="tagfun")
tagfun.x.array[:] = cell_tags.values

file_results = XDMFFile(MPI.COMM_WORLD, "tagtest/tagstest.xdmf", "w")
file_results.write_mesh(mesh)
file_results.write_meshtags(cell_tags, mesh.geometry)
file_results.write_function(tagfun)
file_results.close()

Although the mesh_tags array shows up in the properties of the file, I can’t find a way to visualize it. Look at the screenshots:

Instead, if I replace the last few lines of the MWE with

file_results = XDMFFile(MPI.COMM_WORLD, "tagtest/tagstest.xdmf", "w")
file_results.write_mesh(mesh)
file_results.write_meshtags(cell_tags, mesh.geometry)
file_results.close()

i.e., when the MeshTags object is the only data exported in the xdmf file aside from the mesh, then I’m able to access the mesh_tags array, as you can see from the screenshots:


Exporting mesh tags as functions is not ideal as it forces me to write them at every time of the simulation, making the xdmf file unnecessarily large.

How trivial is this issue? :slight_smile:

Ese the extract block filter to extract the tag or function, ref:
https://jsdokken.com/dolfinx-tutorial/chapter1/membrane_paraview.html

Not sure that is the issue. Extract block isn’t even available:

The problem persists also in Paraview 6.0.0. The Extract block filter is greyed out and can not be selected.

Without an actual XDMF file (and corresponding hdf5 file if you use binary format), it is really hard to give any guidance here.

Dear Jørgen, please find below a xdmf file of a 3D first order mesh, with several meshtags and a DG0 function named MPI_rank.


<?xml version="1.0"?>
<!DOCTYPE Xdmf SYSTEM "Xdmf.dtd" []>
<Xdmf Version="3.0" xmlns:xi="https://www.w3.org/2001/XInclude">
  <Domain>
    <Grid Name="Grid" GridType="Uniform">
      <Topology TopologyType="Tetrahedron" NumberOfElements="16" NodesPerElement="4">
        <DataItem Dimensions="16 4" NumberType="Int" Format="XML">0 1 2 3
4 1 0 3
1 0 2 5
4 6 1 3
5 1 0 4
2 7 1 5
1 8 6 4
1 5 8 4
1 7 8 5
6 8 9 4
6 7 8 1
8 5 10 4
7 11 8 5
10 9 8 4
8 11 10 5
9 10 8 11
</DataItem>
      </Topology>
      <Geometry GeometryType="XYZ">
        <DataItem Dimensions="12 3" Format="XML">1.847759 0.765367 0.5
1 0 0.5
2 -0 1
2 -0 0
1.414214 1.414214 0
1.414214 1.414214 1
0 0 0
0 0 1
0 1 0.5
-0 2 0
0.765367 1.847759 0.5
0 2 1
</DataItem>
      </Geometry>
    </Grid>
    <Grid Name="MPI_rank" GridType="Collection" CollectionType="Temporal">
      <Grid Name="MPI_rank" GridType="Uniform">
        <xi:include xpointer="xpointer(/Xdmf/Domain/Grid[@GridType='Uniform'][1]/*[self::Topology or self::Geometry])" />
        <Time Value="0" />
        <Attribute Name="MPI_rank" AttributeType="Scalar" Center="Cell">
          <DataItem Dimensions="16 1" Format="XML">0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
</DataItem>
        </Attribute>
      </Grid>
    </Grid>
    <Grid Name="x_fixed_edges" GridType="Uniform">
      <xi:include xpointer="xpointer(/Xdmf/Domain/Grid/Geometry)" />
      <Topology TopologyType="PolyLine" NumberOfElements="11" NodesPerElement="2">
        <DataItem Dimensions="11 2" NumberType="Int" Format="XML">2 3
2 5
2 7
4 3
6 3
9 4
11 5
6 7
6 9
7 11
9 11
</DataItem>
      </Topology>
      <Attribute Name="x_fixed_edges" AttributeType="Scalar" Center="Cell">
        <DataItem Dimensions="11 1" Format="XML">0
1
0
0
0
0
1
0
0
0
0
</DataItem>
      </Attribute>
    </Grid>
    <Grid Name="y_fixed_faces" GridType="Uniform">
      <xi:include xpointer="xpointer(/Xdmf/Domain/Grid/Geometry)" />
      <Topology TopologyType="Triangle" NumberOfElements="20" NodesPerElement="3">
        <DataItem Dimensions="20 3" NumberType="Int" Format="XML">0 2 3
0 2 5
4 0 3
5 0 4
1 2 3
2 7 1
6 1 3
6 7 1
2 7 5
4 6 3
5 10 4
6 9 4
10 9 4
7 11 5
11 10 5
6 7 8
6 8 9
7 11 8
9 8 11
9 10 11
</DataItem>
      </Topology>
      <Attribute Name="y_fixed_faces" AttributeType="Scalar" Center="Cell">
        <DataItem Dimensions="20 1" Format="XML">0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
0
</DataItem>
      </Attribute>
    </Grid>
    <Grid Name="z_fixed_faces" GridType="Uniform">
      <xi:include xpointer="xpointer(/Xdmf/Domain/Grid/Geometry)" />
      <Topology TopologyType="Triangle" NumberOfElements="20" NodesPerElement="3">
        <DataItem Dimensions="20 3" NumberType="Int" Format="XML">0 2 3
0 2 5
4 0 3
5 0 4
1 2 3
2 7 1
6 1 3
6 7 1
2 7 5
4 6 3
5 10 4
6 9 4
10 9 4
7 11 5
11 10 5
6 7 8
6 8 9
7 11 8
9 8 11
9 10 11
</DataItem>
      </Topology>
      <Attribute Name="z_fixed_faces" AttributeType="Scalar" Center="Cell">
        <DataItem Dimensions="20 1" Format="XML">1
1
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
1
</DataItem>
      </Attribute>
    </Grid>
    <Grid Name="my_faces" GridType="Uniform">
      <xi:include xpointer="xpointer(/Xdmf/Domain/Grid/Geometry)" />
      <Topology TopologyType="Triangle" NumberOfElements="20" NodesPerElement="3">
        <DataItem Dimensions="20 3" NumberType="Int" Format="XML">0 2 3
0 2 5
4 0 3
5 0 4
1 2 3
2 7 1
6 1 3
6 7 1
2 7 5
4 6 3
5 10 4
6 9 4
10 9 4
7 11 5
11 10 5
6 7 8
6 8 9
7 11 8
9 8 11
9 10 11
</DataItem>
      </Topology>
      <Attribute Name="my_faces" AttributeType="Scalar" Center="Cell">
        <DataItem Dimensions="20 1" Format="XML">0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
</DataItem>
      </Attribute>
    </Grid>
    <Grid Name="my_edges" GridType="Uniform">
      <xi:include xpointer="xpointer(/Xdmf/Domain/Grid/Geometry)" />
      <Topology TopologyType="PolyLine" NumberOfElements="11" NodesPerElement="2">
        <DataItem Dimensions="11 2" NumberType="Int" Format="XML">2 3
2 5
2 7
4 3
6 3
9 4
11 5
6 7
6 9
7 11
9 11
</DataItem>
      </Topology>
      <Attribute Name="my_edges" AttributeType="Scalar" Center="Cell">
        <DataItem Dimensions="11 1" Format="XML">0
0
0
0
1
0
0
0
0
0
0
</DataItem>
      </Attribute>
    </Grid>
  </Domain>
</Xdmf>