PrincipleStrainPython: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(Created page with "<table> <tr> <td valign="top"> <source lang="python"> # ParaView Programmable Filter script. ParaView 5.0.1. # # This code will read in an eigenvector, calculate an # eig...") |
No edit summary |
||
Line 130: | Line 130: | ||
#print "\n" | #print "\n" | ||
</source> | </source> | ||
</td> | </td> | ||
</tr> | </tr> | ||
</table> | </table> |
Revision as of 23:48, 28 July 2016
<source lang="python">
import numpy as np def process_composite_dataset(input0): # Pick up input arrays xxar = input0.CellData["EPSXX"] xyar = input0.CellData["EPSXY"] zxar = input0.CellData["EPSZX"] yyar = input0.CellData["EPSYY"] yzar = input0.CellData["EPSYZ"] zzar = input0.CellData["EPSZZ"] #print `xxar` #print len(xxar.Arrays) # Set output arrays to same type as input array. # Do a multiply to make sure we don't just have a # pointer to the original. outarray0 = xxar*0.5 outarray1 = xxar*0.5 outarray2 = xxar*0.5
# Run a for loop over all blocks numsubarrays = len(xxar.Arrays) for ii in range(0, numsubarrays): # pick up input arrays for each block. xxarsub = xxar.Arrays[ii] xyarsub = xyar.Arrays[ii] zxarsub = zxar.Arrays[ii] yyarsub = yyar.Arrays[ii] yzarsub = yzar.Arrays[ii] zzarsub = zzar.Arrays[ii] #print `xxarsub` # Transpose and calculate the principle strain. strain = np.transpose( np.array( [ [xxarsub, xyarsub, zxarsub], [xyarsub, yyarsub, yzarsub], [zxarsub, yzarsub, zzarsub] ] ), (2,0,1)) principal_strain = np.linalg.eigvalsh(strain) # Move principle strain to temp output arrays for this block outarray0.Arrays[ii] = principal_strain[:,0] outarray1.Arrays[ii] = principal_strain[:,1] outarray2.Arrays[ii] = principal_strain[:,2] #ps0 = principal_strain[:,0] #print "ps0 len: " + str(len(ps0)) # Finally, move the temp arrays to output arrays output.CellData.append(outarray0, "principal_strain_0") output.CellData.append(outarray1, "principal_strain_1") output.CellData.append(outarray2, "principal_strain_2")
# Pick up input arrays xxar = input0.CellData["EPSXX"] xyar = input0.CellData["EPSXY"] zxar = input0.CellData["EPSZX"] yyar = input0.CellData["EPSYY"] yzar = input0.CellData["EPSYZ"] zzar = input0.CellData["EPSZZ"] #print `xxar` #print len(xxar.Arrays) # Transpose and calculate the principle strain. strain = np.transpose( np.array( [ [xxar, xyar, zxar], [xyar, yyar, yzar], [zxar, yzar, zzar] ] ), (2,0,1)) principal_strain = np.linalg.eigvalsh(strain)
#ps0 = principal_strain[:,0] #print "ps0 len: " + str(len(ps0)) # Finally, move the temp arrays to output arrays output.CellData.append(principal_strain[:,0], "principal_strain_0") output.CellData.append(principal_strain[:,1], "principal_strain_1") output.CellData.append(principal_strain[:,2], "principal_strain_2")
input0 = inputs[0] if input0.IsA("vtkCompositeDataSet"): process_composite_dataset(input0) elif input0.IsA("vtkUnstructuredGrid"): process_unstructured_dataset(input0) else: print "Bad dataset type for this script"
</source> |