Esempio n. 1
0
def setup_grid():
    from landlab import RasterModelGrid
    grid = RasterModelGrid((20, 20), spacing=10e3)
    flex = Flexure1D(grid)
    globals().update({
        'flex': Flexure1D(grid)
    })
Esempio n. 2
0
def test_method_keyword():
    """Test using the method keyword."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method='airy')
    assert_equal(flex.method, 'airy')
    flex = Flexure1D(RasterModelGrid((3, 5)), method='flexure')
    assert_equal(flex.method, 'flexure')
    with assert_raises(ValueError):
        Flexure1D(RasterModelGrid((3, 5)), method='Flexure')
Esempio n. 3
0
def test_method_keyword():
    """Test using the method keyword."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy")
    assert flex.method == "airy"
    flex = Flexure1D(RasterModelGrid((3, 5)), method="flexure")
    assert flex.method == "flexure"
    with pytest.raises(ValueError):
        Flexure1D(RasterModelGrid((3, 5)), method="Flexure")
Esempio n. 4
0
def test_flexure_keywords(flexure_keyword):
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")
    flex = Flexure1D(grid, **{flexure_keyword: 1.0})
    assert getattr(flex, flexure_keyword) == 1.0
    assert isinstance(getattr(flex, flexure_keyword), float)
    with pytest.raises(ValueError):
        flex = Flexure1D(grid, **{flexure_keyword: -1})
Esempio n. 5
0
def test_method_keyword():
    """Test using the method keyword."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="airy")
    assert flex.method == "airy"
    flex = Flexure1D(grid, method="flexure")
    assert flex.method == "flexure"
    with pytest.raises(ValueError):
        Flexure1D(grid, method="Flexure")
Esempio n. 6
0
def test_subside_loads():
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy")
    dz_airy = flex.subside_loads([0.0, 0.0, flex.gamma_mantle, 0.0, 0])
    assert dz_airy.shape == flex.grid.shape
    assert np.all(dz_airy == [0.0, 0.0, 1.0, 0.0, 0])

    flex = Flexure1D(RasterModelGrid((3, 5)), method="flexure")
    dz_flexure = flex.subside_loads([0.0, 0.0, flex.gamma_mantle, 0.0, 0])

    assert dz_flexure.shape == flex.grid.shape
    assert np.argmax(dz_flexure) == 2
    assert np.all(dz_flexure[:, 2] < dz_airy[:, 2])
    assert np.all(dz_flexure[:, 2::-1] == pytest.approx(dz_flexure[:, 2:]))
Esempio n. 7
0
def test_calc_flexure_with_out_keyword():
    """Test calc_flexure out keyword."""
    x = np.arange(100.0)
    loads = np.ones(100)
    buffer = np.empty_like(x)
    dz = Flexure1D.calc_flexure(x, loads, 1.0, 1.0, out=buffer)
    assert np.may_share_memory(dz, buffer)
Esempio n. 8
0
def test_calc_flexure_with_out_keyword():
    """Test calc_flexure out keyword."""
    x = np.arange(100.)
    loads = np.ones(100)
    buffer = np.empty_like(x)
    dz = Flexure1D.calc_flexure(x, loads, 1., 1., out=buffer)
    assert np.may_share_memory(dz, buffer)
Esempio n. 9
0
def test_x_at_node():
    """Test x_at_node is reshaped and shares memory with the grid."""
    flex = Flexure1D(RasterModelGrid((3, 5)))

    assert_array_equal(
        flex.x_at_node,
        [[0., 1., 2., 3., 4.], [0., 1., 2., 3., 4.], [0., 1., 2., 3., 4.]],
    )
Esempio n. 10
0
def test_load_is_contiguous():
    """Test that load_at_node is contiguous."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid)
    assert flex.load_at_node.flags["C_CONTIGUOUS"]
