def find_active_neighbors_for_fixed_links(grid): """Find active link neighbors for every fixed link. Specialized link ID function used to ID the active links that neighbor fixed links in the vertical and horizontal directions. If the user wants to assign fixed gradients or values to the fixed links dynamically, this function identifies the nearest active_link neighbor. Each fixed link can either have 0 or 1 active neighbor. This function finds if and where that active neighbor is and stores those IDs in an array. Parameters ---------- grid : RasterModelGrid A landlab grid. Returns ------- ndarray of int, shape `(*, )` Flat array of links. Examples -------- >>> from landlab.grid.structured_quad.links import neighbors_at_link >>> from landlab import NodeStatus, RasterModelGrid >>> from landlab.components.overland_flow.generate_overland_flow_deAlmeida import find_active_neighbors_for_fixed_links >>> grid = RasterModelGrid((4, 5)) >>> grid.status_at_node[:5] = NodeStatus.FIXED_GRADIENT >>> grid.status_at_node[::5] = NodeStatus.FIXED_GRADIENT >>> grid.status_at_node # doctest: +NORMALIZE_WHITESPACE array([2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 1, 1, 1, 1], dtype=uint8) >>> grid.fixed_links array([ 5, 6, 7, 9, 18]) >>> grid.active_links array([10, 11, 12, 14, 15, 16, 19, 20, 21, 23, 24, 25]) >>> find_active_neighbors_for_fixed_links(grid) array([14, 15, 16, 10, 19]) >>> rmg = RasterModelGrid((4, 7)) >>> rmg.at_node['topographic__elevation'] = rmg.zeros(at='node') >>> rmg.at_link['topographic__slope'] = rmg.zeros(at='link') >>> rmg.status_at_node[rmg.perimeter_nodes] = rmg.BC_NODE_IS_FIXED_GRADIENT >>> find_active_neighbors_for_fixed_links(rmg) array([20, 21, 22, 23, 24, 14, 17, 27, 30, 20, 21, 22, 23, 24]) """ neighbors = links.neighbors_at_link(grid.shape, grid.fixed_links).flat return neighbors[np.in1d(neighbors, grid.active_links)]
def find_active_neighbors_for_fixed_links(grid): """Find active link neighbors for every fixed link. Specialized link ID function used to ID the active links that neighbor fixed links in the vertical and horizontal directions. If the user wants to assign fixed gradients or values to the fixed links dynamically, this function identifies the nearest active_link neighbor. Each fixed link can either have 0 or 1 active neighbor. This function finds if and where that active neighbor is and stores those IDs in an array. Parameters ---------- grid : RasterModelGrid A landlab grid. Returns ------- ndarray of int, shape `(*, )` Flat array of links. Examples -------- >>> from landlab.grid.structured_quad.links import neighbors_at_link >>> from landlab import RasterModelGrid >>> from landlab.components.overland_flow.generate_overland_flow_deAlmeida import find_active_neighbors_for_fixed_links >>> from landlab import RasterModelGrid, FIXED_GRADIENT_BOUNDARY >>> grid = RasterModelGrid((4, 5)) >>> grid.status_at_node[:5] = FIXED_GRADIENT_BOUNDARY >>> grid.status_at_node[::5] = FIXED_GRADIENT_BOUNDARY >>> grid.status_at_node # doctest: +NORMALIZE_WHITESPACE array([2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 2, 0, 0, 0, 1, 2, 1, 1, 1, 1], dtype=uint8) >>> grid.fixed_links array([ 5, 6, 7, 9, 18]) >>> grid.active_links array([10, 11, 12, 14, 15, 16, 19, 20, 21, 23, 24, 25]) >>> find_active_neighbors_for_fixed_links(grid) array([14, 15, 16, 10, 19]) >>> rmg = RasterModelGrid((4, 7)) >>> rmg.at_node['topographic__elevation'] = rmg.zeros(at='node') >>> rmg.at_link['topographic__slope'] = rmg.zeros(at='link') >>> rmg.set_fixed_link_boundaries_at_grid_edges(True, True, True, True) >>> find_active_neighbors_for_fixed_links(rmg) array([20, 21, 22, 23, 24, 14, 17, 27, 30, 20, 21, 22, 23, 24]) """ neighbors = links.neighbors_at_link(grid.shape, grid.fixed_links).flat return neighbors[np.in1d(neighbors, grid.active_links)]