# Visualization of cell tags with Paraview (XDMF)

**URL:** <https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847>\
**Category:** General\
**Created:** [January 27, 2025, 12:47am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847 "2025-01-27T00:47:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabs](https://avatars.discourse-cdn.com/v4/letter/f/74df32/32.png) [@fabs](https://fenicsproject.discourse.group/u/fabs)\
**Post date:** [January 27, 2025, 12:47am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/1 "2025-01-27T00:47:07Z")

</div>

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`.

> ```auto
> 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:

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/f/f7dfa6ae0b04dcc0e4c5bfcc44c79465cb5608c7.png)

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/f/fe67d0aece367f4ebf1c88312990f16af9462e13.png)

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

> ```auto
> 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:

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/0/0cd3a2ebdde9c666a5e9dee4b9b83ac33bb1d2cc.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/89e6a9410e505135e42451429f3a5e4cabb71fd3.png)

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? 🙂

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [January 27, 2025, 4:41am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/2 "2025-01-27T04:41:05Z")

</div>

Ese the extract block filter to extract the tag or function, ref:  
[https://jsdokken.com/dolfinx-tutorial/chapter1/membrane\_paraview.html](https://jsdokken.com/dolfinx-tutorial/chapter1/membrane_paraview.html)

---

<div class="post-metadata">

**Author:** ![fabs](https://avatars.discourse-cdn.com/v4/letter/f/74df32/32.png) [@fabs](https://fenicsproject.discourse.group/u/fabs)\
**Post date:** [January 27, 2025, 5:10am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/3 "2025-01-27T05:10:13Z")

</div>

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

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/c/c1169b7b451c92b77ab010812bf2b44fdfde90f6.png)

---

<div class="post-metadata">

**Author:** ![Jari](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@Jari](https://fenicsproject.discourse.group/u/Jari)\
**Post date:** [June 12, 2025, 10:09am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/4 "2025-06-12T10:09:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 12, 2025, 11:16am UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/5 "2025-06-12T11:16:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jari](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@Jari](https://fenicsproject.discourse.group/u/Jari)\
**Post date:** [June 12, 2025, 12:05pm UTC](https://fenicsproject.discourse.group/t/visualization-of-cell-tags-with-paraview-xdmf/16847/6 "2025-06-12T12:05:52Z")

</div>

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.

```auto

<?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>

```
