Search code examples
paraview

Calculating transpose of a tensor in Paraview


I am required to calculate the following in Paraview:

enter image description here

How can I calculate the transpose used in the above formula ? Basically I would like to know how to calculate the transpose of a matrix in Paraview.


Solution

  • As suggested by @Nico Vuaille, you should make use of Numpy support in ParaView. Simply apply a Programmable Filter to the dataset of interest, and supply a script comparable to the following.

    import numpy as np
    u = inputs[0].PointData['Velocity']
    # Calculate gradient here, say uGrad
    output.PointData.append(uGrad, 'Gradient')
    

    EDIT: I have actually tried to generate your calculation with one of my datasets and realised that my answer and comments are not so helpful. Therefore, this is what I would suggest now, which should work:

    • Load your dataset in ParaView
    • Apply a Gradient / Gradient Of Unstructured Dataset filter on your dataset and select the velocity field as the input field (I used Gradient Of Unstructured Dataset, from which you have the possibility to also directly work out both divergence and vorticity fields).
    • Apply a Programmable Filter filter to the resulting dataset you obtained from the previous step and supply the code below.

    Script

    import numpy as np
    grad = inputs[0].PointData['Gradients']
    omega = (grad - np.transpose(grad, axes=(0, 2, 1))) / 2
    output.PointData.append(omega, 'Omega')
    

    You should end up with another item in your ParaView pipeline that only contains the expected Omega.

    EDIT 2: The input file is using the XMDF format. When loaded into ParaView, it is interpreted as a Multi-Block Dataset of Blocks. As a result, the code snippet provided to the Script argument of Programmable Filter has to be updated to:

    import paraview.vtk.numpy_interface.dataset_adapter as dsa
    for i in range(inputs[0].GetNumberOfBlocks()):
        data = dsa.WrapDataObject(inputs[0].GetBlock(i))
        grad = data.PointData['Gradients']
        omega = (grad - np.transpose(grad, axes=(0, 2, 1))) / 2
        data.PointData.append(omega, 'Omega')
        output.SetBlock(i, data.VTKObject)