def test_mass_conservation(self): mb = LinearMassBalance(2600.) fls = dummy_constant_bed() model = MassConservationChecker(fls, mb_model=mb, y0=0., glen_a=self.glen_a) model.run_until(200) assert_allclose(model.total_mass, model.volume_m3, rtol=1e-3) fls = dummy_noisy_bed() model = MassConservationChecker(fls, mb_model=mb, y0=0., glen_a=self.glen_a) model.run_until(200) assert_allclose(model.total_mass, model.volume_m3, rtol=1e-3) fls = dummy_width_bed_tributary() model = MassConservationChecker(fls, mb_model=mb, y0=0., glen_a=self.glen_a) model.run_until(200) assert_allclose(model.total_mass, model.volume_m3, rtol=1e-3) # Calving! fls = dummy_constant_bed(hmax=1000., hmin=0., nx=100) mb = LinearMassBalance(450.) model = MassConservationChecker(fls, mb_model=mb, y0=0., glen_a=self.glen_a, is_tidewater=True) model.run_until(500) tot_vol = model.volume_m3 + model.calving_m3_since_y0 assert_allclose(model.total_mass, tot_vol, rtol=2e-2)
def test_tributary(self): models = [KarthausModel, FluxBasedModel] steps = [15 * SEC_IN_DAY, None] flss = [dummy_width_bed(), dummy_width_bed_tributary()] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 500, 2) for model, step, fls in zip(models, steps, flss): mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=step) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) assert model.yr == y length[i] = fls[-1].length_m vol[i] = np.sum([f.volume_km3 for f in fls]) lens.append(length) volume.append(vol) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(lens[0][-1], lens[1][-1], atol=101) np.testing.assert_allclose(volume[0][-1], volume[1][-1], atol=2e-2) np.testing.assert_allclose(utils.rmsd(lens[0], lens[1]), 0., atol=70) np.testing.assert_allclose(utils.rmsd(volume[0], volume[1]), 0., atol=6e-3) np.testing.assert_allclose(utils.rmsd(surface_h[0], surface_h[1]), 0., atol=5) 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()
def test_flux_gate_with_trib(self): mb = ScalarMassBalance() model = FluxBasedModel(dummy_width_bed_tributary(), mb_model=mb, flux_gate_thickness=150, flux_gate_build_up=50) model.run_until(1000) assert_allclose(model.volume_m3, model.flux_gate_m3_since_y0) if do_plot: # pragma: no cover plt.plot(model.fls[-1].bed_h, 'k') plt.plot(model.fls[-1].surface_h, 'b') plt.show()
def test_tributary(self): models = [KarthausModel, FluxBasedModel] steps = [15 * SEC_IN_DAY, None] flss = [dummy_width_bed(), dummy_width_bed_tributary()] lens = [] surface_h = [] volume = [] yrs = np.arange(1, 500, 2) for model, step, fls in zip(models, steps, flss): mb = LinearMassBalance(2600.) model = model(fls, mb_model=mb, fs=self.fs_old, glen_a=self.aglen_old, fixed_dt=step) length = yrs * 0. vol = yrs * 0. for i, y in enumerate(yrs): model.run_until(y) length[i] = fls[-1].length_m vol[i] = np.sum([f.volume_km3 for f in fls]) lens.append(length) volume.append(vol) surface_h.append(fls[-1].surface_h.copy()) np.testing.assert_allclose(lens[0][-1], lens[1][-1], atol=101) np.testing.assert_allclose(volume[0][-1], volume[1][-1], atol=2e-2) np.testing.assert_allclose(utils.rmsd(lens[0], lens[1]), 0., atol=70) np.testing.assert_allclose(utils.rmsd(volume[0], volume[1]), 0., atol=6e-3) np.testing.assert_allclose(utils.rmsd(surface_h[0], surface_h[1]), 0., atol=5) 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()
def test_staggered_diagnostics(self): mb = LinearMassBalance(2600.) fls = dummy_constant_bed() model = FluxBasedModel(fls, mb_model=mb, y0=0.) model.run_until(700) assert_allclose(mb.get_specific_mb(fls=fls), 0, atol=10) # Check the flux just for fun fl = model.flux_stag[0] assert fl[0] == 0 # Now check the diags df = model.get_diagnostics() fl = model.fls[0] df['my_flux'] = np.cumsum(mb.get_annual_mb(fl.surface_h) * fl.widths_m * fl.dx_meter * cfg.SEC_IN_YEAR).clip(0) df = df.loc[df['ice_thick'] > 0] # Also convert ours df['ice_flux'] *= cfg.SEC_IN_YEAR df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR assert_allclose(np.abs(df['ice_flux'] - df['my_flux']), 0, atol=35e3) assert df['ice_velocity'].max() > 25 assert df['tributary_flux'].max() == 0 fls = dummy_width_bed_tributary() model = FluxBasedModel(fls, mb_model=mb, y0=0.) model.run_until(500) df = model.get_diagnostics() df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR df = df.loc[df['ice_thick'] > 0] assert df['ice_velocity'].max() > 50 assert df['tributary_flux'].max() > 30e4 df = model.get_diagnostics(fl_id=0) df = df.loc[df['ice_thick'] > 0] df['ice_velocity'] *= cfg.SEC_IN_YEAR df['tributary_flux'] *= cfg.SEC_IN_YEAR assert df['ice_velocity'].max() > 10 assert df['tributary_flux'].max() == 0