-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmarbl_interior_tendency_mod.F90
3839 lines (3142 loc) · 191 KB
/
marbl_interior_tendency_mod.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module marbl_interior_tendency_mod
use marbl_kinds_mod, only : int_kind
use marbl_kinds_mod, only : r8
use marbl_kinds_mod, only : log_kind
use marbl_kinds_mod, only : char_len
use marbl_constants_mod, only : T0_Kelvin
use marbl_constants_mod, only : c0
use marbl_constants_mod, only : c1
use marbl_constants_mod, only : c2
use marbl_constants_mod, only : c10
use marbl_constants_mod, only : mpercm
use marbl_constants_mod, only : spd
use marbl_constants_mod, only : dps
use marbl_constants_mod, only : yps
use marbl_interface_private_types, only : marbl_PAR_type
use marbl_interface_private_types, only : autotroph_derived_terms_type
use marbl_interface_private_types, only : autotroph_local_type
use marbl_interface_private_types, only : zooplankton_derived_terms_type
use marbl_interface_private_types, only : zooplankton_local_type
use marbl_interface_private_types, only : zooplankton_share_type
use marbl_interface_private_types, only : marbl_surface_flux_forcing_indexing_type
use marbl_interface_private_types, only : marbl_interior_tendency_forcing_indexing_type
use marbl_interface_private_types, only : marbl_tracer_index_type
use marbl_interface_private_types, only : marbl_particulate_share_type
use marbl_interface_private_types, only : marbl_interior_tendency_share_type
use marbl_interface_private_types, only : dissolved_organic_matter_type
use marbl_interface_private_types, only : carbonate_type
use marbl_interface_private_types, only : column_sinking_particle_type
use marbl_interface_private_types, only : co2calc_coeffs_type
use marbl_interface_private_types, only : co2calc_state_type
use marbl_interface_public_types, only : marbl_domain_type
use marbl_interface_public_types, only : marbl_forcing_fields_type
use marbl_interface_public_types, only : marbl_saved_state_type
use marbl_interface_public_types, only : marbl_running_mean_0d_type
use marbl_logging, only : marbl_log_type
use marbl_settings_mod, only : autotroph_cnt
use marbl_settings_mod, only : zooplankton_cnt
use marbl_settings_mod, only : max_grazer_prey_cnt
use marbl_settings_mod, only : lsource_sink
use marbl_settings_mod, only : lcheck_forcing
use marbl_settings_mod, only : ladjust_bury_coeff
use marbl_settings_mod, only : autotroph_settings
use marbl_settings_mod, only : zooplankton_settings
use marbl_settings_mod, only : dust_to_Fe
use marbl_settings_mod, only : denitrif_C_N
use marbl_settings_mod, only : parm_Red_Fe_C
use marbl_settings_mod, only : Q
use marbl_settings_mod, only : parm_scalelen_z
use marbl_settings_mod, only : parm_scalelen_vals
use marbl_settings_mod, only : caco3_poc_min
use marbl_settings_mod, only : DOCprod_refract
use marbl_settings_mod, only : DONprod_refract
use marbl_settings_mod, only : DOPprod_refract
use marbl_settings_mod, only : POCremin_refract
use marbl_settings_mod, only : PONremin_refract
use marbl_settings_mod, only : POPremin_refract
use marbl_settings_mod, only : f_toDON
use marbl_settings_mod, only : f_graze_CaCO3_remin
use marbl_settings_mod, only : f_graze_si_remin
use marbl_settings_mod, only : f_graze_sp_poc_lim
use marbl_settings_mod, only : parm_labile_ratio
use marbl_settings_mod, only : parm_o2_min
use marbl_settings_mod, only : parm_o2_min_delta
use marbl_settings_mod, only : parm_red_d_c_o2
use marbl_settings_mod, only : parm_red_d_c_o2_diaz
use marbl_settings_mod, only : parm_Remin_D_C_O2
use marbl_settings_mod, only : Qfe_zoo
use marbl_settings_mod, only : spc_poc_fac
use marbl_settings_mod, only : grazing_relationship_settings
use marbl_settings_mod, only : PON_bury_coeff
use marbl_settings_mod, only : del_ph
use marbl_settings_mod, only : phhi_3d_init
use marbl_settings_mod, only : phlo_3d_init
use marbl_settings_mod, only : bftt_dz_sum_thres
use marbl_pft_mod, only : Qp_zoo
implicit none
private
public :: marbl_interior_tendency_compute
public :: marbl_interior_tendency_adjust_bury_coeff
contains
!***********************************************************************
subroutine marbl_interior_tendency_compute( &
domain, &
bot_flux_to_tend, &
interior_tendency_forcings, &
tracers, &
surface_flux_forcing_indices, &
interior_tendency_forcing_indices, &
saved_state_ind, &
marbl_tracer_indices, &
marbl_timer_indices, &
PAR, &
dissolved_organic_matter, &
carbonate, &
autotroph_derived_terms, &
autotroph_local, &
zooplankton_derived_terms, &
zooplankton_local, &
zooplankton_share, &
saved_state, &
marbl_timers, &
interior_tendency_share, &
marbl_particulate_share, &
interior_tendency_diags, &
co2calc_coeffs, &
co2calc_state, &
interior_tendencies, &
glo_avg_fields_interior_tendency, &
marbl_status_log)
! Compute time derivatives for ecosystem state variables
use marbl_temperature, only : marbl_temperature_potemp
use marbl_ciso_interior_tendency_mod, only : marbl_ciso_interior_tendency_compute
use marbl_diagnostics_mod , only : marbl_diagnostics_interior_tendency_compute
use marbl_interface_private_types, only : marbl_internal_timers_type
use marbl_interface_private_types, only : marbl_timer_indexing_type
use marbl_interface_private_types, only : marbl_interior_tendency_saved_state_indexing_type
use marbl_interface_public_types, only : marbl_diagnostics_type
use marbl_interior_tendency_share_mod, only : marbl_interior_tendency_share_export_variables
use marbl_interior_tendency_share_mod, only : marbl_interior_tendency_share_export_zooplankton
use marbl_restore_mod, only : marbl_restore_compute_interior_restore
use marbl_settings_mod, only : lo2_consumption_scalef
use marbl_settings_mod, only : lp_remin_scalef
type(marbl_domain_type), intent(in) :: domain
real(r8), intent(in) :: bot_flux_to_tend(:) ! (km)
type(marbl_forcing_fields_type), intent(in) :: interior_tendency_forcings(:)
real(r8), intent(in) :: tracers(:,:) ! (tracer_cnt, km) tracer values
type(marbl_surface_flux_forcing_indexing_type), intent(in) :: surface_flux_forcing_indices
type(marbl_interior_tendency_forcing_indexing_type), intent(in) :: interior_tendency_forcing_indices
type(marbl_interior_tendency_saved_state_indexing_type), intent(in) :: saved_state_ind
type(marbl_tracer_index_type), intent(in) :: marbl_tracer_indices
type(marbl_timer_indexing_type), intent(in) :: marbl_timer_indices
type(marbl_PAR_type), intent(inout) :: PAR
type(dissolved_organic_matter_type), intent(inout) :: dissolved_organic_matter
type(carbonate_type), intent(inout) :: carbonate
type(autotroph_derived_terms_type), intent(inout) :: autotroph_derived_terms
type(autotroph_local_type), intent(inout) :: autotroph_local
type(zooplankton_derived_terms_type), intent(inout) :: zooplankton_derived_terms
type(zooplankton_local_type), intent(inout) :: zooplankton_local
type(zooplankton_share_type), intent(inout) :: zooplankton_share
type(marbl_saved_state_type), intent(inout) :: saved_state
type(marbl_internal_timers_type), intent(inout) :: marbl_timers
type(marbl_interior_tendency_share_type), intent(inout) :: interior_tendency_share
type(marbl_particulate_share_type), intent(inout) :: marbl_particulate_share
type(marbl_diagnostics_type), intent(inout) :: interior_tendency_diags
type(co2calc_coeffs_type), intent(inout) :: co2calc_coeffs
type(co2calc_state_type), intent(inout) :: co2calc_state
real(r8), intent(out) :: interior_tendencies(:,:) ! (tracer_cnt, km) computed source/sink terms
real(r8), intent(out) :: glo_avg_fields_interior_tendency(:)
type(marbl_log_type), intent(inout) :: marbl_status_log
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
character(len=*), parameter :: subname = 'marbl_interior_tendency_mod:marbl_interior_tendency_compute'
character(len=char_len) :: log_message
real(r8), dimension(size(tracers,1), domain%km) :: interior_restore
real(r8), dimension(size(tracers,1), domain%km) :: tracer_local
integer (int_kind) :: k ! vertical level index
real (r8) :: surf_press(domain%km) ! pressure in surface layer
real (r8) :: temperature(domain%km) ! in situ temperature
real (r8) :: o2_consumption_scalef(domain%km) ! O2 Consumption Scale Factor
real (r8) :: p_remin_scalef(domain%km) ! Particulate Remin Scale Factor
real (r8) :: O2_production(domain%km) ! O2 production
real (r8) :: O2_consumption(domain%km) ! O2 consumption
real (r8) :: nitrif(domain%km) ! nitrification (NH4 -> NO3) (mmol N/m^3/sec)
real (r8) :: denitrif(domain%km) ! WC nitrification (NO3 -> N2) (mmol N/m^3/sec)
real (r8) :: sed_denitrif(domain%km) ! sedimentary denitrification (nmol N/cm^3/sec)
real (r8) :: other_remin(domain%km) ! organic C remin not due oxic or denitrif (nmolC/cm^3/sec)
real (r8) :: Tfunc_auto(autotroph_cnt, domain%km) ! Temperature scaling for autotrophs
real (r8) :: Tfunc_zoo(zooplankton_cnt, domain%km) ! Temperature scaling for zooplankton
real (r8) :: Fe_scavenge_rate(domain%km) ! annual scavenging rate of iron as % of ambient
real (r8) :: Fe_scavenge(domain%km) ! loss of dissolved iron, scavenging (mmol Fe/m^3/sec)
real (r8) :: Lig_scavenge(domain%km) ! loss of Fe-binding Ligand from scavenging (mmol Fe/m^3/sec)
real (r8) :: QA_dust_def(domain%km)
real (r8) :: PON_remin(domain%km) ! remin of PON
real (r8) :: PON_sed_loss(domain%km) ! loss of PON to sediments
real (r8) :: Fefree(domain%km) ! unbound Fe
real (r8) :: Lig_prod(domain%km) ! production of Fe-binding Ligand
real (r8) :: Lig_photochem(domain%km) ! loss of Fe-binding Ligand from UV radiation
real (r8) :: Lig_deg(domain%km) ! loss of Fe-binding Ligand from bacterial degradation
real (r8) :: Lig_loss(domain%km) ! loss of Fe-binding Ligand
real (r8) :: totalChl_local(domain%km) ! local value of totalChl
! NOTE(bja, 2015-07) vectorization: arrays that are (n, k, c, i)
! probably can not be vectorized reasonably over c without memory
! copies. If we break up the main k loop, some of the (k, c) loops
! can probably be vectorized over k and / or c!
!-----------------------------------------------------------------------
! NOTE(bja, 2015-07) interior_tendencies=0 must come before the "not
! lsource_sink check to ensure correct answer when not doing
! computations.
interior_tendencies(:, :) = c0
if (abs(c1 - sum(domain%delta_z(:) * bot_flux_to_tend(:))) > bftt_dz_sum_thres) then
write(log_message, "(A, E11.3, A)") "1 - sum(bot_flux_to_tend * dz) = ", &
c1 - sum(domain%delta_z(:) * bot_flux_to_tend(:)), &
", which is too far from 0 for conservation"
call marbl_status_log%log_error(log_message, subname)
do k=1,domain%km
write(log_message, *) k, domain%delta_z(k), bot_flux_to_tend(k), domain%zw(k), &
c1 - sum(domain%delta_z(1:k) * bot_flux_to_tend(1:k))
call marbl_status_log%log_error(log_message, subname)
end do
return
end if
if (.not. lsource_sink) then
!-----------------------------------------------------------------------
! exit immediately if computations are not to be performed
!-----------------------------------------------------------------------
return
endif
! Verify forcing is consistent
if (lcheck_forcing) &
call check_forcing(interior_tendency_forcings, interior_tendency_forcing_indices, marbl_status_log)
associate( &
km => domain%km, &
kmt => domain%kmt, &
num_PAR_subcols => domain%num_PAR_subcols, &
delta_z1 => domain%delta_z(1), &
POC => marbl_particulate_share%POC, &
POP => marbl_particulate_share%POP, &
P_CaCO3 => marbl_particulate_share%P_CaCO3, &
P_CaCO3_ALT_CO2 => marbl_particulate_share%P_CaCO3_ALT_CO2,&
P_SiO2 => marbl_particulate_share%P_SiO2, &
dust => marbl_particulate_share%dust, &
P_iron => marbl_particulate_share%P_iron, &
ph_prev_col => saved_state%state(saved_state_ind%ph_col)%field_3d(:,1), &
ph_prev_alt_co2_col => saved_state%state(saved_state_ind%ph_alt_co2_col)%field_3d(:,1), &
! Hard-coding in that there is only 1 column passed in at a time!
dust_flux_in => interior_tendency_forcings(interior_tendency_forcing_indices%dustflux_id)%field_0d(1), &
potemp => interior_tendency_forcings(interior_tendency_forcing_indices%potemp_id)%field_1d(1,:), &
pressure => interior_tendency_forcings(interior_tendency_forcing_indices%pressure_id)%field_1d(1,:), &
salinity => interior_tendency_forcings(interior_tendency_forcing_indices%salinity_id)%field_1d(1,:), &
fesedflux => interior_tendency_forcings(interior_tendency_forcing_indices%fesedflux_id)%field_1d(1,:),&
po4_ind => marbl_tracer_indices%po4_ind, &
no3_ind => marbl_tracer_indices%no3_ind, &
sio3_ind => marbl_tracer_indices%sio3_ind, &
nh4_ind => marbl_tracer_indices%nh4_ind, &
fe_ind => marbl_tracer_indices%fe_ind, &
lig_ind => marbl_tracer_indices%lig_ind, &
o2_ind => marbl_tracer_indices%o2_ind, &
dic_ind => marbl_tracer_indices%dic_ind, &
dic_alt_co2_ind => marbl_tracer_indices%dic_alt_co2_ind, &
doc_ind => marbl_tracer_indices%doc_ind, &
don_ind => marbl_tracer_indices%don_ind, &
dop_ind => marbl_tracer_indices%dop_ind, &
dopr_ind => marbl_tracer_indices%dopr_ind, &
donr_ind => marbl_tracer_indices%donr_ind, &
docr_ind => marbl_tracer_indices%docr_ind &
)
!-----------------------------------------------------------------------
! Compute in situ temp
! displace surface parcel with temp potemp to pressure
!-----------------------------------------------------------------------
surf_press(1:kmt) = c0
temperature(1:kmt) = marbl_temperature_potemp(kmt, salinity, potemp, surf_press, pressure)
temperature(kmt+1:km) = c0
!-----------------------------------------------------------------------
! local copies of optional forcings
! these are not handled via associate block because their forcing indices might be zero
!-----------------------------------------------------------------------
if (lo2_consumption_scalef) then
o2_consumption_scalef(:) = &
interior_tendency_forcings(interior_tendency_forcing_indices%o2_consumption_scalef_id)%field_1d(1,:)
else
o2_consumption_scalef(:) = c1
endif
if (lp_remin_scalef) then
p_remin_scalef(:) = &
interior_tendency_forcings(interior_tendency_forcing_indices%p_remin_scalef_id)%field_1d(1,:)
else
p_remin_scalef(:) = c1
endif
!-----------------------------------------------------------------------
! Compute adjustment to tendencies due to tracer restoring
!-----------------------------------------------------------------------
call marbl_restore_compute_interior_restore( &
tracers, &
interior_tendency_forcings, &
interior_tendency_forcing_indices, &
interior_restore)
!-----------------------------------------------------------------------
! create local copies of model tracers
!-----------------------------------------------------------------------
call setup_local_tracers(kmt, marbl_tracer_indices, tracers(:,:), autotroph_local, &
tracer_local(:,:), zooplankton_local, totalChl_local)
call set_surface_particulate_terms(surface_flux_forcing_indices, POC, POP, P_CaCO3, &
P_CaCO3_ALT_CO2, P_SiO2, dust, P_iron, QA_dust_def(:), dust_flux_in)
call marbl_timers%start(marbl_timer_indices%carbonate_chem_id, &
marbl_status_log)
call compute_carbonate_chemistry(domain, temperature, pressure, &
salinity, tracer_local(:, :), marbl_tracer_indices, co2calc_coeffs, &
co2calc_state, carbonate, ph_prev_col(:), ph_prev_alt_co2_col(:), &
marbl_status_log)
call marbl_timers%stop(marbl_timer_indices%carbonate_chem_id, &
marbl_status_log)
if (marbl_status_log%labort_marbl) then
call marbl_status_log%log_error_trace(&
'compute_carbonate_chemistry()', subname)
return
end if
call compute_PAR(domain, interior_tendency_forcings, interior_tendency_forcing_indices, &
totalChl_local, PAR)
call compute_autotroph_elemental_ratios(km, autotroph_local, marbl_tracer_indices, tracer_local, &
autotroph_derived_terms)
call compute_temperature_functional_form(temperature(:), autotroph_settings(:)%Tref, &
autotroph_settings(:)%temp_func_form_iopt, autotroph_settings(:)%Ea, Tfunc_auto(:,:))
call compute_temperature_functional_form(temperature(:), zooplankton_settings(:)%Tref, &
zooplankton_settings(:)%temp_func_form_iopt, zooplankton_settings(:)%Ea, Tfunc_zoo(:,:))
call compute_Pprime(km, domain%zt, autotroph_local, temperature, autotroph_derived_terms%Pprime)
call compute_autotroph_uptake(km, marbl_tracer_indices, tracer_local(:, :), carbonate, autotroph_derived_terms)
call compute_autotroph_photosynthesis(km, num_PAR_subcols, autotroph_local, temperature(:), &
Tfunc_auto(:,:), PAR%col_frac(:), PAR%avg(:,:), autotroph_derived_terms)
call compute_autotroph_nutrient_uptake(marbl_tracer_indices, autotroph_derived_terms)
call compute_autotroph_calcification(km, autotroph_local, temperature, carbonate, autotroph_derived_terms)
call compute_autotroph_nfixation(km, autotroph_derived_terms)
call compute_autotroph_loss(km, Tfunc_auto(:,:), autotroph_derived_terms)
call compute_Zprime(km, domain%zt, zooplankton_local%C, Tfunc_zoo(:,:), zooplankton_derived_terms)
call compute_grazing(km, Tfunc_zoo(:,:), zooplankton_local, zooplankton_derived_terms, autotroph_derived_terms)
call compute_routing(km, zooplankton_derived_terms, autotroph_derived_terms)
call compute_dissolved_organic_matter (km, marbl_tracer_indices, num_PAR_subcols, &
PAR, zooplankton_derived_terms, autotroph_derived_terms, &
delta_z1, tracer_local(:, :), dissolved_organic_matter)
do k = 1, km
call compute_scavenging(k, km, marbl_tracer_indices, tracer_local(:,:), &
POC, P_CaCO3, P_SiO2, dust, Fefree(:), Fe_scavenge_rate(:), &
Fe_scavenge(:), Lig_scavenge(:), marbl_status_log)
if (marbl_status_log%labort_marbl) then
call marbl_status_log%log_error_trace('compute_scavenging()', subname)
return
end if
call compute_large_detritus_prod(k, domain, marbl_tracer_indices, zooplankton_derived_terms, &
autotroph_derived_terms, Fe_scavenge(k), &
POC, POP, P_CaCO3, P_CaCO3_ALT_CO2, P_SiO2, dust, P_iron, &
dissolved_organic_matter%DOP_loss_P_bal(k), marbl_status_log)
! FIXME #28: need to pull particulate share out
! of compute_particulate_terms!
call compute_particulate_terms(k, domain, bot_flux_to_tend, &
marbl_particulate_share, p_remin_scalef(k), &
POC, POP, P_CaCO3, P_CaCO3_ALT_CO2, &
P_SiO2, dust, P_iron, PON_remin(:), PON_sed_loss(k), &
QA_dust_def(k), &
tracer_local(:, :), carbonate, sed_denitrif(:), &
other_remin(:), fesedflux(k), marbl_tracer_indices, &
glo_avg_fields_interior_tendency, marbl_status_log)
if (marbl_status_log%labort_marbl) then
call marbl_status_log%log_error_trace('compute_particulate_terms()', subname)
return
end if
if (k < km) then
call update_particulate_terms_from_prior_level(k+1, POC, POP, P_CaCO3, &
P_CaCO3_ALT_CO2, P_SiO2, dust, P_iron, QA_dust_def(:))
endif
end do ! k
call compute_Lig_terms(km, num_PAR_subcols, marbl_tracer_indices, &
POC%remin(:), dissolved_organic_matter%DOC_prod(:), PAR, delta_z1, tracer_local, Lig_scavenge(:), &
autotroph_derived_terms%photoFe(:,:), Lig_prod(:), Lig_photochem(:), Lig_deg(:), Lig_loss(:))
call compute_nitrif(kmt, km, num_PAR_subcols, marbl_tracer_indices, PAR, tracer_local(:,:), nitrif(:))
call compute_denitrif(km, marbl_tracer_indices, tracer_local(:, :), &
dissolved_organic_matter%DOC_remin(:), &
dissolved_organic_matter%DOCr_remin(:), &
POC%remin(:), other_remin(:), sed_denitrif(:), denitrif(:))
call compute_local_tendencies(km, marbl_tracer_indices, autotroph_derived_terms, &
zooplankton_derived_terms, &
dissolved_organic_matter, &
nitrif(:), denitrif(:), sed_denitrif(:), &
Fe_scavenge(:), Lig_prod(:), Lig_loss(:), &
P_iron%remin(:), POC%remin(:), POP%remin(:), &
P_SiO2%remin(:), P_CaCO3%remin(:), P_CaCO3_ALT_CO2%remin(:), &
other_remin(:), PON_remin(:), &
tracer_local(:,:), &
o2_consumption_scalef(:), &
o2_production(:), o2_consumption(:), &
interior_tendencies(:,:))
! Compute interior diagnostics
call marbl_diagnostics_interior_tendency_compute( &
domain, &
interior_tendency_forcing_indices, &
interior_tendency_forcings, &
temperature, &
interior_tendencies, &
marbl_tracer_indices, &
carbonate, &
autotroph_local, &
autotroph_derived_terms, &
zooplankton_derived_terms, &
dissolved_organic_matter, &
marbl_particulate_share, &
PAR, &
PON_remin, PON_sed_loss, &
sed_denitrif, other_remin, nitrif, denitrif, &
tracers(o2_ind, :), o2_production, o2_consumption, &
fe_scavenge, fe_scavenge_rate, &
Lig_prod, Lig_loss, Lig_scavenge, Fefree, &
Lig_photochem, Lig_deg, &
interior_restore, &
interior_tendency_diags, &
marbl_status_log)
if (marbl_status_log%labort_marbl) then
call marbl_status_log%log_error_trace(&
'marbl_diagnostics_interior_tendency_compute()', subname)
return
end if
!-----------------------------------------------------------------------
! Compute time derivatives for ecosystem carbon isotope state variables
!-----------------------------------------------------------------------
! Store any variables needed in other tracer modules
! FIXME #28: need to pull particulate share out
! of compute_particulate_terms!
call marbl_interior_tendency_share_export_variables(km, marbl_tracer_indices, &
tracer_local(:,:), carbonate, dissolved_organic_matter, &
QA_dust_def(:), interior_tendency_share)
call marbl_interior_tendency_share_export_zooplankton(zooplankton_local, &
zooplankton_derived_terms, zooplankton_share)
! call marbl_ciso_interior_tendency_compute()
call marbl_ciso_interior_tendency_compute( &
marbl_domain = domain, &
bot_flux_to_tend = bot_flux_to_tend(:), &
interior_tendency_share = interior_tendency_share, &
zooplankton_share = zooplankton_share, &
marbl_particulate_share = marbl_particulate_share, &
autotroph_derived_terms = autotroph_derived_terms, &
tracer_local = tracer_local, &
autotroph_local = autotroph_local, &
temperature = temperature, &
marbl_tracer_indices = marbl_tracer_indices, &
interior_tendencies = interior_tendencies, &
marbl_interior_diags = interior_tendency_diags, &
marbl_status_log = marbl_status_log)
if (marbl_status_log%labort_marbl) then
call marbl_status_log%log_error_trace(&
'marbl_ciso_interior_tendency_compute()', subname)
return
end if
end associate
! ADD RESTORING
interior_tendencies = interior_tendencies + interior_restore
end subroutine marbl_interior_tendency_compute
!***********************************************************************
subroutine compute_PAR(domain, interior_tendency_forcings, interior_tendency_forcing_ind, &
totalChl_local, PAR)
!-----------------------------------------------------------------------
! compute PAR related quantities
! Morel, Maritorena, JGR, Vol 106, No. C4, pp 7163--7180, 2001
! 0.45 fraction of incoming SW -> PAR (non-dim)
!-----------------------------------------------------------------------
use marbl_settings_mod, only : f_qsw_par
! PAR is intent(inout) because it components, while entirely set here, are allocated elsewhere
type(marbl_domain_type) , intent(in) :: domain
type(marbl_forcing_fields_type) , intent(in) :: interior_tendency_forcings(:)
type(marbl_interior_tendency_forcing_indexing_type), intent(in) :: interior_tendency_forcing_ind
real(r8) , intent(in) :: totalChl_local(:)
type(marbl_PAR_type) , intent(inout) :: PAR
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
! PAR below this threshold is changed to 0.0
! tendencies from PAR below this threshold are small enough to not affect tracer values
real (r8), parameter :: PAR_threshold = 1.0e-19_r8
real (r8) :: WORK1(domain%kmt)
integer(int_kind) :: k, subcol_ind
!-----------------------------------------------------------------------
associate( &
dkm => domain%km, &
column_kmt => domain%kmt, &
delta_z => domain%delta_z, &
PAR_nsubcols => domain%num_PAR_subcols &
)
!-----------------------------------------------------------------------
! set depth independent quantities, sub-column fractions and PAR at surface
! ignore provided shortwave where col_frac == 0
!-----------------------------------------------------------------------
if (interior_tendency_forcing_ind%PAR_col_frac_id .ne. 0) then
PAR%col_frac(:) = interior_tendency_forcings(interior_tendency_forcing_ind%PAR_col_frac_id)%field_1d(1,:)
else
PAR%col_frac(:) = c1
end if
where (PAR%col_frac(:) > c0)
PAR%interface(0,:) = f_qsw_par &
* interior_tendency_forcings(interior_tendency_forcing_ind%surf_shortwave_id)%field_1d(1,:)
elsewhere
PAR%interface(0,:) = c0
end where
where (PAR%interface(0,:) < PAR_threshold)
PAR%interface(0,:) = c0
end where
!-----------------------------------------------------------------------
! avoid further computations, such as computing attenuation coefficient, if there is no light
! treat forcing as a single dark value, by setting col_frac(1) to 1
!-----------------------------------------------------------------------
if (all(PAR%interface(0,:) == c0)) then
PAR%col_frac(:) = c0
PAR%col_frac(1) = c1
PAR%interface(:,:) = c0
PAR%avg(:,:) = c0
PAR%KPARdz(:) = c0
return
end if
!-----------------------------------------------------------------------
! compute attenuation coefficient over column
!-----------------------------------------------------------------------
WORK1(:) = max(totalChl_local(1:column_kmt), 0.02_r8)
do k = 1, column_kmt
if (WORK1(k) < 0.13224_r8) then
PAR%KPARdz(k) = 0.000919_r8*(WORK1(k)**0.3536_r8)
else
PAR%KPARdz(k) = 0.001131_r8*(WORK1(k)**0.4562_r8)
end if
PAR%KPARdz(k) = PAR%KPARdz(k) * delta_z(k)
end do
PAR%KPARdz(column_kmt+1:dkm) = c0
!-----------------------------------------------------------------------
! propagate PAR values through column, only on subcolumns with PAR>0
! note that if col_frac is 0, then so is PAR
!-----------------------------------------------------------------------
WORK1(:) = exp(-PAR%KPARdz(1:column_kmt))
do subcol_ind = 1, PAR_nsubcols
if (PAR%interface(0,subcol_ind) > c0) then
! this loop will probably not vectorize
do k = 1, column_kmt
PAR%interface(k,subcol_ind) = PAR%interface(k-1,subcol_ind) * WORK1(k)
if (PAR%interface(k,subcol_ind) < PAR_threshold) then
PAR%interface(k:column_kmt,subcol_ind) = c0
exit
end if
end do
PAR%interface(column_kmt+1:dkm,subcol_ind) = c0
do k = 1, column_kmt
PAR%avg(k,subcol_ind) = PAR%interface(k-1,subcol_ind) * (c1 - WORK1(k)) / PAR%KPARdz(k)
end do
PAR%avg(column_kmt+1:dkm,subcol_ind) = c0
else
PAR%interface(1:dkm,subcol_ind) = c0
PAR%avg(1:dkm,subcol_ind) = c0
end if
end do
end associate
end subroutine compute_PAR
!***********************************************************************
subroutine marbl_interior_tendency_adjust_bury_coeff(marbl_particulate_share, &
glo_avg_rmean_interior_tendency, glo_avg_rmean_surface_flux, &
glo_scalar_rmean_interior_tendency, glo_scalar_interior_tendency)
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_CaCO3_bury
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_POC_bury
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_POP_bury
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_bSi_bury
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_d_POC_bury_d_bury_coeff
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_d_POP_bury_d_bury_coeff
use marbl_glo_avg_mod, only : glo_avg_field_ind_interior_tendency_d_bSi_bury_d_bury_coeff
use marbl_glo_avg_mod, only : glo_avg_field_ind_surface_flux_C_input
use marbl_glo_avg_mod, only : glo_avg_field_ind_surface_flux_P_input
use marbl_glo_avg_mod, only : glo_avg_field_ind_surface_flux_Si_input
use marbl_glo_avg_mod, only : glo_scalar_ind_interior_tendency_POC_bury_coeff
use marbl_glo_avg_mod, only : glo_scalar_ind_interior_tendency_POP_bury_coeff
use marbl_glo_avg_mod, only : glo_scalar_ind_interior_tendency_bSi_bury_coeff
type (marbl_particulate_share_type), intent(inout) :: marbl_particulate_share
type (marbl_running_mean_0d_type) , intent(in) :: glo_avg_rmean_interior_tendency(:)
type (marbl_running_mean_0d_type) , intent(in) :: glo_avg_rmean_surface_flux(:)
type (marbl_running_mean_0d_type) , intent(in) :: glo_scalar_rmean_interior_tendency(:)
real (r8) , intent(inout) :: glo_scalar_interior_tendency(:)
!-----------------------------------------------------------------------
if (.not. ladjust_bury_coeff) return
associate( &
POC_bury_coeff => marbl_particulate_share%POC_bury_coeff, &
POP_bury_coeff => marbl_particulate_share%POP_bury_coeff, &
bSi_bury_coeff => marbl_particulate_share%bSi_bury_coeff, &
rmean_CaCO3_bury_avg => glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_CaCO3_bury)%rmean, &
rmean_POC_bury_avg => glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_POC_bury)%rmean, &
rmean_POP_bury_avg => glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_POP_bury)%rmean, &
rmean_bSi_bury_avg => glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_bSi_bury)%rmean, &
rmean_POC_bury_deriv_avg => &
glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_d_POC_bury_d_bury_coeff)%rmean, &
rmean_POP_bury_deriv_avg => &
glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_d_POP_bury_d_bury_coeff)%rmean, &
rmean_bSi_bury_deriv_avg => &
glo_avg_rmean_interior_tendency(glo_avg_field_ind_interior_tendency_d_bSi_bury_d_bury_coeff)%rmean, &
rmean_C_input_avg => glo_avg_rmean_surface_flux(glo_avg_field_ind_surface_flux_C_input)%rmean, &
rmean_P_input_avg => glo_avg_rmean_surface_flux(glo_avg_field_ind_surface_flux_P_input)%rmean, &
rmean_Si_input_avg => glo_avg_rmean_surface_flux(glo_avg_field_ind_surface_flux_Si_input)%rmean, &
rmean_POC_bury_coeff => &
glo_scalar_rmean_interior_tendency(glo_scalar_ind_interior_tendency_POC_bury_coeff)%rmean, &
rmean_POP_bury_coeff => &
glo_scalar_rmean_interior_tendency(glo_scalar_ind_interior_tendency_POP_bury_coeff)%rmean, &
rmean_bSi_bury_coeff => &
glo_scalar_rmean_interior_tendency(glo_scalar_ind_interior_tendency_bSi_bury_coeff)%rmean &
)
! Newton's method for POC_bury(coeff) + CaCO3_bury - C_input = 0
POC_bury_coeff = rmean_POC_bury_coeff &
- (rmean_POC_bury_avg + rmean_CaCO3_bury_avg - rmean_C_input_avg) &
/ rmean_POC_bury_deriv_avg
! Newton's method for POP_bury(coeff) - P_input = 0
POP_bury_coeff = rmean_POP_bury_coeff &
- (rmean_POP_bury_avg - rmean_P_input_avg) / rmean_POP_bury_deriv_avg
! Newton's method for bSi_bury(coeff) - Si_input = 0
bSi_bury_coeff = rmean_bSi_bury_coeff &
- (rmean_bSi_bury_avg - rmean_Si_input_avg) / rmean_bSi_bury_deriv_avg
! copy computed bury coefficients into output argument
glo_scalar_interior_tendency(glo_scalar_ind_interior_tendency_POC_bury_coeff) = POC_bury_coeff
glo_scalar_interior_tendency(glo_scalar_ind_interior_tendency_POP_bury_coeff) = POP_bury_coeff
glo_scalar_interior_tendency(glo_scalar_ind_interior_tendency_bSi_bury_coeff) = bSi_bury_coeff
end associate
end subroutine marbl_interior_tendency_adjust_bury_coeff
!***********************************************************************
subroutine setup_local_tracers(column_kmt, marbl_tracer_indices, tracers, &
autotroph_local, tracer_local, zooplankton_local, totalChl_local)
!-----------------------------------------------------------------------
! create local copies of model tracers
! treat negative values as zero, apply mask to local copies
!-----------------------------------------------------------------------
integer(int_kind) , intent(in) :: column_kmt
type(marbl_tracer_index_type), intent(in) :: marbl_tracer_indices
real (r8) , intent(in) :: tracers(:,:)
type(autotroph_local_type) , intent(inout) :: autotroph_local
real (r8) , intent(out) :: tracer_local(:,:)
type(zooplankton_local_type) , intent(inout) :: zooplankton_local
real (r8) , intent(out) :: totalChl_local(:)
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
integer (int_kind) :: k ! vertical loop index
integer (int_kind) :: zoo_ind, auto_ind, n ! tracer indices
!-----------------------------------------------------------------------
do k = 1, column_kmt
tracer_local(:,k) = max(c0, tracers(1:size(tracer_local,1),k))
end do
do k = column_kmt+1, size(tracer_local,2)
tracer_local(:,k) = c0
end do
!-----------------------------------------------------------------------
! populate zooplankton specific arrays from tracer_local
!-----------------------------------------------------------------------
do zoo_ind = 1, zooplankton_cnt
n = marbl_tracer_indices%zoo_inds(zoo_ind)%C_ind
zooplankton_local%C(zoo_ind,:) = tracer_local(n,:)
end do
!-----------------------------------------------------------------------
! populate autotroph specific arrays from tracer_local
!-----------------------------------------------------------------------
do auto_ind = 1, autotroph_cnt
n = marbl_tracer_indices%auto_inds(auto_ind)%Chl_ind
autotroph_local%Chl(auto_ind,:) = tracer_local(n,:)
n = marbl_tracer_indices%auto_inds(auto_ind)%C_ind
autotroph_local%C(auto_ind,:) = tracer_local(n,:)
n = marbl_tracer_indices%auto_inds(auto_ind)%P_ind
if (n > 0) then
autotroph_local%P(auto_ind,:) = tracer_local(n,:)
else
autotroph_local%P(auto_ind,:) = autotroph_settings(auto_ind)%Qp_fixed * autotroph_local%C(auto_ind,:)
end if
n = marbl_tracer_indices%auto_inds(auto_ind)%Fe_ind
autotroph_local%Fe(auto_ind,:) = tracer_local(n,:)
n = marbl_tracer_indices%auto_inds(auto_ind)%Si_ind
if (n > 0) then
autotroph_local%Si(auto_ind,:) = tracer_local(n,:)
end if
n = marbl_tracer_indices%auto_inds(auto_ind)%CaCO3_ind
if (n > 0) then
autotroph_local%CaCO3(auto_ind,:) = tracer_local(n,:)
end if
! Carbon isotope elements of autotroph_local
n = marbl_tracer_indices%auto_inds(auto_ind)%C13_ind
if (n > 0) then
autotroph_local%C13(auto_ind,:) = tracer_local(n,:)
end if
n = marbl_tracer_indices%auto_inds(auto_ind)%C14_ind
if (n > 0) then
autotroph_local%C14(auto_ind,:) = tracer_local(n,:)
end if
n = marbl_tracer_indices%auto_inds(auto_ind)%Ca13CO3_ind
if (n > 0) then
autotroph_local%Ca13CO3(auto_ind,:) = tracer_local(n,:)
end if
n = marbl_tracer_indices%auto_inds(auto_ind)%Ca14CO3_ind
if (n > 0) then
autotroph_local%Ca14CO3(auto_ind,:) = tracer_local(n,:)
end if
end do
! autotroph consistency check
call autotroph_zero_consistency_enforce(column_kmt, marbl_tracer_indices, autotroph_local)
! set totalChl_local
totalChl_local = sum(autotroph_local%Chl(:,:), dim=1)
end subroutine setup_local_tracers
!***********************************************************************
subroutine set_surface_particulate_terms(surface_flux_forcing_indices, POC, POP, P_CaCO3, &
P_CaCO3_ALT_CO2, P_SiO2, dust, P_iron, QA_dust_def, NET_DUST_IN)
! Set incoming fluxes (put into outgoing flux for first level usage).
! Set dissolution length, production fraction and mass terms.
!
! The first 6 arguments are intent(inout) in
! order to preserve contents on other blocks.
! !USES:
use marbl_settings_mod, only : parm_POC_diss
use marbl_settings_mod, only : parm_CaCO3_diss
use marbl_settings_mod, only : parm_CaCO3_gamma
use marbl_settings_mod, only : parm_hPOC_CaCO3_ratio
use marbl_settings_mod, only : parm_SiO2_diss
use marbl_settings_mod, only : parm_SiO2_gamma
use marbl_settings_mod, only : parm_hPOC_SiO2_ratio
use marbl_settings_mod, only : parm_hPOC_dust_ratio
real (r8) , intent(in) :: net_dust_in ! dust flux
type(marbl_surface_flux_forcing_indexing_type), intent(in) :: surface_flux_forcing_indices
type(column_sinking_particle_type) , intent(inout) :: POC ! base units = nmol C
type(column_sinking_particle_type) , intent(inout) :: POP ! base units = nmol P
type(column_sinking_particle_type) , intent(inout) :: P_CaCO3 ! base units = nmol CaCO3
type(column_sinking_particle_type) , intent(inout) :: P_CaCO3_ALT_CO2 ! base units = nmol CaCO3
type(column_sinking_particle_type) , intent(inout) :: P_SiO2 ! base units = nmol SiO2
type(column_sinking_particle_type) , intent(inout) :: dust ! base units = g
type(column_sinking_particle_type) , intent(inout) :: P_iron ! base units = nmol Fe
real (r8) , intent(inout) :: QA_dust_def(:) ! incoming deficit in the QA(dust) POC flux (km)
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
integer(int_kind) :: ksurf
!-----------------------------------------------------------------------
! parameters, from Armstrong et al. 2000
!
! July 2002, length scale for excess POC and bSI modified by temperature
! Value given here is at Tref of 30 degC, JKM
!-----------------------------------------------------------------------
POC%diss = parm_POC_diss ! diss. length (cm), modified by TEMP
POC%gamma = c0 ! not used
POC%mass = 12.01_r8 ! molecular weight of C
POC%rho = c0 ! not used
POP%diss = parm_POC_diss ! not used
POP%gamma = c0 ! not used
POP%mass = 30.974_r8 ! molecular weight of P
POP%rho = c0 ! not used
P_CaCO3%diss = parm_CaCO3_diss ! diss. length (cm)
P_CaCO3%gamma = parm_CacO3_gamma! prod frac -> hard subclass
P_CaCO3%mass = 100.09_r8 ! molecular weight of CaCO
P_CaCO3%rho = parm_hPOC_CaCO3_ratio * P_CaCO3%mass / POC%mass ! QA mass ratio for CaCO3
P_CaCO3_ALT_CO2%diss = P_CaCO3%diss
P_CaCO3_ALT_CO2%gamma = P_CaCO3%gamma
P_CaCO3_ALT_CO2%mass = P_CaCO3%mass
P_CaCO3_ALT_CO2%rho = P_CaCO3%rho
P_SiO2%diss = parm_SiO2_diss ! diss. length (cm), modified by TEMP
P_SiO2%gamma = parm_SiO2_gamma ! prod frac -> hard subclass
P_SiO2%mass = 60.08_r8 ! molecular weight of SiO2
P_SiO2%rho = parm_hPOC_SiO2_ratio * P_SiO2%mass / POC%mass ! QA mass ratio for SiO2
dust%diss = 40000.0_r8 ! diss. length (cm)
dust%gamma = 0.98_r8 ! prod frac -> hard subclass
dust%mass = 1.0e9_r8 ! base units are already grams
dust%rho = parm_hPOC_dust_ratio * dust%mass / POC%mass ! QA mass ratio for dust
P_iron%diss = 60000.0_r8 ! diss. length (cm) - not used
P_iron%gamma = c0 ! prod frac -> hard subclass - not used
P_iron%mass = c0 ! not used
P_iron%rho = c0 ! not used
!-----------------------------------------------------------------------
! Set incoming fluxes
!-----------------------------------------------------------------------
ksurf = 1
P_CaCO3%sflux_in(ksurf) = c0
P_CaCO3%hflux_in(ksurf) = c0
P_CaCO3_ALT_CO2%sflux_in(ksurf) = c0
P_CaCO3_ALT_CO2%hflux_in(ksurf) = c0
P_SiO2%sflux_in(ksurf) = c0
P_SiO2%hflux_in(ksurf) = c0
if (surface_flux_forcing_indices%dust_flux_id.ne.0) then
dust%sflux_in(ksurf) = (c1 - dust%gamma) * net_dust_in
dust%hflux_in(ksurf) = dust%gamma * net_dust_in
else
dust%sflux_in(ksurf) = c0
dust%hflux_in(ksurf) = c0
end if
P_iron%sflux_in(ksurf) = c0
P_iron%hflux_in(ksurf) = c0
!-----------------------------------------------------------------------
! Hard POC is QA flux and soft POC is excess POC.
!-----------------------------------------------------------------------
POC%sflux_in(ksurf) = c0
POC%hflux_in(ksurf) = c0
POP%sflux_in(ksurf) = c0
POP%hflux_in(ksurf) = c0
!-----------------------------------------------------------------------
! Compute initial QA(dust) POC flux deficit.
!-----------------------------------------------------------------------
QA_dust_def(ksurf) = dust%rho * (dust%sflux_in(ksurf) + dust%hflux_in(ksurf))
end subroutine set_surface_particulate_terms
!***********************************************************************
subroutine compute_carbonate_chemistry(domain, temperature, press_bar, &
salinity, tracer_local, marbl_tracer_indices, &
co2calc_coeffs, co2calc_state, carbonate, ph_prev_col, &
ph_prev_alt_co2_col, marbl_status_log)
use marbl_co2calc_mod, only : marbl_co2calc_interior
use marbl_co2calc_mod, only : marbl_co2calc_co3_sat_vals
type(marbl_domain_type), intent(in) :: domain
real (r8), intent(in) :: temperature(:)
real (r8), intent(in) :: press_bar(:)
real (r8), intent(in) :: salinity(:)
real (r8), intent(in) :: tracer_local(:,:) ! local copies of model tracer concentrations
type(marbl_tracer_index_type), intent(in) :: marbl_tracer_indices
type(co2calc_coeffs_type), intent(inout) :: co2calc_coeffs
type(co2calc_state_type), intent(inout) :: co2calc_state
type(carbonate_type), intent(inout) :: carbonate
real(r8), intent(inout) :: ph_prev_col(:) ! km
real(r8), intent(inout) :: ph_prev_alt_co2_col(:) ! km
type(marbl_log_type), intent(inout) :: marbl_status_log
!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
character(len=*), parameter :: subname = 'marbl_interior_tendency_mod:compute_carbonate_chemistry'
integer :: k
real(r8), dimension(domain%km) :: ph_lower_bound
real(r8), dimension(domain%km) :: ph_upper_bound
real(r8), dimension(domain%km) :: dic_loc
real(r8), dimension(domain%km) :: dic_alt_co2_loc
real(r8), dimension(domain%km) :: alk_loc
real(r8), dimension(domain%km) :: alk_alt_co2_loc
real(r8), dimension(domain%km) :: po4_loc
real(r8), dimension(domain%km) :: sio3_loc
! make local copies instead of using associate construct because of gnu fortran bug
! https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68546
dic_loc = tracer_local(marbl_tracer_indices%dic_ind,:)
dic_alt_co2_loc = tracer_local(marbl_tracer_indices%dic_alt_co2_ind,:)
alk_loc = tracer_local(marbl_tracer_indices%alk_ind,:)
alk_alt_co2_loc = tracer_local(marbl_tracer_indices%alk_alt_co2_ind,:)
po4_loc = tracer_local(marbl_tracer_indices%po4_ind,:)
sio3_loc = tracer_local(marbl_tracer_indices%sio3_ind,:)
associate( &
dkm => domain%km, &
column_kmt => domain%kmt, &
co3 => carbonate%CO3(:), &
hco3 => carbonate%HCO3(:), &
h2co3 => carbonate%H2CO3(:), &
ph => carbonate%pH(:), &