-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtsfc_deb_calc.m
823 lines (649 loc) · 41 KB
/
tsfc_deb_calc.m
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
% ------------------------------------------------------------------------
% Calculate the surface temperature and melt based on the Newton-Raphson
% and Crank-Nicholson method and surface energy balance modelling
% ------------------------------------------------------------------------
% pert = 0;
% Debris properties
rhor = 2600; % Density of debris (kg m-3) from Bozhinskiy et al. 1986
cR = 1260; % Specific heat capacity of debris (J kg-1 K-1) from Bozhinskiy et al. 1986
phi_deb = 0.43; % Debris porosity from Bozhinskiy et al. 1986
albdeb = 0.10; % Debris albedo from Bozhinskiy et al. 1986
k_r = 2.8; % Debris whole rock thermal conductivity (W K-1 m-1) from Bozhinskiy et al. 1986
C_ex_deb = 0.004; % Exchange coefficient turbulent fluxes debris
hd_crit = 0.03; % Characteristic snow thickness debris (m w.e.)
phi_low = 0.10; % Porosity of lowest debris layer
em_d = 0.90; % Surface emissivity debris
%% Initialize
i = 1;
% Moisture
start_moist = 0; % 0 = no, 1 = yes
deg_sat = 2; % % 0 = dry, 1 = partially saturated (bottom layer), 2 = saturated, 3 = simplifiied percolation scheme
t_tune = 500;
tau_min = 1;
tau_max = 1000;
% Rain
start_rain = 1;
evap_parameter = 1;
%% Start the loop to determine snow cover evolution
for n = 1:no_gridpointsx
for l = 1:no_gridpointsy
if mask(n,l) < 2 % If no debris, surface temperature and SMB is NaN
yearly_deb_deb(i,n,l) = NaN;
yearly_runoff_deb(i,n,l) = NaN;
yearly_massbal_deb_ice(i,n,l) = NaN;
else
%% Initialization variables
temp_data_deb = temp_glacier(:,n,l);
temp_deb = temp_data_deb+273.15;
prec_deb = prec_glacier(:,n,l);
solarslopingsfc_deb = solarslopingsfc(:,n,l);
solid_prec_glacier_deb = solid_prec_glacier(:,n,l);
yearly_melt_clean_ice = yearly_meltice_tsfc(:,n,l);
lw_in_deb = lw_in(:,n,l);
u_deb = u(:,n,l);
u_AWS_deb = u_d(:,n,l);
p_deb = P(:,n,l);
tau_deb = tau_glacier(:,n,l);
rh_deb = (max(0,rh_AWS));
w = 0;
tsnow_sfc = 0;
fract_cov = 1;
%% Initialization loop
Td = zeros(1, tmax);
Ts_past = zeros(1, tmax);
n_iterations = zeros(1, tmax);
Qnet_deb = zeros(1, tmax);
Lnet_deb = zeros(1, tmax);
Lout_deb = zeros(1, tmax);
SHF_deb = zeros(1, tmax);
LHF_deb = zeros(1, tmax);
Qrain_sfc_deb = zeros(1, tmax);
F_deb = zeros(1, tmax);
dQnet_deb = zeros(1, tmax);
dLnet_deb = zeros(1, tmax);
dSHF_deb = zeros(1, tmax);
dLHF_deb = zeros(1, tmax);
dQrain_sfc_deb = zeros(1, tmax);
dF_deb = zeros(1, tmax);
em_d_deb = zeros(1, tmax);
eS_saturated = zeros(1, tmax);
eZ_saturated = zeros(1, tmax);
eS = zeros(1, tmax);
eZ = zeros(1, tmax);
qS = zeros(1, tmax);
qZ = zeros(1, tmax);
tdsnow_deb = zeros(1, tmax);
dsnow_deb = zeros(1, tmax);
% Compute height of each layer
debris_thickness = th_deb(n,l)./100;
h = debris_thickness / 10;
% Compute various information needed
N = debris_thickness/h + 1;
N_iterations = 0; % Set iterations to vary debris thickness
debris_depth = zeros(N, tmax); % Debris depth
phi_deb2 = zeros(N, tmax); % Debris porosity
% Initialization
a_Crank = zeros(N,tmax);
b_Crank = zeros(N,tmax);
c_Crank = zeros(N,tmax);
d_Crank = zeros(N,tmax);
A_Crank = zeros(N,tmax);
S_Crank = zeros(N,tmax);
Qc_deb = zeros(1, tmax);
dQc_deb = zeros(1, tmax);
Qm_ice = zeros(1, tmax);
Q_rain_deb = zeros(N, tmax);
wd_deb = zeros(N,tmax);
wd_deb_vol = zeros(N,tmax);
wd_deb_tot_vol = zeros(1,tmax);
vol_heat_cap_deb = zeros(N,tmax);
k_eff_deb = zeros(N,tmax);
C_deb = zeros(N,tmax);
tau_j = zeros(N,tmax);
wi = zeros(N,tmax);
advz = zeros(N,tmax);
t_change = zeros(N,tmax);
Q_rain_LWS = zeros(N,tmax);
SHF_within_deb = zeros(N,tmax);
% Note notation in loop: "i-1" refers to the past
%% Surface temperature and surface energy fluxes calculation
for i = 1:tmax
debris_depth(2:N-1,i) = linspace(0,debris_thickness,N-2);
phi_deb2(2:N-1,i) = max(0,linspace(phi_deb,phi_low,N-2));
if i == 1
dsnow_deb(i) = 1e-50; % Artificial infinitesimally small snow depth for first time step
solid_prec_glacier_deb(i) = 1e-50;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IN THE CASE SNOW IS PRESENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if dsnow_deb(i) > 0
n_iterations(i) = 0; % Set iterations to vary surface temperature
Ts_past(i) = 0;
% Initially assume Ts = temp, for all other time steps assume it's equal to previous Ts
if i == 1
Td(1,i) = temp_deb(i);
else
Td(1,i) = Td(1,i-1);
end
if Td(1,i) > 273.15
Td(1,i) = 273.15; % Correct for maximum of melting surface (0 degrees C)
end
% Compute fluxes normally
T_diff(i)=(temp_deb(i)-Td(1,i));
% Albedo
dstar_d = debris_thickness + dstar_i;
if dstar_d > hd_crit
dstar_d = hd_crit + dstar_i;
end
if i == 1
alb_deb(i) = albsnow+(albdeb-albsnow).*exp(-dsnow_deb(i)./dstar_d);
elseif i >= 2
tsnow_sfc(i) = -1.*(find(solid_prec_glacier_deb(1:i)>0,1,'last')-i);
albsnow_deb(i) = albfirn+(albsnow-albfirn).*exp(-tsnow_sfc(i)./tsnow);
alb_deb(i) = albsnow_deb(i)+(albdeb-albsnow_deb(i)).*exp(-dsnow_deb(i)./dstar_d);
end
% Surface fluxes
Qnet_deb(i) = tau_deb(i).*(1-alb_deb(i)).*solarslopingsfc_deb(i);
Lout_deb(i) = em_s.*(stf_bltz.*Td(1,i).^4);
Lnet_deb(i) = lw_in_deb(i) - Lout_deb(i);
SHF_deb(i) = rhoa.*cA.*(C_ex_ice).*u_deb(i).*T_diff(i);
if temp_deb(i) > 273.15
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = rhoa.*Lv.*(C_ex_ice).*u_deb(i).*(qZ(i)-qS(i));
else
eS_saturated(i) = 0;
LHF_deb(i) = 0;
eZ_saturated(i) = 0;
eS(i) = 0;
eZ(i) = 0;
qS(i) = 0;
qZ(i) = 0;
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0;% && dsnow_deb(i) == 0
Qrain_sfc_deb(i) = cW.*rhow.*(prec_deb(i)./(sechr)).*(temp_data_deb(i));
end
F_deb(i) = Qnet_deb(i) + Lnet_deb(i) + SHF_deb(i) + LHF_deb(i) + Qrain_sfc_deb(i);
% Calculate derivative of fluxes w.r.t surface temperature
dQnet_deb(i) = 0;
dLnet_deb(i) = -4.*em_s.*(stf_bltz).*Td(1,i).^3;
dSHF_deb(i) = -1.*rhoa.*cA.*(C_ex_ice).*u_deb(i);
if temp_deb(i) > 273.15
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_ice).*u_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
else
dLHF_deb(i) = 0;
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0;% && dsnow_deb(i) == 0
dQrain_sfc_deb(i) = -cW.*rhow.*(prec_deb(i)./(sechr));
end
dF_deb(i) = dQnet_deb(i) + dLnet_deb(i) + dSHF_deb(i) + dLHF_deb(i) + dQrain_sfc_deb(i);
% Newton-Raphson method to solve for surface temperature
while abs(Td(1,i)-Ts_past(i)) > 0.01 & n_iterations < 100
n_iterations(i) = n_iterations(i) + 1;
Ts_past(i) = Td(1,i);
Td(1,i) = Ts_past(i) - F_deb(i)/dF_deb(i);
if (Td(1,i) - Ts_past(i)) > 1 % Max step size is 1 degree C
Td(1,i) = Ts_past(i) + 1;
elseif (Td(1,i) - Ts_past(i)) < -1
Td(1,i) = Ts_past(i) - 1;
end
if Td(1,i) > 273.15
Td(1,i) = 273.15; % Correct for maximum of melting surface (0 degrees C)
end
% Compute fluxes normally
T_diff(i)=(temp_deb(i)-Td(1,i));
% Albedo
dstar_d = debris_thickness + dstar_i;
if dstar_d > hd_crit
dstar_d = hd_crit + dstar_i;
end
if i == 1
alb_deb(i) = albsnow+(albdeb-albsnow).*exp(-dsnow_deb(i)./dstar_d);
elseif i >= 2
tsnow_sfc(i) = -1.*(find(solid_prec_glacier_deb(1:i)>0,1,'last')-i);
albsnow_deb(i) = albfirn+(albsnow-albfirn).*exp(-tsnow_sfc(i)./tsnow);
alb_deb(i) = albsnow_deb(i)+(albdeb-albsnow_deb(i)).*exp(-dsnow_deb(i)./dstar_d);
end
% Surface fluxes
Qnet_deb(i) = tau_deb(i).*(1-alb_deb(i)).*solarslopingsfc_deb(i);
Lout_deb(i) = em_s.*(stf_bltz.*Td(1,i).^4);
Lnet_deb(i) = lw_in_deb(i) - Lout_deb(i);
SHF_deb(i) = rhoa.*cA.*(C_ex_ice).*u_deb(i).*T_diff(i);
if temp_deb(i) > 273.15
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_ice).*u_deb(i).*(qZ(i)-qS(i));
else
eS_saturated(i) = 0;
LHF_deb(i) = 0;
eZ_saturated(i) = 0;
eS(i) = 0;
eZ(i) = 0;
qS(i) = 0;
qZ(i) = 0;
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0;% && dsnow_deb(i) == 0
Qrain_sfc_deb(i) = cW.*rhow.*(prec_deb(i)./(sechr)).*(temp_data_deb(i));
end
F_deb(i) = Qnet_deb(i) + Lnet_deb(i) + SHF_deb(i) + LHF_deb(i) + Qrain_sfc_deb(i);
% Calculate derivative of fluxes w.r.t surface temperature
dQnet_deb(i) = 0;
dLnet_deb(i) = -4.*em_s.*(stf_bltz).*Td(1,i).^3;
dSHF_deb(i) = -1.*rhoa.*cA.*(C_ex_ice).*u_deb(i);
if temp_deb(i) > 273.15
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_ice).*u_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
else
dLHF_deb(i) = 0;
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0;% && dsnow_deb(i) == 0
dQrain_sfc_deb(i) = -cW.*rhow.*(prec_deb(i)./(sechr));
end
dF_deb(i) = dQnet_deb(i) + dLnet_deb(i) + dSHF_deb(i) + dLHF_deb(i) + dQrain_sfc_deb(i);
% Set maximum iterations to 100
if n_iterations == 100
Td(1,i) = (Td(1,i) + Ts_past(i)) / 2;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% IN THE CASE SNOW IS ABSENT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
elseif dsnow_deb(i) == 0
n_iterations(i) = 0; % Set iterations to vary surface temperature
Ts_past(i) = 0;
Td(N,i) = 273.15; % Ice temperature is 0 degrees C
% Initially assume Ts = temp_deb, for all other time steps assume it's equal to previous Ts
if i == tdsnow_deb(i-1)+1
Td(1,i) = temp_deb(i);
else
Td(1,i) = Td(1,i-1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% HEAT DIFFUSION BY CONDIUCTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate temperature profile in the debris
if i == tdsnow_deb(i-1)+1 % For t = 0, which is i = 1, assume initial condition of linear temperature profile in the debris
Td_gradient = (Td(1,i) - Td(N,i))/debris_thickness;
for j = 2:1:(N-1)
Td(j,i) = Td(1,i) - (j*h)*Td_gradient;
end
else % Perform Crank-Nicholson Scheme
for j = 2:1:(N-1) % Equation A8 in Reid and Brock (2010)
vol_heat_cap_deb(j,i) = rhor.*cR.*(1-phi_deb2(j,i))+(rhow.*cW.*(wd_deb_vol(j,i)) + rhoa.*cA.*(1-wd_deb_vol(j,i))).*(phi_deb2(j,i));
k_eff_deb(j,i) = k_r.*(1-phi_deb2(j,i))+(k_w.*(wd_deb_vol(j,i)) + k_a.*(1-wd_deb_vol(j,i))).*(phi_deb2(j,i));
C_deb(j,i) = k_eff_deb(j,i)*sechr/(2*(vol_heat_cap_deb(j,i))*h^2);
a_Crank(j,i) = C_deb(j,i);
b_Crank(j,i) = 2*C_deb(j,i)+1;
c_Crank(j,i) = C_deb(j,i);
if j == 2 % Equation A9 in Reid and Brock (2010)
d_Crank(j,i) = C_deb(j,i)*Td(1,i) + C_deb(j,i)*Td(1,i-1) + (1-2*C_deb(j,i))*Td(j,i-1) + C_deb(j,i)*Td(j+1,i-1);
elseif j < (N-1)
d_Crank(j,i) = C_deb(j,i)*Td(j-1,i-1) + (1-2*C_deb(j,i))*Td(j,i-1) + C_deb(j,i)*Td(j+1,i-1);
elseif j == (N-1)
d_Crank(j,i) = 2*C_deb(j,i)*Td(N,i) + C_deb(j,i)*Td(N-2,i-1) + (1-2*C_deb(j,i))*Td(N-1,i-1);
end
if j == 2 % Equations A10 and A11 in Reid and Brock (2010)
A_Crank(j,i) = b_Crank(j,i);
S_Crank(j,i) = d_Crank(j,i);
else
A_Crank(j,i) = b_Crank(j,i) - a_Crank(j,i)/A_Crank(j-1,i)*c_Crank(j-1,i);
S_Crank(j,i) = d_Crank(j,i) + a_Crank(j,i)/A_Crank(j-1,i)*S_Crank(j-1,i);
end
end
for j = N-1:-1:2 % Equation A12 in Reid and Brock (2010)
if j == (N-1)
Td(j,i) = S_Crank(j,i)/A_Crank(j,i);
else
Td(j,i) = 1/A_Crank(j,i)*(S_Crank(j,i)+c_Crank(j,i)*Td(j+1,i));
end
end
end
% Assume snow-free surface and compute fluxes normally
T_diff(i)=(temp_deb(i)-Td(1,i));
if i == 1
alb_deb(i) = albsnow+(albdeb-albsnow).*exp(-dsnow_deb(i)./dstar_d);
solid_prec_glacier_deb(i) = 1e-50;
elseif i >= 2
tsnow_sfc(i) = -1.*(find(solid_prec_glacier_deb(1:i)>0,1,'last')-i);
albsnow_deb(i) = albfirn+(albsnow-albfirn).*exp(-tsnow_sfc(i)./tsnow);
alb_deb(i) = albsnow_deb(i)+(albdeb-albsnow_deb(i)).*exp(-dsnow_deb(i)./dstar_d);
end
Qnet_deb(i) = tau_deb(i).*(1-alb_deb(i)).*solarslopingsfc_deb(i);
Lout_deb(i) = em_d_deb(i).*(stf_bltz.*Td(1,i).^4);
Lnet_deb(i) = lw_in_deb(i) - Lout_deb(i);
SHF_deb(i) = rhoa.*cA.*(C_ex_deb).*u_AWS_deb(i).*T_diff(i);
if start_moist == 0 || deg_sat == 0
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
else
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
eS(i) = (eZ(i).*((Td(1,i))./(temp_deb(i))));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = 0;
end
end
if start_moist == 1 && deg_sat == 1 || deg_sat == 2 || deg_sat == 3
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
if qS(i) == 0
LHF_deb(i) = 0;
end
elseif i > 2 && dsnow_deb(i-1) == 0 && Qm_ice(i-1) > 0 || Wsnow(i-1) > 0 || prec_deb(i-1) > 0
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
eS(i) = (eZ(i).*((Td(1,i))./(temp_deb(i)))) + ((eS_saturated(i)-(eZ(i).*((Td(1,i))./(temp_deb(i)))))*(((sum(wd_deb_vol(2:N-1,i))./(N-2)))));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
if qS(i) == 0
LHF_deb(i) = 0;
end
end
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0 && dsnow_deb(i) == 0
Qrain_sfc_deb(i) = cW.*rhow.*(prec_deb(i)./(sechr)).*(temp_deb(i)-Td(1,i));
end
Qc_deb(i) = k_eff_deb(2,i)*(Td(2,i) - Td(1,i))/h;
F_deb(i) = Qnet_deb(i) + Lnet_deb(i) + SHF_deb(i) + LHF_deb(i) + Qrain_sfc_deb(i) + Qc_deb(i);
% Calculate derivative of fluxes w.r.t surface temperature
dQnet_deb(i) = 0;
dLnet_deb(i) = -4.*em_d_deb(i).*(stf_bltz).*Td(1,i).^3;
dSHF_deb(i) = -1.*rhoa.*cA.*(C_ex_deb).*u_AWS_deb(i);
if start_moist == 0 || deg_sat == 0
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
else
dLHF_deb(i) = 0;
end
end
if start_moist == 1 && deg_sat == 1 || deg_sat == 2 || deg_sat == 3
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
if qS(i) == 0
dLHF_deb(i) = 0;
end
else i > 2 && dsnow_deb(i-1) == 0 && Qm_ice(i-1) > 0 || Wsnow(i-1) > 0 || prec_deb(i-1) > 0;
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
if qS(i) == 0
dLHF_deb(i) = 0;
end
end
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0 && dsnow_deb(i) == 0
dQrain_sfc_deb(i) = -cW.*rhow.*(prec_deb(i)./(sechr));
end
dQc_deb(i) = -k_eff_deb(2,i)/h;
dF_deb(i) = dQnet_deb(i) + dLnet_deb(i) + dSHF_deb(i) + dLHF_deb(i) + dQrain_sfc_deb(i) + dQc_deb(i);
% Newton-Raphson method to solve for surface temperature
while abs(Td(1,i)-Ts_past(i)) > 0.01 & n_iterations < 100
n_iterations(i) = n_iterations(i) + 1;
Ts_past(i) = Td(1,i);
Td(1,i) = Ts_past(i) - F_deb(i)/dF_deb(i);
if dsnow_deb(i) > 0
Td(1,i) = 273.15; % In case of snow cover, surface temperature is 0 degrees C
end
if (Td(1,i) - Ts_past(i)) > 1 % Max step size is 1 degree C
Td(1,i) = Ts_past(i) + 1;
elseif (Td(1,i) - Ts_past(i)) < -1
Td(1,i) = Ts_past(i) - 1;
end
% Calculate temperature profile in the debris
if i == tdsnow_deb(i-1)+1 % For t = 0, which is i = 1, assume initial condition of linear temperature profile in the debris
Td(1,i) = temp_deb(i);
Td_gradient = (Td(1,i) - Td(N,i))/debris_thickness;
for j = 2:1:(N-1)
Td(j,i) = Td(1,i) - (j*h)*Td_gradient;
end
else % Perform Crank-Nicholson Scheme
for j = 2:1:(N-1) % Equation A8 in Reid and Brock (2010)
vol_heat_cap_deb(j,i) = rhor.*cR.*(1-phi_deb2(j,i))+(rhow.*cW.*(wd_deb_vol(j,i)) + rhoa.*cA.*(1-wd_deb_vol(j,i))).*(phi_deb2(j,i));
k_eff_deb(j,i) = k_r.*(1-phi_deb2(j,i))+(k_w.*(wd_deb_vol(j,i)) + k_a.*(1-wd_deb_vol(j,i))).*(phi_deb2(j,i));
C_deb(j,i) = k_eff_deb(j,i)*sechr/(2*(vol_heat_cap_deb(j,i))*h^2);
a_Crank(j,i) = C_deb(j,i);
b_Crank(j,i) = 2*C_deb(j,i)+1;
c_Crank(j,i) = C_deb(j,i);
if j == 2 % Equation A9 in Reid and Brock (2010)
d_Crank(j,i) = C_deb(j,i)*Td(1,i) + C_deb(j,i)*Td(1,i-1) + (1-2*C_deb(j,i))*Td(j,i-1) + C_deb(j,i)*Td(j+1,i-1);
elseif j < (N-1)
d_Crank(j,i) = C_deb(j,i)*Td(j-1,i-1) + (1-2*C_deb(j,i))*Td(j,i-1) + C_deb(j,i)*Td(j+1,i-1);
elseif j == (N-1)
d_Crank(j,i) = 2*C_deb(j,i)*Td(N,i) + C_deb(j,i)*Td(N-2,i-1) + (1-2*C_deb(j,i))*Td(N-1,i-1);
end
if j == 2 % Equations A10 and A11 in Reid and Brock (2010)
A_Crank(j,i) = b_Crank(j,i);
S_Crank(j,i) = d_Crank(j,i);
else
A_Crank(j,i) = b_Crank(j,i) - a_Crank(j,i)/A_Crank(j-1,i)*c_Crank(j-1,i);
S_Crank(j,i) = d_Crank(j,i) + a_Crank(j,i)/A_Crank(j-1,i)*S_Crank(j-1,i);
end
end
for j = N-1:-1:2 % Equation A12 in Reid and Brock (2010)
if j == (N-1)
Td(j,i) = S_Crank(j,i)/A_Crank(j,i);
else
Td(j,i) = 1/A_Crank(j,i)*(S_Crank(j,i)+c_Crank(j,i)*Td(j+1,i));
end
end
end
% Assume snow-free surface and compute fluxes normally
T_diff(i)=(temp_deb(i)-Td(1,i));
if i == 1
alb_deb(i) = albsnow+(albdeb-albsnow).*exp(-dsnow_deb(i)./dstar_d);
solid_prec_glacier_deb(i) = 1e-50;
elseif i >= 2
tsnow_sfc(i) = -1.*(find(solid_prec_glacier_deb(1:i)>0,1,'last')-i);
albsnow_deb(i) = albfirn+(albsnow-albfirn).*exp(-tsnow_sfc(i)./tsnow);
alb_deb(i) = albsnow_deb(i)+(albdeb-albsnow_deb(i)).*exp(-dsnow_deb(i)./dstar_d);
end
Qnet_deb(i) = tau_deb(i).*(1-alb_deb(i)).*solarslopingsfc_deb(i);
Lout_deb(i) = em_d_deb(i).*(stf_bltz.*Td(1,i).^4);
Lnet_deb(i) = lw_in_deb(i) - Lout_deb(i);
SHF_deb(i) = rhoa.*cA.*(C_ex_deb).*u_AWS_deb(i).*T_diff(i);
if start_moist == 0 || deg_sat == 0
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
else
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
eS(i) = (eZ(i).*((Td(1,i))./(temp_deb(i))));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = 0;
end
end
if start_moist == 1 && deg_sat == 1 || deg_sat == 2 || deg_sat == 3
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh 0
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eS(i) = eS_saturated(i);
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
if qS(i) == 0
LHF_deb(i) = 0;
end
elseif i > 2 && dsnow_deb(i-1) == 0 && Qm_ice(i-1) > 0 || Wsnow(i-1) > 0 || prec_deb(i-1) > 0
eS_saturated(i) = 611.*exp(-Lv./R2.*(1./Td(1,i)-1/273.15));
eZ_saturated(i) = 611.*exp(-Lv./R2.*(1./(temp_deb(i))-1/273.15));
eZ(i) = ((rh_deb(i)./100)*eZ_saturated(i));
eS(i) = (eZ(i).*((Td(1,i))./(temp_deb(i)))) + ((eS_saturated(i)-(eZ(i).*((Td(1,i))./(temp_deb(i)))))*(((sum(wd_deb_vol(2:N-1,i))./(N-2)))));
qS(i) = (mwratio).*(eS(i)./p_deb(i));
qZ(i) = (mwratio).*(eZ(i)./p_deb(i));
LHF_deb(i) = Lv.*rhoa.*(C_ex_deb).*u_AWS_deb(i).*(qZ(i)-qS(i));
if qS(i) == 0
LHF_deb(i) = 0;
end
end
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0 && dsnow_deb(i) == 0
Qrain_sfc_deb(i) = cW.*rhow.*(prec_deb(i)./(sechr)).*(temp_deb(i)-Td(1,i));
end
Qc_deb(i) = k_eff_deb(2,i)*(Td(2,i) - Td(1,i))/h;
F_deb(i) = Qnet_deb(i) + Lnet_deb(i) + SHF_deb(i) + LHF_deb(i) + Qrain_sfc_deb(i) + Qc_deb(i);
% Calculate derivative of fluxes w.r.t surface temperature
dQnet_deb(i) = 0;
dLnet_deb(i) = -4.*em_d_deb(i).*(stf_bltz).*Td(1,i).^3;
dSHF_deb(i) = -1.*rhoa.*cA.*(C_ex_deb).*u_AWS_deb(i);
if start_moist == 0 || deg_sat == 0
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
else
dLHF_deb(i) = 0;
end
end
if start_moist == 1 && deg_sat == 1 || deg_sat == 2 || deg_sat == 3
if prec_deb(i) > 0 && dsnow_deb(i) == 0 && temp_deb(i) > 273.15+t_tresh
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
if qS(i) == 0
dLHF_deb(i) = 0;
end
else i > 2 && dsnow_deb(i-1) == 0 && Qm_ice(i-1) > 0 || Wsnow(i-1) > 0 || prec_deb(i-1) > 0;
dLHF_deb(i) = -1.*rhoa.*Lv.*(C_ex_deb).*u_AWS_deb(i).*((611.*exp(-Lv./R2.*(1./Td(1,i)-1./273.15)).*(Lv./R2.*Td(1,i).^-2)).*(mwratio/(p_deb(i))));
if qS(i) == 0
dLHF_deb(i) = 0;
end
end
end
if prec_deb(i) > 0 && solid_prec_glacier_deb(i) == 0 && dsnow_deb(i) == 0
dQrain_sfc_deb(i) = -cW.*rhow.*(prec_deb(i)./(sechr));
end
dQc_deb(i) = -k_eff_deb(2,i)/h;
dF_deb(i) = dQnet_deb(i) + dLnet_deb(i) + dSHF_deb(i) + dLHF_deb(i) + dQrain_sfc_deb(i) + dQc_deb(i);
% Set maximum iterations to 100
if n_iterations == 100
Td(1,i) = (Td(1,i) + Ts_past(i)) / 2;
end
end
if start_rain == 1
heat_rain;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SUB-DEBRIS ENERGY FOR MELTING %%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate energy for melting
if start_rain == 1
Qm_ice(i) = max(0,(k_eff_deb(N-1,i)*(Td(N-1,i) - Td(N,i))/h) + Q_rain_LWS(N-1,i));
else
Qm_ice(i) = max(0,(k_eff_deb(N-1,i)*(Td(N-1,i) - Td(N,i))/h));
end
if Qm_ice(i) < 0
Qm_ice(i) = 0;
end
% Adjust temperature profile
for j = 2:1:(N-1)
if start_rain == 1
Td(j,i) = Td(j,i) + t_change(j,i);
else
Td(j,i) = Td(j,i);
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MOISTURE WITHIN DEBRIS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if start_moist == 1
moisture_calc;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SAVE THE VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save values for the energy balance components
yearly_tempsfc_deb(i,n,l) = Td(1,i);
yearly_rh(i,n,l) = rh_deb(i);
yearly_ta_deb(i,n,l) = temp_deb(i);
yearly_qnet_deb(i,n,l) = Qnet_deb(i);
yearly_qin_deb(i,n,l) = tau_deb(i).*solarslopingsfc_deb(i);
yearly_albedo_deb(i,n,l) = alb_deb(i);
yearly_dsnow_deb(i,n,l) = dsnow_deb(i);
yearly_lnet_deb(i,n,l) = Lnet_deb(i);
yearly_lout_deb(i,n,l) = Lout_deb(i);
yearly_lin_deb(i,n,l) = lw_in_deb(i);
yearly_shf_deb(i,n,l) = SHF_deb(i);
yearly_lhf_deb(i,n,l) = LHF_deb(i);
yearly_qrain_sfc_deb(i,n,l) = Qrain_sfc_deb(i);
yearly_psi_deb(i,n,l) = F_deb(i);
yearly_ez_saturated_deb(i,n,l) = eZ_saturated(i);
yearly_es_saturated_deb(i,n,l) = eS_saturated(i);
yearly_es_deb(i,n,l) = eS(i);
yearly_ez_deb(i,n,l) = eZ(i);
yearly_qs_deb(i,n,l) = qS(i);
yearly_qz_deb(i,n,l) = qZ(i);
yearly_qc_deb(i,n,l) = Qc_deb(i);
yearly_qrain_deb(i,n,l) = Q_rain_LWS(N-1,i);
yearly_qrain_temp_deb(i,n,l) = t_change(N-1,i);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MASS BALANCE CALCULATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculate snow melt
if dsnow_deb(i) > 0
meltsnow(i) = min(dsnow_deb(i),(max(0,(sechr.*F_deb(i))./(rhow.*lm))));
Wsnow(i) = max(0,(w(i)-(ns.*dsnow_deb(i))));
w(i+1) = w(i) + meltsnow(i) - Wsnow(i);
meltice(i) = 0;
runoff(i) = Wsnow(i);
% In the case of debris-covered ice surface
elseif dsnow_deb(i) == 0
meltice(i) = (fract_cov.*(max(0,(sechr.*Qm_ice(i))./(rhow.*lm)))) + ((1-fract_cov).*yearly_melt_clean_ice(i));
Wsnow(i) = 0;
w(i+1) = 0;
meltsnow(i) = 0;
runoff(i) = meltice(i);
end
% Update snow depth
dsnow_deb(i+1) = dsnow_deb(i) + solid_prec_glacier_deb(i) - meltsnow(i);
tdsnow_deb(i) = (find(dsnow_deb(1:i)>0,1,'last'));
tdsnow_deb2(i) = -1.*(find(dsnow_deb(1:i)>0,1,'last')-i);
% Avoid negative snow depth
if dsnow_deb(i+1) < 0
dsnow_deb(i+1) = 0;
end
% Avoid that more water is retained then the retention capacity
if w(i) > ns.*dsnow_deb(i)
w(i) = ns.*dsnow_deb(i);
end
% Calculate final mass balance profile
massbal(i+1) = massbal(i) + dt*(solid_prec_glacier_deb(i)-runoff(i));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SAVE THE VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yearly_runoff_deb(i,n,l) = runoff(i);
yearly_massbal_deb_ice(i,n,l) = massbal(i);
yearly_meltsnow_deb(i,n,l) = meltsnow(i);
yearly_Wsnow_deb(i,n,l) = Wsnow(i);
yearly_meltice_deb(i,n,l) = meltice(i);
end
end
end
end