Calculating heat flux density in FEniCSx

I have reviewed the relevant posts and summarized the following code. Could someone please help verify the correctness of my code? Thank you very much!

    # heat flux
    Q = functionspace(mesh, ("DG", 0, (mesh.geometry.dim,)))
    q = Function(Q)
    q_expr = Expression(materials.kappa_m * grad(Tm), Q.element.interpolation_points())
    q.interpolate(q_expr)
    vtkFile = io.VTKFile(MPI.COMM_WORLD, "results/flux/q_m.pvd", "w")
    vtkFile.write_function(q)
    vtkFile.close()

This looks reasonable, but we can’t really give more guidance given we don’t know exactly what you want and the full context of a minimal working example. E.g., we’re assuming here that

materials.kappa_m * grad(Tm)

lives in a DG0 space, and that you’re happy with the approximation offered by the degree 0 space.

Thank you for your confirmation. This result is sufficient.