Exemplo n.º 1
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