Esempio n. 11
0
def test_calc_airy():
    """Test airy isostasy."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy")
    flex.load_at_node[:] = flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.)
    flex.update()
    assert_array_equal(flex.dz_at_node, 1.)
Esempio n. 12
0
def test_run_one_step():
    """Test the run_one_step method."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy")
    flex.load_at_node[:] = flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.)
    flex.run_one_step()
    assert_array_equal(flex.dz_at_node, 1.)
Esempio n. 13
0
def test_x_at_node():
    """Test x_at_node is reshaped and shares memory with the grid."""
    flex = Flexure1D(RasterModelGrid((3, 5)))

    assert_array_equal(flex.x_at_node, [[0., 1., 2., 3., 4.,],
                                        [0., 1., 2., 3., 4.,],
                                        [0., 1., 2., 3., 4.,]])
    assert_true(np.may_share_memory(flex.x_at_node, flex.grid.x_of_node))
Esempio n. 14
0
def test_dz_at_node():
    """Test dz_at_node is reshaped and shares memory with its field."""
    flex = Flexure1D(RasterModelGrid((3, 5)))

    vals = flex.grid.at_node["lithosphere_surface__increment_of_elevation"]
    assert_array_equal(vals, 0.)

    assert np.may_share_memory(vals, flex.dz_at_node)
    assert flex.dz_at_node.shape == (3, 5)
Esempio n. 15
0
def test_load_at_node():
    """Test load_at_node is reshaped and shares memory with its field."""
    flex = Flexure1D(RasterModelGrid((3, 5)))

    vals = flex.grid.at_node["lithosphere__increment_of_overlying_pressure"]
    assert_array_equal(vals, 0.)

    assert np.may_share_memory(vals, flex.load_at_node)
    assert flex.load_at_node.shape == (3, 5)
Esempio n. 16
0
def test_with_one_row():
    """Test calculating on one row."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy", rows=1)
    flex.load_at_node[:] = flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.)
    flex.update()
    assert_array_equal(flex.dz_at_node[0], 0.)
    assert_array_equal(flex.dz_at_node[1], 1.)
    assert_array_equal(flex.dz_at_node[2], 0.)
Esempio n. 17
0
def test_setters(flexure_keyword):
    EPS = 1e-6
    flex = Flexure1D(RasterModelGrid((3, 5)))
    val_before = {}
    for name in DEPENDS_ON[flexure_keyword]:
        val_before[name] = 1. * getattr(flex, name)
    for name in DEPENDS_ON[flexure_keyword]:
        setattr(flex, flexure_keyword,
                getattr(flex, flexure_keyword) * (1. + EPS) + EPS)
        assert val_before[name] != getattr(flex, name)
Esempio n. 18
0
def test_field_is_updated():
    """Test the output field is updated."""
    flex = Flexure1D(RasterModelGrid((3, 5)), method="airy", rows=(0, 2))
    flex.load_at_node[:] = -flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.)
    flex.update()

    dz = flex.grid.at_node["lithosphere_surface__increment_of_elevation"]
    assert_array_equal(flex.dz_at_node.flatten(), dz)
Esempio n. 19
0
def test_calc_flexure():
    """Test calc_flexure function."""
    x = np.arange(100.)
    loads = np.ones(100)
    dz = Flexure1D.calc_flexure(x, loads, 1., 1.)

    assert_array_less(0., dz)
    assert isinstance(dz, np.ndarray)
    assert dz.shape == loads.shape
    assert dz.dtype == loads.dtype
Esempio n. 20
0
def test_calc_flexure():
    """Test calc_flexure function."""
    x = np.arange(100.0)
    loads = np.ones(100)
    dz = Flexure1D.calc_flexure(x, loads, 1.0, 1.0)

    assert_array_less(0.0, dz)
    assert isinstance(dz, np.ndarray)
    assert dz.shape == loads.shape
    assert dz.dtype == loads.dtype
Esempio n. 21
0
    def update(self):

        if self._isostasytime > 0.0:
            isostasyfrac = 1 - np.exp(-1.0 * self._dt / self._isostasytime)
        else:
            isostasyfrac = 1.0

        self.grid.at_node[
            "lithosphere_surface__increment_of_elevation"][:] = 0.0

        # calculate density based on sand_frac
        percent_sand = self.grid.at_node[
            "delta_sediment_sand__volume_fraction"].reshape(self.grid.shape)[1]
        rho_sediment = (percent_sand * self._rho_sand +
                        (1 - percent_sand) * self._rho_mud)

        # load underwater displaces water
        z = self.grid.at_node["topographic__elevation"].reshape(
            self.grid.shape)[1]
        sea_level = self.grid.at_grid["sea_level__elevation"]
        under_water = z < sea_level
        rho_sediment[under_water] = rho_sediment[under_water] - 1030.0

        dz = self.grid.at_node["sediment_deposit__thickness"].reshape(
            self.grid.shape)[1]
        pressure = self.grid.at_node[
            "lithosphere__increment_of_overlying_pressure"].reshape(
                self.grid.shape)[1]
        pressure[:] = dz * rho_sediment * self.gravity * self.grid.dx

        Flexure1D.update(self)

        dz = self.grid.at_node["lithosphere_surface__increment_of_elevation"]
        self.subs_pool[:] += dz
        dz = self.subs_pool[:] * isostasyfrac
        self.subs_pool[:] = self.subs_pool[:] - dz

        self.grid.at_node["bedrock_surface__increment_of_elevation"][:] = dz

        self.grid.at_node["bedrock_surface__elevation"] -= dz
        self.grid.at_node["topographic__elevation"] -= dz
Esempio n. 22
0
def test_calc_airy():
    """Test airy isostasy."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="airy")
    flex.load_at_node[:] = flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.0)
    flex.update()
    assert_array_equal(flex.dz_at_node, 1.0)
