-
Notifications
You must be signed in to change notification settings - Fork 0
/
solvemodel_v12_1k.sed.m
1213 lines (1030 loc) · 57.5 KB
/
solvemodel_v12_1k.sed.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
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
% === MyLake model, version 1.2, 15.03.05 ===
% by Tom Andersen & Tuomo Saloranta, NIVA 2005
%
% VERSION 1.2.1k KOJI
% VERSION 1.2.1 (two phytoplankton groups are included; variable Cz denotes
% this second group now. Frazil ice included + some small bug-fixes and code rearrangements. Using convection_v12_1a.m code)
%
% Main module
% Code checked by TSA, xx.xx.200x
% Last modified by TSA, 21.08.2007
%% SIMPLE VERSION BY KOJI BASED ON TUOMO'S SUGGESION SEE [SIMPLE] 2011-07-26
% main differences:
% no inflow (switch)
% light attenuation coefficients (lambdaz) TODO
% does not touch depth profile except for temperature (no
% advection- or diffusion-effect on concentrations
% wind-mixing does not affect concentrations (should be already
% homogenious
% uses convection_v12_1a_simple.m
% no use of Ppart()
%%
% KOJI making it further SIMPLE2 2011-07-28
% removing everything to do with the sediments
% removed everything to do with algae growth
function [zz,Az,Vz,tt,Qst,Kzt,Tzt,Czt,Szt,Pzt,Chlzt,PPzt,DOPzt,DOCzt,lambdazt,...
His,DoF,DoM,MixStat,Wt] = ...
solvemodel_v12_1k(M_start,M_stop,Initfile,Initsheet,Inputfile,Inputsheet,Parafile,Parasheet,varargin);
% $$$ function [zz,Az,Vz,tt,Qst,Kzt,Tzt,Czt,Szt,Pzt,Chlzt,PPzt,DOPzt,DOCzt,Qzt_sed,lambdazt,...
% $$$ P3zt_sed,P3zt_sed_sc,His,DoF,DoM,MixStat,Wt] = ...
% $$$ solvemodel_v12_1b_simple(M_start,M_stop,Initfile,Initsheet,Inputfile,Inputsheet,Parafile,Parasheet,varargin);
% warning off MATLAB:fzero:UndeterminedSyntax %suppressing a warning message
% Inputs (to function)
% M_start : Model start date [year, month, day]
% M_stop : Model stop date [year, month, day]
% + Input filenames and sheetnames
% Inputs (received from input module):
% tt : Solution time domain (day)
% In_Z : Depths read from initial profiles file (m)
% In_Az : Areas read from initial profiles file (m2)
% In_Tz : Initial temperature profile read from initial profiles file (deg C)
% In_Cz : Initial chlorophyll (group 2) profile read from initial profiles file (-)
% In_Sz : Initial sedimenting tracer (or suspended inorganic matter) profile read from initial profiles file (kg m-3)
% In_TPz : Initial total P profile read from initial profiles file (incl. DOP & Chla & Cz) (mg m-3)
% In_DOPz : Initial dissolved organic P profile read from initial profiles file (mg m-3)
% In_Chlz : Initial chlorophyll (group 1) profile read from initial profiles file (mg m-3)
% In_DOCz : Initial DOC profile read from initial profiles file (mg m-3)
% In_TPz_sed : Initial total P profile in the sediment compartments read from initial profiles file (mg m-3)
% In_Chlz_sed : Initial chlorophyll profile (groups 1+2) in the sediment compartments read from initial profiles file (mg m-3)
% In_FIM : Initial profile of volume fraction of inorganic matter in the sediment solids (dry weight basis)
% Ice0 : Initial conditions, ice and snow thicknesses (m) (Ice, Snow)
% Wt : Weather data
% Inflow : Inflow data
% Phys_par : Main 23 parameters that are more or less fixed
% Phys_par_range : Minimum and maximum values for Phys_par (23 * 2)
% Phys_par_names : Names for Phys_par
% Bio_par : Main 23 parameters that are more or less site specific
% Bio_par_range : Minimum and maximum values for Bio_par (23 * 2)
% Bio_par_names : Names for Bio_par
% Outputs (other than Inputs from input module):
% Qst : Estimated surface heat fluxes ([sw, lw, sl] * tt) (W m-2)
% Kzt : Predicted vertical diffusion coefficient (tt * zz) (m2 d-1)
% Tzt : Predicted temperature profile (tt * zz) (deg C)
% Czt : Predicted chlorophyll (group 2) profile (tt * zz) (-)
% Szt : Predicted passive sedimenting tracer (or suspended inorganic matter) profile (tt * zz) (kg m-3)=(g L-1)
% Pzt : Predicted dissolved inorganic phosphorus profile (tt * zz) (mg m-3)
% Chlzt : Predicted chlorophyll (group 1) profile (tt * zz) (mg m-3)
% PPzt : Predicted particulate inorganic phosphorus profile (tt * zz) (mg m-3)
% DOPzt : Predicted dissolved organic phosphorus profile (tt * zz) (mg m-3)
% DOCzt : Predicted dissolved organic carbon (DOC) profile (tt * zz) (mg m-3)
% $$$ % Qz_sed : Predicted sediment-water heat flux (tt * zz) (W m-2, normalised to lake surface area)
% lambdazt : Predicted average total light attenuation coefficient down to depth z (tt * zz) (m-1)
% $$$ % P3zt_sed : Predicted P conc. in sediment for P (mg m-3), PP(mg kg-1 dry w.) and Chl (mg kg-1 dry w.) (tt * zz * 3)
% $$$ % P3zt_sed_sc : Predicted P source from sediment for P, PP and Chl (mg m-3 day-1) (tt * zz * 3)
% His : Ice information matrix ([Hi Hs Hsi Tice Tair rho_snow IceIndicator] * tt)
% DoF, DoM : Days of freezing and melting (model timestep number)
% MixStat : Temporary variables used in model testing, see code (N * tt)
% These variables are still global and not transferred by functions
global ies80;
tic
% $$$ disp(['Running MyLake v.1.2.1b from ' datestr(datenum(M_start)) ' to ' datestr(datenum(M_stop)) ' ...']);
% ===Switches===
snow_compaction_switch=1; %snow compaction: 0=no, 1=yes
river_inflow_switch=1; %river inflow: 0=no, 1=yes SIMPLE
sediment_heatflux_switch=1; %heatflux from sediments: 0=no, 1=yes
selfshading_switch=0; %light attenuation by chlorophyll a: 0=no, 1=yes
tracer_switch=0; %simulate tracers: 0=no, 1=yes SIMPLE
% ==============
dt=1.0; %model time step = 1 day (DO NOT CHANGE!)
if (nargin>8) %if optional command line parameter input is used
% $$$ disp('Bypassing input files...Running with input data & parameters given on command line');
[In_Z,In_Az,tt,In_Tz,In_Cz,In_Sz,In_TPz,In_DOPz,In_Chlz,In_DOCz,In_TPz_sed,In_Chlz_sed,In_FIM,Ice0,Wt,Inflw,...
Phys_par,Phys_par_range,Phys_par_names,Bio_par,Bio_par_range,Bio_par_names]...
= deal(varargin{:});
else
%Read input data
[In_Z,In_Az,tt,In_Tz,In_Cz,In_Sz,In_TPz,In_DOPz,In_Chlz,In_DOCz,In_TPz_sed,In_Chlz_sed,In_FIM,Ice0,Wt,Inflw,...
Phys_par,Phys_par_range,Phys_par_names,Bio_par,Bio_par_range,Bio_par_names]...
= modelinputs_v12_1b(M_start,M_stop,Initfile,Initsheet,Inputfile,Inputsheet,Parafile,Parasheet,dt);
end
load albedot1.mat; %load albedot1 table, in order to save execution time
% Unpack the more fixed parameter values from input array "Phys_par"
dz = Phys_par(1); %grid stepsize (m)
zm = In_Z(end); %max depth
zz = [0:dz:zm-dz]'; %solution depth domain
Kz_K1 = Phys_par(2); % open water diffusion parameter (-)
Kz_K1_ice = Phys_par(3); % under ice diffusion parameter (-)
Kz_N0 = Phys_par(4); % min. stability frequency (s-2)
C_shelter = Phys_par(5); % wind shelter parameter (-)
lat = Phys_par(6); %latitude (decimal degrees)
lon = Phys_par(7); %longitude (decimal degrees)
alb_melt_ice = Phys_par(8); %albedo of melting ice (-)
alb_melt_snow = Phys_par(9); %albedo of melting snow (-)
PAR_sat = Phys_par(10); %PAR saturation level for phytoplankton growth (mol(quanta) m-2 s-1)
f_par = Phys_par(11); %Fraction of PAR in incoming solar radiation (-)
beta_chl = Phys_par(12); %Optical cross_section of chlorophyll (m2 mg-1)
lambda_i = Phys_par(13); %PAR light attenuation coefficient for ice (m-1)
lambda_s = Phys_par(14); %PAR light attenuation coefficient for snow (m-1)
F_sed_sld = Phys_par(15); %volume fraction of solids in sediment (= 1-porosity)
I_scV = Phys_par(16); %scaling factor for inflow volume (-)
I_scT = Phys_par(17); %scaling coefficient for inflow temperature (-)
I_scC = Phys_par(18); %scaling factor for inflow concentration of C (-)
I_scS = Phys_par(19); %scaling factor for inflow concentration of S (-)
I_scTP = Phys_par(20); %scaling factor for inflow concentration of total P (-)
I_scDOP = Phys_par(21); %scaling factor for inflow concentration of diss. organic P (-)
I_scChl = Phys_par(22); %scaling factor for inflow concentration of Chl a (-)
I_scDOC = Phys_par(23); %scaling factor for inflow concentration of DOC (-)
% Unpack the more site specific parameter values from input array "Bio_par"
swa_b0 = Bio_par(1); % non-PAR light atteneuation coeff. (m-1)
swa_b1 = Bio_par(2); % PAR light atteneuation coeff. (m-1)
S_res_epi = Bio_par(3); %Particle resuspension mass transfer coefficient, epilimnion (m day-1, dry)
S_res_hypo = Bio_par(4); %Particle resuspension mass transfer coefficient, hypolimnion (m day-1, dry)
H_sed = Bio_par(5); %height of active sediment layer (m, wet mass)
Psat_L = Bio_par(6); %Half saturation parameter for Langmuir isotherm
Fmax_L = Bio_par(7); %Scaling parameter for Langmuir isotherm !!!!!!!!!!!!
w_s = Bio_par(8); %settling velocity for S (m day-1)
w_chl = Bio_par(9); %settling velocity for Chl a (m day-1)
Y_cp = Bio_par(10); %yield coefficient (chlorophyll to carbon) * (carbon to phosphorus) ratio (-)
m_twty = Bio_par(11); %loss rate (1/day) at 20 deg C
g_twty = Bio_par(12); %specific growth rate (1/day) at 20 deg C
k_twty = Bio_par(13); %specific Chl a to P transformation rate (1/day) at 20 deg C
dop_twty = Bio_par(14); %specific DOP to P transformation rate (day-1) at 20 deg C
P_half = Bio_par(15); %Half saturation growth P level (mg/m3)
%NEW!!!===parameters for the 2 group of chlorophyll variable
PAR_sat_2 = Bio_par(16); %PAR saturation level for phytoplankton growth (mol(quanta) m-2 s-1)
beta_chl_2 = Bio_par(17); %Optical cross_section of chlorophyll (m2 mg-1)
w_chl_2 = Bio_par(18); %Settling velocity for Chl a (m day-1)
m_twty_2 = Bio_par(19); %Loss rate (1/day) at 20 deg C
g_twty_2 = Bio_par(20); %Specific growth rate (1/day) at 20 deg C
P_half_2 = Bio_par(21); %Half saturation growth P level (mg/m3)
oc_DOC = Bio_par(22); %Optical cross-section of DOC (m2/mg DOC)
qy_DOC = Bio_par(23); %Quantum yield (mg DOC degraded/mol quanta)
%===========
% ====== Other variables/parameters not read from the input file:
Nz=length(zz); %total number of layers in the water column
N_sed=26; %total number of layers in the sediment column
theta_m = exp(0.1*log(2)); %loss and growth rate parameter base, ~1.072
e_par = 240800; %Average energy of PAR photons (J mol-1)
% diffusion parameterisation exponents
Kz_b1 = 0.43;
Kz_b1_ice = 0.43;
% ice & snow parameter values
rho_fw=1000; %density of freshwater (kg m-3)
rho_ice=910; %ice (incl. snow ice) density (kg m-3)
rho_new_snow=250; %new-snow density (kg m-3)
max_rho_snow=450; %maximum snow density (kg m-3)
L_ice=333500; %latent heat of freezing (J kg-1)
K_ice=2.1; %ice heat conduction coefficient (W m-1 K-1)
C1=7.0; %snow compaction coefficient #1
C2=21.0; %snow compaction coefficient #2
Tf=0; %water freezing point temperature (deg C)
F_OM=1e+6*0.012; %mass fraction [mg kg-1] of P of dry organic matter (assuming 50% of C, and Redfield ratio)
K_sed=0.035; %thermal diffusivity of the sediments (m2 day-1)
rho_sed=2500; %bulk density of the inorganic solids in sediments (kg m-3)
rho_org=1000; %bulk density of the organic solids in sediments (kg m-3)
cp_sed=1000; %specific heat capasity of the sediments (J kg-1 K-1)
ksw=1e-3; %sediment pore water mass transfer coefficient (m/d)
Fmax_L_sed=Fmax_L;
Fstable=655; % Inactive P conc. in inorg. particles (mg/kg dw);
Frazil2Ice_tresh=0.03; % treshold (m) where frazil is assumed to turn into a solid ice cover NEW!!!
%=======
% Allocate and initialise output data matrices
Qst = zeros(3,length(tt));
Kzt = zeros(Nz,length(tt));
Tzt = zeros(Nz,length(tt));
Czt = zeros(Nz,length(tt));
Szt = zeros(Nz,length(tt));
Pzt = zeros(Nz,length(tt));
Chlzt = zeros(Nz,length(tt));
PPzt = zeros(Nz,length(tt));
DOPzt = zeros(Nz,length(tt));
DOCzt = zeros(Nz,length(tt));
Qzt_sed = zeros(Nz,length(tt));
lambdazt = zeros(Nz,length(tt));
P3zt_sed = zeros(Nz,length(tt),4); %3-D
P3zt_sed_sc = zeros(Nz,length(tt),3); %3-D
His = zeros(8,length(tt)); %NEW!!!
MixStat = zeros(10,length(tt));
% Initial profiles
Az = interp1(In_Z,In_Az,zz);
Vz = dz * (Az + [Az(2:end); 0]) / 2;
T0 = interp1(In_Z,In_Tz,zz+dz/2); % Initial temperature distribution (deg C)
C0 = interp1(In_Z,In_Cz,zz+dz/2); % Initial chlorophyll (group 2) distribution (mg m-3)
S0 = interp1(In_Z,In_Sz,zz+dz/2); % Initial passive sedimenting tracer (or suspended inorganic matter) distribution (kg m-3)
TP0 = interp1(In_Z,In_TPz,zz+dz/2); % Initial total P distribution (incl. DOP & Chla & Cz) (mg m-3)
DOP0 = interp1(In_Z,In_DOPz,zz+dz/2); % Initial dissolved organic P distribution (mg m-3)
Chl0 = interp1(In_Z,In_Chlz,zz+dz/2); % Initial chlorophyll (group 2) distribution (mg m-3)
DOC0 = interp1(In_Z,In_DOCz,zz+dz/2); % Initial DOC distribution (mg m-3)
TP0_sed = interp1(In_Z,In_TPz_sed,zz+dz/2); % Initial total P distribution in bulk wet sediment ((mg m-3); particles + porewater)
Chl0_sed = interp1(In_Z,In_Chlz_sed,zz+dz/2); % Initial chlorophyll (group 1+2) distribution in bulk wet sediment (mg m-3)
FIM0 = interp1(In_Z,In_FIM,zz+dz/2); % Initial sediment solids volume fraction of inorganic matter (-)
VolFrac=1./(1+(1-F_sed_sld)./(F_sed_sld*FIM0)); %volume fraction: inorg sed. / (inorg.sed + pore water)
if any((TP0-DOP0-(Chl0 + C0)./Y_cp-S0*Fstable)<0) %NEW!!!
error('Sum of initial DOP, stably particle bound P, and P contained in Chl (both groups) a cannot be larger than TP')
end
if any((TP0_sed-DOP0-Chl0_sed./Y_cp-VolFrac*rho_sed*Fstable)<0)
error('Sum of initial DOP stably, particle bound P, and P contained in Chl_sed a cannot be larger than TP_sed')
end
if (any(FIM0<0)|any(FIM0>1))
error('Initial fraction of inorganic matter in sediments must be between 0 and 1')
end
if (any(ksw>(H_sed*(1-F_sed_sld))))
error('Parameter ksw is larger than the volume (thickness) of porewater')
end %OBS! Ideally should also be that the daily diffused porewater should not be larger
%than the corresponding water layer volume, but this seems very unlike in practise
Tz = T0;
Cz = C0; % (mg m-3)
Sz = S0; % (kg m-3)
Chlz = Chl0; % (mg m-3)
DOPz = DOP0; % (mg m-3)
[Pz, trash] =Ppart(S0./rho_sed,TP0-DOP0-((Chl0 + C0)./Y_cp),Psat_L,Fmax_L,rho_sed,Fstable); % (mg m-3) NEW!!! SIMPLE
PPz = TP0-DOP0-((Chl0 + C0)./Y_cp)-Pz; % (mg m-3) NEW!!!
DOCz = DOC0; % (mg m-3)
F_IM = FIM0; %initial VOLUME fraction of inorganic particles of total dry sediment solids
%== P-partitioning in sediments==
%Pdz_store: %diss. inorg. P in sediment pore water (mg m-3)
%Psz_store: %P conc. in inorganic sediment particles (mg kg-1 dry w.)
[Pdz_store, Psz_store]=Ppart(VolFrac,TP0_sed-(Chl0_sed./Y_cp)-DOP0,Psat_L,Fmax_L_sed,rho_sed,Fstable);
%Chlsz_store: %Chla conc. in organic sediment particles (mg kg-1 dry w.)
Chlsz_store = Chl0_sed./(rho_org*F_sed_sld*(1-F_IM)); %(mg kg-1 dry w.)
% assume linear initial temperature profile in sediment (4 deg C at the bottom)
clear Tzy_sed
for j=1:Nz
Tzy_sed(:,j) = interp1([0.2 10], [Tz(j) 4], [0.2:0.2:2 2.5:0.5:10])';
end
S_resusp=S_res_hypo*ones(Nz,1); %hypolimnion resuspension assumed on the first time step
rho_snow=rho_new_snow; %initial snow density (kg m-3)
Tice=NaN; %ice surface temperature (initial value, deg C)
XE_melt=0; %energy flux that is left from last ice melting (initial value, W m-2)
XE_surf=0; %energy flux from water to ice (initial value, J m-2 per day)
%Initialisation of ice & snow variables
Hi=Ice0(1); %total ice thickness (initial value, m)
WEQs=(rho_snow/rho_fw)*Ice0(2); %snow water equivalent (initial value, m)
Hsi=0; %snow ice thickness (initial value = 0 m)
HFrazil=0; % (initial value, m) NEW!!!
if ((Hi<=0)&(WEQs>0))
error('Mismatch in initial ice and snow thicknesses')
end
if (Hi<=0)
IceIndicator=0; %IceIndicator==0 means no ice cover
else
IceIndicator=1;
end
pp=1; %initial indexes for ice freezing/melting date arrays
qq=1;
DoF=[]; %initialize
DoM=[]; %initialize
% >>>>>> Start of the time loop >>>>>>
Resuspension_counter=zeros(Nz,1); %kg
Sedimentation_counter=zeros(Nz,1); %kg
SS_decr=0; %kg
for i = 1:length(tt)
% Surface heat fluxes (W m-2), wind stress (N m-2) & daylight fraction (-), based on Air-Sea Toolbox
[Qsw,Qlw,Qsl,tau,DayFrac,DayFracHeating] = heatflux_v12(tt(i),Wt(i,1),Wt(i,2),Wt(i,3),Wt(i,4),Wt(i,5),Wt(i,6),Tz(1), ...
lat,lon,WEQs,Hi,alb_melt_ice,alb_melt_snow,albedot1); %Qlw and Qsl are functions of Tz(1)
% Calculate total mean PAR and non-PAR light extinction coefficient in water (background + due to Chl a)
lambdaz_wtot_avg=zeros(Nz,1);
lambdaz_NP_wtot_avg=zeros(Nz,1);
%NEW!!! below additional term for chlorophyll group 2
if (selfshading_switch==1)
lambdaz_wtot=swa_b1 * ones(Nz,1) + beta_chl*Chlz + beta_chl_2*Cz; %at layer z
lambdaz_NP_wtot=swa_b0 * ones(Nz,1) + beta_chl*Chlz + beta_chl_2*Cz; %at layer z
for j=1:Nz
lambdaz_wtot_avg(j)=mean(swa_b1 * ones(j,1) + beta_chl*Chlz(1:j) + beta_chl_2*Cz(1:j)); %average down to layer z
lambdaz_NP_wtot_avg(j)=mean(swa_b0 * ones(j,1) + beta_chl*Chlz(1:j) + beta_chl_2*Cz(1:j)); %average down to layer z
end
else %constant with depth
lambdaz_wtot=swa_b1 * ones(Nz,1);
lambdaz_wtot_avg=swa_b1 * ones(Nz,1);
lambdaz_NP_wtot=swa_b0 * ones(Nz,1);
lambdaz_NP_wtot_avg=swa_b0 * ones(Nz,1);
end %if selfshading...
if(IceIndicator==0)
IceSnowAttCoeff=1; %no extra light attenuation due to snow and ice
else %extra light attenuation due to ice and snow
IceSnowAttCoeff=exp(-lambda_i * Hi) * exp(-lambda_s * (rho_fw/rho_snow)*WEQs);
end
Tprof_prev=Tz; %temperature profile at previous time step (for convection_v12_1a.m)
rho = polyval(ies80,max(0,Tz(:))) + min(Tz(:),0); % Density (kg/m3)
% Sediment vertical heat flux, Q_sed
% (averaged over the whole top area of the layer, although actually coming only from the "sides")
if (sediment_heatflux_switch==1)
% update top sediment temperatures
dz_sf = 0.2; %fixed distance between the two topmost sediment layers (m)
Tzy_sed(1,:) = Tz';
Tzy_sed_upd = sedimentheat_v11(Tzy_sed, K_sed, dt);
Tzy_sed=Tzy_sed_upd;
Qz_sed=K_sed*rho_sed*cp_sed*(1/dz_sf)*(-diff([Az; 0])./Az) .* (Tzy_sed(2,:)'-Tzy_sed(1,:)'); %(J day-1 m-2)
%positive heat flux => from sediment to water
else
Qz_sed = zeros(Nz,1);
end
Cw = 4.18e+6; % Volumetric heat capacity of water (J K-1 m-3)
%Heat sources/sinks:
%Total attenuation coefficient profile, two-band extinction, PAR & non-PAR
Par_Attn=exp([0; -lambdaz_wtot_avg] .* [zz; zz(end)+dz]);
NonPar_Attn=exp([0; -lambdaz_NP_wtot_avg] .* [zz; zz(end)+dz]);
Attn_z=(-f_par * diff([1; ([Az(2:end);0]./Az).*Par_Attn(2:end)]) + ...
(-(1-f_par)) * diff([1; ([Az(2:end);0]./Az).*NonPar_Attn(2:end)])); %NEW (corrected 210807)
if(IceIndicator==0)
% 1) Vertical heating profile for open water periods (during daytime heating)
Qz = (Qsw + XE_melt) * Attn_z; %(W m-2)
Qz(1) = Qz(1) + DayFracHeating*(Qlw + Qsl); %surface layer heating
XE_melt=0; %Reset
dT = Az .* ((60*60*24*dt) * Qz + DayFracHeating*Qz_sed) ./ (Cw * Vz); %Heat source (K day-1) (daytime heating, ice melt, sediment);
% === Frazil ice melting, NEW!!! === %
postemp=find(dT>0);
if (isempty(postemp)==0)
RelT=dT(postemp)./sum(dT(postemp));
HFrazilnew=max(0, HFrazil - sum(dT(postemp))*1/((Az(1)*rho_ice*L_ice)/(Cw * Vz(1)))); %
sumdTnew = max(0, sum(dT(postemp))-(HFrazil*Az(1)*rho_ice*L_ice)/(Cw * Vz(1)));
dT(postemp)=RelT.*sumdTnew;
HFrazil=HFrazilnew;
end
% === === ===
else
% Vertical heating profile for ice-covered periods (both day- and nighttime)
Qz = Qsw * IceSnowAttCoeff * Attn_z; %(W/m2)
dT = Az .* ((60*60*24*dt) * Qz + Qz_sed) ./ (Cw * Vz); %Heat source (K day-1) (solar rad., sediment);
end
Tz = Tz + dT; %Temperature change after daytime surface heatfluxes (or whole day in ice covered period)
% Convective mixing adjustment (mix successive layers until stable density profile)
% and
% Spring/autumn turnover (don't allow temperature jumps over temperature of maximum density)
[Tz] = convection_v12_1a_simple(Tz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
% $$$ [Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz] = convection_v12_1a(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
Tprof_prev=Tz; %NEW!!! Update Tprof_prev
if(IceIndicator==0)
% 2) Vertical heating profile for open water periods (during nighttime heating)
[Qsw,Qlw_2,Qsl_2,tau,DayFrac,DayFracHeating] = heatflux_v12(tt(i),Wt(i,1),Wt(i,2),Wt(i,3),Wt(i,4),Wt(i,5),Wt(i,6),Tz(1), ...
lat,lon,WEQs,Hi,alb_melt_ice,alb_melt_snow,albedot1); %Qlw and Qsl are functions of Tz(1)
Qz(1) = (1-DayFracHeating)*(Qlw_2 + Qsl_2); %surface layer heating
Qz(2:end)=0; %No other heating below surface layer
dT = Az .* ((60*60*24*dt) * Qz + (1-DayFracHeating)*Qz_sed) ./ (Cw * Vz); %Heat source (K day-1) (longwave & turbulent fluxes);
% === NEW!!! frazil ice melting === %
postemp=find(dT>0);
if (isempty(postemp)==0)
%disp(['NOTE: positive night heat flux at T=' num2str(Tz(postemp),2)]) %NEW
RelT=dT(postemp)./sum(dT(postemp));
HFrazilnew=max(0, HFrazil - sum(dT(postemp))*1/((Az(1)*rho_ice*L_ice)/(Cw * Vz(1)))); %
sumdTnew = max(0, sum(dT(postemp))-(HFrazil*Az(1)*rho_ice*L_ice)/(Cw * Vz(1)));
dT(postemp)=RelT.*sumdTnew;
HFrazil=HFrazilnew;
end
% === === ===
Tz = Tz + dT; %Temperature change after nighttime surface heatfluxes
% Convective mixing adjustment (mix successive layers until stable density profile)
% and
% Spring/autumn turnover (don't allow temperature jumps over temperature of maximum density)
[Tz] = convection_v12_1a_simple(Tz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
% $$$ [Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz] = convection_v12_1a(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
Qlw = DayFracHeating*Qlw + (1-DayFracHeating)*Qlw_2; %total amounts, only for output purposes
Qsl = DayFracHeating*Qsl + (1-DayFracHeating)*Qsl_2; %total amounts, only for output purposes
end
% Vertical turbulent diffusion
g = 9.81; % Gravity acceleration (m s-2)
rho = polyval(ies80,max(0,Tz(:))) + min(Tz(:),0); % Water density (kg m-3)
% Note: in equations of rho it is assumed that every supercooled degree lowers density by
% 1 kg m-3 due to frazil ice formation (probably no practical meaning, but included for "safety")
N2 = g * (diff(log(rho)) ./ diff(zz)); % Brunt-Vaisala frequency (s-2) for level (zz+1)
if (IceIndicator==0)
Kz = Kz_K1 * max(Kz_N0, N2).^(-Kz_b1); % Vertical diffusion coeff. in ice free season (m2 day-1)
% for level (zz+1)
else
Kz = Kz_K1_ice * max(Kz_N0, N2).^(-Kz_b1_ice); % Vertical diffusion coeff. under ice cover (m2 day-1)
% for level (zz+1)
end
Fi = tridiag_DIF_v11([NaN; Kz],Vz,Az,dz,dt); %Tridiagonal matrix for general diffusion
Tz = Fi \ (Tz); %Solving new temperature profile (diffusion, sources/sinks already added to Tz above)
% $$$ %%%% SIMPLE2
% $$$ % Convective mixing adjustment (mix successive layers until stable density profile)
% $$$ % (don't allow temperature jumps over temperature of maximum density, no summer/autumn turnover here!)
% $$$ [Tz] = convection_v12_1a_simple(Tz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
% $$$ % $$$ [Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz] = convection_v12_1a(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
% $$$
% $$$
% $$$ % NEW!!! === Code rearranging
% $$$ % Calculate again the total mean PAR light extinction coefficient in water (background + due to Chl a)
% $$$ lambdaz_wtot_avg=zeros(Nz,1);
% $$$
% $$$ %NEW!!! below additional term for chlorophyll group 2
% $$$ if (selfshading_switch==1)
% $$$ lambdaz_wtot=swa_b1 * ones(Nz,1) + beta_chl*Chlz + beta_chl_2*Cz; %at layer z.
% $$$ for j=1:Nz
% $$$ lambdaz_wtot_avg(j)=mean(swa_b1 * ones(j,1) + beta_chl*Chlz(1:j) + beta_chl_2*Cz(1:j)); %average down to layer z
% $$$ end
% $$$ else %constant with depth
% $$$ lambdaz_wtot=swa_b1 * ones(Nz,1);
% $$$ lambdaz_wtot_avg=swa_b1 * ones(Nz,1);
% $$$ end %if selfshading...
% $$$
% $$$ %Photosynthetically Active Radiation (for chlorophyll group 1)
% $$$ H_sw_z=NaN*zeros(Nz,1);
% $$$
% $$$ % ===== NEW!!! bug (when Dayfrac==0) fixed 071107
% $$$ if ((IceIndicator==0)&(DayFrac>0))
% $$$ PAR_z=((3/2) / (e_par * DayFrac)) * f_par * Qsw * exp(-lambdaz_wtot_avg .* zz);
% $$$ %Irradiance at noon (mol m-2 s-1) at levels zz
% $$$ elseif ((IceIndicator==1)&(DayFrac>0)) %extra light attenuation due to ice and snow
% $$$ PAR_z=((3/2) / (e_par * DayFrac)) * IceSnowAttCoeff * f_par *...
% $$$ Qsw * exp(-lambdaz_wtot_avg .* zz);
% $$$ else PAR_z=zeros(Nz,1); %DayFrac==0, polar night
% $$$ end
% $$$ % =====
% $$$
% $$$ U_sw_z=PAR_z./PAR_sat; %scaled irradiance at levels zz
% $$$ inx_u=find(U_sw_z<=1); %undersaturated
% $$$ inx_s=find(U_sw_z>1); %saturated
% $$$
% $$$ H_sw_z(inx_u)=(2/3)*U_sw_z(inx_u); %undersaturated
% $$$
% $$$ dum_a=sqrt(U_sw_z);
% $$$ dum_b=sqrt(U_sw_z-1);
% $$$ H_sw_z(inx_s)=(2/3)*U_sw_z(inx_s) + log((dum_a(inx_s) + dum_b(inx_s))./(dum_a(inx_s) ... %saturated
% $$$ - dum_b(inx_s))) - (2/3)*(U_sw_z(inx_s)+2).*(dum_b(inx_s)./dum_a(inx_s));
% $$$
% $$$
% $$$ %NEW!!!! modified for chlorophyll group 1
% $$$ Growth_bioz=g_twty*theta_m.^(Tz-20) .* (Pz./(P_half+Pz)) .* (DayFrac./(dz*lambdaz_wtot)) .* diff([-H_sw_z; 0]);
% $$$ Loss_bioz=m_twty*theta_m.^(Tz-20);
% $$$ R_bioz = Growth_bioz-Loss_bioz;
% $$$
% $$$ %Photosynthetically Active Radiation (for chlorophyll group 2) NEW!!!
% $$$ H_sw_z=NaN*zeros(Nz,1);
% $$$
% $$$ U_sw_z=PAR_z./PAR_sat_2; %scaled irradiance at levels zz
% $$$ inx_u=find(U_sw_z<=1); %undersaturated
% $$$ inx_s=find(U_sw_z>1); %saturated
% $$$
% $$$ H_sw_z(inx_u)=(2/3)*U_sw_z(inx_u); %undersaturated
% $$$
% $$$ dum_a=sqrt(U_sw_z);
% $$$ dum_b=sqrt(U_sw_z-1);
% $$$ H_sw_z(inx_s)=(2/3)*U_sw_z(inx_s) + log((dum_a(inx_s) + dum_b(inx_s))./(dum_a(inx_s) ... %saturated
% $$$ - dum_b(inx_s))) - (2/3)*(U_sw_z(inx_s)+2).*(dum_b(inx_s)./dum_a(inx_s));
% $$$
% $$$ Growth_bioz_2=g_twty_2*theta_m.^(Tz-20) .* (Pz./(P_half_2+Pz)) .* (DayFrac./(dz*lambdaz_wtot)) .* diff([-H_sw_z; 0]);
% $$$ Loss_bioz_2=m_twty_2*theta_m.^(Tz-20);
% $$$ R_bioz_2 = Growth_bioz_2-Loss_bioz_2;
% $$$
% $$$ %growth rate is limited by available phosphorus
% $$$ exinx = find( (R_bioz.*Chlz*dt + R_bioz_2.*Cz*dt)>(Y_cp*Pz) );
% $$$
% $$$ if (isempty(exinx)==0)
% $$$ R_bioz_ratio = (R_bioz(exinx).*Chlz(exinx)*dt)./((R_bioz(exinx).*Chlz(exinx)*dt) + (R_bioz_2(exinx).*Cz(exinx)*dt)); %fraction of Growth rate 1 of total growth rate
% $$$ R_bioz(exinx) = R_bioz_ratio.*(Y_cp*Pz(exinx)./(Chlz(exinx)*dt));
% $$$ % R_bioz_2(exinx) =
% $$$ % (1-R_bioz_ratio).*(Y_cp*Pz(exinx)./(Cz(exinx)*dt)); %% quick
% $$$ % fix by KOJI 20110607
% $$$ end
% $$$ %================================
%%% SIMPLE2
%%% SIMPLE
% $$$ dDOP = dop_twty * DOPz .* theta_m.^(Tz-20); %Mineralisation to P
% $$$ DOPz = Fi \ (DOPz - dDOP); %Solving new dissolved inorganic P profile (diffusion)
% $$$
% $$$ % Suspended solids, particulate inorganic P
% $$$ Fi_ad = tridiag_HAD_v11([NaN; Kz],w_s,Vz,Az,dz,dt); %Tridiagonal matrix for advection and diffusion
% $$$
% $$$ dSz_inorg = rho_sed*S_resusp.*F_IM.*(-diff([Az; 0])./Vz); % Dry inorganic particle resuspension source from sediment (kg m-3 day-1)
%%% SIMPLE2 below (they don't need to be calculated as they are not
%needed for sediment calculations
% $$$ % $$$ Sz = Fi_ad \ (Sz + dSz_inorg); %Solving new suspended solids profile (advection + diffusion)
% $$$ % $$$
% $$$ dPP = dSz_inorg.*Psz_store; % PP resuspension source from sediment((kg m-3 day-1)*(mg kg-1) = mg m-3 day-1)
% $$$ % $$$ PPz = Fi_ad \ (PPz + dPP); %Solving new suspended particulate inorganic P profile (advection + diffusion)
% $$$ % $$$
% $$$ % $$$ %Chlorophyll, Group 1+2 resuspension (now divided 50/50 between the groups)
% $$$ dSz_org = rho_org*S_resusp.*(1-F_IM).*(-diff([Az; 0])./Vz); %Dry organic particle resuspension source from sediment (kg m-3 day-1)
% $$$ dChl_res = dSz_org.*Chlsz_store; %Chl a resuspension source from sediment resusp. ((kg m-3 day-1)*(mg kg-1) = mg m-3 day-1);
% $$$ % $$$
% $$$ % $$$ %Chlorophyll, Group 1
% $$$ % $$$ dChl_growth = Chlz .* R_bioz; %Chl a growth source
% $$$ % $$$ dChl = dChl_growth + 0.5*dChl_res; % Total Chl a source (resuspension 50/50 between the two groups, NEW!!!)
% $$$ Fi_ad = tridiag_HAD_v11([NaN; Kz],w_chl,Vz,Az,dz,dt); %Tridiagonal matrix for advection and diffusion
% $$$ Chlz = Fi_ad \ (Chlz + dChl); %Solving new phytoplankton profile (advection + diffusion) (always larger than background level)
% $$$
% $$$ %Chlorophyll, Group 2
% $$$ dCz_growth = Cz .* R_bioz_2; %Chl a growth source
% $$$ dCz = dCz_growth + 0.5*dChl_res; % Total Chl a source (resuspension 50/50 between the two groups, NEW!!!)
% $$$ Fi_ad = tridiag_HAD_v11([NaN; Kz],w_chl_2,Vz,Az,dz,dt); %Tridiagonal matrix for advection and diffusion
% $$$ Cz = Fi_ad \ (Cz + dCz); %Solving new phytoplankton profile (advection + diffusion) (always larger than background level)
% $$$
% $$$ %Dissolved inorganic phosphorus
% $$$ dP = dDOP - (dChl_growth + dCz_growth)./ Y_cp; %DOP source, P sink = Chla growth source !!!NEW
% $$$ Pz = Fi \ (Pz + dP); %Solving new dissolved inorganic P profile (diffusion)
% $$$
% $$$ %Dissolved organic carbon
% $$$ dDOC = -oc_DOC*qy_DOC*f_par*(1/e_par)*(60*60*24*dt)*Qsw*Attn_z; %photochemical degradation
% $$$ %[m2/mg_doc]*[mg_doc/mol_qnt]*[-]*[mol_qnt/J]*[s/day]*[J/s/m2]*[-] = [1/day]
% $$$ DOCz = Fi \ (DOCz + dDOC.*DOCz); %Solving new dissolved inorganic P profile (diffusion)
% $$$
%%%%%% SIMPLE
%%%%%% SIMPLE2
% $$$ %Sediment-water exchange (DOP source neglected)
% $$$ %-porewater to water
% $$$
% $$$ PwwFrac=ksw*(-diff([Az; 0]))./Vz; %fraction between resuspended porewater and water layer volumes
% $$$ %PwwFrac=(((1-F_sed_sld)/F_sed_sld)*S_resusp.*(-diff([Az; 0]))./Vz); %fraction between resuspended porewater and water layer volumes
% $$$ EquP1 = (1-PwwFrac).*Pz + PwwFrac.*Pdz_store; %Mixture of porewater and water
% $$$ dPW_up = EquP1-Pz; %"source/sink" for output purposes
% $$$
% $$$ %-water to porewater
% $$$ PwwFrac=ksw./((1-F_sed_sld)*H_sed); %NEW testing 3.8.05; fraction between resuspended (incoming) water and sediment layer volumes
% $$$ %PwwFrac=S_resusp./(F_sed_sld*H_sed); %fraction between resuspended (incoming) water and sediment layer volumes
% $$$ EquP2 = PwwFrac.*Pz + (1-PwwFrac).*Pdz_store; %Mixture of porewater and water
% $$$ dPW_down = EquP2-Pdz_store; %"source/sink" for output purposes
% $$$
% $$$ %-update concentrations
% $$$ Pz = EquP1;
% $$$ Pdz_store=EquP2;
% $$$
% $$$
% $$$ %Calculate the thickness ratio of newly settled net sedimentation and mix these
% $$$ %two to get new sediment P concentrations in sediment (taking into account particle resuspension)
% $$$ delPP_inorg=NaN*ones(Nz,1); %initialize
% $$$ delC_inorg=NaN*ones(Nz,1); %initialize
% $$$ delC_org=NaN*ones(Nz,1); %initialize
% $$$ delC_org2=NaN*ones(Nz,1); %initialize % NEW!!! for chlorophyll group 2
% $$$
% $$$ delA=diff([Az; 0]); %Area difference for layer i (OBS: negative)
% $$$ meanA=0.5*(Az+[Az(2:end); 0]);
% $$$
% $$$ %sedimentation is calculated from "Funnelling-NonFunnelling" difference
% $$$ %(corrected 03.10.05)
% $$$ delPP_inorg(1)=(0 - PPz(1)*delA(1)./meanA(1))./(dz/(dt*w_s) + 1);
% $$$ delC_inorg(1)=(0 - Sz(1)*delA(1)./meanA(1))./(dz/(dt*w_s) + 1);
% $$$ delC_org(1)=(0 - Chlz(1)*delA(1)./meanA(1))./(dz/(dt*w_chl) + 1);
% $$$ delC_org2(1)= (0 - Cz(1)*delA(1)./meanA(1))./(dz/(dt*w_chl_2) + 1); % NEW!!! for chlorophyll group 2
% $$$
% $$$ for ii=2:Nz
% $$$ delPP_inorg(ii)=(delPP_inorg(ii-1) - PPz(ii)*delA(ii)./meanA(ii))./(dz/(dt*w_s) + 1); %(mg m-3)
% $$$ delC_inorg(ii)=(delC_inorg(ii-1) - Sz(ii)*delA(ii)./meanA(ii))./(dz/(dt*w_s) + 1); %(kg m-3)
% $$$ delC_org(ii)=(delC_org(ii-1) - Chlz(ii)*delA(ii)./meanA(ii))./(dz/(dt*w_chl) + 1); %(mg m-3)
% $$$ delC_org2(ii)=(delC_org2(ii-1) - Cz(ii)*delA(ii)./meanA(ii))./(dz/(dt*w_chl_2) + 1); %(mg m-3) % NEW!!! for chlorophyll group 2
% $$$ end
% $$$
% $$$ H_netsed_inorg=max(0, (Vz./(-diff([Az; 0]))).*delC_inorg./rho_sed - F_IM.*S_resusp); %inorganic(m day-1, dry), always positive
% $$$ H_netsed_org=max(0, (Vz./(-diff([Az; 0]))).*(delC_org+delC_org2)./(F_OM*Y_cp*rho_org) - (1-F_IM).*S_resusp); %organic (m day-1, dry), always positive, NEW!!! for chlorophyll group 2
% $$$
% $$$ H_totsed=H_netsed_org + H_netsed_inorg; %total (m day-1), always positive
% $$$
% $$$ F_IM_NewSed=F_IM;
% $$$ inx=find(H_totsed>0);
% $$$ F_IM_NewSed(inx)=H_netsed_inorg(inx)./H_totsed(inx); %volume fraction of inorganic matter in net settling sediment
% $$$
% $$$ NewSedFrac = min(1, H_totsed./(F_sed_sld*H_sed)); %Fraction of newly fallen net sediment of total active sediment depth, never above 1
% $$$ NewSedFrac_inorg = min(1, H_netsed_inorg./(F_IM.*F_sed_sld*H_sed)); %Fraction of newly fallen net inorganic sediment of total active sediment depth, never above 1
% $$$ NewSedFrac_org = min(1, H_netsed_org./((1-F_IM).*F_sed_sld*H_sed)); %Fraction of newly fallen net organic sediment of total active sediment depth, never above 1
% $$$
% $$$ %Psz_store: %P conc. in inorganic sediment particles (mg kg-1 dry w.)
% $$$ Psz_store = (1-NewSedFrac_inorg).*Psz_store + NewSedFrac_inorg.*PPz./Sz; %(mg kg-1)
% $$$
% $$$ %Update counters
% $$$ Sedimentation_counter = Sedimentation_counter + Vz.*(delC_inorg + (delC_org+delC_org2)./(F_OM*Y_cp)); %Inorg.+Org. (kg)
% $$$ Resuspension_counter = Resuspension_counter + Vz.*(dSz_inorg + dSz_org); %Inorg.+Org. (kg)
% $$$
% $$$ %Chlsz_store (for group 1+2): %Chl a conc. in sediment particles (mg kg-1 dry w.)
% $$$ Chlsz_store = (1-NewSedFrac_org).*Chlsz_store + NewSedFrac_org.*F_OM*Y_cp; %(mg kg-1)
% $$$ %Subtract degradation to P in pore water
% $$$ Chlz_seddeg = k_twty * Chlsz_store .* theta_m.^(Tz-20);
% $$$ Chlsz_store = Chlsz_store - Chlz_seddeg;
% $$$ Pdz_store=Pdz_store + Chlz_seddeg .* (rho_org*F_sed_sld*(1-F_IM))./Y_cp;
% $$$
% $$$ %== P-partitioning in sediments==
% $$$ VolFrac=1./(1+(1-F_sed_sld)./(F_sed_sld*F_IM)); %volume fraction: inorg sed. / (inorg.sed + pore water)
% $$$ TIP_sed =rho_sed*VolFrac.*Psz_store + (1-VolFrac).*Pdz_store; %total inorganic P in sediments (mg m-3)
% $$$ % $$$ [Pdz_store, Psz_store]=Ppart(VolFrac,TIP_sed,Psat_L,Fmax_L_sed,rho_sed,Fstable); SIMPLE
% $$$ %calculate new VOLUME fraction of inorganic particles of total dry sediment
% $$$ F_IM=min(1,((k_twty *(1-F_IM).*theta_m.^(Tz-20)) + F_IM)).*(1-NewSedFrac) + F_IM_NewSed.*NewSedFrac;
%%%%% SIMPLE2
% Inflow calculation
% Inflw(:,1) Inflow volume (m3 day-1)
% Inflw(:,2) Inflow temperature (deg C)
% Inflw(:,3) Inflow chlorophyll (group 2) concentration (-)
% Inflw(:,4) Inflow sedimenting tracer (or suspended inorganic matter) concentration (kg m-3)
% Inflw(:,5) Inflow total phosphorus (TP) concentration (incl. DOP & Chla) (mg m-3)
% Inflw(:,6) Inflow dissolved organic phosphorus (DOP) concentration (mg m-3)
% Inflw(:,7) Inflow chlorophyll (group 1) concentration (mg m-3)
% Inflw(:,8) Inflow DOC concentration (mg m-3)
if (river_inflow_switch==1)
Iflw = I_scV * Inflw(i,1); % (scaled) inflow rate
Iflw_T = I_scT + Inflw(i,2); %(adjusted) inflow temperature
if (Iflw_T<Tf) %negative temperatures changed to Tf
Iflw_T=Tf;
end
Iflw_C = I_scC * Inflw(i,3); %(scaled) inflow C concentration
Iflw_S = I_scS * Inflw(i,4); %(scaled) inflow S concentration
Iflw_TP = I_scTP * Inflw(i,5); %(scaled) inflow TP concentration (incl. DOP & Chla)
Iflw_DOP = I_scDOP * Inflw(i,6); %(scaled) inflow DOP concentration
Iflw_Chl = I_scChl * Inflw(i,7); %(scaled) inflow Chl a concentration
Iflw_DOC = I_scDOC * Inflw(i,8); %(scaled) inflow DOC concentration
%Added suspended solids correction: minimum allowed P bioavailability factor is 0.1
if any((1-(Iflw_DOP+(Iflw_Chl+Iflw_C)./Y_cp)./Iflw_TP-(Iflw_S*Fstable)./Iflw_TP)<0.1); % NEW!!!!
Iflw_S_dum = (1 - (Iflw_DOP+(Iflw_Chl+Iflw_C)./Y_cp)./Iflw_TP - 0.1).*(Iflw_TP./Fstable); %NEW!!!
SS_decr=SS_decr+(Iflw_S-Iflw_S_dum)*Iflw;
Iflw_S=Iflw_S_dum;
end
if any((Iflw_TP-Iflw_DOP-(Iflw_Chl+Iflw_C)./Y_cp-Iflw_S*Fstable)<0) %NEW!!!
error('Sum of DOP, inactive PP, and P contained in Chl a (both groups) in inflow cannot be larger than TP')
end
if(Iflw>0)
if (isnan(Iflw_T))
lvlD=0;
Iflw_T=Tz(1);
else
rho = polyval(ies80,max(0,Tz(:)))+min(Tz(:),0); % Density (kg/m3)
rho_Iflw=polyval(ies80,max(0,Iflw_T))+min(Iflw_T,0);
lvlG=find(rho>=rho_Iflw);
if (isempty(lvlG))
lvlG=length(rho);
end
lvlD=zz(lvlG(1)); %level zz above which inflow is put
end %if isnan...
%Changes in properties due to inflow
dummy=IOflow_v11(dz, zz, Vz, Tz, lvlD, Iflw, Iflw_T);
Tz=dummy; %Temperature
dummy=IOflow_v11(dz, zz, Vz, Sz, lvlD, Iflw, Iflw_S);
Sz=dummy; %Sedimenting tracer
dummy=IOflow_v11(dz, zz, Vz, DOPz, lvlD, Iflw, Iflw_DOP);
DOPz=dummy; %Particulate organic P
TIPz=Pz + PPz; % Total inorg. phosphorus (excl. Chla and DOP) in the water column (mg m-3)
dummy=IOflow_v11(dz, zz, Vz, TIPz, lvlD, Iflw, Iflw_TP-((Iflw_Chl+Iflw_C)./Y_cp)-Iflw_DOP); %NEW!!!
TIPz=dummy; %Total inorg. phosphorus (excl. Chla and DOP)
%== P-partitioning in water==
% $$$ [Pz, trash]=Ppart(Sz./rho_sed,TIPz,Psat_L,Fmax_L,rho_sed,Fstable); SIMPLE
PPz=TIPz-Pz;
dummy=IOflow_v11(dz, zz, Vz, Cz, lvlD, Iflw, Iflw_C);
Cz=dummy; %Chlorophyll (group 2)
dummy=IOflow_v11(dz, zz, Vz, Chlz, lvlD, Iflw, Iflw_Chl);
Chlz=dummy; %Chlorophyll (group 1)
dummy=IOflow_v11(dz, zz, Vz, DOCz, lvlD, Iflw, Iflw_DOC);
DOCz=dummy; %DOC
else
lvlD=NaN;
end %if(Iflw>0)
else
Iflw=0; % (scaled) inflow rate
Iflw_T = NaN; %(adjusted) inflow temperature
Iflw_C = NaN; %(scaled) inflow C concentration
Iflw_S = NaN; %(scaled) inflow S concentration
Iflw_TP = NaN; %(scaled) inflow TP concentration (incl. DOP & Chla)
Iflw_DOP = NaN; %(scaled) inflow DOP concentration
Iflw_Chl = NaN; %(scaled) inflow Chl a concentration
Iflw_DOC = NaN; %(scaled) inflow DOC concentration
lvlD=NaN;
end %if (river_inflow_switch==1)
% Convective mixing adjustment (mix successive layers until stable density profile, no summer/autumn turnover here!)
[Tz] = convection_v12_1a_simple(Tz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
% $$$ [Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz] = convection_v12_1a(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,1);
if (IceIndicator==0)
TKE=C_shelter*Az(1)*sqrt(tau^3/rho(1))*(24*60*60*dt); %Turbulent kinetic energy (J day-1) over the whole lake
%Wind mixing
WmixIndicator=1;
Bef_wind=sum(diff(rho)==0); %just a watch variable
while (WmixIndicator==1)
d_rho=diff(rho);
inx=find(d_rho>0);
if (isempty(inx)==0); %if water column not already fully mixed
zb=inx(1);
MLD=dz*zb; %mixed layer depth
dD=d_rho(zb); %density difference
Zg=sum( Az(1:zb+1) .* zz(1:zb+1) ) / sum(Az(1:zb+1)); %Depth of center of mass of mixed layer
V_weight=Vz(zb+1)*sum(Vz(1:zb))/(Vz(zb+1)+sum(Vz(1:zb)));
POE=(dD*g*V_weight*(MLD + dz/2 - Zg));
KP_ratio=TKE/POE;
if (KP_ratio>=1)
Tmix=sum( Vz(1:zb+1).*Tz(1:zb+1) ) / sum(Vz(1:zb+1));
Tz(1:zb+1)=Tmix;
%%%%% SIMPLE
% $$$ Cmix=sum( Vz(1:zb+1).*Cz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ Cz(1:zb+1)=Cmix;
% $$$
% $$$ Smix=sum( Vz(1:zb+1).*Sz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ Sz(1:zb+1)=Smix;
% $$$
% $$$ Pmix=sum( Vz(1:zb+1).*Pz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ Pz(1:zb+1)=Pmix;
% $$$
% $$$ Chlmix=sum( Vz(1:zb+1).*Chlz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ Chlz(1:zb+1)=Chlmix;
% $$$
% $$$ PPmix=sum( Vz(1:zb+1).*PPz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ PPz(1:zb+1)=PPmix;
% $$$
% $$$ DOPmix=sum( Vz(1:zb+1).*DOPz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ DOPz(1:zb+1)=DOPmix;
% $$$
% $$$ DOCmix=sum( Vz(1:zb+1).*DOCz(1:zb+1) ) / sum(Vz(1:zb+1));
% $$$ DOCz(1:zb+1)=DOCmix;
%%%%% SIMPLE
rho = polyval(ies80,max(0,Tz(:))) + min(Tz(:),0);
TKE=TKE-POE;
else %if KP_ratio < 1, then mix with the remaining TKE part of the underlying layer
Tmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*Tz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
Tz(1:zb)=Tmix;
Tz(zb+1)=KP_ratio*Tmix + (1-KP_ratio)*Tz(zb+1);
%%%% SIMPLE
% $$$ Cmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*Cz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ Cz(1:zb)=Cmix;
% $$$ Cz(zb+1)=KP_ratio*Cmix + (1-KP_ratio)*Cz(zb+1);
% $$$
% $$$ Smix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*Sz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ Sz(1:zb)=Smix;
% $$$ Sz(zb+1)=KP_ratio*Smix + (1-KP_ratio)*Sz(zb+1);
% $$$
% $$$ Pmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*Pz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ Pz(1:zb)=Pmix;
% $$$ Pz(zb+1)=KP_ratio*Pmix + (1-KP_ratio)*Pz(zb+1);
% $$$
% $$$ Chlmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*Chlz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ Chlz(1:zb)=Chlmix;
% $$$ Chlz(zb+1)=KP_ratio*Chlmix + (1-KP_ratio)*Chlz(zb+1);
% $$$
% $$$ PPmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*PPz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ PPz(1:zb)=PPmix;
% $$$ PPz(zb+1)=KP_ratio*PPmix + (1-KP_ratio)*PPz(zb+1);
% $$$
% $$$ DOPmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*DOPz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ DOPz(1:zb)=DOPmix;
% $$$ DOPz(zb+1)=KP_ratio*DOPmix + (1-KP_ratio)*DOPz(zb+1);
% $$$
% $$$ DOCmix=sum( [Vz(1:zb); KP_ratio*Vz(zb+1)].*DOCz(1:zb+1) ) / sum([Vz(1:zb); KP_ratio*Vz(zb+1)]);
% $$$ DOCz(1:zb)=DOCmix;
% $$$ DOCz(zb+1)=KP_ratio*DOCmix + (1-KP_ratio)*DOCz(zb+1);
%%% SIMPLE
rho = polyval(ies80,max(0,Tz(:))) + min(Tz(:),0);
TKE=0;
WmixIndicator=0;
end %if (KP_ratio>=1)
else
WmixIndicator=0;
end %if water column (not) already mixed
end %while
Aft_wind=sum(diff(rho)==0); %just a watch variable
else % ice cover module
XE_surf=(Tz(1)-Tf) * Cw * dz; %Daily heat accumulation into the first water layer (J m-2)
Tz(1)=Tf; %Ensure that tem
Tice=Tf; %ice surface at freezing point
dWEQnews=0; %No new snowperature of the first water layer is kept at freezing point
TKE=0; %No energy for wind mixing under ice
if (Wt(i,3)<Tf) %if air temperature is below freezing
%Calculate ice surface temperature (Tice)
if(WEQs==0) %if no snow
alfa=1/(10*Hi);
dHsi=0;
else
K_snow=2.22362*(rho_snow/1000)^1.885; %Yen (1981)
alfa=(K_ice/K_snow)*(((rho_fw/rho_snow)*WEQs)/Hi);
%Slush/snow ice formation (directly to ice)
dHsi=max([0, Hi*(rho_ice/rho_fw-1)+WEQs]);
Hsi=Hsi+dHsi;
end
Tice=(alfa*Tf+Wt(i,3))/(1+alfa);
%Ice growth by Stefan's law
Hi_new=sqrt((Hi+dHsi)^2+(2*K_ice/(rho_ice*L_ice))*(24*60*60)*(Tf-Tice));
%snow fall
dWEQnews=0.001*Wt(i,7); %mm->m
dWEQs=dWEQnews-dHsi*(rho_ice/rho_fw); % new precipitation minus snow-to-snowice in snow water equivalent
dHsi=0; %reset new snow ice formation
else %if air temperature is NOT below freezing
Tice=Tf; %ice surface at freezing point
dWEQnews=0; %No new snow
if (WEQs>0)
%snow melting in water equivalents
dWEQs=-max([0, (60*60*24)*(((1-IceSnowAttCoeff)*Qsw)+Qlw+Qsl)/(rho_fw*L_ice)]);
if ((WEQs+dWEQs)<0) %if more than all snow melts...
Hi_new=Hi+(WEQs+dWEQs)*(rho_fw/rho_ice); %...take the excess melting from ice thickness
else
Hi_new=Hi; %ice does not melt until snow is melted away
end
else
%total ice melting
dWEQs=0;
Hi_new=Hi-max([0, (60*60*24)*(((1-IceSnowAttCoeff)*Qsw)+Qlw+Qsl)/(rho_ice*L_ice)]);
%snow ice part melting
Hsi=Hsi-max([0, (60*60*24)*(((1-IceSnowAttCoeff)*Qsw)+Qlw+Qsl)/(rho_ice*L_ice)]);
if (Hsi<=0)
Hsi=0;
end
end %if there is snow or not
end %if air temperature is or isn't below freezing
%Update ice and snow thicknesses
Hi=Hi_new-(XE_surf/(rho_ice*L_ice)); %new ice thickness (minus melting due to heat flux from water)
XE_surf=0; %reset energy flux from water to ice (J m-2 per day)
WEQs=WEQs+dWEQs; %new snow water equivalent
if(Hi<Hsi)
Hsi=max(0,Hi); %to ensure that snow ice thickness does not exceed ice thickness
%(if e.g. much ice melting much from bottom)
end
if(WEQs<=0)
WEQs=0; %excess melt energy already transferred to ice above
rho_snow=rho_new_snow;
else
%Update snow density as weighed average of old and new snow densities
rho_snow=rho_snow*(WEQs-dWEQnews)/WEQs + rho_new_snow*dWEQnews/WEQs;
if (snow_compaction_switch==1)
%snow compaction
if (Wt(i,3)<Tf) %if air temperature is below freezing
rhos=1e-3*rho_snow; %from kg/m3 to g/cm3
delta_rhos=24*rhos*C1*(0.5*WEQs)*exp(-C2*rhos)*exp(-0.08*(Tf-0.5*(Tice+Wt(i,3))));
rho_snow=min([rho_snow+1e+3*delta_rhos, max_rho_snow]); %from g/cm3 back to kg/m3
else
rho_snow=max_rho_snow;
end
end
end
if(Hi<=0)
IceIndicator=0;
disp(['Ice-off, ' datestr(datenum(M_start)+i-1)])
XE_melt=(-Hi-(WEQs*rho_fw/rho_ice))*rho_ice*L_ice/(24*60*60);
%(W m-2) snow part is in case ice has melted from bottom leaving some snow on top (reducing XE_melt)
Hi=0;
WEQs=0;
Tice=NaN;
DoM(pp)=i;
pp=pp+1;
end
end %of ice cover module
%== P-partitioning in water==
TIPz=Pz + PPz; % Total inorg. phosphorus (excl. Chla and DOP) in the water column (mg m-3)
% $$$ [Pz, trash]=Ppart(Sz./rho_sed,TIPz,Psat_L,Fmax_L,rho_sed,Fstable);
PPz=TIPz-Pz;
%Initial freezing
Supercooled=find(Tz<Tf);
if (isempty(Supercooled)==0)
%===NEW!!! (040707)
if(Supercooled(1)~=1); disp('NOTE: non-surface subsurface supercooling'); end;
InitIceEnergy=sum((Tf-Tz(Supercooled)).*Vz(Supercooled)*Cw);
HFrazil=HFrazil+(InitIceEnergy/(rho_ice*L_ice))/Az(1);
Tz(Supercooled)=Tf;
if ((IceIndicator==0)&(HFrazil > Frazil2Ice_tresh))
IceIndicator=1;
Hi=Hi+HFrazil;
HFrazil=0;
DoF(qq)=i;
disp(['Ice-on, ' datestr(datenum(M_start)+i-1)])
qq=qq+1;
end
if (IceIndicator==1)
Hi=Hi+HFrazil;
HFrazil=0;
end
Tz(1)=Tf; %set temperature of the first layer to freezing point
%======================