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) # 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) if self.use_fixed_links: fixed_link_ids = links.fixed_link_ids(grid.shape, grid.node_status) fixed_horizontal_links = links.horizontal_fixed_link_ids( grid.shape, fixed_link_ids) fixed_vertical_links = links.vertical_fixed_link_ids( grid.shape, fixed_link_ids) self.horizontal_active_link_ids = np.maximum( self.horizontal_active_link_ids, fixed_horizontal_links) self.vertical_active_link_ids = np.maximum( self.vertical_active_link_ids, fixed_vertical_links) # Using the active vertical link ids we can find the north and south # vertical neighbors self.north_neighbors = links.vertical_north_link_neighbor( grid.shape, self.vertical_active_link_ids) self.south_neighbors = links.vertical_south_link_neighbor( grid.shape, self.vertical_active_link_ids) # Using the horizontal active link ids, we can find the west and east # neighbors self.west_neighbors = links.horizontal_west_link_neighbor( grid.shape, self.horizontal_active_link_ids) self.east_neighbors = links.horizontal_east_link_neighbor( grid.shape, self.horizontal_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
# Get a list of the core nodes core_nodes = mg.core_nodes active_links = mg.active_links # Display a message print ("Running ...") start_time = time.time() # These functions find link neighbors for horizontal and vertical active links. # First, we find all active links in the raster grid. active_ids = links.active_link_ids(mg.shape, mg.status_at_node) # Then we find all horizontal link ids... 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)
def set_up_neighbor_arrays(self): """Create and initialize link neighbor arrays. Set up arrays of neighboring horizontal and vertical links that are needed for the de Almeida solution. """ # First we identify all active links self._active_ids = links.active_link_ids( self._grid.shape, self._grid.status_at_node ) self._active_links_at_open_bdy = _active_links_at_node( self.grid, self.grid.open_boundary_nodes ).transpose() self._active_links_at_open_bdy = self._active_links_at_open_bdy[ np.where(self._active_links_at_open_bdy > -1) ] # And then find all horizontal link IDs (Active and Inactive) self._horizontal_ids = links.horizontal_link_ids(self._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( self._grid.shape, self._active_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(self._grid.shape).flatten() # Find the *active* verical link ids self._vertical_active_link_ids = links.vertical_active_link_ids( self._grid.shape, self._active_ids ) if self._default_fixed_links is True: fixed_link_ids = links.fixed_link_ids( self._grid.shape, self._grid.status_at_node ) fixed_horizontal_links = links.horizontal_fixed_link_ids( self._grid.shape, fixed_link_ids ) fixed_vertical_links = links.vertical_fixed_link_ids( self._grid.shape, fixed_link_ids ) self._horizontal_active_link_ids = np.maximum( self._horizontal_active_link_ids, fixed_horizontal_links ) self._vertical_active_link_ids = np.maximum( self._vertical_active_link_ids, fixed_vertical_links ) self._active_neighbors = find_active_neighbors_for_fixed_links(self._grid) self._vert_bdy_ids = self._active_links_at_open_bdy[ links.is_vertical_link(self._grid.shape, self._active_links_at_open_bdy) ] self._vert_bdy_ids = links.nth_vertical_link( self._grid.shape, self._vert_bdy_ids ) self._horiz_bdy_ids = self._active_links_at_open_bdy[ links.is_horizontal_link(self._grid.shape, self._active_links_at_open_bdy) ] self._horiz_bdy_ids = links.nth_horizontal_link( self._grid.shape, self._horiz_bdy_ids ) # Using the active vertical link ids we can find the north # and south vertical neighbors self._north_neighbors = links.vertical_north_link_neighbor( self._grid.shape, self._vertical_active_link_ids ) self._south_neighbors = links.vertical_south_link_neighbor( self._grid.shape, self._vertical_active_link_ids ) # Using the horizontal active link ids, we can find the west and # east neighbors self._west_neighbors = links.horizontal_west_link_neighbor( self._grid.shape, self._horizontal_active_link_ids ) self._east_neighbors = links.horizontal_east_link_neighbor( self._grid.shape, self._horizontal_active_link_ids ) # replace bdy condition links (ids,) = np.where(self._west_neighbors[self._horiz_bdy_ids] == -1) ids = self._horiz_bdy_ids[ids] self._west_neighbors[ids] = self._horizontal_active_link_ids[ids] (ids,) = np.where(self._east_neighbors[self._horiz_bdy_ids] == -1) ids = self._horiz_bdy_ids[ids] self._east_neighbors[ids] = self._horizontal_active_link_ids[ids] (ids,) = np.where(self._north_neighbors[self._vert_bdy_ids] == -1) ids = self._vert_bdy_ids[ids] self._north_neighbors[ids] = self._vertical_active_link_ids[ids] (ids,) = np.where(self._south_neighbors[self._vert_bdy_ids] == -1) ids = self._vert_bdy_ids[ids] self._south_neighbors[ids] = self._vertical_active_link_ids[ids] # Set up arrays for discharge in the horizontal & vertical directions. self._q_horizontal = np.zeros( links.number_of_horizontal_links(self._grid.shape) ) self._q_vertical = np.zeros(links.number_of_vertical_links(self._grid.shape)) # Once the neighbor arrays are set up, we change the flag to True! self._neighbor_flag = True
#rmg['node']['water_depth'] += h_init # Now we'll identify our leftmost, but interior, column and the IDs of those # nodes. One column in to prevent issues with BC. inside_left_edge = rmg.nodes[1:-1, 1] # Initializing our class... of = OverlandFlow(rmg, mannings_n=n, theta=0.8, h_init=0.001) # Now, we need to set a fixed value on the left edge, so we find the # link neighbor arrays... of.set_up_neighbor_arrays() # ... and get a list of all horizonal ids, not just active ids (which is what # the deAlmeida solution uses) all_horizontal_ids = links.horizontal_link_ids(rmg.shape) # from there, we are going to reset our west neighbor array... of.west_neighbors = (links.horizontal_west_link_neighbor( rmg.shape, all_horizontal_ids)) # and find the ids of the arrays along the west edge of the grid. We actually # will set the discharge values here at every time step in the loop. left_inactive_ids = links.left_edge_horizontal_ids(rmg.shape) # Let's see how long this run takes... starttime = time() while elapsed_time < run_time: # Now we are going to set the left edge horizontal links to their
def set_up_neighbor_arrays(self): """Create and initialize link neighbor arrays. Set up arrays of neighboring horizontal and vertical links that are needed for the de Almeida solution. """ # First we identify all active links self.active_ids = links.active_link_ids(self.grid.shape, self.grid.status_at_node) # And then find all horizontal link IDs (Active and Inactive) self.horizontal_ids = links.horizontal_link_ids(self.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( self.grid.shape, self.active_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(self.grid.shape).flatten() # Find the *active* verical link ids self.vertical_active_link_ids = links.vertical_active_link_ids( self.grid.shape, self.active_ids) if self.default_fixed_links is True: fixed_link_ids = links.fixed_link_ids(self.grid.shape, self.grid.status_at_node) fixed_horizontal_links = links.horizontal_fixed_link_ids( self.grid.shape, fixed_link_ids) fixed_vertical_links = links.vertical_fixed_link_ids( self.grid.shape, fixed_link_ids) self.horizontal_active_link_ids = np.maximum( self.horizontal_active_link_ids, fixed_horizontal_links) self.vertical_active_link_ids = np.maximum( self.vertical_active_link_ids, fixed_vertical_links) self.active_neighbors = find_active_neighbors_for_fixed_links( self.grid) # Using the active vertical link ids we can find the north # and south vertical neighbors self.north_neighbors = links.vertical_north_link_neighbor( self.grid.shape, self.vertical_active_link_ids) self.south_neighbors = links.vertical_south_link_neighbor( self.grid.shape, self.vertical_active_link_ids) # Using the horizontal active link ids, we can find the west and # east neighbors self.west_neighbors = links.horizontal_west_link_neighbor( self.grid.shape, self.horizontal_active_link_ids) self.east_neighbors = links.horizontal_east_link_neighbor( self.grid.shape, self.horizontal_active_link_ids) # Set up arrays for discharge in the horizontal & vertical directions. self.q_horizontal = np.zeros( links.number_of_horizontal_links(self.grid.shape)) self.q_vertical = np.zeros( links.number_of_vertical_links(self.grid.shape)) # Once the neighbor arrays are set up, we change the flag to True! self.neighbor_flag = True
# rmg['node']['surface_water__depth'] += h_init # Now we'll identify our leftmost, but interior, column and the IDs of those # nodes. One column in to prevent issues with BC. inside_left_edge = rmg.nodes[1:-1, 1] # Initializing our class... of = OverlandFlow(rmg, mannings_n=n, theta=0.8, h_init=0.001) # Now, we need to set a fixed value on the left edge, so we find the # link neighbor arrays... of.set_up_neighbor_arrays() # ... and get a list of all horizonal ids, not just active ids (which is what # the deAlmeida solution uses) all_horizontal_ids = links.horizontal_link_ids(rmg.shape) # from there, we are going to reset our west neighbor array... of.west_neighbors = links.horizontal_west_link_neighbor(rmg.shape, all_horizontal_ids) # and find the ids of the arrays along the west edge of the grid. We actually # will set the discharge values here at every time step in the loop. left_inactive_ids = links.left_edge_horizontal_ids(rmg.shape) # Let's see how long this run takes... starttime = time() while elapsed_time < run_time: # Now we are going to set the left edge horizontal links to their # neighboring discharge value
def set_up_neighbor_arrays(self): """Create and initialize link neighbor arrays. Set up arrays of neighboring horizontal and vertical links that are needed for the de Almeida solution. """ # First we identify all active links self.active_ids = links.active_link_ids( self.grid.shape, self.grid.status_at_node ) self.active_links_at_open_bdy = self.grid._active_links_at_node( self.grid.open_boundary_nodes ).transpose() self.active_links_at_open_bdy = self.active_links_at_open_bdy[ np.where(self.active_links_at_open_bdy > -1) ] # And then find all horizontal link IDs (Active and Inactive) self.horizontal_ids = links.horizontal_link_ids(self.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( self.grid.shape, self.active_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(self.grid.shape).flatten() # Find the *active* verical link ids self.vertical_active_link_ids = links.vertical_active_link_ids( self.grid.shape, self.active_ids ) if self.default_fixed_links is True: fixed_link_ids = links.fixed_link_ids( self.grid.shape, self.grid.status_at_node ) fixed_horizontal_links = links.horizontal_fixed_link_ids( self.grid.shape, fixed_link_ids ) fixed_vertical_links = links.vertical_fixed_link_ids( self.grid.shape, fixed_link_ids ) self.horizontal_active_link_ids = np.maximum( self.horizontal_active_link_ids, fixed_horizontal_links ) self.vertical_active_link_ids = np.maximum( self.vertical_active_link_ids, fixed_vertical_links ) self.active_neighbors = find_active_neighbors_for_fixed_links(self.grid) self.vert_bdy_ids = self.active_links_at_open_bdy[ links.is_vertical_link(self.grid.shape, self.active_links_at_open_bdy) ] self.vert_bdy_ids = links.nth_vertical_link(self.grid.shape, self.vert_bdy_ids) self.horiz_bdy_ids = self.active_links_at_open_bdy[ links.is_horizontal_link(self.grid.shape, self.active_links_at_open_bdy) ] self.horiz_bdy_ids = links.nth_horizontal_link( self.grid.shape, self.horiz_bdy_ids ) # Using the active vertical link ids we can find the north # and south vertical neighbors self.north_neighbors = links.vertical_north_link_neighbor( self.grid.shape, self.vertical_active_link_ids ) self.south_neighbors = links.vertical_south_link_neighbor( self.grid.shape, self.vertical_active_link_ids ) # Using the horizontal active link ids, we can find the west and # east neighbors self.west_neighbors = links.horizontal_west_link_neighbor( self.grid.shape, self.horizontal_active_link_ids ) self.east_neighbors = links.horizontal_east_link_neighbor( self.grid.shape, self.horizontal_active_link_ids ) # replace bdy condition links (ids,) = np.where(self.west_neighbors[self.horiz_bdy_ids] == -1) ids = self.horiz_bdy_ids[ids] self.west_neighbors[ids] = self.horizontal_active_link_ids[ids] (ids,) = np.where(self.east_neighbors[self.horiz_bdy_ids] == -1) ids = self.horiz_bdy_ids[ids] self.east_neighbors[ids] = self.horizontal_active_link_ids[ids] (ids,) = np.where(self.north_neighbors[self.vert_bdy_ids] == -1) ids = self.vert_bdy_ids[ids] self.north_neighbors[ids] = self.vertical_active_link_ids[ids] (ids,) = np.where(self.south_neighbors[self.vert_bdy_ids] == -1) ids = self.vert_bdy_ids[ids] self.south_neighbors[ids] = self.vertical_active_link_ids[ids] # Set up arrays for discharge in the horizontal & vertical directions. self.q_horizontal = np.zeros(links.number_of_horizontal_links(self.grid.shape)) self.q_vertical = np.zeros(links.number_of_vertical_links(self.grid.shape)) # Once the neighbor arrays are set up, we change the flag to True! self.neighbor_flag = True