How to generate a new field from other fields without calculator

Dear support,

I am trying to estimate the principal stress from stress and shear stress components using matrix resolution.

This type of resolution cannot be used in a calculator ad thus I wanted to do it using pvbatch:

  1. loop over all cells
  2. Solve the matrix for each cell
  3. Add the result to a new field
  4. Visualise the new field over the whole domain

Could anyone help me, especially regarding the creation of a new field (cell based) and the filling of said field?

Thank you

PS: long live Paraview

You want to do that using a programmable filter :slight_smile:

Hello Mathieu,

Thanks for the quick feedback, it’s a nice feature that I didn’t know about.

So I gave it a try and I can recover the data I want using the examples.

The only issue I have then is using VTKArray with numpy, due to the format of the data:

How can I convert it to numpy array? I tried np.array on the VTKArray but it failed.

Thank you

Below the script I tried to use

##############################################
Code for ‘Script’

import numpy as np

input0 = inputs\[0\]

#Recover data

sigma_x =  np.array(input0.CellData\[“sigma_xx”\])
sigma_y =  np.array(input0.CellData\[“sigma_yy”\])
sigma_z =  np.array(input0.CellData\[“sigma_zz”\])
tau_xy =  np.array(input0.CellData\[“sigma_xy”\])
tau_yz =  np.array(input0.CellData\[“sigma_yz”\])
tau_xz = np.array(input0.CellData\[“sigma_xz”\])

#Build the tensor

sigma_tensor = np.array(\[
\[sigma_x, tau_xy, tau_xz\],
\[tau_xy, sigma_y, tau_yz\],
\[tau_xz, tau_yz, sigma_z\]
\])

#Solve the coefficients

I1 = np.trace(sigma_tensor)
I2 = (sigma_x  *sigma_y + sigma_y  sigma_z + sigma_z  sigma_x
- tau_xy\*\****2 - tau_yz**\*\*2 - tau_xz\*\*2)
I3 = np.linalg.det(sigma_tensor)

Note that the Yield Criteria filter could compute the principal stress (but not shear stress):

However there is some assumption regarding the tensor itself, see : Pb with YieldCriteria Filter

1 Like