1 !WRF:MEDIATION_LAYER:couple_uncouple_utility
3 SUBROUTINE couple_or_uncouple_em ( grid , config_flags , couple &
5 #include "dummy_new_args.inc"
12 ! Driver layer modules
13 USE module_domain, ONLY : domain, get_ijk_from_grid
14 USE module_configure, ONLY : grid_config_rec_type
15 USE module_driver_constants
19 USE module_dm, ONLY : local_communicator, mytask, ntasks, ntasks_x, ntasks_y, local_communicator_periodic
20 USE module_comm_dm, ONLY : halo_em_couple_a_sub,halo_em_couple_b_sub,period_em_couple_a_sub,period_em_couple_b_sub
25 ! Mediation layer modules
26 ! Registry generated module
27 USE module_state_description
31 ! Subroutine interface block.
33 TYPE(domain) , TARGET :: grid
35 ! Definitions of dummy arguments to solve
36 #include "dummy_new_decl.inc"
39 TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags
41 LOGICAL, INTENT( IN) :: couple
45 INTEGER :: k_start , k_end
46 INTEGER :: ids , ide , jds , jde , kds , kde , &
47 ims , ime , jms , jme , kms , kme , &
48 ips , ipe , jps , jpe , kps , kpe
51 INTEGER :: num_3d_c, num_3d_m, num_3d_s
54 REAL, DIMENSION(grid%sm31:grid%em31,grid%sm32:grid%em32,grid%sm33:grid%em33) :: mutf_2, muth_2, muut_2, muvt_2, muwt_2
56 ! De-reference dimension information stored in the grid data structure.
57 IF ( .NOT. grid%active_this_task ) RETURN
59 CALL get_ijk_from_grid ( grid , &
60 ids, ide, jds, jde, kds, kde, &
61 ims, ime, jms, jme, kms, kme, &
62 ips, ipe, jps, jpe, kps, kpe )
68 ! couple or uncouple mass-point variables
69 ! first, compute mu or its reciprical as necessary
71 ! write(6,*) ' in couple '
72 ! write(6,*) ' x,y memory ', grid%sm31,grid%em31,grid%sm33,grid%em33
73 ! write(6,*) ' x,y patch ', ips, ipe, jps, jpe
77 ! write(6,*) ' coupling variables for grid ',grid%id
78 ! write(6,*) ' ips, ipe, jps, jpe ',ips,ipe,jps,jpe
80 ! write(6,*) ' uncoupling variables for grid ',grid%id
81 ! write(6,*) ' ips, ipe, jps, jpe ',ips,ipe,jps,jpe
82 ! write(6,*) ' x, y, size ',size(mu_2,1),size(mu_2,2)
86 IF ( config_flags%periodic_x .OR. config_flags%periodic_y ) THEN
87 CALL set_physical_bc2d( grid%mub, 't', &
89 ids,ide, jds,jde, & ! domain dims
90 ims,ime, jms,jme, & ! memory dims
91 ips,ipe, jps,jpe, & ! patch dims
93 CALL set_physical_bc2d( grid%mu_1, 't', &
95 ids,ide, jds,jde, & ! domain dims
96 ims,ime, jms,jme, & ! memory dims
97 ips,ipe, jps,jpe, & ! patch dims
99 CALL set_physical_bc2d( grid%mu_2, 't', &
101 ids,ide, jds,jde, & ! domain dims
102 ims,ime, jms,jme, & ! memory dims
103 ips,ipe, jps,jpe, & ! patch dims
109 # include "HALO_EM_COUPLE_A.inc"
110 # include "PERIOD_EM_COUPLE_A.inc"
113 ! computations go out one row and column to avoid having to communicate before solver
117 ! write(6,*) ' coupling: setting mu arrays '
119 DO j = max(jds,jps),min(jde-1,jpe)
121 DO i = max(ids,ips),min(ide-1,ipe)
122 mutf_2(i,k,j) = (grid%c1f(k)*grid%Mub(i,j)+grid%c2f(k)) + (grid%c1f(k)*grid%Mu_2(i,j))
123 muwt_2(i,k,j) = ((grid%c1f(k)*grid%Mub(i,j)+grid%c2f(k)) + (grid%c1f(k)*grid%Mu_2(i,j)))/grid%msfty(i,j) ! w coupled with y
128 DO j = max(jds,jps),min(jde-1,jpe)
130 DO i = max(ids,ips),min(ide-1,ipe)
131 muth_2(i,k,j) = (grid%c1h(k)*grid%mub(i,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j))
136 ! need boundary condition fixes for u and v ???
138 ! write(6,*) ' coupling: setting muv and muv arrays '
140 DO j = max(jds,jps),min(jde-1,jpe)
142 DO i = max(ids,ips),min(ide-1,ipe)
143 muut_2(i,k,j) = 0.5*((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i-1,j)))/grid%msfuy(i,j) ! u coupled with y
144 muvt_2(i,k,j) = 0.5*((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i,j-1)))/grid%msfvx(i,j) ! v coupled with x
149 IF ( config_flags%nested .or. config_flags%specified .or. config_flags%polar ) THEN
151 IF ( jpe .eq. jde ) THEN
154 DO i = max(ids,ips),min(ide-1,ipe)
155 muvt_2(i,k,j) = ((grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j-1)))/grid%msfvx(i,j) ! v coupled with x
159 IF ( ipe .eq. ide .AND. .NOT. config_flags%periodic_x ) THEN
161 DO j = max(jds,jps),min(jde-1,jpe)
163 muut_2(i,k,j) = ((grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i-1,j)))/grid%msfuy(i,j) ! u coupled with y
170 IF ( jpe .eq. jde ) THEN
173 DO i = max(ids,ips),min(ide-1,ipe)
174 muvt_2(i,k,j) = 0.5*((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i,j-1)))/grid%msfvx(i,j) ! v coupled with x
178 IF ( ipe .eq. ide ) THEN
180 DO j = max(jds,jps),min(jde-1,jpe)
182 muut_2(i,k,j) = 0.5*((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i-1,j)))/grid%msfuy(i,j) ! u coupled with y
191 ! write(6,*) ' uncoupling: setting mu arrays '
193 DO j = max(jds,jps),min(jde-1,jpe)
195 DO i = max(ids,ips),min(ide-1,ipe)
196 mutf_2(i,k,j) = 1./((grid%c1f(k)*grid%Mub(i,j)+grid%c2f(k)) + (grid%c1f(k)*grid%Mu_2(i,j)))
197 muwt_2(i,k,j) = grid%msfty(i,j)/((grid%c1f(k)*grid%Mub(i,j)+grid%c2f(k)) + (grid%c1f(k)*grid%Mu_2(i,j))) ! w coupled with y
202 DO j = max(jds,jps),min(jde-1,jpe)
204 DO i = max(ids,ips),min(ide-1,ipe)
205 muth_2(i,k,j) = 1./((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)))
210 ! write(6,*) ' uncoupling: setting muv arrays '
212 DO j = max(jds,jps),min(jde-1,jpe)
214 DO i = max(ids,ips),min(ide-1,ipe)
215 muut_2(i,k,j) = 2.*grid%msfuy(i,j)/((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i-1,j))) ! u coupled with y
220 DO j = max(jds,jps),min(jde-1,jpe)
222 DO i = max(ids,ips),min(ide-1,ipe)
223 muvt_2(i,k,j) = 2.*grid%msfvx(i,j)/((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i,j-1))) ! v coupled with x
228 IF ( config_flags%nested .or. config_flags%specified .or. config_flags%polar ) THEN
230 IF ( jpe .eq. jde ) THEN
233 DO i = max(ids,ips),min(ide-1,ipe)
234 muvt_2(i,k,j) = grid%msfvx(i,j)/((grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j-1))) ! v coupled with x
238 IF ( ipe .eq. ide .AND. .NOT. config_flags%periodic_x ) THEN
240 DO j = max(jds,jps),min(jde-1,jpe)
242 muut_2(i,k,j) = grid%msfuy(i,j)/((grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i-1,j))) ! u coupled with y
249 IF ( jpe .eq. jde ) THEN
252 DO i = max(ids,ips),min(ide-1,ipe)
253 muvt_2(i,k,j) = 2.*grid%msfvx(i,j)/((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i,j-1)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i,j-1))) ! v coupled with x
257 IF ( ipe .eq. ide ) THEN
259 DO j = max(jds,jps),min(jde-1,jpe)
261 muut_2(i,k,j) = 2.*grid%msfuy(i,j)/((grid%c1h(k)*grid%mub(i,j)+grid%c2h(k))+(grid%c1h(k)*grid%mub(i-1,j)+grid%c2h(k)) + (grid%c1h(k)*grid%mu_2(i,j)) + (grid%c1h(k)*grid%mu_2(i-1,j))) ! u coupled with y
270 ! couple/uncouple mu point variables
273 !$OMP PRIVATE ( i,j,k,im )
274 DO j = max(jds,jps),min(jde-1,jpe)
277 DO i = max(ids,ips),min(ide-1,ipe)
278 grid%ph_2(i,k,j) = grid%ph_2(i,k,j)*mutf_2(i,k,j)
279 grid%w_2(i,k,j) = grid%w_2(i,k,j)*muwt_2(i,k,j)
284 DO i = max(ids,ips),min(ide-1,ipe)
285 grid%t_2(i,k,j) = grid%t_2(i,k,j)*muth_2(i,k,j)
289 IF (num_3d_m >= PARAM_FIRST_SCALAR ) THEN
290 DO im = PARAM_FIRST_SCALAR, num_3d_m
292 DO i = max(ids,ips),min(ide-1,ipe)
293 moist(i,k,j,im) = moist(i,k,j,im)*muth_2(i,k,j)
299 IF (num_3d_c >= PARAM_FIRST_SCALAR ) THEN
300 DO im = PARAM_FIRST_SCALAR, num_3d_c
302 DO i = max(ids,ips),min(ide-1,ipe)
303 chem(i,k,j,im) = chem(i,k,j,im)*muth_2(i,k,j)
309 IF (num_3d_s >= PARAM_FIRST_SCALAR ) THEN
310 DO im = PARAM_FIRST_SCALAR, num_3d_s
312 DO i = max(ids,ips),min(ide-1,ipe)
313 scalar(i,k,j,im) = scalar(i,k,j,im)*muth_2(i,k,j)
319 IF (num_tracer >= PARAM_FIRST_SCALAR ) THEN
320 DO im = PARAM_FIRST_SCALAR, num_tracer
322 DO i = max(ids,ips),min(ide-1,ipe)
323 tracer(i,k,j,im) = tracer(i,k,j,im)*muth_2(i,k,j)
332 DO i = max(ids,ips),min(ide,ipe)
333 grid%u_2(i,k,j) = grid%u_2(i,k,j)*muut_2(i,k,j)
338 !$OMP END PARALLEL DO
341 !$OMP PRIVATE ( i,j,k )
342 DO j = max(jds,jps),min(jde,jpe)
344 DO i = max(ids,ips),min(ide-1,ipe)
345 grid%v_2(i,k,j) = grid%v_2(i,k,j)*muvt_2(i,k,j)
349 !$OMP END PARALLEL DO
351 IF ( config_flags%periodic_x .OR. config_flags%periodic_y ) THEN
352 CALL set_physical_bc3d( grid%ph_1, 'w', &
354 ids,ide, jds,jde, kds,kde, & ! domain dims
355 ims,ime, jms,jme, kms,kme, & ! memory dims
356 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
357 ips,ipe, jps,jpe, kps,kpe )
358 CALL set_physical_bc3d( grid%ph_2, 'w', &
360 ids,ide, jds,jde, kds,kde, & ! domain dims
361 ims,ime, jms,jme, kms,kme, & ! memory dims
362 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
363 ips,ipe, jps,jpe, kps,kpe )
364 CALL set_physical_bc3d( grid%w_1, 'w', &
366 ids,ide, jds,jde, kds,kde, & ! domain dims
367 ims,ime, jms,jme, kms,kme, & ! memory dims
368 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
369 ips,ipe, jps,jpe, kps,kpe )
370 CALL set_physical_bc3d( grid%w_2, 'w', &
372 ids,ide, jds,jde, kds,kde, & ! domain dims
373 ims,ime, jms,jme, kms,kme, & ! memory dims
374 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
375 ips,ipe, jps,jpe, kps,kpe )
376 CALL set_physical_bc3d( grid%t_1, 't', &
378 ids,ide, jds,jde, kds,kde, & ! domain dims
379 ims,ime, jms,jme, kms,kme, & ! memory dims
380 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
381 ips,ipe, jps,jpe, kps,kpe )
382 CALL set_physical_bc3d( grid%t_2, 't', &
384 ids,ide, jds,jde, kds,kde, & ! domain dims
385 ims,ime, jms,jme, kms,kme, & ! memory dims
386 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
387 ips,ipe, jps,jpe, kps,kpe )
388 CALL set_physical_bc3d( grid%u_1, 'u', &
390 ids,ide, jds,jde, kds,kde, & ! domain dims
391 ims,ime, jms,jme, kms,kme, & ! memory dims
392 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
393 ips,ipe, jps,jpe, kps,kpe )
394 CALL set_physical_bc3d( grid%u_2, 'u', &
396 ids,ide, jds,jde, kds,kde, & ! domain dims
397 ims,ime, jms,jme, kms,kme, & ! memory dims
398 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
399 ips,ipe, jps,jpe, kps,kpe )
400 CALL set_physical_bc3d( grid%v_1, 'v', &
402 ids,ide, jds,jde, kds,kde, & ! domain dims
403 ims,ime, jms,jme, kms,kme, & ! memory dims
404 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
405 ips,ipe, jps,jpe, kps,kpe )
406 CALL set_physical_bc3d( grid%v_2, 'v', &
408 ids,ide, jds,jde, kds,kde, & ! domain dims
409 ims,ime, jms,jme, kms,kme, & ! memory dims
410 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
411 ips,ipe, jps,jpe, kps,kpe )
413 IF (num_3d_m >= PARAM_FIRST_SCALAR) THEN
414 DO im = PARAM_FIRST_SCALAR , num_3d_m
416 CALL set_physical_bc3d( moist(ims,kms,jms,im), 'p', &
418 ids,ide, jds,jde, kds,kde, & ! domain dims
419 ims,ime, jms,jme, kms,kme, & ! memory dims
420 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
421 ips,ipe, jps,jpe, kps,kpe )
426 IF (num_3d_c >= PARAM_FIRST_SCALAR) THEN
427 DO im = PARAM_FIRST_SCALAR , num_3d_c
429 CALL set_physical_bc3d( chem(ims,kms,jms,im), 'p', &
431 ids,ide, jds,jde, kds,kde, & ! domain dims
432 ims,ime, jms,jme, kms,kme, & ! memory dims
433 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
434 ips,ipe, jps,jpe, kps,kpe )
438 IF (num_3d_s >= PARAM_FIRST_SCALAR) THEN
439 DO im = PARAM_FIRST_SCALAR , num_3d_s
441 CALL set_physical_bc3d( scalar(ims,kms,jms,im), 'p', &
443 ids,ide, jds,jde, kds,kde, & ! domain dims
444 ims,ime, jms,jme, kms,kme, & ! memory dims
445 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
446 ips,ipe, jps,jpe, kps,kpe )
450 IF (num_tracer >= PARAM_FIRST_SCALAR) THEN
451 DO im = PARAM_FIRST_SCALAR , num_tracer
453 CALL set_physical_bc3d( tracer(ims,kms,jms,im), 'p', &
455 ids,ide, jds,jde, kds,kde, & ! domain dims
456 ims,ime, jms,jme, kms,kme, & ! memory dims
457 ips,ipe, jps,jpe, kps,kpe, & ! patch dims
458 ips,ipe, jps,jpe, kps,kpe )
465 # include "HALO_EM_COUPLE_B.inc"
466 # include "PERIOD_EM_COUPLE_B.inc"
469 END SUBROUTINE couple_or_uncouple_em
471 LOGICAL FUNCTION cd_feedback_mask( pig, ips_save, ipe_save , pjg, jps_save, jpe_save, xstag, ystag )
473 INTEGER, INTENT(IN) :: pig, ips_save, ipe_save , pjg, jps_save, jpe_save
474 LOGICAL, INTENT(IN) :: xstag, ystag
476 INTEGER ioff, joff, spec_zone
478 CALL nl_get_spec_zone( 1, spec_zone )
480 IF ( xstag ) ioff = 1
481 IF ( ystag ) joff = 1
483 cd_feedback_mask = ( pig .ge. ips_save+spec_zone .and. &
484 pjg .ge. jps_save+spec_zone .and. &
485 pig .le. ipe_save-spec_zone +ioff .and. &
486 pjg .le. jpe_save-spec_zone +joff )
489 END FUNCTION cd_feedback_mask