-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoundaryConditions_mod.f90
executable file
·1387 lines (1243 loc) · 55.1 KB
/
BoundaryConditions_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 BoundaryConditions_mod
! -----------------------------------------------------------------------
! This module is the main driver module for defining and setting
! initial & boundary conditions (ICs & BCs) for the chemical species.
!
! The main code calls up these routines with just:
! call BoundaryConditions(month) !once per month, after say newmonth
!
! On first call, this routine runs some intialisation routines in related
! modules, reads the global data, and sets full 3-D concentration fields
! of the advected and background concentration fields (xn_adv, xn_bgn).
! On subsequent calls (first_call=.false.), the routine reads new
! global input data, and sets the concentrations at the top level and
! lateral boundaries for advected species. For background species it reset
! full 3-D concentration fields.
! The main related IC/BC modules/files are:
!
! 1. GetBICData, reads or define BIC from tables and functions (replaces older GlobalBC_mod)
!
! 2. CM_BoundaryConditions.inc - assigns mappings, telling which
! Unified EMEP model species the global model fdata are
! assigned to (bc2xn_adv, bc2xn_bgn arrays).
!
! 3. NB: Nest_mod.f90 - In nested runs (such as forecast runs), the ICs & BCs
! are reseted by readxn (Nest_mod), superseeding the IC/BCs in this module.
! -----------------------------------------------------------------------
!
! The routines make use of a "feature" of the model: that the concentration
! (xn) values along boundaries are not changed due to advection or chemistry.
! Thus, bc values only need to be set once per month, firstly for the whole 3-D
! domain, then monthly for the sides and top.
! Background species must be reset in 3-D each month.
! -----------------------------------------------------------------------
use CheckStop_mod, only: CheckStop
use Chemfields_mod, only: xn_adv, xn_bgn, NSPEC_BGN ! emep model concs.
use ChemDims_mod, only: NSPEC_SHL,NSPEC_ADV
use ChemSpecs_mod ! provide species names, IXADV_*
use Config_module, only: KMAX_MID & ! Number of levels in vertical
,iyr_trend & ! Used for e.g. future scenarios
! Two options for CH4. BGND_CH4 has priority.
,BGND_CH4 & ! If positive, replaces defaults
,fileName_CH4_ibcs & ! If present, replaces uses iyr_trend
,USES, MasterProc, PPB, Pref, LoganO3File, DustFile
use Debug_module, only: DEBUG ! -> DEBUG%BCS
use Functions_mod, only: StandardAtmos_kPa_2_km ! for use in Hz scaling
use GridValues_mod, only: glon, glat & ! full domain lat, long
,debug_proc, debug_li, debug_lj & ! debugging
,i_fdom, j_fdom,A_mid,B_mid !
use Io_mod, only: open_file, ios, IO_TMP
use Io_Progs_mod, only: datewrite, PrintLog
use Landuse_mod, only: mainly_sea
use LocalVariables_mod, only: Grid
use MetFields_mod, only: roa
use MPI_Groups_mod, only: MPI_DOUBLE_PRECISION, MPI_SUM,MPI_INTEGER, &
MPI_COMM_CALC, IERROR
use NetCDF_mod, only: ReadField_CDF,vertical_interpolate
use Par_mod, only: &
LIMAX, LJMAX, limax, ljmax, me &
,neighbor, NORTH, SOUTH, EAST, WEST & ! domain neighbours
,NOPROC&
,IRUNBEG,JRUNBEG,li1,li0,lj0,lj1
use PhysicalConstants_mod, only: PI, ATWAIR
use SmallUtils_mod, only : find_index
use TimeDate_mod, only: daynumber
use TimeDate_ExtraUtil_mod,only: date2string
implicit none
private
integer, public, parameter :: &
IBC_O3 = 1 &
,IBC_NO = 2 &
,IBC_NO2 = 3 &
,IBC_PAN = 4 &
,IBC_HNO3 = 5 & ! used for nitrate too
,IBC_SO2 = 6 &
,IBC_SO4 = 7 &
,IBC_CO = 8 &
,IBC_C2H6 = 9 &
,IBC_C4H10 = 10 &
,IBC_HCHO = 11 &
,IBC_CH3CHO = 12 &
,IBC_H2O2 = 13 &
,IBC_NH4_f = 14 &
,IBC_NO3_f = 15 &
,IBC_NO3_c = 16 &
,IBC_SeaSalt_f= 17 &
,IBC_SeaSalt_c= 18 &
,IBC_SeaSalt_g= 19 &
,IBC_Dust_f = 20 & ! Dust
,IBC_Dust_c = 21 & ! Dust
,NGLOB_BC = IBC_Dust_c ! Totan no. species setup in this module
! -- subroutines in this module:
public :: BoundaryConditions ! call every month
private :: GetBICData, &
Set_bcmap, & ! sets xn2adv_changed, etc.
My_bcmap ! sets bc2xn_adv, bc2xn_bc, and misc_bc
!/- Allow different behaviour on 1st call - full 3-D asimilation done
logical, private, save :: first_call = .true.
!/ - for debugging
logical, private, parameter :: DEBUG_MYBC = .false.
! Set indices
! -----------------------------------------------------------------------
! For species which have constant mixing ratios:
integer, public, parameter :: &
NMISC_BC = 2, &
IBC_H2 = NGLOB_BC + 1, &
IBC_CH4 = NGLOB_BC + 2, &
NTOT_BC = NGLOB_BC + NMISC_BC
! misc_bc specifies concentrations of these species:
real, public, allocatable,save, dimension(:,:) :: misc_bc
! Define mapping arrays
! -----------------------------------------------------------------------
! The mapping is done through the arrays bc2xn_adv and bc2xn_bgn, such that
! the emep species are given along the x-dimension and the bc species along
! the y. e.g., the statement
! bc2xn_adv(IBC_NOX,IXADV_NO2) = 0.55
! would assign the BC concentration of NOX to the EMEP model concentration
! of NO2 after multiplication with a factor 0.55.
! (The CTM2 concentration of NOx used as BC after a multilication
! with a factor 0.55.)
! -----------------------------------------------------------------------
real, public, save :: bc2xn_adv(NTOT_BC,NSPEC_ADV), & ! see above
bc2xn_bgn(NTOT_BC,NSPEC_BGN)
! Arrays for mapping from global bc to emep xn concentrations:
! ---------------------------------------------------------------------------
integer, private,save, dimension(NTOT_BC) :: &
bc_used,bc_used_adv,bc_used_bgn ! set to 1 if bc used
integer, private, save :: &
num_adv_changed, & ! Num. adv. species that have bc's
num_used_adv, & ! Max times a conc. from e.g CTM2 is used as bc
num_bgn_changed,num_used_bgn, &
num_changed ! sum of adv and bgn
!In general "changed" means "bc used for this species"
logical, private, save :: &
xn_adv_changed(NSPEC_ADV), & ! true if emep xn_adv changed by bcs
xn_bgn_changed(NSPEC_BGN) ! true if emep xn_bgn changed by bcs
integer, private, save :: &
spc_adv2changed(NSPEC_ADV), & ! index of advected specie is converted to index
spc_bgn2changed(NSPEC_BGN) ! in the row of advected species that have bc
integer, allocatable, dimension(:),save :: &
spc_changed2adv, & ! index of adv. specie that have bc is converted
spc_changed2bgn ! to index in the row of advected species
integer, allocatable, dimension(:,:),save :: &
spc_used_adv, & ! 1.dimension(ibc) runs through bc adv.species
spc_used_bgn ! 2.dim.(i) through those who get same conc. from
! bc (eg i=1,2 for ibc=HNO3 when HNO3 from CTM2
! is used as bc both for HNO3 and SO4) spc_used_adv
! gives the index in the row of advected species
real, allocatable,dimension(:,:,:),save :: O3_logan,O3_logan_emep
real, allocatable,dimension(:,:,:),save :: Dust_3D, Dust_3D_emep
contains
subroutine BoundaryConditions(year,month)
! ---------------------------------------------------------------------------
! Read in monthly-average global mixing ratios, and if found, collect the
! data in bc_adv, bc_bgn arrays for later interpolations
! NOTES
! 1.- If mixing ratio by mass the scale by molcular weight)
! 2.- So far no scaling is done, but this could be done
! in Set_bcmap with atomic weights
! 3.- On the first call, we also run the setup-subroutines
! 4.- Year is now obtained from the iyr_trend set in run.pl.
! This allows, e.g. runs with BCs for 2100 and met of 1990.
! ---------------------------------------------------------------------------
integer, intent(in) :: year ! "meteorology" year
integer, intent(in) :: month
integer :: ibc, iem, k, i, j ,n, ntot ! loop variables
integer :: info ! used in rsend
real :: bc_fac ! Set to 1.0, except sea-salt over land = 0.01
logical :: bc_seaspec ! if sea-salt species
integer :: errcode
integer, save :: idebug=0, itest=1, i_test=0, j_test=0
real :: bc_data(LIMAX,LJMAX,KMAX_MID)
if (first_call) then
if (DEBUG%BCS) write(*,"(a,I3,1X,a,i5)") &
"FIRST CALL TO BOUNDARY CONDITIONS, me: ", me, "TREND YR ", iyr_trend
allocate(misc_bc(NGLOB_BC+1:NTOT_BC,KMAX_MID))
call My_bcmap(iyr_trend) ! assigns bc2xn_adv and bc2xn_bgn mappings
call Set_bcmap() ! assigns xn2adv_changed, etc.
num_changed = num_adv_changed + num_bgn_changed !u1
if (DEBUG%BCS) write(*, "((A,I0,1X))") &
"BCs: num_adv_changed: ", num_adv_changed, &
"BCs: num_bgn_changed: ", num_bgn_changed, &
"BCs: num changed: ", num_changed
bc_data=0.0
end if ! first call
if (DEBUG%BCS) write(*, "((A,I0,1X))") &
"CALL TO BOUNDARY CONDITIONS, me:", me, &
"month ", month, "TREND2 YR ", iyr_trend, "me ", me
if (num_changed==0) then
write(*,*) "BCs: No species requested"
return
end if
errcode = 0
if (DEBUG%BCS.and.debug_proc) then
do i = 1, limax
do j = 1, ljmax
if (i_fdom(i)==DEBUG%IJ(1).and.j_fdom(j)==DEBUG%IJ(2)) then
i_test = i
j_test = j
end if
end do
end do
end if
if (first_call) then
idebug = 1
if (DEBUG%BCS) write(*,*) "RESET 3D BOUNDARY CONDITIONS", me
do k = 1, KMAX_MID
do j = 1, ljmax
do i = 1, limax
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
end do
end do
else
if (DEBUG%BCS.and.MasterProc) write(*,*) "RESET LATERAL BOUNDARIES"
do k = 2, KMAX_MID
do j = lj0, lj1
!left
do i = 1, li0-1
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
!right
do i = li1+1, limax
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
end do
!lower
do j = 1, lj0-1
do i = 1, limax
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
end do
!upper
do j = lj1+1, ljmax
do i = 1, limax
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
end do
end do
!top
do k = 1, 1
do j = 1, ljmax
do i = 1, limax
xn_adv(:,i,j,k)=0.0
xn_bgn(:,i,j,k)=0.0
end do
end do
end do
end if
!== BEGIN READ_IN OF GLOBAL DATA
do ibc = 1, NGLOB_BC
if(bc_used(ibc) == 0)cycle
call GetBICData(year,month,ibc,bc_used(ibc),bc_data,errcode)
if (first_call) then
! Set 3-D arrays of new BCs
do n = 1, bc_used_adv(ibc)
iem = spc_used_adv(ibc,n)
ntot = iem + NSPEC_SHL
! Sea-salt.
! If SeaSalt isn't called from mk.GenChem, we don't have the
! SS_GROUP, so we search for the simple SEASALT name.
bc_seaspec = .false.
if ( USES%SEASALT .and. &
( index( species(ntot)%name, "SeaSalt_" ) > 0 ) ) then
bc_seaspec = .true.
end if
if ( debug_proc ) write (*,*) "SEAINDEX", &
trim(species(ntot)%name), n, ntot, bc_seaspec,&
index( species(ntot)%name, "SeaSalt_")
do k = 1, KMAX_MID
do j = 1, ljmax
do i = 1, limax
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do ! i
end do ! j
end do ! k
end do !n
do n = 1,bc_used_bgn(ibc)
iem = spc_used_bgn(ibc,n)
!/- Non-advected background species
do k = 1, KMAX_MID
do j = 1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
! ! bc_bgn(n,(i_fdom(i)-IRUNBEG+1),(j_fdom(j)-JRUNBEG+1),k)
end do ! i
end do ! j
end do ! k
end do
else
! Set LATERAL (edge and top) arrays of new BCs
idebug = idebug + 1
do n = 1, bc_used_adv(ibc)
iem = spc_used_adv(ibc,n)
ntot = iem + NSPEC_SHL
bc_seaspec = .false.
if ( USES%SEASALT .and. ( index( species(ntot)%name, "SeaSalt_" ) > 0 ) ) then
bc_seaspec = .true.
end if
do k = 2, KMAX_MID
do j = lj0, lj1
!left
do i = 1, li0-1
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do
!right
do i = li1+1, limax
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do
end do
!lower
do j = 1, lj0-1
do i = 1, limax
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do
end do
!upper
do j = lj1+1, ljmax
do i = 1, limax
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do
end do
end do
!top
do k = 1, 1
do j = 1, ljmax
do i = 1, limax
bc_fac = 1.0
if ( bc_seaspec ) then
if ( .not. mainly_sea(i,j)) bc_fac = 0.001 ! low over land
if ( .not. USES%SEASALT ) bc_fac = 0.0 ! not wanted!
end if
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) +&
bc_fac * & ! used for sea-salt species
! bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_adv(ibc,iem)
bc_data(i,j,k)*bc2xn_adv(ibc,iem)
end do
end do
end do
end do !n
!/- Non-advected background species
do n = 1,bc_used_bgn(ibc)
iem = spc_used_bgn(ibc,n)
do k = 2, KMAX_MID
do j = lj0, lj1
!left
do i = 1, li0-1
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
end do
!right
do i = li1+1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
end do
end do
!lower
do j = 1, lj0-1
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
end do
end do
!upper
do j = lj1+1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
end do
end do
end do
!top
do k = 1, 1
do j = 1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) &
! + bc_data(i_fdom(i)-IRUNBEG+1,j_fdom(j)-JRUNBEG+1,k)*bc2xn_bgn(ibc,iem)
+ bc_data(i,j,k)*bc2xn_bgn(ibc,iem)
end do
end do
end do
end do
end if
end do ! ibc
if (first_call) then
!3D misc
do ibc = NGLOB_BC+1, NTOT_BC
do n = 1,bc_used_bgn(ibc)
iem = spc_used_bgn(ibc,n)
!/- Non-advected background misc species
do k = 1, KMAX_MID
do j = 1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do ! i
end do ! j
end do ! k
end do
do n = 1,bc_used_adv(ibc)
iem = spc_used_adv(ibc,n)
!/- Advected misc species
do k = 1, KMAX_MID
do j = 1, ljmax
do i = 1, limax
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
! ! bc_bgn(n,(i_fdom(i)-IRUNBEG+1),(j_fdom(j)-JRUNBEG+1),k)
end do ! i
end do ! j
end do ! k
end do!n
end do!ibc
else
!LATERAL misc
do ibc = NGLOB_BC+1, NTOT_BC
do n = 1,bc_used_bgn(ibc)
iem = spc_used_bgn(ibc,n)
!/- Non-advected background misc species
do k = 2, KMAX_MID
do j = lj0, lj1
!left
do i = 1, li0-1
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do
!right
do i = li1+1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do
end do
!lower
do j = 1, lj0-1
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do
end do
!upper
do j = lj1+1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do
end do
end do
!top
do k = 1, 1
do j = 1, ljmax
do i = 1, limax
xn_bgn(iem,i,j,k) = xn_bgn(iem,i,j,k) +misc_bc(ibc,k)
end do
end do
end do
end do
!/- Advected misc species
do n = 1,bc_used_adv(ibc)
iem = spc_used_adv(ibc,n)
do k = 2, KMAX_MID
do j = lj0, lj1
!left
do i = 1, li0-1
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
end do
!right
do i = li1+1, limax
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
end do
end do
!lower
do j = 1, lj0-1
do i = 1, limax
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
end do
end do
!upper
do j = lj1+1, ljmax
do i = 1, limax
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
end do
end do
end do
!top
do k = 1, 1
do j = 1, ljmax
do i = 1, limax
xn_adv(iem,i,j,k) = xn_adv(iem,i,j,k) + misc_bc(ibc,k)!
end do
end do
end do
end do!n
end do!ibc
end if
if (DEBUG%BCS.and.debug_proc.and.i_test>0) then
i = i_test
j = j_test
print "(a20,3i4,2f8.2)","DEBUG BCS Rorvik", me, i,j,glon(i,j),glat(i,j)
print "(a20,3i4)","DEBUG BCS Rorvik DIMS",num_adv_changed
do k = 1, KMAX_MID
print "(a20,i4,f8.2)","DEBUG O3 Debug-site ", k, &
xn_adv(IXADV_O3,i_test,j_test,k)/PPB
end do
end if ! DEBUG
if (DEBUG%BCS.and.debug_proc) then
itest = 1
print *,"BoundaryConditions: No CALLS TO BOUND Cs", first_call,idebug
!*** the following uses hard-coded IXADV_ values for testing.
! Remove later **
info = 1 ! index for ozone in bcs
print *,"BCs: bc2xn(info,itest) : ", bc2xn_adv(info,itest)
info = 43 ! index for NO in bcs
print *,"BCs: NSPECS: BC, ADV, BG, ", NTOT_BC, NSPEC_ADV, NSPEC_BGN
print *,"BCs: Number of bc_used: ", sum(bc_used)
print *,"BCs: limax, ljmax", limax, ljmax
if (NSPEC_BGN>0) then
do k = KMAX_MID, 1, -1
print "(a23,i3,e14.4)","BCs NO :",k,xn_bgn(itest,i_test,j_test,k)/PPB
end do
else
print "(a)","No SET BACKGROUND BCs"
end if
end if ! DEBUG
if (first_call) first_call = .false.
end subroutine BoundaryConditions
subroutine My_bcmap(iyr_trend)
! ---------------------------------------------------------------------------
! sets bc2xn_adv, bc2xn_bc, and misc_bc
! ---------------------------------------------------------------------------
integer, intent(in) :: iyr_trend !ds Year for which BCs are wanted
real :: trend_ch4
integer :: ii,i,k, io_ch4, yr_rcp= -999
real :: decrease_factor(NGLOB_BC+1:NTOT_BC) ! Decrease factor for misc bc's
! Gives the factor for how much of the top-layer conc. that is left
! at bottom layer
character(len=120) :: txt
real :: ch4_rcp
character(len=*),parameter :: dtxt='BCs_Mybcmap:'
real :: top_misc_bc(NGLOB_BC+1:NTOT_BC) ! Conc. at top of misc bc
! real :: ratio_length(KMAX_MID) ! Vertical length of the actual layer
! divided by length from midpoint of
! layer 1 to layer KMAX_MID
! - Initialise
misc_bc = 0.0
bc2xn_adv = 0.0
bc2xn_bgn = 0.0
! Own (constant mixing ratio) boundary conditions
! NOTE: these species have to have the bc2xn_ indices set to 1.0 for either
! the advected or the background concentrations, in order that the
! concentrations specified in misc_bc are transferred correctly into the
! boundary conditions.
! CH4 IBCs. Default is ACP2012 values unless overridden by BGND_CH4 or
! RCP settings
! Default:
! set values of 1625 in 1980, 1780 in 1990, 1820 in 2000, and 1970 in
! 2010. Interpolate
! between these for other years. Values from EMEP Rep 3/97, Table 6.2 for
! 1980, 1990, and from CDIAC (Mace Head) data for 2000.
! 2010 also from Mace Head
if ( BGND_CH4 == -1 ) then
if( iyr_trend >= 2010) then
top_misc_bc(IBC_CH4) = 1870.0
else if ( iyr_trend >= 2000) then
top_misc_bc(IBC_CH4) = 1820 + (iyr_trend-2000)*0.1*(1870-1820)
else if ( iyr_trend >= 1990 ) then
top_misc_bc(IBC_CH4) = 1780.0 + (iyr_trend-1990)*0.1*(1820-1780.0)
else
top_misc_bc(IBC_CH4) = 1780.0 * exp(-0.01*0.91*(1990-iyr_trend)) ! Zander,1975-1990
!exp(-0.01*0.6633*(1975-iyr_trend)) ! Zander,1951-1975
end if
else if ( fileName_CH4_ibcs /= 'NOTSET' ) then ! use RCP26, 45 or 85, set in config_emep
call open_file(IO_TMP,'r',fileName_CH4_ibcs,needed=.true.)
call CheckStop(ios,dtxt//"CH4_ibcs error in "//trim(fileName_CH4_ibcs) )
do i=1, 9999 ! has 750 records while(.true.)
read(IO_TMP,'(a80)') txt
if ( txt(1:1) == '#' ) cycle
read(txt, *) yr_rcp, ch4_rcp
if ( yr_rcp == iyr_trend) exit
end do
close(IO_TMP)
top_misc_bc(IBC_CH4) = ch4_rcp
if ( MasterProc ) write(*,*) dtxt//'CH4 SET from RCPs for CH4:', &
trim(fileName_CH4_ibcs), iyr_trend, ch4_rcp
end if
! Reset with namelist values if set
if ( BGND_CH4 > 0 ) then
if ( MasterProc ) write(*,*) dtxt//'CH4 OVERRIDE for CH4:', BGND_CH4
top_misc_bc(IBC_CH4) = BGND_CH4
end if
trend_ch4 = top_misc_bc(IBC_CH4)/1780.0
if (MasterProc) then
write(txt,"(a,3i6,f8.1,f8.3)") dtxt//" CH4 settings (iyr,nml,ch4,trend): ",&
iyr_trend, yr_rcp, nint(BGND_CH4), top_misc_bc(IBC_CH4),trend_ch4
call PrintLog(txt)
end if
top_misc_bc(IBC_CH4) = top_misc_bc(IBC_CH4) * PPB
top_misc_bc(IBC_H2) = 600.0 * PPB
decrease_factor(IBC_H2) = 0.0 ! No increase/decrease with height
decrease_factor(IBC_CH4) = 0.0 ! No increase/decrease with height
! Vertical profile: Function of sigma_mid. Assumes that top_misc_bc is given for
! top(sigma_bnd(1)=0., and that at ground (sigma_bnd(KMAX_BND)=1.) the conc.
! is top_misc_bc -decrease_factor*top_misc_bc. Since the choice to set the
! concentration as a factor of sigma_mid, the concentration in the lowest
! grid cell will not be excactly top_misc_bc -decrease_factor*top_misc_bc, but close.
!pw March 2013 sigma_mid replaced by B_mid (equal for sigma coordinates)
do ii=NGLOB_BC+1,NTOT_BC
do k=1,KMAX_MID
misc_bc(ii,k) = top_misc_bc(ii)*(1.0-decrease_factor(ii)*B_mid(k))
if (MasterProc.and.DEBUG_MYBC) print "(a20,2es12.4,i4)",&
"height,misc_vert,k",B_mid(k),misc_bc(ii,k),k
end do
end do
bc2xn_adv(IBC_H2, IXADV_H2) = 1.0
bc2xn_adv(IBC_CH4, IXADV_CH4) = 1.0
!/- completeness check
if (DEBUG_MYBC ) then
print *, "In My_bcmap, NGLOB_BC, NTOT_BC is", NGLOB_BC, NTOT_BC
do i = NGLOB_BC+1 , NTOT_BC
print *, "In My_bcmap, sum-adv", i, " is", sum(bc2xn_adv(i,:))
print *, "In My_bcmap, sum-bgn", i, " is", sum(bc2xn_bgn(i,:))
end do
end if ! DEBUG
do i = NGLOB_BC+1 , NTOT_BC
call CheckStop(sum(bc2xn_adv(i,:))+sum(bc2xn_bgn(i,:))/=1.0,&
"BCproblem - My_bcmap")
end do
!/- mappings for species from Logan + obs model given with IBC index.
include 'BoundaryConditions_CM.inc'
end subroutine My_bcmap
subroutine Set_bcmap()
! ---------------------------------------------------------------------------
! Returns some 1-D arrays which say if a bc is used or if an
! emep xn_adv or xn_bgn is affected. This information is derived from
! the mapping arrays bc2xn_adv and bc2xn_bgn, such that the emep species
! are given along the x-dimension and the bc species along the y.
! e.g., the statement
! bc2xn_adv(IBC_NOX,IXADV_NO2) = 0.55
! would assign the BC concentration of NOX to the EMEP model concentration
! of NO2 after multiplication with a factor 0.55.
! These arrays have been set in the CM_BoundaryConditions.inc file.
! ---------------------------------------------------------------------------
integer :: ibc, iem ! local loop variables
integer :: i
! Initialise
bc_used = 0
bc_used_adv = 0
bc_used_bgn = 0
!/- bc_used set to one where a bc species is to be used.
do ibc = 1, NTOT_BC
if (any(bc2xn_adv(ibc,:)>0).or. &
any(bc2xn_bgn(ibc,:)>0)) bc_used(ibc) = 1
do iem = 1, NSPEC_ADV
if(bc2xn_adv(ibc,iem)>0) bc_used_adv(ibc) = bc_used_adv(ibc)+1
end do
do iem = 1, NSPEC_BGN
if(bc2xn_bgn(ibc,iem)>0) bc_used_bgn(ibc) = bc_used_bgn(ibc)+1
end do
end do ! ibc
num_used_adv = maxval(bc_used_adv)
num_used_bgn = maxval(bc_used_bgn)
! Initialise
xn_adv_changed = .false.
xn_bgn_changed = .false.
num_adv_changed = 0
num_bgn_changed = 0
do iem = 1, NSPEC_ADV
if (any(bc2xn_adv(:,iem)>0)) then
xn_adv_changed(iem) = .true.
num_adv_changed = num_adv_changed + 1
end if
end do ! iem
do iem = 1, NSPEC_BGN
if (any(bc2xn_bgn(:,iem)>0)) then
xn_bgn_changed(iem) = .true.
num_bgn_changed = num_bgn_changed + 1
end if
end do ! iem
if (DEBUG%BCS) write(*,*) "TEST SET_BCMAP bc_used: ",&
(bc_used(ibc),ibc=1, NTOT_BC)
if (MasterProc.and.DEBUG%BCS) write(*,*)"Finished Set_bcmap: Nbcused is ", sum(bc_used)
allocate(spc_changed2adv(num_adv_changed))
allocate(spc_changed2bgn(num_bgn_changed))
i = 0
spc_adv2changed = 0
do iem = 1, NSPEC_ADV
if(xn_adv_changed(iem))then
i = i+1
spc_changed2adv(i) = iem
spc_adv2changed(iem) = i
end if
end do
i = 0
spc_bgn2changed = 0
do iem = 1, NSPEC_BGN
if(xn_bgn_changed(iem))then
i = i+1
spc_changed2bgn(i) = iem
spc_bgn2changed(iem) = i
end if
end do
allocate(spc_used_adv(NTOT_BC,num_used_adv))
allocate(spc_used_bgn(NTOT_BC,num_used_bgn))
spc_used_adv = 0
spc_used_bgn = 0
do ibc = 1, NTOT_BC
if ( bc_used(ibc) > 0 ) then
! - set bc_adv: advected species
i = 0
do iem = 1, NSPEC_ADV
if (bc2xn_adv(ibc,iem)>0.0) then
i = i+1
spc_used_adv(ibc,i) = iem
end if
end do
! - set bc_bgn: background (prescribed) species
i = 0
do iem = 1, NSPEC_BGN
if ( bc2xn_bgn(ibc,iem) > 0.0 ) then
i = i+1
spc_used_bgn(ibc,i) = iem
end if
end do
end if ! bc_used
end do ! ibc
end subroutine Set_bcmap
subroutine GetBICData(year,month,ibc,used,bc_data,errcode)
logical, parameter :: &
DEBUG_Logan = .false., &
DEBUG_HZ = .false.
! we define some concentrations in terms of sine curves and other simple data:
type :: sineconc
real :: surf ! Mean surface conc. (ppb)
integer :: dmax ! Day when concentrations peak
real :: amp ! amplitude of surface conc. (ppb)
real :: hz ! Scale-height (km) - height to drop 1/e concentration
real :: vmin ! background, minimum conc., in vertical direction
real :: hmin ! background, minimum conc., in horiz direction
real :: conv_fac ! factor to convert input data to mixing ratio
end type sineconc
type(sineconc), save, dimension(NGLOB_BC) :: SpecBC
type :: SIAfac ! trends in boundary conditions
integer :: year
real:: so2,nox,nh4
end type SIAfac
!temporary used by BoundaryConditions
real :: O3fix=0.0
real :: trend_o3=1.0, trend_co, trend_voc
! -----------------------------------------------------------------------
! HANDLES READ_IN OF GLOBAL DATA. We read in the raw data from the
! global model, and do the vertical interpolation to EMEP k values
! here if the species is to be used.
! -----------------------------------------------------------------------
integer, intent(in) :: year ! for Mace Head correction
integer, intent(in) :: month
integer, intent(in) :: ibc ! Index of BC
integer, intent(in) :: used ! set to 1 if species wanted
real, dimension(LIMAX,LJMAX,KMAX_MID), &
intent(out) :: bc_data ! BC Data defined here
integer, intent(inout) :: errcode ! i/o number
logical, save :: first_call = .true.
integer, allocatable,dimension(:,:), save :: lat5 ! for latfunc below
real, dimension(NGLOB_BC,6:14), save :: latfunc ! lat. function
real, save :: twopi_yr, cosfac ! for time-variations
!---------------------------------------------------------------------------
! Mace Head ozone concentrations for backgroudn sectors
! from Fig 5., Derwent et al., 1998, AE Vol. 32, No. 2, pp 145-157
integer, parameter :: MH_YEAR1 = 1990, MH_YEAR2 = 2016
real, dimension(12,MH_YEAR1:MH_YEAR2), parameter :: macehead_year=reshape(&
[35.3,36.3,38.4,43.0,41.2,33.4,35.1,27.8,33.7,36.2,28.4,37.7,& !1990
36.1,38.7,37.7,45.8,38.8,36.3,29.6,33.1,33.4,35.7,37.3,36.7,& !1991
36.1,37.3,41.8,39.6,41.2,31.5,28.3,30.3,31.3,34.2,36.1,34.9,& !1992
37.6,40.4,44.4,42.6,43.4,29.2,28.5,29.6,32.2,37.3,37.3,38.3,& !1993
38.6,37.3,45.7,43.8,42.9,35.1,30.8,30.5,33.8,36.5,34.0,37.3,& !1994
37.5,37.1,41.6,42.4,41.1,33.1,29.1,28.7,33.7,34.8,35.0,36.0,& !1995
37.0,40.1,42.9,44.6,41.3,38.3,29.3,29.4,35.6,38.4,37.8,38.4,& !1996
36.2,41.9,41.8,40.4,40.6,34.4,26.2,29.3,31.3,35.2,25.7,39.5,& !1997
38.6,42.0,44.6,45.1,44.2,33.0,29.7,32.9,35.7,38.8,39.7,40.4,& !1998
39.9,44.5,49.4,45.0,42.8,34.3,29.0,30.0,31.8,36.9,39.6,39.2,& !1999
39.5,42.1,41.8,43.8,43.4,34.5,28.0,27.3,33.6,37.4,35.6,35.8,& !2000
37.3,38.0,42.2,44.8,42.6,34.9,28.9,29.4,29.9,35.3,37.3,37.5,& !2001
! Preliminary BCs generated using Mace Head CFC and other greenhouse gases
! data to define clean air masses. Data cover all of 2002 and 9 months
! of 2003. What to do for Oct-Dec 2003?
! Could use (1) 2002 data or (2) 10-year average?
! Simmonds paper would support (1), simplicity (2).
! After seeing earlier 2003 plots, chose (2).
42.4,44.4,45.5,45.0,45.9,39.8,32.5,28.7,37.7,39.3,40.5,42.3,& !2002
39.8,40.1,44.7,45.4,45.7,41.7,33.3,31.0,35.7,37.9,40.9,38.1,& !2003
40.8,42.0,48.3,46.6,39.9,31.9,32.4,32.1,33.9,36.7,40.2,39.8,& !2004
40.9,41.4,44.1,45.6,42.7,32.9,26.7,30.0,33.2,37.7,39.5,38.0,& !2005
! 2006 and 2007 are calculated with using IE31 O3 data and
! trajectory sectors (based on PARLAM-PS and HIRLAM20 met) for resp. year
39.8,42.4,44.2,48.3,41.3,39.0,31.9,29.5,34.8,37.4,41.9,39.9,& !2006
40.7,38.2,46.1,46.4,40.9,34.5,31.2,28.8,33.3,36.1,40.6,41.7,& !2007
! 2008 Mace Head correction calculated using IE31 O3 data and
! trajectory sectors (based on HIRLAM20 met) for 2008
41.0,45.1,48.0,46.3,44.2,37.1,30.8,31.3,34.3,37.5,37.9,40.0,& !2008
! 2009 to 2011 Mace Head correction calculated using IE31 O3 data and
! trajectory sectors (based on ECMWF met) for respective year
37.7,43.3,46.5,46.2,41.6,39.1,31.0,29.0,34.5,34.4,40.5,38.4,& !2009
36.8,38.9,43.9,46.4,41.7,35.5,31.0,31.3,35.6,36.7,33.4,33.8,& !2010
36.5,42.4,43.3,44.5,40.2,34.6,30.1,30.8,32.0,34.7,37.7,38.1,& !2011
35.0,40.2,41.0,46.8,43.1,34.0,29.6,33.8,34.9,33.3,37.9,38.7,& !2012
38.8,42.8,45.1,46.7,43.3,31.8,31.0,33.3,32.8,39.0,39.5,42.7,& !2013
41.4,42.9,43.5,46.4,42.4,35.1,28.6,32.6,33.8,37.1,38.1,41.1,& !2014
41.0,43.3,43.8,42.5,39.4,33.6,31.5,35.3,35.8,42.1,40.4,41.0,& !2015
40.4,42.5,43.7,43.6,42.4,29.7,27.5,28.6,32.0,37.7,40.5,42.5]& !2016
,[12,MH_YEAR2-MH_YEAR1+1])
real, dimension(12), parameter :: macehead_default=&
! Defaults from 1998-2010 average
(/39.8,41.9,45.4,46.5,43.2,36.2,30.5,30.1,34.1,37.0,39.0,38.5/)
real, dimension(12):: macehead_O3=macehead_default
!---------------------------------------------------------------------------
integer :: i, j, k, i0, i1, Nlevel_logan, Nlevel_Dust, ierror
real :: f0, f1 ! interpolation factors
character(len=30) :: fname ! input filename
character(len=99) :: txtmsg ! error messages
real,allocatable,save, dimension(:) :: p_kPa, h_km !Use of standard atmosphere
real :: scale_old, scale_new
real, parameter :: macehead_lat = 53.3 !latitude of Macehead station
real, parameter :: macehead_lon = -9.9 !longitude of Macehead station
character(len = 100) ::varname
real :: count_loc,O3fix_loc, mpi_rcv(2),mpi_snd(2)
real :: conv_fac
!----------------------------------------------------------
!Trends 1980-2003 derived from EPA emissions of so2,nox.
! nh4 derived from 2/3so3+1/3nox
!Support for SO2 can be found in Hicks, Artz, Meyer and Hosker, 2002
! Figure 7 (Eastern US) which show 'close' correspondance between national
! emissions and concentration trend
!1920-1970 BCs derived from:
! NH4: nh3 emissions
! SOx: winter ice cores, Col du dome
! NOx: winter ice cores
!1890-1920: trends from emissions for SOx,NOx,NH3, Aardenne USA
! Updated: April 2013
! - use data above to 1980, then EPA download of April 2013
! - then IIASA/ECLAIRE/ECLIPSE
type(SIAfac), dimension(37), save :: SIAtrends = (/ &
SIAfac(1890,0.12,0.15,0.44) &
,SIAfac(1900,0.18,0.20,0.48) &
,SIAfac(1910,0.27,0.27,0.52) &
,SIAfac(1920,0.32,0.33,0.59) &
,SIAfac(1930,0.35,0.33,0.55) &
,SIAfac(1940,0.46,0.25,0.59) &
,SIAfac(1950,0.59,0.33,0.69) &
,SIAfac(1960,0.76,0.50,0.76) &
,SIAfac(1970,0.95,0.75,0.90) &
,SIAfac(1980, 1.000, 1.000, 1.000)&
,SIAfac(1985, 0.899, 0.951, 0.989)&
,SIAfac(1990, 0.890, 0.943, 0.920)&