Neighbors and boundary conditions (grid_dendro.boundary)#
- class grid_dendro.boundary.NeighborIndex(shape, boundary_flag, corner=True)[source]#
Dictionary mapping from the cell index to the indices of its neighbors
The object acts like a pseudo-array of the shape (Ncells, N_neighbors), such that obj[k] returns the neighbor indices of the k-th cell. If k fall on the boundary, it finds the precomputed neighbor indices (nghbr_idx) from the dictionary. Otherwise, it computes the neighbor indices on-the-fly by k + displacements.
Caution: allow out-of-bound index for performance.
- Parameters
shape (array-like) – shape of the input data
boundary_flag (str, {'periodic', 'outflow'}) – Flag for boundary condition. Affects how to set neighbors of the edge cells.
corner (Boolean, default: True) – If true, the corner cells are counted as neighbors (26 neighbors in total)
Examples
pcn = pcnDict() pcn[1][0] is the flattened index of the (-1,-1,-1) neighbor of the (k,j,i) = (0,0,1) cell, which is (k,j,i) = (-1, -1, 0) = (Nz-1, Ny-1, 0) for periodic BC. See docstring of get_offsets for the ordering of neighbor directions.
- grid_dendro.boundary.get_edge_cells(cells, pcn)[source]#
Helper function to find edge cells of the given region
- Parameters
cells (array_like) – flattened indices that defines some region
pcn (array_like) – precomputed neighbors.
- Returns
edge_cells – flattened indices that defines edge cells of the given region
- Return type
array_like