|
11 | 11 | "cell_type": "markdown", |
12 | 12 | "metadata": {}, |
13 | 13 | "source": [ |
14 | | - "<div class=\"alert alert-info\">\n", |
15 | | - " <b>\n", |
16 | | - " The calving parameterization in OGGM has been developped for versions of OGGM before 1.6 (mostly: 1.5.3). The v1.6 series brought several changes in the mass balance calibration which made a lot of the calibration code obsolete and in need of updates. As of today (August 2024), calving dynamics are implemented in the dynamical model and they \"work\", as illustrated below. However, there is still quite some work to make calving (including calibration) fully operational for large scale runs.</b><br>See <a href=\"https://github.com/OGGM/oggm/issues/1733\">this github issue</a> for a longer discussion.\n", |
17 | | - "</div>" |
| 14 | + "```{note}\n", |
| 15 | + "The calving parameterization in OGGM has been developped for versions of OGGM before 1.6 (mostly: 1.5.3). \n", |
| 16 | + "\n", |
| 17 | + "The v1.6 series brought several changes in the mass balance calibration which made a lot of the calibration code obsolete and in need of updates. As of today (April 2026), calving dynamics are implemented in the dynamical model and they work, as illustrated below. A [recent PR](https://github.com/OGGM/oggm/pull/1858) by Beatriz Recinos further improved the model by adding the calving parameterization to the default OGGM solver, which is what we use below.\n", |
| 18 | + "\n", |
| 19 | + "However, there is quite some work to make calving (including calibration) fully operational for large scale runs. OGGM's calving is used operationally by PyGEM - which means it can be done!\n", |
| 20 | + "\n", |
| 21 | + "See [this github issue](https://github.com/OGGM/oggm/issues/1733) for a longer discussion.\n", |
| 22 | + "```" |
18 | 23 | ] |
19 | 24 | }, |
20 | 25 | { |
|
27 | 32 | "\n", |
28 | 33 | "With $H_f$, $d$ and $w$ the ice thickness, the water depth and the glacier width at the calving front, $F_{calving}$ the calving flux in units m$^3$ yr$^{-1}$ and $k$ a scaling parameter that needs to be calibrated (units: yr$^{-1}$). Another way to see at this equation is to note that the frontal calving rate $\\frac{F_{Calving}}{H_f w}$ (m yr$^{-1}$) is simply the water depth scaled by the $k$ parameter.\n", |
29 | 34 | "\n", |
30 | | - "[Malles et al., 2023](https://doi.org/10.1017/jog.2023.19) introduces some changes to the physics and numerics of calving. We illustrate both models below." |
| 35 | + "[Malles et al., 2023](https://doi.org/10.1017/jog.2023.19) introduces some changes to the physics and numerics of calving. We illustrate its use at the end of this notebook." |
31 | 36 | ] |
32 | 37 | }, |
33 | 38 | { |
|
36 | 41 | "metadata": {}, |
37 | 42 | "outputs": [], |
38 | 43 | "source": [ |
39 | | - "import matplotlib.pyplot as plt\n", |
40 | 44 | "import numpy as np\n", |
| 45 | + "import pandas as pd\n", |
41 | 46 | "import xarray as xr\n", |
42 | 47 | "import time, os\n", |
43 | | - "\n", |
| 48 | + "import matplotlib.pyplot as plt\n", |
44 | 49 | "from oggm.core.massbalance import ScalarMassBalance\n", |
45 | 50 | "from oggm import cfg, utils, workflow, tasks, graphics\n", |
46 | 51 | "from oggm.tests.funcs import bu_tidewater_bed\n", |
47 | | - "from oggm.core.flowline import FluxBasedModel\n", |
| 52 | + "from oggm.core.flowline import TrapezoidalBedFlowline, SemiImplicitModel\n", |
48 | 53 | "\n", |
49 | 54 | "cfg.initialize(logging_level='WARNING')\n", |
50 | | - "cfg.PARAMS['cfl_number'] = 0.01 # less numerical instabilities\n", |
51 | | - "cfg.PARAMS['use_multiprocessing'] = False" |
| 55 | + "cfg.PARAMS['cfl_number'] = 0.01\n", |
| 56 | + "cfg.PARAMS['use_multiprocessing'] = True\n", |
| 57 | + "cfg.PARAMS['mp_processes'] = 4\n", |
| 58 | + "cfg.PARAMS['tidewater_type'] = 4\n", |
| 59 | + "cfg.PARAMS['clip_tidewater_border'] = True\n", |
| 60 | + "cfg.PARAMS['use_kcalving_for_inversion'] = True\n", |
| 61 | + "cfg.PARAMS['use_kcalving_for_run'] = True" |
52 | 62 | ] |
53 | 63 | }, |
54 | 64 | { |
|
91 | 101 | "metadata": {}, |
92 | 102 | "outputs": [], |
93 | 103 | "source": [ |
94 | | - "bu_fl = bu_tidewater_bed()[0]\n", |
| 104 | + "bu_fl = bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0)[0]\n", |
95 | 105 | "\n", |
96 | 106 | "xc = bu_fl.dis_on_line * bu_fl.dx_meter / 1000\n", |
97 | 107 | "f, ax = plt.subplots(1, 1, figsize=(12, 5))\n", |
|
118 | 128 | "to_plot = None\n", |
119 | 129 | "keys = []\n", |
120 | 130 | "for flux_gate in [0.06, 0.10, 0.16]:\n", |
121 | | - " model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n", |
122 | | - " is_tidewater=True, \n", |
123 | | - " flux_gate=flux_gate, # default is 0\n", |
124 | | - " calving_k=0.2, # default is 2.4\n", |
125 | | - " do_kcalving=True\n", |
126 | | - " )\n", |
127 | | - " # long enough to reach approx. equilibrium \n", |
| 131 | + " model = SemiImplicitModel(\n", |
| 132 | + " bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0), # use your trapezoid builder\n", |
| 133 | + " mb_model=mb_model,\n", |
| 134 | + " flux_gate=flux_gate,\n", |
| 135 | + " do_calving=True,\n", |
| 136 | + " calving_k=0.2,\n", |
| 137 | + " water_level=0.0,\n", |
| 138 | + " cfl_number=0.5, # optional, if you want similar strictness\n", |
| 139 | + " )\n", |
| 140 | + " # long enough to reach approx. equilibrium\n", |
128 | 141 | " ds = model.run_until_and_store(6000)\n", |
129 | 142 | " df_diag = model.get_diagnostics()\n", |
130 | | - " \n", |
| 143 | + "\n", |
131 | 144 | " if to_plot is None:\n", |
132 | 145 | " to_plot = df_diag\n", |
133 | | - " \n", |
| 146 | + "\n", |
134 | 147 | " key = 'Flux gate={:.02f}. Calving rate: {:.0f} m yr-1'.format(flux_gate, model.calving_rate_myr)\n", |
135 | 148 | " to_plot[key] = df_diag['surface_h']\n", |
136 | 149 | " keys.append(key)\n", |
137 | | - " \n", |
| 150 | + "\n", |
138 | 151 | " # Plot of volume\n", |
139 | | - " (ds.volume_m3 * 1e-9).plot(label=key)\n", |
| 152 | + " (ds.volume_m3 * 1e-9).plot(label=key);\n", |
140 | 153 | "plt.legend(); plt.ylabel('Volume [km$^{3}$]');\n", |
141 | 154 | "to_plot.index = xc" |
142 | 155 | ] |
|
184 | 197 | "to_plot = None\n", |
185 | 198 | "keys = []\n", |
186 | 199 | "for limiter in [True, False]:\n", |
187 | | - " model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n", |
188 | | - " is_tidewater=True, \n", |
| 200 | + " model = SemiImplicitModel(bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0),\n", |
| 201 | + " mb_model=mb_model,\n", |
| 202 | + " water_level=0.0,\n", |
| 203 | + " is_tidewater=True,\n", |
189 | 204 | " calving_use_limiter=limiter, # default is True\n", |
190 | 205 | " flux_gate=0.06, # default is 0\n", |
191 | 206 | " calving_k=0.2, # default is 2.4\n", |
192 | | - " do_kcalving=True\n", |
| 207 | + " do_calving=True\n", |
193 | 208 | " )\n", |
194 | | - " # long enough to reach approx. equilibrium \n", |
| 209 | + " # long enough to reach approx. equilibrium\n", |
195 | 210 | " ds = model.run_until_and_store(7000)\n", |
196 | 211 | " df_diag = model.get_diagnostics()\n", |
197 | | - " \n", |
| 212 | + "\n", |
198 | 213 | " if to_plot is None:\n", |
199 | 214 | " to_plot = df_diag\n", |
200 | | - " \n", |
201 | | - " key = 'Flux limiter={}. Calving rate: {:.0f} m yr-1'.format(limiter, model.calving_rate_myr)\n", |
202 | | - " to_plot[key] = df_diag['surface_h']\n", |
| 215 | + "\n", |
| 216 | + " key = f\"Flux limiter={limiter}. Calving rate: {model.calving_rate_myr:.0f} m yr-1\"\n", |
| 217 | + " to_plot[key] = df_diag[\"surface_h\"]\n", |
203 | 218 | " keys.append(key)\n", |
204 | | - " \n", |
205 | | - " # Plot of volume\n", |
| 219 | + "\n", |
206 | 220 | " (ds.volume_m3 * 1e-9).plot(label=key)\n", |
| 221 | + "\n", |
207 | 222 | "plt.legend(); plt.ylabel('Volume [km$^{3}$]');\n", |
208 | 223 | "to_plot.index = xc" |
209 | 224 | ] |
|
270 | 285 | "metadata": {}, |
271 | 286 | "outputs": [], |
272 | 287 | "source": [ |
273 | | - "model = FluxBasedModel(bu_tidewater_bed(), mb_model=mb_model,\n", |
274 | | - " is_tidewater=True, \n", |
275 | | - " glen_a=cfg.PARAMS['glen_a']*3, # make the glacier flow faster\n", |
276 | | - " flux_gate=flux_gate, # default is 0\n", |
277 | | - " calving_k=1, # default is 2.4\n", |
278 | | - " do_kcalving=True\n", |
279 | | - " )\n", |
| 288 | + "model = SemiImplicitModel(bu_tidewater_bed(bed_shape='trapezoidal', lambdas=0.0),\n", |
| 289 | + " mb_model=mb_model,\n", |
| 290 | + " is_tidewater=True,\n", |
| 291 | + " glen_a=cfg.PARAMS['glen_a']*3, # make the glacier flow faster\n", |
| 292 | + " flux_gate=flux_gate, # default is 0\n", |
| 293 | + " calving_k=1, # default is 2.4\n", |
| 294 | + " do_calving=True\n", |
| 295 | + " )\n", |
280 | 296 | "t0 = time.time()\n", |
281 | 297 | "ds = model.run_until_and_store(len(flux)-1)\n", |
282 | 298 | "print('Done! Time needed: {}s'.format(int(time.time()-t0)))" |
|
362 | 378 | "- backpressure from the water is implemented, making physics more realistic and removing the need for the flux limiter\n", |
363 | 379 | "- sliding is increased when below water\n", |
364 | 380 | "- some other logics and checks that where needed to make calving more realistic in edge cases (this is a large part of the code)\n", |
| 381 | + "- it's only implemented for the `FluxBasedModel`, which is much less stable and slowier than the SemiImplicitModel used above\n", |
365 | 382 | "\n", |
366 | 383 | "Otherwise, it works pretty much like the existing one:" |
367 | 384 | ] |
|
382 | 399 | "outputs": [], |
383 | 400 | "source": [ |
384 | 401 | "model = calving_jan.CalvingFluxBasedModelJan(bu_tidewater_bed(), mb_model=mb_model,\n", |
385 | | - " is_tidewater=True, \n", |
| 402 | + " is_tidewater=True,\n", |
386 | 403 | " glen_a=cfg.PARAMS['glen_a']*3, # make the glacier flow faster\n", |
387 | 404 | " flux_gate=flux_gate, # default is 0\n", |
388 | 405 | " calving_k=0.6, # default is 2.4 - Note the different value for calving here to obtain similar results as above\n", |
|
397 | 414 | "cell_type": "markdown", |
398 | 415 | "metadata": {}, |
399 | 416 | "source": [ |
400 | | - "First observation is that its slower by a factor at least two. Let's have a look at the results:" |
| 417 | + "**First observation is that its at least ~5× slower**. Let's have a look at the results:" |
401 | 418 | ] |
402 | 419 | }, |
403 | 420 | { |
|
457 | 474 | "metadata": {}, |
458 | 475 | "outputs": [], |
459 | 476 | "source": [ |
460 | | - "ds.length_m.plot()\n", |
461 | | - "ds_new.length_m.plot();" |
| 477 | + "ds.length_m.plot(label=\"old\")\n", |
| 478 | + "ds_new.length_m.plot(label=\"new\")\n", |
| 479 | + "plt.legend();" |
462 | 480 | ] |
463 | 481 | }, |
464 | 482 | { |
|
491 | 509 | "name": "python", |
492 | 510 | "nbconvert_exporter": "python", |
493 | 511 | "pygments_lexer": "ipython3", |
494 | | - "version": "3.12.4" |
| 512 | + "version": "3.14.0" |
495 | 513 | }, |
496 | 514 | "toc": { |
497 | 515 | "base_numbering": 1, |
|
0 commit comments