def test_deAlm_analytical():
    from landlab import RasterModelGrid
    grid = RasterModelGrid((32, 240), spacing = 25)
    grid.add_zeros('node', 'surface_water__depth')
    grid.add_zeros('node', 'topographic__elevation')
    grid.set_closed_boundaries_at_grid_edges(True, True, True, True)
    left_inactive_ids = left_edge_horizontal_ids(grid.shape)
    deAlm = OverlandFlow(grid, mannings_n=0.01, h_init=0.001)
    time = 0.0

    while time < 500.:
        grid['link']['surface_water__discharge'][left_inactive_ids] = (
            grid['link']['surface_water__discharge'][left_inactive_ids + 1])
        dt = deAlm.calc_time_step()
        deAlm.overland_flow(dt)
        h_boundary = (((7./3.) * (0.01**2) * (0.4**3) *
                      time) ** (3./7.))
        grid.at_node['surface_water__depth'][grid.nodes[1: -1, 1]] = h_boundary
        time += dt

    x = np.arange(0, ((grid.shape[1]) * grid.dx), grid.dx)
    h_analytical = (-(7./3.) * (0.01**2) * (0.4**2) * (x - (0.4 * 500)))

    h_analytical[np.where(h_analytical > 0)] = (h_analytical[np.where(
        h_analytical > 0)] ** (3./7.))
    h_analytical[np.where(h_analytical < 0)] = 0.0

    hdeAlm = deAlm.h.reshape(grid.shape)
    hdeAlm = hdeAlm[1][1:]
    hdeAlm = np.append(hdeAlm, [0])
    np.testing.assert_almost_equal(h_analytical, hdeAlm, decimal=1)
Esempio n. 2
0
def test_deAlm_analytical_imposed_dt_short():
    grid = RasterModelGrid((32, 240), xy_spacing=25)
    grid.add_zeros("node", "surface_water__depth")
    grid.add_zeros("node", "topographic__elevation")
    grid.set_closed_boundaries_at_grid_edges(True, True, True, True)
    left_inactive_ids = left_edge_horizontal_ids(grid.shape)
    deAlm = OverlandFlow(grid, mannings_n=0.01, h_init=0.001)
    time = 0.0

    while time < 500.0:
        grid.at_link["surface_water__discharge"][
            left_inactive_ids] = grid.at_link["surface_water__discharge"][
                left_inactive_ids + 1]
        dt = 10.0
        deAlm.overland_flow(dt)
        h_boundary = ((7.0 / 3.0) * (0.01**2) * (0.4**3) * time)**(3.0 / 7.0)
        grid.at_node["surface_water__depth"][grid.nodes[1:-1, 1]] = h_boundary
        time += dt

    x = np.arange(0, ((grid.shape[1]) * grid.dx), grid.dx)
    h_analytical = -(7.0 / 3.0) * (0.01**2) * (0.4**2) * (x - (0.4 * 500))

    h_analytical[np.where(h_analytical > 0)] = h_analytical[np.where(
        h_analytical > 0)]**(3.0 / 7.0)
    h_analytical[np.where(h_analytical < 0)] = 0.0

    hdeAlm = deAlm.h.reshape(grid.shape)
    hdeAlm = hdeAlm[1][1:]
    hdeAlm = np.append(hdeAlm, [0])
    np.testing.assert_almost_equal(h_analytical, hdeAlm, decimal=1)
def test_deAlm_analytical():
    from landlab import RasterModelGrid
    grid = RasterModelGrid((32, 240), spacing=25)
    grid.add_zeros('node', 'water__depth')
    grid.add_zeros('node', 'topographic__elevation')
    grid.set_closed_boundaries_at_grid_edges(True, True, True, True)
    left_inactive_ids = left_edge_horizontal_ids(grid.shape)
    deAlm = OverlandFlow(grid, mannings_n=0.01, h_init=0.001)
    time = 0.0

    while time < 500:
        grid['link']['water__discharge'][left_inactive_ids] = (
            grid['link']['water__discharge'][left_inactive_ids + 1])
        dt = deAlm.calc_time_step()
        deAlm.overland_flow(dt)
        h_boundary = (((7. / 3.) * (0.01**2) * (0.4**3) * time)**(3. / 7.))
        grid.at_node['water__depth'][grid.nodes[1:-1, 1]] = h_boundary
        time += dt

    x = np.arange(0, ((grid.shape[1]) * grid.dx), grid.dx)
    h_analytical = (-(7. / 3.) * (0.01**2) * (0.4**2) * (x - (0.4 * 500)))

    h_analytical[np.where(h_analytical > 0)] = (h_analytical[np.where(
        h_analytical > 0)]**(3. / 7.))
    h_analytical[np.where(h_analytical < 0)] = 0.0

    hdeAlm = deAlm.h.reshape(grid.shape)
    hdeAlm = hdeAlm[1][1:]
    hdeAlm = np.append(hdeAlm, [0])
    np.testing.assert_almost_equal(h_analytical, hdeAlm, decimal=1)
def test_deAlm_analytical_imposed_dt_short():
    grid = RasterModelGrid((32, 240), xy_spacing=25)
    grid.add_zeros("node", "surface_water__depth")
    grid.add_zeros("node", "topographic__elevation")
    grid.set_closed_boundaries_at_grid_edges(True, True, True, True)
    left_inactive_ids = left_edge_horizontal_ids(grid.shape)
    deAlm = OverlandFlow(grid, mannings_n=0.01, h_init=0.001)
    time = 0.0

    while time < 500.0:
        grid.at_link["surface_water__discharge"][left_inactive_ids] = grid.at_link[
            "surface_water__discharge"
        ][left_inactive_ids + 1]
        dt = 10.0
        deAlm.overland_flow(dt)
        h_boundary = ((7.0 / 3.0) * (0.01 ** 2) * (0.4 ** 3) * time) ** (3.0 / 7.0)
        grid.at_node["surface_water__depth"][grid.nodes[1:-1, 1]] = h_boundary
        time += dt

    x = np.arange(0, ((grid.shape[1]) * grid.dx), grid.dx)
    h_analytical = -(7.0 / 3.0) * (0.01 ** 2) * (0.4 ** 2) * (x - (0.4 * 500))

    h_analytical[np.where(h_analytical > 0)] = h_analytical[
        np.where(h_analytical > 0)
    ] ** (3.0 / 7.0)
    h_analytical[np.where(h_analytical < 0)] = 0.0

    hdeAlm = deAlm.h.reshape(grid.shape)
    hdeAlm = hdeAlm[1][1:]
    hdeAlm = np.append(hdeAlm, [0])
    np.testing.assert_almost_equal(h_analytical, hdeAlm, decimal=1)
Esempio n. 5
0
# 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

    rmg['link']['water__discharge'][left_inactive_ids] = (
        rmg['link']['water__discharge'][left_inactive_ids + 1])

    # Now, we can generate overland flow.
    of.overland_flow()
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

    rmg["link"]["surface_water__discharge"][left_inactive_ids] = rmg["link"][
        "surface_water__discharge"
    ][left_inactive_ids + 1]

    # Now, we can generate overland flow.
    of.overland_flow()