Example #1
0
def run_day(mg, precipitation: float, duration=1800):
    """
    Calculates the mm of water that has infiltrated into soil after a rainfall event.
    Rainfall events are assumed to be instantaneous and constant over the model grid.

    :param dem: model grid
    :param precipitation: rainfall in mm/hr
    :param duration: seconds of rainfall
    :return: mm of water infiltrated into the soil at every coordinate in the grid
    """
    elapsed_time = 0.0
    swd = mg.add_zeros('surface_water__depth', at='node', clobber=True)
    swd += precipitation
    swid = mg.add_zeros('soil_water_infiltration__depth',
                        at='node',
                        clobber=True)
    swid += 1e-6
    siga = SoilInfiltrationGreenAmpt(mg)
    of = OverlandFlow(mg, steep_slopes=True)

    while elapsed_time < duration:
        dt = of.calc_time_step()
        dt = dt if dt + elapsed_time < duration else duration - elapsed_time
        of.run_one_step(dt=dt)
        siga.run_one_step(dt=dt)
        elapsed_time += dt
    return xr.DataArray(mg.at_node['soil_water_infiltration__depth'].reshape(
        mg.shape),
                        dims=('x', 'y'))
Example #2
0
def test_deAlm_analytical():
    grid = RasterModelGrid((32, 240), xy_spacing=25)
    grid.add_zeros("surface_water__depth", at="node")
    grid.add_zeros("topographic__elevation", at="node")
    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 = deAlm.calc_time_step()
        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', '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)
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)
Example #5
0
isChannel = np.logical_and(rmg.x_of_node < channel_left,
                           rmg.x_of_node > channel_right)

highInfBand = np.logical_and(rmg.x_of_node < channel_left + infBandWidth,
                             rmg.x_of_node > channel_right - infBandWidth)
inf_mask = np.logical_xor(highInfBand, isChannel)
hc[inf_mask] *= 10

of = OverlandFlow(rmg, steep_slopes=True)

SI = SoilInfiltrationGreenAmpt(rmg, hydraulic_conductivity=hc)

elapsed_time = 0
run_time = 1e4
iters = 0

while elapsed_time < run_time:
    # First, we calculate our time step.
    dt = of.calc_time_step()
    # Now, we can generate overland flow.
    of.overland_flow()
    SI.run_one_step(dt)
    # Increased elapsed time
    if iters % 1000 == 0:
        print('Elapsed time: ', elapsed_time)
    elapsed_time += dt
    iters += 1

imshow_grid(rmg, 'surface_water__depth', cmap='Blues')