Changing CollectionType in Dolfinx XDMF Writer

Is there a way to change the CollectionType of the XDMF writer in Dolfinx? Currently the CollectionType in the xdmf file is always Temporal. I’m working on a project where I need to adjust the collection type but haven’t found clear documentation on this. Any guidance or examples would be greatly appreciated. Should this be done in post, or is there a way to solve this drectly with the writer?

import dolfinx
import numpy as np
from mpi4py import MPI

mesh = dolfinx.mesh.create_rectangle(MPI.COMM_WORLD, [np.array([-2, -2]), np.array([2, 2])],
                                     [128, 128], dolfinx.mesh.CellType.triangle)
v = dolfinx.fem.FuncitionSpace(mesh, ("Lagrange", 1))
kappa = dolfinx.fem.Function(v)

out_file =, "out.xdmf", "w",

for exponent in range(10):
    kappa.interpolate(lambda x: x[0] ** exponent + x[1] ** exponent)
    # Would like to encode the exponent in the collection type
    out_file.write_function(kappa, exponent)


This is hard-coded in the XDMFFile when storing the mesh:

Please note that XDMFFile is not longer maintained by Kitware: Xdmf / Xdmf · GitLab (no activity in 3 years), and we recommend using other file formats, such as VTKFile, VTXWriter or FidesWriter, depending on the use-case at hand.