forked from NOAA-EMC/GFDL_atmos_cubed_sphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdyn_core.F90
2977 lines (2652 loc) · 104 KB
/
dyn_core.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 'dyn_core' peforms the Lagrangian acoustic dynamics
!! described by \cite lin2004vertically.
!>@details The forward timestep is handled by routines in 'sw_core.F90'.
!! The backwards-in-time PGF is evaluated in one_grad_p or split_p_grad (hydrostatic) and nh_p_grad (nonhydrostatic)
!! see \cite lin1997explicit.
!! The nonhydrostatic components are handled by 'nh_core.F90'.
module dyn_core_mod
! <table>
! <tr>
! <th>Module Name</th>
! <th>Functions Included</th>
! </tr>
! <tr>
! <td>a2b_edge_mod</td>
! <td>a2b_ord2, a2b_ord4</td>
! </tr>
! <tr>
! <td>boundary_mod</td>
! <td>extrapolation_BC, nested_grid_BC_apply_intT</td>
! </tr>
! <tr>
! <td>constants_mod</td>
! <td>rdgas, radius, cp_air, pi</td>
! </tr>
! <tr>
! <td>diag_manager_mod</td>
! <td>send_data</td>
! </tr>
! <tr>
! <td>fv_ada_nudge_mod</td>
! <td>breed_slp_inline_ada</td>
! </tr>
! <tr>
! <td>fv_arrays_mod</td>
! <td>fv_grid_type, fv_flags_type, fv_nest_type,
! fv_diag_type,fv_grid_bounds_type, R_GRID </td>
! </tr>
! <tr>
! <td>fv_diagnostics_mod</td>
! <td>prt_maxmin, fv_time, prt_mxm</td>
! </tr>
! <tr>
! <td>fv_mp_mod</td>
! <td>is_master, start_group_halo_update,
! complete_group_halo_update,group_halo_update_type</td>
! </tr>
! <tr>
! <td>fv_nwp_nudge_mod</td>
! <td>breed_slp_inline, do_adiabatic_init</td>
! </tr>
! <tr>
! <td>fv_timing_mod</td>
! <td>timing_on, timing_off</td>
! </tr>
! <tr>
! <td>fv_update_phys_mod</td>
! <td>update_dwinds_phys</td>
! </tr>
! <tr>
! <td>mpp_mod</td>
! <td>mpp_pe </td>
! </tr>
! <tr>
! <td>mpp_domains_mod</td>
! <td>CGRID_NE, DGRID_NE, mpp_get_boundary, mpp_update_domains,domain2d</td>
! </tr>
! <tr>
! <td>mpp_parameter_mod</td>
! <td>CORNER</td>
! </tr>
! <tr>
! <td>nh_core_mod</td>
! <td>Riem_Solver3, Riem_Solver_C, update_dz_c, update_dz_d, nest_halo_nh</td>
! </tr>
! <tr>
! <td>test_cases_mod</td>
! <td>test_case, case9_forcing1, case9_forcing2</td>
! </tr>
! <tr>
! <td>tp_core_mod</td>
! <td>copy_corners</td>
! </tr>
! </table>
use constants_mod, only: rdgas, radius, cp_air, pi
use mpp_mod, only: mpp_pe
use mpp_domains_mod, only: CGRID_NE, DGRID_NE, mpp_get_boundary, mpp_update_domains, &
domain2d
use mpp_parameter_mod, only: CORNER
use fv_mp_mod, only: is_master
use fv_mp_mod, only: start_group_halo_update, complete_group_halo_update
use fv_mp_mod, only: group_halo_update_type
use molecular_diffusion_mod, &
only: md_time, md_layers, md_consv_te, md_tadj_layers
use sw_core_mod, only: c_sw, d_sw, d_md
use a2b_edge_mod, only: a2b_ord2, a2b_ord4
use nh_core_mod, only: Riem_Solver3, Riem_Solver_C, update_dz_c, update_dz_d, nh_bc
use tp_core_mod, only: copy_corners
use fv_timing_mod, only: timing_on, timing_off
use fv_diagnostics_mod, only: prt_maxmin, fv_time, prt_mxm
use fv_diag_column_mod, only: do_diag_debug_dyn, debug_column_dyn
#ifdef ROT3
use fv_update_phys_mod, only: update_dwinds_phys
#endif
#if defined (ADA_NUDGE)
use fv_ada_nudge_mod, only: breed_slp_inline_ada
#else
use fv_nwp_nudge_mod, only: breed_slp_inline, do_adiabatic_init
#endif
use diag_manager_mod, only: send_data
use fv_arrays_mod, only: fv_grid_type, fv_flags_type, fv_nest_type, fv_diag_type, &
fv_grid_bounds_type, R_GRID, fv_nest_BC_type_3d
use boundary_mod, only: extrapolation_BC, nested_grid_BC_apply_intT
use fv_regional_mod, only: regional_boundary_update
use fv_regional_mod, only: current_time_in_seconds, bc_time_interval
use fv_regional_mod, only: delz_regBC ! TEMPORARY --- lmh
#ifdef SW_DYNAMICS
use test_cases_mod, only: test_case, case9_forcing1, case9_forcing2
#endif
#ifdef MULTI_GASES
use multi_gases_mod, only: virqd, vicpqd, vicvqd, virq, vicvq
#endif
use fv_regional_mod, only: dump_field, exch_uv, H_STAGGER, U_STAGGER, V_STAGGER
use fv_regional_mod, only: a_step, p_step, k_step, n_step
implicit none
private
public :: dyn_core, del2_cubed, init_ijk_mem
real :: ptk, peln1, rgrav
real :: d3_damp
real, allocatable, dimension(:,:,:) :: ut, vt, crx, cry, xfx, yfx, divgd, &
zh, du, dv, pkc, delpc, pk3, ptc, gz
! real, parameter:: delt_max = 1.e-1 ! Max dissipative heating/cooling rate
! 6 deg per 10-min
real(kind=R_GRID), parameter :: cnst_0p20=0.20d0
real, allocatable :: rf(:)
integer:: k_rf = 0
logical:: RFF_initialized = .false.
logical:: first_call = .true.
integer :: kmax=1
real, parameter :: rad2deg = 180./pi
contains
!-----------------------------------------------------------------------
! dyn_core :: FV Lagrangian dynamics driver
!-----------------------------------------------------------------------
subroutine dyn_core(npx, npy, npz, ng, sphum, nq, bdt, n_map, n_split, zvir, cp, 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, &
init_step, i_pack, end_step, diss_est,time_total)
integer, intent(IN) :: npx
integer, intent(IN) :: npy
integer, intent(IN) :: npz
integer, intent(IN) :: ng, nq, sphum
integer, intent(IN) :: n_map, n_split
real , intent(IN) :: bdt
real , intent(IN) :: zvir, cp, akap, grav
real , intent(IN) :: ptop
logical, intent(IN) :: hydrostatic
logical, intent(IN) :: init_step, end_step
real, intent(in) :: pfull(npz)
real, intent(in), dimension(npz+1) :: ak, bk
integer, intent(IN) :: ks
type(group_halo_update_type), intent(inout) :: i_pack(*)
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:) !< vertical vel. (m/s)
real, intent(inout) :: delz(bd%is:,bd%js:,1:) !< delta-height (m, negative)
real, intent(inout) :: cappa(bd%isd:bd%ied,bd%jsd:bd%jed,1:npz) !< moist kappa
#ifdef MULTI_GASES
real, intent(inout) :: kapad(bd%isd:bd%ied,bd%jsd:bd%jed,1:npz) !< multi_gases kappa
#endif
real, intent(inout) :: pt( bd%isd:bd%ied ,bd%jsd:bd%jed ,npz) !< potential 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, nq) !
real, intent(in), optional:: time_total !< total time (seconds) since start
real, intent(inout) :: diss_est(bd%isd:bd%ied ,bd%jsd:bd%jed ,npz) !< skeb dissipation estimate
!-----------------------------------------------------------------------
! Auxilliary pressure arrays:
! The 5 vars below can be re-computed from delp and ptop.
!-----------------------------------------------------------------------
! dyn_aux:
real, intent(inout):: phis(bd%isd:bd%ied,bd%jsd:bd%jed) !< Surface geopotential (g*Z_surf)
real, intent(inout):: pe(bd%is-1:bd%ie+1, npz+1,bd%js-1:bd%je+1) !< edge pressure (pascal)
real, intent(inout):: peln(bd%is:bd%ie,npz+1,bd%js:bd%je) !< ln(pe)
real, intent(inout):: pk(bd%is:bd%ie,bd%js:bd%je, npz+1) !< pe**kappa
!-----------------------------------------------------------------------
! Others:
real, parameter:: near0 = 1.E-8
#ifdef OVERLOAD_R4
real, parameter:: huge_r = 1.E8
#else
real, parameter:: huge_r = 1.E40
#endif
!-----------------------------------------------------------------------
real, intent(out ):: ws(bd%is:bd%ie,bd%js:bd%je) !< w at surface
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) are 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(inout):: q_con(bd%isd:, bd%jsd:, 1:)
! The Flux capacitors: accumulated Mass flux arrays
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)
real, intent(inout),dimension(bd%is:bd%ie,bd%js:bd%je,npz):: pkz
type(fv_grid_type), intent(INOUT), target :: gridstruct
type(fv_flags_type), intent(IN), target :: flagstruct
type(fv_nest_type), intent(INOUT) :: neststruct
type(fv_diag_type), intent(IN) :: idiag
type(domain2d), intent(INOUT) :: domain
real, allocatable, dimension(:,:,:):: pem, heat_source
! Auto 1D & 2D arrays:
real, dimension(bd%isd:bd%ied,bd%jsd:bd%jed):: ws3, z_rat
real:: dp_ref(npz)
real:: zs(bd%isd:bd%ied,bd%jsd:bd%jed) !< surface height (m)
real:: p1d(bd%is:bd%ie)
real:: om2d(bd%is:bd%ie,npz)
real wbuffer(npy+2,npz)
real ebuffer(npy+2,npz)
real nbuffer(npx+2,npz)
real sbuffer(npx+2,npz)
! ---- For external mode:
real divg2(bd%is:bd%ie+1,bd%js:bd%je+1)
real wk(bd%isd:bd%ied,bd%jsd:bd%jed)
real fz(bd%is: bd%ie+1,bd%js: bd%je+1)
real heat_s(bd%is:bd%ie,bd%js:bd%je)
! new array for stochastic kinetic energy backscatter (SKEB)
real diss_e(bd%is:bd%ie,bd%js:bd%je)
real damp_vt(npz+1)
integer nord_v(npz+1)
!-------------------------------------
integer :: hord_m, hord_v, hord_t, hord_p
integer :: nord_k, nord_w, nord_t
integer :: ms
!---------------------------------------
integer :: i,j,k, it, iq, n_con, nf_ke
integer :: iep1, jep1
real :: beta, beta_d, d_con_k, damp_w, damp_t, kgb, cv_air
real :: dt, dt2, rdt
real :: d2_divg
real :: k1k, rdg, dtmp, delt
real :: recip_k_split_n_split
real :: reg_bc_update_time
logical :: last_step, remap_step
logical used
real :: split_timestep_bc
integer :: is, ie, js, je
integer :: isd, ied, jsd, jed
is = bd%is
ie = bd%ie
js = bd%js
je = bd%je
isd = bd%isd
ied = bd%ied
jsd = bd%jsd
jed = bd%jed
#ifdef SW_DYNAMICS
peln1 = 0.
#else
peln1 = log(ptop)
#endif
ptk = ptop ** akap
dt = bdt / real(n_split)
dt2 = 0.5*dt
rdt = 1.0/dt
ms = max(1, flagstruct%m_split/2)
beta = flagstruct%beta
rdg = -rdgas / grav
cv_air = cp_air - rdgas
recip_k_split_n_split=1./real(flagstruct%k_split*n_split)
! Indexes:
iep1 = ie + 1
jep1 = je + 1
if ( .not.hydrostatic ) then
rgrav = 1.0/grav
k1k = akap / (1.-akap) ! rg/Cv=0.4
!$OMP parallel do default(none) shared(npz,dp_ref,ak,bk)
do k=1,npz
dp_ref(k) = ak(k+1)-ak(k) + (bk(k+1)-bk(k))*1.E5
enddo
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,zs,phis,rgrav)
do j=jsd,jed
do i=isd,ied
zs(i,j) = phis(i,j) * rgrav
enddo
enddo
endif
if ( init_step ) then ! Start of the big dynamic time stepping
allocate( gz(isd:ied, jsd:jed ,npz+1) )
call init_ijk_mem(isd,ied, jsd,jed, npz+1, gz, huge_r)
allocate( pkc(isd:ied, jsd:jed ,npz+1) )
allocate( ptc(isd:ied, jsd:jed ,npz ) )
allocate( crx(is :ie+1, jsd:jed, npz) )
allocate( xfx(is :ie+1, jsd:jed, npz) )
allocate( cry(isd:ied, js :je+1, npz) )
allocate( yfx(isd:ied, js :je+1, npz) )
allocate( divgd(isd:ied+1,jsd:jed+1,npz) )
allocate( delpc(isd:ied, jsd:jed ,npz ) )
! call init_ijk_mem(isd,ied, jsd,jed, npz, delpc, 0.)
allocate( ut(isd:ied, jsd:jed, npz) )
! call init_ijk_mem(isd,ied, jsd,jed, npz, ut, 0.)
allocate( vt(isd:ied, jsd:jed, npz) )
! call init_ijk_mem(isd,ied, jsd,jed, npz, vt, 0.)
if ( .not. hydrostatic ) then
allocate( zh(isd:ied, jsd:jed, npz+1) )
! call init_ijk_mem(isd,ied, jsd,jed, npz+1, zh, huge_r )
allocate ( pk3(isd:ied,jsd:jed,npz+1) )
call init_ijk_mem(isd,ied, jsd,jed, npz+1, pk3, huge_r )
endif
if ( beta > near0 ) then
allocate( du(isd:ied, jsd:jed+1,npz) )
call init_ijk_mem(isd,ied, jsd,jed+1, npz, du, 0.)
allocate( dv(isd:ied+1,jsd:jed, npz) )
call init_ijk_mem(isd,ied+1, jsd,jed , npz, dv, 0.)
endif
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,diss_est)
do k=1,npz
do j=jsd,jed
do i=isd,ied
diss_est(i,j,k) = 0.
enddo
enddo
enddo
endif ! end init_step
! Empty the "flux capacitors"
call init_ijk_mem(is, ie+1, js, je, npz, mfx, 0.)
call init_ijk_mem(is, ie , js, je+1, npz, mfy, 0.)
call init_ijk_mem(is, ie+1, jsd, jed, npz, cx, 0.)
call init_ijk_mem(isd, ied, js, je+1, npz, cy, 0.)
if ( flagstruct%d_con > 1.0E-5 ) then
allocate( heat_source(isd:ied, jsd:jed, npz) )
call init_ijk_mem(isd, ied, jsd, jed, npz, heat_source, 0.)
endif
if ( flagstruct%convert_ke .or. flagstruct%vtdm4> 1.E-4 ) then
n_con = npz
else
if ( flagstruct%d2_bg_k1 < 1.E-3 ) then
n_con = 0
else
if ( flagstruct%d2_bg_k2 < 1.E-3 ) then
n_con = 1
else
n_con = 2
endif
endif
endif
!-----------------------------------------------------
do it=1,n_split
!-----------------------------------------------------
n_step = it
#ifdef ROT3
call start_group_halo_update(i_pack(8), u, v, domain, gridtype=DGRID_NE)
#endif
if ( flagstruct%breed_vortex_inline .or. it==n_split ) then
remap_step = .true.
else
remap_step = .false.
endif
if ( flagstruct%fv_debug ) then
if(is_master()) write(*,*) 'n_split loop, it=', it
if ( .not. flagstruct%hydrostatic ) &
call prt_mxm('delz', delz, is, ie, js, je, 0, npz, 1., gridstruct%area_64, domain)
endif
if (gridstruct%nested) then
!First split timestep has split_timestep_BC = n_split*k_split
! to do time-extrapolation on BCs.
split_timestep_bc = real(n_split*flagstruct%k_split+neststruct%nest_timestep)
endif
if ( nq > 0 ) then
call timing_on('COMM_TOTAL')
call timing_on('COMM_TRACER')
if ( flagstruct%inline_q ) then
call start_group_halo_update(i_pack(10), q, domain)
endif
call timing_off('COMM_TRACER')
call timing_off('COMM_TOTAL')
endif
if ( .not. hydrostatic ) then
call timing_on('COMM_TOTAL')
call start_group_halo_update(i_pack(7), w, domain)
call timing_off('COMM_TOTAL')
if ( it==1 ) then
if (gridstruct%bounded_domain) then
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,gz,zs,npz)
do j=jsd,jed
do i=isd,ied
gz(i,j,npz+1) = zs(i,j)
enddo
enddo
if (gridstruct%nested) then
call gz_bc(gz,neststruct%delz_BC,bd,npx,npy,npz,split_timestep_BC, real(n_split*flagstruct%k_split))
endif
if (gridstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
if (is_master() .and. flagstruct%fv_debug) print*, ' REG_BC_UPDATE_TIME: ', it, current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
call gz_bc(gz, delz_regBC,bd,npx,npy,npz,mod(reg_bc_update_time,bc_time_interval*3600.), bc_time_interval*3600.)
endif
else
!$OMP parallel do default(none) shared(is,ie,js,je,gz,zs,npz)
do j=js,je
do i=is,ie
gz(i,j,npz+1) = zs(i,j)
enddo
enddo
endif
!$OMP parallel do default(none) shared(is,ie,js,je,npz,gz,delz)
do j=js,je
do k=npz,1,-1
do i=is,ie
gz(i,j,k) = gz(i,j,k+1) - delz(i,j,k)
enddo
enddo
enddo
call timing_on('COMM_TOTAL')
call start_group_halo_update(i_pack(5), gz, domain)
call timing_off('COMM_TOTAL')
endif
endif
#ifdef SW_DYNAMICS
if (test_case>1) then
#ifdef USE_OLD
if (test_case==9) call case9_forcing1(phis, time_total)
#endif
#endif
if ( it==1 ) then
call timing_on('COMM_TOTAL')
call complete_group_halo_update(i_pack(1), domain)
call timing_off('COMM_TOTAL')
beta_d = 0.
else
beta_d = beta
endif
if ( it==n_split .and. end_step ) then
if ( flagstruct%use_old_omega ) then
allocate ( pem(is-1:ie+1,npz+1,js-1:je+1) )
!$OMP parallel do default(none) shared(is,ie,js,je,npz,pem,delp,ptop)
do j=js-1,je+1
do i=is-1,ie+1
pem(i,1,j) = ptop
enddo
do k=1,npz
do i=is-1,ie+1
pem(i,k+1,j) = pem(i,k,j) + delp(i,j,k)
enddo
enddo
enddo
endif
last_step = .true.
else
last_step = .false.
endif
call timing_on('COMM_TOTAL')
call complete_group_halo_update(i_pack(8), domain)
if( .not. hydrostatic ) &
call complete_group_halo_update(i_pack(7), domain)
call timing_off('COMM_TOTAL')
call timing_on('c_sw')
!$OMP parallel do default(none) shared(npz,isd,jsd,delpc,delp,ptc,pt,u,v,w,uc,vc,ua,va, &
!$OMP omga,ut,vt,divgd,flagstruct,dt2,hydrostatic,bd, &
!$OMP gridstruct)
do k=1,npz
call c_sw(delpc(isd,jsd,k), delp(isd,jsd,k), ptc(isd,jsd,k), &
pt(isd,jsd,k), u(isd,jsd,k), v(isd,jsd,k), &
w(isd:,jsd:,k), uc(isd,jsd,k), vc(isd,jsd,k), &
ua(isd,jsd,k), va(isd,jsd,k), omga(isd,jsd,k), &
ut(isd,jsd,k), vt(isd,jsd,k), divgd(isd,jsd,k), &
flagstruct%nord, dt2, hydrostatic, .true., bd, &
gridstruct, flagstruct)
enddo
call timing_off('c_sw')
if ( flagstruct%nord > 0 ) then
call timing_on('COMM_TOTAL')
call start_group_halo_update(i_pack(3), divgd, domain, position=CORNER)
call timing_off('COMM_TOTAL')
endif
if (gridstruct%nested) then
call nested_grid_BC_apply_intT(delpc, &
0, 0, npx, npy, npz, bd, split_timestep_BC+0.5, real(n_split*flagstruct%k_split), &
neststruct%delp_BC, bctype=neststruct%nestbctype)
#ifndef SW_DYNAMICS
call nested_grid_BC_apply_intT(ptc, &
0, 0, npx, npy, npz, bd, split_timestep_BC+0.5, real(n_split*flagstruct%k_split), &
neststruct%pt_BC, bctype=neststruct%nestbctype )
#endif
endif
if (flagstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(0.5+(it-1))*dt
call regional_boundary_update(delpc, 'delp', &
isd, ied, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
#ifndef SW_DYNAMICS
call regional_boundary_update(ptc, 'pt', &
isd, ied, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
#endif
endif
if ( hydrostatic ) then
call geopk(ptop, pe, peln, delpc, pkc, gz, phis, ptc, &
#ifdef MULTI_GASES
kapad, &
#endif
q_con, pkz, npz, akap, .true., &
gridstruct%bounded_domain, .false., npx, npy, flagstruct%a2b_ord, bd)
else
#ifndef SW_DYNAMICS
if ( it == 1 ) then
call timing_on('COMM_TOTAL')
call complete_group_halo_update(i_pack(5), domain)
call timing_off('COMM_TOTAL')
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,zh,gz)
do k=1,npz+1
do j=jsd,jed
do i=isd,ied
! Save edge heights for update_dz_d
zh(i,j,k) = gz(i,j,k)
enddo
enddo
enddo
else
if (gridstruct%bounded_domain) then
if (gridstruct%nested) then
call gz_bc(gz,neststruct%delz_BC,bd,npx,npy,npz,split_timestep_BC, real(n_split*flagstruct%k_split))
endif
if (gridstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
if (is_master() .and. flagstruct%fv_debug) print*, ' REG_BC_UPDATE_TIME: ', it, current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
call gz_bc(gz, delz_regBC,bd,npx,npy,npz,mod(reg_bc_update_time,bc_time_interval*3600.), bc_time_interval*3600.)
endif
endif
!$OMP parallel do default(none) shared(isd,ied,jsd,jed,npz,zh,gz)
do k=1, npz+1
do j=jsd,jed
do i=isd,ied
gz(i,j,k) = zh(i,j,k)
enddo
enddo
enddo
endif
call timing_on('UPDATE_DZ_C')
call update_dz_c(is, ie, js, je, npz, ng, dt2, dp_ref, zs, gridstruct%area, ut, vt, gz, ws3, &
npx, npy, gridstruct%sw_corner, gridstruct%se_corner, &
gridstruct%ne_corner, gridstruct%nw_corner, bd, gridstruct%grid_type, flagstruct%dz_min)
call timing_off('UPDATE_DZ_C')
call timing_on('Riem_Solver')
call Riem_Solver_C( ms, dt2, is, ie, js, je, npz, ng, &
akap, cappa, cp, &
#ifdef MULTI_GASES
kapad, &
#endif
ptop, phis, omga, ptc, &
q_con, delpc, gz, pkc, ws3, flagstruct%p_fac, &
flagstruct%a_imp, flagstruct%scale_z )
call timing_off('Riem_Solver')
if (gridstruct%nested) then
call nh_bc(ptop, grav, akap, cp, delpc, neststruct%delz_BC, ptc, phis, &
#ifdef MULTI_GASES
q, &
#endif
#ifdef USE_COND
q_con, &
#ifdef MOIST_CAPPA
cappa, &
#endif
#endif
pkc, gz, pk3, &
split_timestep_BC+0.5, real(n_split*flagstruct%k_split), &
npx, npy, npz, gridstruct%bounded_domain, .false., .false., .false., bd)
endif
if (flagstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(0.5+(it-1))*dt
call nh_bc(ptop, grav, akap, cp, delpc, delz_regBC, ptc, phis, &
#ifdef MULTI_GASES
q, &
#endif
#ifdef USE_COND
q_con, &
#ifdef MOIST_CAPPA
cappa, &
#endif
#endif
pkc, gz, pk3, &
mod(reg_bc_update_time,bc_time_interval*3600.), bc_time_interval*3600., &
npx, npy, npz, gridstruct%bounded_domain, .false., .false., .false., bd)
endif
#endif SW_DYNAMICS
endif ! end hydro check
call p_grad_c(dt2, npz, delpc, pkc, gz, uc, vc, bd, gridstruct%rdxc, gridstruct%rdyc, hydrostatic)
call timing_on('COMM_TOTAL')
call start_group_halo_update(i_pack(9), uc, vc, domain, gridtype=CGRID_NE)
call timing_off('COMM_TOTAL')
#ifdef SW_DYNAMICS
#ifdef USE_OLD
if (test_case==9) call case9_forcing2(phis)
#endif
endif !test_case>1
#endif
call timing_on('COMM_TOTAL')
if (flagstruct%inline_q .and. nq>0) call complete_group_halo_update(i_pack(10), domain)
if (flagstruct%nord > 0) call complete_group_halo_update(i_pack(3), domain)
call complete_group_halo_update(i_pack(9), domain)
call timing_off('COMM_TOTAL')
if (gridstruct%nested) then
!On a nested grid we have to do SOMETHING with uc and vc in
! the boundary halo, particularly at the corners of the
! domain and of each processor element. We must either
! apply an interpolated BC, or extrapolate into the
! boundary halo
! NOTE:
!The update_domains calls for uc and vc need to go BEFORE the BCs to ensure cross-restart
!bitwise-consistent solutions when doing the spatial extrapolation; should not make a
!difference for interpolated BCs from the coarse grid.
call nested_grid_BC_apply_intT(vc, &
0, 1, npx, npy, npz, bd, split_timestep_bc+0.5, real(n_split*flagstruct%k_split), &
neststruct%vc_BC, bctype=neststruct%nestbctype )
call nested_grid_BC_apply_intT(uc, &
1, 0, npx, npy, npz, bd, split_timestep_bc+0.5, real(n_split*flagstruct%k_split), &
neststruct%uc_BC, bctype=neststruct%nestbctype )
call nested_grid_BC_apply_intT(divgd, &
1, 1, npx, npy, npz, bd, split_timestep_bc, real(n_split*flagstruct%k_split), &
neststruct%divg_BC, bctype=neststruct%nestbctype )
end if
if (flagstruct%regional) then
!call exch_uv(domain, bd, npz, vc, uc)
call mpp_update_domains(uc, vc, domain, gridtype=CGRID_NE)
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(0.5+(it-1))*dt
call regional_boundary_update(vc, 'vc', &
isd, ied, jsd, jed+1, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
call regional_boundary_update(uc, 'uc', &
isd, ied+1, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
call mpp_update_domains(uc, vc, domain, gridtype=CGRID_NE)
!!! Currently divgd is always 0.0 in the regional domain boundary area.
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
call regional_boundary_update(divgd, 'divgd', &
isd, ied+1, jsd, jed+1, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
endif
if ( flagstruct%inline_q ) then
if ( gridstruct%nested ) then
do iq=1,nq
call nested_grid_BC_apply_intT(q(isd:ied,jsd:jed,:,iq), &
0, 0, npx, npy, npz, bd, split_timestep_BC+1, real(n_split*flagstruct%k_split), &
neststruct%q_BC(iq), bctype=neststruct%nestbctype )
end do
endif
if (flagstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
do iq=1,nq
call regional_boundary_update(q(:,:,:,iq), 'q', &
isd, ied, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
enddo
endif
endif
call timing_on('d_sw')
!$OMP parallel do default(none) shared(npz,flagstruct,nord_v,pfull,damp_vt,hydrostatic,last_step, &
!$OMP is,ie,js,je,isd,ied,jsd,jed,omga,delp,gridstruct,npx,npy, &
!$OMP ng,zh,vt,ptc,pt,u,v,w,uc,vc,ua,va,divgd,mfx,mfy,cx,cy, &
!$OMP crx,cry,xfx,yfx,q_con,zvir,sphum,nq,q,dt,bd,rdt,iep1,jep1, &
!$OMP heat_source,diss_est,ptop,first_call) &
!$OMP private(nord_k, nord_w, nord_t, damp_w, damp_t, d2_divg, &
!$OMP d_con_k,kgb, hord_m, hord_v, hord_t, hord_p, wk, heat_s,diss_e, z_rat)
do k=1,npz
hord_m = flagstruct%hord_mt
hord_t = flagstruct%hord_tm
hord_v = flagstruct%hord_vt
hord_p = flagstruct%hord_dp
nord_k = flagstruct%nord
! if ( k==npz ) then
kgb = flagstruct%ke_bg
! else
! kgb = 0.
! endif
nord_v(k) = min(2, flagstruct%nord)
! d2_divg = min(0.20, flagstruct%d2_bg*(1.-3.*tanh(0.1*log(pfull(k)/pfull(npz)))))
d2_divg = min(0.20, flagstruct%d2_bg)
if ( flagstruct%do_vort_damp ) then
damp_vt(k) = flagstruct%vtdm4 ! for delp, delz, and vorticity
else
damp_vt(k) = 0.
endif
nord_w = nord_v(k)
nord_t = nord_v(k)
damp_w = damp_vt(k)
damp_t = damp_vt(k)
d_con_k = flagstruct%d_con
if ( npz==1 .or. flagstruct%n_sponge<0 ) then
d2_divg = flagstruct%d2_bg
else
! Sponge layers with del-2 damping on divergence, vorticity, w, z, and air mass (delp).
! no special damping of potential temperature in sponge layers
! enhanced del-2 divergence damping has same vertical structure as Rayleigh
! damping if d2_bg_k2<=0.
if (flagstruct%d2_bg_k2 > 0) then ! old version, only applied at top two or three levels
if ( k==1 ) then
! Divergence damping:
nord_k=0; d2_divg = max(0.01, flagstruct%d2_bg, flagstruct%d2_bg_k1)
! Vertical velocity:
nord_w=0; damp_w = d2_divg
if ( flagstruct%do_vort_damp ) then
! damping on delp and vorticity:
nord_v(k)=0;
#ifndef HIWPP
damp_vt(k) = 0.5*d2_divg
#endif
endif
d_con_k = 0.
elseif ( k==2 .and. flagstruct%d2_bg_k2>0.01 ) then
nord_k=0; d2_divg = max(flagstruct%d2_bg, flagstruct%d2_bg_k2)
nord_w=0; damp_w = d2_divg
if ( flagstruct%do_vort_damp ) then
nord_v(k)=0;
#ifndef HIWPP
damp_vt(k) = 0.5*d2_divg
#endif
endif
d_con_k = 0.
elseif ( k==3 .and. flagstruct%d2_bg_k2>0.05 ) then
nord_k=0; d2_divg = max(flagstruct%d2_bg, 0.2*flagstruct%d2_bg_k2)
nord_w=0; damp_w = d2_divg
d_con_k = 0.
endif
else ! new version, uses d2_bg_k1 and sponge layer vertical structure
if ( pfull(k) < flagstruct%rf_cutoff ) then
nord_k=0; nord_w=0
d2_divg = max(flagstruct%d2_bg, flagstruct%d2_bg_k1* &
sin(0.5*pi*log(flagstruct%rf_cutoff/pfull(k))/log(flagstruct%rf_cutoff/ptop))**2)
if (first_call .and. is_master() .and. last_step) write(6,*) k, 0.01*pfull(k), d2_divg
damp_w = d2_divg
if ( flagstruct%do_vort_damp ) then
! damping on delp and vorticity
nord_v(k)=0
damp_vt(k) = 0.5*d2_divg
endif
endif
endif
endif
if( hydrostatic .and. (.not.flagstruct%use_old_omega) .and. last_step ) then
! Average horizontal "convergence" to cell center
do j=js,je
do i=is,ie
omga(i,j,k) = delp(i,j,k)
enddo
enddo
endif
!--- external mode divergence damping ---
if ( flagstruct%d_ext > 0. ) &
call a2b_ord2(delp(isd,jsd,k), wk, gridstruct, npx, npy, is, &
ie, js, je, ng, .false.)
if ( .not.hydrostatic .and. flagstruct%do_f3d ) then
! Correction factor for 3D Coriolis force
do j=jsd,jed
do i=isd,ied
z_rat(i,j) = 1. + (zh(i,j,k)+zh(i,j,k+1))/radius
enddo
enddo
endif
call d_sw(vt(isd,jsd,k), delp(isd,jsd,k), ptc(isd,jsd,k), pt(isd,jsd,k), &
u(isd,jsd,k), v(isd,jsd,k), w(isd:,jsd:,k), uc(isd,jsd,k), &
vc(isd,jsd,k), ua(isd,jsd,k), va(isd,jsd,k), divgd(isd,jsd,k), &
mfx(is, js, k), mfy(is, js, k), cx(is, jsd,k), cy(isd,js, k), &
crx(is, jsd,k), cry(isd,js, k), xfx(is, jsd,k), yfx(isd,js, k), &
#ifdef USE_COND
q_con(isd:,jsd:,k), z_rat(isd,jsd), &
#else
q_con(isd:,jsd:,1), z_rat(isd,jsd), &
#endif
kgb, heat_s, diss_e,zvir, sphum, nq, q, k, npz, flagstruct%inline_q, dt, &
flagstruct%hord_tr, hord_m, hord_v, hord_t, hord_p, &
nord_k, nord_v(k), nord_w, nord_t, flagstruct%dddmp, d2_divg, flagstruct%d4_bg, &
damp_vt(k), damp_w, damp_t, d_con_k, hydrostatic, gridstruct, flagstruct, bd)
if( hydrostatic .and. (.not.flagstruct%use_old_omega) .and. last_step ) then
! Average horizontal "convergence" to cell center
do j=js,je
do i=is,ie
omga(i,j,k) = omga(i,j,k)*(xfx(i,j,k)-xfx(i+1,j,k)+yfx(i,j,k)-yfx(i,j+1,k))*gridstruct%rarea(i,j)*rdt
enddo
enddo
endif
if ( flagstruct%d_ext > 0. ) then
do j=js,jep1
do i=is,iep1
ptc(i,j,k) = wk(i,j) ! delp at cell corners
enddo
enddo
endif
if ( flagstruct%d_con > 1.0E-5 .OR. flagstruct%do_skeb ) then
! Average horizontal "convergence" to cell center
do j=js,je
do i=is,ie
heat_source(i,j,k) = heat_source(i,j,k) + heat_s(i,j)
diss_est(i,j,k) = diss_est(i,j,k) + diss_e(i,j)
enddo
enddo
endif
enddo ! end openMP k-loop
if (flagstruct%regional) then
call mpp_update_domains(uc, vc, domain, gridtype=CGRID_NE)
call mpp_update_domains(u , v , domain, gridtype=DGRID_NE)
endif
call timing_off('d_sw')
if( flagstruct%fill_dp ) call mix_dp(hydrostatic, w, delp, pt, npz, ak, bk, .false., flagstruct%fv_debug, bd, gridstruct)
call timing_on('COMM_TOTAL')
call start_group_halo_update(i_pack(1), delp, domain, complete=.false.)
call start_group_halo_update(i_pack(1), pt, domain, complete=.true.)
#ifdef USE_COND
call start_group_halo_update(i_pack(11), q_con, domain)
#endif
call timing_off('COMM_TOTAL')
if ( flagstruct%d_ext > 0. ) then
d2_divg = flagstruct%d_ext * gridstruct%da_min_c
!$OMP parallel do default(none) shared(is,iep1,js,jep1,npz,wk,ptc,divg2,vt,d2_divg)
do j=js,jep1
do i=is,iep1
wk(i,j) = ptc(i,j,1)
divg2(i,j) = wk(i,j)*vt(i,j,1)
enddo
do k=2,npz
do i=is,iep1
wk(i,j) = wk(i,j) + ptc(i,j,k)
divg2(i,j) = divg2(i,j) + ptc(i,j,k)*vt(i,j,k)
enddo
enddo
do i=is,iep1
divg2(i,j) = d2_divg*divg2(i,j)/wk(i,j)
enddo
enddo
else
divg2(:,:) = 0.
endif
call timing_on('COMM_TOTAL')
call complete_group_halo_update(i_pack(1), domain)
#ifdef USE_COND
call complete_group_halo_update(i_pack(11), domain)
#endif
call timing_off('COMM_TOTAL')
if ( flagstruct%fv_debug ) then
if ( .not. flagstruct%hydrostatic ) &
call prt_mxm('delz', delz, is, ie, js, je, 0, npz, 1., gridstruct%area_64, domain)
endif
!Want to move this block into the hydro/nonhydro branch above and merge the two if structures
if (gridstruct%nested) then
call nested_grid_BC_apply_intT(delp, &
0, 0, npx, npy, npz, bd, split_timestep_BC+1, real(n_split*flagstruct%k_split), &
neststruct%delp_BC, bctype=neststruct%nestbctype )
#ifndef SW_DYNAMICS
call nested_grid_BC_apply_intT(pt, &
0, 0, npx, npy, npz, bd, split_timestep_BC+1, real(n_split*flagstruct%k_split), &
neststruct%pt_BC, bctype=neststruct%nestbctype )
#ifdef USE_COND
call nested_grid_BC_apply_intT(q_con, &
0, 0, npx, npy, npz, bd, split_timestep_BC+1, real(n_split*flagstruct%k_split), &
neststruct%q_con_BC, bctype=neststruct%nestbctype )
#endif
#endif
end if
if (flagstruct%regional) then
reg_bc_update_time=current_time_in_seconds+bdt*(n_map-1)+(it-1)*dt
call regional_boundary_update(delp, 'delp', &
isd, ied, jsd, jed, npz, &
is, ie, js, je, &
isd, ied, jsd, jed, &
reg_bc_update_time,it )
#ifndef SW_DYNAMICS