-
Notifications
You must be signed in to change notification settings - Fork 0
/
solvemodel_v2.m
1887 lines (1546 loc) · 89.2 KB
/
solvemodel_v2.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.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_v2.m code)
%
% Main module
% Code checked by TSA, xx.xx.200x
% Last modified by TSA, 21.08.2007
% Modified to include Fokema-module by Kai Rasmus. 16.5.2007
% Modified to include the latest Fokema module 30.12.2010 by PK
% New matrices: DOCzt1,DOCzt2,DOCzt3,Daily_BB1t,Daily_BB2t,Daily_BB3t,Daily_PBt
% New DIC variable 29.12.2010 (incl. inflow, convection, diffusion) by PK
% New O2 variable 10.2.2011 by PK
function [zz,Az,Vz,tt,Qst,Kzt,Tzt,Czt,Szt,Pzt,Chlzt,PPzt,DOPzt,DOCzt,DICzt,CO2zt,O2zt,NO3zt,NH4zt,SO4zt,HSzt,H2Szt,Fe2zt,Ca2zt,pHzt,CH4zt,Fe3zt,Al3zt,SiO4zt,SiO2zt,diatomzt,O2_sat_relt,O2_sat_abst,BODzt,Qzt_sed,lambdazt,...
P3zt_sed,P3zt_sed_sc,His,DoF,DoM,MixStat,Wt,surfaceflux,O2fluxt,CO2_eqt,K0t,O2_eqt,K0_O2t,...
CO2_ppmt,dO2Chlt,dO2BODt,dphotoDOCt,delC_org3,testi1t,testi2t,testi3t,...
sediment_results] = ...
solvemodel_v2(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_DICz : Initial DIC profile read from initial profiles file (mg m-3) (PK)
% In_O2z : Initial oxygen profile read from initial profiles file (mg m-3) (PK)
% 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) profileo (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)
% DICzt : Predicted dissolved inorganic carbon (DIC) profile (tt * zz) (mg m-3) (PK)
% CO2zt : Predicted dissolved carbon dioxide profile (tt * zz) (mg m-3) (PK)
% O2zt : Predicted dissolved oxygen profile (tt * zz) (mg m-3) (PK)
% O2_sat_rel : Predicted relative oxygen saturation (PK)
% O2_sat_abs : Predicted absolute oxygen saturation (PK)
% 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)
% Fokema outputs
% CDOMzt : Coloured dissolved organic matter absorption m-1
% : (tt * zz)
% These variables are still global and not transferred by functions
global ies80 O2_diffzt;
tic
disp(['Running MyLake-DOCOMO 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
deposition_switch= 0; %human impact, atm deposition , point source addition %% NEW_DOCOMO
sediment_heatflux_switch=1; %heatflux from sediments: 0=no, 1=yes
selfshading_switch=1; %light attenuation by chlorophyll a: 0=no, 1=yes
tracer_switch=1; %simulate tracers: 0=no, 1=yes
matsedlab_sediments_module = 1; %MATSEDLAB sediment module %% NEW_DOCOMO
%fokema
photobleaching=0; %photo bleaching: 0=TSA model, 1=FOKEMA model
flocculation_switch=1; % flocculation according to Wachenfeldt 2008 %% NEW_DOCOMO
% ==============
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_DICz,In_O2z,In_NO3z,In_NH4z,In_SO4z,In_HSz,In_H2Sz,In_Fe2z,In_Ca2z,In_pHz,In_CH4z,In_Fe3z,In_Al3z,In_SiO4z,In_SiO2z,In_diatomz,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, Deposition]...
= 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_DICz,In_O2z,In_NO3z,In_NH4z,In_SO4z,In_HSz,In_H2Sz,In_Fe2z,In_Ca2z,In_pHz,In_CH4z,In_Fe3z,In_Al3z,In_SiO4z,In_SiO2z,In_diatomz,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(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 (-)
I_scDIC = Bio_par(32); %Scaling factor for inflow concentration of DOC (-)
I_scO = Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scNO3 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scNH4 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scSO4 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scFe2 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scCa2 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scpH = 1;% Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scCH4 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scFe3 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scAl3 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scSiO4 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scSiO2 = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
I_scdiatom = 1;%Bio_par(37); %scaling factor for inflow concentration of O2 (-)
% 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)
%===========
% Parameters for oxygen
k_BOD = Bio_par(24); %Organic decomposition rate (1/d)
k_SOD = Bio_par(25); %Sedimentary oxygen demand (mg m-2 d-1)
theta_bod = Bio_par(26); %Temperature adjustment coefficient for BOD, T ? 10 °C
theta_bod_ice = Bio_par(27); %Temperature adjustment coefficient for BOD, T < 10 °C
theta_sod = Bio_par(28); %Temperature adjustment coefficient for SOD, T ? 10 °C
theta_sod_ice = Bio_par(29); %Temperature adjustment coefficient for SOD, T < 10 °C
BOD_temp_switch = Bio_par(30); %Threshold for bod or bod_ice °C
% Parameters for dissolved inorganic carbon
pH = Bio_par(31); %Lake water pH
Mass_Ratio_C_Chl = Bio_par(33); % Fixed empirical ratio C:Chl (mass/mass)
I_scDIC = Bio_par(32); %Scaling factor for inflow concentration of DOC (-)
SS_C = Bio_par(34); % Carbon fraction in H_netsed_catch
density_org_H_nc = Bio_par(35); % Density of organic fraction in H_netsed_catch [g cm-3]
density_inorg_H_nc = Bio_par(36);% Density of inorganic fraction in H_netsed_catch [g cm-3]
% ====== 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));
DICzt = zeros(Nz,length(tt));
CO2zt = zeros(Nz,length(tt));
O2zt = zeros(Nz,length(tt));
NO3zt = zeros(Nz,length(tt));
NH4zt = zeros(Nz,length(tt));
SO4zt = zeros(Nz,length(tt));
HSzt = zeros(Nz,length(tt));
H2Szt = zeros(Nz,length(tt));
Fe2zt = zeros(Nz,length(tt));
Ca2zt = zeros(Nz,length(tt));
pHzt = zeros(Nz,length(tt));
CH4zt = zeros(Nz,length(tt));
Fe3zt = zeros(Nz,length(tt));
Al3zt = zeros(Nz,length(tt));
SiO4zt = zeros(Nz,length(tt));
SiO2zt = zeros(Nz,length(tt));
diatomzt = zeros(Nz,length(tt));
O2_diffzt = zeros(Nz,length(tt));
O2_sat_relt = zeros(Nz,length(tt));
O2_sat_abst = 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(23,length(tt));
% Fokema
CDOMzt=zeros(Nz,length(tt));
DOCzt1=zeros(Nz,length(tt)); %Fokema-model subpool 1
DOCzt2=zeros(Nz,length(tt)); %Fokema-model subpool 2
DOCzt3=zeros(Nz,length(tt)); %Fokema-model subpool 3
DOC1tfrac=zeros(Nz,length(tt)); %Fokema-model subpool 1
DOC2tfrac=zeros(Nz,length(tt)); %Fokema-model subpool 2 fraction
DOC3tfrac=zeros(Nz,length(tt)); %Fokema-model subpool 3 fraction
Daily_BB1t=zeros(Nz,length(tt)); %Fokema-model subpool 1 daily bacterial decomposition
Daily_BB2t=zeros(Nz,length(tt)); %Fokema-model subpool 2 daily bacterial decomposition
Daily_BB3t=zeros(Nz,length(tt)); %Fokema-model subpool 3 daily bacterial decomposition
Daily_PBt=zeros(Nz,length(tt)); %Fokema-model daily photobleaching
surfaceflux = zeros(1,length(tt)); %CO2 surface flux
CO2_eqt = zeros(1,length(tt)); %CO2 equilibrium concentration
CO2_ppmt = zeros(1,length(tt)); %CO2 fraction in air
K0t = zeros(1,length(tt)); %CO2 solubility coefficient
O2fluxt = zeros(1,length(tt)); %oxygen surface flux
O2_eqt = zeros(1,length(tt)); %O2 equilibrium concentration
K0_O2t = zeros(1,length(tt)); %O2 solubility coefficient
dO2Chlt = zeros(Nz,length(tt)); %Oxygen change due to phytoplankton (mg m-3))
dO2BODt = zeros(Nz,length(tt)); %Oxygen consumption due to BOD (mg m-3))
dphotoDOCt = zeros(Nz,length(tt)); %DOC loss due to photodeg (mg m-3))
% dO2SODt = zeros(Nz,length(tt)); %Oxygen consumption due to SOD (mg m-3))
testi1t = zeros(Nz,length(tt));
testi2t = zeros(Nz,length(tt));testi3t = zeros(Nz,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)
DIC0 = interp1(In_Z,In_DICz,zz+dz/2); % Initial DIC distribution (mg m-3)
O20 = interp1(In_Z,In_O2z,zz+dz/2); % Initial oxygen 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 (-)
NO30 = interp1(In_Z,In_NO3z,zz+dz/2);
NH40 = interp1(In_Z,In_NH4z,zz+dz/2);
SO40 = interp1(In_Z,In_SO4z,zz+dz/2);
HS0 = interp1(In_Z,In_HSz,zz+dz/2);
H2S0 = interp1(In_Z,In_H2Sz,zz+dz/2);
Fe20 = interp1(In_Z,In_Fe2z,zz+dz/2);
Ca20 = interp1(In_Z,In_Ca2z,zz+dz/2);
pH0 = interp1(In_Z,In_pHz,zz+dz/2);
CH40 = interp1(In_Z,In_CH4z,zz+dz/2);
Fe30 = interp1(In_Z,In_Fe3z,zz+dz/2);
Al30 = interp1(In_Z,In_Al3z,zz+dz/2);
SiO40 = interp1(In_Z,In_SiO4z,zz+dz/2);
SiO20 = interp1(In_Z,In_SiO2z,zz+dz/2);
diatom0 = interp1(In_Z,In_diatomz,zz+dz/2);
VolFrac=1./(1+(1-F_sed_sld)./(F_sed_sld*FIM0)); %volume fraction: inorg sed. / (inorg.sed + pore water)
%Fokema
%CDOM0=interp1(In_Z,In_DOCz,zz+dz/2); %%!!!!NB: assumed CDOM=DOC!!!
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-DOP0-((Chl0 + C0)./Y_cp-S0*Fstable))<0) %NEW!!!
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!!!
PPz = TP0-DOP0-((Chl0 + C0)./Y_cp)-Pz; % (mg m-3) NEW!!!
DOCz = DOC0; % (mg m-3)
DICz = DIC0; % (mg m-3)
O2z = O20; % (mg m-3)
NO3z = NO30;
NH4z =NH40;
SO4z = SO40;
HSz = HS0;
H2Sz = H2S0;
Fe2z = Fe20;
Ca2z = Ca20;
pHz = pH0;
CH4z = CH40;
Fe3z = Fe30;
Al3z = Al30;
SiO4z = SiO40;
SiO2z = SiO20;
diatomz = diatom0;
F_IM = FIM0; %initial VOLUME fraction of inorganic particles of total dry sediment solids
% Fokema
%CDOMz = CDOM0;
%CO2z = NaN*zeros(1,length(zz));
%surfflux = 0;
%== 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
% ============ Sediments module ============
% Allocation and initial sediments profiles concentrations and reading initial concentrations for sediments from file
[sediment_concentrations, sediment_params, sediment_matrix_templates, species_sediments] = sediments_init( pH, zm, In_Tz(end) );
% ==========================================
% >>>>>> 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_v2.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,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz] = convection_v2(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz,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,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz] = convection_v2(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz,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)
% 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,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz] = convection_v2(Tz,Cz,Sz,Pz,Chlz,PPz,DOPz,DOCz,DICz,O2z,NO3z,NH4z,SO4z,HSz,H2Sz,Fe2z,Ca2z,pHz,CH4z,Fe3z,Al3z,SiO4z,SiO2z,diatomz,Tprof_prev,Vz,Cw,f_par,lambdaz_wtot_avg,zz,swa_b0,tracer_switch,0);
%% Deposition
if deposition_switch == 1
DOPz(1) = DOPz(1) + (Deposition(i,6) ./ Vz(1)) ; % qty added in mg to the top layer z
end
%%flocculation
% rate in Wachenfeldt et al. 2008 is mg C m-2 day-1
%dfloc = 3.5 * exp(0.25 .* (DOCz ./ 1000)); % loss of DOC to POC
dfloc = 0.030/365 .* DOCz ./ 1000; % loss of DOC to POC
% 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));
end
%================================
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)
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
% - current version
Kd_old=0;
Theeta=0;
Currdate=datevec(tt(i)); %Date
%Date=0;
Date=Currdate(1,2); %Month number
if (photobleaching==1) %Fokema
%[DOCz,Kd_new] = fokema(DOCz,Kd_old,Qsw,Tz,Theeta,Date,zz);
DOCz1 = 0.0775.*DOCz; %Subpools
DOCz2 = 0.1486.*DOCz;
DOCz3 = 0.7739.*DOCz;
[DOCz1_new,DOCz2_new,DOCz3_new,DOC1frac,DOC2frac,DOC3frac,Kd_new,Daily_BB1,Daily_BB2,Daily_BB3,Daily_PB] = fokema_new(DOCz1,DOCz2,DOCz3,Kd_old,Qsw,Tz,Theeta,Date,zz);
DOCz = DOCz1_new + DOCz2_new + DOCz3_new; %Total DOC
DOCz = Fi \ DOCz; %Solving new dissolved organic C profile (diffusion)
%DOCz1_new = Fi \ DOCz1_new; %Solving new dissolved organic C profile (diffusion)
%DOCz2_new = Fi \ DOCz2_new; %Solving new dissolved organic C profile (diffusion)
%DOCz3_new = Fi \ DOCz3_new; %Solving new dissolved organic C profile (diffusion)
else %TSA model
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 organic C profile (diffusion)
end
%Oxygen
%Oxygen production/consumption in phytoplankton growth & mineralization
dO2_Chl = 110.*(dChl_growth+dCz_growth);
%Biochemical & sediment oxygen demand
BOD = 1*ones(length(zz),1);
theta_b = NaN*ones(length(zz),1);
%theta_s = NaN*ones(length(zz),1);
for k = 1:length(Tz)
if(Tz(k)<BOD_temp_switch)
theta_b(k) = theta_bod_ice;
%theta_s(k) = theta_sod_ice;
else
theta_b(k) = theta_bod;
%theta_s(k) = theta_sod;
end
end
if(IceIndicator==0)
% BOD = 1.5*BOD7*ones(length(zz),1);
dO2_BOD = (32/12) .* DOCz .* k_BOD.*theta_b.^(Tz-20);
% dO2_BOD = k_BOD*theta_bod.^(Tz-20).*BOD;
% dO2_SOD = k_SOD.*theta_sod.^(Tz-20).*(-diff([Az; 0])./Vz);
else
% BOD_ice = 1.5*BOD7_ice*ones(length(zz),1);
dO2_BOD = (32/12) .* DOCz .* k_BOD.*theta_b.^(Tz-20);
% dO2_BOD = k_BOD*theta_bod_ice.^(Tz-20).*BOD_ice;
% dO2_SOD = k_SOD_ice.*theta_sod_ice.^(Tz-20).*(-diff([Az; 0])./Vz);
% % dO2_BOD = k_BOD.*0.25.*Tz.*BOD;
% % dO2_SOD = k_SOD.*0.25.*Tz.*(-diff([Az; 0])./Vz);
end
O2_old = O2z;
O2z = max(0,O2z + dO2_Chl - dO2_BOD);% - dO2_SOD);
O2_diff = O2z - O2_old;
O2_new = O2z;
%Oxygen surface flux
if(IceIndicator==0)
[O2z(1),O2flux,O2_eq,K0_O2] = oxygenflux(O2z(1),C_shelter^(1/3)*Wt(i,6),Wt(i,5),Tz(1),dz);
else
O2flux = 0;
end
O2z = Fi \ O2z; %Solving new dissolved oxygen profile (diffusion)
DOCz = max(0, DOCz - (12/32) * dO2_BOD);
DOCz = Fi \ DOCz;
%Dissolved inorganic carbon
%DIC partitioning in water
[CO2z,CO2frac] = carbonequilibrium(DICz,Tz,pH);
% CO2 production by degraded DOC
CO2z = max(0,CO2z + 1.375.*(-O2_diff));
DICz = CO2z./CO2frac;
%TC = Tz(1); %For monitoring only
%Carbon dioxide surface flux
if(IceIndicator==0)
[CO2z(1),surfflux,CO2_eq,K0,CO2_ppm] = carbondioxideflux(CO2z(1),C_shelter^(1/3)*Wt(i,6),Wt(i,5),Tz(1),dz,tt(i));
DICz(1) = CO2z(1)/CO2frac(1);
else
surfflux=0;
end
DICz = Fi \ DICz; %Solving new DIC profile (diffusion)
%==================================
%Dissolved inorganic carbon - version II
%
% pH = 7*ones(1,length(zz));
% TC = Tz(1); %For monitoring only
% [CO2z,CO2frac,C_acid,C_basic] = carbonequilibrium(DICz,Tz,pH);
%
% C_acid = C_acid + 1.375.*(-O2_erotus);
% DICz = C_acid+C_basic;
% [CO2z,CO2frac,C_acid,C_basic] = carbonequilibrium(DICz,Tz,pH);
% if(IceIndicator==0)
% [CO2z(1),surfflux,CO2_eq,K0,CO2_ppm] = carbondioxideflux(CO2z(1),Wt(i,6),Wt(i,5),Tz(1),dz,tt(i));
% DICz(1) = CO2z(1)/CO2frac(1);
% else
% surfflux=0;
% end
% DICz = Fi \ DICz;
%==================================
%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
delC_org3=NaN*ones(Nz,1); % initialize for DOC flocculation
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
delC_org3(1)= (0 - DOCz(1)*delA(1)./meanA(1))./(dz/(dt*dfloc(1)) + 1); % NEW!!! for DOC floculates
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
delC_org3(ii)=(delC_org3(ii-1) - DOCz(ii)*delA(ii)./meanA(ii))./(dz/(dt*dfloc(ii)) + 1); %(mg m-3) % NEW!!! for DOC flocculation
end
if (flocculation_switch==1)
% is POC going to Sz then advected ?
DOCz = max(0, DOCz - delC_org3); %
DOCz = Fi \ DOCz;
end
H_netsed_catch=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+delC_org3)./(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_catch; %total (m day-1), always positive
F_IM_NewSed=F_IM;
inx=find(H_totsed>0);
F_IM_NewSed(inx)=H_netsed_catch(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_catch./(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+delC_org3)./(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);
%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;
% 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)
% Inflw(:,9) Inflow DIC concentration (mg m-3)
% Inflw(:,10) Inflow O2 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
Iflw_DIC = I_scDIC * Inflw(i,9); %(scaled) inflow DIC concentration
Iflw_O2 = I_scO * Inflw(i,10); %(scaled) inflow O2 concentration
% inflow HS and H2S are neglected
Iflw_NO3 = I_scNO3 * Inflw(i,11);
Iflw_NH4 = I_scNH4 * Inflw(i,12);
Iflw_SO4 = I_scSO4 * Inflw(i,13);
Iflw_Fe2 = I_scFe2 * Inflw(i,14);
Iflw_Ca2 = I_scCa2 * Inflw(i,15);
Iflw_pH = I_scpH * Inflw(i,16);
Iflw_CH4 = I_scCH4 * Inflw(i,17);
Iflw_Fe3 = I_scFe3 * Inflw(i,18);
Iflw_Al3 = I_scAl3 * Inflw(i,19);
Iflw_SiO4 = I_scSiO4 * Inflw(i,20);
Iflw_SiO2 = I_scSiO2 * Inflw(i,21);
Iflw_diatom = I_scdiatom * Inflw(i,22);
%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...