Esempio n. 23
0
def test_subside_loads():
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="airy")
    dz_airy = flex.subside_loads([0.0, 0.0, flex.gamma_mantle, 0.0, 0])
    assert dz_airy.shape == flex.grid.shape
    assert np.all(dz_airy == [0.0, 0.0, 1.0, 0.0, 0])

    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="flexure")
    dz_flexure = flex.subside_loads([0.0, 0.0, flex.gamma_mantle, 0.0, 0])

    assert dz_flexure.shape == flex.grid.shape
    assert np.argmax(dz_flexure) == 2
    assert np.all(dz_flexure[:, 2] < dz_airy[:, 2])
    assert np.all(dz_flexure[:, 2::-1] == pytest.approx(dz_flexure[:, 2:]))
Esempio n. 24
0
def test_load_at_node():
    """Test load_at_node is reshaped and shares memory with its field."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid)

    vals = flex.grid.at_node["lithosphere__increment_of_overlying_pressure"]
    assert_array_equal(vals, 0.0)

    assert np.may_share_memory(vals, flex.load_at_node)
    assert flex.load_at_node.shape == (3, 5)
Esempio n. 25
0
def test_with_method_flexure():
    n = 101
    i_mid = (n - 1) // 2
    flex = Flexure1D(RasterModelGrid((3, n)), method="flexure")
    flex.load_at_node[1, i_mid] = 1.0

    flex.update()

    assert np.argmax(flex.dz_at_node[1]) == i_mid
    assert np.all(
        flex.dz_at_node[:,
                        i_mid::-1] == pytest.approx(flex.dz_at_node[:,
                                                                    i_mid:]))
Esempio n. 26
0
    def __init__(
        self,
        grid,
        sand_density=2650,
        mud_density=2720.0,
        isostasytime=7000.0,
        **kwds,
        # **sediments,
    ):
        self._rho_sand = sand_density * (1 -
                                         0.4) + 1030.0 * 0.4  # porosity = 40%
        self._rho_mud = mud_density * (1 -
                                       0.65) + 1030.0 * 0.65  # porosity = 65%
        self._isostasytime = isostasytime
        self._dt = 100.0  # default timestep = 100 y

        grid.add_zeros("lithosphere__increment_of_overlying_pressure",
                       at="node")

        Flexure1D.__init__(self, grid, **kwds)

        self.subs_pool = self.grid.zeros(at="node")
Esempio n. 27
0
def test_calc_flexure_with_multiple_rows():
    """Test calc_flexure with multiple rows of loads."""
    x = np.arange(100.0) * 1e3
    loads = np.ones(500).reshape((5, 100))
    dz = Flexure1D.calc_flexure(x, loads, 1e4, 1.0)

    assert_array_less(0.0, dz)
    assert isinstance(dz, np.ndarray)
    assert dz.shape == loads.shape
    assert dz.dtype == loads.dtype

    for row in range(5):
        assert_array_almost_equal(dz[0], dz[row])
Esempio n. 28
0
def test_calc_flexure():
    """Test calc_flexure with multiple rows of loads."""
    x = np.arange(100.) * 1e3
    loads = np.ones(500).reshape((5, 100))
    dz = Flexure1D.calc_flexure(x, loads, 1e4, 1.)

    assert_array_less(0., dz)
    assert isinstance(dz, np.ndarray)
    assert dz.shape == loads.shape
    assert dz.dtype == loads.dtype

    for row in range(5):
        assert_array_almost_equal(dz[0], dz[row])
Esempio n. 29
0
def test_with_two_row():
    """Test calculating on one row."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="airy", rows=(0, 2))
    flex.load_at_node[:] = -flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.0)
    flex.update()
    assert_array_equal(flex.dz_at_node[0], -1.0)
    assert_array_equal(flex.dz_at_node[1], 0.0)
    assert_array_equal(flex.dz_at_node[2], -1.0)
