Example #1
0
 def get_neighbors(self,indices):
     (N,) = indices.shape
     D = self.dim
     shift = self.cell_shift()
     
     neighbors = col_vect(indices) + row_vect(shift)
     assert((N,2**D) == neighbors.shape)
     return neighbors
Example #2
0
    def cell_coords_to_vertex_indices(self,cell_coords):
        assert isinstance(cell_coords,Coordinates)
        (N,D) = cell_coords.shape
        assert self.dim == D


        """
        The low node index in the cell has the same coords in node-land
        as the cell in cell-land:
         |   |
        -o - o-
         | x |
        -x - o-
         |   |
        """        
        low_vertex = self.node_indexer.coords_to_indices(cell_coords)

        # Array of index offsets to reach every vertex in cell
        shift = self.node_indexer.cell_shift()
        assert (2**D,) == shift.shape
        
        vertices = col_vect(low_vertex) + row_vect(shift)
        assert (N,2**D) == vertices.shape

        """
        Handle out of bound nodes. There is a constant offset for 
        converting cell oob indices to node oob indices.
        Also the difference between max spatial indices.
        """
        oob = cell_coords.oob
        if oob.has_oob():
            # Figure out the right oob node
            oob_indices = cell_coords.oob.indices[oob.mask]
            offset = self.node_indexer.get_num_spatial_nodes()
            vertices[oob.mask,0] = oob_indices + offset
            vertices[oob.mask,1:] = np.nan

        return vertices