Issues with Tensor6/Tensor in XDMF

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 (222 Bytes)
tensor.xdmf2 (1.1 KB)

I think this discrepancy comes from here: VTK/IO/Xdmf2/vtkXdmfHeavyData.cxx at 9822c2ff75ca5dbd8a6465b071cf7c2481b9c753 · Kitware/VTK · GitHub
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) 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:

<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:

  <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?