# Writing XDMF file leads to inf & nan values

**URL:** <https://fenicsproject.discourse.group/t/writing-xdmf-file-leads-to-inf-nan-values/13830>\
**Category:** dolfinx\
**Created:** [March 5, 2024, 10:35pm UTC](https://fenicsproject.discourse.group/t/writing-xdmf-file-leads-to-inf-nan-values/13830 "2024-03-05T22:35:48Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Jesus\_Vellojin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/jesus_vellojin/32/6485_2.png) [@Jesus\_Vellojin](https://fenicsproject.discourse.group/u/Jesus_Vellojin)\
**Post date:** [March 6, 2024, 3:25pm UTC](https://fenicsproject.discourse.group/t/writing-xdmf-file-leads-to-inf-nan-values/13830/4 "2024-03-06T15:25:23Z")

</div>

As stated [here](https://fenicsproject.discourse.group/t/meaning-of-collapse/10641/2) by @dokken for function spaces,`sub(i)` and `collapse()` gives you a function space over the ith element of the mixed element, which can be seen in your case as the “mixed element” between CG1 spaces (one per component). For an already defined `fem.Function`, you could do the same (see this [link](https://github.com/FEniCS/dolfinx/blob/989a3edcb28790cc5486535382c619e5770d392c/python/dolfinx/fem/function.py#L560)) to access its components if available. By using `uh.x.array[1::3]` you have to be aware of the dof ordering on FEniCS.

Regarding your second question, since you now have `uh`, you could obtain the stress by using an interpolation into a DG0 space. I would do the following

```auto
Tensorplot_space = fem.FunctionSpace(
mesh_domain, ("DG", 0, (3, 3)))
sig_h = fem.Function(Tensorplot_space)
sig = fem.Expression(ufl.as_ufl(sigma(uh)),
                 Tensorplot_space.element.interpolation_points())
sig_h.interpolate(sig)
sig_h.name = "$\sigma$"

write_file.write_function(sig_h, step)

```

Maybe there is a better (faster) way of doing that.

Cheers.

---

_[View the full topic](https://fenicsproject.discourse.group/t/writing-xdmf-file-leads-to-inf-nan-values/13830)._
