forked from NOAA-EMC/fv3atm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atmos_model.F90
2727 lines (2409 loc) · 107 KB
/
atmos_model.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
!***********************************************************************
!* GNU General Public License *
!* This file is a part of fvGFS. *
!* *
!* fvGFS is free software; you can redistribute it and/or modify it *
!* and are expected to follow the terms of the GNU General Public *
!* License as published by the Free Software Foundation; either *
!* version 2 of the License, or (at your option) any later version. *
!* *
!* fvGFS is distributed in the hope that it will be useful, but *
!* WITHOUT ANY WARRANTY; without even the implied warranty of *
!* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
!* General Public License for more details. *
!* *
!* For the full text of the GNU General Public License, *
!* write to: Free Software Foundation, Inc., *
!* 675 Mass Ave, Cambridge, MA 02139, USA. *
!* or see: http://www.gnu.org/licenses/gpl.html *
!***********************************************************************
module atmos_model_mod
!-----------------------------------------------------------------------
!<OVERVIEW>
! Driver for the atmospheric model, contains routines to advance the
! atmospheric model state by one time step.
!</OVERVIEW>
!<DESCRIPTION>
! This version of atmos_model_mod has been designed around the implicit
! version diffusion scheme of the GCM. It requires two routines to advance
! the atmospheric model one time step into the future. These two routines
! correspond to the down and up sweeps of the standard tridiagonal solver.
! Most atmospheric processes (dynamics,radiation,etc.) are performed
! in the down routine. The up routine finishes the vertical diffusion
! and computes moisture related terms (convection,large-scale condensation,
! and precipitation).
! The boundary variables needed by other component models for coupling
! are contained in a derived data type. A variable of this derived type
! is returned when initializing the atmospheric model. It is used by other
! routines in this module and by coupling routines. The contents of
! this derived type should only be modified by the atmospheric model.
!</DESCRIPTION>
use mpp_mod, only: mpp_pe, mpp_root_pe, mpp_clock_id, mpp_clock_begin
use mpp_mod, only: mpp_clock_end, CLOCK_COMPONENT, MPP_CLOCK_SYNC
use mpp_mod, only: FATAL, mpp_min, mpp_max, mpp_error, mpp_chksum
use mpp_domains_mod, only: domain2d
use mpp_mod, only: mpp_get_current_pelist_name
#ifdef INTERNAL_FILE_NML
use mpp_mod, only: input_nml_file
#else
use fms_mod, only: open_namelist_file
#endif
use fms_mod, only: file_exist, error_mesg
use fms_mod, only: close_file, write_version_number, stdlog, stdout
use fms_mod, only: clock_flag_default
use fms_mod, only: check_nml_error
use diag_manager_mod, only: diag_send_complete_instant
use time_manager_mod, only: time_type, get_time, get_date, &
operator(+), operator(-),real_to_time_type
use field_manager_mod, only: MODEL_ATMOS
use tracer_manager_mod, only: get_number_tracers, get_tracer_names, &
get_tracer_index, NO_TRACER
use xgrid_mod, only: grid_box_type
use atmosphere_mod, only: atmosphere_init
use atmosphere_mod, only: atmosphere_restart
use atmosphere_mod, only: atmosphere_end
use atmosphere_mod, only: atmosphere_state_update
use atmosphere_mod, only: atmos_phys_driver_statein
use atmosphere_mod, only: atmosphere_control_data
use atmosphere_mod, only: atmosphere_resolution, atmosphere_domain
use atmosphere_mod, only: atmosphere_grid_bdry, atmosphere_grid_ctr
use atmosphere_mod, only: atmosphere_dynamics, atmosphere_diag_axes
use atmosphere_mod, only: atmosphere_etalvls, atmosphere_hgt
!rab use atmosphere_mod, only: atmosphere_tracer_postinit
use atmosphere_mod, only: atmosphere_diss_est, atmosphere_nggps_diag
use atmosphere_mod, only: atmosphere_scalar_field_halo
use atmosphere_mod, only: atmosphere_get_bottom_layer
use atmosphere_mod, only: set_atmosphere_pelist
use atmosphere_mod, only: Atm, mygrid
use block_control_mod, only: block_control_type, define_blocks_packed
use DYCORE_typedefs, only: DYCORE_data_type, DYCORE_diag_type
use GFS_typedefs, only: GFS_init_type, GFS_kind_phys => kind_phys
use GFS_restart, only: GFS_restart_type, GFS_restart_populate
use GFS_diagnostics, only: GFS_externaldiag_type, &
GFS_externaldiag_populate
use CCPP_data, only: ccpp_suite, GFS_control, &
GFS_data, GFS_interstitial
use GFS_init, only: GFS_initialize
use CCPP_driver, only: CCPP_step, non_uniform_blocks
use stochastic_physics_wrapper_mod, only: stochastic_physics_wrapper,stochastic_physics_wrapper_end
use FV3GFS_io_mod, only: FV3GFS_restart_read, FV3GFS_restart_write, &
FV3GFS_GFS_checksum, &
FV3GFS_diag_register, FV3GFS_diag_output, &
DIAG_SIZE
use fv_iau_mod, only: iau_external_data_type,getiauforcing,iau_initialize
use module_fv3_config, only: output_1st_tstep_rst, first_kdt, nsout, &
frestart, restart_endfcst
!-----------------------------------------------------------------------
implicit none
private
public update_atmos_radiation_physics
public update_atmos_model_state
public update_atmos_model_dynamics
public atmos_model_init, atmos_model_end, atmos_data_type
public atmos_model_exchange_phase_1, atmos_model_exchange_phase_2
public atmos_model_restart
public get_atmos_model_ungridded_dim
public addLsmask2grid
!-----------------------------------------------------------------------
!<PUBLICTYPE >
type atmos_data_type
integer :: axes(4) ! axis indices (returned by diag_manager) for the atmospheric grid
! (they correspond to the x, y, pfull, phalf axes)
integer, pointer :: pelist(:) =>null() ! pelist where atmosphere is running.
integer :: layout(2) ! computer task laytout
logical :: regional ! true if domain is regional
logical :: nested ! true if there is a nest
integer :: mlon, mlat
integer :: iau_offset ! iau running window length
logical :: pe ! current pe.
real(kind=8), pointer, dimension(:) :: ak, bk
real, pointer, dimension(:,:) :: lon_bnd => null() ! local longitude axis grid box corners in radians.
real, pointer, dimension(:,:) :: lat_bnd => null() ! local latitude axis grid box corners in radians.
real(kind=GFS_kind_phys), pointer, dimension(:,:) :: lon => null() ! local longitude axis grid box centers in radians.
real(kind=GFS_kind_phys), pointer, dimension(:,:) :: lat => null() ! local latitude axis grid box centers in radians.
real(kind=GFS_kind_phys), pointer, dimension(:,:) :: dx, dy
real(kind=8), pointer, dimension(:,:) :: area
real(kind=8), pointer, dimension(:,:,:) :: layer_hgt, level_hgt
type(domain2d) :: domain ! domain decomposition
type(time_type) :: Time ! current time
type(time_type) :: Time_step ! atmospheric time step.
type(time_type) :: Time_init ! reference time.
type(grid_box_type) :: grid ! hold grid information needed for 2nd order conservative flux exchange
type(GFS_externaldiag_type), pointer, dimension(:) :: Diag
end type atmos_data_type
! to calculate gradient on cubic sphere grid.
!</PUBLICTYPE >
integer :: fv3Clock, getClock, updClock, setupClock, radClock, physClock
!-----------------------------------------------------------------------
integer :: blocksize = 1
logical :: chksum_debug = .false.
logical :: dycore_only = .false.
logical :: debug = .false.
!logical :: debug = .true.
logical :: sync = .false.
integer, parameter :: maxhr = 4096
real, dimension(maxhr) :: fdiag = 0.
real :: fhmax=384.0, fhmaxhf=120.0, fhout=3.0, fhouthf=1.0,avg_max_length=3600.
namelist /atmos_model_nml/ blocksize, chksum_debug, dycore_only, debug, sync, fdiag, fhmax, fhmaxhf, fhout, fhouthf, ccpp_suite, avg_max_length
type (time_type) :: diag_time, diag_time_fhzero
!--- concurrent and decoupled radiation and physics variables
!-------------------
! DYCORE containers
!-------------------
type(DYCORE_data_type), allocatable :: DYCORE_Data(:) ! number of blocks
type(DYCORE_diag_type) :: DYCORE_Diag(25)
!----------------
! GFS containers
!----------------
type(GFS_externaldiag_type), target :: GFS_Diag(DIAG_SIZE)
type(GFS_restart_type) :: GFS_restart_var
!--------------
! IAU container
!--------------
type(iau_external_data_type) :: IAU_Data ! number of blocks
!-----------------
! Block container
!-----------------
type (block_control_type), target :: Atm_block
!-----------------------------------------------------------------------
character(len=128) :: version = '$Id$'
character(len=128) :: tagname = '$Name$'
#ifdef NAM_phys
logical,parameter :: flip_vc = .false.
#else
logical,parameter :: flip_vc = .true.
#endif
real(kind=GFS_kind_phys), parameter :: zero = 0.0_GFS_kind_phys, &
one = 1.0_GFS_kind_phys, &
epsln = 1.0e-10_GFS_kind_phys, &
zorlmin = 1.0e-7_GFS_kind_phys
contains
!#######################################################################
! <SUBROUTINE NAME="update_radiation_physics">
!
!<DESCRIPTION>
! Called every time step as the atmospheric driver to compute the
! atmospheric tendencies for dynamics, radiation, vertical diffusion of
! momentum, tracers, and heat/moisture. For heat/moisture only the
! downward sweep of the tridiagonal elimination is performed, hence
! the name "_down".
!</DESCRIPTION>
! <TEMPLATE>
! call update_atmos_radiation_physics (Atmos)
! </TEMPLATE>
! <INOUT NAME="Atmos" TYPE="type(atmos_data_type)">
! Derived-type variable that contains fields needed by the flux exchange module.
! These fields describe the atmospheric grid and are needed to
! compute/exchange fluxes with other component models. All fields in this
! variable type are allocated for the global grid (without halo regions).
! </INOUT>
subroutine update_atmos_radiation_physics (Atmos)
!-----------------------------------------------------------------------
type (atmos_data_type), intent(in) :: Atmos
!--- local variables---
integer :: nb, jdat(8), rc, ierr
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "statein driver"
!--- get atmospheric state from the dynamic core
call set_atmosphere_pelist()
call mpp_clock_begin(getClock)
if (GFS_control%do_skeb) call atmosphere_diss_est (GFS_control%skeb_npass) ! do smoothing for SKEB
call atmos_phys_driver_statein (GFS_data, Atm_block, flip_vc)
call mpp_clock_end(getClock)
!--- if dycore only run, set up the dummy physics output state as the input state
if (dycore_only) then
do nb = 1,Atm_block%nblks
GFS_data(nb)%Stateout%gu0 = GFS_data(nb)%Statein%ugrs
GFS_data(nb)%Stateout%gv0 = GFS_data(nb)%Statein%vgrs
GFS_data(nb)%Stateout%gt0 = GFS_data(nb)%Statein%tgrs
GFS_data(nb)%Stateout%gq0 = GFS_data(nb)%Statein%qgrs
enddo
else
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "setup step"
!--- update GFS_control%jdat(8)
jdat(:) = 0
call get_date (Atmos%Time, jdat(1), jdat(2), jdat(3), &
jdat(5), jdat(6), jdat(7))
GFS_control%jdat(:) = jdat(:)
!--- execute the IPD atmospheric setup step
call mpp_clock_begin(setupClock)
call CCPP_step (step="timestep_init", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP timestep_init step failed')
!--- call stochastic physics pattern generation / cellular automata
call stochastic_physics_wrapper(GFS_control, GFS_data, Atm_block, ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to stochastic_physics_wrapper failed')
!--- if coupled, assign coupled fields
if( GFS_control%cplflx .or. GFS_control%cplwav ) then
! if (mpp_pe() == mpp_root_pe() .and. debug) then
! print *,'in atmos_model,nblks=',Atm_block%nblks
! print *,'in atmos_model,GFS_data size=',size(GFS_data)
! print *,'in atmos_model,tsfc(1)=',GFS_data(1)%sfcprop%tsfc(1)
! print *,'in atmos_model, tsfc size=',size(GFS_data(1)%sfcprop%tsfc)
! endif
call assign_importdata(rc)
endif
! Calculate total non-physics tendencies by substracting old IPD Stateout
! variables from new/updated IPD Statein variables (gives the tendencies
! due to anything else than physics)
if (GFS_control%ldiag3d) then
do nb = 1,Atm_block%nblks
GFS_data(nb)%Intdiag%du3dt(:,:,8) = GFS_data(nb)%Intdiag%du3dt(:,:,8) &
+ (GFS_data(nb)%Statein%ugrs - GFS_data(nb)%Stateout%gu0)
GFS_data(nb)%Intdiag%dv3dt(:,:,8) = GFS_data(nb)%Intdiag%dv3dt(:,:,8) &
+ (GFS_data(nb)%Statein%vgrs - GFS_data(nb)%Stateout%gv0)
GFS_data(nb)%Intdiag%dt3dt(:,:,11) = GFS_data(nb)%Intdiag%dt3dt(:,:,11) &
+ (GFS_data(nb)%Statein%tgrs - GFS_data(nb)%Stateout%gt0)
enddo
if (GFS_control%qdiag3d) then
do nb = 1,Atm_block%nblks
GFS_data(nb)%Intdiag%dq3dt(:,:,12) = GFS_data(nb)%Intdiag%dq3dt(:,:,12) &
+ (GFS_data(nb)%Statein%qgrs(:,:,GFS_control%ntqv) - GFS_data(nb)%Stateout%gq0(:,:,GFS_control%ntqv))
GFS_data(nb)%Intdiag%dq3dt(:,:,13) = GFS_data(nb)%Intdiag%dq3dt(:,:,13) &
+ (GFS_data(nb)%Statein%qgrs(:,:,GFS_control%ntoz) - GFS_data(nb)%Stateout%gq0(:,:,GFS_control%ntoz))
enddo
endif
endif
call mpp_clock_end(setupClock)
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "radiation driver"
!--- execute the IPD atmospheric radiation subcomponent (RRTM)
call mpp_clock_begin(radClock)
! Performance improvement. Only enter if it is time to call the radiation physics.
if (GFS_control%lsswr .or. GFS_control%lslwr) then
call CCPP_step (step="radiation", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP radiation step failed')
endif
call mpp_clock_end(radClock)
if (chksum_debug) then
if (mpp_pe() == mpp_root_pe()) print *,'RADIATION STEP ', GFS_control%kdt, GFS_control%fhour
call FV3GFS_GFS_checksum(GFS_control, GFS_data, Atm_block)
endif
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "physics driver"
!--- execute the IPD atmospheric physics step1 subcomponent (main physics driver)
call mpp_clock_begin(physClock)
call CCPP_step (step="physics", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP physics step failed')
call mpp_clock_end(physClock)
if (chksum_debug) then
if (mpp_pe() == mpp_root_pe()) print *,'PHYSICS STEP1 ', GFS_control%kdt, GFS_control%fhour
call FV3GFS_GFS_checksum(GFS_control, GFS_data, Atm_block)
endif
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "stochastic physics driver"
!--- execute the IPD atmospheric physics step2 subcomponent (stochastic physics driver)
call mpp_clock_begin(physClock)
call CCPP_step (step="stochastics", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP stochastics step failed')
call mpp_clock_end(physClock)
if (chksum_debug) then
if (mpp_pe() == mpp_root_pe()) print *,'PHYSICS STEP2 ', GFS_control%kdt, GFS_control%fhour
call FV3GFS_GFS_checksum(GFS_control, GFS_data, Atm_block)
endif
call getiauforcing(GFS_control,IAU_data)
if (mpp_pe() == mpp_root_pe() .and. debug) write(6,*) "end of radiation and physics step"
!--- execute the IPD atmospheric timestep finalize step
call mpp_clock_begin(setupClock)
call CCPP_step (step="timestep_finalize", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP timestep_finalize step failed')
call mpp_clock_end(setupClock)
endif
! Update flag for first time step of time integration
GFS_control%first_time_step = .false.
!-----------------------------------------------------------------------
end subroutine update_atmos_radiation_physics
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="atmos_model_init">
!
! <OVERVIEW>
! Routine to initialize the atmospheric model
! </OVERVIEW>
subroutine atmos_model_init (Atmos, Time_init, Time, Time_step)
#ifdef _OPENMP
use omp_lib
#endif
use fv_mp_mod, only: commglobal
use mpp_mod, only: mpp_npes
type (atmos_data_type), intent(inout) :: Atmos
type (time_type), intent(in) :: Time_init, Time, Time_step
!--- local variables ---
integer :: unit, ntdiag, ntfamily, i, j, k
integer :: mlon, mlat, nlon, nlat, nlev, sec, dt
integer :: ierr, io, logunit
integer :: idx, tile_num
integer :: isc, iec, jsc, jec
integer :: isd, ied, jsd, jed
integer :: blk, ibs, ibe, jbs, jbe
real(kind=GFS_kind_phys) :: dt_phys
real, allocatable :: q(:,:,:,:), p_half(:,:,:)
character(len=80) :: control
character(len=64) :: filename, filename2, pelist_name
character(len=132) :: text
logical :: p_hydro, hydro, fexist
logical, save :: block_message = .true.
type(GFS_init_type) :: Init_parm
integer :: bdat(8), cdat(8)
integer :: ntracers, maxhf, maxh
character(len=32), allocatable, target :: tracer_names(:)
integer :: nthrds, nb
!-----------------------------------------------------------------------
!---- set the atmospheric model time ------
Atmos % Time_init = Time_init
Atmos % Time = Time
Atmos % Time_step = Time_step
call get_time (Atmos % Time_step, sec)
dt_phys = real(sec) ! integer seconds
logunit = stdlog()
!-----------------------------------------------------------------------
! initialize atmospheric model -----
IF ( file_exist('input.nml')) THEN
#ifdef INTERNAL_FILE_NML
read(input_nml_file, nml=atmos_model_nml, iostat=io)
ierr = check_nml_error(io, 'atmos_model_nml')
#else
unit = open_namelist_file ( )
ierr=1
do while (ierr /= 0)
read (unit, nml=atmos_model_nml, iostat=io, end=10)
ierr = check_nml_error(io,'atmos_model_nml')
enddo
10 call close_file (unit)
#endif
endif
!---------- initialize atmospheric dynamics after reading the namelist -------
!---------- (need name of CCPP suite definition file from input.nml) ---------
call atmosphere_init (Atmos%Time_init, Atmos%Time, Atmos%Time_step,&
Atmos%grid, Atmos%area)
!-----------------------------------------------------------------------
call atmosphere_resolution (nlon, nlat, global=.false.)
call atmosphere_resolution (mlon, mlat, global=.true.)
call alloc_atmos_data_type (nlon, nlat, Atmos)
call atmosphere_domain (Atmos%domain, Atmos%layout, Atmos%regional, Atmos%nested, Atmos%pelist)
call atmosphere_diag_axes (Atmos%axes)
call atmosphere_etalvls (Atmos%ak, Atmos%bk, flip=flip_vc)
call atmosphere_grid_bdry (Atmos%lon_bnd, Atmos%lat_bnd, global=.false.)
call atmosphere_grid_ctr (Atmos%lon, Atmos%lat)
call atmosphere_hgt (Atmos%layer_hgt, 'layer', relative=.false., flip=flip_vc)
call atmosphere_hgt (Atmos%level_hgt, 'level', relative=.false., flip=flip_vc)
Atmos%mlon = mlon
Atmos%mlat = mlat
!-----------------------------------------------------------------------
!--- before going any further check definitions for 'blocks'
!-----------------------------------------------------------------------
call atmosphere_control_data (isc, iec, jsc, jec, nlev, p_hydro, hydro, tile_num)
call define_blocks_packed ('atmos_model', Atm_block, isc, iec, jsc, jec, nlev, &
blocksize, block_message)
allocate(DYCORE_Data(Atm_block%nblks))
allocate(GFS_data(Atm_block%nblks))
#ifdef _OPENMP
nthrds = omp_get_max_threads()
#else
nthrds = 1
#endif
! This logic deals with non-uniform block sizes for CCPP.
! When non-uniform block sizes are used, it is required
! that only the last block has a different (smaller)
! size than all other blocks. This is the standard in
! FV3. If this is the case, set non_uniform_blocks (a
! variable imported from CCPP_driver) to .true. and
! allocate nthreads+1 elements of the interstitial array.
! The extra element will be used by the thread that
! runs over the last, smaller block.
if (minval(Atm_block%blksz)==maxval(Atm_block%blksz)) then
non_uniform_blocks = .false.
allocate(GFS_interstitial(nthrds))
else if (all(minloc(Atm_block%blksz)==(/size(Atm_block%blksz)/))) then
non_uniform_blocks = .true.
allocate(GFS_interstitial(nthrds+1))
else
call mpp_error(FATAL, 'For non-uniform blocksizes, only the last element ' // &
'in Atm_block%blksz can be different from the others')
end if
!--- update GFS_control%jdat(8)
bdat(:) = 0
call get_date (Time_init, bdat(1), bdat(2), bdat(3), &
bdat(5), bdat(6), bdat(7))
cdat(:) = 0
call get_date (Time, cdat(1), cdat(2), cdat(3), &
cdat(5), cdat(6), cdat(7))
call get_number_tracers(MODEL_ATMOS, num_tracers=ntracers)
allocate (tracer_names(ntracers))
do i = 1, ntracers
call get_tracer_names(MODEL_ATMOS, i, tracer_names(i))
enddo
!--- setup IPD Init_parm
Init_parm%me = mpp_pe()
Init_parm%master = mpp_root_pe()
Init_parm%tile_num = tile_num
Init_parm%isc = isc
Init_parm%jsc = jsc
Init_parm%nx = nlon
Init_parm%ny = nlat
Init_parm%levs = nlev
Init_parm%cnx = mlon
Init_parm%cny = mlat
Init_parm%gnx = Init_parm%cnx*4
Init_parm%gny = Init_parm%cny*2
Init_parm%nlunit = 9999
Init_parm%logunit = logunit
Init_parm%bdat(:) = bdat(:)
Init_parm%cdat(:) = cdat(:)
Init_parm%dt_dycore = dt_phys
Init_parm%dt_phys = dt_phys
Init_parm%iau_offset = Atmos%iau_offset
Init_parm%blksz => Atm_block%blksz
Init_parm%ak => Atmos%ak
Init_parm%bk => Atmos%bk
Init_parm%xlon => Atmos%lon
Init_parm%xlat => Atmos%lat
Init_parm%area => Atmos%area
Init_parm%tracer_names => tracer_names
Init_parm%restart = Atm(mygrid)%flagstruct%warm_start
Init_parm%hydrostatic = Atm(mygrid)%flagstruct%hydrostatic
#ifdef INTERNAL_FILE_NML
Init_parm%input_nml_file => input_nml_file
Init_parm%fn_nml='using internal file'
#else
pelist_name=mpp_get_current_pelist_name()
Init_parm%fn_nml='input_'//trim(pelist_name)//'.nml'
inquire(FILE=Init_parm%fn_nml, EXIST=fexist)
if (.not. fexist ) then
Init_parm%fn_nml='input.nml'
endif
#endif
call GFS_initialize (GFS_control, GFS_data%Statein, GFS_data%Stateout, GFS_data%Sfcprop, &
GFS_data%Coupling, GFS_data%Grid, GFS_data%Tbd, GFS_data%Cldprop, GFS_data%Radtend, &
GFS_data%Intdiag, GFS_interstitial, commglobal, mpp_npes(), Init_parm)
!--- populate/associate the Diag container elements
call GFS_externaldiag_populate (GFS_Diag, GFS_Control, GFS_Data%Statein, GFS_Data%Stateout, &
GFS_Data%Sfcprop, GFS_Data%Coupling, GFS_Data%Grid, &
GFS_Data%Tbd, GFS_Data%Cldprop, GFS_Data%Radtend, &
GFS_Data%Intdiag, Init_parm)
Atmos%Diag => GFS_Diag
Atm(mygrid)%flagstruct%do_skeb = GFS_control%do_skeb
! initialize the IAU module
call iau_initialize (GFS_control,IAU_data,Init_parm)
Init_parm%blksz => null()
Init_parm%ak => null()
Init_parm%bk => null()
Init_parm%xlon => null()
Init_parm%xlat => null()
Init_parm%area => null()
Init_parm%tracer_names => null()
deallocate (tracer_names)
!--- update tracers in FV3 with any initialized during the physics/radiation init phase
!rab call atmosphere_tracer_postinit (GFS_data, Atm_block)
call atmosphere_nggps_diag (Time, init=.true.)
call FV3GFS_diag_register (GFS_Diag, Time, Atm_block, GFS_control, Atmos%lon, Atmos%lat, Atmos%axes)
call GFS_restart_populate (GFS_restart_var, GFS_control, GFS_data%Statein, GFS_data%Stateout, GFS_data%Sfcprop, &
GFS_data%Coupling, GFS_data%Grid, GFS_data%Tbd, GFS_data%Cldprop, GFS_data%Radtend, &
GFS_data%IntDiag, Init_parm, GFS_Diag)
call FV3GFS_restart_read (GFS_data, GFS_restart_var, Atm_block, GFS_control, Atmos%domain, Atm(mygrid)%flagstruct%warm_start)
! Populate the GFS_data%Statein container with the prognostic state
! in Atm_block, which contains the initial conditions/restart data.
call atmos_phys_driver_statein (GFS_data, Atm_block, flip_vc)
! When asked to calculate 3-dim. tendencies, set Stateout variables to
! Statein variables here in order to capture the first call to dycore
if (GFS_control%ldiag3d) then
do nb = 1,Atm_block%nblks
GFS_data(nb)%Stateout%gu0 = GFS_data(nb)%Statein%ugrs
GFS_data(nb)%Stateout%gv0 = GFS_data(nb)%Statein%vgrs
GFS_data(nb)%Stateout%gt0 = GFS_data(nb)%Statein%tgrs
GFS_data(nb)%Stateout%gq0 = GFS_data(nb)%Statein%qgrs
enddo
endif
! Initialize the CCPP framework
call CCPP_step (step="init", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP init step failed')
! Initialize the CCPP physics
call CCPP_step (step="physics_init", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP physics_init step failed')
!--- Initialize stochastic physics pattern generation / cellular automata for first time step
call stochastic_physics_wrapper(GFS_control, GFS_data, Atm_block, ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to stochastic_physics_wrapper failed')
!--- set the initial diagnostic timestamp
diag_time = Time
if (output_1st_tstep_rst) then
diag_time = Time - real_to_time_type(mod(int((first_kdt - 1)*dt_phys/3600.),6)*3600.0)
endif
if (Atmos%iau_offset > zero) then
call get_time (Atmos%Time - Atmos%Time_init, sec)
if (sec < Atmos%iau_offset*3600) then
diag_time = Atmos%Time_init
diag_time_fhzero = Atmos%Time
endif
endif
!---- print version number to logfile ----
call write_version_number ( version, tagname )
!--- write the namelist to a log file
if (mpp_pe() == mpp_root_pe()) then
unit = stdlog( )
write (unit, nml=atmos_model_nml)
call close_file (unit)
endif
!--- get fdiag
#ifdef GFS_PHYS
!--- check fdiag to see if it is an interval or a list
if (nint(fdiag(2)) == 0) then
if (fhmaxhf > 0) then
maxhf = fhmaxhf / fhouthf
maxh = maxhf + (fhmax-fhmaxhf) / fhout
fdiag(1) = fhouthf
do i=2,maxhf
fdiag(i) = fdiag(i-1) + fhouthf
enddo
do i=maxhf+1,maxh
fdiag(i) = fdiag(i-1) + fhout
enddo
else
maxh = fhmax / fhout
do i = 2, maxh
fdiag(i) = fdiag(i-1) + fhout
enddo
endif
endif
if (mpp_pe() == mpp_root_pe()) write(6,*) "---fdiag",fdiag(1:40)
#endif
setupClock = mpp_clock_id( 'GFS Step Setup ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
radClock = mpp_clock_id( 'GFS Radiation ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
physClock = mpp_clock_id( 'GFS Physics ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
getClock = mpp_clock_id( 'Dynamics get state ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
updClock = mpp_clock_id( 'Dynamics update state ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
if (sync) then
fv3Clock = mpp_clock_id( 'FV3 Dycore ', flags=clock_flag_default+MPP_CLOCK_SYNC, grain=CLOCK_COMPONENT )
else
fv3Clock = mpp_clock_id( 'FV3 Dycore ', flags=clock_flag_default, grain=CLOCK_COMPONENT )
endif
!--- get bottom layer data from dynamical core for coupling
call atmosphere_get_bottom_layer (Atm_block, DYCORE_Data)
!if in coupled mode, set up coupled fields
if (GFS_control%cplflx .or. GFS_control%cplwav) then
if (mpp_pe() == mpp_root_pe()) print *,'COUPLING: IPD layer'
call setup_exportdata(ierr)
endif
! Set flag for first time step of time integration
GFS_control%first_time_step = .true.
!-----------------------------------------------------------------------
end subroutine atmos_model_init
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="update_atmos_model_dynamics"
!
! <OVERVIEW>
subroutine update_atmos_model_dynamics (Atmos)
! run the atmospheric dynamics to advect the properties
type (atmos_data_type), intent(in) :: Atmos
call set_atmosphere_pelist()
call mpp_clock_begin(fv3Clock)
call atmosphere_dynamics (Atmos%Time)
call mpp_clock_end(fv3Clock)
end subroutine update_atmos_model_dynamics
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="atmos_model_exchange_phase_1"
!
! <OVERVIEW>
! Perform data exchange with coupled components in run phase 1
! </OVERVIEW>
!
! <DESCRIPTION>
! This subroutine currently exports atmospheric fields and tracers
! to the chemistry component during the model's run phase 1, i.e.
! before chemistry is run.
! </DESCRIPTION>
subroutine atmos_model_exchange_phase_1 (Atmos, rc)
use ESMF
type (atmos_data_type), intent(inout) :: Atmos
integer, optional, intent(out) :: rc
!--- local variables
integer :: localrc
!--- begin
if (present(rc)) rc = ESMF_SUCCESS
!--- if coupled, exchange coupled fields
if( GFS_control%cplchm ) then
! -- export fields to chemistry
call update_atmos_chemistry('export', rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
endif
end subroutine atmos_model_exchange_phase_1
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="atmos_model_exchange_phase_2"
!
! <OVERVIEW>
! Perform data exchange with coupled components in run phase 2
! </OVERVIEW>
!
! <DESCRIPTION>
! This subroutine currently imports fields updated by the coupled
! chemistry component back into the atmospheric model during run
! phase 2.
! </DESCRIPTION>
subroutine atmos_model_exchange_phase_2 (Atmos, rc)
use ESMF
type (atmos_data_type), intent(inout) :: Atmos
integer, optional, intent(out) :: rc
!--- local variables
integer :: localrc
!--- begin
if (present(rc)) rc = ESMF_SUCCESS
!--- if coupled, exchange coupled fields
if( GFS_control%cplchm ) then
! -- import fields from chemistry
call update_atmos_chemistry('import', rc=localrc)
if (ESMF_LogFoundError(rcToCheck=localrc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__, rcToReturn=rc)) return
endif
end subroutine atmos_model_exchange_phase_2
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="update_atmos_model_state"
!
! <OVERVIEW>
subroutine update_atmos_model_state (Atmos)
! to update the model state after all concurrency is completed
type (atmos_data_type), intent(inout) :: Atmos
!--- local variables
integer :: isec, seconds, isec_fhzero
integer :: rc
real(kind=GFS_kind_phys) :: time_int, time_intfull
!
call set_atmosphere_pelist()
call mpp_clock_begin(fv3Clock)
call mpp_clock_begin(updClock)
call atmosphere_state_update (Atmos%Time, GFS_data, IAU_Data, Atm_block, flip_vc)
call mpp_clock_end(updClock)
call mpp_clock_end(fv3Clock)
if (chksum_debug) then
if (mpp_pe() == mpp_root_pe()) print *,'UPDATE STATE ', GFS_control%kdt, GFS_control%fhour
if (mpp_pe() == mpp_root_pe()) print *,'in UPDATE STATE ', size(GFS_data(1)%SfcProp%tsfc),'nblks=',Atm_block%nblks
call FV3GFS_GFS_checksum(GFS_control, GFS_data, Atm_block)
endif
!--- advance time ---
Atmos % Time = Atmos % Time + Atmos % Time_step
call get_time (Atmos%Time - diag_time, isec)
call get_time (Atmos%Time - Atmos%Time_init, seconds)
call atmosphere_nggps_diag(Atmos%Time,ltavg=.true.,avg_max_length=avg_max_length)
if (ANY(nint(fdiag(:)*3600.0) == seconds) .or. (GFS_control%kdt == first_kdt) .or. nsout > 0) then
if (mpp_pe() == mpp_root_pe()) write(6,*) "---isec,seconds",isec,seconds
time_int = real(isec)
if(Atmos%iau_offset > zero) then
if( time_int - Atmos%iau_offset*3600. > zero ) then
time_int = time_int - Atmos%iau_offset*3600.
else if(seconds == Atmos%iau_offset*3600) then
call get_time (Atmos%Time - diag_time_fhzero, isec_fhzero)
time_int = real(isec_fhzero)
if (mpp_pe() == mpp_root_pe()) write(6,*) "---iseczero",isec_fhzero
endif
endif
time_intfull = real(seconds)
if(Atmos%iau_offset > zero) then
if( time_intfull - Atmos%iau_offset*3600. > zero) then
time_intfull = time_intfull - Atmos%iau_offset*3600.
endif
endif
if (mpp_pe() == mpp_root_pe()) write(6,*) ' gfs diags time since last bucket empty: ',time_int/3600.,'hrs'
call atmosphere_nggps_diag(Atmos%Time)
call FV3GFS_diag_output(Atmos%Time, GFS_Diag, Atm_block, GFS_control%nx, GFS_control%ny, &
GFS_control%levs, 1, 1, 1.0_GFS_kind_phys, time_int, time_intfull, &
GFS_control%fhswr, GFS_control%fhlwr)
if (nint(GFS_control%fhzero) > 0) then
if (mod(isec,3600*nint(GFS_control%fhzero)) == 0) diag_time = Atmos%Time
else
if (mod(isec,nint(3600*GFS_control%fhzero)) == 0) diag_time = Atmos%Time
endif
call diag_send_complete_instant (Atmos%Time)
endif
!--- this may not be necessary once write_component is fully implemented
!!!call diag_send_complete_extra (Atmos%Time)
!--- get bottom layer data from dynamical core for coupling
call atmosphere_get_bottom_layer (Atm_block, DYCORE_Data)
!if in coupled mode, set up coupled fields
if (GFS_control%cplflx .or. GFS_control%cplwav) then
call setup_exportdata(rc)
endif
end subroutine update_atmos_model_state
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="atmos_model_end">
!
! <OVERVIEW>
! termination routine for atmospheric model
! </OVERVIEW>
! <DESCRIPTION>
! Call once to terminate this module and any other modules used.
! This routine writes a restart file and deallocates storage
! used by the derived-type variable atmos_boundary_data_type.
! </DESCRIPTION>
! <TEMPLATE>
! call atmos_model_end (Atmos)
! </TEMPLATE>
! <INOUT NAME="Atmos" TYPE="type(atmos_data_type)">
! Derived-type variable that contains fields needed by the flux exchange module.
! </INOUT>
subroutine atmos_model_end (Atmos)
type (atmos_data_type), intent(inout) :: Atmos
!---local variables
integer :: idx, seconds, ierr
!-----------------------------------------------------------------------
!---- termination routine for atmospheric model ----
call atmosphere_end (Atmos % Time, Atmos%grid, restart_endfcst)
call stochastic_physics_wrapper_end(GFS_control)
if(restart_endfcst) then
call FV3GFS_restart_write (GFS_data, GFS_restart_var, Atm_block, &
GFS_control, Atmos%domain)
endif
! Fast physics (from dynamics) are finalized in atmosphere_end above;
! standard/slow physics (from IPD) are finalized in CCPP_step 'finalize'.
! The CCPP framework for all cdata structures is finalized in CCPP_step 'finalize'.
call CCPP_step (step="finalize", nblks=Atm_block%nblks, ierr=ierr)
if (ierr/=0) call mpp_error(FATAL, 'Call to CCPP finalize step failed')
end subroutine atmos_model_end
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="atmos_model_restart">
! <DESCRIPTION>
! Write out restart files registered through register_restart_file
! </DESCRIPTION>
subroutine atmos_model_restart(Atmos, timestamp)
type (atmos_data_type), intent(inout) :: Atmos
character(len=*), intent(in) :: timestamp
call atmosphere_restart(timestamp)
call FV3GFS_restart_write (GFS_data, GFS_restart_var, Atm_block, &
GFS_control, Atmos%domain, timestamp)
end subroutine atmos_model_restart
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="get_atmos_model_ungridded_dim">
!
! <DESCRIPTION>
! Retrieve ungridded dimensions of atmospheric model arrays
! </DESCRIPTION>
subroutine get_atmos_model_ungridded_dim(nlev, nsoillev, ntracers, &
num_diag_sfc_emis_flux, num_diag_down_flux, num_diag_type_down_flux, &
num_diag_burn_emis_flux, num_diag_cmass)
integer, optional, intent(out) :: nlev, nsoillev, ntracers, &
num_diag_sfc_emis_flux, num_diag_down_flux, num_diag_type_down_flux, &
num_diag_burn_emis_flux, num_diag_cmass
!--- number of atmospheric vertical levels
if (present(nlev)) nlev = Atm_block%npz
!--- number of soil levels
if (present(nsoillev)) then
nsoillev = 0
if (allocated(GFS_data)) then
if (associated(GFS_data(1)%Sfcprop%slc)) &
nsoillev = size(GFS_data(1)%Sfcprop%slc, dim=2)
end if
end if
!--- total number of atmospheric tracers
if (present(ntracers)) call get_number_tracers(MODEL_ATMOS, num_tracers=ntracers)
!--- number of tracers used in chemistry diagnostic output
if (present(num_diag_down_flux)) then
num_diag_down_flux = 0
if (associated(GFS_data(1)%IntDiag%sedim)) &
num_diag_down_flux = size(GFS_data(1)%IntDiag%sedim, dim=2)
if (present(num_diag_type_down_flux)) then
num_diag_type_down_flux = 0
if (associated(GFS_data(1)%IntDiag%sedim)) &
num_diag_type_down_flux = num_diag_type_down_flux + 1
if (associated(GFS_data(1)%IntDiag%drydep)) &
num_diag_type_down_flux = num_diag_type_down_flux + 1
if (associated(GFS_data(1)%IntDiag%wetdpl)) &
num_diag_type_down_flux = num_diag_type_down_flux + 1
if (associated(GFS_data(1)%IntDiag%wetdpc)) &
num_diag_type_down_flux = num_diag_type_down_flux + 1
end if
end if
!--- number of bins for chemistry diagnostic output
if (present(num_diag_sfc_emis_flux)) then
num_diag_sfc_emis_flux = 0
if (associated(GFS_data(1)%IntDiag%duem)) &
num_diag_sfc_emis_flux = size(GFS_data(1)%IntDiag%duem, dim=2)
if (associated(GFS_data(1)%IntDiag%ssem)) &
num_diag_sfc_emis_flux = &
num_diag_sfc_emis_flux + size(GFS_data(1)%IntDiag%ssem, dim=2)
end if
!--- number of tracers used in emission diagnostic output
if (present(num_diag_burn_emis_flux)) then
num_diag_burn_emis_flux = 0
if (associated(GFS_data(1)%IntDiag%abem)) &
num_diag_burn_emis_flux = size(GFS_data(1)%IntDiag%abem, dim=2)
end if
!--- number of tracers used in column mass density diagnostics
if (present(num_diag_cmass)) then
num_diag_cmass = 0
if (associated(GFS_data(1)%IntDiag%aecm)) &
num_diag_cmass = size(GFS_data(1)%IntDiag%aecm, dim=2)
end if
end subroutine get_atmos_model_ungridded_dim
! </SUBROUTINE>
!#######################################################################
! <SUBROUTINE NAME="update_atmos_chemistry">
! <DESCRIPTION>
! Populate exported chemistry fields with current atmospheric state
! data (state='export'). Update tracer concentrations for atmospheric
! chemistry with values from chemistry component (state='import').
! Fields should be exported/imported from/to the atmospheric state
! after physics calculations.
!
! NOTE: It is assumed that all the chemical tracers follow the standard
! atmospheric tracers, which end with ozone. The order of the chemical
! tracers must match their order in the chemistry component.
!