-
Notifications
You must be signed in to change notification settings - Fork 0
/
CARMA_GridComp.F90
1591 lines (1357 loc) · 60.9 KB
/
CARMA_GridComp.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
#include "MAPL_Generic.h"
!-------------------------------------------------------------------------
!NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1, GEOS/DAS!
!-------------------------------------------------------------------------
!BOP
!
! !MODULE: CARMA_GridCompMod --- CARMA Grid Component Class
!
! Grid Component class for the Community Aerosol and Radiation
! Model for Atmospheres aerosol/cloud microphysics package.
!
! !INTERFACE:
!
MODULE CARMA_GridCompMod
! !USES:
USE ESMF
USE MAPL
USE Chem_Mod
USE Chem_UtilMod
USE m_inpak90 ! Resource file management
! Utility Modules
use DryDepositionMod ! Aerosol Dry Deposition
use WetRemovalMod ! Aerosol Wet Removal
use DustEmissionMod, only: KokSizeDistribution
! CARMA Specific Methods
use carma_precision_mod
use carma_constants_mod
use carma_enums_mod
use carma_types_mod
use carmaelement_mod
use carmagroup_mod
use carmagas_mod
use carmastate_mod
use carma_mod
IMPLICIT NONE
INTEGER, PARAMETER :: DBL = KIND(0.00D+00)
! !TYPES:
PRIVATE
PUBLIC CARMA_GridComp ! The CARMA object
PUBLIC CARMA_Registry
! !PUBLIC MEMBER FUNCTIONS:
PUBLIC CARMA_GridCompInitialize
PUBLIC CARMA_GridCompRun
PUBLIC CARMA_GridCompFinalize
PRIVATE dumpGas
PRIVATE dumpElement
PRIVATE dumpGroup
!
! !DESCRIPTION:
!
! This module implements the CARMA aerosol & cloud microphysics model
!
! !REVISION HISTORY:
!
! 16Sep2003 da Silva First crack.
! 24Jan2O05 Nielsen Implementation of Code 916 chemistry
! 19Dec2005 d Silva Minor portability mods.
! 30Oct2007 Nielsen GMI Combo set up
! 18May2009 Colarco Follow GMI setup to implement CARMA
!
!EOP
!-------------------------------------------------------------------------
TYPE CARMA_GridComp
CHARACTER(LEN=255) :: name = "CARMA aerosol/cloud microphysics"
type(CARMA_Registry), pointer :: CARMAreg => null()
type(carma_type), pointer :: carma
type(Chem_Mie), pointer :: CARMAmie ! GOCART style Mie lookup tables
integer :: i1 = 1, i2, im, j1 = 1, j2, jm, km
type(ESMF_grid) :: grid
real, pointer, dimension(:,:) :: LONS, LATS
integer :: nymd_bc = 1
! Pointers to species specific emissions
! Dust
real, pointer, dimension(:,:) :: dust_source => null()
! Smoke
! Sulfate
real, pointer :: vLat(:) => null(), &
vLon(:) => null(), &
vSO2(:) => null(), &
vElev(:) => null(), &
vCloud(:) => null()
! Component derived type declarations
! -----------------------------------
! TYPE(t_Chemistry ) :: Chemistry
END TYPE CARMA_GridComp
TYPE CARMA_Registry
logical :: doing_CARMA = .false.
integer :: nq
character(len=255), pointer :: vname(:) ! variable name (groupname::elemname::XXX)
CHARACTER(LEN=255) :: rcfilen = 'CARMAchem_Registry.rc'
integer :: NBIN, NGROUP, NELEM, NSOLUTE, NGAS, NWAVE
REAL(kind=f), pointer :: RMRAT(:) =>null(), &
RMIN(:) =>null(), &
RHOP(:) =>null(), &
ESHAPE(:) =>null(), &
FSCAV(:) =>null()
INTEGER, pointer :: IGROUP(:) =>null(), &
IRHSWELL(:) =>null(), &
IRHSWCOMP(:) =>null(), &
ISHAPE(:) =>null(), &
ICOMPOSITION(:) =>null(), &
ITYPE(:) =>null()
character(len=255), pointer :: GROUPNAME(:) =>null(), &
ELEMNAME(:) =>null()
! Gases
character(len=255), pointer :: GASNAME(:) => null()
integer, pointer :: IGCOMP(:) => null(), &
IGVAPREQ(:) => null()
logical :: do_cnst_rlh = .false.
logical :: do_coag = .false. !! do coagulation?
logical :: do_detrain = .false.
logical :: do_fixedinit = .false.
logical :: do_grow = .false. !! do nucleation, growth and evaporation?
logical :: do_incloud = .false.
logical :: do_explised = .false.
logical :: do_print_init = .false.
logical :: do_substep = .false. !! do substepping
logical :: do_thermo = .false. !! do thermodynamics
logical :: do_vdiff = .false. !! do Brownin diffusion
logical :: do_vtran = .false. !! do sedimentation
real(kind=f) :: vf_const = 0._f !! if specified and non-zero, constant
!! fall velocity for all particles [cm/s]
integer :: minsubsteps = 1 !! minimum number of substeps, default = 1
integer :: maxsubsteps = 32 !! maximum number of substeps, default = 32
integer :: maxretries = 16 !! maximum number of substep retries, default = 16
real(kind=f) :: conmax = 0.1_f !! minimum relative concentration to
!! consider, default = 1e-1
! Species specific information
integer :: igrp_mixed = -1 !! mixed group
integer :: mixedcorecomp = -1 !! mixed core element (sulfate)
integer :: igrp_sulfate = -1 !! sulfate group
integer :: ielm_sulfate = -1 !! sulfate pc element
integer :: igrp_dust = -1 !! dust group
integer :: ielm_dust = -1 !! dust pc element
integer :: igrp_seasalt = -1 !! seasalt group
integer :: ielm_seasalt = -1 !! seasalt pc element
integer :: igrp_smoke = -1 !! smoke group
integer :: ielm_smoke = -1 !! smoke pc element
integer :: igrp_black_carbon = -1 !! black carbon group
integer :: ielm_black_carbon = -1 !! black carbon pc element
integer :: igrp_ash = -1 !! ash group
integer :: ielm_ash = -1 !! ash pc element
integer :: ielm_mxpc = -1 !! mixed group pc element
integer :: ielm_mxsulfate= -1 !! mixed group sulfate core element
integer :: ielm_mxdust = -1 !! mixed group dust core element
integer :: ielm_mxsmoke = -1 !! mixed group smoke core element
integer :: ielm_mxseasalt= -1 !! mixed group seasalt core element
integer :: ielm_mxbc = -1 !! mixed group black carbon core element
integer :: ielm_mxash = -1 !! mixed group ash core element
integer :: igas_h2o = -1 !! water vapor
integer :: igas_h2so4 = -1 !! sulfuric acid gas
integer :: igas_hno3 = -1 !! nitric acid gas
integer :: ifallrtn = 1 !! default fall velocity routine for particles
! Dust
real :: dust_emissions_fudgefactor
real, pointer :: dmass_dust(:) => null() !! dust emission size distribution
! Sea Salt
real :: seasalt_emissions_fudgefactor
! Smoke
real :: organic_matter_to_organic_carbon_ratio
real :: fraction_terpene_to_organic_carbon
! Black Carbon
! Sulfate
character(len=255) :: sulfuric_acid_source
! GOCART-style Mie Lookup Tables
integer :: nchannels, nmoments
real, pointer :: channels(:)
character(len=255) :: du_optics_file
character(len=255) :: ss_optics_file
character(len=255) :: bc_optics_file
character(len=255) :: sm_optics_file
character(len=255) :: su_optics_file
! Workspace for any requested point emissions
! Sulfate
logical :: doing_point_emissions_sulfate=.FALSE. ! Providing pointwise emissions
character(len=255) :: point_emissions_srcfilen_sulfate ! filename for pointwise emissions
integer :: nPts_sulfate = -1
integer, pointer, dimension(:) :: vstart_sulfate => null(), &
vend_sulfate => null()
real, pointer, dimension(:) :: vLat_sulfate => null(), &
vLon_sulfate => null(), &
vBase_sulfate => null(), &
vTop_sulfate => null(), &
vEmis_sulfate => null()
! Ash
logical :: doing_point_emissions_ash=.FALSE. ! Providing pointwise emissions
character(len=255) :: point_emissions_srcfilen_ash ! filename for pointwise emissions
integer :: nPts_ash = -1
integer, pointer, dimension(:) :: vstart_ash => null(), &
vend_ash => null()
real, pointer, dimension(:) :: vLat_ash => null(), &
vLon_ash => null(), &
vBase_ash => null(), &
vTop_ash => null(), &
vEmis_ash => null()
! Dust
logical :: doing_point_emissions_dust=.FALSE. ! Providing pointwise emissions
character(len=255) :: point_emissions_srcfilen_dust ! filename for pointwise emissions
integer :: nPts_dust = -1
integer, pointer, dimension(:) :: vstart_dust => null(), &
vend_dust => null()
real, pointer, dimension(:) :: vLat_dust => null(), &
vLon_dust => null(), &
vBase_dust => null(), &
vTop_dust => null(), &
vEmis_dust => null()
END TYPE CARMA_Registry
CONTAINS
!-------------------------------------------------------------------------
!NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1, GEOS/DAS!
!-------------------------------------------------------------------------
!BOP
!
! !IROUTINE: CARMA_GridCompInitialize --- Initialize CARMA_GridComp
!
! !INTERFACE:
!
SUBROUTINE CARMA_GridCompInitialize( gcCARMA, impChem, expChem, nymd, nhms, cdt, &
rc )
IMPLICIT none
INTEGER, PARAMETER :: DBL = KIND(0.00D+00)
! !INPUT PARAMETERS:
INTEGER, INTENT(IN) :: nymd, nhms ! Time from AGCM
REAL, INTENT(IN) :: cdt ! Chemistry time step (secs)
! !OUTPUT PARAMETERS:
TYPE(CARMA_GridComp), INTENT(INOUT) :: gcCARMA ! Grid Component
TYPE(ESMF_State), INTENT(INOUT) :: impChem ! Import State
TYPE(ESMF_State), INTENT(INOUT) :: expChem ! Export State
INTEGER, INTENT(out) :: rc ! Error return code:
! 0 - all is well
! 1 -
! !DESCRIPTION: Initializes the CARMA Grid Component. It primarily sets
! the import state.
!
! !REVISION HISTORY:
!
! 18Sep2003 da Silva First crack.
! 30Jun2007 Nielsen GMI Combo set up
! 18May2009 Colarco Adapt to use for CARMA
!
!EOP
!-------------------------------------------------------------------------
CHARACTER(LEN=*), PARAMETER :: IAm = 'CARMA_GridCompInitialize'
CHARACTER(LEN=255) :: rcfilen = 'CARMAchem_Registry.rc'
CHARACTER(LEN=255) :: string
INTEGER :: ios, n
INTEGER, ALLOCATABLE :: ier(:)
INTEGER :: i, i1, i2, ic, im, j, j1, j2, jm, km
INTEGER :: nbins, n1, n2
INTEGER :: STATUS
INTEGER :: NBIN, NGROUP, NELEM, NSOLUTE, NWAVE, NGAS
REAL(kind=f), allocatable :: rmrat(:), rmin(:), rhop(:), &
eshape(:), ishape(:), &
radius_(:), rlow_(:), rup_(:), &
rhod_(:), rhog_(:)
real, allocatable :: radius(:), rlow(:), rup(:)
REAL(kind=f) :: gwtmol
REAL :: rhod, rhog
INTEGER, allocatable :: IGROUP(:)
character(len=255) :: groupname, elemname, gasname
type(carmagroup_type) :: cgroup
type(carmaelement_type) :: celement
type(carmastate_type), allocatable :: cstate(:)
logical :: do_coag = .false. !! do coagulation?
logical :: do_grow = .false. !! do nucleation, growth and evaporation?
logical :: do_implised = .false. !! do sedimentation with substepping
logical :: do_substep = .false. !! do substepping
logical :: do_thermo = .false. !! do thermodynamics
logical :: do_vdiff = .false. !! do Brownin diffusion
logical :: do_vtran = .false. !! do sedimentation
logical :: is_sulfate = .false. !! special handling for sulfate aerosol case
real(kind=f) :: vf_const = 0._f !! if specified and non-zero, constant fall velocity for all particles [cm/s]
integer :: minsubsteps = 1 !! minimum number of substeps, default = 1
integer :: maxsubsteps = 1 !! maximum number of substeps, default = 1
integer :: maxretries = 5 !! maximum number of substep retries, default = 5
real(kind=f) :: conmax = 0.1_f !! minimum relative concentration to consider, default = 1e-1
type(CARMA_Registry), pointer :: reg => null()
type(carma_type), pointer :: r => null()
! This is for initializing condensed H2O to zero, for now
! -------------------------------------------------------
REAL, ALLOCATABLE :: h2ocond(:,:,:)
REAL, ALLOCATABLE :: cellArea(:,:)
reg => gcCARMA%CARMAreg
gcCARMA%name = 'CARMA aerosol/cloud microphysics'
! Initialize local variables
! --------------------------
rc = 0
CALL init_()
IF ( rc /= 0 ) RETURN
ier(:)=0
!! Check on the parameters and if they agree with the Chem_Registry
!! ----------------------------------------------------------------
!! n_CARMA = NELEM*NBIN + NGAS
! if(nbins .ne. (nbin*nelem + ngas) ) then
! call final_(25)
! return
! endif
! Establish the CARMA structure
! -----------------------------
allocate(gcCARMA%carma, stat=ios)
if(ios /= 0) then
call final_(103)
return
endif
if(MAPL_AM_I_ROOT()) then
call CARMA_Create(gcCARMA%carma, reg%NBIN, reg%NELEM, reg%NGROUP, &
reg%NSOLUTE, reg%NGAS, reg%NWAVE, rc, &
LUNOPRT=6)
else
call CARMA_Create(gcCARMA%carma, reg%NBIN, reg%NELEM, reg%NGROUP, &
reg%NSOLUTE, reg%NGAS, reg%NWAVE, rc )
endif
if (rc /=0) then
call final_(rc)
return
endif
r => gcCARMA%carma
! Establish the groups
! --------------------
! NOTE: Hard coded optionals and parameters here
do j = 1, reg%NGROUP
is_sulfate = .false.
! Assumes MIXEDP has sulfate as PC
if( ESMF_UtilStringUpperCase(trim(reg%groupname(j))) == 'SULFATE' .or. &
ESMF_UtilStringUpperCase(trim(reg%groupname(j))) == 'MIXEDP' ) is_sulfate = .true.
if(reg%ishape(j) .eq. 1) then
reg%ifallrtn = I_FALLRTN_STD
else
reg%ifallrtn = I_FALLRTN_STD_SHAPE
endif
call CARMAGROUP_Create(r, j, reg%groupname(j), reg%rmin(j), reg%rmrat(j), &
reg%ishape(j), reg%eshape(j), .FALSE., rc, ifallrtn=reg%ifallrtn, &
irhswell=reg%irhswell(j), irhswcomp=reg%irhswcomp(j), is_sulfate=is_sulfate)
if(rc /=0) then
call final_(rc)
return
endif
end do
! Establish the elements
! ----------------------
! NOTE: Hard coded optionals and parameters here
do i = 1, reg%NELEM
call CARMAELEMENT_Create(r, i, reg%igroup(i), &
reg%elemname(i), reg%rhop(i), reg%itype(i), reg%icomposition(i), rc)
if(rc /=0) then
call final_(rc)
return
endif
end do
! Establish the gases
! -------------------
do i = 1, reg%NGAS
select case (reg%igcomp(i))
case (1)
gwtmol = WTMOL_H2O
case (2)
gwtmol = WTMOL_H2SO4
case (3)
gwtmol = WTMOL_SO2
case (4)
gwtmol = WTMOL_HNO3
case default
print *, 'Unknown gas IGCOMP from CARMAchem_Registry.rc for gas ',i
call final_(-100)
return
end select
call CARMAGAS_Create(r, i, reg%gasname(i), &
gwtmol, reg%igvapreq(i), reg%igcomp(i), rc, ds_threshold=-0.2_f)
if(rc /=0) then
call final_(rc)
return
endif
end do
! Check the group/element/gas names and assign some indices
! ---------------------------------------------------------
! Look for pure groups, mixed group, and sulfuric acid gas
do i = 1, reg%NELEM
j = reg%igroup(i)
groupname = ESMF_UtilStringUpperCase(trim(reg%groupname(j)))
elemname = ESMF_UtilStringUpperCase(trim(reg%elemname(i)))
if(groupname == 'SULFATE') then
reg%igrp_sulfate = j
if(elemname == 'PC') reg%ielm_sulfate = i
endif
if(groupname == 'DUST') then
reg%igrp_dust = j
if(elemname == 'PC') reg%ielm_dust = i
endif
if(groupname == 'SEASALT') then
reg%igrp_seasalt = j
if(elemname == 'PC') reg%ielm_seasalt = i
endif
if(groupname == 'SMOKE') then
reg%igrp_smoke = j
if(elemname == 'PC') reg%ielm_smoke = i
endif
if(groupname == 'BLACK_CARBON') then
reg%igrp_black_carbon = j
if(elemname == 'PC') reg%ielm_black_carbon = i
endif
if(groupname == 'ASH') then
reg%igrp_ash = j
if(elemname == 'PC') reg%ielm_ash = i
endif
! Mixed group may contain sulfate element
if(groupname == 'MIXEDP') then
reg%igrp_mixed = j
if(elemname == 'PC') reg%ielm_mxpc = i
if(elemname == 'SULFATE') reg%ielm_mxsulfate = i
if(elemname == 'DUST') reg%ielm_mxdust = i
if(elemname == 'SEASALT') reg%ielm_mxseasalt = i
if(elemname == 'SMOKE') reg%ielm_mxsmoke = i
if(elemname == 'ASH') reg%ielm_mxash = i
if(elemname == 'BLACK_CARBON') reg%ielm_mxbc = i
endif
end do
do i = 1, reg%NGAS
gasname = ESMF_UtilStringUpperCase(trim(reg%gasname(i)))
if(gasname == 'H2SO4') reg%igas_h2so4 = i
if(gasname == 'H2O' ) reg%igas_h2o = i
if(gasname == 'HNO3' ) reg%igas_hno3 = i
end do
! NEED:
! Hooks to CARMA_Solute
! Setup Growth/Nucleation
! -----------------------
! Check that growth is correctly implemented based on elements/gases
if(reg%do_grow) then
if(reg%igrp_sulfate < 0 .or. reg%ielm_sulfate < 0 .or. &
reg%igas_h2so4 < 0 .or. reg%igas_h2o < 0 ) then
reg%do_grow = .false.
print *, 'Not set up correctly for growth; do_grow set false'
endif
endif
if(reg%do_grow) then
! Pure sulfate group
call CARMA_AddGrowth(r, reg%ielm_sulfate, reg%igas_h2so4, rc)
if(rc /=0) then
call final_(rc)
return
endif
! Add growth to the sulfate element of the mixed group (which is nominally
! the particle concentration element)
if(reg%ielm_mxsulfate > 0) then
call CARMA_AddGrowth(r, reg%ielm_mxsulfate, reg%igas_h2so4, rc)
if(rc /=0) then
call final_(rc)
return
endif
endif
! Add nucleation
call CARMA_AddNucleation(r, reg%ielm_sulfate, reg%ielm_sulfate, &
I_HOMNUC, 0._f, rc, igas=reg%igas_h2so4)
if(reg%igrp_mixed > 0) then
if(reg%ielm_dust > 0 .and. reg%ielm_mxdust > 0) &
call CARMA_AddNucleation(r, reg%ielm_dust, reg%ielm_mxdust, &
I_HETNUCSULF, 0._f, rc, igas=reg%igas_h2so4, &
ievp2elem=reg%ielm_dust)
if(reg%ielm_smoke > 0 .and. reg%ielm_mxsmoke > 0) &
call CARMA_AddNucleation(r, reg%ielm_smoke, reg%ielm_mxsmoke, &
I_HETNUCSULF, 0._f, rc, igas=reg%igas_h2so4, &
ievp2elem=reg%ielm_smoke)
if(reg%ielm_seasalt > 0 .and. reg%ielm_mxseasalt > 0) &
call CARMA_AddNucleation(r, reg%ielm_seasalt, reg%ielm_mxseasalt, &
I_HETNUCSULF, 0._f, rc, igas=reg%igas_h2so4, &
ievp2elem=reg%ielm_seasalt)
endif
if(rc /=0) then
call final_(rc)
return
endif
endif
! Setup Coagulation
! --------------------
! We set up self coagulation for pure SULFATE and SMOKE groups.
! If there is MIXEDP we allow coagulation of SULFATE with MIXEDP
if(reg%do_coag) then
do i = 1, reg%NELEM
j = reg%igroup(i)
groupname = ESMF_UtilStringUpperCase(trim(reg%groupname(j)))
elemname = ESMF_UtilStringUpperCase(trim(reg%elemname(i)))
if(groupname == 'MIXEDP' .and. elemname == 'SULFATE') reg%mixedcorecomp = reg%icomposition(i)
! This block adds the self coagulation of the pure sulfate group and the
! coagulation of the pure sulfate to the mixed group.
if( groupname == 'SULFATE' ) then
call CARMA_AddCoagulation(r, j, j, j, I_COLLEC_FUCHS, rc )
if(reg%igrp_mixed > 0 .AND. reg%icomposition(i) == reg%mixedcorecomp) then
call CARMA_AddCoagulation(r, j, reg%igrp_mixed, reg%igrp_mixed, I_COLLEC_FUCHS, rc )
endif
endif
if( groupname == 'SMOKE' ) call CARMA_AddCoagulation(r, j, j, j, I_COLLEC_FUCHS, rc )
if(rc /=0) then
call final_(rc)
return
endif
end do
endif
! Initialize CARMA
! ----------------
call CARMA_Initialize(r, rc, &
do_cnst_rlh=reg%do_cnst_rlh, do_coag=reg%do_coag, &
do_detrain=reg%do_detrain, do_fixedinit=reg%do_fixedinit, &
do_grow=reg%do_grow, do_incloud=reg%do_incloud, &
do_explised=reg%do_explised, do_print_init=reg%do_print_init, &
do_substep=reg%do_substep, &
do_thermo=reg%do_thermo, do_vdiff=reg%do_vdiff, &
do_vtran=reg%do_vtran, vf_const=reg%vf_const, conmax=reg%conmax, &
minsubsteps=reg%minsubsteps, maxsubsteps=reg%maxsubsteps, &
maxretries=reg%maxretries, dt_threshold=1._f )
! Get the dust emissions size fraction
! -----------------------
! Look for dust aerosol group / element
do i = 1, reg%NELEM
j = reg%igroup(i)
groupname = ESMF_UtilStringUpperCase(trim(reg%groupname(j)))
if(groupname == 'DUST' .OR. ESMF_UtilStringUpperCase(trim(reg%elemname(i))) == 'DUST') then
allocate(radius_(reg%NBIN), rlow_(reg%NBIN), rup_(reg%NBIN), __STAT__)
allocate(radius(reg%NBIN), rlow(reg%NBIN), rup(reg%NBIN), __STAT__)
allocate(rhod_(reg%NBIN), rhog_(reg%NBIN), __STAT__)
call CARMAGroup_Get(r, j, rc, r=radius_, rlow=rlow_, rup=rup_)
radius = radius_ / 100. ! go from CARMA cm -> m
rlow = rlow_ / 100.
rup = rup_ / 100.
call CARMAElement_Get(r, i, rc, rho=rhod_)
call CARMAElement_Get(r, r%f_group(j)%f_ienconc, rc, rho=rhog_)
rhod = rhod_(1) * 1000. ! go from CARMA to MKS
rhog = rhog_(1) * 1000. ! go from CARMA to MKS
call KokSizeDistribution(radius, rlow, rup, reg%dmass_dust, rhod=rhod, rhog=rhog)
deallocate(radius, rlow, rup, radius_, rlow_, rup_, rhod_, rhog_, __STAT__)
endif
enddo
! Print information
! -----------------
IF( MAPL_AM_I_ROOT() ) THEN
call dumpGroup(r, rc)
if(rc /=0) then
call final_(104)
return
endif
call dumpElement(r, rc)
if(rc /=0) then
call final_(105)
return
endif
END IF
!! Housekeeping
!! ------------
! deallocate ( r, stat=ios )
! if ( ios /= 0) then
! call final_(200)
! return
! endif
! ier(:)=0
RETURN
CONTAINS
SUBROUTINE init_()
INTEGER :: ios, n
n=128
ios=0
ALLOCATE ( ier(n), stat=ios )
IF ( ios /= 0 ) rc = 100
END SUBROUTINE init_
SUBROUTINE final_(ierr)
INTEGER :: ios, ierr
DEALLOCATE ( r, ier, stat=ios )
CALL I90_release()
rc = ierr
END SUBROUTINE final_
!-------------------------------------------------------------------------
!NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1, GEOS/DAS!
!-------------------------------------------------------------------------
!BOP
!
! !ROUTINE: TFQuery: Find whether a token in T or F.
!
! !INTERFACE:
!
LOGICAL FUNCTION TFQuery(string,fn)
! !USES:
IMPLICIT NONE
! !INPUT PARAMETERS:
CHARACTER(LEN=*), INTENT(IN) :: string, fn
! !OUTPUT PARAMETERS:
! !DESCRIPTION: Return the value (T or F) of a particular token (string)
! in the file fn.
! !REVISION HISTORY:
!
! 15 Aug 2007 Nielsen First version.
!EOP
!-------------------------------------------------------------------------
CHARACTER(LEN=8) :: tOrF
INTEGER :: rc
rc = 0
tOrF = ' '
TFQuery = .FALSE.
CALL I90_label ( TRIM(string), rc )
IF(rc .NE. 0) THEN
PRINT *,'Could not find ',TRIM(string),' in ',TRIM(fn)
CALL final_(99)
END IF
CALL I90_Gtoken( tOrF, rc )
IF(TRIM(tOrF) == 'T' .OR. TRIM(tOrF) == 't' .OR. &
TRIM(tOrF) == 'TRUE' .OR. TRIM(tOrF) == 'true') TFQuery = .TRUE.
END FUNCTION TFQuery
!-------------------------------------------------------------------------
!NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1, GEOS/DAS!
!-------------------------------------------------------------------------
!BOP
!
! !ROUTINE: setmcor: Find area of tiles.
!
! !INTERFACE:
!
SUBROUTINE setmcor(i1,i2,j1,j2,im,jm,lats,cellArea)
! !USES:
IMPLICIT NONE
! !INPUT PARAMETERS:
INTEGER, INTENT(IN) :: i1,i2,j1,j2,im,jm
REAL, INTENT(IN) :: lats(i1:i2,j1:j2) !radians
! !OUTPUT PARAMETERS:
REAL, INTENT(OUT) :: cellArea(i1:i2,j1:j2) !m^2
! !DESCRIPTION: Find the horizontal surface area (m^2) of each cell.
! In testing with 8-byte words, the total surface area
! was 4.0000508 PI R^2.
! !REVISION HISTORY:
! 15 Aug 2007 Nielsen First version.
!EOP
!-------------------------------------------------------------------------
REAL, PARAMETER :: ae=6.371E+06
INTEGER :: i,j
REAL :: scale,dlat,f,arg,err,pi
err=1.00E-05
pi=4.00*ATAN(1.00)
dlat=pi/FLOAT(jm-1)
scale = 2.00*pi*ae*ae/FLOAT(im)
DO j=j1,j2
DO i=i1,i2
! South pole
IF( lats(i,j) < -0.50*pi+err ) THEN
f=0.25
arg=0.50*(lats(i,j)+lats(i,j+1))
! North pole
ELSE IF( lats(i,j) > 0.50*pi-err ) THEN
f=0.25
arg=0.50*(lats(i,j-1)+lats(i,j))
! Interior
ELSE
f=1.00
arg=lats(i,j)
END IF
cellArea(i,j)=scale*dlat*f*cos(arg)
END DO
END DO
RETURN
END SUBROUTINE setmcor
END SUBROUTINE CARMA_GridCompInitialize
!-------------------------------------------------------------------------
!NASA/GSFC, Global Modeling and Assimilation Office, Code 610.1, GEOS/DAS!
!-------------------------------------------------------------------------
!BOP
!
! !ROUTINE: CARMA_GridCompRun --- The CARMA Driver
!
! !INTERFACE:
!
SUBROUTINE CARMA_GridCompRun ( gcCARMA, qa, impChem, expChem, nymd, nhms, &
cdt, rc )
IMPLICIT none
! !INPUT/OUTPUT PARAMETERS:
TYPE(CARMA_GridComp), INTENT(INOUT) :: gcCARMA ! Grid Component
TYPE(Chem_Array), pointer :: qa(:) ! tracer array will go here
! !INPUT PARAMETERS:
TYPE(ESMF_State), INTENT(INOUT) :: impChem ! Import State
INTEGER, INTENT(IN) :: nymd, nhms ! time
REAL, INTENT(IN) :: cdt ! chemical timestep (secs)
! !OUTPUT PARAMETERS:
TYPE(ESMF_State), INTENT(INOUT) :: expChem ! Export State
INTEGER, INTENT(OUT) :: rc ! Error return code:
! 0 - all is well
! 1 -
! !DESCRIPTION: This routine implements the CARMA driver
!
! !IMPLEMENTATION NOTES:
!
! No pointer is reservered in the export state for deposition of water.
!
! !REVISION HISTORY:
!
! 18Sep2003 da Silva First crack.
! 24Jan2005 Nielsen Implementation of Code 916 chemistry
! 30Oct2007 Nielsen Implementation of GMI cmbined
! stratosphere/troposphere chemistry
! 12Aug2009 Colarco First crack at CARMA run method
!
!EOP
!-------------------------------------------------------------------------
CHARACTER(LEN=*), PARAMETER :: IAm = 'CARMA_GridCompRun'
INTEGER :: STATUS
! Input fields from GEOS-5
! ------------------------
REAL, POINTER, DIMENSION(:,:,:) :: p, ple, rhoa, tmpu, zc, zl, q, zle, &
rh, u, v, su_nuc, &
zsubsteps, sath2so4, su_sareav, &
su_sarea, su_numd, su_reff, &
du_sarea, du_numd, du_reff, &
ash_sarea, ash_numd, ash_reff, &
ss_sarea, ss_numd, ss_reff, &
sm_sarea, sm_numd, sm_reff, &
mx_sarea, mx_numd, mx_reff, &
su_mass, hno3, h2so4
REAL, POINTER, DIMENSION(:,:) :: gwettop, fraclake, oro, u10m, v10m, &
ustar, pblh, z0h, shflux, precc, precl, &
substeps, retries
real, pointer, dimension(:,:) :: du_sed, su_sed, ss_sed, bc_sed, ash_sed, sm_sed, &
mxdu_sed, mxsu_sed, mxss_sed, mxbc_sed, mxash_sed, mxsm_sed
type(Chem_Array), pointer :: suvf(:), mxvf(:)
! Local
! -----
INTEGER :: i, i1, i2, ic, ier(512), im, ijl, ios
INTEGER :: j, j1, j2, jm
INTEGER :: ielem, ibin, igrp, igas
INTEGER :: k, km, kReverse
INTEGER :: n, n2, nbegin, nend, nCARMABegin, nCARMAEnd
INTEGER :: nymd1, nhms1
INTEGER :: substep_int, last_sub
real(kind=f) :: retry_real, last_ret
logical :: rootproc
real(kind=f) :: dtime
character(len=ESMF_MAXSTR) :: binstr
INTEGER, PARAMETER :: ToCARMA = 1
INTEGER, PARAMETER :: FromCARMA = -1
! We are using the CARMA constants here (CGS units) but need
! MKS values to go back to GEOS-5
REAL, PARAMETER :: grav_mks = grav/100.
integer :: igroup
CHARACTER(LEN=255) :: groupname, elemname, gasname
REAL :: qmax,qmin
real(kind=f) :: lon, lat
real(kind=f), allocatable :: xc(:), dx(:), yc(:), dy(:)
real(kind=f), allocatable :: p_(:), ple_(:), tmpu_(:), zc_(:), zl_(:), &
q_(:), rh_(:), nuc_(:), sarea_(:), numd_(:), &
r_wet_(:), reff_num(:), reff_den(:), vf_(:), &
zsubsteps_(:)
real(kind=f), allocatable :: satice_(:,:), satliq_(:,:), told_(:), gasold_(:,:)
real(kind=f) :: dq_
type(carmastate_type) :: cstate
type(carma_type), pointer :: r => null()
type(CARMA_Registry), pointer :: reg => null()
character(len=255) :: string
! For a reference atmosphere we'll choose some values
real, parameter, dimension(73) :: pleRef = &
(/ 1, 2, 3, 4, 6, 8, 11, 15, 21, 27, 36, 47, 61, 79, 101, 130, &
165, 208, 262, 327, 407, 504, 621, 761, 929, 1127, 1364, 1645, &
1979, 2373, 2836, 3381, 4017, 4764, 5638, 6660, 7851, 9236, &
10866, 12783, 15039, 17693, 20792, 24398, 28606, 33388, 37003, &
40612, 44214, 47816, 51405, 54997, 58584, 62170, 65769, 68147, &
70540, 72931, 75313, 77711, 79623, 81046, 82485, 83906, 85344, &
86765, 88201, 89636, 91071, 92516, 93921, 95376, 100000 /)
real, parameter, dimension(72) :: tmpuRef = &
(/ 219, 221, 223, 228, 230, 230, 232, 238, 245, 253, 259, 263, &
264, 262, 258, 253, 247, 239, 233, 229, 227, 227, 226, 223, &
222, 221, 220, 219, 218, 217, 216, 215, 214, 213, 212, 212, &
214, 214, 216, 219, 219, 210, 210, 218, 227, 234, 240, 245, &
250, 254, 257, 260, 262, 263, 265, 266, 267, 268, 269, 270, &
270, 270, 270, 270, 271, 271, 271, 270, 267, 265, 266, 266 /)
real, parameter, dimension(72) :: rhRef = 1e-6 * &
(/ 1, 2, 2, 2, 3, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 6, 18, 51, &
129, 267, 394, 502, 682, 1135, 1603, 2076, 2820, 3792, 5120, &
6806, 8912, 11597, 15397, 20386, 28168, 29755, 28748, 33875, &
34058, 28657, 43458, 401856, 947266, 932618, 902344, 657227, &
371583, 203370, 235108, 317872, 413086, 511719, 691407, 686524, &
601563, 456055, 475098, 626954, 590821, 483399, 380860, 297852, &
230958, 183594, 144288, 111084, 96558, 136963, 369629, 770508, &
793946, 799805 /)
ier(:) = 0
! Short-hand to object
r => gcCARMA%carma
reg => gcCARMA%CARMAreg
! Grid specs from Chem_Bundle%grid
! --------------------------------
rc = 0
i1 = gcCARMA%i1
i2 = gcCARMA%i2
im = gcCARMA%im
j1 = gcCARMA%j1
j2 = gcCARMA%j2
jm = gcCARMA%jm
km = gcCARMA%km
ijl = (i2-i1+1)*(j2-j1+1)
dtime = cdt
! Location of species from Chem_Bundle%registry.
! ----------------------------------------------
nCARMABegin = 1
nCARMAEnd = gcCARMA%CARMAreg%nq
rootProc=.FALSE.
IF( MAPL_AM_I_ROOT() ) THEN
rootProc=.TRUE.
END IF
! Allocate
! --------
allocate(p(i1:i2,j1:j2,km), __STAT__ )
allocate(xc(km), dx(km), yc(km), dy(km), &
p_(km), ple_(km+1), tmpu_(km), zc_(km), zl_(km+1), &
q_(km), rh_(km), nuc_(km), sarea_(km), numd_(km), &
r_wet_(km), reff_num(km), reff_den(km), vf_(km+1), &
zsubsteps_(km), __STAT__ )
allocate(told_(km), gasold_(km,reg%NGAS), satice_(km,reg%NGAS), satliq_(km,reg%NGAS), __STAT__ )
! Get Imports
! -----------
call MAPL_GetPointer ( impChem, rhoa, 'AIRDENS', __RC__)
call MAPL_GetPointer ( impChem, ple, 'PLE', __RC__)
call MAPL_GetPointer ( impChem, zle, 'ZLE', __RC__)
call MAPL_GetPointer ( impChem, q, 'Q', __RC__)
call MAPL_GetPointer ( impChem, rh, 'RH2', __RC__)
call MAPL_GetPointer ( impChem, tmpu, 'T', __RC__)
call MAPL_GetPointer ( impChem, ustar, 'USTAR', __RC__)
call MAPL_GetPointer ( impChem, fraclake, 'FRLAKE', __RC__)
call MAPL_GetPointer ( impChem, gwettop, 'WET1', __RC__)
call MAPL_GetPointer ( impChem, u10m, 'U10M', __RC__)
call MAPL_GetPointer ( impChem, v10m, 'V10M', __RC__)
call MAPL_GetPointer ( impChem, pblh, 'ZPBL', __RC__)
call MAPL_GetPointer ( impChem, z0h, 'Z0H', __RC__)
call MAPL_GetPointer ( impChem, shflux, 'SH', __RC__)
call MAPL_GetPointer ( impChem, precl, 'NCN_PRCP', __RC__)
call MAPL_GetPointer ( impChem, precc, 'CN_PRCP', __RC__)
call MAPL_GetPointer ( impChem, oro, 'LWI', __RC__)
call MAPL_GetPointer ( impChem, u, 'U', __RC__)
call MAPL_GetPointer ( impChem, v, 'V', __RC__)
call MAPL_GetPointer ( impChem, hno3, 'CARMA_HNO3', notFoundOK=.TRUE., __RC__)
call MAPL_GetPointer ( impChem, h2so4, 'CARMA_H2SO4', notFoundOK=.TRUE., __RC__)
! Fill the internal state with direct gas species from GMI
! Expectation is species are in VMR and needed in MMR for CARMA
! -----------
if(reg%sulfuric_acid_source(1:10) == 'full_field' .and. reg%NGAS > 0) then
do igas = 1, reg%NGAS
n = nCARMAbegin + reg%NBIN*reg%NELEM - 1 + igas
gasname = ESMF_UtilStringUpperCase(reg%gasname(igas))
if(gasname == 'H2SO4') then
if(associated(h2so4)) qa(n)%data3d = h2so4*WTMOL_H2SO4/WTMOL_AIR
endif
if(gasname == 'HNO3' ) then
if(associated(hno3)) qa(n)%data3d = hno3 *WTMOL_HNO3 /WTMOL_AIR
endif
enddo
endif
! Get Exports
! -----------
! Mixed Group
call MAPL_GetPointer(expChem, mx_sarea, 'CARMA_MXSAREA', __RC__)
call MAPL_GetPointer(expChem, mx_numd, 'CARMA_MXNUMD', __RC__)
call MAPL_GetPointer(expChem, mx_reff, 'CARMA_MXREFF', __RC__)
! Dust
call MAPL_GetPointer(expChem, du_sed, 'CARMA_DUSD', __RC__)