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 = dolfinx.io.XDMFFile(MPI.COMM_WORLD, "out.xdmf", "w", encoding=dolfinx.io.XDMFFile.Encoding.HDF5)
out_file.write_mesh(mesh)

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)

out_file.close()

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.

2 Likes