-
Notifications
You must be signed in to change notification settings - Fork 27
/
GCHPctmEnv_GridCompMod.F90
1141 lines (1014 loc) · 42.4 KB
/
GCHPctmEnv_GridCompMod.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"
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !MODULE: GCHPctmEnv_GridCompMod
!
! !DESCRIPTION: Cinderella component to compute derived variables to pass to
! advection
!\\
!\\
! !INTERFACE:
!
module GCHPctmEnv_GridComp
!
! !USES:
!
use ESMF
use MAPL_Mod
use FV_StateMod, only : fv_computeMassFluxes, fv_getVerticalMassFlux
use GEOS_FV3_UtilitiesMod, only : A2D2C
use m_set_eta, only : set_eta
use pFlogger, only: logging, Logger
implicit none
private
!
! !PUBLIC MEMBER FUNCTIONS:
!
public :: SetServices
!
! !PRIVATE MEMBER FUNCTIONS:
!
private :: Initialize
private :: Run
private :: prepare_ple_exports
private :: prepare_sphu_export
private :: prepare_massflux_exports
private :: calculate_ple
!
! !PUBLIC DATA MEMBERS:
!
logical, public :: import_mass_flux_from_extdata = .false.
!
! !PRIVATE DATA MEMBERS:
!
integer, parameter :: r8 = 8
integer, parameter :: r4 = 4
logical :: meteorology_vertical_index_is_top_down
integer :: use_total_air_pressure_in_advection
integer :: correct_mass_flux_for_humidity
class(Logger), pointer :: lgr => null()
!
! !REMARKS:
! This file was adapted from a GEOS file developed at NASA GMAO.
! .
! NOTES:
! - The abbreviation "PET" stands for "Persistent Execution Thread".
! It is a synomym for CPU.
!
! !REVISION HISTORY:
! 06 Dec 2009 - A. da Silva - Initial version this file was adapted from
! 08 Sep 2014 - M. Long - Modification to calculate pressure at vertical
! grid edges from hybrid coordinates
! 24 Jan 2019 - E. Lundgren - Modification for compatibility with ESMF v7.1.0r
! See https://github.com/geoschem/geos-chem for history since GCHP version 12.5
!
!EOP
!------------------------------------------------------------------------------
!BOC
contains
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !IROUTINE: SetServices -- Sets ESMF services for this component
!
! !INTERFACE:
!
subroutine SetServices(GC, RC)
!
! !INPUT/OUTPUT PARAMETERS
!
type(ESMF_GridComp), intent(INOUT) :: GC ! gridded component
!
! !OUTPUT PARAMETERS
!
integer, intent(OUT) :: RC ! return code
!
! !DESCRIPTION:
! The SetServices for the CTM needs to register its Initialize and Run.
! It uses the MAPL_Generic construct for defining state specs.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: STATUS
type(ESMF_Config) :: CF
character(len=ESMF_MAXSTR) :: COMP_NAME, msg
character(len=ESMF_MAXSTR) :: IAm = 'SetServices'
!================================
! SetServices starts here
!================================
! Get gridded component name and set-up traceback handle
! -----------------------------------------------------------------
call ESMF_GridCompGet(GC, NAME=COMP_NAME, CONFIG=CF, RC=STATUS)
_VERIFY(STATUS)
Iam = trim(COMP_NAME) // TRIM(Iam)
lgr => logging%get_logger('GCHPctmEnv')
! Get whether to import mass fluxes from ExtData or derive from winds
! -----------------------------------------------------------------
call ESMF_ConfigGetAttribute(CF, &
value=import_mass_flux_from_extdata, &
label='IMPORT_MASS_FLUX_FROM_EXTDATA:', &
Default=.false., &
__RC__)
if (import_mass_flux_from_extdata) then
msg = 'Configured to import mass fluxes from ''ExtData'''
else
msg = 'Configured to derive and export mass flux and courant numbers'
end if
call lgr%info(msg)
! Register services for this component
! -----------------------------------------------------------------
call MAPL_GridCompSetEntryPoint(gc, ESMF_METHOD_INITIALIZE, Initialize, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_GridCompSetEntryPoint(gc, ESMF_METHOD_RUN, Run, RC=STATUS)
_VERIFY(STATUS)
! Define Import state
! -----------------------------------------------------------------
call lgr%debug('Adding import specs')
call MAPL_AddImportSpec(gc, &
SHORT_NAME='PS1', &
LONG_NAME='pressure_at_surface_before_advection',&
UNITS='hPa', &
DIMS=MAPL_DimsHorzOnly, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='PS2', &
LONG_NAME='pressure_at_surface_after_advection',&
UNITS='hPa', &
DIMS=MAPL_DimsHorzOnly, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='PS2', &
LONG_NAME='pressure_at_surface_after_advection', &
UNITS='hPa', &
DIMS=MAPL_DimsHorzOnly, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='SPHU1', &
LONG_NAME='specific_humidity_before_advection', &
UNITS='kg kg-1', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='SPHU2', &
LONG_NAME='specific_humidity_after_advection', &
UNITS='kg kg-1', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
! Different imports depending on where mass fluxes will come from
if ( import_mass_flux_from_extdata ) then
call MAPL_AddImportSpec(gc, &
SHORT_NAME='MFXC', &
LONG_NAME='pressure_weighted_xward_mass_flux',&
UNITS='Pa m+2 s-1', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
VERIFY_(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='MFYC', &
LONG_NAME='pressure_weighted_yward_mass_flux',&
UNITS='Pa m+2 s-1', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
VERIFY_(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='CXC', &
LONG_NAME='xward_accumulated_courant_number', &
UNITS='', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
VERIFY_(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='CYC', &
LONG_NAME='yward_accumulated_courant_number', &
UNITS='', &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
VERIFY_(STATUS)
else
call MAPL_AddImportSpec(gc, &
SHORT_NAME='UA', &
LONG_NAME='eastward_wind_on_A-Grid', &
UNITS='m s-1', &
STAGGERING=MAPL_AGrid, &
ROTATION=MAPL_RotateLL, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddImportSpec(gc, &
SHORT_NAME='VA', &
LONG_NAME='northward_wind_on_A-Grid', &
UNITS='m s-1', &
STAGGERING=MAPL_AGrid, &
ROTATION=MAPL_RotateLL, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
endif
! Define Export State
! -----------------------------------------------------------------
call lgr%debug('Adding export specs')
call MAPL_AddExportSpec(gc, &
SHORT_NAME='SPHU0', &
LONG_NAME='specific_humidity_before_advection', &
UNITS='kg kg-1', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='PLE0', &
LONG_NAME='pressure_at_layer_edges_before_advection',&
UNITS='Pa', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='PLE1', &
LONG_NAME='pressure_at_layer_edges_after_advection', &
UNITS='Pa', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME = 'DryPLE0', &
LONG_NAME = 'dry_pressure_at_layer_edges_before_advection',&
UNITS = 'Pa', &
PRECISION = ESMF_KIND_R8, &
DIMS = MAPL_DimsHorzVert, &
VLOCATION = MAPL_VLocationEdge, &
RC=STATUS )
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME = 'DryPLE1', &
LONG_NAME = 'dry_pressure_at_layer_edges_after_advection',&
UNITS = 'Pa', &
PRECISION = ESMF_KIND_R8, &
DIMS = MAPL_DimsHorzVert, &
VLOCATION = MAPL_VLocationEdge, &
RC=STATUS )
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='CX', &
LONG_NAME='xward_accumulated_courant_number', &
UNITS='', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='CY', &
LONG_NAME='yward_accumulated_courant_number', &
UNITS='', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='MFX', &
LONG_NAME='pressure_weighted_accumulated_xward_mass_flux', &
UNITS='Pa m+2 s-1', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='MFY', &
LONG_NAME='pressure_weighted_accumulated_yward_mass_flux', &
UNITS='Pa m+2 s-1', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationCenter, &
RC=STATUS)
_VERIFY(STATUS)
call MAPL_AddExportSpec(gc, &
SHORT_NAME='UpwardsMassFlux', &
LONG_NAME='upward_mass_flux_of_air', &
UNITS='kg m-2 s-1', &
PRECISION=ESMF_KIND_R8, &
DIMS=MAPL_DimsHorzVert, &
VLOCATION=MAPL_VLocationEdge, &
RC=STATUS)
_VERIFY(STATUS)
! Set profiling timers
!-------------------------
call lgr%debug('Adding timers')
call MAPL_TimerAdd(gc, name="INITIALIZE", RC=STATUS)
_VERIFY(STATUS)
call MAPL_TimerAdd(gc, name="RUN", RC=STATUS)
_VERIFY(STATUS)
call lgr%debug('Calling MAPL_GenericSetServices')
! Create children's gridded components and invoke their SetServices
! -----------------------------------------------------------------
call MAPL_GenericSetServices(gc, RC=STATUS)
_VERIFY(STATUS)
_RETURN(ESMF_SUCCESS)
end subroutine SetServices
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialize -- Initialized method for composite the CTMder
!
! !INTERFACE:
!
subroutine Initialize(GC, IMPORT, EXPORT, CLOCK, RC)
!
! !INPUT/OUTPUT PARAMETERS:
!
type(ESMF_GridComp), intent(inout) :: GC ! Gridded component
type(ESMF_State), intent(inout) :: IMPORT ! Import state
type(ESMF_State), intent(inout) :: EXPORT ! Export state
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
!
! !OUTPUT PARAMETERS:
!
integer, optional, intent(out) :: RC ! Error code
!
! !DESCRIPTION:
! The Initialize method of the CTM Derived Gridded Component.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: comm
character(len=ESMF_MAXSTR) :: COMP_NAME
character(len=ESMF_MAXSTR) :: msg
type(ESMF_Config) :: CF
type(ESMF_Grid) :: esmfGrid
type(ESMF_VM) :: VM
type(MAPL_MetaComp), pointer :: ggState ! MAPL Generic State
REAL, POINTER, DIMENSION(:,:) :: cellArea
!================================
! Initialize starts here
!================================
__Iam__('Initialize')
! Get this gridded component name and set-up traceback handle
! -----------------------------------------------------------------
call ESMF_GridCompGet(GC, NAME=COMP_NAME, CONFIG=CF, VM=VM, RC=STATUS)
_VERIFY(STATUS)
Iam = TRIM(COMP_NAME)//"::Initialize"
! Initialize MAPL_Generic
! -----------------------------------------------------------------
call MAPL_GenericInitialize(gc, IMPORT, EXPORT, clock, RC=STATUS)
_VERIFY(STATUS)
! Get internal MAPL_Generic state
! -----------------------------------------------------------------
call MAPL_GetObjectFromGC(GC, ggState, RC=STATUS)
_VERIFY(STATUS)
! Turn on timers
! -----------------------------------------------------------------
call MAPL_TimerOn(ggSTATE, "TOTAL")
call MAPL_TimerOn(ggSTATE, "INITIALIZE")
! Get grid-related information
! -----------------------------------------------------------------
call ESMF_GridCompGet(GC, GRID=esmfGrid, rc=STATUS)
_VERIFY(STATUS)
! Get whether meteorology vertical index is top down (native fields)
! or bottom up (GEOS-Chem processed fields)
! -----------------------------------------------------------------
call ESMF_ConfigGetAttribute( &
CF, &
value=meteorology_vertical_index_is_top_down, &
label='METEOROLOGY_VERTICAL_INDEX_IS_TOP_DOWN:',&
Default=.false., &
__RC__ )
if (meteorology_vertical_index_is_top_down) then
msg='Configured to expect ''top-down'' meteorological data'// &
' from ''ExtData'''
else
msg='Configured to expect ''bottom-up'' meteorological'// &
' data from ''ExtData'''
end if
call lgr%info(trim(msg))
! Get whether to use total or dry air pressure in advection
! -----------------------------------------------------------------
call ESMF_ConfigGetAttribute( &
CF, &
value=use_total_air_pressure_in_advection, &
label='USE_TOTAL_AIR_PRESSURE_IN_ADVECTION:', &
Default=0, &
__RC__ )
if ( use_total_air_pressure_in_advection > 0 ) then
msg='Configured to use total air pressure in advection'
else
msg='Configured to use dry air pressure in advection'
end if
call lgr%info(trim(msg))
! Get whether to correct mass flux for humidity (convert total to dry)
! -----------------------------------------------------------------
call ESMF_ConfigGetAttribute( &
CF, &
value=correct_mass_flux_for_humidity, &
label='CORRECT_MASS_FLUX_FOR_HUMIDITY:', &
Default=1, &
__RC__ )
if ( correct_mass_flux_for_humidity > 0 ) then
msg='Configured to correct native mass flux (if using) for humidity'
else
msg='Configured to not correct native mass flux (if using) for humidity'
end if
call lgr%info(trim(msg))
! Turn off timers
! -----------------------------------------------------------------
call MAPL_TimerOff(ggSTATE,"INITIALIZE")
call MAPL_TimerOff(ggSTATE,"TOTAL")
_RETURN(ESMF_SUCCESS)
end subroutine Initialize
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !INTERFACE:
!
subroutine Run(GC, IMPORT, EXPORT, CLOCK, RC)
!
! !INPUT/OUTPUT PARAMETERS:
!
type(ESMF_GridComp), intent(inout) :: GC ! Gridded component
type(ESMF_State), intent(inout) :: IMPORT ! Import state
type(ESMF_State), intent(inout) :: EXPORT ! Export state
type(ESMF_Clock), intent(inout) :: CLOCK ! The clock
!
! !OUTPUT PARAMETERS:
!
integer, optional, intent(out) :: RC ! Error code
!
! !DESCRIPTION:
! The Run method of the derived variables CTM Gridded Component.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: STATUS
integer :: ndt
character(len=ESMF_MAXSTR) :: IAm = "Run"
character(len=ESMF_MAXSTR) :: COMP_NAME
type(MAPL_MetaComp), pointer :: ggState
type(ESMF_Grid) :: esmfGrid
real(r8) :: dt
real(r8), pointer :: PLE(:,:,:) ! Edge pressures
! Saved variables
logical, save :: firstRun = .true.
#ifdef ADJOINT
integer :: reverseTime
#endif
!================================
! Run starts here
!================================
! Get this component's name and set-up traceback handle.
call ESMF_GridCompGet(GC, name=COMP_NAME, Grid=esmfGrid, RC=STATUS)
_VERIFY(STATUS)
Iam = trim(COMP_NAME) // TRIM(Iam)
! Get internal MAPL_Generic state
call MAPL_GetObjectFromGC(GC, ggState, RC=STATUS)
_VERIFY(STATUS)
! Turn on timers
call MAPL_TimerOn(ggState,"TOTAL")
call MAPL_TimerOn(ggState,"RUN")
! Retrieve timestep [s] and store as real
call MAPL_GetResource( ggState, &
ndt, &
'RUN_DT:', &
default=0, &
RC=STATUS )
_VERIFY(STATUS)
dt = ndt
#ifdef ADJOINT
! Modifications for running time backwards in adjoint
call MAPL_GetResource( ggState, &
reverseTime, &
'REVERSE_TIME:', &
default=0, &
RC=STATUS )
_VERIFY(STATUS)
IF(MAPL_Am_I_Root()) WRITE(*,*) ' GIGCenv REVERSE_TIME: ', reverseTime
IF(reverseTime .eq. 1) THEN
WRITE(*,*) ' GIGCenv swapping timestep sign.'
dt = -dt
ENDIF
#endif
! Compute the exports
call prepare_ple_exports(IMPORT, EXPORT, PLE, RC=STATUS)
_VERIFY(STATUS)
call prepare_sphu_export(IMPORT, EXPORT, RC=STATUS)
_VERIFY(STATUS)
call prepare_massflux_exports(IMPORT, EXPORT, PLE, dt, RC=STATUS)
_VERIFY(STATUS)
! Turn off timers
call MAPL_TimerOff(ggState,"RUN")
call MAPL_TimerOff(ggState,"TOTAL")
_RETURN(ESMF_SUCCESS)
end subroutine Run
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !INTERFACE:
!
subroutine prepare_ple_exports(IMPORT, EXPORT, PLE, RC)
!
! !INPUT/OUTPUT PARAMETERS:
!
type(ESMF_State), intent(inout) :: IMPORT
type(ESMF_State), intent(inout) :: EXPORT
!
! !OUTPUT PARAMETERS:
!
real(r8), intent(out), pointer :: PLE(:,:,:) ! Edge pressures
integer, intent(out), optional :: RC
!
! !DESCRIPTION: Compute pressure edge exports for use in advection.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: LM
integer :: STATUS
real, pointer, dimension(:,:) :: PS1_IMPORT => null()
real, pointer, dimension(:,:) :: PS2_IMPORT => null()
real, pointer, dimension(:,:,:) :: SPHU1_IMPORT => null()
real, pointer, dimension(:,:,:) :: SPHU2_IMPORT => null()
real(r8), pointer, dimension(:,:,:) :: PLE0_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: PLE1_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: DryPLE0_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: DryPLE1_EXPORT => null()
!================================
! prepare_ple_exports starts here
!================================
! NB: Input at ExtData is PS1 (before) and PS2 (after)
! Input at FV3 is PLE0 (before) and PLE1 (after)
call lgr%debug('Preparing FV3 inputs PLE0 and PLE1')
! Get imports (real4)
call MAPL_GetPointer(IMPORT, PS1_IMPORT, 'PS1', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(IMPORT, PS2_IMPORT, 'PS2', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(IMPORT, SPHU1_IMPORT, 'SPHU1', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(IMPORT, SPHU2_IMPORT, 'SPHU2', RC=STATUS)
_VERIFY(STATUS)
! Get exports (real8) and initialize
call MAPL_GetPointer(EXPORT, PLE0_EXPORT, 'PLE0', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(EXPORT, PLE1_EXPORT, 'PLE1', RC=STATUS)
_VERIFY(STATUS)
PLE0_EXPORT(:,:,:) = 0.0d0
PLE1_EXPORT(:,:,:) = 0.0d0
if ( use_total_air_pressure_in_advection < 1 ) then
call MAPL_GetPointer(EXPORT, DryPLE0_EXPORT, 'DryPLE0', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(EXPORT, DryPLE1_EXPORT, 'DryPLE1', RC=STATUS)
_VERIFY(STATUS)
DryPLE0_EXPORT(:,:,:) = 0.0d0
DryPLE1_EXPORT(:,:,:) = 0.0d0
endif
! Set number of levels
LM = size(PLE0_EXPORT,3) - 1
! Compute pressure edge exports from surface pressure and
! then convert from hPa to Pa and vertically flip so that level index
! is top-down (level 1 is TOA). The transformation is needed because
! calculate_ple returns bottom-up pressure as in [hPa] and advection
! expects top-down pressure in [Pa].
! Compute PLE0 from PS1 (naming mismatch between FV3 GEOS-Chem)
call calculate_ple(PS1_IMPORT, PLE0_EXPORT)
PLE0_EXPORT = 100.0d0 * PLE0_EXPORT
PLE0_EXPORT = PLE0_EXPORT(:,:,LM:0:-1)
! Compute PLE1 from PS2 (naming mismatch between FV3 GEOS-Chem )
call calculate_ple(PS2_IMPORT, PLE1_EXPORT)
PLE1_EXPORT = 100.0d0 * PLE1_EXPORT
PLE1_EXPORT = PLE1_EXPORT(:,:,LM:0:-1)
! Also compute dry pressures if using dry pressure in advection
if ( use_total_air_pressure_in_advection < 1 ) then
call calculate_ple( &
PS=PS1_IMPORT, &
PLE=DryPLE0_EXPORT, &
SPHU=SPHU1_IMPORT, &
topDownMet=meteorology_vertical_index_is_top_down )
DryPLE0_EXPORT = 100.0d0 * DryPLE0_EXPORT
DryPLE0_EXPORT = DryPLE0_EXPORT(:,:,LM:0:-1)
call calculate_ple( &
PS=PS2_IMPORT, &
PLE=DryPLE1_EXPORT, &
SPHU=SPHU2_IMPORT, &
topDownMet=meteorology_vertical_index_is_top_down )
DryPLE1_EXPORT = 100.0d0 * DryPLE1_EXPORT
DryPLE1_EXPORT = DryPLE1_EXPORT(:,:,LM:0:-1)
endif
! Set PLE output which will be used to compute mass fluxes in FV3
if ( use_total_air_pressure_in_advection > 0 ) then
PLE => PLE0_EXPORT
else
PLE => DryPLE0_Export
endif
_RETURN(ESMF_SUCCESS)
end subroutine prepare_ple_exports
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !INTERFACE:
!
subroutine prepare_sphu_export(IMPORT, EXPORT, RC)
!
! !INPUT/OUTPUT PARAMETERS:
!
type(ESMF_State), intent(inout) :: IMPORT
type(ESMF_State), intent(inout) :: EXPORT
!
! !OUTPUT PARAMETERS:
!
integer, optional, intent(out) :: RC
integer :: LM
!
! !DESCRIPTION: Set SPHU export for advection. This is only done if using
! total rather than dry pressure in advection.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: STATUS
real, pointer, dimension(:,:,:) :: SPHU1_IMPORT => null()
real(r8), pointer, dimension(:,:,:) :: SPHU0_EXPORT => null()
!================================
! prepare_sphu_export starts here
!================================
! NB: Input at ExtData is SPHU1 (before) and SPHU2 (after)
! Input at FV3 is SPHU0 (before) and SPHU1 (after)
call lgr%debug('Preparing FV3 input SPHU0')
! Get imports (real4)
call MAPL_GetPointer(IMPORT, SPHU1_IMPORT, 'SPHU1', RC=STATUS)
_VERIFY(STATUS)
! Get exports (real8) and initialize to 0
call MAPL_GetPointer(EXPORT, SPHU0_EXPORT, 'SPHU0', RC=STATUS)
_VERIFY(STATUS)
SPHU0_EXPORT(:,:,:) = 0.0d0
! Set number of levels
LM = size(SPHU1_IMPORT, 3)
! Set export as copy of import casted to real8 and set vertical index
! as top-down (level 1 corresponds to TOA)
if (meteorology_vertical_index_is_top_down) then
SPHU0_EXPORT = dble(SPHU1_IMPORT)
else
SPHU0_EXPORT(:,:,:) = dble(SPHU1_IMPORT(:,:,LM:1:-1))
end if
_RETURN(ESMF_SUCCESS)
end subroutine prepare_sphu_export
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !INTERFACE:
!
subroutine prepare_massflux_exports(IMPORT, EXPORT, PLE, dt, RC)
!
! !INPUT PARAMETERS:
!
real(r8), intent(in), pointer :: PLE(:,:,:) ! Edge pressures
real(r8), intent(in) :: dt
!
! !INPUT/OUTPUT PARAMETERS:
!
type(ESMF_State), intent(inout) :: IMPORT
type(ESMF_State), intent(inout) :: EXPORT
!
! OUTPUT PARAMETERS:
!
integer, optional, intent(out) :: RC ! Error code
!
! !DESCRIPTION:
! Set mass flux and courant exports needed for offline advection. How this
! is done is dependent upon whether importing them via ExtData or computing
! from winds.
!
!EOP
!-------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
integer :: is, ie, js, je, lm
integer :: STATUS
! Pointers to exports
real(r8), pointer, dimension(:,:,:) :: MFX_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: MFY_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: CX_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: CY_EXPORT => null()
real(r8), pointer, dimension(:,:,:) :: SPHU0_EXPORT => null()
! Pointers to imports
real, pointer, dimension(:,:,:) :: UA_IMPORT => null()
real, pointer, dimension(:,:,:) :: VA_IMPORT => null()
! Pointer to diagnostic export
real(r8), pointer, dimension(:,:,:) :: UpwardsMassFlux => null()
! Pointers to local arrays
real, pointer, dimension(:,:,:) :: temp3d_r4 => null()
real, pointer, dimension(:,:,:) :: UC => null()
real, pointer, dimension(:,:,:) :: VC => null()
real(r8), pointer, dimension(:,:,:) :: UCr8 => null()
real(r8), pointer, dimension(:,:,:) :: VCr8 => null()
!=====================================
! prepare_massflux_exports starts here
!=====================================
call lgr%debug('Preparing FV3 input MFX, MFY, CX, and CY')
is = lbound(PLE, 1); ie = ubound(PLE, 1)
js = lbound(PLE, 2); je = ubound(PLE, 2)
lm = size(PLE, 3) - 1
! Get exports (real8)
call MAPL_GetPointer(EXPORT, MFX_EXPORT, 'MFX', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(EXPORT, MFY_EXPORT, 'MFY', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(EXPORT, CX_EXPORT, 'CX', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(EXPORT, CY_EXPORT, 'CY', RC=STATUS)
_VERIFY(STATUS)
if ( import_mass_flux_from_extdata ) then
! Get SPHU0 export set in prepare_sphu_export
if ( correct_mass_flux_for_humidity > 0 ) then
call MAPL_GetPointer(EXPORT, SPHU0_EXPORT, 'SPHU0', RC=STATUS)
_VERIFY(STATUS)
endif
! Get imports (real4) and copy to exports, converting to real8
call MAPL_GetPointer(IMPORT, temp3d_r4, 'MFXC', RC=STATUS)
_VERIFY(STATUS)
if ( correct_mass_flux_for_humidity > 0 ) then
MFX_EXPORT = dble(temp3d_r4) / ( 1.d0 - SPHU0_EXPORT )
else
MFX_EXPORT = dble(temp3d_r4)
endif
call MAPL_GetPointer(IMPORT, temp3d_r4, 'MFYC', RC=STATUS)
_VERIFY(STATUS)
if ( correct_mass_flux_for_humidity > 0 ) then
MFY_EXPORT = dble(temp3d_r4) / ( 1.d0 - SPHU0_EXPORT )
else
MFY_EXPORT = dble(temp3d_r4)
endif
call MAPL_GetPointer(IMPORT, temp3d_r4, 'CXC', RC=STATUS)
_VERIFY(STATUS)
CX_EXPORT = dble(temp3d_r4)
call MAPL_GetPointer(IMPORT, temp3d_r4, 'CYC', RC=STATUS)
_VERIFY(STATUS)
CY_EXPORT = dble(temp3d_r4)
else
! Get wind imports (real4, A-grid)
call MAPL_GetPointer(IMPORT, UA_IMPORT, 'UA', RC=STATUS)
_VERIFY(STATUS)
call MAPL_GetPointer(IMPORT, VA_IMPORT, 'VA', RC=STATUS)
_VERIFY(STATUS)
! Allocate local arrays for C-grid, both real4 and real8
ALLOCATE( UC (is:ie, js:je, lm), STAT=STATUS);
_VERIFY(STATUS)
ALLOCATE( VC (is:ie, js:je, lm), STAT=STATUS);
_VERIFY(STATUS)
ALLOCATE( UCr8 (is:ie, js:je, lm), STAT=STATUS);
_VERIFY(STATUS)
ALLOCATE( VCr8 (is:ie, js:je, lm), STAT=STATUS);
_VERIFY(STATUS)
! Copy imports to local arrays so that vertical index is top down
if (meteorology_vertical_index_is_top_down) then
UC(:,:,:) = UA_IMPORT(:,:,:)
VC(:,:,:) = VA_IMPORT(:,:,:)
else
UC(:,:,:) = UA_IMPORT(:,:,LM:1:-1)
VC(:,:,:) = VA_IMPORT(:,:,LM:1:-1)
end if
! Restagger winds (A-grid to C-grid) (requires real4)
call A2D2C(U=UC, V=VC, npz=lm, getC=.true.)
! Store as real8 for input to FV3 subroutine to compute mass fluxes
UCr8 = dble(UC)
VCr8 = dble(VC)
#ifdef ADJOINT
if (.not. firstRun) THEN
#endif
! Calculate mass fluxes and courant numbers
call fv_computeMassFluxes(UCr8, VCr8, PLE, &
MFX_EXPORT, MFY_EXPORT, &
CX_EXPORT, CY_EXPORT, dt)
#ifdef ADJOINT
endif
firstRun = .false.
#endif
! Deallocate local arrays
DEALLOCATE(UC, VC, UCr8, VCr8)
end if
! Set vertical motion diagnostic if enabled in HISTORY.rc
call MAPL_GetPointer(EXPORT, UpwardsMassFlux, 'UpwardsMassFlux', &
NotFoundOK=.TRUE., RC=STATUS)
_VERIFY(STATUS)
if (associated(UpwardsMassFlux)) then
call lgr%debug('Calculating diagnostic export UpwardsMassFlux')
! Get vertical mass flux
call fv_getVerticalMassFlux(MFX_EXPORT, MFY_EXPORT, UpwardsMassFlux, dt)
! Flip vertical so that GCHP diagnostic is positive="up"
UpwardsMassFlux(:,:,:) = UpwardsMassFlux(:,:,LM:0:-1)/dt
end if
! nullify pointers
MFX_EXPORT => null()
MFY_EXPORT => null()
CX_EXPORT => null()
CY_EXPORT => null()
SPHU0_EXPORT => null()
UA_IMPORT => null()
VA_IMPORT => null()
UpwardsMassFlux => null()
temp3d_r4 => null()
UC => null()
VC => null()
UCr8 => null()
VCr8 => null()
_RETURN(ESMF_SUCCESS)
end subroutine prepare_massflux_exports
!EOC
!-------------------------------------------------------------------------
! GEOS-Chem High Performance Global Chemical Transport Model
!-------------------------------------------------------------------------
!BOP
!
! !INTERFACE:
!
subroutine calculate_ple(PS, PLE, SPHU, topDownMet )
!
! !INPUT PARAMETERS:
!
real(r4), intent(in) :: PS(:,:) ! Surface pressure [hPa]
real(r4), intent(in), OPTIONAL :: SPHU(:,:,:) ! Specific humidity [kg/kg]
logical, intent(in), OPTIONAL :: topDownMet ! True if meteorology level 1 is TOA
!
! !INPUT PARAMETERS:
!
real(r8), intent(out) :: PLE(:,:,:) ! Edge pressure [hPa]
!
! !DESCRIPTION:
! Compute edge pressures from surface pressure and grid parameters. This
! subroutine is currently hard-coded for 72 levels only and returns pressure