# Issues with Tensor6/Tensor in XDMF

**URL:** https://discourse.paraview.org/t/issues-with-tensor6-tensor-in-xdmf/14534
**Category:** ParaView Support
**Created:** [May 1, 2024, 9:03am UTC](https://discourse.paraview.org/t/issues-with-tensor6-tensor-in-xdmf/14534 "2024-05-01T09:03:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![reox](https://discourse.paraview.org/user_avatar/discourse.paraview.org/reox/32/16237_2.png) [@reox](https://discourse.paraview.org/u/reox)
#### Post date: [May 1, 2024, 9:03am UTC](https://discourse.paraview.org/t/issues-with-tensor6-tensor-in-xdmf/14534/1 "2024-05-01T09:03:18Z")

</div>

I get stress and strain tensors from a finite element solver in a h5 file and would like to visualize them in paraview.

I found out by reading some source code and trial and error, that the ordering of tensor6 in XDMF is `11 12 13 22 23 33` - contrary to VTK files were the order is `11 22 33 12 23 13`.

Here are two files that show that for both tensor types (full tensor and tensor6):  
[tensor.vtk](https://discourse.paraview.org/uploads/short-url/w2bXTBLAQkf8X7ZQqZNLI0kmCfj.vtk) (222 Bytes)  
[tensor.xdmf2](https://discourse.paraview.org/uploads/short-url/6ewBMKk2i87c9EVsFq9jpTzTx7m.xdmf2) (1.1 KB)

I think this discrepancy comes from here: [VTK/IO/Xdmf2/vtkXdmfHeavyData.cxx at 9822c2ff75ca5dbd8a6465b071cf7c2481b9c753 · Kitware/VTK · GitHub](https://github.com/Kitware/VTK/blob/9822c2ff75ca5dbd8a6465b071cf7c2481b9c753/IO/Xdmf2/vtkXdmfHeavyData.cxx#L1141)  
For the XDMF data, the tensor is converted to a 9 component tensor (I can verify that in Paraview, as the VTK file shows the 6 component tensor with only 6 components, but in the XDMF file both are 9-component tensors).  
Is that intentional that the ordering is different?

However, the FE solver prints out the components of the stress and strain tensor as `11 22 33 12 23 13`, thus I would need to reorder the components. Furthermore, the strains are given in engineering notation, thus to get to the true strain tensor, I would need to divide the shear components by 2.

I played around with HyperSlabs and Functions ([XDMF Model and Format - XdmfWeb](https://www.xdmf.org/index.php/XDMF_Model_and_Format#XdmfItem)) and got it working, however, I found some quirks with the XDMF reader and I’m not fully happy with the solution.

What is working is the following:

```auto
<Attribute Name="StrainTensor" AttributeType="Tensor6" Center="Cell">
	<DataItem ItemType="Function" Function="JOIN($0, $3, $5, $1, $4, $2)" Dimensions="125000 6">
		<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
			<DataItem Dimensions="3 2" Format="XML">0 0 1 1 125000 1</DataItem>
			<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
		</DataItem>
		<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
			<DataItem Dimensions="3 2" Format="XML">0 1 1 1 125000 1</DataItem>
			<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
		</DataItem>
		<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
			<DataItem Dimensions="3 2" Format="XML">0 2 1 1 125000 1</DataItem>
			<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
		</DataItem>
		<DataItem ItemType="Function" Function="$0 * 0.5" Dimensions="125000 1">
			<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
				<DataItem Dimensions="3 2" Format="XML">0 3 1 1 125000 1</DataItem>
				<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
			</DataItem>
		</DataItem>
		<DataItem ItemType="Function" Function="$0 * 0.5" Dimensions="125000 1">
			<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
				<DataItem Dimensions="3 2" Format="XML">0 4 1 1 125000 1</DataItem>
				<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
			</DataItem>
		</DataItem>
		<DataItem ItemType="Function" Function="$0 * 0.5" Dimensions="125000 1">
			<DataItem ItemType="HyperSlab" Dimensions="125000 1" Type="HyperSlab">
				<DataItem Dimensions="3 2" Format="XML">0 5 1 1 125000 1</DataItem>
				<DataItem Dimensions="125000 6" NumberType="Float" Precision="4" Format="HDF">result.h5:/Strain</DataItem>
			</DataItem>
		</DataItem>
	</DataItem>
</Attribute>

```

Basically, I need to create Scalar values using HyperSlabs, which are then joined with a function. For each shear strain, I divide by two with a function. I also tried to do this all in the join like this:

```auto
  <DataItem ItemType="Function" Function="JOIN($0, $3 / 2, $5 / 2, $1, $4 / 2, $2)" Dimensions="125000 6">

```

However, this does not work, as it seems the divisions are stacked for each element - thus $0 is divided by 2, $3 is divided by 4, $5 is divided by 8 and so on… Is this a bug or a feature?

Then I wanted to use references instead of specifying the DataItems several times, but is that possible to search for a named item in a current Grid?  
My problem is, I have several steps in the XDMF, for each a new Grid is defined. Can I lookup with the reference the DataItem with a certain name in the current Grid?

Another question would be if there is a more simple way to do this permutation of the components?

---

<div class="post-metadata">

### Author: ![philbucher](https://discourse.paraview.org/user_avatar/discourse.paraview.org/philbucher/32/16891_2.png) [@philbucher](https://discourse.paraview.org/u/philbucher)
#### Post date: [August 17, 2025, 12:17pm UTC](https://discourse.paraview.org/t/issues-with-tensor6-tensor-in-xdmf/14534/2 "2025-08-17T12:17:24Z")

</div>

Hi,  
I found this issue while trying to get tensor6 to work myself.  
I figured out that by using matrix with size 6 it shows it with only 6 components in tensor notation

Here is an example with different types:  
[types.xdmf2](https://discourse.paraview.org/uploads/short-url/bwCnLVE1REsT2MDwK1w9GVJVqEM.xdmf2) (31.7 KB)

Hope it helps
