-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyelmox_ismip6.f90
2625 lines (1959 loc) · 131 KB
/
yelmox_ismip6.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program yelmox_ismip6
use nml
use ncio
use timer
use timeout
use yelmo
use ice_optimization
! External libraries
use geothermal
use ismip6
use fastisostasy ! also reexports barysealevel
use marine_shelf
use sediments
use smbpal
use snapclim
use hyster
implicit none
character(len=256) :: outfldr, file1D, file2D, file2D_small
character(len=256) :: file1D_ismip6, file2D_ismip6
character(len=256) :: file_isos, file_bsl
character(len=256) :: domain, grid_name
character(len=512) :: path_par
character(len=512) :: path_tf_corr
character(len=512) :: ismip6_path_par
integer :: n, m
real(wp) :: time, time_bp
real(wp) :: time_elapsed
real(wp) :: time_wt
real(sp) :: convert_km3_Gt
type(yelmo_class) :: yelmo1
type(bsl_class) :: bsl
type(snapclim_class) :: snp1
type(marshelf_class) :: mshlf1
type(smbpal_class) :: smbpal1
type(sediments_class) :: sed1
type(geothermal_class) :: gthrm1
type(isos_class) :: isos1
type(ismip6_forcing_class) :: ismp1
type(hyster_class) :: hyst1
type(timeout_class) :: tm_1D, tm_2D, tm_2Dsm
! Model timing
type(timer_class) :: tmr
type(timer_class) :: tmrs
character(len=512) :: tmr_file
type reg_def_class
character(len=56) :: name
character(len=512) :: fnm
logical, allocatable :: mask(:,:)
logical :: write
end type
type(reg_def_class) :: reg1
type(reg_def_class) :: reg2
type(reg_def_class) :: reg3
character(len=512) :: regions_mask_fnm
real(wp), allocatable :: regions_mask(:,:)
type ctrl_params
character(len=56) :: run_step
real(wp) :: time_init
real(wp) :: time_end
real(wp) :: time_equil ! Only for spinup
real(wp) :: time_const ! Only for spinup
real(wp) :: dtt
logical :: with_ice_sheet
character(len=56) :: equil_method
character(len=56) :: abumip_scenario
real(wp) :: abumip_bmb
character(len=56) :: hyst_scenario
real(wp) :: hyst_f_to
real(wp) :: hyst_f_ta
character(len=512) :: ismip6_par_file
character(len=56) :: ismip6_expname
logical :: ismip6_write_formatted
real(wp) :: ismip6_dt_formatted
real(wp) :: isos_tau_1
real(wp) :: isos_tau_2
real(wp) :: isos_sigma
end type
type(ctrl_params) :: ctl
type(ice_opt_params) :: opt
type(ismip6_experiment_class) :: ismip6exp
! Determine the parameter file from the command line
call yelmo_load_command_line_args(path_par)
! Control parameters
call nml_read(path_par,"ctrl","run_step", ctl%run_step)
! ISMIP6 parameters
call nml_read(path_par,"ismip6","par_file", ctl%ismip6_par_file)
call nml_read(path_par,"ismip6","expname", ctl%ismip6_expname)
call nml_read(path_par,"ismip6","write_formatted", ctl%ismip6_write_formatted)
call nml_read(path_par,"ismip6","dt_formatted", ctl%ismip6_dt_formatted)
if (index(ctl%ismip6_par_file,"ant") .gt. 0) then
! Running Antarctica domain, load Antarctica specific parameters
call ismip6_experiment_def(ismip6exp,ctl%ismip6_expname,ctl%ismip6_par_file,"UCM","YELMO")
end if
! Read run_step specific control parameters
call nml_read(path_par,trim(ctl%run_step),"time_init", ctl%time_init) ! [yr] Starting time
call nml_read(path_par,trim(ctl%run_step),"time_end", ctl%time_end) ! [yr] Ending time
call nml_read(path_par,trim(ctl%run_step),"dtt", ctl%dtt) ! [yr] Main loop time step
call nml_read(path_par,trim(ctl%run_step),"time_equil", ctl%time_equil) ! [yr] Years to equilibrate first
call nml_read(path_par,trim(ctl%run_step),"time_const", ctl%time_const)
call nml_read(path_par,trim(ctl%run_step),"with_ice_sheet",ctl%with_ice_sheet) ! Active ice sheet?
call nml_read(path_par,trim(ctl%run_step),"equil_method", ctl%equil_method) ! What method should be used for spin-up?
if (trim(ctl%equil_method) .eq. "opt") then
! Load optimization parameters
call optimize_par_load(opt,path_par,"opt")
end if
! Check if special scenario is being run, make parameter adjustments
select case(trim(ctl%run_step))
case("abumip")
call nml_read(path_par,"abumip","scenario", ctl%abumip_scenario)
call nml_read(path_par,"abumip","bmb", ctl%abumip_bmb)
case("hysteresis")
call nml_read(path_par,"hysteresis","scenario", ctl%hyst_scenario)
call nml_read(path_par,"hysteresis","f_to", ctl%hyst_f_to)
call nml_read(path_par,"hysteresis","f_ta", ctl%hyst_f_ta)
end select
! Get output times
call timeout_init(tm_1D, path_par,"tm_1D", "small", ctl%time_init,ctl%time_end)
call timeout_init(tm_2D, path_par,"tm_2D", "heavy", ctl%time_init,ctl%time_end)
call timeout_init(tm_2Dsm,path_par,"tm_2Dsm","medium", ctl%time_init,ctl%time_end)
! Assume program is running from the output folder
outfldr = "./"
! Define input and output locations
file1D = trim(outfldr)//"yelmo1D.nc"
file2D = trim(outfldr)//"yelmo2D.nc"
file2D_small = trim(outfldr)//"yelmo2Dsm.nc"
file_isos = trim(outfldr)//"fastisostasy.nc"
file_bsl = trim(outfldr)//"bsl.nc"
file1D_ismip6 = trim(outfldr)//"yelmo1D_ismip6.nc"
file2D_ismip6 = trim(outfldr)//"yelmo2D_ismip6.nc"
tmr_file = trim(outfldr)//"timer_table.txt"
! Set initial model time
time = ctl%time_init
time_bp = time - 1950.0_wp
! =========================================================
! Print summary of run settings
write(*,*)
write(*,*) "run_step: ", trim(ctl%run_step)
write(*,*)
write(*,*) "time_init: ", ctl%time_init
write(*,*) "time_end: ", ctl%time_end
write(*,*) "dtt: ", ctl%dtt
write(*,*)
write(*,*) "ismip6_par_file: ", trim(ctl%ismip6_par_file)
write(*,*) "ismip6_expname: ", trim(ctl%ismip6_expname)
write(*,*) "ismip6_experiment: ", trim(ismip6exp%experiment)
select case(trim(ctl%run_step))
case("spinup")
write(*,*) "time_equil: ", ctl%time_equil
write(*,*) "time_const: ", ctl%time_const
time_bp = ctl%time_const - 1950.0_wp
case("transient")
write(*,*) "ismip6_shlf_collapse: ", ismip6exp%shlf_collapse
write(*,*) "ismip6_write_formatted: ", ctl%ismip6_write_formatted
write(*,*) "ismip6_file_suffix: ", trim(ismip6exp%file_suffix)
case("abumip")
write(*,*) "abumip_scenario: ", trim(ctl%abumip_scenario)
end select
write(*,*) "time = ", time
write(*,*) "time_bp = ", time_bp
write(*,*)
write(*,*) "with_ice_sheet: ", ctl%with_ice_sheet
write(*,*) "equil_method: ", trim(ctl%equil_method)
! Start timing
call timer_step(tmr,comp=-1)
! === Initialize ice sheet model =====
! Initialize data objects and load initial topography
call yelmo_init(yelmo1,filename=path_par,grid_def="file",time=time)
! Store domain and grid_name as shortcuts
domain = yelmo1%par%domain
grid_name = yelmo1%par%grid_name
! Ensure optimization fields are allocated and preassigned
allocate(opt%cf_min(yelmo1%grd%nx,yelmo1%grd%ny))
allocate(opt%cf_max(yelmo1%grd%nx,yelmo1%grd%ny))
opt%cf_min = opt%cf_min_par
opt%cf_max = yelmo1%dyn%par%till_cf_ref
! Define specific regions of interest =====================
select case(trim(domain))
case("Antarctica")
! Define base regions for whole domain first
regions_mask_fnm = "ice_data/Antarctica/"//trim(yelmo1%par%grid_name)//&
"/"//trim(yelmo1%par%grid_name)//"_BASINS-nasa.nc"
allocate(regions_mask(yelmo1%grd%nx,yelmo1%grd%ny))
! Load mask from file
call nc_read(regions_mask_fnm,"mask_regions",regions_mask)
! ajr (2023-03-13): files are now consistent, this fix should not be needed!
! ! ajr: fix mask inconsistency at 16km resolution
! ! Note: the files themselves should be fixed and made consistent!
! if (trim(yelmo1%par%grid_name) .eq. "ANT-16KM") then
! where(abs(regions_mask - 4.0) .lt. 1e-3) regions_mask = 1.0
! where(abs(regions_mask - 5.0) .lt. 1e-3) regions_mask = 2.0
! end if
! APIS region (region=3.0 in regions map)
reg1%write = .TRUE.
reg1%name = "APIS"
reg1%fnm = trim(outfldr)//"yelmo1D_"//trim(reg1%name)//".nc"
allocate(reg1%mask(yelmo1%grd%nx,yelmo1%grd%ny))
reg1%mask = .FALSE.
where(abs(regions_mask - 3.0) .lt. 1e-3) reg1%mask = .TRUE.
! WAIS region (region=1.0 in regions map)
reg2%write = .TRUE.
reg2%name = "WAIS"
reg2%fnm = trim(outfldr)//"yelmo1D_"//trim(reg2%name)//".nc"
allocate(reg2%mask(yelmo1%grd%nx,yelmo1%grd%ny))
reg2%mask = .FALSE.
where(abs(regions_mask - 1.0) .lt. 1e-3) reg2%mask = .TRUE.
! EAIS region (region=2.0 in regions map)
reg3%write = .TRUE.
reg3%name = "EAIS"
reg3%fnm = trim(outfldr)//"yelmo1D_"//trim(reg3%name)//".nc"
allocate(reg3%mask(yelmo1%grd%nx,yelmo1%grd%ny))
reg3%mask = .FALSE.
where(abs(regions_mask - 2.0) .lt. 1e-3) reg3%mask = .TRUE.
! Adjust optimization cf_max field specifically for the WAIS and Amery
!where(abs(yelmo1%bnd%basins - 14.0) .lt. 1e-3) opt%cf_max = min(opt%cf_ref_wais,opt%cf_max)
!where(abs(yelmo1%bnd%basins - 6.0) .lt. 1e-3) opt%cf_max = min(opt%cf_ref_wais,opt%cf_max)
! Note ajr (2023-03-13): this is no longer needed as long as ytill.cf_ref is set to 0.1 instead of 1.0.
! Also, it was not nice having cf_ref_wais inside of the opt object in ice_optimization.f90. This
! will be removed. If it is needed in the future, cf_ref_wais should be included in a parameter
! section loaded in this program directly.
case DEFAULT
reg1%write = .FALSE.
reg2%write = .FALSE.
reg3%write = .FALSE.
end select
! === Initialize external models (forcing for ice sheet) ======
! Initialize barysealevel model
call bsl_init(bsl, path_par, time_bp)
! Initialize fastisosaty
call isos_init(isos1, path_par, "isos", yelmo1%grd%nx, yelmo1%grd%ny, &
yelmo1%grd%dx, yelmo1%grd%dy)
! Initialize "climate" model (climate and ocean forcing)
call snapclim_init(snp1,path_par,domain,yelmo1%par%grid_name,yelmo1%grd%nx,yelmo1%grd%ny,yelmo1%bnd%basins)
! Initialize surface mass balance model (bnd%smb, bnd%T_srf)
call smbpal_init(smbpal1,path_par,x=yelmo1%grd%xc,y=yelmo1%grd%yc,lats=yelmo1%grd%lat)
! Initialize marine melt model (bnd%bmb_shlf)
call marshelf_init(mshlf1,path_par,"marine_shelf",yelmo1%grd%nx,yelmo1%grd%ny,domain,grid_name,yelmo1%bnd%regions,yelmo1%bnd%basins)
! Initialize variables inside of ismip6 object
ismip6_path_par = trim(outfldr)//"/"//trim(ctl%ismip6_par_file)
call ismip6_forcing_init(ismp1,ismip6_path_par,domain,grid_name,experiment=ismip6exp%experiment, &
shlf_collapse=ismip6exp%shlf_collapse)
! ===== tf_corr initialization ======
! Make sure that tf is prescribed externally
mshlf1%par%tf_method = 0
if (yelmo1%par%use_restart) then
! Load tf_corr field from file
call load_tf_corr_from_restart(mshlf1%now%tf_corr,yelmo1%par%restart, &
yelmo1%par%domain,yelmo1%par%grid_name)
else
! Initialize tf_corr to be equal to tf_corr_basin, and
! set tf_corr_basin to zero (all corrections will be contained in one field)
mshlf1%now%tf_corr = mshlf1%now%tf_corr_basin
mshlf1%now%tf_corr_basin = 0.0_wp
end if
! === Update external modules and pass variables to yelmo boundaries =======
! Sediments
call sediments_init(sed1,path_par,yelmo1%grd%nx,yelmo1%grd%ny,domain,grid_name)
yelmo1%bnd%H_sed = sed1%now%H
! Geothermal heat flow
call geothermal_init(gthrm1,path_par,yelmo1%grd%nx,yelmo1%grd%ny,domain,grid_name)
yelmo1%bnd%Q_geo = gthrm1%now%ghf
! Barystatic sea level
call bsl_update(bsl, year_bp=time_bp)
call bsl_write_init(bsl, file_bsl, time)
! Initialize the isostasy reference state using reference topography fields
call isos_init_ref(isos1, yelmo1%bnd%z_bed_ref, yelmo1%bnd%H_ice_ref)
call isos_init_state(isos1, yelmo1%bnd%z_bed, yelmo1%tpo%now%H_ice, time, bsl)
call isos_write_init_extended(isos1, file_isos, time)
yelmo1%bnd%z_bed = isos1%out%z_bed
yelmo1%bnd%z_sl = isos1%out%z_ss
! Update snapclim
call snapclim_update(snp1,z_srf=yelmo1%tpo%now%z_srf,time=time_bp,domain=domain,dx=yelmo1%grd%dx,basins=yelmo1%bnd%basins)
! Equilibrate snowpack for itm
if (trim(smbpal1%par%abl_method) .eq. "itm") then
call smbpal_update_monthly_equil(smbpal1,snp1%now%tas,snp1%now%pr, &
yelmo1%tpo%now%z_srf,yelmo1%tpo%now%H_ice,time_bp,time_equil=100.0)
end if
! Update forcing to present-day reference using ISMIP6 forcing
call calc_climate_ismip6(snp1,smbpal1,mshlf1,ismp1,yelmo1, &
time=ctl%time_const,time_bp=ctl%time_const-1950.0_wp)
yelmo1%bnd%smb = smbpal1%ann%smb*yelmo1%bnd%c%conv_we_ie*1e-3 ! [mm we/a] => [m ie/a]
yelmo1%bnd%T_srf = smbpal1%ann%tsrf
yelmo1%bnd%bmb_shlf = mshlf1%now%bmb_shlf
yelmo1%bnd%T_shlf = mshlf1%now%T_shlf
call yelmo_print_bound(yelmo1%bnd)
! Initialize state variables (dyn,therm,mat)
! (initialize temps with robin method with a cold base)
call yelmo_init_state(yelmo1,time=time,thrm_method="robin-cold")
! ================= RUN STEPS ===============================================
select case(trim(ctl%run_step))
case("spinup")
! Model can start from no spinup or equilibration (using restart file),
! here it is run under constant boundary conditions to spinup
! desired state.
write(*,*)
write(*,*) "Performing spinup."
write(*,*)
! ===== basal friction optimization ======
if (trim(ctl%equil_method) .eq. "opt") then
! Ensure that cb_ref will be optimized (till_method == set externally)
yelmo1%dyn%par%till_method = -1
! If not using restart...
if (.not. yelmo1%par%use_restart) then
if (opt%cf_init .gt. 0.0) then
! Prescribe cb_ref to initial guess
yelmo1%dyn%now%cb_ref = opt%cf_init
else
! Load cb_ref from calculated cb_tgt field
yelmo1%dyn%now%cb_ref = yelmo1%dyn%now%cb_tgt
end if
end if
end if
if (ctl%with_ice_sheet .and. .not. yelmo1%par%use_restart) then
! Run yelmo alone for one or a few years with constant boundary conditions
! to sort out inconsistencies from initialization.
call yelmo_update_equil(yelmo1,time,time_tot=1.0_wp,dt=1.0_wp,topo_fixed=.FALSE.)
end if
if (trim(ctl%equil_method) .eq. "opt") then
! Additional initialization option when running 'opt' spinup...
if (ctl%with_ice_sheet .and. ctl%time_equil .gt. 0.0) then
! Calculate thermodynamics with fixed ice sheet
call yelmo_update_equil(yelmo1,time,time_tot=ctl%time_equil,dt=ctl%dtt,topo_fixed=.TRUE.)
end if
end if
write(*,*) "Initialization complete."
! Initialize output files for checking progress
call yelmo_write_init(yelmo1,file2D,time_init=time,units="years")
call yelmo_write_reg_init(yelmo1,file1D,time_init=time,units="years",mask=yelmo1%bnd%ice_allowed)
call timer_step(tmr,comp=1,label="initialization")
call timer_step(tmrs,comp=-1)
! Next perform 'coupled' model simulations for desired time
do n = 0, ceiling((ctl%time_end-ctl%time_init)/ctl%dtt)
! Get current time
time = ctl%time_init + n*ctl%dtt
time_bp = time - 1950.0_wp
time_elapsed = time - ctl%time_init
!!ajr: only update optimized fields if ice sheet is running
if (ctl%with_ice_sheet) then
select case(trim(ctl%equil_method))
case("opt")
if (time_elapsed .le. opt%rel_time2) then
! Apply relaxation to the model
! Update model relaxation time scale and error scaling (in [m])
call optimize_set_transient_param(opt%rel_tau,time_elapsed,time1=opt%rel_time1, &
time2=opt%rel_time2,p1=opt%rel_tau1,p2=opt%rel_tau2,m=opt%rel_m)
! Set model tau, and set yelmo relaxation switch (4: gl line and grounding zone relaxing; 0: no relaxation)
yelmo1%tpo%par%topo_rel_tau = opt%rel_tau
yelmo1%tpo%par%topo_rel = 3
else
! Turn-off relaxation now
yelmo1%tpo%par%topo_rel = 0
end if
! === Optimization update step =========
if (opt%opt_cf .and. &
(time_elapsed .ge. opt%cf_time_init .and. time_elapsed .le. opt%cf_time_end) ) then
! Perform cf_ref optimization
! Update cb_ref based on error metric(s)
call optimize_cb_ref(yelmo1%dyn%now%cb_ref,yelmo1%tpo%now%H_ice, &
yelmo1%tpo%now%dHidt,yelmo1%bnd%z_bed,yelmo1%bnd%z_sl,yelmo1%dyn%now%ux_s,yelmo1%dyn%now%uy_s, &
yelmo1%dta%pd%H_ice,yelmo1%dta%pd%uxy_s,yelmo1%dta%pd%H_grnd, &
opt%cf_min,opt%cf_max,yelmo1%tpo%par%dx,opt%sigma_err,opt%sigma_vel,opt%tau_c,opt%H0, &
dt=ctl%dtt,fill_method=opt%fill_method,fill_dist=opt%sigma_err, &
cb_tgt=yelmo1%dyn%now%cb_tgt)
end if
if (opt%opt_tf .and. &
(time_elapsed .ge. opt%tf_time_init .and. time_elapsed .le. opt%tf_time_end) ) then
! Perform tf_corr optimization
call optimize_tf_corr(mshlf1%now%tf_corr,yelmo1%tpo%now%H_ice,yelmo1%tpo%now%H_grnd,yelmo1%tpo%now%dHidt, &
yelmo1%dta%pd%H_ice,yelmo1%dta%pd%H_grnd,opt%H_grnd_lim,opt%tau_m,opt%m_temp, &
opt%tf_min,opt%tf_max,yelmo1%tpo%par%dx,sigma=opt%tf_sigma,dt=ctl%dtt)
end if
case("relax")
! ===== relaxation spinup ==================
if (time_elapsed .lt. ctl%time_equil) then
! Turn on relaxation for now, to let thermodynamics equilibrate
! without changing the topography too much. Important when
! effective pressure = f(thermodynamics).
yelmo1%tpo%par%topo_rel = 3
yelmo1%tpo%par%topo_rel_tau = 50.0
write(*,*) "timelog, tau = ", yelmo1%tpo%par%topo_rel_tau
else if (time_elapsed .eq. ctl%time_equil) then
! Disable relaxation now...
yelmo1%tpo%par%topo_rel = 0
write(*,*) "timelog, relation off..."
end if
case DEFAULT ! == "none", etc
! Pass - do nothing
end select
end if
! ====================================================
call timer_step(tmrs,comp=0)
! == ISOSTASY and SEA LEVEL ===========================================
call bsl_update(bsl, time)
call isos_update(isos1, yelmo1%tpo%now%H_ice, time, bsl, dwdt_corr=yelmo1%bnd%dzbdt_corr)
yelmo1%bnd%z_bed = isos1%out%z_bed
yelmo1%bnd%z_sl = isos1%out%z_ss
call timer_step(tmrs,comp=1,time_mod=[time-ctl%dtt,time]*1e-3,label="isostasy")
! == ICE SHEET ===================================================
if (ctl%with_ice_sheet) call yelmo_update(yelmo1,time)
call timer_step(tmrs,comp=2,time_mod=[time-ctl%dtt,time]*1e-3,label="yelmo")
! == CLIMATE ===========================================================
! Update forcing to present-day reference, but
! adjusting to ice topography
call calc_climate_ismip6(snp1,smbpal1,mshlf1,ismp1,yelmo1, &
time=ctl%time_const,time_bp=ctl%time_const-1950.0_wp)
yelmo1%bnd%smb = smbpal1%ann%smb*yelmo1%bnd%c%conv_we_ie*1e-3 ! [mm we/a] => [m ie/a]
yelmo1%bnd%T_srf = smbpal1%ann%tsrf
yelmo1%bnd%bmb_shlf = mshlf1%now%bmb_shlf
yelmo1%bnd%T_shlf = mshlf1%now%T_shlf
call timer_step(tmrs,comp=3,time_mod=[time-ctl%dtt,time]*1e-3,label="climate")
! == MODEL OUTPUT ===================================
if (timeout_check(tm_2D,time)) then
call write_step_2D_combined(yelmo1,isos1,snp1,mshlf1,smbpal1,file2D,time)
end if
if (timeout_check(tm_1D,time)) then
call yelmo_write_reg_step(yelmo1,file1D,time=time)
end if
call timer_step(tmrs,comp=4,time_mod=[time-ctl%dtt,time]*1e-3,label="io")
if (mod(time_elapsed,10.0)==0) then
! Print timestep timing info and write log table
call timer_write_table(tmrs,[time,ctl%dtt]*1e-3,"m",tmr_file,init=time_elapsed .eq. 0.0)
end if
if (mod(time_elapsed,10.0)==0 .and. (.not. yelmo_log)) then
write(*,"(a,f14.4)") "yelmo:: time = ", time
end if
end do
write(*,*)
write(*,*) "spinup complete."
write(*,*)
! Write the restart snapshot for the end of the simulation
call yelmox_restart_write(bsl,isos1,yelmo1,time_bp)
case("transient")
! Here it is assumed that the model has gone through spinup
! and is ready for transient simulations
write(*,*)
write(*,*) "Performing transient."
write(*,*)
! Additionally make sure isostasy is updated every timestep
isos1%par%dt_prognostics = 1.0_wp
isos1%par%dt_diagnostics = 10.0_wp
! Get current time
time = ctl%time_init
time_bp = time - 1950.0_wp
! Initialize output files
call yelmo_write_init(yelmo1,file2D,time_init=time,units="years")
call yelmo_write_reg_init(yelmo1,file1D,time_init=time,units="years",mask=yelmo1%bnd%ice_allowed)
if (ctl%ismip6_write_formatted) then
! Initialize output files for ISMIP6
call yelmo_write_init(yelmo1,file2D_ismip6,time_init=time,units="years")
call yelmo_write_reg_init(yelmo1,file1D_ismip6,time_init=time,units="years",mask=yelmo1%bnd%ice_allowed)
end if
call timer_step(tmr,comp=1,label="initialization")
call timer_step(tmrs,comp=-1)
! Perform 'coupled' model simulations for desired time
do n = 0, ceiling((ctl%time_end-ctl%time_init)/ctl%dtt)
! Get current time
time = ctl%time_init + n*ctl%dtt
time_bp = time - 1950.0_wp
time_elapsed = time - ctl%time_init
if (ismip6exp%shlf_collapse) then
! Perform mask_shlf_collapse experiments
! Set H to zero where mask==1, then compute Yelmo.
if(time .ge. 2015) then
!where((yelmo1%tpo%now%f_grnd .eq. 0.0) .and. (ismp1%mask_shlf%var(:,:,1,1) .eq. 1.0)) yelmo1%tpo%now%H_ice = 0.0
where((yelmo1%tpo%now%f_grnd .eq. 0.0) .and. (ismp1%mask_shlf%var(:,:,1,1) .eq. 1.0)) yelmo1%bnd%ice_allowed = .FALSE.
end if
end if
call timer_step(tmrs,comp=0)
! == ISOSTASY and SEA LEVEL ===========================================
call bsl_update(bsl, time_bp)
call isos_update(isos1, yelmo1%tpo%now%H_ice, time, bsl, dwdt_corr=yelmo1%bnd%dzbdt_corr)
yelmo1%bnd%z_bed = isos1%out%z_bed
yelmo1%bnd%z_sl = isos1%out%z_ss
call timer_step(tmrs,comp=1,time_mod=[time-ctl%dtt,time]*1e-3,label="isostasy")
! == ICE SHEET ===================================================
if (ctl%with_ice_sheet) call yelmo_update(yelmo1,time)
if (ismip6exp%shlf_collapse) then
! Clean up icebergs for mask_shlf_collapse experiments
call calc_iceberg_island(ismp1%iceberg_mask,yelmo1%tpo%now%f_grnd,yelmo1%tpo%now%H_ice)
where(ismp1%iceberg_mask .eq. 1.0) yelmo1%tpo%now%H_ice = 0.0
end if
call timer_step(tmrs,comp=2,time_mod=[time-ctl%dtt,time]*1e-3,label="yelmo")
! == CLIMATE and OCEAN ==========================================
! Get ISMIP6 climate and ocean forcing
call calc_climate_ismip6(snp1,smbpal1,mshlf1,ismp1,yelmo1,time,time_bp)
yelmo1%bnd%smb = smbpal1%ann%smb*yelmo1%bnd%c%conv_we_ie*1e-3 ! [mm we/a] => [m ie/a]
yelmo1%bnd%T_srf = smbpal1%ann%tsrf
yelmo1%bnd%bmb_shlf = mshlf1%now%bmb_shlf
yelmo1%bnd%T_shlf = mshlf1%now%T_shlf
call timer_step(tmrs,comp=3,time_mod=[time-ctl%dtt,time]*1e-3,label="climate")
! == MODEL OUTPUT ===================================
if (timeout_check(tm_2D,time)) then
call write_step_2D_combined(yelmo1,isos1,snp1,mshlf1,smbpal1,file2D,time)
end if
if (timeout_check(tm_1D,time)) then
call yelmo_write_reg_step(yelmo1,file1D,time=time)
end if
! ISMIP6 output if desired:
if (ctl%ismip6_write_formatted) then
if (mod(nint(time_elapsed*100),nint(ctl%ismip6_dt_formatted*100))==0) then
call write_step_2D_ismip6(yelmo1,file2D_ismip6,time)
call write_1D_ismip6(yelmo1,file1D_ismip6,time)
end if
end if
call timer_step(tmrs,comp=4,time_mod=[time-ctl%dtt,time]*1e-3,label="io")
if (mod(time_elapsed,10.0)==0) then
! Print timestep timing info and write log table
call timer_write_table(tmrs,[time,ctl%dtt]*1e-3,"m",tmr_file,init=time_elapsed .eq. 0.0)
end if
if (mod(time_elapsed,10.0)==0 .and. (.not. yelmo_log)) then
write(*,"(a,f14.4)") "yelmo:: time = ", time
end if
end do
write(*,*)
write(*,*) "Transient complete."
write(*,*)
! Write the restart snapshot for the end of the simulation
call yelmox_restart_write(bsl,isos1,yelmo1,time)
case("abumip")
! Here it is assumed that the model has gone through spinup
! and is ready for transient simulations
write(*,*)
write(*,*) "Performing transient. [abumip]"
write(*,*)
! Additionally make sure isostasy is updated every timestep
isos1%par%dt_prognostics = 1.0_wp
isos1%par%dt_diagnostics = 10.0_wp
! Get current time
time = ctl%time_init
time_bp = time - 1950.0_wp
! Initialize output files
call yelmo_write_init(yelmo1,file2D,time_init=time,units="years")
call yelmo_write_reg_init(yelmo1,file1D,time_init=time,units="years",mask=yelmo1%bnd%ice_allowed)
call timer_step(tmr,comp=1,label="initialization")
call timer_step(tmrs,comp=-1)
! Perform 'coupled' model simulations for desired time
do n = 0, ceiling((ctl%time_end-ctl%time_init)/ctl%dtt)
! Get current time
time = ctl%time_init + n*ctl%dtt
time_bp = time - 1950.0_wp
time_elapsed = time - ctl%time_init
! == ABUMIP =========================================================
! Make parameter changes relevant to abumip
select case(trim(ctl%abumip_scenario))
case("abuc")
! Do nothing - control experiment
case("abuk")
! Ensure ice shelves are killed
yelmo1%tpo%par%calv_flt_method = "kill"
case("abum")
! Apply 400 m/yr melt rate on shelves
yelmo1%bnd%bmb_shlf = ctl%abumip_bmb ! [m/yr]
case DEFAULT
write(io_unit_err,*) ""
write(io_unit_err,*) "yelmox_ismip6:: error: abumip scenario not recognized."
write(io_unit_err,*) "abumip_scenario: ", trim(ctl%abumip_scenario)
stop 1
end select
call timer_step(tmrs,comp=0)
! == ISOSTASY and SEA LEVEL ===========================================
call bsl_update(bsl, time_bp)
call isos_update(isos1, yelmo1%tpo%now%H_ice, time, bsl, dwdt_corr=yelmo1%bnd%dzbdt_corr)
yelmo1%bnd%z_bed = isos1%out%z_bed
yelmo1%bnd%z_sl = isos1%out%z_ss
call timer_step(tmrs,comp=1,time_mod=[time-ctl%dtt,time]*1e-3,label="isostasy")
! == ICE SHEET ===================================================
if (ctl%with_ice_sheet) call yelmo_update(yelmo1,time)
call timer_step(tmrs,comp=2,time_mod=[time-ctl%dtt,time]*1e-3,label="yelmo")
! ISMIP6 forcing
! Update ismip6 forcing to current time
call ismip6_forcing_update(ismp1,ctl%time_const)
! Set climate to present day
snp1%now = snp1%clim0
! == SURFACE MASS BALANCE ==============================================
if (n .eq. 0) then
! Calculate smb for present day
call smbpal_update_monthly(smbpal1,snp1%now%tas,snp1%now%pr, &
yelmo1%tpo%now%z_srf,yelmo1%tpo%now%H_ice,ctl%time_const)
! Apply ISMIP6 anomalies
! (apply to climate just for consistency)
smbpal1%ann%smb = smbpal1%ann%smb + ismp1%smb%var(:,:,1,1)*1.0/(yelmo1%bnd%c%conv_we_ie*1e-3) ! [m ie/yr] => [mm we/a]
smbpal1%ann%tsrf = smbpal1%ann%tsrf + ismp1%ts%var(:,:,1,1)
do m = 1,12
snp1%now%tas(:,:,m) = snp1%now%tas(:,:,m) + ismp1%ts%var(:,:,1,1)
snp1%now%pr(:,:,m) = snp1%now%pr(:,:,m) + ismp1%pr%var(:,:,1,1)/365.0 ! [mm/yr] => [mm/d]
end do
snp1%now%ta_ann = sum(snp1%now%tas,dim=3) / 12.0_wp
if (trim(domain) .eq. "Antarctica") then
snp1%now%ta_sum = sum(snp1%now%tas(:,:,[12,1,2]),dim=3)/3.0 ! Antarctica summer
else
snp1%now%ta_sum = sum(snp1%now%tas(:,:,[6,7,8]),dim=3)/3.0 ! NH summer
end if
snp1%now%pr_ann = sum(snp1%now%pr,dim=3) / 12.0 * 365.0 ! [mm/d] => [mm/a]
end if
! == MARINE AND TOTAL BASAL MASS BALANCE ===============================
call marshelf_update_shelf(mshlf1,yelmo1%tpo%now%H_ice,yelmo1%bnd%z_bed,yelmo1%tpo%now%f_grnd, &
yelmo1%bnd%basins,yelmo1%bnd%z_sl,yelmo1%grd%dx,-ismp1%to%z, &
ismp1%to%var(:,:,:,1),ismp1%so%var(:,:,:,1), &
dto_ann=ismp1%to%var(:,:,:,1)-ismp1%to_ref%var(:,:,:,1), &
tf_ann=ismp1%tf%var(:,:,:,1))
! Update temperature forcing field with tf_corr and tf_corr_basin
mshlf1%now%tf_shlf = mshlf1%now%tf_shlf + mshlf1%now%tf_corr + mshlf1%now%tf_corr_basin
call marshelf_update(mshlf1,yelmo1%tpo%now%H_ice,yelmo1%bnd%z_bed,yelmo1%tpo%now%f_grnd, &
yelmo1%bnd%regions,yelmo1%bnd%basins,yelmo1%bnd%z_sl,dx=yelmo1%grd%dx)
yelmo1%bnd%smb = smbpal1%ann%smb*yelmo1%bnd%c%conv_we_ie*1e-3
yelmo1%bnd%T_srf = smbpal1%ann%tsrf
yelmo1%bnd%bmb_shlf = mshlf1%now%bmb_shlf
yelmo1%bnd%T_shlf = mshlf1%now%T_shlf
if (trim(ctl%abumip_scenario) .eq. "abum") then
! Ensure bmb_shlf output is consistent with what is applied
yelmo1%bnd%bmb_shlf = ctl%abumip_bmb ! [m/yr]
end if
call timer_step(tmrs,comp=3,time_mod=[time-ctl%dtt,time]*1e-3,label="climate")
! == MODEL OUTPUT ===================================
if (timeout_check(tm_2D,time)) then
call write_step_2D_combined(yelmo1,isos1,snp1,mshlf1,smbpal1,file2D,time)
end if
if (timeout_check(tm_1D,time)) then
call yelmo_write_reg_step(yelmo1,file1D,time=time)
end if
call timer_step(tmrs,comp=4,time_mod=[time-ctl%dtt,time]*1e-3,label="io")
if (mod(time_elapsed,10.0)==0) then
! Print timestep timing info and write log table
call timer_write_table(tmrs,[time,ctl%dtt]*1e-3,"m",tmr_file,init=time_elapsed .eq. 0.0)
end if
if (mod(time_elapsed,10.0)==0 .and. (.not. yelmo_log)) then
write(*,"(a,f14.4)") "yelmo:: time = ", time
end if
end do
write(*,*)
write(*,*) "Transient complete."
write(*,*)
! Write the restart snapshot for the end of the simulation
call yelmox_restart_write(bsl,isos1,yelmo1,time)
case("hysteresis")
! Here it is assumed that the model has gone through spinup
! and is ready for transient simulations
write(*,*)
write(*,*) "Performing transient. [hysteresis]"
write(*,*)
! Additionally make sure isostasy is updated every timestep
isos1%par%dt_prognostics = 1.0_wp
isos1%par%dt_diagnostics = 10.0_wp
! Get current time
time = ctl%time_init
time_bp = time - 1950.0_wp
! === HYST ============
! Initialize hysteresis module for transient forcing experiments
call hyster_init(hyst1,path_par,time)
convert_km3_Gt = yelmo1%bnd%c%rho_ice *1e-3
! =====================
! Update forcing to constant reference time with initial hyst forcing
call calc_climate_ismip6(snp1,smbpal1,mshlf1,ismp1,yelmo1, &
time=ctl%time_const,time_bp=ctl%time_const-1950.0_wp, &
dTa=hyst1%f_now*ctl%hyst_f_ta,dTo=hyst1%f_now*ctl%hyst_f_to)
yelmo1%bnd%smb = smbpal1%ann%smb*yelmo1%bnd%c%conv_we_ie*1e-3 ! [mm we/a] => [m ie/a]
yelmo1%bnd%T_srf = smbpal1%ann%tsrf
yelmo1%bnd%bmb_shlf = mshlf1%now%bmb_shlf
yelmo1%bnd%T_shlf = mshlf1%now%T_shlf
! Initialize hysteresis output files
call yx_hyst_write_yelmo_init_1D_combined(yelmo1,file1D,time,units="years",mask=yelmo1%bnd%ice_allowed, &
dT_min=hyst1%par%f_min,dT_max=hyst1%par%f_max)
call yelmo_write_init(yelmo1,file2D,time_init=time,units="years")
call yelmo_write_init(yelmo1,file2D_small,time_init=time,units="years")
if (reg1%write) then
call yelmo_write_reg_init(yelmo1,reg1%fnm,time_init=time,units="years",mask=reg1%mask)
end if
if (reg2%write) then
call yelmo_write_reg_init(yelmo1,reg2%fnm,time_init=time,units="years",mask=reg2%mask)
end if
if (reg3%write) then
call yelmo_write_reg_init(yelmo1,reg3%fnm,time_init=time,units="years",mask=reg3%mask)
end if
call timer_step(tmr,comp=1,label="initialization")
call timer_step(tmrs,comp=-1)
! Perform 'coupled' model simulations for desired time
do n = 0, ceiling((ctl%time_end-ctl%time_init)/ctl%dtt)
! Get current time
time = ctl%time_init + n*ctl%dtt
time_bp = time - 1950.0_wp
time_elapsed = time - ctl%time_init
! == HYSTERESIS =========================================================
! Make parameter changes relevant to hysteresis runs
! snapclim should use the anomaly method
snp1%par%atm_type = "anom"
snp1%par%ocn_type = "anom"
select case(trim(ctl%hyst_scenario))
case("ctrl")
! Do nothing - control experiment
case("scenario1")
! Possible scenario 1
! To do
case("scenario2")
! Possible scenario 2
! To do
case DEFAULT
write(io_unit_err,*) ""
write(io_unit_err,*) "yelmox_ismip6:: error: hysteresis scenario not recognized."
write(io_unit_err,*) "hysteresis.scenario: ", trim(ctl%hyst_scenario)
stop 1
end select
call timer_step(tmrs,comp=0)
! == ISOSTASY and SEA LEVEL ===========================================
call bsl_update(bsl, time_bp)
call isos_update(isos1, yelmo1%tpo%now%H_ice, time, bsl, dwdt_corr=yelmo1%bnd%dzbdt_corr)
yelmo1%bnd%z_bed = isos1%out%z_bed