forked from NOAA-GFDL/GFDL_atmos_cubed_sphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfv_dynamics.F90
1598 lines (1459 loc) · 62.2 KB
/
fv_dynamics.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 Lesser General Public License
!*
!* This file is part of the FV3 dynamical core.
!*
!* The FV3 dynamical core is free software: you can redistribute it
!* and/or modify it under the terms of the
!* GNU Lesser General Public License as published by the
!* Free Software Foundation, either version 3 of the License, or
!* (at your option) any later version.
!*
!* The FV3 dynamical core is distributed in the hope that it will be
!* useful, but WITHOUT ANYWARRANTY; without even the implied warranty
!* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
!* See the GNU General Public License for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with the FV3 dynamical core.
!* If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************
!>@brief The module 'fv_dynamics' is the top-level routine for the dynamical core.
!>@details It executes on the dt_atmos (or p_split) loop.
module fv_dynamics_mod
! Modules Included:
! <table>
! <tr>
! <th>Module Name</th>
! <th>Functions Included</th>
! </tr>
! <tr>
! <td>boundary_mod</td>
! <td>nested_grid_BC_apply_intT</td>
! </tr>
! <tr>
! <td>constants_mod</td>
! <td>grav, pi=>pi_8, radius, hlv, rdgas, omega, rvgas, cp_vapor</td>
! </tr>
! <tr>
! <td>diag_manager_mod</td>
! <td>send_data</td>
! </tr>
! <tr>
! <td>dyn_core_mod</td>
! <td>dyn_core, del2_cubed, init_ijk_mem</td>
! </tr>
! <tr>
! <td>field_manager_mod</td>
! <td>MODEL_ATMOS</td>
! </tr>
! <tr>
! <td>fv_arrays_mod</td>
! <td>fv_grid_type, fv_flags_type, fv_atmos_type, fv_nest_type, fv_diag_type, fv_grid_bounds_type</td>
! </tr>
! <tr>
! <td>fv_diagnostics_mod</td>
! <td>fv_time, prt_mxm, range_check, prt_minmax</td>
! </tr>
! <tr>
! <td>fv_fill_mod</td>
! <td>fill2D</td>
! </tr>
! <tr>
! <td>fv_grid_utils_mod</td>
! <td>cubed_to_latlon, c2l_ord2, g_sum</td>
! </tr>
! <tr>
! <td>fv_mapz_mod</td>
! <td>compute_total_energy, Lagrangian_to_Eulerian, moist_cv, moist_cp</td>
! </tr>
! <tr>
! <td>fv_mp_mod</td>
! <td>is_master,group_halo_update_type, start_group_halo_update, complete_group_halo_update</td>
! </tr>
! <tr>
! <td>fv_nesting_mod</td>
! <td>setup_nested_grid_BCs</td>
! </tr>
! <tr>
! <td>fv_nwp_mod</td>
! <td>do_adiabatic_init</td>
! </tr>
! <tr>
! <td>fv_restart_mod</td>
! <td>d2a_setup, d2c_setup</td>
! </tr>
! <tr>
! <td>fv_sg_mod</td>
! <td>neg_adj3</td>
! </tr>
! <tr>
! <td>fv_sg_mod</td>
! <td>neg_adj2</td>
! </tr>
! <tr>
! <td>fv_sg_mod</td>
! <td>neg_adj4</td>
! </tr>
! <tr>
! <td>fv_timing_mod</td>
! <td>timing_on, timing_off</td>
! </tr>
! <tr>
! <td>fv_tracer2d_mod</td>
! <td>tracer_2d, tracer_2d_1L, tracer_2d_nested</td>
! </tr>
! <tr>
! <td>mpp_mod/td>
! <td>mpp_pe</td>
! </tr>
! <tr>
! <td>mpp_domains_mod/td>
! <td>DGRID_NE, CGRID_NE, mpp_update_domains, domain2D</td>
! </tr>
! <tr>
! <td>fv_sg_mod</td>
! <td>neg_adj3</td>
! </tr>
! <tr>
! <td>fv_sg_mod</td>
! <td>neg_adj4</td>
! </tr>
! <tr>
! <td>tracer_manager_mod</td>
! <td>get_tracer_index</td>
! </tr>
! </table>
use constants_mod, only: grav, pi=>pi_8, radius, hlv, rdgas, omega, rvgas, cp_vapor
use dyn_core_mod, only: dyn_core, del2_cubed, init_ijk_mem
use fv_mapz_mod, only: compute_total_energy, Lagrangian_to_Eulerian, moist_cv, moist_cp
use fv_tracer2d_mod, only: tracer_2d, tracer_2d_1L, tracer_2d_nested
use fv_grid_utils_mod, only: cubed_to_latlon, c2l_ord2, g_sum
use fv_fill_mod, only: fill2D
use fv_mp_mod, only: is_master
use fv_mp_mod, only: group_halo_update_type
use fv_mp_mod, only: start_group_halo_update, complete_group_halo_update
use fv_timing_mod, only: timing_on, timing_off
use diag_manager_mod, only: send_data
use fv_diagnostics_mod, only: fv_time, prt_mxm, range_check, prt_minmax
use mpp_domains_mod, only: DGRID_NE, CGRID_NE, mpp_update_domains, domain2D
use mpp_mod, only: mpp_pe
use field_manager_mod, only: MODEL_ATMOS
use tracer_manager_mod, only: get_tracer_index
use fv_sg_mod, only: neg_adj3, neg_adj2, neg_adj4
use fv_nesting_mod, only: setup_nested_grid_BCs
use fv_regional_mod, only: regional_boundary_update, set_regional_BCs
use fv_regional_mod, only: dump_field, H_STAGGER, U_STAGGER, V_STAGGER
use fv_regional_mod, only: a_step, p_step, k_step
use fv_regional_mod, only: current_time_in_seconds
use boundary_mod, only: nested_grid_BC_apply_intT
use fv_arrays_mod, only: fv_grid_type, fv_flags_type, fv_atmos_type, fv_nest_type, fv_diag_type, fv_grid_bounds_type, inline_mp_type
use fv_nwp_nudge_mod, only: do_adiabatic_init
use time_manager_mod, only: get_time
#ifdef MULTI_GASES
use multi_gases_mod, only: virq, vicpq, virqd, vicpqd
#endif
implicit none
logical :: RF_initialized = .false.
logical :: pt_initialized = .false.
logical :: bad_range = .false.
real, allocatable :: rf(:)
real, allocatable :: rw(:) !< related to tau_w
integer :: kmax=1
integer :: k_rf = 0
real :: agrav
#ifdef HIWPP
real, allocatable:: u00(:,:,:), v00(:,:,:)
#endif
private
public :: fv_dynamics
contains
!-----------------------------------------------------------------------
! fv_dynamics :: FV dynamical core driver
!-----------------------------------------------------------------------
subroutine fv_dynamics(npx, npy, npz, nq_tot, ng, bdt, consv_te, fill, &
reproduce_sum, kappa, cp_air, zvir, ptop, ks, ncnst, n_split, &
q_split, u, v, w, delz, hydrostatic, pt, delp, q, &
ps, pe, pk, peln, pkz, phis, q_con, omga, ua, va, uc, vc, &
ak, bk, mfx, mfy, cx, cy, ze0, hybrid_z, &
gridstruct, flagstruct, neststruct, idiag, bd, &
parent_grid, domain, diss_est, inline_mp)
use mpp_mod, only: FATAL, mpp_error
use ccpp_static_api, only: ccpp_physics_timestep_init, &
ccpp_physics_timestep_finalize
use CCPP_data, only: ccpp_suite
use CCPP_data, only: cdata => cdata_tile
use CCPP_data, only: CCPP_interstitial
use molecular_diffusion_mod, only: md_time, md_wait_sec, md_tadj_layers, &
thermosphere_adjustment
real, intent(IN) :: bdt !< Large time-step
real, intent(IN) :: consv_te
real, intent(IN) :: kappa, cp_air
real, intent(IN) :: zvir, ptop
integer, intent(IN) :: npx
integer, intent(IN) :: npy
integer, intent(IN) :: npz
integer, intent(IN) :: nq_tot !< transported tracers
integer, intent(IN) :: ng
integer, intent(IN) :: ks
integer, intent(IN) :: ncnst
integer, intent(IN) :: n_split !< small-step horizontal dynamics
integer, intent(IN) :: q_split !< tracer
logical, intent(IN) :: fill
logical, intent(IN) :: reproduce_sum
logical, intent(IN) :: hydrostatic
logical, intent(IN) :: hybrid_z !< Using hybrid_z for remapping
type(fv_grid_bounds_type), intent(IN) :: bd
real, intent(inout), dimension(bd%isd:bd%ied ,bd%jsd:bd%jed+1,npz) :: u !< D grid zonal wind (m/s)
real, intent(inout), dimension(bd%isd:bd%ied+1,bd%jsd:bd%jed ,npz) :: v !< D grid meridional wind (m/s)
real, intent(inout) :: w( bd%isd: ,bd%jsd: ,1:) !< W (m/s)
real, intent(inout) :: pt( bd%isd:bd%ied ,bd%jsd:bd%jed ,npz) !< temperature (K)
real, intent(inout) :: delp(bd%isd:bd%ied ,bd%jsd:bd%jed ,npz) !< pressure thickness (pascal)
real, intent(inout) :: q( bd%isd:bd%ied ,bd%jsd:bd%jed ,npz, ncnst) !< specific humidity and constituents
real, intent(inout) :: delz(bd%is:,bd%js:,1:) !< delta-height (m); non-hydrostatic only
real, intent(inout) :: ze0(bd%is:, bd%js: ,1:) !< height at edges (m); non-hydrostatic
real, intent(inout), dimension(bd%isd:bd%ied ,bd%jsd:bd%jed,npz) :: diss_est! diffusion estimate for SKEB
! ze0 no longer used
!-----------------------------------------------------------------------
! Auxilliary pressure arrays:
! The 5 vars below can be re-computed from delp and ptop.
!-----------------------------------------------------------------------
! dyn_aux:
real, intent(inout) :: ps (bd%isd:bd%ied ,bd%jsd:bd%jed) !< Surface pressure (pascal)
real, intent(inout) :: pe (bd%is-1:bd%ie+1, npz+1,bd%js-1:bd%je+1) !< edge pressure (pascal)
real, intent(inout) :: pk (bd%is:bd%ie,bd%js:bd%je, npz+1) !< pe**kappa
real, intent(inout) :: peln(bd%is:bd%ie,npz+1,bd%js:bd%je) !< ln(pe)
real, intent(inout) :: pkz (bd%is:bd%ie,bd%js:bd%je,npz) !< finite-volume mean pk
real, intent(inout):: q_con(bd%isd:, bd%jsd:, 1:)
!-----------------------------------------------------------------------
! Others:
!-----------------------------------------------------------------------
real, intent(inout) :: phis(bd%isd:bd%ied,bd%jsd:bd%jed) !< Surface geopotential (g*Z_surf)
real, intent(inout) :: omga(bd%isd:bd%ied,bd%jsd:bd%jed,npz) !< Vertical pressure velocity (pa/s)
real, intent(inout) :: uc(bd%isd:bd%ied+1,bd%jsd:bd%jed ,npz) !< (uc,vc) mostly used as the C grid winds
real, intent(inout) :: vc(bd%isd:bd%ied ,bd%jsd:bd%jed+1,npz)
real, intent(inout), dimension(bd%isd:bd%ied ,bd%jsd:bd%jed ,npz):: ua, va
real, intent(in), dimension(npz+1):: ak, bk
type(inline_mp_type), intent(inout) :: inline_mp
! Accumulated Mass flux arrays: the "Flux Capacitor"
real, intent(inout) :: mfx(bd%is:bd%ie+1, bd%js:bd%je, npz)
real, intent(inout) :: mfy(bd%is:bd%ie , bd%js:bd%je+1, npz)
! Accumulated Courant number arrays
real, intent(inout) :: cx(bd%is:bd%ie+1, bd%jsd:bd%jed, npz)
real, intent(inout) :: cy(bd%isd:bd%ied ,bd%js:bd%je+1, npz)
type(fv_grid_type), intent(inout), target :: gridstruct
type(fv_flags_type), intent(INOUT) :: flagstruct
type(fv_nest_type), intent(INOUT) :: neststruct
type(domain2d), intent(INOUT) :: domain
type(fv_atmos_type), pointer, intent(IN) :: parent_grid
type(fv_diag_type), intent(IN) :: idiag
! Local Arrays
real:: ws(bd%is:bd%ie,bd%js:bd%je)
real:: teq(bd%is:bd%ie,bd%js:bd%je)
real:: ps2(bd%isd:bd%ied,bd%jsd:bd%jed)
real:: m_fac(bd%is:bd%ie,bd%js:bd%je)
real:: pfull(npz)
real, dimension(bd%is:bd%ie):: cvm
#ifdef MULTI_GASES
real, allocatable :: kapad(:,:,:)
#endif
real, save :: time_offset = -1.00
real t(bd%isd:bd%ied,bd%jsd:bd%jed)
real :: correct, aave_t1, ttsave, tdsave
real:: akap, rdg, ph1, ph2, mdt, gam, amdt, u0
real:: recip_k_split,reg_bc_update_time
integer:: kord_tracer(ncnst)
integer :: i,j,k, n, iq, n_map, nq, nr, nwat, k_split
integer :: sphum, liq_wat = -999, ice_wat = -999 ! GFDL physics
integer :: rainwat = -999, snowwat = -999, graupel = -999, hailwat = -999, cld_amt = -999
integer :: theta_d = -999
logical used, do_omega
integer, parameter :: max_packs=13
type(group_halo_update_type), save :: i_pack(max_packs)
integer :: is, ie, js, je
integer :: isd, ied, jsd, jed
real :: dt2
integer :: ierr
real :: time_total
integer :: seconds, days
ccpp_associate: associate( cappa => CCPP_interstitial%cappa, &
dp1 => CCPP_interstitial%te0, &
dtdt_m => CCPP_interstitial%dtdt, &
last_step => CCPP_interstitial%last_step, &
te_2d => CCPP_interstitial%te0_2d )
is = bd%is
ie = bd%ie
js = bd%js
je = bd%je
isd = bd%isd
ied = bd%ied
jsd = bd%jsd
jed = bd%jed
! cv_air = cp_air - rdgas
agrav = 1. / grav
dt2 = 0.5*bdt
k_split = flagstruct%k_split
recip_k_split=1./real(k_split)
nwat = flagstruct%nwat
nq = nq_tot - flagstruct%dnats
nr = nq_tot - flagstruct%dnrts
rdg = -rdgas * agrav
! Call CCPP timestep init
call ccpp_physics_timestep_init(cdata, suite_name=trim(ccpp_suite), group_name="fast_physics", ierr=ierr)
! Reset all interstitial variables for CCPP version
! of fast physics, and manually set runtime parameters
call CCPP_interstitial%reset()
if (flagstruct%do_sat_adj) then
CCPP_interstitial%out_dt = (idiag%id_mdt > 0)
end if
#ifdef MULTI_GASES
allocate ( kapad(isd:ied, jsd:jed, npz) )
call init_ijk_mem(isd,ied, jsd,jed, npz, kapad, kappa)
#endif
if (flagstruct%molecular_diffusion ) then
call get_time(fv_time, seconds, days)
time_total = seconds + 86400. * days
if( time_offset .lt. 0.0) time_offset = time_total
endif
!We call this BEFORE converting pt to virtual potential temperature,
!since we interpolate on (regular) temperature rather than theta.
if (gridstruct%nested .or. ANY(neststruct%child_grids)) then
call timing_on('NEST_BCs')
call setup_nested_grid_BCs(npx, npy, npz, zvir, ncnst, &
u, v, w, pt, delp, delz, q, uc, vc, &
#ifdef USE_COND
q_con, &
#ifdef MOIST_CAPPA
cappa, &
#endif
#endif
neststruct%nested, flagstruct%inline_q, flagstruct%make_nh, ng, &
gridstruct, flagstruct, neststruct, &
neststruct%nest_timestep, neststruct%tracer_nest_timestep, &
domain, parent_grid, bd, nwat, ak, bk)
call timing_off('NEST_BCs')
endif
! For the regional domain set values valid the beginning of the
! current large timestep at the boundary points of the pertinent
! prognostic arrays.
if (flagstruct%regional) then
call timing_on('Regional_BCs')
reg_bc_update_time=current_time_in_seconds
call set_regional_BCs & !<-- Insert values into the boundary region valid for the start of this large timestep.
(delp,delz,w,pt &
#ifdef USE_COND
,q_con &
#endif
#ifdef MOIST_CAPPA
,cappa &
#endif
,q,u,v,uc,vc, bd, npz, reg_bc_update_time )
call timing_off('Regional_BCs')
endif
if ( flagstruct%no_dycore ) then
if ( nwat.eq.2 .and. (.not.hydrostatic) ) then
sphum = get_tracer_index (MODEL_ATMOS, 'sphum')
endif
goto 911
endif
if ( nwat==0 ) then
sphum = 1
cld_amt = -1 ! to cause trouble if (mis)used
else
sphum = get_tracer_index (MODEL_ATMOS, 'sphum')
liq_wat = get_tracer_index (MODEL_ATMOS, 'liq_wat')
ice_wat = get_tracer_index (MODEL_ATMOS, 'ice_wat')
rainwat = get_tracer_index (MODEL_ATMOS, 'rainwat')
snowwat = get_tracer_index (MODEL_ATMOS, 'snowwat')
graupel = get_tracer_index (MODEL_ATMOS, 'graupel')
hailwat = get_tracer_index (MODEL_ATMOS, 'hailwat')
cld_amt = get_tracer_index (MODEL_ATMOS, 'cld_amt')
endif
theta_d = get_tracer_index (MODEL_ATMOS, 'theta_d')
#ifdef SW_DYNAMICS
akap = 1.
pfull(1) = 0.5*flagstruct%p_ref
#else
akap = kappa
!$OMP parallel do default(none) shared(npz,ak,bk,flagstruct,pfull) &
!$OMP private(ph1, ph2,k)
do k=1,npz
ph1 = ak(k ) + bk(k )*flagstruct%p_ref
ph2 = ak(k+1) + bk(k+1)*flagstruct%p_ref
pfull(k) = (ph2 - ph1) / log(ph2/ph1)
enddo
if ( hydrostatic ) then
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,isd,ied,jsd,jed,npz,zvir,nwat,q,q_con,sphum,liq_wat, &
#else
!$OMP parallel do default(none) shared(is,ie,js,je,isd,ied,jsd,jed,npz,dp1,zvir,nwat,q,q_con,sphum,liq_wat, &
#endif
!$OMP rainwat,ice_wat,snowwat,graupel,hailwat) private(cvm,i,j,k)
do k=1,npz
do j=js,je
#ifdef USE_COND
call moist_cp(is,ie,isd,ied,jsd,jed, npz, j, k, nwat, sphum, liq_wat, rainwat, &
ice_wat, snowwat, graupel, hailwat, q, q_con(is:ie,j,k), cvm)
#endif
do i=is,ie
dp1(i,j,k) = zvir*q(i,j,k,sphum)
enddo
enddo
enddo
else
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,isd,ied,jsd,jed,npz,zvir,q,q_con,sphum,liq_wat, &
#else
!$OMP parallel do default(none) shared(is,ie,js,je,isd,ied,jsd,jed,npz,dp1,zvir,q,q_con,sphum,liq_wat, &
#endif
!$OMP rainwat,ice_wat,snowwat,graupel,hailwat,pkz,flagstruct, &
#ifdef MULTI_GASES
!$OMP kapad, &
#endif
#ifdef __GFORTRAN__
!$OMP kappa,rdg,delp,pt,delz,nwat) &
#else
!$OMP cappa,kappa,rdg,delp,pt,delz,nwat) &
#endif
!$OMP private(cvm,i,j,k)
do k=1,npz
if ( flagstruct%moist_phys ) then
do j=js,je
#ifdef MOIST_CAPPA
call moist_cv(is,ie,isd,ied,jsd,jed, npz, j, k, nwat, sphum, liq_wat, rainwat, &
ice_wat, snowwat, graupel, hailwat, q, q_con(is:ie,j,k), cvm)
#endif
do i=is,ie
#ifdef MULTI_GASES
dp1(i,j,k) = virq(q(i,j,k,:))-1.
kapad(i,j,k)= kappa * (virqd(q(i,j,k,:))/vicpqd(q(i,j,k,:)))
#else
dp1(i,j,k) = zvir*q(i,j,k,sphum)
#endif
#ifdef MOIST_CAPPA
cappa(i,j,k) = rdgas/(rdgas + cvm(i)/(1.+dp1(i,j,k)))
pkz(i,j,k) = exp(cappa(i,j,k)*log(rdg*delp(i,j,k)*pt(i,j,k)* &
#ifdef MULTI_GASES
(1.+dp1(i,j,k)) /delz(i,j,k)) )
#else
(1.+dp1(i,j,k))*(1.-q_con(i,j,k))/delz(i,j,k)) )
#endif
#else
pkz(i,j,k) = exp( kappa*log(rdg*delp(i,j,k)*pt(i,j,k)* &
(1.+dp1(i,j,k))/delz(i,j,k)) )
! Using dry pressure for the definition of the virtual potential temperature
! pkz(i,j,k) = exp( kappa*log(rdg*delp(i,j,k)*pt(i,j,k)* &
! (1.-q(i,j,k,sphum))/delz(i,j,k)) )
#endif
enddo
enddo
else
do j=js,je
do i=is,ie
dp1(i,j,k) = 0.
#ifdef MULTI_GASES
kapad(i,j,k)= kappa * (virqd(q(i,j,k,:))/vicpqd(q(i,j,k,:)))
pkz(i,j,k) = exp(kapad(i,j,k)*log(rdg*virqd(q(i,j,k,:))*delp(i,j,k)*pt(i,j,k)/delz(i,j,k)))
#else
pkz(i,j,k) = exp(kappa*log(rdg*delp(i,j,k)*pt(i,j,k)/delz(i,j,k)))
#endif
enddo
enddo
endif
enddo
endif
if ( flagstruct%fv_debug ) then
#ifdef MOIST_CAPPA
call prt_mxm('cappa', cappa, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
#endif
call prt_mxm('PS', ps, is, ie, js, je, ng, 1, 0.01, gridstruct%area_64, domain)
call prt_mxm('T_dyn_b', pt, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
if ( .not. hydrostatic) call prt_mxm('delz', delz, is, ie, js, je, 0, npz, 1., gridstruct%area_64, domain)
call prt_mxm('delp_b ', delp, is, ie, js, je, ng, npz, 0.01, gridstruct%area_64, domain)
call prt_mxm('pk_b', pk, is, ie, js, je, 0, npz+1, 1.,gridstruct%area_64, domain)
call prt_mxm('pkz_b', pkz,is, ie, js, je, 0, npz, 1.,gridstruct%area_64, domain)
endif
!---------------------
! Compute Total Energy
!---------------------
if ( (consv_te > 0. .or. idiag%id_te>0) .and. (.not.do_adiabatic_init) ) then
call compute_total_energy(is, ie, js, je, isd, ied, jsd, jed, npz, &
u, v, w, delz, pt, delp, q, dp1, pe, peln, phis, &
gridstruct%rsin2, gridstruct%cosa_s, &
zvir, cp_air, rdgas, hlv, te_2d, ua, va, teq, &
flagstruct%moist_phys, nwat, sphum, liq_wat, rainwat, &
ice_wat, snowwat, graupel, hailwat, hydrostatic, idiag%id_te)
if( idiag%id_te>0 ) then
used = send_data(idiag%id_te, teq, fv_time)
! te_den=1.E-9*g_sum(teq, is, ie, js, je, ng, area, 0)/(grav*4.*pi*radius**2)
! if(is_master()) write(*,*) 'Total Energy Density (Giga J/m**2)=',te_den
endif
endif
if( (flagstruct%consv_am .or. idiag%id_amdt>0) .and. (.not.do_adiabatic_init) ) then
call compute_aam(npz, is, ie, js, je, isd, ied, jsd, jed, gridstruct, bd, &
ptop, ua, va, u, v, delp, teq, ps2, m_fac)
endif
if( .not.flagstruct%RF_fast .and. flagstruct%tau .ne. 0. ) then
if ( gridstruct%grid_type<4 .or. gridstruct%bounded_domain ) then
! if ( flagstruct%RF_fast ) then
! call Ray_fast(abs(dt), npx, npy, npz, pfull, flagstruct%tau, u, v, w, &
! dp_ref, ptop, hydrostatic, flagstruct%rf_cutoff, bd)
! else
call Rayleigh_Super(abs(bdt), npx, npy, npz, ks, pfull, phis, flagstruct%tau, flagstruct%tau_w, u, v, w, pt, &
#ifdef MULTI_GASES
q, ncnst, &
#endif
ua, va, delz, gridstruct%agrid, cp_air, rdgas, ptop, hydrostatic, &
.not. gridstruct%bounded_domain, flagstruct%molecular_diffusion, consv_te, flagstruct%rf_cutoff, gridstruct, domain, bd)
! endif
else
call Rayleigh_Friction(abs(bdt), npx, npy, npz, ks, pfull, flagstruct%tau, u, v, w, pt, &
ua, va, delz, cp_air, rdgas, ptop, hydrostatic, .true., flagstruct%rf_cutoff, gridstruct, domain, bd)
endif
endif
#endif
#ifndef SW_DYNAMICS
! Convert pt to virtual potential temperature on the first timestep
if ( flagstruct%adiabatic .and. flagstruct%kord_tm>0 ) then
if ( .not.pt_initialized )then
!$OMP parallel do default(none) shared(theta_d,is,ie,js,je,npz,pt,pkz,q)
do k=1,npz
do j=js,je
do i=is,ie
pt(i,j,k) = pt(i,j,k)/pkz(i,j,k)
enddo
enddo
if ( theta_d>0 ) then
do j=js,je
do i=is,ie
q(i,j,k,theta_d) = pt(i,j,k)
enddo
enddo
endif
enddo
pt_initialized = .true.
endif
else
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,npz,pt,pkz,q_con)
#else
!$OMP parallel do default(none) shared(is,ie,js,je,npz,pt,dp1,pkz,q_con)
#endif
do k=1,npz
do j=js,je
do i=is,ie
#ifdef MULTI_GASES
pt(i,j,k) = pt(i,j,k)*(1.+dp1(i,j,k))/pkz(i,j,k)
#else
#ifdef USE_COND
pt(i,j,k) = pt(i,j,k)*(1.+dp1(i,j,k))*(1.-q_con(i,j,k))/pkz(i,j,k)
#else
pt(i,j,k) = pt(i,j,k)*(1.+dp1(i,j,k))/pkz(i,j,k)
#endif
#endif
enddo
enddo
enddo
endif
#endif
last_step = .false.
mdt = bdt / real(k_split)
if ( idiag%id_mdt > 0 .and. (.not. do_adiabatic_init) ) then
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,npz)
#else
!$OMP parallel do default(none) shared(is,ie,js,je,npz,dtdt_m)
#endif
do k=1,npz
do j=js,je
do i=is,ie
dtdt_m(i,j,k) = 0.
enddo
enddo
enddo
endif
call timing_on('FV_DYN_LOOP')
do n_map=1, k_split ! first level of time-split
k_step = n_map
call timing_on('COMM_TOTAL')
#ifdef USE_COND
call start_group_halo_update(i_pack(11), q_con, domain)
#ifdef MOIST_CAPPA
call start_group_halo_update(i_pack(12), cappa, domain)
#endif
#endif
#ifdef MULTI_GASES
call start_group_halo_update(i_pack(13), kapad, domain)
#endif
call start_group_halo_update(i_pack(1), delp, domain, complete=.false.)
call start_group_halo_update(i_pack(1), pt, domain, complete=.true.)
#ifndef ROT3
call start_group_halo_update(i_pack(8), u, v, domain, gridtype=DGRID_NE)
#endif
call timing_off('COMM_TOTAL')
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,delp)
#else
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,dp1,delp)
#endif
do k=1,npz
do j=jsd,jed
do i=isd,ied
dp1(i,j,k) = delp(i,j,k)
enddo
enddo
enddo
if ( flagstruct%trdm2 > 1.e-4 ) then
call start_group_halo_update(i_pack(13), dp1, domain)
endif
if ( n_map==k_split ) last_step = .true.
#ifdef USE_COND
call timing_on('COMM_TOTAL')
call complete_group_halo_update(i_pack(11), domain)
#ifdef MOIST_CAPPA
call complete_group_halo_update(i_pack(12), domain)
#endif
call timing_off('COMM_TOTAL')
#endif
#ifdef MULTI_GASES
call complete_group_halo_update(i_pack(13), domain)
#endif
call timing_on('DYN_CORE')
call dyn_core(npx, npy, npz, ng, sphum, nq, mdt, n_map, n_split, zvir, cp_air, akap, cappa, &
#ifdef MULTI_GASES
kapad, &
#endif
grav, hydrostatic, &
u, v, w, delz, pt, q, delp, pe, pk, phis, ws, omga, ptop, pfull, ua, va, &
uc, vc, mfx, mfy, cx, cy, pkz, peln, q_con, ak, bk, ks, &
gridstruct, flagstruct, neststruct, idiag, bd, &
domain, n_map==1, i_pack, last_step, diss_est,time_total)
call timing_off('DYN_CORE')
#ifdef SW_DYNAMICS
!!$OMP parallel do default(none) shared(is,ie,js,je,ps,delp,agrav)
do j=js,je
do i=is,ie
ps(i,j) = delp(i,j,1) * agrav
enddo
enddo
#else
if( .not. flagstruct%inline_q .and. nq /= 0 ) then
!--------------------------------------------------------
! Perform large-time-step scalar transport using the accumulated CFL and
! mass fluxes
call timing_on('tracer_2d')
!!! CLEANUP: merge these two calls?
if (gridstruct%bounded_domain) then
call tracer_2d_nested(q, dp1, mfx, mfy, cx, cy, gridstruct, bd, domain, npx, npy, npz, nq, &
flagstruct%hord_tr, q_split, mdt, idiag%id_divg, i_pack(10), i_pack(13), &
flagstruct%nord_tr, flagstruct%trdm2, &
k_split, neststruct, parent_grid, n_map, flagstruct%lim_fac)
else
if ( flagstruct%z_tracer ) then
call tracer_2d_1L(q, dp1, mfx, mfy, cx, cy, gridstruct, bd, domain, npx, npy, npz, nq, &
flagstruct%hord_tr, q_split, mdt, idiag%id_divg, i_pack(10), i_pack(13), &
flagstruct%nord_tr, flagstruct%trdm2, flagstruct%lim_fac)
else
call tracer_2d(q, dp1, mfx, mfy, cx, cy, gridstruct, bd, domain, npx, npy, npz, nq, &
flagstruct%hord_tr, q_split, mdt, idiag%id_divg, i_pack(10), i_pack(13), &
flagstruct%nord_tr, flagstruct%trdm2, flagstruct%lim_fac)
endif
endif
call timing_off('tracer_2d')
#ifdef FILL2D
if ( flagstruct%hord_tr<8 .and. flagstruct%moist_phys ) then
call timing_on('Fill2D')
if ( liq_wat > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,liq_wat), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
if ( rainwat > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,rainwat), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
if ( ice_wat > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,ice_wat), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
if ( snowwat > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,snowwat), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
if ( graupel > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,graupel), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
if ( hailwat > 0 ) &
call fill2D(is, ie, js, je, ng, npz, q(isd,jsd,1,hailwat), delp, gridstruct%area, domain, gridstruct%bounded_domain, npx, npy)
call timing_off('Fill2D')
endif
#endif
if( last_step .and. idiag%id_divg>0 ) then
used = send_data(idiag%id_divg, dp1, fv_time)
if(flagstruct%fv_debug) call prt_mxm('divg', dp1, is, ie, js, je, 0, npz, 1.,gridstruct%area_64, domain)
endif
endif
if ( npz > 4 ) then
!------------------------------------------------------------------------
! Perform vertical remapping from Lagrangian control-volume to
! the Eulerian coordinate as specified by the routine set_eta.
! Note that this finite-volume dycore is otherwise independent of the vertical
! Eulerian coordinate.
!------------------------------------------------------------------------
do iq=1,nr
kord_tracer(iq) = flagstruct%kord_tr
if ( iq==cld_amt ) kord_tracer(iq) = 9 ! monotonic
enddo
do_omega = hydrostatic .and. last_step
call timing_on('Remapping')
#ifdef AVEC_TIMERS
call avec_timer_start(6)
#endif
call Lagrangian_to_Eulerian(last_step, consv_te, ps, pe, delp, &
pkz, pk, mdt, bdt, npx, npy, npz, is,ie,js,je, isd,ied,jsd,jed, &
nr, nwat, sphum, q_con, u, v, w, delz, pt, q, phis, &
zvir, cp_air, akap, cappa, flagstruct%kord_mt, flagstruct%kord_wz, &
kord_tracer, flagstruct%kord_tm, peln, te_2d, &
ng, ua, va, omga, dp1, ws, fill, reproduce_sum, &
idiag%id_mdt>0, dtdt_m, ptop, ak, bk, pfull, gridstruct, domain, &
flagstruct%do_sat_adj, hydrostatic, flagstruct%phys_hydrostatic, &
hybrid_z, do_omega, &
flagstruct%adiabatic, do_adiabatic_init, flagstruct%do_inline_mp, &
inline_mp, flagstruct%c2l_ord, bd, flagstruct%fv_debug, &
flagstruct%moist_phys)
if ( flagstruct%molecular_diffusion ) then
! do thermosphere adjustment if it is turned on and at last_step.
if( md_tadj_layers .gt.0 .and. md_time .and. last_step ) then
call thermosphere_adjustment(domain,gridstruct,npz,bd,ng,pt)
endif ! md_tadj_layers>0 and md_time and last_step
endif
if ( flagstruct%fv_debug ) then
if (is_master()) write(*,'(A, I3, A1, I3)') 'finished k_split ', n_map, '/', k_split
call prt_mxm('T_dyn_a4', pt, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
if (sphum > 0) call prt_mxm('SPHUM_dyn', q(isd,jsd,1,sphum ), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (liq_wat > 0) call prt_mxm('liq_wat_dyn', q(isd,jsd,1,liq_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (rainwat > 0) call prt_mxm('rainwat_dyn', q(isd,jsd,1,rainwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (ice_wat > 0) call prt_mxm('ice_wat_dyn', q(isd,jsd,1,ice_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (snowwat > 0) call prt_mxm('snowwat_dyn', q(isd,jsd,1,snowwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (graupel > 0) call prt_mxm('graupel_dyn', q(isd,jsd,1,graupel), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
if (hailwat > 0) call prt_mxm('hailwat_dyn', q(isd,jsd,1,hailwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
endif
#ifdef AVEC_TIMERS
call avec_timer_stop(6)
#endif
call timing_off('Remapping')
#ifdef MOIST_CAPPA
if ( neststruct%nested .and. .not. last_step) then
call nested_grid_BC_apply_intT(cappa, &
0, 0, npx, npy, npz, bd, real(n_map+1), real(k_split), &
neststruct%cappa_BC, bctype=neststruct%nestbctype )
endif
if ( flagstruct%regional .and. .not. last_step) then
reg_bc_update_time=current_time_in_seconds+(n_map+1)*mdt
call regional_boundary_update(cappa, 'cappa', &
isd, ied, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time )
endif
#endif
if( last_step ) then
if( .not. hydrostatic ) then
!$OMP parallel do default(none) shared(is,ie,js,je,npz,omga,delp,delz,w)
do k=1,npz
do j=js,je
do i=is,ie
omga(i,j,k) = delp(i,j,k)/delz(i,j,k)*w(i,j,k)
enddo
enddo
enddo
endif
!--------------------------
! Filter omega for physics:
!--------------------------
if(flagstruct%nf_omega>0) &
call del2_cubed(omga, 0.18*gridstruct%da_min, gridstruct, domain, npx, npy, npz, flagstruct%nf_omega, bd)
endif
end if
#endif
enddo ! n_map loop
call timing_off('FV_DYN_LOOP')
if ( flagstruct%molecular_diffusion ) then
if( .not. md_time .and. time_total - time_offset .gt. md_wait_sec ) then
md_time= .true.
if( is_master() ) write(*,*) 'Molecular diffusion is on with explicit scheme '
endif
endif
if ( idiag%id_mdt > 0 .and. (.not.do_adiabatic_init) ) then
! Output temperature tendency due to inline moist physics:
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,npz,bdt)
#else
!$OMP parallel do default(none) shared(is,ie,js,je,npz,dtdt_m,bdt)
#endif
do k=1,npz
do j=js,je
do i=is,ie
dtdt_m(i,j,k) = dtdt_m(i,j,k) / bdt * 86400.
enddo
enddo
enddo
! call prt_mxm('Fast DTDT (deg/Day)', dtdt_m, is, ie, js, je, 0, npz, 1., gridstruct%area_64, domain)
used = send_data(idiag%id_mdt, dtdt_m, fv_time)
endif
if( nwat==7 ) then
if (cld_amt > 0) then
call neg_adj4(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
q(isd,jsd,1,graupel), &
q(isd,jsd,1,hailwat), &
q(isd,jsd,1,cld_amt), flagstruct%check_negative)
else
call neg_adj4(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
q(isd,jsd,1,graupel), &
q(isd,jsd,1,hailwat), check_negative=flagstruct%check_negative)
endif
if ( flagstruct%fv_debug ) then
call prt_mxm('T_dyn_a3', pt, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
call prt_mxm('SPHUM_dyn', q(isd,jsd,1,sphum ), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('liq_wat_dyn', q(isd,jsd,1,liq_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('rainwat_dyn', q(isd,jsd,1,rainwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('ice_wat_dyn', q(isd,jsd,1,ice_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('snowwat_dyn', q(isd,jsd,1,snowwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('graupel_dyn', q(isd,jsd,1,graupel), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
IF ( hailwat > 0 ) call prt_mxm('hailwat_dyn', q(isd,jsd,1,hailwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
endif
endif
if( nwat == 6 ) then
if (cld_amt > 0) then
call neg_adj3(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
q(isd,jsd,1,graupel), &
q(isd,jsd,1,cld_amt), flagstruct%check_negative)
else
call neg_adj3(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
q(isd,jsd,1,graupel), check_negative=flagstruct%check_negative)
endif
if ( flagstruct%fv_debug ) then
call prt_mxm('T_dyn_a3', pt, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
call prt_mxm('SPHUM_dyn', q(isd,jsd,1,sphum ), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('liq_wat_dyn', q(isd,jsd,1,liq_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('rainwat_dyn', q(isd,jsd,1,rainwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('ice_wat_dyn', q(isd,jsd,1,ice_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('snowwat_dyn', q(isd,jsd,1,snowwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('graupel_dyn', q(isd,jsd,1,graupel), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
endif
endif
if( nwat == 5 ) then
if (cld_amt > 0) then
call neg_adj2(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
q(isd,jsd,1,cld_amt), flagstruct%check_negative)
else
call neg_adj2(is, ie, js, je, ng, npz, &
flagstruct%hydrostatic, &
peln, delz, &
pt, delp, q(isd,jsd,1,sphum), &
q(isd,jsd,1,liq_wat), &
q(isd,jsd,1,rainwat), &
q(isd,jsd,1,ice_wat), &
q(isd,jsd,1,snowwat), &
check_negative=flagstruct%check_negative)
endif
if ( flagstruct%fv_debug ) then
call prt_mxm('T_dyn_a3', pt, is, ie, js, je, ng, npz, 1., gridstruct%area_64, domain)
call prt_mxm('SPHUM_dyn', q(isd,jsd,1,sphum ), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('liq_wat_dyn', q(isd,jsd,1,liq_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('rainwat_dyn', q(isd,jsd,1,rainwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('ice_wat_dyn', q(isd,jsd,1,ice_wat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
call prt_mxm('snowwat_dyn', q(isd,jsd,1,snowwat), is, ie, js, je, ng, npz, 1.,gridstruct%area_64, domain)
endif
endif
if( (flagstruct%consv_am.or.idiag%id_amdt>0.or.idiag%id_aam>0) .and. (.not.do_adiabatic_init) ) then
call compute_aam(npz, is, ie, js, je, isd, ied, jsd, jed, gridstruct, bd, &
ptop, ua, va, u, v, delp, te_2d, ps, m_fac)
if( idiag%id_aam>0 ) then
used = send_data(idiag%id_aam, te_2d, fv_time)
endif
if ( idiag%id_aam>0 .or. flagstruct%consv_am ) then
if ( prt_minmax ) then
gam = g_sum( domain, te_2d, is, ie, js, je, ng, gridstruct%area_64, 0)
if( is_master() ) write(6,*) 'Total AAM =', gam
endif
endif
endif
if( (flagstruct%consv_am.or.idiag%id_amdt>0) .and. (.not.do_adiabatic_init) ) then
#ifdef __GFORTRAN__
!$OMP parallel do default(none) shared(is,ie,js,je,teq,dt2,ps2,ps,idiag)
#else
!$OMP parallel do default(none) shared(is,ie,js,je,te_2d,teq,dt2,ps2,ps,idiag)
#endif
do j=js,je
do i=is,ie
! Note: the mountain torque computation contains also numerical error
! The numerical error is mostly from the zonal gradient of the terrain (zxg)
te_2d(i,j) = te_2d(i,j)-teq(i,j) + dt2*(ps2(i,j)+ps(i,j))*idiag%zxg(i,j)
enddo
enddo
if( idiag%id_amdt>0 ) used = send_data(idiag%id_amdt, te_2d/bdt, fv_time)
if ( flagstruct%consv_am .or. prt_minmax ) then
amdt = g_sum( domain, te_2d, is, ie, js, je, ng, gridstruct%area_64, 0, reproduce=.true.)
u0 = -radius*amdt/g_sum( domain, m_fac, is, ie, js, je, ng, gridstruct%area_64, 0,reproduce=.true.)
if(is_master() .and. prt_minmax) &