All,

I need a couple homebrew versions of Pt-to-Cell Data because:

1.       I don't want all pts variables done - just 1 at a time

2.       I need special handling for angles that go from -180 to +180 (when 1 
end of element has angle of -178 and other end has angle of 180,  a straight 
average will give an element angle of 1, when the correct answer is -179)

I have attached the kludge versions which I am using.   They are terribly slow. 
  The Pt-to-Cell data filter is much faster processing the entire set of 
variables than these are to process a single one.   Is there any VTK routines I 
can tap to make these faster?

If I'm doing something stupid which is making them slow, please feel free to 
correct me.

Thanks for looking

Dennis
#
#
def AveragePointToCellData(block,point_variable):
   #
   # Simple averaging of value at all nodes in element
   # like a simple PointDataToCellData filter
   numCells = block.GetNumberOfCells()
   elem_variable=zeros( (numCells,1) )
   #
   for element in range (numCells):
      # Initialize element variables
      elem_variable[element]=0.0
      cell=block.GetCell(element)
      numElemPts=cell.GetNumberOfPoints()
      # loop over pts and accumulate - divide by numPts for average
      for pt in range(numElemPts):
          pointID=cell.GetPointId(pt)
          #print pointID
          elem_variable[element]=elem_variable[element]+point_variable[pointID]
      elem_variable[element]=elem_variable[element]/numElemPts
      #print elem_variable[element]
   return elem_variable

#
def calc_element_angles(block):
   #
   # Must be done separately because of unique angle averaging problem at 
180degrees
   # If average angles of 180 and -178, will get angle of 1 and we desire -179
   #
   # check if angles already exist
   if check_elem_variable_exists(block,'Sector_Angle_undef'):
      el_angles=block.CellData['Sector_Angle_undef']
      return el_angles
   #
   # Didn't find angles so: 
   # Get Node angles and average at each cell 
   # Undeformed Sector Angles (degrees about Y-axis, 0=FP)
   node_angles=calc_node_angles(block)
   #   
   #All nodes now have angles -  average and assign to elements
   # declare new variable arrays
   numCells = block.GetNumberOfCells()
   el_angles=zeros( (numCells,1) )
   #
   for element in range (numCells):
      cell=block.GetCell(element)
      numElemPts=cell.GetNumberOfPoints()
      # flags to detect border sectors with both positive and negative angles
      sector_angle_pos=0
      sector_angle_neg=0
      # Initialize element variables
      el_angles[element]=0.0
      # loop over pts and accumulate - divide by numPts for average
      for pt in range(numElemPts):
          pointID=cell.GetPointId(pt)
          #print pointID
          el_angles[element]=el_angles[element]+node_angles[pointID]
          if node_angles[pointID]>=0:
             sector_angle_pos=1
          else:
             sector_angle_neg=1
          #print el_angles[element]
      # detect "boundary" sectors with + and - angles and treat specially
      # sector between 180 and -178 deg would get +1deg from averaging
      # boundary sectors are always negative
      if (sector_angle_pos and sector_angle_neg):
         el_angles[element]=0.0
         for pt in range(numElemPts):
            pointID=cell.GetPointId(pt)
            el_angles[element]=el_angles[element]-abs(node_angles[pointID])
      el_angles[element]=el_angles[element]/numElemPts
      #print el_angles[element]
   return el_angles
_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=ParaView

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

Reply via email to