/
msm.py
2142 lines (2135 loc) · 89 KB
/
msm.py
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
"""
=======================================================================================
Mercury Simulation Module (MSM): Main Program
=======================================================================================
Developed by:
* Dr. Todd E. Steissberg (ERDC-EL)
* Dr. Billy E. Johnson (ERDC-EL, LimnoTech)
* Dr. Zhonglong Zhang (Portland State University)
* Mr. Mark Jensen (HEC)
This module computes the water quality of a single computational cell. The algorithms
and structure of this program were adapted from the Fortran 95 version of this module,
developed by:
* Dr. Billy E. Johnson (ERDC-EL)
* Dr. Zhonglong Zhang (Portland State University)
* Mr. Mark Jensen (HEC)
Version 1.0
Initial Version: June 15, 2021
Last Revision Date: June 15, 2021
"""
"""
module modMercury
use modGlobal
use modDLL, only: TempCorrectionStruct, Arrhenius_TempCorrection, AddIndex
implicit none
!
! temperature correction parameters (21)
type(TempCorrectionStruct), allocatable, dimension(:) :: kd23 ! Methylation rate from dissolved HgII to MeHg in water column (1/day)
real(R8) :: kd23_tc
type(TempCorrectionStruct), allocatable, dimension(:) :: kdoc23 ! Methylation rate from DOC sorbed HgII to MeHg in water column (1/day)
real(R8) :: kdoc23_tc
type(TempCorrectionStruct), allocatable, dimension(:) :: kso42 ! Sediment sulfate reduction rate (1/day)
real(R8) :: kso42_tc
type(TempCorrectionStruct), allocatable, dimension(:) :: kd32_2 ! Sediment demethylation rate (1/day)
real(R8) :: kd32_2_tc
!
type(TempCorrectionStruct), allocatable, dimension(:,:) :: vv ! Volatilization velocity of Hg0 and MeHg in water column (m/day)
real(R8) :: vv_tc(3)
!
real(R8), allocatable, dimension(:) :: k12 ! Oxidation rate from Hg0 to HgII in water column (1/day)
real(R8) :: k12_tc
real(R8), allocatable, dimension(:) :: Ea12 ! Arrhenius activation energy for Hg0 oxidation rate (kJ/mol)
real(R8), allocatable, dimension(:) :: Tr12 ! Reference temperature for which Hg0 oxidation rate is reported (C)
!
real(R8), allocatable, dimension(:) :: kadpom ! Adsorption rate of POM sorbed HgII in water column (L/�g/day)
real(R8) :: kadpom_tc
real(R8), allocatable, dimension(:) :: kadpom2 ! Adsorption rate of POM sorbed HgII in bed sediment (L/�g/day)
real(R8) :: kadpom2_tc
!
real(R8), allocatable, dimension(:) :: kdapom ! Desorption rate of POM sorbed HgII in water column (1/day)
real(R8) :: kdapom_tc
real(R8), allocatable, dimension(:) :: kdapom2 ! Desorption rate of POM sorbed HgII in bed sediment (1/day)
real(R8) :: kdapom2_tc
!
real(R8), allocatable, dimension(:) :: kadap ! Adsorption rate of algae sorbed HgII in water column (L/�g/day)
real(R8) :: kadap_tc
real(R8), allocatable, dimension(:) :: kdaap ! Desorption rate of algae sorbed HgII in water column (1/day)
real(R8) :: kdaap_tc
!
real(R8), allocatable, dimension(:,:) :: kadp ! Adsorption rate of solid j sorbed HgII in water column (L/�g/day)
real(R8), allocatable, dimension(:) :: kadp_tc
real(R8), allocatable, dimension(:,:) :: kadp2 ! Adsorption rate of solid j sorbed HgII in bed sediment (L/�g/day)
real(R8), allocatable, dimension(:) :: kadp2_tc
!
real(R8), allocatable, dimension(:,:) :: kdap ! Desorption rate of solid j sorbed HgII in water column (1/day)
real(R8), allocatable, dimension(:) :: kdap_tc
real(R8), allocatable, dimension(:,:) :: kdap2 ! Desorption rate of solid j sorbed HgII in bed sediment (1/day)
real(R8), allocatable, dimension(:) :: kdap2_tc
!
real(R8), allocatable, dimension(:) :: Eaad ! Arrhenius activation energy for adsorption rate (kJ/mol)
real(R8), allocatable, dimension(:) :: Eade ! Arrhenius activation energy for desorption rate (kJ/mol)
real(R8), allocatable, dimension(:) :: Trade ! Reference temperature for which adsorption and desorption rate is reported (C)
!
! global parameters (10)
real(R8), allocatable, dimension(:) :: vsap ! Settling velocity of algae in water column (m/d)
real(R8), allocatable, dimension(:) :: vsom ! Settling velocity of POM in water column (m/d)
real(R8), allocatable, dimension(:) :: h2 ! Active Sediment layer thickness (m)
real(R8), allocatable, dimension(:) :: Por ! Porosity or volume water per volume bed sediment (unitless)
!
real(R8), allocatable, dimension(:) :: z2 ! The average bioturbed depth in bed sediments (cm)
real(R8), allocatable, dimension(:) :: Db ! Biodiffusion coefficient representing particle diffusivity in the bed (cm2/d)
real(R8), allocatable, dimension(:) :: Beta ! Water-side benthic boundary layer mass transfer coefficient (cm/d)
real(R8), allocatable, dimension(:) :: ps ! Density of total bed sediments
!
real(R8), allocatable, dimension(:) :: alpha ! Coefficient to adjust light extinction coefficient (unitless) (1/d)
real(R8), allocatable, dimension(:) :: res ! Maximum relative error of Newton-Raphson or Bisection method (unitless)
! Hg (5)
real(R8), allocatable, dimension(:,:) :: vm ! Sediment-water mass transfer velocity for HgII and MeHg (m/d)
real(R8), allocatable, dimension(:,:) :: Dm ! Molecular diffusivity for HgII and MeHg (m2/d)
real(R8), allocatable, dimension(:,:) :: MW ! Molecular weight of Hg0, HgII and MeHg (g/mol)
real(R8), allocatable, dimension(:,:) :: Hgds ! Solubility of Hg0, HgII and MeHg (ng/l)
real(R8), allocatable, dimension(:,:) :: KH ! Henry's constant of Hg0 and MeHg (Pa m3/mol)
! linear partitioning (7)
real(R8), allocatable, dimension(:,:) :: Kdoc ! Dissolved organic carbon partition coefficient of HgII and MeHg in water column (L/kg)
real(R8), allocatable, dimension(:,:) :: Kdoc2 ! Dissolved organic carbon partition coefficient of HgII and MeHg in bed sediment (L/kg)
real(R8), allocatable, dimension(:,:) :: Kpom ! Organic matter partition coefficient of HgII and MeHg in water column (L/kg)
real(R8), allocatable, dimension(:,:) :: Kpom2 ! Organic matter partition coefficient of HgII and MeHg in bed sediment (L/kg)
real(R8), allocatable, dimension(:,:) :: Kap ! Algae partition coefficient of HgII and MeHg in water column (L/kg)
real(R8), allocatable, dimension(:,:,:) :: Kp ! Solid partition coefficient of HgII and MeHg in water column (L/kg)
real(R8), allocatable, dimension(:,:,:) :: Kp2 ! Solid partition coefficient of HgII and MeHg in bed sediment (L/kg)
! Freundlich and Langmuir equilibrium partitioning (20)
real(R8), allocatable, dimension(:,:) :: Klpom ! Langmuir adsorption constant of HgII (MeHg) on organic matter in water column (L/�g)
real(R8), allocatable, dimension(:,:) :: Klpom2 ! Langmuir adsorption constant of HgII (MeHg) on organic matter in bed sediment (L/�g)
real(R8), allocatable, dimension(:,:) :: qcpom ! Adsorption capacity of HgII (MeHg) on POM in water column (�g/g)
real(R8), allocatable, dimension(:,:) :: qcpom2 ! Adsorption capacity of HgII (MeHg) on POM in bed sediment (�g/g)
real(R8), allocatable, dimension(:,:) :: Kfpom ! Freundlich adsorption constant of HgII (MeHg) on organic matter in water column (L/kg)
real(R8), allocatable, dimension(:,:) :: Kfpom2 ! Freundlich adsorption constant of HgII (MeHg) on organic matter in bed sediment (L/kg)
real(R8), allocatable, dimension(:,:) :: bpom ! Freundlich exponent of HgII (MeHg) on organic matter in water column (unitless)
real(R8), allocatable, dimension(:,:) :: bpom2 ! Freundlich exponent of HgII (MeHg) on organic matter in bed sediment (unitless)
real(R8), allocatable, dimension(:,:) :: Klap ! Langmuir adsorption constant of HgII (MeHg) on algae in water column (L/�g)
real(R8), allocatable, dimension(:,:) :: qcap ! Adsoption capacity of HgII (MeHg) on algae (�g/g)
real(R8), allocatable, dimension(:,:) :: Kfap ! Freundlich adsorption constant of HgII (MeHg) on algae (L/kg)
real(R8), allocatable, dimension(:,:) :: bap ! Freundlich exponent of HgII (MeHg) on algae (unitless)
real(R8), allocatable, dimension(:,:,:) :: Klp ! Langmuir adsorption constant of HgII (MeHg) on solid in water column (L/�g)
real(R8), allocatable, dimension(:,:,:) :: Klp2 ! Langmuir adsorption constant of HgII (MeHg) on solid in bed sediment (L/�g)
real(R8), allocatable, dimension(:,:,:) :: qcp ! Adsorption capacity of HgII (MeHg) on solid in water column (�g/g)
real(R8), allocatable, dimension(:,:,:) :: qcp2 ! Adsorption capacity of HgII (MeHg) on solid in bed sediment (�g/g)
real(R8), allocatable, dimension(:,:,:) :: Kfp ! Freundlich adsorption constant of HgII (MeHg) on solid in water column (L/kg)
real(R8), allocatable, dimension(:,:,:) :: Kfp2 ! Freundlich adsorption constant of HgII (MeHg) on solid in bed sediment (L/kg)
real(R8), allocatable, dimension(:,:,:) :: bp ! Freundlich exponent of HgII (MeHg) on solid in water column (unitless)
real(R8), allocatable, dimension(:,:,:) :: bp2 ! Freundlich exponent of HgII (MeHg) on solid in bed sediment (unitless)
! transform parameters (14)
real(R8), allocatable, dimension(:) :: kd21 ! Reduction rate from dissolved HgII to Hg0 in water column (1/day)
real(R8), allocatable, dimension(:) :: kdoc21 ! Reduction rate from DOC partitioned HgII to Hg0 in water column (1/day)
real(R8), allocatable, dimension(:,:) :: I0pht ! Light intensity at which kd21 and kdoc21 (kd31 and kdoc31) is measured (w/m2)
real(R8), allocatable, dimension(:) :: kd31 ! Photoreduction rate from dissolved MeHg to Hg0 in water column (1/day)
real(R8), allocatable, dimension(:) :: kdoc31 ! Photoreduction rate from DOC partitioned MeHg to Hg0 in water column (1/day)
real(R8), allocatable, dimension(:) :: kd32 ! Demethylation rate from dissolved MeHg to HgII in water (1/day)
real(R8), allocatable, dimension(:) :: kdoc32 ! Demethylation rate from DOC sorbed MeHg to HgII in water (1/day)
real(R8), allocatable, dimension(:) :: rmso4 ! Ratio of sediment methylation rate and sulfate reduction rate (L/mg)
real(R8), allocatable, dimension(:) :: Kso4 ! Half-saturation constant for the effect of sulfate on methylation (mg-O2/L)
real(R8), allocatable, dimension(:) :: Y12 ! Oxidation yield coefficient from Hg0 to HgII in water column (g/g)
real(R8), allocatable, dimension(:) :: Y21 ! Reduction yield coefficient from HgII to Hg0 in water column (g/g)
real(R8), allocatable, dimension(:) :: Y23 ! Methylation yield coefficient from HgII to MeHg in water column (g/g)
real(R8), allocatable, dimension(:) :: Y31 ! Photodegradation yield coefficient from MeHg to Hg0 in water column (g/g)
real(R8), allocatable, dimension(:) :: Y32 ! Demethylation yield coefficient from MeHg to HgII in water column (g/g)
! integer parameter (3)
integer, allocatable, dimension(:,:) :: vv_option ! 1 user defined; 2 compute
integer, allocatable, dimension(:,:) :: vm_option ! 1 user defined; 2-5 compute
integer, allocatable, dimension(:,:) :: Hgd_solution_option ! 1 Newton; 2 Bisection
!
! pathways (25)
! Hg0
real(R8) :: Hg0_Volatilization ! Hg0 volatilization in water column (ng/L/d)
real(R8) :: Hg0_Oxidation ! Hg0 oxidation in water column (ng/L/d)
! HgII
real(R8) :: HgII_Air_Deposition ! HgII air deposition in water column (ng/L/d)
real(R8) :: HgII_Photoreduction ! HgII photoreduction in water column (ng/L/d)
real(R8) :: HgII_Methylation ! HgII methylation in water column (ng/L/d)
real(R8) :: HgII2_Methylation ! HgII methylation in bed sediment (ng/L/d)
real(R8) :: HgII_Settling ! HgII settling from water column (ng/L/d)
real(R8) :: HgII_Deposition ! HgII settling to bed sediment (ng/L/d)
real(R8) :: HgII_Resuspension ! HgII resuspension to water column (ng/L/d)
real(R8) :: HgII_Erosion ! HgII resuspension from bed sediment (ng/L/d)
real(R8) :: HgII_Burial ! HgII burial in bed sediment (ng/L/d)
real(R8) :: HgII_Transfer ! HgII transfer to water column (ng/L/d)
real(R8) :: HgII2_Transfer ! HgII transfer to bed sediment (ng/L/d)
! MeHg
real(R8) :: MeHg_Air_Deposition ! MeHg air deposition in water column (ng/L/d)
real(R8) :: MeHg_Volatilization ! MeHg volatilization in water column (ng/L/d)
real(R8) :: MeHg_Photoreduction ! MeHg photoreduction in water column (ng/L/d)
real(R8) :: MeHg_Demethylation ! MeHg demethylation in water column (ng/L/d)
real(R8) :: MeHg2_Demethylation ! MeHg demethylation in bed sediment (ng/L/d)
real(R8) :: MeHg_Settling ! MeHg settling from water column (ng/L/d)
real(R8) :: MeHg_Deposition ! MeHg settling to bed sediment (ng/L/d)
real(R8) :: MeHg_Resuspension ! MeHg resuspension to water column (ng/L/d)
real(R8) :: MeHg_Erosion ! MeHg resuspension from bed sediment (ng/L/d)
real(R8) :: MeHg_Burial ! MeHg burial in bed sediment (ng/L/d)
real(R8) :: MeHg_Transfer ! MeHg transfer to water column (ng/L/d)
real(R8) :: MeHg2_Transfer ! MeHg transfer to bed sediment (ng/L/d)
!
! pathway index (25)
integer :: Hg0_Volatilization_index
integer :: Hg0_Oxidation_index
!
integer :: HgII_Air_deposition_index
integer :: HgII_Photoreduction_index
integer :: HgII_Methylation_index
integer :: HgII2_Methylation_index
integer :: HgII_Settling_index
integer :: HgII_Deposition_index
integer :: HgII_Resuspension_index
integer :: HgII_Erosion_index
integer :: HgII_Burial_index
integer :: HgII_Transfer_index
integer :: HgII2_Transfer_index
!
integer :: MeHg_Air_Deposition_index
integer :: MeHg_Volatilization_index
integer :: MeHg_Photoreduction_index
integer :: MeHg_Demethylation_index
integer :: MeHg2_Demethylation_index
integer :: MeHg_Settling_index
integer :: MeHg_Deposition_index
integer :: MeHg_Resuspension_index
integer :: MeHg_Erosion_index
integer :: MeHg_Burial_index
integer :: MeHg_Transfer_index
integer :: MeHg2_Transfer_index
!
! local variables
real(R8) :: Cd2(2:3), Cdoc2(2:3)
!
real(R8) :: gas_constant = 8.314 ! universal gas constant (J/mole/K)
real(R8) :: Iav(2:3), SO4_reduction
real(R8) :: TwaterK, TsedK
integer :: imax = 100
integer :: i, k
logical :: IsWaterCell
!
contains
!===========================================================================================================================
! allocate and initialize all the input parameters with default values
subroutine InitializeHg()
!
! Linear equilibrium partition for DOC
if (use_DOCSorbed(2) .or. use_DOCSorbed(3)) then
if (allocated(Kdoc)) deallocate(Kdoc)
allocate(Kdoc(2:3,nRegion))
Kdoc = 2.0E5
!
if (use_BedSediment) then
if (allocated(Kdoc2)) deallocate(Kdoc2)
allocate(Kdoc2(2:3,nRegion))
Kdoc2 = 2.0E5
end if
end if
!
! Linear equilibrium partition for algae, POM and solids
if ((use_Equilibrium(2,1) .and. use_AlgaeSorbed(2)) .or. (use_Equilibrium(3,1) .and. use_AlgaeSorbed(3))) then
if (allocated(Kap)) deallocate(Kap)
allocate(Kap(2:3,nRegion))
Kap = 2.0E5
end if
!
if ((use_Equilibrium(2,1) .and. use_POMSorbed(2)) .or. (use_Equilibrium(3,1) .and. use_POMSorbed(3))) then
if (allocated(Kpom)) deallocate(Kpom)
allocate(Kpom(2:3,nRegion))
Kpom = 2.0E5
end if
!
if ((use_Equilibrium(2,1) .and. use_AnySolidSorbed(2)) .or. (use_Equilibrium(3,1) .and. use_AnySolidSorbed(3))) then
if (allocated(Kp)) deallocate(Kp)
allocate(Kp(2:3,nGS,nRegion))
Kp = 2.0E5
end if
!
if ((use_Equilibrium(2,2) .and. use_POMSorbed(2)) .or. (use_Equilibrium(3,2) .and. use_POMSorbed(3))) then
if (allocated(Kpom2)) deallocate(Kpom2)
allocate(Kpom2(2:3,nRegion))
Kpom2 = 2.0E5
end if
!
if ((use_Equilibrium(2,2) .and. use_AnySolidSorbed(2)) .or. (use_Equilibrium(3,2) .and. use_AnySolidSorbed(3))) then
if (allocated(Kp2)) deallocate(Kp2)
allocate(Kp2(2:3,nGS,nRegion))
Kp2 = 2.0E5
end if
!
! Langmuir equilibrium partition for algae, POM and solids
if ((use_Langmuir(2,1) .and. use_AlgaeSorbed(2)) .or. (use_Langmuir(3,1) .and. use_AlgaeSorbed(3))) then
if (allocated(Klap)) deallocate(Klap)
allocate(Klap(2:3, nRegion))
Klap = 1.0E5
!
if (allocated(qcap)) deallocate(qcap)
allocate(qcap(2:3, nRegion))
qcap = 1000.0
end if
!
if ((use_Langmuir(2,1) .and. use_POMSorbed(2)) .or. (use_Langmuir(3,1) .and. use_POMSorbed(3))) then
if (allocated(Klpom)) deallocate(Klpom)
allocate(Klpom(2:3, nRegion))
Klpom = 1.0E5
!
if (allocated(qcpom)) deallocate(qcpom)
allocate(qcpom(2:3, nRegion))
qcpom = 1000.0
end if
!
if ((use_Langmuir(2,1) .and. use_AnySolidSorbed(2)) .or. (use_Langmuir(3,1) .and. use_AnySolidSorbed(3))) then
if (allocated(Klp)) deallocate(Klp)
allocate(Klp(2:3, nGS,nRegion))
Klp = 1.0E5
!
if (allocated(qcp)) deallocate(qcp)
allocate(qcp(2:3, nGS,nRegion))
qcp = 1000.0
end if
!
if ((use_Langmuir(2,2) .and. use_POMSorbed(2)) .or. (use_Langmuir(3,2) .and. use_POMSorbed(3))) then
if (allocated(Klpom2)) deallocate(Klpom2)
allocate(Klpom2(2:3, nRegion))
Klpom2 = 1.0E5
!
if (allocated(qcpom2)) deallocate(qcpom2)
allocate(qcpom2(2:3, nRegion))
qcpom2 = 1000.0
end if
!
if ((use_Langmuir(2,2) .and. use_AnySolidSorbed(2)) .or. (use_Langmuir(3,2) .and. use_AnySolidSorbed(3))) then
if (allocated(Klp2)) deallocate(Klp2)
allocate(Klp2(2:3, nGS,nRegion))
Klp2 = 1.0E5
!
if (allocated(qcp2)) deallocate(qcp2)
allocate(qcp2(2:3, nGS,nRegion))
qcp2 = 1000.0
end if
!
! Freundlich equilibrium partition for algae, POM and solids
if ((use_Freundlich(2,1) .and. use_AlgaeSorbed(2)) .or. (use_Freundlich(3,1) .and. use_AlgaeSorbed(3))) then
if (allocated(Kfap)) deallocate(Kfap)
allocate(Kfap(2:3, nRegion))
Kfap = 1.0E2
!
if (allocated(bap)) deallocate(bap)
allocate(bap(2:3, nRegion))
bap = 1.0
end if
!
if ((use_Freundlich(2,1) .and. use_POMSorbed(2)) .or. (use_Freundlich(3,1) .and. use_POMSorbed(3))) then
if (allocated(Kfpom)) deallocate(Kfpom)
allocate(Kfpom(2:3, nRegion))
Kfpom = 1.0E2
!
if (allocated(bpom)) deallocate(bpom)
allocate(bpom(2:3, nRegion))
bpom = 1.0
end if
!
if ((use_Freundlich(2,1) .and. use_AnySolidSorbed(2)) .or. (use_Freundlich(3,1) .and. use_AnySolidSorbed(3))) then
if (allocated(Kfp)) deallocate(Kfp)
allocate(Kfp(2:3, nGS,nRegion))
Kfp = 1.0E2
!
if (allocated(bp)) deallocate(bp)
allocate(bp(2:3, nGS,nRegion))
bp = 1.0
end if
!
if ((use_Freundlich(2,2) .and. use_POMSorbed(2)) .or. (use_Freundlich(3,2) .and. use_POMSorbed(3))) then
if (allocated(Kfpom2)) deallocate(Kfpom2)
allocate(Kfpom2(2:3, nRegion))
Kfpom2 = 1.0E2
!
if (allocated(bpom2)) deallocate(bpom2)
allocate(bpom2(2:3, nRegion))
bpom2 = 1.0
end if
!
if ((use_Freundlich(2,2) .and. use_AnySolidSorbed(2)) .or. (use_Freundlich(3,2) .and. use_AnySolidSorbed(3))) then
if (allocated(Kfp2)) deallocate(Kfp2)
allocate(Kfp2(2:3, nGS,nRegion))
Kfp2 = 1.0E2
!
if (allocated(bp2)) deallocate(bp2)
allocate(bp2(2:3, nGS,nRegion))
bp2 = 1.0
end if
!
! Non-equilibrium partition for algae, POM and solids
if (use_NonEquilibrium(1)) then
if (use_AlgaeSorbed(2)) then
if (allocated(kadap)) deallocate(kadap)
allocate(kadap(nRegion))
kadap = 0.0001
!
if (allocated(kdaap)) deallocate(kdaap)
allocate(kdaap(nRegion))
kdaap = 0.1
!
if (allocated(qcap)) deallocate(qcap)
allocate(qcap(2:3, nRegion))
qcap = 1000.0
end if
!
if (use_POMSorbed(2)) then
if (allocated(kadpom)) deallocate(kadpom)
allocate(kadpom(nRegion))
kadpom = 0.0001
!
if (allocated(kdapom)) deallocate(kdapom)
allocate(kdapom(nRegion))
kdapom = 0.1
!
if (allocated(qcpom)) deallocate(qcpom)
allocate(qcpom(2:3, nRegion))
qcpom = 1000.0
end if
!
if (use_AnySolidSorbed(2)) then
if (allocated(kadp)) deallocate(kadp, kadp_tc)
allocate(kadp(nGS,nRegion), kadp_tc(nGS))
kadp = 0.0001
!
if (allocated(kdap)) deallocate(kdap, kdap_tc)
allocate(kdap(nGS,nRegion), kdap_tc(nGS))
kdap = 0.1
!
if (allocated(qcp)) deallocate(qcp)
allocate(qcp(2:3, nGS,nRegion))
qcp = 1000.0
end if
end if
!
if (use_NonEquilibrium(2)) then
if (use_POMSorbed(2)) then
if (allocated(kadpom2)) deallocate(kadpom2)
allocate(kadpom2(nRegion))
kadpom2 = 0.0001
!
if (allocated(kdapom2)) deallocate(kdapom2)
allocate(kdapom2(nRegion))
kdapom2 = 0.1
!
if (allocated(qcpom2)) deallocate(qcpom2)
allocate(qcpom2(2:3, nRegion))
qcpom2 = 1000.0
end if
!
if (use_AnySolidSorbed(2)) then
if (allocated(kadp2)) deallocate(kadp2, kadp2_tc)
allocate(kadp2(nGS,nRegion), kadp2_tc(nGS))
kadp2 = 0.0001
!
if (allocated(kdap2)) deallocate(kdap2, kdap2_tc)
allocate(kdap2(nGS,nRegion), kdap2_tc(nGS))
kdap2 = 0.1
!
if (allocated(qcp2)) deallocate(qcp2)
allocate(qcp2(2:3, nGS,nRegion))
qcp2 = 1000.0
end if
end if
!
if (use_NonEquilibrium(1) .or. use_NonEquilibrium(2)) then
if (use_AlgaeSorbed(2) .or. use_POMSorbed(2) .or. use_AnySolidSorbed(2)) then
if (allocated(Eaad)) deallocate(Eaad)
allocate(Eaad(nRegion))
Eaad = 50.0
!
if (allocated(Eade)) deallocate(Eade)
allocate(Eade(nRegion))
Eade = 50.0
!
if (allocated(TRade)) deallocate(TRade)
allocate(TRade(nRegion))
Trade = 20.0
end if
end if
!
! Reaction processes
if (allocated(vv)) deallocate(vv)
allocate(vv(3, nRegion))
vv(1, nRegion)%rc20 = 0.144; vv(1, nRegion)%theta = 1.024
vv(3, nRegion)%rc20 = 1.9E-5; vv(3, nRegion)%theta = 1.024
!
if (allocated(KH)) deallocate(KH)
allocate(KH(3, nRegion))
KH(1, nRegion) = 0.09
KH(3, nRegion) = 4.5E-6
!
if (allocated(k12)) deallocate(k12)
allocate(k12(nRegion))
k12 = 1.0E-3
!
if (allocated(Y12)) deallocate(Y12)
allocate(Y12(nRegion))
Y12 = 1.0
!
if (allocated(Ea12)) deallocate(Ea12)
allocate(Ea12(nRegion))
Ea12 = 50.0
!
if (allocated(Tr12)) deallocate(Tr12)
allocate(Tr12(nRegion))
Tr12 = 20.0
!
if (allocated(kd21)) deallocate(kd21)
allocate(kd21(nRegion))
kd21 = 0.05
!
if (allocated(Y21)) deallocate(Y21)
allocate(Y21(nRegion))
Y21 = 1.0
!
if (allocated(I0pht)) deallocate(I0pht)
allocate(I0pht(2:3,nRegion))
I0pht = 100.0
!
if (use_DOCSorbed(2)) then
if (allocated(kdoc21)) deallocate(kdoc21)
allocate(kdoc21(nRegion))
kdoc21 = 0.0
end if
!
if (allocated(kd23)) deallocate(kd23)
allocate(kd23(nRegion))
kd23%rc20 = 1.0E-3; kd23%theta = 1.013
!
if (allocated(Y23)) deallocate(Y23)
allocate(Y23(nRegion))
Y23 = 1.07
!
if (use_DOCSorbed(2)) then
if (allocated(kdoc23)) deallocate(kdoc23)
allocate(kdoc23(nRegion))
kdoc23%rc20 = 0.0; kdoc23%theta = 1.013
end if
!
if (use_BedSediment) then
if (allocated(kso42)) deallocate(kso42)
allocate(kso42(nRegion))
kso42(nRegion)%rc20 = 0.0; kso42(nRegion)%theta = 1.024
!
if (allocated(rmso4)) deallocate(rmso4)
allocate(rmso4(nRegion))
rmso4 = 1.0
!
if (allocated(kso4)) deallocate(Kso4)
allocate(Kso4(nRegion))
Kso4 = 0.5
end if
!
if (allocated(kd31)) deallocate(kd31)
allocate(kd31(nRegion))
kd31 = 0.01
!
if (allocated(Y31)) deallocate(Y31)
allocate(Y31(nRegion))
Y31 = 0.93
!
if (use_DOCSorbed(3)) then
if (allocated(kdoc31)) deallocate(kdoc31)
allocate(kdoc31(nRegion))
kdoc31 = 0.0
end if
!
if (allocated(kd32)) deallocate(kd32)
allocate(kd32(nRegion))
kd32 = 0.05
!
if (allocated(Y32)) deallocate(Y32)
allocate(Y32(nRegion))
Y32 = 0.93
!
if (use_DOCSorbed(3)) then
if (allocated(kdoc32)) deallocate(kdoc32)
allocate(kdoc32(nRegion))
kdoc32 = 0.0
end if
!
if (use_BedSediment) then
if (allocated(kd32_2)) deallocate(kd32_2)
allocate(kd32_2(nRegion))
kd32_2%rc20 = 0.2; kd32_2%theta = 1.013
end if
!
! Global parameters
if (use_AlgaeSorbed(2) .or. use_AlgaeSorbed(3)) then
if (allocated(vsap)) deallocate(vsap)
allocate(vsap(nRegion))
vsap = 0.15
end if
!
if (use_POMSorbed(2) .or. use_POMSorbed(3)) then
if (allocated(vsom)) deallocate(vsom)
allocate(vsom(nRegion))
vsom = 0.1
end if
!
if (use_BedSediment) then
if (allocated(h2)) deallocate(h2)
allocate(h2(nRegion))
h2 = 0.1
!
if (allocated(Por)) deallocate(Por)
allocate(Por(nRegion))
Por = 0.9
!
if (allocated(z2)) deallocate(z2)
allocate(z2(nRegion))
z2 = 5.0
!
if (allocated(Db)) deallocate(Db)
allocate(Db(nRegion))
Db = 0.03
!
if (allocated(beta)) deallocate(beta)
allocate(beta(nRegion))
beta = 33.3
!
if (allocated(ps)) deallocate(ps)
allocate(ps(nRegion))
ps = 2.7
end if
!
if (allocated(alpha)) deallocate(alpha)
allocate(alpha(nRegion))
alpha = 1.3
!
if (((use_Langmuir(2,1) .or. use_Freundlich(2,1) .or. use_Langmuir(2,2) .or. use_Freundlich(2,2)) .and. (use_AlgaeSorbed(2) .or. use_POMSorbed(2) .or. use_AnySolidSorbed(2))) &
.or. ((use_Langmuir(3,1) .or. use_Freundlich(3,1) .or. use_Langmuir(3,2) .or. use_Freundlich(3,2)) .and. (use_AlgaeSorbed(3) .or. use_POMSorbed(3) .or. use_AnySolidSorbed(3)))) then
if (allocated(res)) deallocate(res)
allocate(res(nRegion))
res = 0.001
end if
!
if (allocated(MW)) deallocate(MW)
allocate(MW(3, nRegion))
MW(1, nRegion) = 200.59
MW(2, nRegion) = 271.52
MW(3, nRegion) = 230.66
!
if (allocated(Hgds)) deallocate(Hgds)
allocate(Hgds(3, nRegion))
Hgds(1, nRegion) = 5.6E4
Hgds(2, nRegion) = 2.86E10
Hgds(3, nRegion) = 1.0E8
!
if (use_BedSediment) then
if (allocated(Dm)) deallocate(Dm)
allocate(Dm(2:3,nRegion))
Dm = 0.0001
!
if (allocated(vm)) deallocate(vm)
allocate(vm(2:3,nRegion))
vm = 0.01
end if
!
! integer parameters
if (allocated(vv_option)) deallocate(vv_option)
allocate(vv_option(3, nRegion))
vv_option = 1
!
if (use_BedSediment) then
if (allocated(vm_option)) deallocate(vm_option)
allocate(vm_option(2:3,nRegion))
vm_option = 1
end if
!
if (((use_Langmuir(2,1) .or. use_Freundlich(2,1) .or. use_Langmuir(2,2) .or. use_Freundlich(2,2)) .and. (use_AlgaeSorbed(2) .or. use_POMSorbed(2) .or. use_AnySolidSorbed(2))) &
.or. ((use_Langmuir(3,1) .or. use_Freundlich(3,1) .or. use_Langmuir(3,2) .or. use_Freundlich(3,2)) .and. (use_AlgaeSorbed(3) .or. use_POMSorbed(3) .or. use_AnySolidSorbed(3)))) then
if (allocated(Hgd_solution_option)) deallocate (Hgd_solution_option)
allocate(Hgd_solution_option(2:3, nRegion))
Hgd_solution_option = 1
end if
!
end subroutine
!===========================================================================================================================
! set a real parameter
logical function SetHgRealParameter(groupName, name, paramValue)
character(len=*), intent(in) :: groupName
character(len=*), intent(in) :: name
real(R8), intent(in) :: paramValue(nRegion)
integer groupIndex
!
SetHgRealParameter = .true.
!
if (groupName == 'Element mercury') then
groupIndex = 1
else if (groupName == 'Inorganic mercury') then
groupIndex = 2
else if (groupName == 'Methylmercury') then
groupIndex = 3
end if
!
if (name(1:3) == 'Kp_' .or. name(1:4) == 'Kp2_') then
do i = 1, nGS
if (name == trim(AddIndex('Kp_',i))) then
Kp(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('Kp2_',i))) then
Kp2(groupIndex,i,:) = paramValue
exit
end if
end do
else if (name(1:4) == 'Klp_' .or. name(1:5) == 'Klp2_' .or. name(1:4) == 'Kfp_' .or. &
name(1:5) == 'Kfp2_' .or. name(1:3) == 'bp_' .or. name(1:4) == 'bp2_') then
do i = 1, nGS
if (name == trim(AddIndex('Klp_',i))) then
Klp(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('Klp2_',i))) then
Klp2(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('Kfp_',i))) then
Kfp(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('Kfp2_',i))) then
Kfp2(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('bp_',i))) then
bp(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('bp2_',i))) then
bp2(groupIndex,i,:) = paramValue
exit
end if
end do
else if (name(1:5) == 'kadp_' .or. name(1:5) == 'kdap_' .or. name(1:4) == 'qcp_' .or. &
name(1:5) == 'qcp2_' .or. name(1:6) == 'kadp2_' .or. name(1:6) == 'kdap2_') then
do i = 1, nGS
if (name == trim(AddIndex('kadp_',i))) then
kadp(i,:) = paramValue
exit
else if (name == trim(AddIndex('kdap_',i))) then
kdap(i,:) = paramValue
exit
else if (name == trim(AddIndex('qcp_',i))) then
qcp(groupIndex,i,:) = paramValue
exit
else if (name == trim(AddIndex('kadp2_',i))) then
kadp2(i,:) = paramValue
exit
else if (name == trim(AddIndex('kdap2_',i))) then
kdap2(i,:) = paramValue
exit
else if (name == trim(AddIndex('qcp2_',i))) then
qcp2(groupIndex,i,:) = paramValue
exit
end if
end do
else
select case (name)
!
! Linear equilibrium partition
case ('Kdoc')
Kdoc(groupIndex,:) = paramValue
case ('Kdoc2')
Kdoc2(groupIndex,:) = paramValue
case ('Kap')
Kap(groupIndex,:) = paramValue
case ('Kpom')
Kpom(groupIndex,:) = paramValue
case ('Kpom2')
Kpom2(groupIndex,:) = paramValue
!
! Langmuir equilibrium partition
case ('Klap')
Klap(groupIndex,:) = paramValue
case ('qcap')
qcap(groupIndex,:) = paramValue
case ('Klpom')
Klpom(groupIndex,:) = paramValue
case ('qcpom')
qcpom(groupIndex,:) = paramValue
case ('Klpom2')
Klpom2(groupIndex,:) = paramValue
case ('qcpom2')
qcpom2(groupIndex,:) = paramValue
!
! Freundlich-equilibrium partition
case ('Kfap')
Kfap(groupIndex,:) = paramValue
case ('bap')
bap(groupIndex,:) = paramValue
case ('Kfpom')
Kfpom(groupIndex,:) = paramValue
case ('bpom')
bpom(groupIndex,:) = paramValue
case ('Kfpom2')
Kfpom2(groupIndex,:) = paramValue
case ('bpom2')
bpom2(groupIndex,:) = paramValue
!
! Non-equilibrium partition
case('kadap')
kadap(:) = paramValue
case('kdaap')
kdaap(:) = paramValue
case('kadpom')
kadpom(:) = paramValue
case('kdapom')
kdapom(:) = paramValue
case('kadpom2')
kadpom2(:) = paramValue
case('kdapom2')
kdapom2(:) = paramValue
case('Eaad')
Eaad(:) = paramValue
case('Eade')
Eade(:) = paramValue
case('Trade')
Trade(:) = paramValue
!
! Processes
case ('k12')
k12(:) = paramValue
case ('Y12')
Y12(:) = paramValue
case ('Ea12')
Ea12(:) = paramValue
case ('Tr12')
Tr12(:) = paramValue
case ('I0pht')
I0pht(groupIndex,:) = paramValue
case ('kd21')
kd21(:) = paramValue
case ('kdoc21')
kdoc21(:) = paramValue
case ('Y21')
Y21(:) = paramValue
case ('kd23_rc20')
kd23(:)%rc20 = paramValue
case ('kd23_theta')
kd23(:)%theta = paramValue
case ('kdoc23_rc20')
kdoc23(:)%rc20 = paramValue
case ('kdoc23_theta')
kdoc23(:)%theta = paramValue
case ('Y23')
Y23(:) = paramValue
case ('kso42_rc20')
kso42(:)%rc20 = paramValue
case ('kso42_theta')
kso42(:)%theta = paramValue
case ('rmso4')
rmso4(:) = paramValue
case ('Kso4')
Kso4(:) = paramValue
case ('kd31')
kd31(:) = paramValue
case ('kdoc31')
kdoc31(:) = paramValue
case ('Y31')
Y31(:) = paramValue
case ('kd32')
kd32(:) = paramValue
case ('kdoc32')
kdoc32(:) = paramValue
case ('Y32')
Y32(:) = paramValue
case ('kd32_2_rc20')
kd32_2(:)%rc20 = paramValue
case ('kd32_2_theta')
kd32_2(:)%theta = paramValue
case ('vv_rc20')
vv(groupIndex,:)%rc20 = paramValue
case ('vv_theta')
vv(groupIndex,:)%theta = paramValue
case ('KH')
KH(groupIndex, :) = paramValue
!
! Global parameters
case ('vsap')
vsap = paramValue
case ('vsom')
vsom = paramValue
case ('h2')
h2 = paramValue
case ('Por')
Por = paramValue
!
case ('beta')
beta = paramValue
case ('z2')
z2 = paramValue
case ('Db')
Db = paramValue
case ('ps')
ps = paramValue
case ('res')
res = paramValue
case ('alpha')
alpha = paramValue
!
case ('MW')
MW(groupIndex, :) = paramValue
case ('Hgds')
Hgds(groupIndex,:) = paramValue
case ('Dm')
Dm(groupIndex,:) = paramValue
case ('vm')
vm(groupIndex,:) = paramValue
case default
! did not find the parameter, return false
SetHgRealParameter = .false.
end select
end if
!
end function
!===========================================================================================================================
! set integer parameter
logical function SetHgIntegerParameter(groupName, name, paramValue)
character(len=*), intent(in) :: groupName
character(len=*), intent(in) :: name
integer, intent(in) :: paramValue(nRegion)
integer groupIndex
!
SetHgIntegerParameter = .true.
if (groupName == 'Element mercury') then
groupIndex = 1
else if (groupName == 'Inorganic mercury') then
groupIndex = 2
else if (groupName == 'Methylmercury') then
groupIndex = 3
end if
select case (name)
case ('vm Option')
vm_option(groupIndex,:) = paramValue
case ('vv Option')
vv_option(groupIndex,:) = paramValue
case ('Hgd Solution')
Hgd_solution_option(groupIndex,:) = paramValue
case default
! did not find the parameter, return false
SetHgIntegerParameter = .false.
end select
end function
!===========================================================================================================================
! set pathway index
logical function SetHgPathwayIndex(pathwayName, index)
character(len=*), intent(in) :: pathwayName
integer :: index
character(len=maxChar) :: name_tempt, name_tempt2
!
SetHgPathwayIndex = .false.
! (25)
select case (pathwayName)
case ('Atm <--> Hg0')
Hg0_Volatilization_index = index
SetHgPathwayIndex = .true.
case ('Hg0 --> HgII')
Hg0_Oxidation_index = index
SetHgPathwayIndex = .true.
!
case ('Air --> HgII')
HgII_Air_Deposition_index = index
SetHgPathwayIndex = .true.
case ('HgII --> Hg0')
HgII_Photoreduction_index = index
SetHgPathwayIndex = .true.
case ('HgII --> MeHg')
HgII_Methylation_index = index
SetHgPathwayIndex = .true.
case ('HgII2 --> MeHg2')
HgII2_Methylation_index = index
SetHgPathwayIndex = .true.
case ('HgII --> Bed')
HgII_Settling_index = index
SetHgPathwayIndex = .true.
case ('HgII --> HgII2')
HgII_Deposition_index = index
SetHgPathwayIndex = .true.
case ('Bed --> HgII')
HgII_Resuspension_index = index
SetHgPathwayIndex = .true.
case ('HgII2 --> HgII')
HgII_Erosion_index = index
SetHgPathwayIndex = .true.
case ('HgII2 burial')
HgII_Burial_index = index
SetHgPathwayIndex = .true.
case ('HgII2 <--> HgII')
HgII_Transfer_index = index
SetHgPathwayIndex = .true.
case ('HgII <--> HgII2')
HgII2_Transfer_index = index
SetHgPathwayIndex = .true.
!
case ('Air --> MeHg')
MeHg_Air_Deposition_index = index
SetHgPathwayIndex = .true.
case ('Atm <--> MeHg')
MeHg_Volatilization_index = index
SetHgPathwayIndex = .true.
case ('MeHg --> Hg0')
MeHg_Photoreduction_index = index
SetHgPathwayIndex = .true.
case ('MeHg --> HgII')
MeHg_Demethylation_index = index
SetHgPathwayIndex = .true.
case ('MeHg2 --> HgII2')
MeHg2_Demethylation_index = index
SetHgPathwayIndex = .true.
case ('MeHg --> Bed')
MeHg_Settling_index = index
SetHgPathwayIndex = .true.
case ('MeHg --> MeHg2')
MeHg_Deposition_index = index
SetHgPathwayIndex = .true.
case ('Bed --> MeHg')
MeHg_Resuspension_index = index
SetHgPathwayIndex = .true.
case ('MeHg2 --> MeHg')
MeHg_Erosion_index = index
SetHgPathwayIndex = .true.
case ('MeHg2 burial')
MeHg_Burial_index = index
SetHgPathwayIndex = .true.
case ('MeHg2 <--> MeHg')
MeHg_Transfer_index = index
SetHgPathwayIndex = .true.
case ('MeHg <--> MeHg2')