updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / dyn_em / module_first_rk_step_part2.F
blob8f092ce79479118241b5de1837451f145db6d21c
1 !WRF:MEDIATION_LAYER:SOLVER
3 #define BENCH_START(A)
4 #define BENCH_END(A)
6 MODULE module_first_rk_step_part2
8 CONTAINS
10   SUBROUTINE first_rk_step_part2 (   grid , config_flags        &
11                              , moist , moist_old , moist_tend   &
12                              , chem  , chem_tend                &
13                              , tracer, tracer_tend              &
14                              , scalar , scalar_tend             &
15                              , fdda3d, fdda2d                   &
16                              , ru_tendf, rv_tendf               &
17                              , rw_tendf, t_tendf                &
18                              , ph_tendf, mu_tendf               &
19                              , tke_tend                         &
20                              , adapt_step_flag , curr_secs      &
21                              , psim , psih , gz1oz0 , chklowq   &
22                              , cu_act_flag , hol , th_phy       &
23                              , pi_phy , p_phy , t_phy           &
24                              , dz8w , p8w , t8w                 &
25                              , nba_mij, n_nba_mij               & !JDM
26                              , nba_rij, n_nba_rij               & !JDM
27                              , ids, ide, jds, jde, kds, kde     &
28                              , ims, ime, jms, jme, kms, kme     &
29                              , ips, ipe, jps, jpe, kps, kpe     &
30                              , imsx,imex,jmsx,jmex,kmsx,kmex    &
31                              , ipsx,ipex,jpsx,jpex,kpsx,kpex    &
32                              , imsy,imey,jmsy,jmey,kmsy,kmey    &
33                              , ipsy,ipey,jpsy,jpey,kpsy,kpey    &
34                              , k_start , k_end                  &
35                             )
36     USE module_state_description
37     USE module_model_constants
38     USE module_domain, ONLY : domain
39     USE module_configure, ONLY : grid_config_rec_type, model_config_rec
40     USE module_big_step_utilities_em, ONLY : conv_t_tendf_to_moist
41 #ifdef DM_PARALLEL
42     USE module_dm, ONLY : local_communicator, mytask, ntasks, ntasks_x, ntasks_y, local_communicator_periodic, &
43                           wrf_dm_maxval, wrf_err_message, local_communicator_x, local_communicator_y
44     USE module_comm_dm, ONLY : halo_em_tke_c_sub,halo_em_tke_d_sub,halo_em_tke_e_sub            &
45             ,halo_em_phys_pbl_sub,halo_em_phys_shcu_sub &
46             ,halo_em_fdda_sub,halo_em_phys_diffusion_sub,halo_em_tke_3_sub &
47             ,halo_em_tke_5_sub,halo_obs_nudge_sub,period_bdy_em_a1_sub,period_bdy_em_phy_bc_sub &
48             ,period_bdy_em_fdda_bc_sub,period_bdy_em_chem_sub,halo_em_phys_cu_sub,halo_em_helicity_sub
49 #endif
51     USE module_driver_constants
52     USE module_diffusion_em, ONLY : phy_bc, cal_deform_and_div, compute_diff_metrics, &
53                                     vertical_diffusion_2, horizontal_diffusion_2, calculate_km_kh, &
54                                     tke_rhs, cal_helicity, &
55                                     nonlocal_flux,meso_length_scale,free_atmos_length, &
56                                     vertical_diffusion_implicit !XZ 
57     USE module_em, ONLY : calculate_phy_tend
58     USE module_fddaobs_driver, ONLY : fddaobs_driver
59     USE module_bc, ONLY : set_physical_bc3d, set_physical_bc2d
60     USE module_physics_addtendc, ONLY : update_phy_ten
62     USE module_sfs_driver !JDM
63     USE module_stoch, ONLY : update_stoch_ten, perturb_physics_tend, RAND_PERT_UPDATE, contiguize_2d
66     IMPLICIT NONE
68     TYPE ( domain ), INTENT(INOUT) :: grid
69     TYPE ( grid_config_rec_type ), INTENT(IN) :: config_flags
71     INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde,     &
72                            ims, ime, jms, jme, kms, kme,     &
73                            ips, ipe, jps, jpe, kps, kpe,     &
74                            imsx,imex,jmsx,jmex,kmsx,kmex,    &
75                            ipsx,ipex,jpsx,jpex,kpsx,kpex,    &
76                            imsy,imey,jmsy,jmey,kmsy,kmey,    &
77                            ipsy,ipey,jpsy,jpey,kpsy,kpey
81     LOGICAL ,INTENT(IN)                        :: adapt_step_flag
82     REAL, INTENT(IN)                           :: curr_secs
84     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_moist),INTENT(INOUT)   :: moist
85     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_moist),INTENT(IN)      :: moist_old
86     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_moist),INTENT(INOUT)   :: moist_tend
87     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_chem),INTENT(INOUT)   :: chem
88     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_chem),INTENT(INOUT)   :: chem_tend
89     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_tracer),INTENT(INOUT)   :: tracer
90     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_tracer),INTENT(INOUT)   :: tracer_tend
91     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_scalar),INTENT(INOUT)   :: scalar
92     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_scalar),INTENT(INOUT)   :: scalar_tend
93     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme,num_fdda3d),INTENT(INOUT)  :: fdda3d
94     REAL    ,DIMENSION(ims:ime,1:1,jms:jme,num_fdda2d),INTENT(INOUT)      :: fdda2d
95     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: psim
96     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: psih
97     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: gz1oz0
98     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: chklowq
99     LOGICAL ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: cu_act_flag
100     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT)         :: hol
102     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: th_phy
103     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: pi_phy
104     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: p_phy
105     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: t_phy
106     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: dz8w
107     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: p8w
108     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: t8w
110     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: ru_tendf
111     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: rv_tendf
112     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: rw_tendf
113     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: ph_tendf
114     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: t_tendf
115     REAL    ,DIMENSION(ims:ime,kms:kme,jms:jme), INTENT(INOUT) :: tke_tend
117     REAL    ,DIMENSION(ims:ime,jms:jme), INTENT(INOUT) :: mu_tendf
119     INTEGER , INTENT(IN)                          ::  k_start, k_end
121 !JDM
122   INTEGER, INTENT(  IN ) :: n_nba_mij, n_nba_rij
124   REAL ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,n_nba_mij) &
125   :: nba_mij
127   REAL ,DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33,n_nba_rij) &
128   :: nba_rij
130 ! Local
132     REAL, DIMENSION( ims:ime, jms:jme ) :: ht_loc
133     REAL :: scale_factor
134     INTEGER, DIMENSION( ims:ime, jms:jme ) :: shadowmask 
135     INTEGER                             :: ij
136     INTEGER  num_roof_layers
137     INTEGER  num_wall_layers
138     INTEGER  num_road_layers
139     INTEGER  iswater
140     INTEGER  rk_step 
141     INTEGER  n
142     LOGICAL :: stepsp_test
144 #if ( WRF_DFI_RADAR == 1 )
145     INTEGER  i_start,i_end,j_start,j_end,i,j,k
146 #endif
148     REAL, DIMENSION(ims:ime,jms:jme) :: SPFORCS3d_loc, SPFORCC3d_loc, SP_AMP3d_loc
150  ! initialize all tendencies to zero in order to update physics
151  ! tendencies first (separate from dry dynamics).
153    rk_step = 1
155       IF ((grid%skebs_on==1).and.(grid%id .EQ. 1 )) then
156           ! update and backtransform T
157           CALL RAND_PERT_UPDATE(grid,'T',                                     &
158                           grid%SPTFORCS,grid%SPTFORCC,                        &
159                           grid%SPT_AMP,grid%ALPH_T,                           &
160                           ips, ipe, jps, jpe, kps, kpe,                       &
161                           ids, ide, jds, jde, kds, kde,                       &
162                           ims, ime, jms, jme, kms, kme,                       &
163                           k_start, k_end,                                     &
164                           imsx,imex,jmsx,jmex,kmsx,kmex,                      &
165                           ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
166                           imsy,imey,jmsy,jmey,kmsy,kmey,                      &
167                           ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
168                           grid%num_stoch_levels,grid%num_stoch_levels,        &
169                           grid%num_stoch_levels,grid%num_stoch_levels,        &
170                           config_flags%restart, grid%iseedarr_skebs,          &
171                           config_flags%seed_dim,                              &
172                           grid%DX,grid%DY,grid%skebs_vertstruc,               &
173                           grid%rt_tendf_stoch,                                &
174                           grid%stddev_cutoff_sppt,grid%gridpt_stddev_sppt, & 
175                           grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPUV      )
176           ! Update streamfunction, backtransform U
177            CALL RAND_PERT_UPDATE(grid,'U',                                    &
178                            grid%SPSTREAMFORCS,grid%SPSTREAMFORCC,             &
179                            grid%SPSTREAM_AMP,grid%ALPH_PSI,                   &
180                            ips, ipe, jps, jpe, kps, kpe,                      &
181                            ids, ide, jds, jde, kds, kde,                      &
182                            ims, ime, jms, jme, kms, kme,                      &
183                            k_start, k_end,                                    &
184                            imsx,imex,jmsx,jmex,kmsx,kmex,                     &
185                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                     &
186                            imsy,imey,jmsy,jmey,kmsy,kmey,                     &
187                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                     &
188                            grid% num_stoch_levels,grid% num_stoch_levels,     &
189                            grid% num_stoch_levels,grid% num_stoch_levels,     &
190                            config_flags%restart, grid%iseedarr_skebs,         &
191                            config_flags%seed_dim,                             &
192                            grid%DX,grid%DY,grid%skebs_vertstruc,              &
193                            grid%ru_tendf_stoch,                               &
194                            grid%stddev_cutoff_sppt,grid%gridpt_stddev_sppt, & 
195                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPUV     )
196           ! Don't update streamfunction, backtransform V
197            CALL RAND_PERT_UPDATE(grid,'V',                                    &
198                            grid%SPSTREAMFORCS,grid%SPSTREAMFORCC,             &
199                            grid%SPSTREAM_AMP,grid%ALPH_PSI,                   &
200                            ips, ipe, jps, jpe, kps, kpe,                      &
201                            ids, ide, jds, jde, kds, kde,                      &
202                            ims, ime, jms, jme, kms, kme,                      &
203                            k_start, k_end,                                    &
204                            imsx,imex,jmsx,jmex,kmsx,kmex,                     &
205                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                     &
206                            imsy,imey,jmsy,jmey,kmsy,kmey,                     &
207                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                     &
208                            grid% num_stoch_levels,grid% num_stoch_levels,     &
209                            grid% num_stoch_levels,grid% num_stoch_levels,     &
210                            config_flags%restart, grid%iseedarr_skebs,         &
211                            config_flags%seed_dim,                             &
212                            grid%DX,grid%DY,grid%skebs_vertstruc,              &
213                            grid%rv_tendf_stoch,                               &
214                            grid%stddev_cutoff_sppt,grid%gridpt_stddev_sppt, & 
215                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT      )
216        ENDIF !skebs_on 
218      if ((grid%sppt_on==1).and.(grid%id .EQ. 1 )) then
219           CALL RAND_PERT_UPDATE(grid,'T',                                     &
220                           grid%SPPTFORCS,grid%SPPTFORCC,                      &
221                           grid%SPPT_AMP,grid%ALPH_SPPT,                       &
222                           ips, ipe, jps, jpe, kps, kpe,                       &
223                           ids, ide, jds, jde, kds, kde,                       &
224                           ims, ime, jms, jme, kms, kme,                       &
225                           k_start, k_end,                                     &
226                           imsx,imex,jmsx,jmex,kmsx,kmex,                      &
227                           ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
228                           imsy,imey,jmsy,jmey,kmsy,kmey,                      &
229                           ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
230                           grid%num_stoch_levels,grid%num_stoch_levels,        &
231                           grid%num_stoch_levels,grid%num_stoch_levels,        &
232                           config_flags%restart, grid%iseedarr_sppt,           &
233                           config_flags%seed_dim,                              &
234                           grid%DX,grid%DY,grid%sppt_vertstruc,                &
235                           grid%rstoch,                                        &
236                           grid%stddev_cutoff_sppt,grid%gridpt_stddev_sppt, & 
237                           grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT       )
238        ENDIF !sppt_on
240       if ((grid%rand_perturb_on==1).and.(grid%id .EQ. 1 )) then
241            CALL RAND_PERT_UPDATE(grid,'T',                                     &
242                            grid%SPFORCS,grid%SPFORCC,                          &
243                            grid%SP_AMP,grid%ALPH_RAND,                         &
244                            ips, ipe, jps, jpe, kps, kpe,                       &
245                            ids, ide, jds, jde, kds, kde,                       &
246                            ims, ime, jms, jme, kms, kme,                       &
247                            k_start, k_end,                                     &
248                            imsx,imex,jmsx,jmex,kmsx,kmex,                      &
249                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
250                            imsy,imey,jmsy,jmey,kmsy,kmey,                      &
251                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
252                            grid%num_stoch_levels,grid%num_stoch_levels,        &
253                            grid%num_stoch_levels,grid%num_stoch_levels,        &
254                            config_flags%restart, grid%iseedarr_rand_pert,      &
255                            config_flags%seed_dim,                              &
256                            grid%DX,grid%DY,grid%rand_pert_vertstruc,           &
257                            grid%RAND_PERT,                                     &
258                            grid%stddev_cutoff_rand_pert,grid%gridpt_stddev_rand_pert, & 
259                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT       )
260       ENDIF !rand_perturb_on
262       IF ( grid%stepsp > 0 ) THEN
263          stepsp_test = ( MOD(grid%itimestep, grid%stepsp) == 0 )
264       ELSE
265          stepsp_test = .FALSE.
266       END IF
267       If_multi_perturb: if ((config_flags%multi_perturb==1).and.(grid%id == 1) .and. &
268           (stepsp_test .or. grid%itimestep == 1)) then
269         Loop_multi_perturb: DO n = 2, config_flags%num_pert_3d
270            CALL contiguize_2d ( .TRUE. , grid%SPFORCS3d, SPFORCS3d_loc, n,       &
271                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
272                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
273                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
274            CALL contiguize_2d ( .TRUE. , grid%SPFORCC3d, SPFORCC3d_loc, n,       &
275                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
276                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
277                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
278            CALL contiguize_2d ( .TRUE. , grid%SP_AMP3d,  SP_AMP3d_loc,  n,       &
279                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
280                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
281                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
282            CALL RAND_PERT_UPDATE(grid,'T',                                     &
283                            SPFORCS3d_loc, SPFORCC3d_loc, SP_AMP3d_loc,         &
284                            grid%ALPH_RAND3d(n),                                &
285                            ips, ipe, jps, jpe, kps, kpe,                       &
286                            ids, ide, jds, jde, kds, kde,                       &
287                            ims, ime, jms, jme, kms, kme,                       &
288                            k_start, k_end,                                     &
289                            imsx,imex,jmsx,jmex,kmsx,kmex,                      &
290                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
291                            imsy,imey,jmsy,jmey,kmsy,kmey,                      &
292                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
293                            grid%num_stoch_levels,grid%num_stoch_levels,        &
294                            grid%num_stoch_levels,grid%num_stoch_levels,        &
295                            config_flags%restart, grid%iseedarr_mult3d(:,n),    &
296                            config_flags%seed_dim,                              &
297                            grid%DX,grid%DY,grid%mult3d_vertstruc(n),           &
298                            grid%PERT3D(:,:,:,n),                               &
299                            grid%stddev_cutoff_mult3d(n),                       &
300                            grid%gridpt_stddev_mult3d(n),                       &
301                            grid%VERTSTRUCC3d(:,:,:,n),                         &
302                            grid%VERTSTRUCS3d(:,:,:,n),                         &
303                            grid%VERTAMPT3d(:,n)                                )
304            CALL contiguize_2d ( .FALSE., grid%SPFORCS3d, SPFORCS3d_loc, n,       &
305                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
306                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
307                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
308            CALL contiguize_2d ( .FALSE., grid%SPFORCC3d, SPFORCC3d_loc, n,       &
309                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
310                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
311                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
312            CALL contiguize_2d ( .FALSE., grid%SP_AMP3d,  SP_AMP3d_loc,  n,       &
313                                 ips, ipe, jps, jpe, 1, config_flags%num_pert_3d, &
314                                 ids, ide, jds, jde, 1, config_flags%num_pert_3d, &
315                                 ims, ime, jms, jme, 1, config_flags%num_pert_3d  )
316         END DO Loop_multi_perturb
317       ENDIF If_multi_perturb
319       if ((grid%spp_conv==1).and.(grid%id .EQ. 1 )) then
320            CALL RAND_PERT_UPDATE(grid,'T',                                     &
321                            grid%SPFORCS2,grid%SPFORCC2,                        &
322                            grid%SP_AMP2,grid%ALPH_RAND2,                       &
323                            ips, ipe, jps, jpe, kps, kpe,                       &
324                            ids, ide, jds, jde, kds, kde,                       &
325                            ims, ime, jms, jme, kms, kme,                       &
326                            k_start, k_end,                                     &
327                            imsx,imex,jmsx,jmex,kmsx,kmex,                      &
328                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
329                            imsy,imey,jmsy,jmey,kmsy,kmey,                      &
330                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
331                            grid%num_stoch_levels,grid%num_stoch_levels,        &
332                            grid%num_stoch_levels,grid%num_stoch_levels,        &
333                            config_flags%restart, grid%iseedarr_spp_conv,       &
334                            config_flags%seed_dim,                              &
335                            grid%DX,grid%DY,grid%vertstruc_spp_conv,            &
336                            grid%pattern_spp_conv,                              & 
337                            grid%stddev_cutoff_spp_conv,grid%gridpt_stddev_spp_conv, & 
338                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT       )
339       ENDIF !spp_conv
340       if ((grid%spp_pbl==1).and.(grid%id .EQ. 1 )) then
341            CALL RAND_PERT_UPDATE(grid,'T',                                     &
342                            grid%SPFORCS3,grid%SPFORCC3,                        &
343                            grid%SP_AMP3,grid%ALPH_RAND3,                       &
344                            ips, ipe, jps, jpe, kps, kpe,                       &
345                            ids, ide, jds, jde, kds, kde,                       &
346                            ims, ime, jms, jme, kms, kme,                       &
347                            k_start, k_end,                                     &
348                            imsx,imex,jmsx,jmex,kmsx,kmex,                      &
349                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
350                            imsy,imey,jmsy,jmey,kmsy,kmey,                      &
351                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
352                            grid%num_stoch_levels,grid%num_stoch_levels,        &
353                            grid%num_stoch_levels,grid%num_stoch_levels,        &
354                            config_flags%restart, grid%iseedarr_spp_pbl,        &
355                            config_flags%seed_dim,                              &
356                            grid%DX,grid%DY,grid%vertstruc_spp_pbl,             &
357                            grid%pattern_spp_pbl,                               & 
358                            grid%stddev_cutoff_spp_pbl,grid%gridpt_stddev_spp_pbl, & 
359                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT       )
360       ENDIF !spp_pbl
361       if ((grid%spp_lsm==1).and.(grid%id .EQ. 1 )) then
362            CALL RAND_PERT_UPDATE(grid,'T',                                     &
363                            grid%SPFORCS4,grid%SPFORCC4,                        &
364                            grid%SP_AMP4,grid%ALPH_RAND4,                       &
365                            ips, ipe, jps, jpe, kps, kpe,                       &
366                            ids, ide, jds, jde, kds, kde,                       &
367                            ims, ime, jms, jme, kms, kme,                       &
368                            k_start, k_end,                                     &
369                            imsx,imex,jmsx,jmex,kmsx,kmex,                      &
370                            ipsx,ipex,jpsx,jpex,kpsx,kpex,                      &
371                            imsy,imey,jmsy,jmey,kmsy,kmey,                      &
372                            ipsy,ipey,jpsy,jpey,kpsy,kpey,                      &
373                            grid%num_stoch_levels,grid%num_stoch_levels,        &
374                            grid%num_stoch_levels,grid%num_stoch_levels,        &
375                            config_flags%restart, grid%iseedarr_spp_lsm,        &
376                            config_flags%seed_dim,                              &
377                            grid%DX,grid%DY,grid%vertstruc_spp_lsm,             &
378                            grid%pattern_spp_lsm,                               & 
379                            grid%stddev_cutoff_spp_lsm,grid%gridpt_stddev_spp_lsm, & 
380                            grid%VERTSTRUCC,grid%VERTSTRUCS,grid%VERTAMPT       )
381       ENDIF !spp_lsm
383 ! calculate_phy_tend
385 BENCH_START(cal_phy_tend)
386       !$OMP PARALLEL DO   &
387       !$OMP PRIVATE ( ij )
389       DO ij = 1 , grid%num_tiles
391         CALL wrf_debug ( 200 , ' call calculate_phy_tend' )
392         CALL calculate_phy_tend (config_flags,grid%c1h,grid%c2h,       &
393                      grid%mut,grid%muu,grid%muv,pi_phy,                &
394                      grid%rthraten,                                    &
395                      grid%rublten,grid%rvblten,grid%rthblten,          &
396                      grid%rqvblten,grid%rqcblten,grid%rqiblten,        &
397                      grid%rucuten,grid%rvcuten,grid%rthcuten,          &
398                      grid%rqvcuten,grid%rqccuten,grid%rqrcuten,        &
399                      grid%rqicuten,grid%rqscuten,                      &
400                      grid%rushten,grid%rvshten,grid%rthshten,          &
401                      grid%rqvshten,grid%rqcshten,grid%rqrshten,        &
402                      grid%rqishten,grid%rqsshten,grid%rqgshten,        &
403                      grid%RUNDGDTEN,grid%RVNDGDTEN,grid%RTHNDGDTEN,grid%RQVNDGDTEN, &
404                      grid%RMUNDGDTEN,                                  &
405                      scalar, scalar_tend, num_scalar,                  &
406                      tracer, tracer_tend, num_tracer,                  &
407                      ids,ide, jds,jde, kds,kde,                        &
408                      ims,ime, jms,jme, kms,kme,                        &
409                      grid%i_start(ij), min(grid%i_end(ij),ide-1),      &
410                      grid%j_start(ij), min(grid%j_end(ij),jde-1),      &
411                      k_start    , min(k_end,kde-1)                     )
413       ENDDO
414       !$OMP END PARALLEL DO
415 BENCH_END(cal_phy_tend)
417 ! tke diffusion
419        IF(config_flags%diff_opt .eq. 2 .OR. config_flags%diff_opt .eq. 1) THEN
421 BENCH_START(comp_diff_metrics_tim)
422          !$OMP PARALLEL DO   &
423          !$OMP PRIVATE ( ij )
424          DO ij = 1 , grid%num_tiles
425            CALL wrf_debug ( 200 , ' call compute_diff_metrics ' )
426            CALL compute_diff_metrics ( config_flags, grid%ph_2, grid%phb, grid%z, grid%rdz, grid%rdzw, &
427                                        grid%zx, grid%zy, grid%rdx, grid%rdy,                      &
428                                        ids, ide, jds, jde, kds, kde,          &
429                                        ims, ime, jms, jme, kms, kme,          &
430                                        grid%i_start(ij), grid%i_end(ij),      &
431                                        grid%j_start(ij), grid%j_end(ij),      &
432                                        k_start    , k_end                    )
433          ENDDO
434          !$OMP END PARALLEL DO
435 BENCH_END(comp_diff_metrics_tim)
437 #ifdef DM_PARALLEL
438 #  include "HALO_EM_TKE_C.inc"
439 #  include "PERIOD_BDY_EM_A1.inc"
440 #endif
442 BENCH_START(tke_diff_bc_tim)
443          !$OMP PARALLEL DO   &
444          !$OMP PRIVATE ( ij )
446          DO ij = 1 , grid%num_tiles
448            CALL wrf_debug ( 200 , ' call bc for diffusion_metrics ' )
449            CALL set_physical_bc3d( grid%rdzw , 'w', config_flags,           &
450                                    ids, ide, jds, jde, kds, kde,       &
451                                    ims, ime, jms, jme, kms, kme,       &
452                                    ips, ipe, jps, jpe, kps, kpe,       &
453                                    grid%i_start(ij), grid%i_end(ij),   &
454                                    grid%j_start(ij), grid%j_end(ij),   &
455                                    k_start    , k_end                 )
456            CALL set_physical_bc3d( grid%rdz , 'w', config_flags,            &
457                                    ids, ide, jds, jde, kds, kde,       &
458                                    ims, ime, jms, jme, kms, kme,       &
459                                    ips, ipe, jps, jpe, kps, kpe,       &
460                                    grid%i_start(ij), grid%i_end(ij),   &
461                                    grid%j_start(ij), grid%j_end(ij),   &
462                                    k_start    , k_end                 )
463            CALL set_physical_bc3d( grid%z , 'w', config_flags,              &
464                                    ids, ide, jds, jde, kds, kde,       &
465                                    ims, ime, jms, jme, kms, kme,       &
466                                    ips, ipe, jps, jpe, kps, kpe,       &
467                                    grid%i_start(ij), grid%i_end(ij),   &
468                                    grid%j_start(ij), grid%j_end(ij),   &
469                                    k_start    , k_end                 )
470            CALL set_physical_bc3d( grid%zx , 'e', config_flags,             &
471                                    ids, ide, jds, jde, kds, kde,       &
472                                    ims, ime, jms, jme, kms, kme,       &
473                                    ips, ipe, jps, jpe, kps, kpe,       &
474                                    grid%i_start(ij), grid%i_end(ij),   &
475                                    grid%j_start(ij), grid%j_end(ij),   &
476                                    k_start    , k_end                 )
477            CALL set_physical_bc3d( grid%zy , 'f', config_flags,             &
478                                    ids, ide, jds, jde, kds, kde,       &
479                                    ims, ime, jms, jme, kms, kme,       &
480                                    ips, ipe, jps, jpe, kps, kpe,       &
481                                    grid%i_start(ij), grid%i_end(ij),   &
482                                    grid%j_start(ij), grid%j_end(ij),   &
483                                    k_start    , k_end                 )
484            CALL set_physical_bc2d( grid%ustm, 't', config_flags,            &
485                                    ids, ide, jds, jde,                 &
486                                    ims, ime, jms, jme,                 &
487                                    ips, ipe, jps, jpe,                 &
488                                    grid%i_start(ij), grid%i_end(ij),   &
489                                    grid%j_start(ij), grid%j_end(ij)   )
490           CALL set_physical_bc2d( grid%ust, 't', config_flags,              &
491                                    ids, ide, jds, jde,                 &
492                                    ims, ime, jms, jme,                 &
493                                    ips, ipe, jps, jpe,                 &
494                                    grid%i_start(ij), grid%i_end(ij),   &
495                                    grid%j_start(ij), grid%j_end(ij)   )
497          ENDDO
498          !$OMP END PARALLEL DO
499 BENCH_END(tke_diff_bc_tim)
501 BENCH_START(deform_div_tim)
503          !$OMP PARALLEL DO   &
504          !$OMP PRIVATE ( ij )
506          DO ij = 1 , grid%num_tiles
508            CALL wrf_debug ( 200 , ' call cal_deform_and_div' )
509            CALL cal_deform_and_div ( config_flags,grid%u_2,grid%v_2,grid%w_2,grid%div,  &
510                                      grid%defor11,grid%defor22,grid%defor33,            &
511                                      grid%defor12,grid%defor13,grid%defor23,            &
512                                      nba_rij, n_nba_rij,                                & !JDM
513                                      grid%u_base, grid%v_base,grid%msfux,grid%msfuy,    &
514                                      grid%msfvx,grid%msfvy,grid%msftx,grid%msfty,       &
515                                      grid%rdx, grid%rdy, grid%dn, grid%dnw, grid%rdz,   &
516                                      grid%rdzw,grid%fnm,grid%fnp,grid%cf1,grid%cf2,     &
517                                      grid%cf3,grid%zx,grid%zy,            &
518                                      ids, ide, jds, jde, kds, kde,        &
519                                      ims, ime, jms, jme, kms, kme,        &
520                                      grid%i_start(ij), grid%i_end(ij),    &
521                                      grid%j_start(ij), grid%j_end(ij),    &
522                                      k_start    , k_end                  )
523          ENDDO
524          !$OMP END PARALLEL DO
525 BENCH_END(deform_div_tim)
527 ! Updraft helicity between output times
529 #ifdef DM_PARALLEL
530 #     include "HALO_EM_HELICITY.inc"
531 #endif
533        IF ( ( config_flags%nwp_diagnostics .eq. 1 ) .OR. &
534             ( ( config_flags%afwa_diag_opt .eq. 1 ) .AND. ( config_flags%afwa_severe_opt .EQ. 1 ) ) ) THEN
535 BENCH_START(helicity_tim)
537        !$OMP PARALLEL DO   &
538        !$OMP PRIVATE ( ij )
540        DO ij = 1 , grid%num_tiles
542           CALL wrf_debug ( 200 , ' call cal_helicity' )
543           CALL cal_helicity ( config_flags,grid%u_2,grid%v_2,grid%w_2,  &
544                               grid%uh,                             &
545                               grid%up_heli_max,                    &
546                               grid%ph_2,grid%phb,                  &
547                               grid%msfux,grid%msfuy,               &
548                               grid%msfvx,grid%msfvy,               &
549                               grid%ht,                             &
550                               grid%rdx, grid%rdy, grid%dn, grid%dnw, grid%rdz, grid%rdzw,   &
551                               grid%fnm,grid%fnp,grid%cf1,grid%cf2,grid%cf3,grid%zx,grid%zy, &
552                               ids, ide, jds, jde, kds, kde,        &
553                               ims, ime, jms, jme, kms, kme,        &
554                               grid%i_start(ij), grid%i_end(ij),    &
555                               grid%j_start(ij), grid%j_end(ij),    &
556                               k_start    , k_end                  )
557        ENDDO
558        !$OMP END PARALLEL DO
559 BENCH_END(helicity_tim)
560        ENDIF
562 #ifdef DM_PARALLEL
563 #     include "HALO_EM_TKE_D.inc"
564 #endif
566 ! calculate tke, kmh, and kmv
568 BENCH_START(calc_tke_tim)
569          !$OMP PARALLEL DO   &
570          !$OMP PRIVATE ( ij )
571          DO ij = 1 , grid%num_tiles
574          IF( config_flags%diff_opt .eq. 2 .and. config_flags%km_opt .eq. 5 ) THEN
575            CALL nonlocal_flux(config_flags,grid%nlflux,grid%gamu,grid%gamv,      &
576                               grid%pblh,grid%kpbl,grid%dx,grid%dy,grid%dt,       &
577                               grid%ust,grid%hfx,grid%qfx,grid%br,ep_1,ep_2,      & 
578                               karman,grid%u_phy,grid%v_phy,th_phy,grid%rho,      & 
579                               moist,num_moist,                                   &
580                               grid%msftx,grid%msfty,grid%rdzw,                   &
581                               grid%u10,grid%v10,grid%wspd,                       &
582                               ids, ide, jds, jde, kds, kde,                      &
583                               ims, ime, jms, jme, kms, kme,                      &
584                               grid%i_start(ij), grid%i_end(ij),                  &
585                               grid%j_start(ij), grid%j_end(ij),                  &
586                               k_start, k_end  )
588            CALL free_atmos_length(config_flags,grid%dx,grid%dy,grid%rdzw,        &
589                                   grid%rdz,grid%tke_2,th_phy,grid%elmin,         &
590                                   grid%hfx,grid%qfx,moist,num_moist,             &
591                                   ids, ide, jds, jde, kds, kde,                  &
592                                   ims, ime, jms, jme, kms, kme,                  &
593                                   grid%i_start(ij),grid%i_end(ij),               &
594                                   grid%j_start(ij), grid%j_end(ij),              &
595                                   k_start, k_end  )
596   
597            CALL meso_length_scale(config_flags,grid%dx,grid%dy,grid%rdzw,        &
598                                   grid%rdz,grid%tke_2,p8w,t8w,th_phy,            &
599                                   grid%dlk,grid%pblh,grid%elmin,                 &
600                                   grid%rmol,grid%rho,grid%hfx,grid%qfx,          &
601                                   moist,num_moist,                               &
602                                   ids, ide, jds, jde, kds, kde,                  &
603                                   ims, ime, jms, jme, kms, kme,                  &
604                                   grid%i_start(ij), grid%i_end(ij),              &
605                                   grid%j_start(ij), grid%j_end(ij),              &
606                                   k_start, k_end  ) 
607          ENDIF
610            CALL wrf_debug ( 200 , ' call calculate_km_kh' )
611            CALL calculate_km_kh( config_flags,grid%dt,grid%dampcoef,grid%zdamp,         &
612                                  config_flags%damp_opt,                                 &
613                                  grid%xkmh,grid%xkmv,grid%xkhh,grid%xkhv,grid%bn2,      &
614                                  grid%khdif,grid%kvdif,grid%div,                        &
615                                  grid%defor11,grid%defor22,grid%defor33,grid%defor12,   &
616                                  grid%defor13,grid%defor23,                             &
617                                  grid%tke_2,p8w,t8w,th_phy,                             &
618                                  t_phy,p_phy,moist,grid%dn,grid%dnw,                    &
619                                  grid%dx,grid%dy,grid%rdz,grid%rdzw,                    &
620                                  config_flags%mix_isotropic,num_moist,                  &
621                                  grid%cf1, grid%cf2, grid%cf3, grid%warm_rain,          &
622                                  grid%mix_upper_bound,                                  &
623                                  grid%msftx, grid%msfty,                                &
624                                  grid%zx, grid%zy,                                      &
625                                  grid%pblh, grid%dlk, grid%xkmv_meso,                   &  
626                                  ids,ide, jds,jde, kds,kde,                             &
627                                  ims,ime, jms,jme, kms,kme,                             &
628                                  grid%i_start(ij), grid%i_end(ij),                      &
629                                  grid%j_start(ij), grid%j_end(ij),                      &
630                                  k_start    , k_end                          )
631          ENDDO
632        !$OMP END PARALLEL DO
633 BENCH_END(calc_tke_tim)
635 #ifdef DM_PARALLEL
636 #     include "HALO_EM_TKE_E.inc"
637 #endif
639        ENDIF
641 #ifdef DM_PARALLEL
642 #      include "PERIOD_BDY_EM_PHY_BC.inc"
643        IF ( config_flags%grid_fdda .eq. 1) THEN
644 #      include "PERIOD_BDY_EM_FDDA_BC.inc"
645        ENDIF
646 #      include "PERIOD_BDY_EM_CHEM.inc"
647 #endif
649 BENCH_START(phy_bc_tim)
650        !$OMP PARALLEL DO   &
651        !$OMP PRIVATE ( ij )
653        DO ij = 1 , grid%num_tiles
655          CALL wrf_debug ( 200 , ' call phy_bc' )
656          CALL phy_bc (config_flags,grid%div,grid%defor11,grid%defor22,grid%defor33,            &
657                       grid%defor12,grid%defor13,grid%defor23,      &
658                       grid%xkmh,grid%xkmv,grid%xkhh,grid%xkhv,     &
659                       grid%tke_2,grid%rho,                         &
660                       grid%rublten, grid%rvblten,                  &
661                       grid%rucuten, grid%rvcuten,                  &
662                       grid%rushten, grid%rvshten,                  &
663                       grid%gamu, grid%gamv, grid%xkmv_meso,        &  ! XZ
664                       ids, ide, jds, jde, kds, kde,                &
665                       ims, ime, jms, jme, kms, kme,                &
666                       ips, ipe, jps, jpe, kps, kpe,                &
667                       grid%i_start(ij), grid%i_end(ij),            &
668                       grid%j_start(ij), grid%j_end(ij),            &
669                       k_start    , k_end                           )
670        ENDDO
671        !$OMP END PARALLEL DO
672 BENCH_END(phy_bc_tim)
674 !JDM
675 IF ( ( config_flags%sfs_opt .GT. 0 ) .AND. ( config_flags%diff_opt .eq. 2 ) ) THEN
677  CALL sfs_driver( grid, config_flags,     &
678                   nba_mij, n_nba_mij,     & 
679                   nba_rij, n_nba_rij      ) 
681 ENDIF
683 #ifdef DM_PARALLEL
684 !-----------------------------------------------------------------------
686 ! MPP for some physics tendency, km, kh, deformation, and divergence
688 !                                                         * * * * * * *
689 !                                            * * * * *    * * * * * * *
690 !               *                     *      * * * * *    * * * * * * *
691 !             * + *      * + *        +      * * + * *    * * * + * * *
692 !               *                     *      * * * * *    * * * * * * *
693 !                                            * * * * *    * * * * * * *
694 !                                                         * * * * * * *
696 ! (for PBL)
697 ! rublten                  x
698 ! rvblten                             x
700 ! (for Cumulus)
701 ! rucuten                  x
702 ! rvcuten                             x
704 ! (for Shallow Cumulus)
705 ! rushten                  x
706 ! rvshten                             x
708 ! (for FDDA)
709 ! rundgdten     x
710 ! rvndgdten     x
712 ! (for TKE3)
713 ! tke_2                                          x               
714 ! (for TKE5)
715 ! tke_2                                                         x
717 ! (for diff_opt >= 1)
718 ! defor11                  x
719 ! defor22                             x
720 ! defor12       x
721 ! defor13                  x
722 ! defor23                             x
723 ! div           x
724 ! xkmv          x
725 ! xkmh          x
726 ! xkhv          x
727 ! xkhh          x
728 ! tke           x
730 !-----------------------------------------------------------------------
731        IF ( config_flags%bl_pbl_physics .ge. 1 ) THEN
732 #      include "HALO_EM_PHYS_PBL.inc"
733        ENDIF
734        IF ( config_flags%shcu_physics .gt. 1 ) THEN
735 #      include "HALO_EM_PHYS_SHCU.inc"
736        ENDIF
737        IF ( config_flags%cu_physics == SASSCHEME      .or.   &
738             config_flags%cu_physics == TIEDTKESCHEME  .or.   &
739             config_flags%cu_physics == NTIEDTKESCHEME .or.   &
740             config_flags%cu_physics == MSKFSCHEME     .or.   &
741             config_flags%cu_physics == CAMZMSCHEME    .or.   &
742             config_flags%cu_physics == SCALESASSCHEME .or.   &
743             config_flags%cu_physics == NSASSCHEME     .or.   &
744             config_flags%cu_physics == KSASSCHEME ) THEN
745 #      include "HALO_EM_PHYS_CU.inc"
746        ENDIF
747        IF ( config_flags%grid_fdda .ge. 1) THEN
748 #      include "HALO_EM_FDDA.inc"
749        ENDIF
750        IF ( config_flags%diff_opt .ge. 1 ) THEN
751 #      include "HALO_EM_PHYS_DIFFUSION.inc"
752        ENDIF
754        IF      ( config_flags%h_sca_adv_order <= 4 ) THEN
755 #       include "HALO_EM_TKE_3.inc"
756        ELSE IF ( config_flags%h_sca_adv_order <= 6 ) THEN
757 #       include "HALO_EM_TKE_5.inc"
758        ELSE
759          WRITE(wrf_err_message,*)'solve_em: invalid h_sca_adv_order = ',config_flags%h_sca_adv_order
760          CALL wrf_error_fatal(TRIM(wrf_err_message))
761        ENDIF
762 #endif
764 BENCH_START(update_phy_ten_tim)
765        !$OMP PARALLEL DO   &
766        !$OMP PRIVATE ( ij )
768        DO ij = 1 , grid%num_tiles
770          CALL wrf_debug ( 200 , ' call update_phy_ten' )
771 #if ( WRF_DFI_RADAR == 1 )
772          if (config_flags%cu_physics .gt. 0) then
773            i_start = grid%i_start(ij)
774            i_end   = min( grid%i_end(ij),ide-1 )
775            j_start = grid%j_start(ij)
776            j_end   = min( grid%j_end(ij),jde-1 )
777            if (grid%dfi_stage == DFI_FWD ) &
778                  CALL wrf_debug ( 200 , ' Zero out cu_physics' )
779            DO j = j_start, j_end
780            DO k = k_start, min( k_end,kde-1 ) - 1
781            DO i = i_start, i_end
782              if (grid%dfi_stage ==DFI_FWD  &
783              .and. grid%dfi_tten_rad(i,k,j) >= 1.0e-7 .and.  &
784                    grid%dfi_tten_rad(i,k,j) <= 10.) then
785 ! zero out cu-param temp tendency
786                 grid%rthcuten(i,k,j) = 0.0
787              endif
788            ENDDO
789            ENDDO
790            ENDDO
791          ENDIF
792 #endif
793          CALL update_phy_ten(ph_tendf,t_tendf, ru_tendf, rv_tendf,moist_tend ,&
794                            scalar_tend, mu_tendf,                           &
795                            grid%rthraten,grid%rthblten,grid%rthcuten,grid%rthshten, &
796                            grid%rublten,grid%rucuten,grid%rushten,          &
797                            grid%rvblten,grid%rvcuten,grid%rvshten,          &
798                            grid%rqvblten,grid%rqcblten,grid%rqiblten,       &
799                            grid%rqniblten,                                  & !CAMUWPBL scheme
800                            grid%rqvcuten,grid%rqccuten,grid%rqrcuten,       &
801                            grid%rqicuten,grid%rqscuten,                     &
802                            grid%rqcncuten,grid%rqincuten,                   & !BSINGH - Added two CU tends
803                            grid%rqvshten,grid%rqcshten,grid%rqrshten,       &
804                            grid%rqishten,grid%rqsshten,grid%rqgshten,       &
805                            grid%rqcnshten,grid%rqinshten,                   &!BSINGH - Added two SHCU tends
806                            grid%RUNDGDTEN,                                  &
807                            grid%RVNDGDTEN,grid%RTHNDGDTEN,grid%RPHNDGDTEN,  &
808                            grid%RQVNDGDTEN,grid%RMUNDGDTEN,                 &
809                            grid%rthfrten,grid%rqvfrten,                     &  ! fire
810                            num_moist,num_scalar,config_flags,rk_step,       &
811                            grid%adv_moist_cond,                             &
812                            ids, ide, jds, jde, kds, kde,                    &
813                            ims, ime, jms, jme, kms, kme,                    &
814                            grid%i_start(ij), grid%i_end(ij),                &
815                            grid%j_start(ij), grid%j_end(ij),                &
816                            k_start, k_end                               )
818        END DO
819        !$OMP END PARALLEL DO
820 BENCH_END(update_phy_ten_tim)
822       IF (grid%skebs_on==1) then
823           !$OMP PARALLEL DO   &
824           !$OMP PRIVATE ( ij )
825           DO ij = 1 , grid%num_tiles
826                CALL wrf_debug ( 200 , ' call update_stoch_ten' )
827                 CALL update_stoch_ten(ru_tendf, rv_tendf, t_tendf,&
828                                grid%ru_tendf_stoch,                          &
829                                grid%rv_tendf_stoch,                          &
830                                grid%rt_tendf_stoch,                          &
831                                grid%mu_2, grid%mub, grid%c1h, grid%c2h,      &
832                                ids, ide, jds, jde, kds, kde,                 &
833                                ims, ime, jms, jme, kms, kme,                 &
834                                grid%i_start(ij), grid%i_end(ij),             &
835                                grid%j_start(ij), grid%j_end(ij),             &
836                                k_start, k_end,                               &
837                                grid%num_stoch_levels,grid%num_stoch_levels   )
839            ENDDO
840            !$OMP END PARALLEL DO
841       ENDIF !skebs_on
843       IF (grid%sppt_on==1) then
844           !$OMP PARALLEL DO   &
845           !$OMP PRIVATE ( ij )
846           DO ij = 1 , grid%num_tiles
847                  call perturb_physics_tend(grid%gridpt_stddev_sppt,          &
848                         grid%stddev_cutoff_sppt,grid%rstoch,                 &
849                         ru_tendf,rv_tendf,t_tendf,                           &
850                         moist_tend(ims,kms,jms,p_qv),                        &
851                         ids, ide, jds, jde, kds, kde,                        &
852                         ims, ime, jms, jme, kms, kme,                        &
853                         grid%i_start(ij), grid%i_end(ij),                    &
854                         grid%j_start(ij), grid%j_end(ij),                    &
855                         k_start, k_end,                                      &
856                         grid%num_stoch_levels,grid%num_stoch_levels          )
857            ENDDO
858           !$OMP END PARALLEL DO
859   ENDIF
861 #ifdef PLANET
862        ! do rayleigh (and zonal-average newtonian) damping during
863        ! first iteration of RK loop only
865 =============================================================
866 INTENTIONALLY PLACED HERE TO BREAK COMPILE
867 1. The DAMPTOP routine needs to have 1d column arrays c1 and c2
868 to correctly use the column pressures mut, muu, and muv.
869 2. The DAMPTOP routine needs to have the grid%t_2 evaluated
870 to see if perturbation of moist potential temperature is OK.
871 =============================================================
873        IF ( (config_flags%damp_opt == 101) .OR. &
874             (config_flags%damp_opt == 103)      ) THEN
875          !$OMP PARALLEL DO   &
876          !$OMP PRIVATE ( ij )
877          DO ij = 1 , grid%num_tiles
878            CALL damptop( grid%u_2, grid%v_2, grid%t_2, &
879                          grid%mut, grid%muu, grid%muv, &
880                          pi_phy,                                &
881                          t_tendf, ru_tendf, rv_tendf, P2SI,     &
882                          ids, ide, jds, jde, kds, kde,          &
883                          ims, ime, jms, jme, kms, kme,          &
884                          grid%i_start(ij), grid%i_end(ij),      &
885                          grid%j_start(ij), grid%j_end(ij),      &
886                          k_start, k_end                         )
887          END DO
888          !$OMP END PARALLEL DO
889        END IF
890 #endif
892        IF( config_flags%diff_opt .eq. 2 .and. ( config_flags%km_opt .eq. 2 .or. &
893            config_flags%km_opt .eq. 5 ) ) THEN  ! XZ
895 BENCH_START(tke_rhs_tim)
896          !$OMP PARALLEL DO   &
897          !$OMP PRIVATE ( ij )
898          DO ij = 1 , grid%num_tiles
900            CALL tke_rhs  ( tke_tend,grid%bn2,                           &
901                          config_flags,grid%defor11,grid%defor22,      &
902                          grid%defor33,                                &
903                          grid%defor12,grid%defor13,grid%defor23,      &
904                          grid%u_2,grid%v_2,grid%w_2,grid%div,         &
905                          grid%tke_2,grid%mut,grid%c1h,grid%c2h,       &
906                          th_phy,p_phy,p8w,t8w,grid%z,grid%fnm,        & 
907                          grid%fnp,grid%cf1,grid%cf2,grid%cf3,         &     
908                          grid%msftx,grid%msfty,grid%xkmh,             &
909                          grid%xkmv,grid%xkhv,grid%rdx,grid%rdy,       &
910                          grid%dx,grid%dy,grid%dt,grid%zx,grid%zy,     &
911                          grid%rdz,grid%rdzw,grid%dn,                  &
912                          grid%dnw,config_flags%mix_isotropic,         &
913                          grid%hfx, grid%qfx, moist(ims,kms,jms,P_QV), &
914                          grid%ustm, grid%rho,                         &
915                          grid%l_diss, grid%nlflux,                    & !XZ
916                          grid%pblh, grid%dlk,                         & !XZ 
917                          ids, ide, jds, jde, kds, kde,                &
918                          ims, ime, jms, jme, kms, kme,                &
919                          grid%i_start(ij), grid%i_end(ij),            &
920                          grid%j_start(ij), grid%j_end(ij),            &
921                          k_start    , k_end                           )
923          ENDDO
924          !$OMP END PARALLEL DO
925 BENCH_END(tke_rhs_tim)
927        ENDIF
929        IF ( grid%obs_nudge_opt .EQ. 1 .AND. grid%xtime <= grid%fdda_end ) THEN
930 # ifdef DM_PARALLEL
931 #       include "HALO_OBS_NUDGE.inc"
932 #endif
933 !***********************************************************************
934 ! This section for obs nudging
935          !$OMP PARALLEL DO   &
936          !$OMP PRIVATE ( ij )
938          DO ij = 1 , grid%num_tiles
940            CALL fddaobs_driver (grid%grid_id, model_config_rec%grid_id, &
941                    model_config_rec%parent_id, config_flags%restart,    &
942                    config_flags,                                        &
943                    grid%obs_nudge_opt,                                  &
944                    grid%obs_ipf_errob,                                  &
945                    grid%obs_ipf_nudob,                                  &
946                    grid%fdda_start,                                     &
947                    grid%fdda_end,                                       &
948                    grid%obs_nudge_wind,                                 &
949                    grid%obs_nudge_temp,                                 &
950                    grid%obs_nudge_mois,                                 &
951                    grid%obs_nudge_pstr,                                 &
952                    grid%obs_coef_wind,                                  &
953                    grid%obs_coef_temp,                                  &
954                    grid%obs_coef_mois,                                  &
955                    grid%obs_coef_pstr,                                  &             
956                    grid%obs_rinxy,                                      &
957                    grid%obs_rinsig,                                     &
958                    grid%obs_npfi,                                       &
959                    grid%obs_ionf,                                       &
960                    grid%obs_prt_max,                                    &
961                    grid%obs_prt_freq,                                   &
962                    grid%obs_idynin,                                     &
963                    grid%obs_dtramp,                                     &
964                    grid%parent_grid_ratio,                              &
965                    grid%max_dom, grid%itimestep,                        &
966                    grid%xtime,                                          &
967                    grid%dt, grid%gmt, grid%julday, grid%fdob,           &
968                    grid%max_obs,                                        &
969                    model_config_rec%nobs_ndg_vars,                      &
970                    model_config_rec%nobs_err_flds,                      &
971                    grid%fdob%nstat, grid%fdob%varobs, grid%fdob%errf,   &
972                    grid%dx, grid%KPBL,grid%HT,                          &
973                    grid%mut, grid%muu, grid%muv, grid%c1h, grid%c2h,    &
974                    grid%msftx, grid%msfty, grid%msfux, grid%msfuy, grid%msfvx, grid%msfvy, &
975                    p_phy, t_tendf, t0,                                  &
976                    grid%u_2, grid%v_2, grid%th_phy_m_t0,                &
977                    moist(ims,kms,jms,P_QV),                             &
978                    grid%pb, grid%p_top, grid%p, grid%phb, grid%ph_2,    &
979                    grid%uratx, grid%vratx, grid%tratx,                  &
980                    ru_tendf, rv_tendf,                                  &
981                    moist_tend(ims,kms,jms,P_QV), grid%obs_savwt,        &
982                    grid%regime, grid%pblh, grid%z_at_w, grid%z,         &
983                    ids,ide, jds,jde, kds,kde,                           &
984                    ims,ime, jms,jme, kms,kme,                           &
985                    grid%i_start(ij), min(grid%i_end(ij),ide-1),         &
986                    grid%j_start(ij), min(grid%j_end(ij),jde-1),         &
987                    k_start    , min(k_end,kde-1)                     )
989          ENDDO
990          !$OMP END PARALLEL DO
991        ENDIF  ! obs_nudge_opt .eq. 1
993        IF ( config_flags%use_theta_m .EQ. 1 ) THEN
994          !$OMP PARALLEL DO   &
995          !$OMP PRIVATE ( ij )
996          DO ij = 1 , grid%num_tiles
997            CALL conv_t_tendf_to_moist ( grid%t_1 , moist_old(ims,kms,jms,P_qv) ,  &
998                                         t_tendf  , moist_tend(ims,kms,jms,P_qv) , &
999                                         ids, ide, jds, jde, kds, kde ,            &
1000                                         ims, ime, jms, jme, kms, kme ,            &
1001                                         grid%i_start(ij), grid%i_end(ij),         &
1002                                         grid%j_start(ij), grid%j_end(ij),         &
1003                                         k_start    , k_end                        )
1004          END DO 
1005          !$OMP END PARALLEL DO
1006        END IF ! use moist theta
1008 ! calculate vertical diffusion first and then horizontal
1009 ! (keep this order)
1011        IF(config_flags%diff_opt .eq. 2) THEN
1013          IF (config_flags%bl_pbl_physics .eq. 0) THEN
1015 !XZ    implicit solver for vertical diffusion tendency
1016          IF( config_flags%km_opt .eq. 5 ) THEN
1017               !$OMP PARALLEL DO   &
1018               !$OMP PRIVATE ( ij )
1019               DO ij = 1 , grid%num_tiles
1020               CALL vertical_diffusion_implicit(ru_tendf, rv_tendf, rw_tendf,                              &
1021                                                t_tendf, tke_tend,                                         &
1022                                                moist_tend, num_moist,                                     &
1023                                                chem_tend, num_chem,                                       &
1024                                                scalar_tend, num_scalar,                                   &
1025                                                tracer_tend, num_tracer,                                   &
1026                                                grid%u_2, grid%v_2,grid%w_2,grid%dt,                       &
1027                                                grid%t_2,grid%u_base,grid%v_base,grid%t_base,grid%qv_base, &
1028                                                grid%mut,grid%tke_2,th_phy,config_flags,                   &
1029                                                moist, chem, scalar, tracer,                               &
1030                                                grid%xkmv, grid%xkhv, grid%xkmh, config_flags%km_opt,      &
1031                                                grid%fnm, grid%fnp, grid%dn, grid%dnw, grid%rdz, grid%rdzw,&
1032                                                grid%hfx, grid%qfx, grid%ustm, grid%rho,                   &
1033                                                grid%nlflux, grid%gamu, grid%gamv,                         & 
1034                                                grid%xkmv_meso, grid%l_diss,                               &
1035                                                grid%c1h, grid%c2h, grid%c1f, grid%c2f,                    &
1036                                                ids, ide, jds, jde, kds, kde,                              &
1037                                                ims, ime, jms, jme, kms, kme,                              &
1038                                                grid%i_start(ij), grid%i_end(ij),                          &
1039                                                grid%j_start(ij), grid%j_end(ij),                          &
1040                                                k_start, k_end      )
1041               ENDDO
1042               !$OMP END PARALLEL DO
1044          ELSE  ! original explicit 
1046 BENCH_START(vert_diff_tim)
1047            !$OMP PARALLEL DO   &
1048            !$OMP PRIVATE ( ij )
1049            DO ij = 1 , grid%num_tiles
1051              CALL wrf_debug ( 200 , ' call vertical_diffusion_2 ' )
1052              CALL vertical_diffusion_2( ru_tendf, rv_tendf, rw_tendf,            &
1053                                       t_tendf, tke_tend,                         &
1054                                       moist_tend, num_moist,                      &
1055                                       chem_tend, num_chem,                       &
1056                                       scalar_tend, num_scalar,                     &
1057                                       tracer_tend, num_tracer,                     &
1058                                       grid%u_2, grid%v_2,                                  &
1059                                       grid%t_2,grid%u_base,grid%v_base,grid%t_base,grid%qv_base,          &
1060                                       grid%tke_2, th_phy, config_flags,              &
1061                                       grid%defor13,grid%defor23,grid%defor33,                   &
1062                                       nba_mij, num_nba_mij,          & !JDM
1063                                       grid%div, moist, chem, scalar,tracer,         &
1064                                       grid%xkmv, grid%xkhv, grid%xkmh, config_flags%km_opt,       & ! xkmh added Oct2013
1065                                       grid%fnm, grid%fnp, grid%dn, grid%dnw, grid%rdz, grid%rdzw, &
1066                                       grid%hfx, grid%qfx, grid%ustm, grid%rho,   &
1067                                       ids, ide, jds, jde, kds, kde,              &
1068                                       ims, ime, jms, jme, kms, kme,              &
1069                                       grid%i_start(ij), grid%i_end(ij),          &
1070                                       grid%j_start(ij), grid%j_end(ij),          &
1071                                       k_start, k_end                             )
1073            ENDDO
1074            !$OMP END PARALLEL DO
1075 BENCH_END(vert_diff_tim)
1077          ENDIF
1078         ENDIF
1080 BENCH_START(hor_diff_tim)
1081          !$OMP PARALLEL DO   &
1082          !$OMP PRIVATE ( ij )
1083          DO ij = 1 , grid%num_tiles
1085            CALL wrf_debug ( 200 , ' call horizontal_diffusion_2' )
1086            CALL horizontal_diffusion_2( t_tendf, ru_tendf, rv_tendf, rw_tendf, &
1087                                       tke_tend,                              &
1088                                       moist_tend, num_moist,                  &
1089                                       chem_tend, num_chem,                   &
1090                                       scalar_tend, num_scalar,                 &
1091                                       tracer_tend, num_tracer,                 &
1092                                       grid%t_2, th_phy,                           &
1093                                       grid%tke_2, config_flags,              &
1094                                       grid%defor11, grid%defor22, grid%defor12,             &
1095                                       grid%defor13, grid%defor23,   &
1096                                       nba_mij, num_nba_mij,         & !JDM
1097                                       grid%div,                     &
1098                                       moist, chem, scalar,tracer,               &
1099                                       grid%msfux,grid%msfuy, grid%msfvx,grid%msfvy, grid%msftx,  &
1100                                       grid%msfty, grid%xkmh, grid%xkmv, grid%xkhh, config_flags%km_opt,     &
1101                                       grid%rdx, grid%rdy, grid%rdz, grid%rdzw,                   &
1102                                       grid%fnm, grid%fnp, grid%cf1, grid%cf2, grid%cf3,          &
1103                                       grid%zx, grid%zy, grid%dn, grid%dnw, grid%rho,             &
1104                                       ids, ide, jds, jde, kds, kde,          &
1105                                       ims, ime, jms, jme, kms, kme,          &
1106                                       grid%i_start(ij), grid%i_end(ij),      &
1107                                       grid%j_start(ij), grid%j_end(ij),      &
1108                                       k_start    , k_end                    )
1109          ENDDO
1110          !$OMP END PARALLEL DO
1111 BENCH_END(hor_diff_tim)
1112        ENDIF
1115 !***********************************************************************
1117   END SUBROUTINE first_rk_step_part2
1119 END MODULE module_first_rk_step_part2