Export DG function correctly to paraview

I wonder how to correctly export a DG1 function to Paraview, since something along the lines of the following does not work (upon having computed vorticity_field already).

def compute_vorticity_field(v):
    """Compute vorticity field from P2 velocity field."""
    curl = v[1].dx(0) - v[0].dx(1)
    W = fem.functionspace(v.function_space.mesh, ("DG", 1))
    curl_expr = fem.Expression(curl, W.element.interpolation_points())
    w = fem.Function(W)
    w.interpolate(curl_expr)
    return w
file = io.XDMFFile(
   MPI.COMM_WORLD,
   "modes.xdmf",
   "w",
)
file.write_mesh(mesh)
file.write_checkpoint(vorticity_field, "mean snapshot vorticity", 0)

I read on various posts that file.write_function() will not work with DG functions and one should use write_checkpoint, but I couldn’t find the correct way to do it.

Does this post help?

(post deleted by author)