Esempio n. 30
0
def test_field_is_updated():
    """Test the output field is updated."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="airy", rows=(0, 2))
    flex.load_at_node[:] = -flex.gamma_mantle

    assert_array_equal(flex.dz_at_node, 0.0)
    flex.update()

    dz = flex.grid.at_node["lithosphere_surface__increment_of_elevation"]
    assert_array_equal(flex.dz_at_node.flatten(), dz)
Esempio n. 31
0
def test_setters(flexure_keyword):
    EPS = 1e-6
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid)
    val_before = {}
    for name in DEPENDS_ON[flexure_keyword]:
        val_before[name] = 1.0 * getattr(flex, name)
    for name in DEPENDS_ON[flexure_keyword]:
        setattr(
            flex, flexure_keyword, getattr(flex, flexure_keyword) * (1.0 + EPS) + EPS
        )
        assert val_before[name] != getattr(flex, name)
Esempio n. 32
0
def test_x_at_node():
    """Test x_at_node is reshaped and shares memory with the grid."""
    grid = RasterModelGrid((3, 5))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid)

    assert_array_equal(
        flex.x_at_node,
        [
            [0.0, 1.0, 2.0, 3.0, 4.0],
            [0.0, 1.0, 2.0, 3.0, 4.0],
            [0.0, 1.0, 2.0, 3.0, 4.0],
        ],
    )
Esempio n. 33
0
def test_with_method_flexure():
    n = 101
    i_mid = (n - 1) // 2
    grid = RasterModelGrid((3, n))
    grid.add_zeros("lithosphere_surface__increment_of_elevation", at="node")
    grid.add_zeros("lithosphere__increment_of_overlying_pressure", at="node")

    flex = Flexure1D(grid, method="flexure")
    flex.load_at_node[1, i_mid] = 1.0

    flex.update()

    assert np.argmax(flex.dz_at_node[1]) == i_mid
    assert np.all(
        flex.dz_at_node[:, i_mid::-1] == pytest.approx(flex.dz_at_node[:, i_mid:])
    )