# Calculating heat flux density in FEniCSx

**URL:** <https://fenicsproject.discourse.group/t/calculating-heat-flux-density-in-fenicsx/17094>\
**Category:** dolfinx\
**Created:** [February 27, 2025, 10:22am UTC](https://fenicsproject.discourse.group/t/calculating-heat-flux-density-in-fenicsx/17094 "2025-02-27T10:22:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![French\_fries](https://avatars.discourse-cdn.com/v4/letter/f/71c47a/32.png) [@French\_fries](https://fenicsproject.discourse.group/u/French_fries)\
**Post date:** [February 27, 2025, 10:22am UTC](https://fenicsproject.discourse.group/t/calculating-heat-flux-density-in-fenicsx/17094/1 "2025-02-27T10:22:01Z")

</div>

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!

```auto
    # 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()

```

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [February 27, 2025, 9:15pm UTC](https://fenicsproject.discourse.group/t/calculating-heat-flux-density-in-fenicsx/17094/2 "2025-02-27T21:15:49Z")

</div>

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

```python
materials.kappa_m * grad(Tm)

```

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

---

<div class="post-metadata">

**Author:** ![French\_fries](https://avatars.discourse-cdn.com/v4/letter/f/71c47a/32.png) [@French\_fries](https://fenicsproject.discourse.group/u/French_fries)\
**Post date:** [February 28, 2025, 1:26am UTC](https://fenicsproject.discourse.group/t/calculating-heat-flux-density-in-fenicsx/17094/3 "2025-02-28T01:26:23Z")

</div>

Thank you for your confirmation. This result is sufficient.
