def test_trapezoidal_bed(self): tb = dummy_trapezoidal_bed()[0] np.testing.assert_almost_equal(tb._w0_m, tb.widths_m) np.testing.assert_almost_equal(tb.section, tb.widths_m * 0) np.testing.assert_almost_equal(tb.area_km2, 0) tb.section = tb.section np.testing.assert_almost_equal(tb._w0_m, tb.widths_m) np.testing.assert_almost_equal(tb.section, tb.widths_m * 0) np.testing.assert_almost_equal(tb.area_km2, 0) h = 50. sec = (2 * tb._w0_m + tb._lambdas * h) * h / 2 tb.section = sec np.testing.assert_almost_equal(sec, tb.section) np.testing.assert_almost_equal(sec * 0 + h, tb.thick) np.testing.assert_almost_equal(tb._w0_m + tb._lambdas * h, tb.widths_m) akm = (tb._w0_m + tb._lambdas * h) * len(sec) * 100 np.testing.assert_almost_equal(tb.area_m2, akm) models = [KarthausModel, FluxBasedModel] flss = [dummy_constant_bed(), dummy_trapezoidal_bed()] lens = [] surface_h = [] volume = [] widths = [] yrs = np.arange(1, 700, 2) for model, fls in zip(models, flss): mb = LinearMassBalance(2800.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=14 * SEC_IN_DAY) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) length[i] = fls[-1].length_m vol[i] = fls[-1].volume_km3 lens.append(length) volume.append(vol) widths.append(fls[-1].widths_m.copy()) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(volume[0][-1], volume[1][-1], atol=1e-2) if do_plot: # pragma: no cover plt.plot(lens[0], 'r') plt.plot(lens[1], 'b') plt.show() plt.plot(volume[0], 'r') plt.plot(volume[1], 'b') plt.show() plt.plot(fls[-1].bed_h, 'k') plt.plot(surface_h[0], 'r') plt.plot(surface_h[1], 'b') plt.show() plt.plot(widths[0], 'r') plt.plot(widths[1], 'b') plt.show()
def test_trapezoidal_bed(self): tb = dummy_trapezoidal_bed()[0] np.testing.assert_almost_equal(tb._w0_m, tb.widths_m) np.testing.assert_almost_equal(tb.section, tb. widths_m * 0) np.testing.assert_almost_equal(tb.area_km2, 0) tb.section = tb.section np.testing.assert_almost_equal(tb._w0_m, tb.widths_m) np.testing.assert_almost_equal(tb.section, tb. widths_m * 0) np.testing.assert_almost_equal(tb.area_km2, 0) h = 50. sec = (2 * tb._w0_m + tb._lambdas * h) * h / 2 tb.section = sec np.testing.assert_almost_equal(sec, tb.section) np.testing.assert_almost_equal(sec * 0 + h, tb.thick) np.testing.assert_almost_equal(tb._w0_m + tb._lambdas * h, tb.widths_m) akm = (tb._w0_m + tb._lambdas * h) * len(sec) * 100 np.testing.assert_almost_equal(tb.area_m2, akm) models = [KarthausModel, FluxBasedModel] flss = [dummy_constant_bed(), dummy_trapezoidal_bed()] lens = [] surface_h = [] volume = [] widths = [] yrs = np.arange(1, 700, 2) for model, fls in zip(models, flss): mb = LinearMassBalance(2800.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=14 * SEC_IN_DAY) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) length[i] = fls[-1].length_m vol[i] = fls[-1].volume_km3 lens.append(length) volume.append(vol) widths.append(fls[-1].widths_m.copy()) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(volume[0][-1], volume[1][-1], atol=1e-2) if do_plot: # pragma: no cover plt.plot(lens[0], 'r') plt.plot(lens[1], 'b') plt.show() plt.plot(volume[0], 'r') plt.plot(volume[1], 'b') plt.show() plt.plot(fls[-1].bed_h, 'k') plt.plot(surface_h[0], 'r') plt.plot(surface_h[1], 'b') plt.show() plt.plot(widths[0], 'r') plt.plot(widths[1], 'b') plt.show()