-1

I have a cell data F that is an array of 3x3 matrices. How can I calculate the sqrt(eigenvalues of F*F.T matrices) and afterwards append this new cell data?

Update 1: This is my code. It does not work because of the line

C = F.Arrays[0] * F.Arrays[0].T

How can I solve solve it?

import numpy as np
import vtk
from vtk.numpy_interface import dataset_adapter as da
from paraview.numpy_support import vtk_to_numpy
from paraview.vtk.numpy_interface import algorithms
from paraview.vtk.numpy_interface.algorithms import sqrt as sqrt
from paraview.vtk.numpy_interface.algorithms import eigenvalue as eigenvalue

# This is a VTKCompositeDataArray
F = inputs[0].GetCellData().GetArray('F')

# Of course it does not work! Error:
#   ValueError: operands could not be broadcast together 
#   with shapes (60,3,3) #(3,3,60)
# How to solve it?
C = F.Arrays[0] * F.Arrays[0].T
Eigs = sqrt(eigenvalue(C))
output.CellData.append(Eigs, "EigenValues")
Caslu
  • 183
  • 1
  • 1
  • 8
  • Take a look at this question : https://stackoverflow.com/questions/46132843/how-to-use-numpy-in-the-programmable-filter-in-paraview That should allow you to transform your data in numpy array and use numpy to compute any matrix operation. – Mathieu Westphal Mar 26 '18 at 06:13
  • Thank you @MathieuWestphal, but unfortunately that did not help me. I tried to convert from VTK to numpy, get the eigenvalues, then converted it back. Did not work! So, I decided to use only VTKArrays and It did not work either. – Caslu Mar 27 '18 at 13:37
  • I do not know, but vtk arrays do not support direct computation. I would suggest asking on the paraview mailing list – Mathieu Westphal Mar 28 '18 at 01:00
  • Actually they do support direct computation, but they are limited. – Caslu Mar 28 '18 at 14:12

1 Answers1

2

I have found a way:

import numpy as np
import vtk
from vtk.numpy_interface import dataset_adapter as da
from vtk.numpy_interface.algorithms import sqrt as sqrt
from vtk.numpy_interface.algorithms import eigenvalue as eigenvalue
from numpy import linalg as LA

F = inputs[0].GetBlock(0).GetCellData().GetArray('F')

arr = []
for j in range(0, F.GetNumberOfTuples()) :
    f = F.GetTuple(j)
    f = np.reshape(f, (3,3))
    f = f.T*f
    lmbda = np.sqrt(LA.eigvals(f))
    arr.append(lmbda)

vtk_arr = da.VTKArray(arr)
output.CellData.append(vtk_arr,"Lambdas")
Caslu
  • 183
  • 1
  • 1
  • 8