-
Notifications
You must be signed in to change notification settings - Fork 6
/
aed_pesticides.F90
1045 lines (857 loc) · 43 KB
/
aed_pesticides.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
!###############################################################################
!# #
!# aed_pesticides.F90 #
!# #
!# Developed by : #
!# AquaticEcoDynamics (AED) Group #
!# The University of Western Australia #
!# #
!# http:https://aquatic.science.uwa.edu.au/ #
!# #
!# Copyright 2022 - The University of Western Australia #
!# #
!# AED 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, either version 3 of the License, or #
!# (at your option) any later version. #
!# #
!# AED 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. See the #
!# GNU General Public License for more details. #
!# #
!# You should have received a copy of the GNU General Public License #
!# along with this program. If not, see <http:https://www.gnu.org/licenses/>. #
!# For use in a commercial seeting please contact the authors. #
!# #
!# ----------------------------------------------------------------------- #
!# #
!# Originally created Dec 2021 by Matthew Hipsey and Thanh Hoang, UWA #
!# Follow updates @ https://github.com/AquaticEcoDynamics/libaed-water #
!# #
!# For information about the module, please refer to the documentation #
!# published here: #
!# #
!# https://aquaticecodynamics.github.io/aed-science/index.html #
!# #
!###############################################################################
#include "aed.h"
MODULE aed_pesticides
!-------------------------------------------------------------------------------
! aed_pesticides --- pesticide contaminant model
!-------------------------------------------------------------------------------
USE aed_core
USE aed_util
IMPLICIT NONE
PRIVATE ! By default make everything private
!
PUBLIC aed_pesticides_data_t
!
!-------------------------------------------------------------------------------
! %% NAMELIST %% pesticide_param_t
TYPE pest_sorb_t
CHARACTER(64) :: pest_sorbent ! State variable name for sorbents
AED_REAL :: Kpst_sorb ! Sorption factors for sorbents
END TYPE pest_sorb_t
TYPE pesticide_param_t
CHARACTER(64) :: name
AED_REAL :: Rhydrol
AED_REAL :: Rphoto
AED_REAL :: Ruptake
AED_REAL :: theta_hydrol
AED_REAL :: K_gpp
AED_REAL :: Fsed_pst
AED_REAL :: coef_light_kb_vis, coef_light_kb_uva, coef_light_kb_uvb !-- Light inactivation
AED_REAL :: porosity, Kpst_sorb_sed, Kdsf
AED_REAL :: pst_initial, pst_initial_sed
INTEGER :: sorption_model
INTEGER :: num_sorb
TYPE(pest_sorb_t) :: sorbents(MAX_PSTC_SORB)
END TYPE pesticide_param_t
TYPE,extends(pesticide_param_t) :: pesticide_data_t
INTEGER :: id_sorb(MAX_PSTC_SORB)
INTEGER :: id_sorbv(MAX_PSTC_SORB)
END TYPE
! %% END NAMELIST %% pesticide_param_t
TYPE,extends(aed_model_data_t) :: aed_pesticides_data_t
!# Variable identifiers
INTEGER,ALLOCATABLE :: id_pstd(:) ! Column ID of pesticides
INTEGER,ALLOCATABLE :: id_psta(:,:) ! Column ID of pesticides attached to components
INTEGER,ALLOCATABLE :: id_psts(:),id_pstw(:) ! Column ID of pesticides in sediment
INTEGER,ALLOCATABLE :: id_ss(:) ! Column ID of ss, if chosen
! Diagnostic IDs for processes
INTEGER,ALLOCATABLE :: id_atmvolat(:), id_sedflux(:), id_sorption(:), &
id_photolysis(:), id_hydrolysis(:), id_uptake(:), &
id_settling(:), id_resus(:), id_total(:), id_tot_s(:)
INTEGER :: id_oxy, id_pH, id_doc, id_tss ! Dependency ID
INTEGER :: id_tem, id_sal, id_gpp ! Environmental IDs (3D)
INTEGER :: id_par, id_nir, id_uva, id_uvb ! Environmental IDs (3D)
INTEGER :: id_I_0 ! Environmental ID (2D)
INTEGER :: id_l_resus, resuspension
INTEGER :: id_epsilon, id_taub
!# Model parameters
INTEGER :: num_pesticides !, num_sorp
TYPE(pesticide_data_t),DIMENSION(:),ALLOCATABLE :: pesticides
INTEGER :: pst_piston_model,pst_sorption_model
LOGICAL :: initSedimentConc = .false.
!INTEGER :: num_ss
!AED_REAL,ALLOCATABLE :: Fsed_pst(:)
!AED_REAL,ALLOCATABLE :: Rhydrol(:),Rphoto(:),Ruptake(:),theta_hydrol(:),K_gpp(:)
!AED_REAL :: tau_0_min, kTau_0
!AED_REAL,ALLOCATABLE :: epsilon(:), tau_0(:), tau_r(:), Ke_ss(:)
!AED_REAL,ALLOCATABLE :: epsilonP(:), tauP_0(:)
!AED_REAL,DIMENSION(:),ALLOCATABLE :: ss_set, ss_tau, ss_ke
LOGICAL :: simSediment, simResuspension, simSorption, &
simVolatilisation, simPhotolysis, simUptake
AED_REAL :: att_ts
CONTAINS
PROCEDURE :: define => aed_define_pesticides
PROCEDURE :: calculate => aed_calculate_pesticides
PROCEDURE :: calculate_surface => aed_calculate_surface_pesticides
PROCEDURE :: calculate_benthic => aed_calculate_benthic_pesticides
PROCEDURE :: initialize_benthic=> aed_initialize_benthic_pesticides
PROCEDURE :: equilibrate => aed_equilibrate_pesticides
PROCEDURE :: mobility => aed_mobility_pesticides
PROCEDURE :: light_extinction => aed_light_extinction_pesticides
!PROCEDURE :: delete => aed_delete_pesticides
END TYPE
!MODULE GLOBALS
INTEGER :: diag_level = 10 ! 0 = no diagnostic outputs
! 1 = basic diagnostic outputs
! 2 = flux rates, and supporitng
! 3 = other metrics
!10 = all debug & checking outputs
!===============================================================================
CONTAINS
!###############################################################################
SUBROUTINE aed_define_pesticides(data, namlst)
!-------------------------------------------------------------------------------
! Initialise the pesticide model
!
! Here, the aed_p_m namelist is read and the variables exported
! by the model are registered with AED core.
!-------------------------------------------------------------------------------
!ARGUMENTS
INTEGER,INTENT(in) :: namlst
CLASS (aed_pesticides_data_t),INTENT(inout) :: data
!
!LOCALS
INTEGER :: status
INTEGER :: i, pst_i, sorp_i
CHARACTER(4) :: trac_name
! %% NAMELIST %% /aed_pesticides/
! %% Last Checked 26/12/2021
INTEGER :: num_pesticides = 1
INTEGER :: the_pesticides(MAX_PATHO_TYPES)
INTEGER :: num_sorp = 0
INTEGER :: pst_piston_model = 1
INTEGER :: pst_sorption_model = 1
INTEGER :: resuspension = 0
LOGICAL :: simSediment = .false.
LOGICAL :: simResuspension = .false.
LOGICAL :: simSorption = .false.
LOGICAL :: simVolatilisation = .false.
LOGICAL :: simPhotolysis = .false.
LOGICAL :: simUptake = .false.
LOGICAL :: initSedimentConc = .false.
CHARACTER(len=64) :: oxy_variable = ''
CHARACTER(len=64) :: gpp_variable = ''
CHARACTER(len=64) :: resus_link ='NCS_resus'
CHARACTER(len=128) :: dbase='aed_pesticide_pars.csv'
! From Module Globals
LOGICAL :: extra_diag = .FALSE. !## Obsolete Use diag_level = 10
! INTEGER :: diag_level = 10 ! 0 = no diagnostic outputs
! ! 1 = basic diagnostic outputs
! ! 2 = flux rates, and supporitng
! ! 3 = other metrics
! !10 = all debug & checking outputs
! %% END NAMELIST %% /aed_pesticides/
NAMELIST /aed_pesticides/ num_pesticides, the_pesticides, &
oxy_variable, &
simSediment, initSedimentConc, &
simResuspension, resuspension, &
simVolatilisation, pst_piston_model, &
simSorption, &
simPhotolysis, &
simUptake, gpp_variable,resus_link, &
dbase, diag_level
!-----------------------------------------------------------------------
!BEGIN
print *," aed_pesticides configuration"
print *," NOTE : This module is under development ... "
!stop "Please disable the pesticide model in your configuration"
! Read the namelist
read(namlst,nml=aed_pesticides,iostat=status)
IF (status /= 0) STOP 'Error reading namelist aed_pesticides'
IF ( extra_diag ) diag_level = 10
! Confirm configuration; defaults, requested config options and checks
data%simSediment = simSediment
data%simPhotolysis = simPhotolysis
data%simResuspension = simResuspension
data%simSorption = simSorption
data%simVolatilisation = simVolatilisation
data%simUptake = simUptake
IF(resuspension == 0) simResuspension = .false.
IF(pst_piston_model == 0) simVolatilisation = .false.
IF(pst_sorption_model == 0 .or. num_sorp == 0) simSorption = .false.
IF(gpp_variable .EQ. '') simUptake = .false.
! Set module values to user provided numbers in the namelist
data%resuspension = resuspension
IF ( .NOT. simResuspension ) resus_link = ''
data%initSedimentConc = initSedimentConc
! Store pesticide specific parameter values in module data type
! NB: all rates must be provided in values per day,
! and are converted here to values per second.
CALL aed_pesticides_load_params(data, dbase, num_pesticides, the_pesticides)
! Register link to sorbent state variables
DO pst_i = 1,num_pesticides
!phy_i = 0
DO sorp_i = 1,data%pesticides(pst_i)%num_sorb
! Find the sorbent concentration
data%pesticides(pst_i)%id_sorb(sorp_i) = &
aed_locate_variable(data%pesticides(pst_i)%sorbents(sorp_i)%pest_sorbent)
! Find the sorbent vvel
data%pesticides(pst_i)%id_sorbv(sorp_i) = &
aed_locate_variable(TRIM(data%pesticides(pst_i)%sorbents(sorp_i)%pest_sorbent)//'_vvel')
ENDDO
ENDDO
! Register state dependencies
data%id_tss=-1 ; data%id_doc=-1 ; data%id_pH=-1 ; data%id_oxy=-1 ; data%id_gpp=-1
IF (oxy_variable .NE. '') data%id_oxy = aed_locate_variable(oxy_variable)
IF (gpp_variable .NE. '') data%id_gpp = aed_locate_variable(gpp_variable)
!-- Locate and check for link variable
IF ( resuspension>0 .AND. .NOT.resus_link .EQ. '' ) THEN
data%id_l_resus = aed_locate_sheet_variable(TRIM(resus_link))
ELSE
data%id_l_resus = 0
data%resuspension = 0.
ENDIF
! Register environmental dependencies
data%id_I_0 = aed_locate_sheet_global('par_sf')
data%id_tem = aed_locate_global('temperature')
data%id_sal = aed_locate_global('salinity')
data%id_par = aed_locate_global('par')
data%id_nir = aed_locate_global('nir')
data%id_uva = aed_locate_global('uva')
data%id_uvb = aed_locate_global('uvb')
IF ( resuspension > 0 ) &
data%id_taub = aed_locate_sheet_global('taub')
END SUBROUTINE aed_define_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
INTEGER FUNCTION load_csv(dbase, pd, dbsize)
!-------------------------------------------------------------------------------
USE aed_csv_reader
!-------------------------------------------------------------------------------
!ARGUMENTS
CHARACTER(len=*),INTENT(in) :: dbase
TYPE(pesticide_data_t) :: pd(MAX_PSTC_TYPES)
INTEGER,INTENT(out) :: dbsize
!
!LOCALS
INTEGER :: unit, nccols, ccol, dcol
CHARACTER(len=32),POINTER,DIMENSION(:) :: csvnames
CHARACTER(len=32) :: name_
TYPE(AED_SYMBOL),DIMENSION(:),ALLOCATABLE :: values
INTEGER :: idx_col = 0
LOGICAL :: meh
INTEGER :: ret = 0
!
!BEGIN
!-------------------------------------------------------------------------------
dbsize = 0
unit = aed_csv_read_header(dbase, csvnames, nccols)
IF (unit <= 0) THEN
load_csv = -1
RETURN !# No file found
ENDIF
ALLOCATE(values(nccols))
DO WHILE ( aed_csv_read_row(unit, values) )
DO ccol=2,nccols
dcol = ccol - 1
pd(dcol)%name = csvnames(ccol)
CALL copy_name(values(1), name_)
SELECT CASE (name_)
CASE ('Rhydrol') ; pd(dcol)%Rhydrol = extract_double(values(ccol))
CASE ('Rphoto') ; pd(dcol)%Rphoto = extract_double(values(ccol))
CASE ('Ruptake') ; pd(dcol)%Ruptake = extract_double(values(ccol))
CASE ('theta_hydrol') ; pd(dcol)%theta_hydrol = extract_double(values(ccol))
CASE ('K_gpp') ; pd(dcol)%K_gpp = extract_double(values(ccol))
CASE ('Fsed_pst') ; pd(dcol)%Fsed_pst = extract_double(values(ccol))
CASE ('porosity') ; pd(dcol)%porosity = extract_double(values(ccol))
CASE ('pst_initial') ; pd(dcol)%pst_initial = extract_double(values(ccol))
CASE ('pst_initial_sed') ; pd(dcol)%pst_initial_sed = extract_double(values(ccol))
CASE ('Kpst_sorb_sed') ; pd(dcol)%Kpst_sorb_sed = extract_double(values(ccol))
CASE ('Kdsf') ; pd(dcol)%Kdsf = extract_double(values(ccol))
CASE ('coef_light_kb_vis') ; pd(dcol)%coef_light_kb_vis = extract_double(values(ccol))
CASE ('coef_light_kb_uva') ; pd(dcol)%coef_light_kb_uva = extract_double(values(ccol))
CASE ('coef_light_kb_uvb') ; pd(dcol)%coef_light_kb_uvb = extract_double(values(ccol))
CASE ('sorption_model') ; pd(dcol)%sorption_model = extract_integer(values(ccol))
CASE ('num_sorb') ; pd(dcol)%num_sorb = extract_integer(values(ccol))
CASE ('sorb(1)%pest_sorbent') ; CALL copy_name(values(ccol), pd(dcol)%sorbents(1)%pest_sorbent)
CASE ('sorb(1)%Kpst_sorb') ; pd(dcol)%sorbents(1)%Kpst_sorb = extract_double(values(ccol))
CASE ('sorb(2)%pest_sorbent') ; CALL copy_name(values(ccol), pd(dcol)%sorbents(2)%pest_sorbent)
CASE ('sorb(2)%Kpst_sorb') ; pd(dcol)%sorbents(2)%Kpst_sorb = extract_double(values(ccol))
CASE ('sorb(3)%pest_sorbent') ; CALL copy_name(values(ccol), pd(dcol)%sorbents(3)%pest_sorbent)
CASE ('sorb(3)%Kpst_sorb') ; pd(dcol)%sorbents(3)%Kpst_sorb = extract_double(values(ccol))
CASE DEFAULT ; print *, 'Unknown pesticide CSV parameter row "', TRIM(name_), '"'
END SELECT
ENDDO
ENDDO
meh = aed_csv_close(unit)
!# don't care if close fails
IF (ASSOCIATED(csvnames)) DEALLOCATE(csvnames)
IF (ALLOCATED(values)) DEALLOCATE(values)
dbsize = nccols-1
load_csv = ret
END FUNCTION load_csv
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_pesticides_load_params(data, dbase, count, list)
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(inout) :: data
CHARACTER(len=*),INTENT(in) :: dbase
INTEGER,INTENT(inout) :: count
INTEGER,INTENT(in) :: list(*)
!
!LOCALS
INTEGER :: status = 0
INTEGER :: i,tfil,ns, dbsize = 0
AED_REAL :: min_conc
CHARACTER(4) :: pst_name
TYPE(pesticide_data_t),ALLOCATABLE :: pd(:)
NAMELIST /pesticide_data/ pd ! %% pesticide_param_t - see above
!-------------------------------------------------------------------------------
!BEGIN
min_conc = zero_ !1e-8
ALLOCATE(pd(MAX_PSTC_TYPES))
SELECT CASE (param_file_type(dbase))
CASE (CSV_TYPE)
status = load_csv(dbase, pd, dbsize)
CASE (NML_TYPE)
print *,'NML file type for pesticides is not supported, please convert to CSV'
! pesticide_data%name = ''
! tfil = find_free_lun()
! open(tfil,file=dbase, status='OLD',iostat=status)
! IF (status /= 0) STOP 'Error opening namelist pesticide_data'
! read(tfil,nml=pesticide_data,iostat=status)
! close(tfil)
! dbsize = 0
! DO i=1,MAX_PSTC_TYPES
! IF (pesticide_data(i)%name == '') EXIT
! dbsize = dbsize + 1
! ENDDO
CASE DEFAULT
print *,'Unknown file type "',TRIM(dbase),'"'; status=1
END SELECT
IF (status /= 0) STOP 'Error reading namelist pesticide_data'
data%num_pesticides = 0
ALLOCATE(data%pesticides(count))
ALLOCATE(data%id_pstd(count))
ALLOCATE(data%id_psta(count,10)) !need to get max num_sorb from pd
IF (data%simSediment) THEN
ALLOCATE(data%id_psts(count))
ALLOCATE(data%id_pstw(count))
ENDIF
IF ( diag_level >= 2 ) THEN
ALLOCATE(data%id_atmvolat(count))
ALLOCATE(data%id_sedflux(count))
ALLOCATE(data%id_settling(count))
ALLOCATE(data%id_resus(count))
ALLOCATE(data%id_sorption(count))
ALLOCATE(data%id_photolysis(count))
ALLOCATE(data%id_hydrolysis(count))
ALLOCATE(data%id_uptake(count))
ALLOCATE(data%id_total(count))
ALLOCATE(data%id_tot_s(count))
ENDIF
DO i=1,count
IF ( list(i) < 1 .OR. list(i) > dbsize ) EXIT !# bad index, exit the loop
data%num_pesticides = data%num_pesticides + 1
! Assign parameters from database to simulated groups
data%pesticides(i) = pd(list(i))
! Unit adjustments from read-in parameters
data%pesticides(i)%Fsed_pst = data%pesticides(i)%Fsed_pst / secs_per_day
data%pesticides(i)%Rhydrol = data%pesticides(i)%Rhydrol / secs_per_day
data%pesticides(i)%Rphoto = data%pesticides(i)%Rphoto / secs_per_day
data%pesticides(i)%Ruptake = data%pesticides(i)%Ruptake / secs_per_day
! Register group as a state variable
data%id_pstd(i) = aed_define_variable( &
TRIM(data%pesticides(i)%name)//'_d', &
'mg/m3', 'pesticide dissolved concentration', &
data%pesticides(i)%pst_initial , &
minimum=min_conc)
! Check if we need to register a variable for the sorbed fraction(s)
IF (data%pesticides(i)%num_sorb > 0) THEN
pst_name = '0'
DO ns = 1, data%pesticides(i)%num_sorb
pst_name(1:1) = CHAR(ICHAR('0') + ns)
data%id_psta(i,ns) = aed_define_variable( &
TRIM(data%pesticides(i)%name)//'_'//TRIM(pst_name),&
'mg/m3', 'pesticide sorbed concentration', &
min_conc, &
minimum=min_conc, &
mobility = zero_)
ENDDO
ENDIF
IF (data%simSediment) THEN
data%id_psts(i) = aed_define_sheet_variable( TRIM(data%pesticides(i)%name)//'_sed', 'mg/m2', &
'sorbed pesticides in sediment',data%pesticides(i)%pst_initial_sed*0.5 )
data%id_pstw(i) = aed_define_sheet_variable( TRIM(data%pesticides(i)%name)//'_pw', 'mg/m2', &
'porewater pesticides in sediment',data%pesticides(i)%pst_initial_sed*0.5)
ENDIF
!data%id_total(i) = aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_t', 'orgs/m3', 'total')
IF ( diag_level >= 2 ) THEN
data%id_sedflux(i) = &
aed_define_sheet_diag_variable( TRIM(data%pesticides(i)%name)//'_dsf', 'mg/m2/d', 'dissolved sediment flux')
IF (data%simVolatilisation) data%id_atmvolat(i) = &
aed_define_sheet_diag_variable( TRIM(data%pesticides(i)%name)//'_atm', 'mg/m2/d', 'volatilisation')
IF (data%simResuspension) data%id_resus(i) = &
aed_define_sheet_diag_variable( TRIM(data%pesticides(i)%name)//'_res', 'mg/m2/d', 'resuspension flux')
data%id_settling(i) = aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_set', 'mg/m3/d', 'settling rate')
data%id_sorption(i) = aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_srp', 'mg/m3/d', 'sorption rate')
data%id_photolysis(i)= aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_pht', 'mg/m3/d', 'photolysis rate')
data%id_hydrolysis(i)= aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_hyd', 'mg/m3/d', 'hydrolysis rate')
data%id_uptake(i) = aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_upt', 'mg/m3/d', 'uptake rate')
data%id_total(i) = &
aed_define_diag_variable( TRIM(data%pesticides(i)%name)//'_tot', 'mg/m3' , 'total pesticide concentration')
IF (data%simSediment) data%id_tot_s(i) = &
aed_define_sheet_diag_variable( TRIM(data%pesticides(i)%name)//'_tot_sed', 'mg/m2' , &
'total pesticide concentration in the sediment')
ENDIF
ENDDO
DEALLOCATE(pd)
END SUBROUTINE aed_pesticides_load_params
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_initialize_benthic_pesticides(data, column, layer_idx)
!-------------------------------------------------------------------------------
! Routine to initialize pesticides mass from spatial conc map
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
!
!LOCALS
INTEGER :: pst_i
AED_REAL :: matz, pest_sed_w, pest_sed_d, PSTtot, PSTpar, PSTdis
AED_REAL :: porosity, density, KPSTp
!-------------------------------------------------------------------------------
!BEGIN
IF (.NOT. data%simSediment) RETURN
! Update sediment conc units after initialisation
DO pst_i=1,data%num_pesticides
! Sorption
porosity = data%pesticides(pst_i)%porosity
density = 2.5 !kg/L
KPSTp = data%pesticides(pst_i)%Kpst_sorb_sed
PSTtot = data%pesticides(pst_i)%pst_initial_sed
! Check if user wishes to initialise from spatial map
IF( data%initSedimentConc) THEN
PSTtot = _DIAG_VAR_S_(data%id_tot_s(pst_i)) ! read in mg/kg
ENDIF
PSTdis = MAX(MIN(1/(porosity+density*((1-porosity)*KPSTp)),1.),0.)
PSTpar = (one_ - PSTdis) !fS()
PSTpar = PSTtot * PSTpar
PSTdis = PSTtot - PSTpar
! Update the pools after partitoning calculation completed
pest_sed_w = PSTdis /porosity
pest_sed_d = PSTpar /(1-porosity)
_STATE_VAR_S_(data%id_psts(pst_i)) = pest_sed_d ! pesticide (sediment solids)
_STATE_VAR_S_(data%id_pstw(pst_i)) = pest_sed_w ! pesticide (sediment porewater)
ENDDO
END SUBROUTINE aed_initialize_benthic_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_calculate_surface_pesticides(data,column,layer_idx)
!------------------------------------------------------------------------------+
! Air-water exchange (volatilisation) for the aed pesticide model
!------------------------------------------------------------------------------+
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
!
!LOCALS
! Environment
AED_REAL :: temp, salt, windHt, wind, vel, depth
! State
AED_REAL :: volat, pst
! Temporary variables
INTEGER :: pst_i
AED_REAL :: k600
!
!------------------------------------------------------------------------------+
!BEGIN
temp = _STATE_VAR_(data%id_tem) ! local temperature
salt = _STATE_VAR_(data%id_sal) ! local salinity
windHt = 1
wind = 1
vel = 0.1
depth = 1
DO pst_i=1,data%num_pesticides
volat = zero_
!-----------------------------------------------
! Compute necessary piston velocity and air-sea flux
IF( data%simVolatilisation ) THEN
pst = _STATE_VAR_(data%id_pstd(pst_i))
k600 = aed_gas_piston_velocity(windHt,wind,temp,salt, &
vel=vel,depth=depth,schmidt_model=2,piston_model=data%pst_piston_model)
volat = k600 * pst
!-----------------------------------------------
! Set surface exchange value (mmmol/m2/s) for AED ODE solution
_FLUX_VAR_T_(data%id_pstd(pst_i)) = volat
!-----------------------------------------------
! Set surface exchange value (mmmol/m2/d) as a diagnostic
_DIAG_VAR_S_(data%id_atmvolat(pst_i)) = volat * secs_per_day
ENDIF
ENDDO
END SUBROUTINE aed_calculate_surface_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_calculate_pesticides(data,column,layer_idx)
!-------------------------------------------------------------------------------
! Right hand sides of pesticide biogeochemical model
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
!
!LOCALS
AED_REAL :: pth_f, pth_a, pest_d, pest_a
AED_REAL :: temp,salinity,oxy,pH,doc
AED_REAL :: Io,par,uva,uvb
AED_REAL :: hydrolysis, photolysis, uptake
AED_REAL :: f_AOC,f_pH,f_DO,phi,lightBW,phstar,att_frac
AED_REAL :: f_upt, f_pht
INTEGER :: pst_i, sorp_i, pst_s
!-------------------------------------------------------------------------------
!BEGIN
! Retrieve current environmental conditions
temp = _STATE_VAR_(data%id_tem) ! local temperature
salinity = _STATE_VAR_(data%id_sal) ! local salinity
IF (data%id_oxy>0) THEN ! & use_oxy
oxy = _STATE_VAR_(data%id_oxy) ! local oxygen
ELSE
oxy = 10.0 !mg/L
ENDIF
!doc = _STATE_VAR_(data%id_doc) ! local DOC
!ph = _STATE_VAR_(data%id_ph) ! local pH
phstar = 0.0 ! abs(ph-7.)
! Get light bandwidth intensities
Io = _STATE_VAR_S_(data%id_I_0) ! surface short wave radiation
par = _STATE_VAR_(data%id_par) ! local photosynthetically active radiation (45% of sw)
IF ( data%id_uva > 0 ) THEN
uva = _STATE_VAR_(data%id_uva)
ELSE
uva = (par/0.45)*0.03 ! uva is 3% of sw (Kirk 1994)
ENDIF
IF ( data%id_uvb > 0 ) THEN
uvb = _STATE_VAR_(data%id_uvb)
ELSE
uvb = (par/0.45)*0.003 ! uvb is 0.3% of sw
ENDIF
DO pst_i=1,data%num_pesticides
!-----------------------------------------------------------------
! RETREIVE THIS PESTICIDE GROUP
pest_d = _STATE_VAR_(data%id_pstd(pst_i))
! IF ( data%num_sorp > 0 ) THEN
! pest_a(pst_s) = _STATE_VAR_(data%id_psta(pst_i,sorp_i))
! END IF
!-----------------------------------------------------------------
! COMPUTE PESTICIDE FLUX RATES
hydrolysis = zero_
photolysis = zero_
uptake = zero_
_DIAG_VAR_(data%id_hydrolysis(pst_i)) = zero_
_DIAG_VAR_(data%id_photolysis(pst_i)) = zero_
_DIAG_VAR_(data%id_uptake(pst_i)) = zero_
_DIAG_VAR_(data%id_total(pst_i)) = zero_
! 1. Breakdown under ambient conditions
hydrolysis = data%pesticides(pst_i)%Rhydrol * (data%pesticides(pst_i)%theta_hydrol**(temp-20.0))
! 2. Sunlight breakdown
IF ( data%simPhotolysis ) THEN
f_pht = par / ( par + 500. )
photolysis = data%pesticides(pst_i)%coef_light_kb_vis * f_pht
f_pht = uva / ( uva + 50. )
photolysis = photolysis+ data%pesticides(pst_i)%coef_light_kb_uva * f_pht
f_pht = uvb / ( uvb + 5. )
photolysis = photolysis+ data%pesticides(pst_i)%coef_light_kb_uvb * f_pht
! photolysis = photo(vis,cdom,1) + photo(uva,cdom,2) + photo(uvb,cdom,3)
! !# Limit photolysis to 90% of doc pool within 1 hour
! IF(photolysis > 0.9*docr/3.6e3) photolysis = 0.9*docr/3.6e3
ENDIF
! 3. Biological uptake
IF ( data%simUptake ) THEN
f_upt = _DIAG_VAR_(data%id_GPP) / ( _DIAG_VAR_(data%id_GPP) + data%pesticides(pst_i)%K_gpp )
uptake = data%pesticides(pst_i)%Ruptake * f_upt
ENDIF
!-----------------------------------------------------------------
! SET TEMPORAL DERIVATIVES FOR ODE SOLVER
! Pesticide breakdown and uptake
_FLUX_VAR_(data%id_pstd(pst_i)) = _FLUX_VAR_(data%id_pstd(pst_i)) &
- (hydrolysis + photolysis + uptake)*pest_d
DO sorp_i=1,data%pesticides(pst_i)%num_sorb
pest_a = _STATE_VAR_(data%id_psta(pst_i,sorp_i))
_FLUX_VAR_(data%id_psta(pst_i,sorp_i)) = _FLUX_VAR_(data%id_psta(pst_i,sorp_i)) &
- (hydrolysis + photolysis/2.)*pest_a
_DIAG_VAR_(data%id_total(pst_i)) = _DIAG_VAR_(data%id_total(pst_i)) + pest_a
ENDDO
_DIAG_VAR_(data%id_total(pst_i)) = _DIAG_VAR_(data%id_total(pst_i)) + pest_d
!-----------------------------------------------------------------
! SET DIAGNOSTICS
IF ( diag_level >= 2 ) THEN
_DIAG_VAR_(data%id_hydrolysis(pst_i)) = &
hydrolysis * (_DIAG_VAR_(data%id_total(pst_i))+pest_d) * secs_per_day
_DIAG_VAR_(data%id_photolysis(pst_i)) = &
photolysis * (_DIAG_VAR_(data%id_total(pst_i))/2.+pest_d) * secs_per_day
_DIAG_VAR_(data%id_uptake(pst_i)) = uptake * pest_d * secs_per_day
ENDIF
ENDDO
END SUBROUTINE aed_calculate_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_calculate_benthic_pesticides(data,column,layer_idx)
!-------------------------------------------------------------------------------
! Calculate pelagic sedimentation of pesticide.
! Everything in units per surface area (not volume!) per time.
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
!
!LOCALS
AED_REAL :: ss ! State
INTEGER :: pst_i, ss_i
AED_REAL :: diss_flux, sett_flux, part_flux, hydrolysis, resus_flux
AED_REAL :: pest_d, pest_sed_d, pest_sed_w
AED_REAL :: PSTtot, PSTpar, PSTdis
AED_REAL :: bottom_stress, dummy_tau, temp
AED_REAL :: porosity, density, KPSTp
! Parameters
!
!-------------------------------------------------------------------------------
!BEGIN
diss_flux = zero_
part_flux = zero_
IF (data%simSediment) THEN
temp = _STATE_VAR_(data%id_tem)
! Dynamic sediment pool of pesticide that increase and decrease
DO pst_i=1,data%num_pesticides
! Retrieve current (local) state variable values
pest_d = _STATE_VAR_(data%id_pstd(pst_i)) ! pesticide (bottom water)
pest_sed_d = _STATE_VAR_S_(data%id_psts(pst_i)) ! pesticide (sediment solids)
pest_sed_w = _STATE_VAR_S_(data%id_pstw(pst_i)) ! pesticide (sediment porewater)
! Sorption
porosity = data%pesticides(pst_i)%porosity
density = 2.5 !kg/L
KPSTp = data%pesticides(pst_i)%Kpst_sorb_sed
PSTtot = pest_sed_w*porosity + pest_sed_d*(1-porosity)
PSTdis = MAX(MIN(1/(porosity+density*((1-porosity)*KPSTp)),1.),0.)
PSTpar = (one_ - PSTdis) !fS()
PSTpar = PSTtot * PSTpar
PSTdis = PSTtot - PSTpar
! Update the pools after partitoning calculation completed
pest_sed_w = PSTdis /porosity
pest_sed_d = PSTpar /(1-porosity)
_STATE_VAR_S_(data%id_psts(pst_i)) = pest_sed_d
_STATE_VAR_S_(data%id_pstw(pst_i)) = pest_sed_w
! Sedimentation flux
part_flux = - _DIAG_VAR_(data%id_settling(pst_i)) / secs_per_day
! Resuspension flux
resus_flux = zero_
IF( data%resuspension > 0 ) THEN
resus_flux = _DIAG_VAR_S_(data%id_l_resus) * pest_sed_d ! g/m2/s * gPST/gSed
IF ( diag_level >= 2 ) &
_DIAG_VAR_S_ (data%id_resus(pst_i)) = resus_flux * secs_per_day
ENDIF
! Now set kinetic flux for breakdown
hydrolysis = data%pesticides(pst_i)%Rhydrol * (data%pesticides(pst_i)%theta_hydrol**(temp-20.0))
! Dissolved pesticide flux to / from the sediment
diss_flux = data%pesticides(pst_i)%Fsed_pst &
* ( PSTdis / (MAX(data%pesticides(pst_i)%Kdsf,1e-3) + PSTdis) )
! Update pools
_FLUX_VAR_B_(data%id_pstw(pst_i)) = _FLUX_VAR_B_(data%id_pstw(pst_i)) - diss_flux - hydrolysis*pest_sed_w
_FLUX_VAR_B_(data%id_psts(pst_i)) = _FLUX_VAR_B_(data%id_psts(pst_i)) + part_flux - hydrolysis*pest_sed_d - resus_flux
! Add to respective pools in water (dissolved)
_FLUX_VAR_(data%id_pstd(pst_i)) = _FLUX_VAR_(data%id_pstd(pst_i)) + diss_flux
DO ss_i=1,data%pesticides(pst_i)%num_sorb
_FLUX_VAR_(data%id_psta(pst_i,ss_i)) = _FLUX_VAR_(data%id_psta(pst_i,ss_i)) &
+ resus_flux/data%pesticides(pst_i)%num_sorb
ENDDO
IF ( diag_level >= 2 ) &
_DIAG_VAR_S_ (data%id_sedflux(pst_i)) = diss_flux * secs_per_day
IF ( diag_level >= 2 ) &
_DIAG_VAR_S_ (data%id_tot_s(pst_i)) = PSTtot
ENDDO
ELSE
! No sediment pool is resolved, but still predict a generic diss flux
DO pst_i=1,data%num_pesticides
diss_flux = data%pesticides(pst_i)%Fsed_pst
! Flux from the sediment
_FLUX_VAR_(data%id_pstd(pst_i)) = _FLUX_VAR_(data%id_pstd(pst_i)) + diss_flux
! Resuspension flux
resus_flux = zero_
IF( data%resuspension > 0 ) THEN
resus_flux = _DIAG_VAR_S_(data%id_l_resus) * data%pesticides(pst_i)%pst_initial_sed ! g/m2/s * gPST/gSed
DO ss_i=1,data%pesticides(pst_i)%num_sorb
_FLUX_VAR_(data%id_psta(pst_i,ss_i)) = _FLUX_VAR_(data%id_psta(pst_i,ss_i)) &
+ resus_flux/data%pesticides(pst_i)%num_sorb
ENDDO
IF ( diag_level >= 2 ) &
_DIAG_VAR_S_ (data%id_resus(pst_i)) = resus_flux * secs_per_day
ENDIF
IF ( diag_level >= 2 ) &
_DIAG_VAR_S_ (data%id_sedflux(pst_i)) = diss_flux * secs_per_day
ENDDO
ENDIF
END SUBROUTINE aed_calculate_benthic_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_equilibrate_pesticides(data,column,layer_idx)
!------------------------------------------------------------------------------+
! Update partitioning of pesticides between dissolved and particulate pools;
! updated after kinetic transformations are applied
!------------------------------------------------------------------------------+
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
!
!LOCALS
! Environment
AED_REAL :: temp, tss
! State
AED_REAL :: pest_d_preequil, pest_t, pest_d, pest_s(10)
! Temporary variables
AED_REAL :: sorbents(10), Kpstp(10)
INTEGER :: pst_i, sorp_i
AED_REAL, PARAMETER :: dt = 900 ! Needs to be linked to aed_core/common
!-------------------------------------------------------------------------------
!BEGIN
IF(.NOT. data%simSorption) RETURN
! Retrieve current environmental conditions for the cell.
temp = _STATE_VAR_(data%id_tem) ! local temperature
pest_d = zero_ ; pest_t = zero_ ; pest_s(:) = zero_
DO pst_i=1,data%num_pesticides
! Record dissolved conc, before the sorption algorithm
pest_d_preequil = _STATE_VAR_(data%id_pstd(pst_i))
! Find the total pesticide across all forms
pest_t = _STATE_VAR_(data%id_pstd(pst_i))
DO sorp_i=1,data%pesticides(pst_i)%num_sorb
sorbents(sorp_i) = _STATE_VAR_(data%pesticides(pst_i)%id_sorb(sorp_i))
pest_t = pest_t + _STATE_VAR_(data%id_psta(pst_i,sorp_i))
Kpstp(sorp_i) = data%pesticides(pst_i)%sorbents(sorp_i)%Kpst_sorb
ENDDO
! Re-distribute based on component concentrations
pest_d = pesticide_sorption(temp,sorbents,pest_t,pest_s,Kpstp,data%pesticides(pst_i)%sorption_model)
! Update core data arrays
_STATE_VAR_(data%id_pstd(pst_i))= pest_d ! Dissolved
DO sorp_i=1,data%pesticides(pst_i)%num_sorb
_STATE_VAR_(data%id_psta(pst_i,sorp_i)) = pest_s(sorp_i) ! Adsorped to particle group i
ENDDO
! Update diagnostic
_DIAG_VAR_(data%id_sorption(pst_i)) = ((pest_d - pest_d_preequil)/dt)* secs_per_day
ENDDO
END SUBROUTINE aed_equilibrate_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_mobility_pesticides(data,column,layer_idx,mobility)
!-------------------------------------------------------------------------------
! Get the vertical movement values based on linked particulates (sorbents)
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
AED_REAL,INTENT(inout) :: mobility(:)
!
!LOCALS
INTEGER :: sorp_i,pst_i
AED_REAL :: temp
AED_REAL :: sorbent_vvel(10)
!
!-------------------------------------------------------------------------------
!BEGIN
temp = _STATE_VAR_(data%id_tem)
! Set velocity of sorped pesticides, if simulated.
DO pst_i=1,data%num_pesticides
IF ( diag_level >= 2 ) _DIAG_VAR_(data%id_settling(pst_i)) = zero_
DO sorp_i=1,data%pesticides(pst_i)%num_sorb
sorbent_vvel(sorp_i) = _DIAG_VAR_(data%pesticides(pst_i)%id_sorbv(sorp_i)) / secs_per_day
mobility(data%id_psta(pst_i,sorp_i)) = sorbent_vvel(sorp_i)
! Record the cumulative sedimentation flux from each cell (units/m2/d)
IF ( diag_level >= 2 ) THEN
_DIAG_VAR_(data%id_settling(pst_i)) = _DIAG_VAR_(data%id_settling(pst_i)) &
+ _STATE_VAR_(data%id_psta(pst_i,sorp_i)) * sorbent_vvel(sorp_i) * secs_per_day
ENDIF
ENDDO
ENDDO
END SUBROUTINE aed_mobility_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
SUBROUTINE aed_light_extinction_pesticides(data,column,layer_idx,extinction)
!-------------------------------------------------------------------------------
! Get the light extinction coefficient due to ss variables in this module
!-------------------------------------------------------------------------------
!ARGUMENTS
CLASS (aed_pesticides_data_t),INTENT(in) :: data
TYPE (aed_column_t),INTENT(inout) :: column(:)
INTEGER,INTENT(in) :: layer_idx
AED_REAL,INTENT(inout) :: extinction
!
!LOCALS
AED_REAL :: ss
INTEGER :: ss_i, pst_i
!
!-----------------------------------------------------------------------
!BEGIN
RETURN
END SUBROUTINE aed_light_extinction_pesticides
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!###############################################################################
FUNCTION pesticide_sorption(temp,sorbents,pest_t,pest_s,Kpstp_,sorption_model) &
RESULT(pest_d)
!-------------------------------------------------------------------------------
! Function to partition pesticide concentration amongst several sorbents
!-------------------------------------------------------------------------------
!ARGUMENTS
INTEGER, INTENT(in) :: sorption_model