# TensorPrincipalInvariants filter

**URL:** https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830
**Category:** ParaView Support
**Created:** [December 4, 2024, 1:40am UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830 "2024-12-04T01:40:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Renato\_E\_Poli](https://discourse.paraview.org/user_avatar/discourse.paraview.org/renato_e_poli/32/14656_2.png) [@Renato\_E\_Poli](https://discourse.paraview.org/u/Renato_E_Poli)
#### Post date: [December 4, 2024, 1:40am UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830/1 "2024-12-04T01:40:52Z")

</div>

Hi

I am wondering if the expected behavior of the TensorPrincipalInvariants filter is to calculate the eigenvectors as sigma1(vector), sigma2(vector) and sigma3(vector).

If so, I am not able to match the results in my dataset.

These are the tensor definition (I assume in the order XX-YY-ZZ-XY-YZ-XZ)  
 ![{E993F715-2486-47BA-90C8-41DC89F7F77F}](https://discourse.paraview.org/uploads/default/original/2X/d/dea9c169ab9a81732324f373c5e869d4bca814ed.png)

And these is calculated sigma1 (vector):  
 ![{E7BEFB08-FE28-4F7F-9ABD-473AB459E6EF}](https://discourse.paraview.org/uploads/default/original/2X/a/adecb140656d332d73ffa60dd54ca9d8496ec162.png)

I could not match these values by manual calculation.

Would the plugin by any chance read the tensor in another order?

One more information: it seems that the sign of the sigma’s “Y” variable is inverted in this case… this means that the eigenvalues are ok, but the eigenvectors _sometimes_ go to the wrong quadrant.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 5, 2024, 2:03pm UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830/2 "2024-12-05T14:03:35Z")

</div>

> [@Renato\_E\_Poli](#):
>
> TensorPrincipalInvariants

Here is how the data is recovered in the filter:

```auto
      tensor[0][0] = array->GetComponent(idx, 0); 
      tensor[1][1] = array->GetComponent(idx, 1); 
      tensor[2][2] = array->GetComponent(idx, 2); 
      tensor[0][1] = array->GetComponent(idx, 3); 
      tensor[1][0] = array->GetComponent(idx, 3); 
      tensor[1][2] = array->GetComponent(idx, 4); 
      tensor[2][1] = array->GetComponent(idx, 4); 
      tensor[0][2] = array->GetComponent(idx, 5); 
      tensor[2][0] = array->GetComponent(idx, 5); 

```

Hence the order is:

XX YY ZZ XY YZ XZ

So looks like your expectation is correct, I do not know why you have different results.

---

<div class="post-metadata">

### Author: ![Renato\_E\_Poli](https://discourse.paraview.org/user_avatar/discourse.paraview.org/renato_e_poli/32/14656_2.png) [@Renato\_E\_Poli](https://discourse.paraview.org/u/Renato_E_Poli)
#### Post date: [December 5, 2024, 5:59pm UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830/3 "2024-12-05T17:59:22Z")

</div>

If I understood everything correctly, these are the eigenvectors and eigenvalues.  
So, this must be valid:

TENSOR \* \sigma\_1(vec) = \sigma\_1(lambda) \* \sigma\_1 (vec)

I cannot get this equality withe the values calculated by the filter.  
Look at the first eigenvector our of the ultra-simple python code below (the y component should be negative):

```auto
TENSOR:
[[1.36070e+04 -3.97784e+04 -2.82264e+01]
 [-3.97784e+04 -4.70215e+03 5.65523e+01]
 [-2.82264e+01 5.65523e+01 1.70698e+03]]
EVAL:
 [45270.72363685 -36365.81693694 1706.92330009]
EVEC:
 [[7.82391753e-01 -6.22784873e-01 1.46537903e-03] <== here
 [-6.22785208e-01 -7.82392812e-01 -2.71208641e-04]
 [-1.31540666e-03 7.00424981e-04 9.99998890e-01]]

```

Python:

```auto
import numpy as np

mxx = 13607
myy = -4702.15
mzz = 1706.98
mxy = -39778.4
myz = 56.5523
mxz = -28.2264
M = np.array( [[mxx, mxy, mxz], [mxy, myy, myz] , [mxz, myz, mzz]] )
print(f"TENSOR:\n{M}")
eval, evec = np.linalg.eig(M)
print( f"EVAL:\n {eval}" );
print ( f"EVEC:\n {evec}" )

```

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [December 6, 2024, 9:00am UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830/4 "2024-12-06T09:00:43Z")

</div>

I’m afraid investigation into the filter is needed to figure this out.

---

<div class="post-metadata">

### Author: ![Renato\_E\_Poli](https://discourse.paraview.org/user_avatar/discourse.paraview.org/renato_e_poli/32/14656_2.png) [@Renato\_E\_Poli](https://discourse.paraview.org/u/Renato_E_Poli)
#### Post date: [February 28, 2025, 10:32pm UTC](https://discourse.paraview.org/t/tensorprincipalinvariants-filter/15830/5 "2025-02-28T22:32:06Z")

</div>

Hi Mathieu,

I ran into a similar issue now using the legacy EXO reader:  
The YZ and XZ components of the tensors are showing swapped.

I could not track down the full code, but I can see this swap in the following comment (vs. the definition in Exo reader).  
Does that make sense?

[https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/Exodus/vtkExodusIIReaderPrivate.h:401](https://gitlab.kitware.com/vtk/vtk/-/blob/master/IO/Exodus/vtkExodusIIReaderPrivate.h:401)

> SymmetricTensor = 3, //!\< The array is a symmetric tensor

> // (order xx, yy, zz, xy, yz, zx) \<\<= HERE

vs.

[https://gitlab.kitware.com/vtk/vtk/blob/master/IO/Exodus/vtkExodusIIReader.cxx:363](https://gitlab.kitware.com/vtk/vtk/blob/master/IO/Exodus/vtkExodusIIReader.cxx:363)  
`const char endST23[] = "XXYYZZXY|XZ|YZ|";` // \<\<= here

Thank you,  
Renato
