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
# 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.
q_horizontal = np.zeros(links.number_of_horizontal_links(mg.shape))
q_vertical = np.zeros(links.number_of_vertical_links(mg.shape))

# First we calculate our updated boundary water depth
h_boundary = ((seven_over_three) * n * n * u * u * u * elapsed_time) ** (
    three_over_seven
)  # water depth at left side (m)

# And now we add it to the second column, in all rows that are not boundary rows.
h[(leftside)[1 : len(leftside) - 1]] = h_boundary

# Main loop
while elapsed_time <= run_time:

    # Calculate time-step size for this iteration (Bates et al., eq 14)
    dtmax = alpha * mg.dx / np.sqrt(g * np.amax(h))
Beispiel #3
0
    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
Beispiel #4
0
    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
    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