[Paraview] Help with Programmable Filter

Dennis Conklin dennis_conklin at goodyear.com
Wed Aug 13 10:45:13 EDT 2014


​Casey,


I am trying to get back to this among all the other firedrills.


Yes, I am using Copy Arrays


I also tried a simple filter where I just assigned values and that worked as well.


It seems the area that isn't working is:


   for i in range(block.GetNumberOfElements()):
      sigma = numpy.array([ [xx[i],xy[i],xz[i]],
                            [xy[i],yy[i],yz[i]],
                            [xz[i],yz[i],zz[i]]
                         ])

      # isotropic strain matrix
      iso = 1.0/3.0*numpy.trace(sigma)*numpy.eye(3)
      # deviatoric strain matrix
      dev = sigma - iso

      #principal strains
      eigvals = list(numpy.linalg.eigvalsh(sigma))
      eigvals.sort()
      eigvals.reverse()
      P1[i] = eigvals[0]
      P2[i] = eigvals[1]
      P3[i] = eigvals[2]
      # max shear
      max_shear[i] = (max(eigvals)-min(eigvals))/2.0



I wasn't sure if I had to convert to numpy arrays for this to work so I tried

   xx = vtkDataArrayToVTKArray(block.CellData['USTRTOTXX'])
...

to get numpy arrays to use in sigma, but that doesn't work either.

P1,P2 and P3 are not declared anywhere before they are first used - could that be the problem?
​
Also, how do I get debug prints to show up somewhere - I'm not getting any error messages in the console or the Output Window.

thanks

Dennis Conklin, PE
RDE&Q Principal Engineer
Goodyear Innovation Center, 5th Floor South, Pillar M34
Phone:  330-796-5701
Email:  dennis_conklin at goodyear.com
________________________________
From: Casey Goodlett <casey.goodlett at kitware.com>
Sent: Tuesday, August 12, 2014 5:26 PM
To: Dennis Conklin
Cc: paraview at paraview.org
Subject: Re: [Paraview] Help with Programmable Filter

Hi Dennis,

I took a look at the filter to see what might be wrong, but I seem to be missing a couple of things:

1) Are you using the "Copy Arrays" option of the programmable filter? Otherwise you will need to reference the input data as well.

2) Where are the P1,P2,P3, etc vectors created?  What type are they?

The below script worked for me if Copy Arrays is enabled.  I used the can.ex2 example dataset from paraview and ensured the "Object Ids" cell data was selected in the reader.


for oblock in output:

   oid = oblock.CellData['ObjectId']

   o2 = oid + 10

   oblock.CellData.append(o2, 'newdata')

Hope that helps


On Mon, Aug 4, 2014 at 3:21 PM, Dennis Conklin <dennis_conklin at goodyear.com<mailto:dennis_conklin at goodyear.com>> wrote:

I have the following script for a Paraview Programmable filter:


import math
import numpy

#
#  Gdyr_Principal_Strains_ProgFilter
#    Rev 0
#    Aug 1, 2014
#  Dennis Conklin - Engineering Mechanics
#
#  Paraview 4.0.1 Progammable Filter
#  Adds Cell Variables:
#      Principal Strains:  str_P1, str_P2, str_P3
#      max shear strain:   tau_max
#  These can be used for coloring, Spreadsheet view, formulas, threshold, etc
#
def process_block(block):
   #
   # Global coordinate strains
   # Assume strains loaded in Paraview
   xx = block.CellData['USTRTOTXX']
   yy = block.CellData['USTRTOTYY']
   zz = block.CellData['USTRTOTZZ']
   xy = block.CellData['USTRTOTXY']
   xz = block.CellData['USTRTOTZX']
   yz = block.CellData['USTRTOTYZ']

   for i in range(block.GetNumberOfCells()
      sigma = numpy.array([ [xx[i],xy[i],xz[i]],
                            [xy[i],yy[i],yz[i]],
                            [xz[i],yz[i],zz[i]]
                         ])

      # isotropic strain matrix
      iso = 1.0/3.0*numpy.trace(sigma)*numpy.eye(3)
      # deviatoric strain matrix
      dev = sigma - iso

      #principal strains
      eigvals = list(numpy.linalg.eigvalsh(sigma))
      eigvals.sort()
      eigvals.reverse()
      P1[i] = eigvals[0]
      P2[i] = eigvals[1]
      P3[i] = eigvals[2]
      # max shear
      max_shear[i] = (max(eigvals)-min(eigvals))/2.0

   block.CellData.append(P1,"P1_strain")
   block.CellData.append(P2,"P2_strain")
   block.CellData.append(P3,"P3_strain")
   block.CellData.append(max_shear,"tauMax")


# Loop over blocks in composite (Exodus) data set
for block in output:
   # process each block
   process_block(block)

After running this script, no errors or warnings are issued but the additional quantites (taumax, Px_strain) are not present as element quantities.

Any hints as to what I'm doing wrong.


Dennis Conklin, PE
RDE&Q Senior Engineer
Goodyear Innovation Center, 5th Floor South, Pillar M34
Phone:  330-796-5701<tel:330-796-5701>
Email:  dennis_conklin at goodyear.com<mailto:dennis_conklin at goodyear.com>

_______________________________________________
Powered by www.kitware.com<http://www.kitware.com>

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview




--
Casey B. Goodlett, Ph.D.
Technical Leader
Kitware, Inc. - North Carolina Office
http://www.kitware.com
(919) 969-6990 x310
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20140813/08efdc51/attachment.html>


More information about the ParaView mailing list