def set_up_neighbor_arrays(self, grid): # This function gets arrays of neighboring horizontal and vertical # links which are needed for the de Almeida solution # First we identify all active links self.active_ids = links.active_link_ids(grid.shape, grid.node_status) # And then find all horizontal link IDs (Active and Inactive) self.horizontal_ids = links.horizontal_link_ids(grid.shape) # And make the array 1-D self.horizontal_ids = self.horizontal_ids.flatten() # Find all horizontal active link ids self.horizontal_active_link_ids = links.horizontal_active_link_ids(grid.shape, self.active_ids) # Using the horizontal active link ids, we can find the west and east neighbors self.west_neighbors = links.find_horizontal_west_neighbor(grid.shape, self.horizontal_active_link_ids) self.east_neighbors = links.find_horizontal_east_neighbor(grid.shape, self.horizontal_active_link_ids) # Now we repeat this process for the vertical links. # First find the vertical link ids and reshape it into a 1-D array self.vertical_ids = links.vertical_link_ids(grid.shape).flatten() # Find the *active* verical link ids self.vertical_active_link_ids = links.vertical_active_link_ids(grid.shape, self.active_ids) # Using the active vertical link ids we can find the north and south vertical neighbors self.north_neighbors = links.find_vertical_north_neighbor(grid.shape, self.vertical_active_link_ids) self.south_neighbors = links.find_vertical_south_neighbor(grid.shape, self.vertical_active_link_ids) # Set up arrays for discharge in the horizontal and vertical directions. self.q_horizontal = np.zeros(links.number_of_horizontal_links(grid.shape)) self.q_vertical = np.zeros(links.number_of_vertical_links(grid.shape)) # Once the neighbor arrays are set up, we change the flag to True! self.neighbor_flag = True
horizontal_ids = links.horizontal_link_ids(mg.shape) # Get ids of left-most link ids for boundary issues... left_inactive_ids = horizontal_ids[:, 0] # Then we flatten our array so we can use it elsewhere. horizontal_ids = horizontal_ids.flatten() # ... and narrow them down to the active horizontal link ids. horizontal_active_link_ids = links.horizontal_active_link_ids(mg.shape, active_ids) # Here we actually identify, for each link, the id of its W and E neighbor. For the # de Almeida solution, horizontal neighbors are west and east. Only # active link ids are given, any inactive link id is replaced with a '-1'. west_neighbors = links.find_horizontal_west_neighbor(mg.shape, horizontal_ids) east_neighbors = links.find_horizontal_east_neighbor(mg.shape, horizontal_active_link_ids) # Now we do the same with all vertical link ids. First, we get ALL vertical ids. vertical_ids = links.vertical_link_ids(mg.shape).flatten() # And then we narrow them down to just the active vertical link ids. vertical_active_link_ids = links.vertical_active_link_ids(mg.shape, active_ids) # For the de Almeida solution, we only need N and S neighbors for vertical active links, # so for each link, the N and S neighbor ids are given by these two function calls. Any # inactive link id is replaced with an index of '-1'. north_neighbors = links.find_vertical_north_neighbor(mg.shape, vertical_active_link_ids) south_neighbors = links.find_vertical_south_neighbor(mg.shape, vertical_active_link_ids) # To solve this 2-D problem as two 1-D sets, we need to create arrays for # discharge in the horizontal and vertical directions.