-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbrom-transport.F90
More file actions
1779 lines (1579 loc) · 92.8 KB
/
brom-transport.F90
File metadata and controls
1779 lines (1579 loc) · 92.8 KB
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
! This file is part of Bottom RedOx Model (BROM, v.1.1).
! BROM is free software: you can redistribute it and/or modify it under
! the terms of the GNU General Public License as published by the Free
! Software Foundation (https://www.gnu.org/licenses/gpl.html).
! It is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY; without even the implied warranty of MERCHANTABILITY or
! FITNESS FOR A PARTICULAR PURPOSE. A copy of the license is provided in
! the COPYING file at the root of the BROM distribution.
!-----------------------------------------------------------------------
! Original author(s): Evgeniy Yakushev, Shamil Yakubov,
! Elizaveta Protsenko, Phil Wallhead,
! Anfisa Berezina, Matvey Novikov, Beatriz Arellano-Nava
!-----------------------------------------------------------------------
!
! Code was adapted for FABM-1.0.3
! More info https://github.com/fabm-model/fabm/wiki/FABM-1.0
!-----------------------------------------------------------------------
module brom_transport
! AB check fabm subroutines
use fabm_omp
use fabm_types !, only: attribute_length, rk ! check attribute_length
use io_netcdf
use io_ascii
use mtridiagonal, only: init_tridiagonal,clean_tridiagonal
use ids !Provides access to variable indices id_O2 etc.
implicit none
private
public init_brom_transport, do_brom_transport, clear_brom_transport
real(rk), parameter :: pi=3.141592653589793_rk
!FABM model with all data and procedures related to biogeochemistry
class (type_fabm_omp_model), pointer :: model
type (type_horizontal_standard_variable), parameter :: id_hice = type_horizontal_standard_variable(name='hice',units='m') ! horizontal - 2D
type (type_horizontal_standard_variable), parameter :: id_aice = type_horizontal_standard_variable(name='aice',units='-')
type (type_interior_standard_variable) :: & ! check if used!!
volume_of_cell = type_interior_standard_variable(name='volume_of_cell')
!Solution parameters to be read from brom.yaml (see brom.yaml for details)
integer :: i_min, i_max !x-axis related
integer :: k_min, k_wat_bbl,k_wat_bbl_manual, k_bbl_sed !z-axis related
integer :: k_points_below_water, k_max, k_storm !z-axis related
integer :: par_max !no. BROM variables
integer :: i_day, year, days_in_yr, freq_turb, freq_sed, freq_float, last_day, multiyears_physics !time related ! ?? freq_sed, freq_turb
integer :: diff_method, kz_bbl_type, bioturb_across_SWI !vertical diffusivity related
integer :: h_adv, h_relax, not_relax_centr, h_turb !horizontal transport (advection and relaxation) switches
integer :: use_swradWm2, use_hice, use_gargett ! use input for light, ice, calculate Kz
integer :: input_type, port_initial_state, ncoutfile_type !I/O related
integer :: use_leak, i_leak, start_leak !leak related
integer :: bio_model ! basic ecosystem model: 0- for BROM_bio (default) 1- for OxyDep
real(rk) :: dt, water_layer_thickness, cc_leak, cc_leak2, w_leak_adv
real(rk) :: K_O2s, gargett_a0, gargett_q, mult_Kz, Kz_storm, Kb, pb, dzeta
! Free timestep input and output
integer :: ist, i_step, input_step, steps_in_yr, output_step ! ist - steps in the course of the day, i_step - step in the course of the year
character(len=64) :: icfile_name, outfile_name, ncoutfile_name
character :: hmix_file
!Forcings to be provided to FABM: These must have the TARGET attribute
real(rk), allocatable, target, dimension(:) :: pco2_atm_1d, wind_speed_1d, hice, aice, swradWm2, swradWm2_1d, hice_1d, aice_1d, lat_light_1d
real(rk), allocatable, target, dimension(:,:) :: surf_flux, bott_flux, bott_source, Izt, pressure, depth, cell_thickness
real(rk), allocatable, target, dimension(:,:,:) :: t, s, u_x
real(rk), allocatable, target, dimension(:,:,:) :: vv, dVV, cc, cc_out, dcc, dcc_R, wbio, air_sea_flux ! add the description cc - all params, dcc - volumes of solids
real(rk), allocatable, target, dimension(:,:) :: wbio_2d
! vv -> 2d
!Surface and bottom forcings, used within brom-transport only
real(rk), allocatable, dimension(:,:,:) :: cc_top, cc_bottom
!Horizontal mixing forcings, used within brom-transport only
real(rk), allocatable, dimension(:,:,:) :: kl
real(rk), allocatable, dimension(:,:,:,:) :: cc_hmix ! relaxation
!Grid parameters and forcings for water column only
real(rk), allocatable, dimension(:) :: z_w, dz_w, hz_w
real(rk), allocatable, dimension(:,:,:) :: t_w, s_w, kz_w, u_x_w
real(rk), allocatable, dimension(:,:,:,:) :: cc_hmix_w
!Grid parameters and forcings for full column including water and sediments
real(rk), allocatable, dimension(:) :: z, dz, hz, x, dx, hx, z1, z_s1
real(rk), allocatable, dimension(:,:) :: bc_top, bc_bottom, kz_bio, alpha, phi, phi1, phi_inv, tortuosity, kztCFL
real(rk), allocatable, dimension(:,:) :: wCFL, w_b, u_b, wat_content
real(rk), allocatable, dimension(:,:,:) :: kz, kzti, fick, fick_per_day, sink, sink_per_day, bcpar_top, bcpar_bottom
real(rk), allocatable, dimension(:,:,:) :: kz_mol, pF1, pF2, wti, w_bub, pWC
integer, allocatable, dimension(:) :: is_solid, is_gas, k_wat, k_sed, k_sed1, k_bbl1
integer, allocatable, dimension(:,:) :: bctype_top, bctype_bottom, hmixtype
integer, allocatable, dimension(:,:) :: kzCFL, kz_molCFL
character(len=attribute_length), allocatable, dimension(:) :: par_name
! variables for building the grid
integer :: sel, iday, istep
! integer :: k_sed(k_max-k_bbl_sed), k_sed1(k_max+1-k_bbl_sed), k_bbl1(k_bbl_sed-k_wat_bbl)
real(rk) :: z_wat_bbl, z_bbl_sed, kz_gr !, z1(k_max+1), z_s1(k_max+1), phi1(i_max,k_max+1)
integer :: dynamic_kz_bbl
real(rk) :: kz_bbl_max, hz_sed_min, dbl_thickness, kz_mol0
real(rk) :: a1_bioirr, a2_bioirr
real(rk) :: kz_bioturb_max, z_const_bioturb, z_decay_bioturb
real(rk) :: phi_0, phi_inf, z_decay_phi, w_binf, rho_def, wat_con_0, wat_con_inf
! real(rk) :: kzCFL(k_bbl_sed-1,steps_in_yr), kz_molCFL(k_max-1,par_max)
integer :: inj_changing !for changing with time injection
real(rk) :: inj_square ! square of the layer with injection
!Constant forcings that can be read as parameters from brom.yaml
real(rk) :: wind_speed, pco2_atm, mu0_musw, dphidz_SWI , hx_min, hx_max, dy ! dx_adv
! Injection of something as a function or years
real(rk) :: inj_smth(400)
real(rk) :: lat_light, Io !Variables used to calculate surface irradiance from latitude
! Environment
real(rk),target :: decimal_yearday
real(rk), allocatable, dimension(:) :: rho
!Counters
integer :: i, k, ip, ip_sol, ip_par, kj, ij !, i_dummy AB
real(rk) :: i_dummy ! AB
contains
!=======================================================================================================================
!
! name: brom_transport.init_brom_transport
! @param
! @return
!
subroutine init_brom_transport()
!Initialises the offline vertical transport model BROM-transport
use ids !Provides access to variable indices id_O2 etc
implicit none
!Reading brom.yaml
call init_common()
!Get grid and numerical solution parameters from from brom.yaml
dt = get_brom_par("dt")
freq_turb = get_brom_par("freq_turb")
freq_sed = get_brom_par("freq_sed ")
freq_float = get_brom_par("freq_float ")
last_day = get_brom_par("last_day")
multiyears_physics = get_brom_par("multiyears_physics")
water_layer_thickness = get_brom_par("water_layer_thickness")
k_min = get_brom_par("k_min")
k_storm = get_brom_par("k_storm")
! k_wat_bbl = get_brom_par("k_wat_bbl")
hz_sed_min = get_brom_par("hz_sed_min")
hz_sed_min = get_brom_par("hz_sed_min")
k_wat_bbl_manual = get_brom_par("k_wat_bbl_manual")
k_points_below_water = get_brom_par("k_points_below_water")
i_min = get_brom_par("i_min")
i_max = get_brom_par("i_max")
year = get_brom_par("year")
days_in_yr = get_brom_par("days_in_yr")
! for free length output (assumed to be a day fraction)
input_step = get_brom_par("input_step")
output_step = get_brom_par("output_step")
bio_model = get_brom_par("bio_model")
diff_method = get_brom_par("diff_method")
bioturb_across_SWI = get_brom_par("bioturb_across_SWI")
input_type = get_brom_par("input_type")
use_swradWm2 = get_brom_par("use_swradWm2")
use_hice = get_brom_par("use_hice")
port_initial_state = get_brom_par("port_initial_state")
icfile_name = get_brom_name("icfile_name")
outfile_name = get_brom_name("outfile_name")
ncoutfile_name = get_brom_name("ncoutfile_name")
ncoutfile_type = get_brom_par("ncoutfile_type")
K_O2s = get_brom_par("K_O2s")
h_adv = get_brom_par("h_adv")
h_relax = get_brom_par("h_relax")
not_relax_centr = get_brom_par("not_relax_centr")
h_turb = get_brom_par("h_turb")
! dx_adv = get_brom_par("dx_adv")
! light connected parameters (if not available in the forcing file)
lat_light = get_brom_par("lat_light")
Io = get_brom_par("Io") !W m-2 maximum surface downwelling irradiance at latitudes <= 23.5N,S
! vertical grid params
!!Get diffusivity parameters from brom.yaml
!Turbulence in the benthic boundary layer
kz_bbl_type = get_brom_par("kz_bbl_type")
kz_bbl_max = get_brom_par("kz_bbl_max")
dbl_thickness = get_brom_par("dbl_thickness")
dynamic_kz_bbl = get_brom_par("dynamic_kz_bbl")
!Molecular diffusivity of solutes (single constant value, infinite dilution)
kz_mol0 = get_brom_par("kz_mol0")
mu0_musw = get_brom_par("mu0_musw")
!Bioturbation
kz_bioturb_max = get_brom_par("kz_bioturb_max")
z_const_bioturb = get_brom_par("z_const_bioturb")
z_decay_bioturb = get_brom_par("z_decay_bioturb")
!Bioirrigation
a1_bioirr = get_brom_par("a1_bioirr")
a2_bioirr = get_brom_par("a2_bioirr")
!Porosity
phi_0 = get_brom_par("phi_0")
phi_inf = get_brom_par("phi_inf")
z_decay_phi = get_brom_par("z_decay_phi")
wat_con_0 = get_brom_par("wat_con_0")
wat_con_inf = get_brom_par("wat_con_inf")
!Vertical advection in the sediments
w_binf = get_brom_par("w_binf")
! horizontal grid params
hx_min = get_brom_par("hx_min")
hx_max = get_brom_par("hx_max")
dy = get_brom_par("dy")
use_gargett = get_brom_par("use_gargett")
gargett_a0 = get_brom_par("gargett_a0")
gargett_q = get_brom_par("gargett_q")
mult_Kz = get_brom_par("mult_Kz")
Kz_storm = get_brom_par("Kz_storm")
Kb = get_brom_par("Kb")
pb = get_brom_par("pb")
dzeta = get_brom_par("dzeta")
use_leak = get_brom_par("use_leak")
i_leak = get_brom_par("i_leak")
start_leak = get_brom_par("start_leak")
w_leak_adv = get_brom_par("w_leak_adv")
cc_leak = get_brom_par("cc_leak")
cc_leak2 = get_brom_par("cc_leak2")
!Initialize FABM model from fabm.yaml
model => fabm_create_omp_model()
par_max = size(model%interior_state_variables)
steps_in_yr = days_in_yr*24*3600/input_step ! determine how much timesteps in the course of the year
if(multiyears_physics.gt.0) then
steps_in_yr = last_day*24*3600/input_step ! determine how much timesteps in the course of the year
endif
!Allocate biological variables now that par_max is known
allocate(surf_flux(i_max,par_max)) !surface flux (tracer unit * m/s, positive for tracer entering column)
allocate(bott_flux(i_max,par_max)) !bottom flux (tracer unit * m/s, positive for tracer entering column)
allocate(bott_source(i_max,k_max)) !surface flux (tracer unit * m/s, positive for tracer entering column)
allocate(bc_top(i_max,par_max))
allocate(bc_bottom(i_max,par_max))
allocate(bctype_top(i_max,par_max))
allocate(bctype_bottom(i_max,par_max))
allocate(bcpar_top(i_max,par_max,3))
allocate(bcpar_bottom(i_max,par_max,3))
allocate(par_name(par_max))
allocate(pco2_atm_1d(i_max))
allocate(lat_light_1d(i_max))
allocate(wind_speed_1d(i_max))
allocate(swradWm2_1d(i_max))
allocate(aice_1d(i_max))
allocate(hice_1d(i_max))
allocate(cc_top(i_max,par_max,days_in_yr))
allocate(cc_bottom(i_max,par_max,days_in_yr))
allocate(is_solid(par_max))
allocate(is_gas(par_max))
allocate(hmixtype(i_max,par_max))
allocate(rho(par_max))
!Retrieve the parameter names from the model structure
do ip=1,par_max
par_name(ip) = model%interior_state_variables(ip)%name
end do
!Make the named parameter indices id_O2 etc.
call get_ids(par_name)
if (id_O2.lt.1) id_O2=id_oxy ! in BROM we have O2 and in OxyDep we have OXY
if (id_POML.lt.1) id_POML=id_POM ! in BROM we have POML and in OxyDep we have POM
!Get boudary condition parameters from brom.yaml:
!bctype = 0, 1, 2, 3 for no flux (default), Dirichlet constant, Dirichlet sinusoid, and Dirichlet netcdf input respectively
do ip=1,par_max
bctype_top(i_max,ip) = get_brom_par('bctype_top_' // trim(par_name(ip)),0.0_rk)
if (bctype_top(i_max,ip).eq.1) then
bc_top(i_max,ip) = get_brom_par('bc_top_' // trim(par_name(ip)))
write(*,*) "Constant Dirichlet upper boundary condition for " // trim(par_name(ip))
write(*,'(a, es10.3)') " = ", bc_top(i_max,ip)
else if (bctype_top(i_max,ip).eq.2) then !Model: bc_top = a1top + a2top*sin(omega*(julianday-a3top))
bcpar_top(i_max,ip,1) = get_brom_par('a1top_' // trim(par_name(ip)))
bcpar_top(i_max,ip,2) = get_brom_par('a2top_' // trim(par_name(ip)))
bcpar_top(i_max,ip,3) = get_brom_par('a3top_' // trim(par_name(ip)))
write(*,*) "Sinusoidal Dirichlet upper boundary condition for " // trim(par_name(ip))
write(*,'(a, es10.3, a, es10.3, a, es10.3, a)') " = ", bcpar_top(i_max,ip,1), " + ", &
bcpar_top(i_max,ip,2), "*sin(omega*(julianday -", bcpar_top(i_max,ip,3), "))"
else if (bctype_top(i_max,ip).eq.3) then !Read from netcdf
write(*,*) "NetCDF specified Dirichlet upper boundary condition for " // trim(par_name(ip))
else if (bctype_top(i_max,ip).eq.4) then !Read from ascii or calc from calintiiy
write(*,*) "Upper boundary condition from NODC " // trim(par_name(ip))
end if
bctype_bottom(i_max,ip) = get_brom_par('bctype_bottom_' // trim(par_name(ip)),0.0_rk)
if (bctype_bottom(i_max,ip).eq.1) then
bc_bottom(i_max,ip) = get_brom_par('bc_bottom_' // trim(par_name(ip)))
write(*,*) "Constant Dirichlet lower boundary condition for " // trim(par_name(ip))
write(*,'(a, es10.3)') " = ", bc_bottom(i_max,ip)
else if (bctype_bottom(i_max,ip).eq.2) then !Model: bc_bottom = a1bottom + a2bottom*sin(omega*julianday-a3bottom))
bcpar_bottom(i_max,ip,1) = get_brom_par('a1bottom_' // trim(par_name(ip)))
bcpar_bottom(i_max,ip,2) = get_brom_par('a2bottom_' // trim(par_name(ip)))
bcpar_bottom(i_max,ip,3) = get_brom_par('a3bottom_' // trim(par_name(ip)))
write(*,*) "Sinusoidal Dirichlet lower boundary condition for " // trim(par_name(ip))
write(*,'(a, es10.3, a, es10.3, a, es10.3, a)') " = ", bcpar_bottom(i_max,ip,1), " + ", &
bcpar_bottom(i_max,ip,2), "*sin(omega*(julianday -", bcpar_bottom(i_max,ip,3), "))"
else if (bctype_bottom(i_max,ip).eq.3) then !Read from netcdf
write(*,*) "NetCDF specified Dirichlet lower boundary condition for " // trim(par_name(ip))
end if
bctype_top(:,ip) = bctype_top(i_max,ip)
bc_top(:,ip) = bc_top(i_max,ip)
bctype_bottom(:,ip) = bctype_bottom(i_max,ip)
bc_bottom(:,ip) = bc_bottom(i_max,ip)
do k=1,3
bcpar_top(:,ip,k) = bcpar_top(i_max,ip,k)
! bcpar_bottom(:,ip,k) = bcpar_bottom(i_max,ip,k)
enddo
end do
write(*,*) "All other boundary conditions use surface and bottom fluxes from FABM"
!Input forcing data
if (input_type.eq.0) then !Input sinusoidal seasonal changes (hypothetical)
call input_primitive_physics(z_w, dz_w, hz_w, k_wat_bbl, water_layer_thickness, t_w, s_w, kz_w, i_max, days_in_yr)
allocate(hice(days_in_yr))
allocate(swradWm2(days_in_yr))
allocate(aice(days_in_yr))
hice = 0.0_rk
swradWm2 = 0.0_rk
aice = 0.0_rk
write(*,*) "Done sinusoidal input"
end if
if (input_type.eq.1) then !Input physics from ascii
call input_ascii_physics(z_w, dz_w, hz_w, k_wat_bbl, water_layer_thickness, t_w, s_w, kz_w, i_max, days_in_yr)
allocate(hice(days_in_yr))
allocate(swradWm2(days_in_yr))
allocate(aice(days_in_yr))
allocate(cc_hmix_w(i_max,par_max,k_wat_bbl,days_in_yr))
cc_hmix_w = 0.0_rk
hice = 0.0_rk
swradWm2 = 0.0_rk
aice = 0.0_rk
write(*,*) "Done ascii input"
end if
if (input_type.eq.2) then !Input water column physics from netcdf
call input_netcdf_2(z_w, dz_w, hz_w, t_w, s_w, kz_w, use_swradWm2, &
hice, swradWm2, aice, use_hice, gargett_a0, gargett_q, use_gargett, &
Kb, pb, dzeta, year, i_max, steps_in_yr, k_wat_bbl, u_x_w)
kz_w=kz_w*mult_Kz
write(*,*) "Done netcdf input"
!Note: This uses the netCDF file to set z_w = layer midpoints, dz_w = increments between layer midpoints, hz_w = layer thicknesses
end if
if(k_wat_bbl_manual.lt.k_wat_bbl) k_wat_bbl=k_wat_bbl_manual
!Determine total number of vertical grid points (layers) now that k_wat_bbl is determined
k_max = k_wat_bbl + k_points_below_water
!Allocate full grid variables now that k_max is knownk
allocate(z(k_max))
allocate(dz(k_max))
allocate(hz(k_max))
allocate(x(i_max))
allocate(dx(i_max))
allocate(hx(i_max))
allocate(t(i_max,k_max,steps_in_yr))
allocate(s(i_max,k_max,steps_in_yr))
allocate(kz(i_max,k_max+1,steps_in_yr))
allocate(air_sea_flux(i_max,k_max,par_max))
allocate(kl(i_max,k_max,steps_in_yr))
allocate(u_x(i_max,k_max,steps_in_yr))
allocate(cc_hmix(i_max,par_max,k_max,days_in_yr))
allocate(kz_mol(i_max,k_max+1,par_max))
allocate(kz_bio(i_max,k_max+1))
allocate(pF1(i_max,k_max,par_max))
allocate(pF2(i_max,k_max+1,par_max))
allocate(pWC(i_max,k_max+1,par_max)) ! water content??
allocate(alpha(i_max,k_max))
allocate(phi(i_max,k_max))
allocate(wat_content(i_max,k_max))
allocate(phi1(i_max,k_max+1))
allocate(phi_inv(i_max,k_max))
allocate(tortuosity(i_max,k_max+1))
allocate(w_b(i_max,k_max+1))
allocate(u_b(i_max,k_max+1))
allocate(wti(i_max,k_max+1,par_max)) ! vertical velocity
allocate(w_bub(i_max,k_max+1,par_max))
allocate(cc(i_max,k_max,par_max))
allocate(cc_out(i_max,k_max,par_max))
allocate(dcc(i_max,k_max,par_max))
allocate(dcc_R(i_max,k_max,par_max))
allocate(fick(i_max,k_max+1,par_max))
allocate(fick_per_day(i_max,k_max+1,par_max))
allocate(wbio(i_max,k_max,par_max)) !sinking vertical velocity (m/s, negative for sinking)
allocate(wbio_2d(k_max,par_max)) !sinking vertical velocity (m/s, negative for sinking)
allocate(sink(i_max,k_max+1,par_max)) !sinking flux (mmol/m2/s, positive downward)
allocate(sink_per_day(i_max,k_max+1,par_max))
allocate(vv(i_max,k_max,1))
allocate(dVV(i_max,k_max,1))
allocate(Izt(i_max,k_max))
allocate(pressure(i_max,k_max))
allocate(cell_thickness(i_max,k_max))
allocate(depth(i_max,k_max))
allocate(kzti(i_max,k_max+1,par_max))
allocate(kztCFL(k_max-1,par_max))
allocate(wCFL(k_max-1,par_max))
! allocate(k_sed(k_max-k_bbl_sed))
! allocate(k_sed1(k_max+1-k_bbl_sed))
allocate(k_bbl1(k_bbl_sed-k_wat_bbl))
allocate(z1(k_max+1))
allocate(z_s1(k_max+1))
allocate(kzCFL(k_bbl_sed-1,steps_in_yr))
allocate(kz_molCFL(k_max-1,par_max))
if (k_points_below_water==0) then !This is to "unlock" BBL and sediments for a "classical" water column model
k_max=k_wat_bbl
z=z_w
dz=dz_w
hz=hz_w
k_bbl_sed=k_wat_bbl !needed for Irradiance calculations
else
!Construct the full vertical grid
call make_vert_grid(z, dz, hz, z_w, dz_w, hz_w, k_wat_bbl, k_max, k_bbl_sed)
write(*,*) "Made vertical grid"
allocate(k_wat(k_bbl_sed))
allocate(k_sed(k_max-k_bbl_sed))
allocate(k_sed1(k_max+1-k_bbl_sed))
k_wat = (/(k,k=1,k_bbl_sed)/) !Index vector for all points in the water column
k_sed = (/(k,k=k_bbl_sed+1,k_max)/) !Index vector for all points in the sediments
k_sed1 = (/(k,k=k_bbl_sed+1,k_max+1)/) !Indices of layer interfaces in the sediments (including the SWI)
endif
!Specify horizontal transport
!dx(:)= dx_adv !horizontal resolution in m
write(*,*) "dx_min=", hx_min," hx_max=", hx_max
if (i_max.gt.1) then
! 1) we calculate thicknesses of the columns where the concentrations are set
do i=1,i_max
hx(i) = hx_min + (hx_max-hx_min)*(cos((i)*2*pi/(i_max+1))+1)*0.5 !here we recieve thicknesses of the columns
! hx(i) = hx_max - (hx_max-hx_min)*sin(pi*(i-1)/(i_max-1)) !here we recieve thicknesses of the columns
enddo
! 2) we calculate coordinates of the centers of the columns, where the concentrations are set
x(1)=0.0_rk
do i=2,i_max
x(i)=x(i-1)+(hx(i)+hx(i-1))/2.0_rk
enddo
! 3) we calculate horizontal steps to calculate fluxes between the columns
do i=1,i_max-1
dx(i)=(hx(i)+hx(i+1))/2.0_rk
enddo
dx(i_max)=hx(i_max)
! 4) print
write(*,*) "i_max,x( ), hx( ), dx(), hx_'REAL' ( )"
do i=1,i_max
write(*,*) i, x(i), hx(i), dx(i), (dx(i)+dx(i-1))/2.0_rk
enddo
else
!allocate u_x_w
x=0.0_rk
u_x_w=0.0_rk
dx=hx_min
endif
!Initialize tridiagonal matrix if necessary
if (diff_method.gt.0) then
call init_tridiagonal(k_max)
write(*,*) "Initialized tridiagonal matrix"
end if
!Set model domain
call model%set_domain(i_max,k_max)
!!!!! DELETE ME !!!!!
! !Specify vertical index of surface and bottom
! call model%set_surface_index(k_min)
! call model%set_bottom_index(k_max)
!Initial volumes of layers:
vv(1:i_max,1:k_max,1) = 1.0_rk
!Make they (full) pressure variable to pass to FABM
!This is used by brom_eqconst.F90 to compute equilibrium constants for pH calculations
!and by brom_carb.F90 to compute equilibrium constants for saturation states (subroutine CARFIN)
do i=1,i_max
pressure(i,:) = z(:) + 10.0_rk
cell_thickness(i,:) = hz(:)
end do
!Point FABM to array slices with biogeochemical state.
do ip=1,par_max
call model%link_interior_state_data(ip, cc(:,:,ip))
end do
!Link temperature and salinity data to FABM (needs to be redone every time julianday is updated below)
call model%link_interior_data(fabm_standard_variables%temperature, t(:,:,1))
call model%link_interior_data(fabm_standard_variables%practical_salinity, s(:,:,1))
!Link other data needed by FABM
call model%link_interior_data(fabm_standard_variables%downwelling_photosynthetic_radiative_flux, Izt) !W m-2
call model%link_interior_data(fabm_standard_variables%pressure, pressure) !dbar
call model%link_interior_data(fabm_standard_variables%depth, depth) !dbar
call model%link_interior_data(fabm_standard_variables%cell_thickness, cell_thickness)
call model%link_horizontal_data(fabm_standard_variables%wind_speed, wind_speed_1d)
call model%link_horizontal_data(fabm_standard_variables%mole_fraction_of_carbon_dioxide_in_air, pco2_atm_1d)
call model%link_horizontal_data(fabm_standard_variables%latitude, lat_light_1d)
call model%link_horizontal_data(fabm_standard_variables%surface_downwelling_shortwave_flux, swradWm2_1d)
call model%link_scalar(fabm_standard_variables%number_of_days_since_start_of_the_year, decimal_yearday)
if (use_hice.eq.1) then
call model%link_horizontal_data(type_horizontal_standard_variable(name='hice'), hice_1d)
call model%link_horizontal_data(type_horizontal_standard_variable(name='aice'), aice_1d)
endif
call model%link_interior_data(volume_of_cell, vv(:,:,1))
!Check FABM is ready
call model%start()
!Allow FABM models to use their default initialization (this sets cc)
do k=1,k_max
call model%initialize_interior_state(1, i_max, k)
end do
!Read initial values from ascii file if req'd
if (port_initial_state.eq.1) call porting_initial_state_variables(trim(icfile_name), year, &
i_day, i_max, k_max, par_max, par_name, cc, vv)
if (port_initial_state.eq.2) then
call porting_initial_state_variables(trim(icfile_name), year, &
i_day, 1, k_max, par_max, par_name, cc, vv)
do i=2,i_max
cc(i,:,:) = cc(1,:,:)
vv(i,:,:) = vv(1,:,:)
enddo
endif
!Check biological parameters for non-zero values
if (bio_model.lt.1) then !case BROM
do ip=1,par_max
if (ip.eq.id_Phy.or.ip.eq.id_Het.or.ip.eq.id_Baae.or.ip.eq.id_Baan.or.ip.eq.id_Bhae.or.ip.eq.id_Bhan) then
do i=1,i_max
do k=1,k_max
if(cc(i,k,ip).le.0.0_rk) cc(i,k,ip)= 1.0E-7 !-11
enddo
enddo
endif
enddo
endif
if (bio_model.ge.1) then !case OxyDep
do ip=1,par_max
if (ip.eq.id_Phy.or.ip.eq.id_Het) then
do i=1,i_max
do k=1,k_max
if(cc(i,k,ip).le.0.0_rk) cc(i,k,ip)= 1.0E-7 !-11
enddo
enddo
endif
enddo
endif
!Initialize output
call init_netcdf(trim(ncoutfile_name), i_max, k_max, model, use_swradWm2, use_hice, year)
!Establish which variables will be treated as solid phase in the sediments, based on the biological velocity (sinking/floating) from FABM.
wbio = 0.0_rk
do k=1,k_wat_bbl
call model%get_vertical_movement(i_min, i_max, k, wbio(i_min:i_max,k,:))
enddo
wbio = -1.0_rk * wbio !FABM returns NEGATIVE wbio for sinking; sign change here means that wbio is POSITIVE for sinking
is_solid = 0
is_gas = 0
ip_sol = 0
ip_par = 0
write(*,*) "The following variables are assumed to join the solid phase in the sediments"
do ip=1,par_max
do i=i_min,i_max
if (wbio(i,k_wat_bbl,ip).gt.0.0_rk) then
is_solid(ip) = 1 !Any variables that SINKS (wbio>0) in the bottom cell of the water column will become "solid" in the sediments
! write(*,*) trim(par_name(ip))
if (ip_par.eq.0) ip_par = ip !Set ip_par = index of first particulate variable
elseif (wbio(i,k_wat_bbl,ip).lt.0.0_rk) then
is_gas(ip) = 1 !Any variables that floats (wbio>1)
! write(*,*) trim(par_name(ip))
else
if (ip_sol.eq.0) ip_sol = ip !Set ip_par = index of first solute variable
end if
enddo
end do
is_solid(26:28) = 1
do ip=1,par_max
if (is_gas(ip).eq.1) then
write(*,*) "Gaseous variable: ", trim(par_name(ip))
endif
enddo
write(*,*) "The following variables are particulate matter:"
!Density of particles
rho_def = get_brom_par("rho_def")
rho = 0.0_rk
do ip=1,par_max
if (is_solid(ip).eq.1) then
rho(ip) = get_brom_par('rho_' // trim(par_name(ip)),rho_def)
write(*,*) "Assumed density of ", trim(par_name(ip)), " = ", rho(ip)
end if
end do
!Complete hydrophysical forcings
cc_hmix=0.0_rk
!!Set useful parameters for calculations
!Useful depths
if (k_points_below_water.gt.0) then
z_wat_bbl = z(k_wat_bbl+1) - 0.5_rk*hz(k_wat_bbl+1) !Depth of water-BBL interface
z_bbl_sed = z(k_bbl_sed+1) - 0.5_rk*hz(k_bbl_sed+1) !Depth of BBL-sediment interface (SWI)
else
z_wat_bbl = z(k_wat_bbl)
z_bbl_sed = z(k_bbl_sed)
endif
z1(1:k_max) = z(:)-0.5_rk*hz(:) !Depth of layer interfaces
!z1(k_max+1) = z(k_max)+0.5_rk*hz(k_max)
z_s1 = z1-z_bbl_sed !Depth of interfaces wrt SWI
!Useful index vectors
k_sed = (/(k,k=k_bbl_sed+1,k_max)/) !Indices of layer midpoints in the sediments
k_sed1 = (/(k,k=k_bbl_sed+1,k_max+1)/) !Indices of layer interfaces in the sediments (including the SWI)
k_bbl1 = (/(k,k=k_wat_bbl+1,k_bbl_sed)/) !Indices of layer interfaces in the BBL (including the top)
!!Calculate physical forcings
!Assume (t, s, cc, hmix_rate) at layer midpoints; (kz, w_b) on interfaces (as in GOTM and ROMS grids):
!Note: kz vertical index starts from 1, not 0 as in e.g. GOTM, ROMS
! Using index starting from 0 leads to array misalignment passing between subroutines (PWA, 11/03/2016)
!
!========= (air-sea interface) kz(1), w_b(1) (unused)
! o t(1), s(1), cc(1), hmix_rate(1)
!--------- kz(2), w_b(2) = 0
! o t(2), s(2), cc(2), hmix_rate(2)
! :
! :
! o t(k_wat_bbl), s(k_wat_bbl), cc(k_wat_bbl), hmix_rate(k_wat_bbl)
!========= (water-bbl interface) kz(k_wat_bbl+1) = kz_bbl or kz_bbl_max
! o t(k_wat_bbl+1), s(k_wat_bbl+1), cc(k_wat_bbl+1), hmix_rate(k_wat_bbl+1) = 0
!--------- kz(k_wat_bbl+2) = kz_bbl (if kz_bbl_type = 0)
! o t(k_wat_bbl+2), s(k_wat_bbl+2), cc(k_wat_bbl+2), hmix_rate(k_wat_bbl+2) = 0
! :
! :
! o t(k_bbl_sed), s(k_bbl_sed), cc(k_bbl_sed), hmix_rate(k_bbl_sed) = 0
!========= (bbl-sediment interface) kz(k_bbl_sed+1) = 0, w_b(k_bbl_sed+1)
! o t(k_bbl_sed+1), s(k_bbl_sed+1), cc(k_bbl_sed+1), hmix_rate(k_bbl_sed+1) = 0
!--------- kz(k_bbl_sed+2) = 0, w_b(k_bbl_sed+2)
! o t(k_bbl_sed+2), s(k_bbl_sed+2), cc(k_bbl_sed+2), hmix_rate(k_bbl_sed+2) = 0
! :
! :
! o t(k_max), s(k_max), cc(k_max), hmix_rate(k_max) = 0
!========= (bottom) kz(k_max+1), w_b(k_max+1)
kz = 0.0_rk
! hmix_rate = 0.0_rk
! cc_hmix = 0.0_rk
!Calculation below are for water column horizontal index
do i = i_min, i_max
iday = 1
do istep=1,steps_in_yr
if (mod(istep,int(86400/input_step)).eq.0) then
! if (mod(istep,24).eq.0) then
iday = iday + 1
end if
!Salinity (s)
s(i,1:k_wat_bbl,istep) = s_w(i,1:k_wat_bbl,istep)
!Temperature (t)
t(i,1:k_wat_bbl,istep) = t_w(i,1:k_wat_bbl,istep)
do k=k_wat_bbl,k_max
s(i,k,istep) = maxval(s_w(i,k_wat_bbl-1,:)) !Assume constant below z_wat_bbl
t(i,k,istep) = minval(t_w(i,k_wat_bbl-1,:)) !Assume constant below z_wat_bbl
enddo
! do k=k_wat_bbl+1,k_max
! s(i,k,istep) = s_w(i,k_wat_bbl,istep) !Assume constant below z_wat_bbl
! t(i,k,istep) = t_w(i,k_wat_bbl,istep) !Assume constant below z_wat_bbl
! enddo
!Horizontal advection (u_x)
u_x(i,1:k_wat_bbl,istep) = u_x_w(i,1:k_wat_bbl,istep)
!Linear u_x across BBL
!kz_gr = (0.0_rk-kz_bbl_max) / (z_bbl_sed-dbl_thickness-z_wat_bbl)
!Note: u_x is assumed to reach zero at height dbl_thickness above the SWI
do k=k_wat_bbl+1,k_bbl_sed-1
!u_x(i,k,istep) = max(0.0_rk, u_x_w(i,k_wat_bbl,istep) + kz_gr * (z1(k)-z_wat_bbl))
! velosity profile (Cushman-Roisin, Beckers, 2011) U(Z)=(U*/K)*ln(Z-Z0)
! were Z-distance from bottom, Z0-roughness, K=0.4 von Karman const, U*- friction velosity.
! 0.07 here is for (U*/K) normalization
u_x(i,k,istep) = (1.0_rk/log((z(k_bbl_sed+1)-z(k_wat_bbl+1))/dbl_thickness)) &
*u_x_w(i,k_wat_bbl,istep)*log((z(k_bbl_sed+1)-z(k))/dbl_thickness)
!u_x(i,k,istep) =0.0_rk
end do
! u_x(i,k_wat_bbl+1:k_max,istep) = 0.0_rk !Assume zero below z_wat_bbl
u_x(i,k_bbl_sed:k_max,istep) = 0.0_rk !Assume zero below z_wat_bbl
!Vertical diffusivity in water column (kz)
kz(i,1:k_wat_bbl,istep) = kz_w(i,1:k_wat_bbl,istep) !Use all values on upper layer interfaces in water column
if (dynamic_kz_bbl.eq.0) then !Static kz_bbl
if (kz_bbl_type.eq.0) then !Constant kz across BBL
do k=k_wat_bbl+1,k_bbl_sed
if (z1(k) < (z_bbl_sed-dbl_thickness)) then !Note that kz(k) is at depth z1(k) = z(k)-hz(k)/2
kz(i,k,istep) = kz_bbl_max
else
kz(i,k,istep) = 0.0_rk !eddy diffusivity kz is assumed to be zero within the diffusive boundary layer
end if
end do
end if
if (kz_bbl_type.eq.1) then !Linear kz across BBL (~=> log-layer for velocity, Holtappels & Lorke, 2011)
kz_gr = (0.0_rk-kz_bbl_max) / (z_bbl_sed-dbl_thickness-z_wat_bbl)
!Note: kz is assumed to reach zero at height dbl_thickness above the SWI
do k=k_wat_bbl+1,k_bbl_sed
kz(i,k,istep) = max(0.0_rk, kz_bbl_max + kz_gr * (z1(k)-z_wat_bbl)) !Note that kz(k) is at depth z1(k) = z(k)-hz(k)/2
end do
end if
end if
if (dynamic_kz_bbl.eq.1) then !Dynamic kz_bbl
kz_gr = (0.0_rk-kz(i,k_wat_bbl,istep)) / (z_bbl_sed-dbl_thickness-z1(k_wat_bbl))
do k=k_wat_bbl+1,k_bbl_sed
kz(i,k,istep) = max(0.0_rk, kz(i,k_wat_bbl,istep) + kz_gr * (z1(k)-z1(k_wat_bbl))) !Note that kz(k) is at depth z1(k) = z(k)-hz(k)/2
end do
end if
!Warning if the diffusive CFL condition is > 0.5
! kzCFL(:,istep) = (kz(i,2:k_bbl_sed,istep)*dt/freq_turb)/(dz(1:k_bbl_sed-1)**2)
! if (diff_method.eq.0.and.maxval(kzCFL(:,istep)).gt.0.5_rk) then
! write(*,*) "WARNING!!! CFL condition due to eddy diffusivity exceeds 0.5 on day", istep
! write(*,*) "z_L, kz, kzCFL = "
! do k=1,k_bbl_sed-1
! if (kzCFL(k,istep).gt.0.5_rk) write(*,*) z(k)+hz(k)/2, kz(i,k+1,istep), kzCFL(k,istep)
! end do
! end if
!Horizontal mixing rate (hmix_rate) and reservoir concentrations (cc_hmix)
! hmix_rate(i,1:k_wat_bbl,istep) = 0.0_rk
! cc_hmix(i,1:par_max,1:k_wat_bbl,iday) = 0.0_rk !cc_hmix_w(i,1:par_max,1:k_wat_bbl,iday)
end do
enddo
!Porosity (phi) (assumed constant in time)
phi = 1.0_rk
phi_inv = 1.0_rk/phi
wat_content = 1.0_rk
phi1 = 1.0_rk
!Calculation below are for water column horizontal index
do i = i_min, i_max
phi(i,k_sed) = phi_inf + (phi_0-phi_inf)*exp(-1.0_rk*(z(k_sed)-z_bbl_sed)/z_decay_phi)
dphidz_SWI = -1.0_rk * (phi_0-phi_inf) / z_decay_phi
!water content (wat_content) (assumed constant in time)
wat_content(i,k_sed) = wat_con_inf + (wat_con_0-wat_con_inf)*exp(-1.0_rk*(z(k_sed)-z_bbl_sed)/z_decay_phi)
!Porosity on layer interfaces (phi1)
phi1(i,k_sed) = phi_inf + (phi_0-phi_inf)*exp(-1.0_rk*(z(k_sed)-0.5_rk*hz(k_sed)-z_bbl_sed)/z_decay_phi)
phi1(i,k_max+1) = phi_inf + (phi_0-phi_inf)*exp(-1.0_rk*(z(k_max)+0.5_rk*hz(k_max)-z_bbl_sed)/z_decay_phi)
enddo
!Porosity factors used in diffusivity calculations (pF1, pF2)
!(assumed constant in time but will vary between solutes vs. solids)
!These allow us to use a single equation to model diffusivity updates in the water column and sediments, for both solutes and solids:
! dC/dt = d/dz(pF2*kzti*d/dz(pF1*C)) where C has units [mass per unit total volume (water+sediments)]
pF1 = 1.0_rk
pF2 = 1.0_rk
pWC = 1.0_rk
!Calculation below are for water column horizontal index
do i = i_min, i_max
do ip=1,par_max
if (is_solid(ip).eq.0) then !Factors for solutes
pF1(i,k_sed,ip) = 1.0_rk/phi(i,k_sed) !Factor to convert [mass per unit total volume] to [mass per unit volume pore water] for solutes in sediments
pF2(i,k_sed1,ip) = phi1(i,k_sed1) !Porosity-related area restriction factor for fluxes across layer interfaces
pWC(i,k_sed,ip) = 1.0_rk/wat_content(i,k_sed) !Factor to convert [mass per unit total volume] to [mass per unit volume pore water] for solutes in sediments (for analytical data)
! dC/dt = d/dz(kzti*dC/dz) in the water column
! dC/dt = d/dz(phi*kzti*d/dz(C/phi)) in the sediments
end if
if (is_solid(ip).eq.1) then !Factors for solids
pF1(i,k_sed,ip) = 1.0_rk/(1.0_rk - phi(i,k_sed)) !Factor to convert [mass per unit total volume] to [mass per unit volume solids] for solids in sediments
pF2(i,k_sed1,ip) = 1.0_rk - phi1(i,k_sed1) !Porosity-related area restriction factor for fluxes across layer interfaces
pWC(i,k_sed,ip) = 1.0_rk/(1.0_rk - wat_content(i,k_sed)) !Factor to convert [mass per unit total volume] to [mass per unit volume solids] for solids in sediments (for analytical data)
! dC/dt = d/dz(kzti*dC/dz) in the water column
! dC/dt = d/dz((1-phi)*kzti*d/dz(C/(1-phi))) in the sediments
end if
end do
!Tortuosity on layer interfaces (following Boudreau 1996, equatoin 4.120)
tortuosity(i,:) = sqrt(1.0_rk - 2.0_rk*log(phi1(i,:)))
enddo
kz_mol = 0.0_rk
kz_bio = 0.0_rk
alpha = 0.0_rk
!Calculation below are for water column horizontal index
do i = i_min, i_max
!Vertical diffusivity due to effective molecular diffusivity of solutes in the sediments (kz_mol)
!(assumed constant in time but in general may vary between solutes)
do ip=1,par_max
if (is_solid(ip).eq.0) then
kz_mol(i,1:k_max+1,ip) = kz_mol0
kz_mol(i,k_sed1,ip) = mu0_musw * kz_mol0/(tortuosity(i,k_sed1)**2)
!Warning if the diffusive CFL condition is > 0.5
kz_molCFL(:,ip) = (kz_mol(i,2:k_max,ip)*dt/freq_turb)/(dz(1:k_max-1)**2)
if (diff_method.eq.0.and.maxval(kz_molCFL(:,ip)).gt.0.5_rk) then
write(*,*) "WARNING!!! CFL condition due to molecular diffusivity exceeds 0.5 for variable", trim(par_name(ip))
write(*,*) "z_L, kz_mol, kz_molCFL = "
do k=1,k_max-1
if (kz_molCFL(k,ip).gt.0.5_rk) write(*,*) z(k)+hz(k)/2, kz_mol(i,k+1,ip), kz_molCFL(k,ip)
end do
end if
end if
end do
!Vertical diffusivity due to bioturbation (kz_bio)
!(assumed constant in time and between solutes/solids)
do k=k_bbl_sed+(2-bioturb_across_SWI),k_max+1 !Note: bioturbation diffusivity is assumed to be non-zero on the SWI
if (z_s1(k)<z_const_bioturb) then
kz_bio(i,k) = kz_bioturb_max
else
kz_bio(i,k) = kz_bioturb_max*exp(-1.0_rk*(z_s1(k)-z_const_bioturb)/z_decay_bioturb)
end if
end do
!Bioirrigation rate (alpha)
!(assumed constant in time and between solutes)
alpha(i,k_sed) = a1_bioirr*exp(-1.0_rk*a2_bioirr*(z(k_sed)-z_bbl_sed)) !Schluter et al. (2000), Eqn. 2
enddo
!Calculation below are for water column horizontal index
!Background vertical advective velocities of particulates and solutes on layer interfaces in the sediments (w_b, u_b)
!(these assume steady state compaction and neglect reaction terms)
w_b = 0.0_rk
u_b = 0.0_rk
!Calculation below are for water column horizontal index
do i = i_min, i_max
w_b(i,k_sed1) = ((1.0_rk - phi_inf)/(1.0_rk - phi1(i,k_sed1))) * w_binf !Boudreau (1997), Eqn 3.67; Holzbecher (2002) Eqn 3
u_b(i,k_sed1) = (phi_inf/phi1(i,k_sed1)) * w_binf !Boudreau (1997), Eqn 3.68; Holzbecher (2002) Eqn 12
!do k=k_bbl_sed-1,k_max
! w_b(i,:) = w_binf
! u_b(i,:) = w_binf
!enddo
enddo
!!Write to output file
! open(12,FILE='Hydrophysics.dat')
! write(12,'(6hiday ,5hk ,5hi ,11hhz[m] ,11hz[m] ,11hz_H[m] ,9ht[degC] ,10hs[psu] ,16hKz_H[m2/s] ,18hKz_mol1_H[m2/s] , 18hKz_bio_H[m2/s] , 18hu[m/s] , 18hstep ,15halpha[/s] ,5hphi ,14htortuosity_H ,17hw_bH [1E-10 m/s] ,17hu_bH [1E-10 m/s] )')
! iday=1
! do istep=1,steps_in_yr
! if (mod(istep,int(86400/input_step)).eq.0) then
! ! if (mod(istep,24).eq.0) then
! iday = iday + 1
! end if
! do k=1,k_max
! write (12,'(2(1x,i4))',advance='NO') istep, k
! do i=1,i_max
! write(12,'(1x,i4,f10.4,1x,f10.4,1x,f10.4,2(1x,f8.4),1x,f15.11,1x,f17.13,1x,f17.13,12x,f7.4,12x,i5,1x,f15.11,f7.4,1x,f7.4,12x,f7.4,12x,f7.4)',advance='NO') &
! i, hz(k), z(k), (z(k)-0.5_rk*hz(k)),&
! t(i,k,istep), s(i,k,istep), kz(i,k,istep), kz_mol(i,k,1), &
! kz_bio(i,k), u_x(i,k,istep), istep, &
! alpha(i,k), phi(i,k), tortuosity(i,k), &
! 1.E10*w_b(i,k), 1.E10*u_b(i,k)
! end do
! write(12,*)
! end do
! end do
! close(12)
write(*,*) "Made physics of BBL, sediments"
!Get horizontal relaxation parameters from brom.yaml:
!hmixtype = 0, 1 or 2 for no horizontal relaxation (default), box model mixing respectively
do ip=1,par_max
hmixtype(i_max,ip) = get_brom_par('hmix_' // trim(par_name(ip)),0.0_rk)
hmixtype(:,ip)=hmixtype(i_max,ip)
if (hmixtype(i_max,ip).eq.1) then
write(*,*) "Horizontal relaxation assumed for " // trim(par_name(ip))
end if
if (hmixtype(i_max,ip).eq.2) then
! hmix_file = get_brom_name("hmix_filename_" // trim(par_name(ip)(13:))) !niva_oxydep_NUT
write(*,*) "Horizontal relaxation (ASCII) assumed for " // trim(par_name(ip))
!else if (hmixtype(i_max,ip).eq.2) then ! read relaxation files in two cases, also for top bondary condition #bctype_top(i_max,ip).eq.4.or.
open(20, file= get_brom_name("hmix_filename_" // trim(par_name(ip))))!'' // hmix_file
write(*,*) ("hmix_filename_" // trim(par_name(ip)))
do k=1,k_wat_bbl
do i_day=1,days_in_yr
read(20, *) i_dummy,i_dummy,cc_hmix(i_max,ip,k,i_day) ! data for relaxation(i_max,par_max,k_max,days_in_yr)
end do
end do
close(20)
do i=i_min,i_max-1
cc_hmix(i,:,:,:)=cc_hmix(i_max,:,:,:)
enddo
else if (bctype_top(i_max,ip).eq.4.) then
open(40, file = get_brom_name("bc_top_filename_" // trim(par_name(ip)))) !to boundary condition file
do i_day=1,days_in_yr
read(40, *) cc_top(i,ip,i_day)
end do
close(40)
do i=i_min,i_max-1
cc_top(i,:,:)=cc_top(i_max,:,:)
enddo
end if
end do
! read an array for injecting of something changing yearly
inj_changing = get_brom_par("inj_changing")
if (inj_changing.ne.0) then
open(21, file= get_brom_name("inj_smth_variable"))
inj_smth=0.0_rk
do iday=1,115
read(21, *) i_dummy, inj_smth(iday) !
enddo
inj_square = get_brom_par("inj_square")
endif
open(8,FILE = 'burying_rate.dat')
!Set constant forcings
wind_speed = get_brom_par("wind_speed") ! 10m wind speed [m s-1]
pco2_atm = get_brom_par("pco2_atm") ! CO2 partical pressure [ppm]
pco2_atm_1d(:) = pco2_atm ! Same pCO2 values for all the surface gridpoints
lat_light_1d(:) = lat_light ! Same latitude for all the surface gridpoints
wind_speed_1d(:) = wind_speed ! Same wind speed to all the surface gridpoints
swradWm2_1d(:) = swradWm2(1) ! Same surface irradiance to all the surface gridpoints
aice_1d(:) = aice(1)
hice_1d(:) = hice(1)
decimal_yearday=0.0_rk
end subroutine init_brom_transport
!=======================================================================================================================
!=======================================================================================================================
subroutine do_brom_transport()
!Executes the offline vertical transport model BROM-transport
use calculate, only: calculate_phys, calculate_sed, calculate_sed_eya, calculate_bubble
implicit none
integer :: id, idt, idf !time related
integer :: surf_flux_with_diff !1 to include surface fluxes in diffusion update, 0 to include in bgc update
integer :: bott_flux_with_diff !1 to include bottom fluxes in diffusion update, 0 to include in bgc update
!integer :: model_w_sed !1 to assume porosity effects for solutes and solids, 0 - sumplified approach
integer :: constant_w_sed !1 to assume constant burial (advection) velocities in the sediments
integer :: dynamic_w_sed !1 to assume dynamic burial (advection) velocities in the sediments depending on dVV(k_bbl_sed)
integer :: show_maxmin, show_kztCFL, show_wCFL, show_nan, show_nan_kztCFL, show_nan_wCFL !options for runtime output to screen
integer :: bc_units_convert, sediments_units_convert !options for conversion of concentrations units in the sediment
integer :: julianday, model_year
integer :: ist, istep, istep_new ! AB
integer :: i_count_pr, i_count_s, i_sec_pr
integer :: trawling_switch ! Switch to run a trawling experiment
integer :: k_trawling,k_erosion,i_trawling,start_trawling,k_suspension, closest_k_depth ! Auxiliary integer variables for bottom trawling experiments
integer :: k_inj,i_inj,inj_switch,inj_num,start_inj,stop_inj !#number of layer and column to inject into, start day, stop day number
integer :: start_inj2,stop_inj2,start_inj3,stop_inj3 !#start day, stop day number for several injections
real(rk) :: cnpar !"Implicitness" parameter for GOTM vertical diffusion (set in brom.yaml)
real(rk) :: cc0 !Resilient concentration (same for all variables)
real(rk) :: omega !angular frequency of sinusoidal forcing = 2*pi/365 rads/day
real(rk) :: O2stat !oxygen status of sediments (factor modulating the bioirrigation rate)
real(rk) :: a1_bioirr !to detect whether or not bioirrigation is activated
real(rk) :: kl_unifrom !uniform horizontal relaxation if prescribed
real(rk) :: tau_relax ! relaxation time (AB)
real(rk) :: fresh_PM_poros ! porosity of fresh precipitated PM (i.e. dVV)
real(rk) :: w_binf ! baseline rate of burying
real(rk) :: bu_co ! "Burial coeficient" for setting velosity exactly to the SWI proportional to the
! settling velocity in the water column (0<bu_co<1), 0 - for no setting velosity, (nd)
real(rk) :: N_bubbles ! Number of rising up bubbles
real(rk) :: injection_rate ! injection rate
real(rk) :: injection_rate_ini ! injection rate initial constant or multiplier if injection rate is a function
real(rk) :: start_inj_part_day ! share of day to start injection first day (0=midnight, 0.75= 18h00m etc.)
real(rk) :: depth_trawling ! Penetration depth of the trawling device in the sediments [m].
real(rk) :: depth_erosion ! Depth of the eroded layer during trawling [m].
real(rk) :: thickness_suspension ! Thickness of the water layer where resuspension occurs [m].
real(rk) :: vol_trawling ! Volume of a set of layers where substances are mixed after trawling
real(rk) :: mass_trawling ! mass of state variable (cc) in a set of layers during trawling.
real(rk) :: sumdz ! Depth within the sediments to interpolate with layers beneath
real(rk) :: interp_slope ! auxiliar variable to interpolate bottom layers of sediments onto upper layers after a trawling event
character(len=attribute_length), allocatable, dimension(:) :: inj_var_name