Create tensor from vectors

Dear paraview staffs
I am recently doing visualization of the anisotropy of the local conductivity on an FEM output (in exodus), in which the conductivity is separately saved as three vector fields k_x, k_y and k_z. As suggested by the wiki, I am using the following lines in the program filter

from paraview.vtk.numpy_interface import dataset_adapter as dsa
import numpy

def make_tensor(xx,yy,zz, xy, yz, xz):
	t = numpy.vstack([xx,yy,zz,xy, yz, xz]).transpose().view(dsa.VTKArray)
	t.DataSet = xx.DataSet
	t.Association = xx.Association
	return t

xx = inputs[0].PointData["k_x"][:,0]
yy = inputs[0].PointData["k_y"][:,1]
zz = inputs[0].PointData["k_z"][:,2]
xy = inputs[0].PointData["k_x"][:,1]
yz = inputs[0].PointData["k_y"][:,2]
xz = inputs[0].PointData["k_z"][:,0]

output.PointData.append(make_tensor(xx,yy,zz,xy,yz,xz), "tensor")

yet paraview keeps returning the error “TypeError: Could not find a suitable VTK type for object”.

Btw, I also tried to separate the components of the conductivity as scalar fields k_11, k_22, k_33, k_12, k_23, k_13, and use the original code provided by the wiki, still obtained the same error msg.

Could someone please explain how to fix the error? Thank you in advance
Best
Yang

I am not so sure, but the following code works

from paraview.vtk.numpy_interface import dataset_adapter as dsa
import numpy

def make_tensor(xx,yy,zz,xy,yz,xz):
 t = numpy.vstack([xx.Arrays[0],yy.Arrays[0],zz.Arrays[0],xy.Arrays[0],yz.Arrays[0],xz.Arrays[0]]).transpose().view(dsa.VTKArray)
 t.DataSet = xx.DataSet
 t.Association = xx.Association
 return t

xx = inputs[0].PointData["k_x"][:,0]
yy = inputs[0].PointData["k_y"][:,1]
zz = inputs[0].PointData["k_z"][:,2]
xy = inputs[0].PointData["k_x"][:,1]
yz = inputs[0].PointData["k_y"][:,2]
xz = inputs[0].PointData["k_z"][:,0]

output.PointData.append(make_tensor(xx,yy,zz,xy,yz,xz), "tensor")

which creates a new PointData ‘tensor’ with components as XX, YY, ZZ, XY, YZ, XZ . TensorGlyph filter is also activated then.
I would then continue trying with the TensorGlyph and would be back to this question. Please point out if there is any possible mistakes.

Best
Yang

1 Like