parameters: (self, node_indices, new_node_indices)
docstring: Create duplicates nodes which are averaged from the given nodes.
  
          If all nodes which are being averaged are in a given node set, the
          newly created node is also added the node set.
  
          For example, 'node_indices = [(0, 1, 2)]' will create a new node which
          is the average of nodes 1, 2, and 3.  Passing
          'node_indices = [((0, 0.25), (1, 0.75))]' will create a node which is
          a weighted combination of nodes 0 and 1.
docstring_summary: Create duplicates nodes which are averaged from the given nodes.
docstring_tokens: Create duplicates nodes which are averaged from the given nodes .
function: def _create_averaged_nodes(self, node_indices, new_node_indices):
          """
          Create duplicates nodes which are averaged from the given nodes.
  
          If all nodes which are being averaged are in a given node set, the
          newly created node is also added the node set.
  
          For example, 'node_indices = [(0, 1, 2)]' will create a new node which
          is the average of nodes 1, 2, and 3.  Passing
          'node_indices = [((0, 0.25), (1, 0.75))]' will create a node which is
          a weighted combination of nodes 0 and 1.
  
          """
          first_node_index = len(self.nodes)
          new_node_indices[:] = range(len(self.nodes),
                                      len(self.nodes) + len(node_indices))
          # format node_indices such that each value is of the given form:
          # ((index, weight), (index2, weight2), ...)
          new_node_indices = []
          for index_list in node_indices:
              new_index_list = []
              if isinstance(index_list, int):
                  new_index_list = [[index_list, 1.0]]
              else:
                  length = float(len(index_list))
                  for specifier in index_list:
                      if isinstance(specifier, int):
                          new_index_list.append([specifier, 1.0 / length])
                      else:
                          new_index_list.append(specifier)
              new_node_indices.append(new_index_list)
          node_indices = new_node_indices
          # ensure weights add up to 1
          for index_list in node_indices:
              total = sum(x[1] for x in index_list)
              if abs(total - 1.0) > 1e-14:
                  self._bug('Incorrect weights.',
                            'The given node averaging weights do not add up '
                            'to 1.')
          # create the new nodes
          first_new_node_index = len(self.nodes)
          new_nodes = []
          for index_list in node_indices:
              this_new_node = [sum(weight * self.nodes[index][d]
                                   for index, weight in index_list)
                               for d in xrange(3)]
              new_nodes.append(this_new_node)
          self.create_nodes(new_nodes)
          # update self.node_fields
          for all_values in self.node_fields.values():
              for values in all_values:
                  new_values = [sum(weight * values[index]
                                    for index, weight in index_list)
                                for index_list in node_indices]
                  values[first_node_index:] = new_values
          # update self.node_sets
          for node_set_id in self.get_node_set_ids():
              members = self.get_node_set_members(node_set_id)
              fields = self._get_node_set_fields(node_set_id)
              members_set = set(members)
              index_from_member_index = dict(
                  (node_index, index)
                  for index, node_index in enumerate(members))
              for node_index, index_list in enumerate(node_indices):
                  check = set(x in members_set for x, _ in index_list)
                  if False in check:
                      continue
                  # okay, we need to add this node to the set
                  members.append(first_new_node_index + node_index)
                  # and calculate its value for all fields
                  for all_values in fields.values():
                      for values in all_values:
                          new_value = sum(
                              weight * values[index_from_member_index[index]]
                              for index, weight in index_list)
                          values.append(new_value)
function_tokens: def _create_averaged_nodes ( self , node_indices , new_node_indices ) : first_node_index = len ( self . nodes ) new_node_indices [ : ] = range ( len ( self . nodes ) , len ( self . nodes ) + len ( node_indices ) ) # format node_indices such that each value is of the given form: # ((index, weight), (index2, weight2), ...) new_node_indices = [ ] for index_list in node_indices : new_index_list = [ ] if isinstance ( index_list , int ) : new_index_list = [ [ index_list , 1.0 ] ] else : length = float ( len ( index_list ) ) for specifier in index_list : if isinstance ( specifier , int ) : new_index_list . append ( [ specifier , 1.0 / length ] ) else : new_index_list . append ( specifier ) new_node_indices . append ( new_index_list ) node_indices = new_node_indices # ensure weights add up to 1 for index_list in node_indices : total = sum ( x [ 1 ] for x in index_list ) if abs ( total - 1.0 ) > 1e-14 : self . _bug ( 'Incorrect weights.' , 'The given node averaging weights do not add up ' 'to 1.' ) # create the new nodes first_new_node_index = len ( self . nodes ) new_nodes = [ ] for index_list in node_indices : this_new_node = [ sum ( weight * self . nodes [ index ] [ d ] for index , weight in index_list ) for d in xrange ( 3 ) ] new_nodes . append ( this_new_node ) self . create_nodes ( new_nodes ) # update self.node_fields for all_values in self . node_fields . values ( ) : for values in all_values : new_values = [ sum ( weight * values [ index ] for index , weight in index_list ) for index_list in node_indices ] values [ first_node_index : ] = new_values # update self.node_sets for node_set_id in self . get_node_set_ids ( ) : members = self . get_node_set_members ( node_set_id ) fields = self . _get_node_set_fields ( node_set_id ) members_set = set ( members ) index_from_member_index = dict ( ( node_index , index ) for index , node_index in enumerate ( members ) ) for node_index , index_list in enumerate ( node_indices ) : check = set ( x in members_set for x , _ in index_list ) if False in check : continue # okay, we need to add this node to the set members . append ( first_new_node_index + node_index ) # and calculate its value for all fields for all_values in fields . values ( ) : for values in all_values : new_value = sum ( weight * values [ index_from_member_index [ index ] ] for index , weight in index_list ) values . append ( new_value )