2 ! ======================================================================================
3 ! This file was generated by the version 5.3.6 of DFT on 07/15/2010. The differentiation
4 ! transforming system(DFT) was jointly developed and sponsored by LASG of IAP(1998-2010)
5 ! and LSEC of ICMSEC, AMSS(2001-2003)
6 ! The copyright of the DFT system was declared by Walls at LASG, 1998-2010
7 ! ======================================================================================
9 MODULE g_module_advect_em
11 USE module_bc !REVISED BY WALLS
12 USE module_model_constants
17 ! Generated by TAPENADE (INRIA, Tropics team)
18 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
20 ! Differentiation of advect_u in forward (tangent) mode:
21 ! variations of useful results: tendency
22 ! with respect to varying inputs: rom u tendency u_old ru rv
24 ! RW status of diff variables: rom:in u:in tendency:in-out u_old:in
26 SUBROUTINE G_ADVECT_U(u, ud, u_old, u_oldd, tendency, tendencyd, ru, rud&
27 & , rv, rvd, rom, romd, mut, mutd, time_step, config_flags, msfux, msfuy&
28 & , msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzw, ids, ide, jds&
29 & , jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts&
33 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
34 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
35 & jme, kms, kme, its, ite, jts, jte, kts, kte
36 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: u, u_old, ru&
38 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ud, u_oldd, &
40 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
41 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd
42 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
43 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
44 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
46 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
47 REAL, INTENT(IN) :: rdx, rdy
48 INTEGER, INTENT(IN) :: time_step
50 INTEGER :: i, j, k, itf, jtf, ktf
51 INTEGER :: i_start, i_end, j_start, j_end
52 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
53 INTEGER :: jmin, jmax, jp, jm, imin, imax, im, ip
54 INTEGER :: jp1, jp0, jtmp
55 INTEGER :: horz_order, vert_order
56 REAL :: mrdx, mrdy, ub, vb, uw, vw, dvm, dvp
57 REAL :: ubd, vbd, vwd, dvmd, dvpd
58 REAL, DIMENSION(its:ite, kts:kte) :: vflux
59 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
60 REAL, DIMENSION(its - 1:ite + 1, kts:kte) :: fqx
61 REAL, DIMENSION(its-1:ite+1, kts:kte) :: fqxd
62 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
63 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
64 LOGICAL :: degrade_xs, degrade_ys
65 LOGICAL :: degrade_xe, degrade_ye
66 ! definition of flux operators, 3rd, 4th, 5th or 6th order
67 REAL :: flux3, flux4, flux5, flux6
68 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
74 IF (config_flags%specified .OR. config_flags%nested) specified = &
76 ! set order for vertical and horzontal flux operators
77 horz_order = config_flags%h_mom_adv_order
78 vert_order = config_flags%v_mom_adv_order
79 IF (kte .GT. kde - 1) THEN
84 ! begin with horizontal flux divergence
85 IF (horz_order .EQ. 6) THEN
86 ! determine boundary mods for flux operators
87 ! We degrade the flux operators from 3rd/4th order
88 ! to second order one gridpoint in from the boundaries for
89 ! all boundary conditions except periodic and symmetry - these
90 ! conditions have boundary zone data fill for correct application
91 ! of the higher order flux stencils
96 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
97 & its .GT. ids + 3) degrade_xs = .false.
98 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
99 & ite .LT. ide - 2) degrade_xe = .false.
100 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
101 & jts .GT. jds + 3) degrade_ys = .false.
102 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
103 & jte .LT. jde - 4) degrade_ye = .false.
104 !--------------- y - advection first
107 IF (config_flags%open_xs .OR. specified) THEN
108 IF (ids + 1 .LT. its) THEN
114 IF (config_flags%open_xe .OR. specified) THEN
115 IF (ide - 1 .GT. ite) THEN
121 IF (config_flags%periodic_x) i_start = its
122 IF (config_flags%periodic_x) i_end = ite
124 IF (jte .GT. jde - 1) THEN
129 ! higher order flux has a 5 or 7 point stencil, so compute
130 ! bounds so we can switch to second order flux close to the boundary
134 IF (jts .LT. jds + 1) THEN
142 IF (jte .GT. jde - 2) THEN
149 IF (config_flags%polar) THEN
150 IF (jte .GT. jde - 1) THEN
156 ! compute fluxes, 5th or 6th order
160 j_loop_y_flux_6:DO j=j_start,j_end+1
161 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
165 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
166 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
167 fqyd(i, k, jp1) = veld*(37.*(u(i, k, j)+u(i, k, j-1))-8.*(u(&
168 & i, k, j+1)+u(i, k, j-2))+(u(i, k, j+2)+u(i, k, j-3)))/60.0&
169 & + vel*(37.*(ud(i, k, j)+ud(i, k, j-1))-8.*(ud(i, k, j+1)+&
170 & ud(i, k, j-2))+ud(i, k, j+2)+ud(i, k, j-3))/60.0
171 fqy(i, k, jp1) = vel*((37.*(u(i, k, j)+u(i, k, j-1))-8.*(u(i&
172 & , k, j+1)+u(i, k, j-2))+(u(i, k, j+2)+u(i, k, j-3)))/60.0)
175 ELSE IF (j .EQ. jds + 1) THEN
176 ! we must be close to some boundary where we need to reduce the order of the stencil
177 ! 2nd order flux next to south boundary
180 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
181 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
183 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
187 ELSE IF (j .EQ. jds + 2) THEN
188 ! third of 4th order flux 2 in from south boundary
191 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
192 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
193 fqyd(i, k, jp1) = veld*(7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
194 & , j+1)+u(i, k, j-2)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k&
195 & , j-1))-ud(i, k, j+1)-ud(i, k, j-2))/12.0
196 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
197 & , j+1)+u(i, k, j-2)))/12.0)
200 ELSE IF (j .EQ. jde - 1) THEN
201 ! 2nd order flux next to north boundary
204 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
205 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
207 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
211 ELSE IF (j .EQ. jde - 2) THEN
212 ! 3rd order flux 2 in from north boundary
215 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
216 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
217 fqyd(i, k, jp1) = veld*(7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
218 & , j+1)+u(i, k, j-2)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k&
219 & , j-1))-ud(i, k, j+1)-ud(i, k, j-2))/12.0
220 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
221 & , j+1)+u(i, k, j-2)))/12.0)
225 ! y flux-divergence into tendency
226 ! (j > j_start) will miss the u(,,jds) tendency
227 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
230 ! ADT eqn 44, 2nd term on RHS
231 mrdy = msfux(i, j-1)*rdy
232 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
234 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
238 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
239 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
242 ! ADT eqn 44, 2nd term on RHS
243 mrdy = msfux(i, j-1)*rdy
244 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
246 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
250 ELSE IF (j .GT. j_start) THEN
254 ! ADT eqn 44, 2nd term on RHS
255 mrdy = msfux(i, j-1)*rdy
256 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
257 & k, jp1)-fqyd(i, k, jp0))
258 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
259 & jp1)-fqy(i, k, jp0))
266 END DO j_loop_y_flux_6
267 ! next, x - flux divergence
271 IF (jte .GT. jde - 1) THEN
276 ! higher order flux has a 5 or 7 point stencil, so compute
277 ! bounds so we can switch to second order flux close to the boundary
281 IF (ids + 1 .LT. its) THEN
289 IF (ide - 1 .GT. ite) THEN
301 ! 5th or 6th order flux
303 DO i=i_start_f,i_end_f
304 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
305 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
306 fqxd(i, k) = veld*(37.*(u(i, k, j)+u(i-1, k, j))-8.*(u(i+1, k&
307 & , j)+u(i-2, k, j))+(u(i+2, k, j)+u(i-3, k, j)))/60.0 + vel*(&
308 & 37.*(ud(i, k, j)+ud(i-1, k, j))-8.*(ud(i+1, k, j)+ud(i-2, k&
309 & , j))+ud(i+2, k, j)+ud(i-3, k, j))/60.0
310 fqx(i, k) = vel*((37.*(u(i, k, j)+u(i-1, k, j))-8.*(u(i+1, k, &
311 & j)+u(i-2, k, j))+(u(i+2, k, j)+u(i-3, k, j)))/60.0)
314 ! lower order fluxes close to boundaries (if not periodic or symmetric)
315 ! specified uses upstream normal wind at boundaries
317 IF (i_start .EQ. ids + 1) THEN
318 ! second order flux next to the boundary
323 IF (specified .AND. u(i, k, j) .LT. 0.) THEN
327 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i, k, j)&
328 & +ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)+ubd))
329 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i, k, j)+ub)
334 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
335 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
336 fqxd(i, k) = veld*(7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+&
337 & u(i-2, k, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i-1, k, j))-ud&
338 & (i+1, k, j)-ud(i-2, k, j))/12.0
339 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
340 & (i-2, k, j)))/12.0)
344 IF (i_end .EQ. ide - 1) THEN
345 ! second order flux next to the boundary
350 IF (specified .AND. u(i-1, k, j) .GT. 0.) THEN
354 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i-1, k, &
355 & j)+ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i-1, k, j)+ubd))
356 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i-1, k, j)+&
362 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
363 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
364 fqxd(i, k) = veld*(7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+&
365 & u(i-2, k, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i-1, k, j))-ud&
366 & (i+1, k, j)-ud(i-2, k, j))/12.0
367 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
368 & (i-2, k, j)))/12.0)
371 ! x flux-divergence into tendency
374 ! ADT eqn 44, 1st term on RHS
375 mrdx = msfux(i, j)*rdx
376 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
378 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
383 ELSE IF (horz_order .EQ. 5) THEN
384 ! 5th order horizontal flux calculation
385 ! This code is EXACTLY the same as the 6th order code
386 ! EXCEPT the 5th order and 3rd operators are used in
387 ! place of the 6th and 4th order operators
388 ! determine boundary mods for flux operators
389 ! We degrade the flux operators from 3rd/4th order
390 ! to second order one gridpoint in from the boundaries for
391 ! all boundary conditions except periodic and symmetry - these
392 ! conditions have boundary zone data fill for correct application
393 ! of the higher order flux stencils
398 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
399 & its .GT. ids + 3) degrade_xs = .false.
400 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
401 & ite .LT. ide - 2) degrade_xe = .false.
402 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
403 & jts .GT. jds + 3) degrade_ys = .false.
404 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
405 & jte .LT. jde - 4) degrade_ye = .false.
406 !--------------- y - advection first
409 IF (config_flags%open_xs .OR. specified) THEN
410 IF (ids + 1 .LT. its) THEN
416 IF (config_flags%open_xe .OR. specified) THEN
417 IF (ide - 1 .GT. ite) THEN
423 IF (config_flags%periodic_x) i_start = its
424 IF (config_flags%periodic_x) i_end = ite
426 IF (jte .GT. jde - 1) THEN
431 ! higher order flux has a 5 or 7 point stencil, so compute
432 ! bounds so we can switch to second order flux close to the boundary
436 IF (jts .LT. jds + 1) THEN
444 IF (jte .GT. jde - 2) THEN
451 IF (config_flags%polar) THEN
452 IF (jte .GT. jde - 1) THEN
458 ! compute fluxes, 5th or 6th order
462 j_loop_y_flux_5:DO j=j_start,j_end+1
463 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
467 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
468 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
469 fqyd(i, k, jp1) = veld*((37.*(u(i, k, j)+u(i, k, j-1))-8.*(u&
470 & (i, k, j+1)+u(i, k, j-2))+(u(i, k, j+2)+u(i, k, j-3)))/&
471 & 60.0-SIGN(1, time_step)*SIGN(1., vel)*(u(i, k, j+2)-u(i, k&
472 & , j-3)-5.*(u(i, k, j+1)-u(i, k, j-2))+10.*(u(i, k, j)-u(i&
473 & , k, j-1)))/60.0) + vel*((37.*(ud(i, k, j)+ud(i, k, j-1))-&
474 & 8.*(ud(i, k, j+1)+ud(i, k, j-2))+ud(i, k, j+2)+ud(i, k, j-&
475 & 3))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(ud(i, k, j+2)-&
476 & ud(i, k, j-3)-5.*(ud(i, k, j+1)-ud(i, k, j-2))+10.*(ud(i, &
477 & k, j)-ud(i, k, j-1)))/60.0)
478 fqy(i, k, jp1) = vel*((37.*(u(i, k, j)+u(i, k, j-1))-8.*(u(i&
479 & , k, j+1)+u(i, k, j-2))+(u(i, k, j+2)+u(i, k, j-3)))/60.0-&
480 & SIGN(1, time_step)*SIGN(1., vel)*(u(i, k, j+2)-u(i, k, j-3&
481 & )-5.*(u(i, k, j+1)-u(i, k, j-2))+10.*(u(i, k, j)-u(i, k, j&
485 ELSE IF (j .EQ. jds + 1) THEN
486 ! we must be close to some boundary where we need to reduce the order of the stencil
487 ! 2nd order flux next to south boundary
490 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
491 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
493 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
497 ELSE IF (j .EQ. jds + 2) THEN
498 ! third of 4th order flux 2 in from south boundary
501 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
502 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
503 fqyd(i, k, jp1) = veld*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, &
504 & k, j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
505 & vel)*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1&
506 & )))/12.0) + vel*((7.*(ud(i, k, j)+ud(i, k, j-1))-ud(i, k, &
507 & j+1)-ud(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
508 & (ud(i, k, j+1)-ud(i, k, j-2)-3.*(ud(i, k, j)-ud(i, k, j-1)&
510 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
511 & , j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
512 & )*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))&
516 ELSE IF (j .EQ. jde - 1) THEN
517 ! 2nd order flux next to north boundary
520 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
521 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
523 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
527 ELSE IF (j .EQ. jde - 2) THEN
528 ! 3rd order flux 2 in from north boundary
531 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
532 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
533 fqyd(i, k, jp1) = veld*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, &
534 & k, j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
535 & vel)*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1&
536 & )))/12.0) + vel*((7.*(ud(i, k, j)+ud(i, k, j-1))-ud(i, k, &
537 & j+1)-ud(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
538 & (ud(i, k, j+1)-ud(i, k, j-2)-3.*(ud(i, k, j)-ud(i, k, j-1)&
540 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
541 & , j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
542 & )*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))&
547 ! y flux-divergence into tendency
548 ! (j > j_start) will miss the u(,,jds) tendency
549 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
552 ! ADT eqn 44, 2nd term on RHS
553 mrdy = msfux(i, j-1)*rdy
554 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
556 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
560 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
561 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
564 ! ADT eqn 44, 2nd term on RHS
565 mrdy = msfux(i, j-1)*rdy
566 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
568 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
572 ELSE IF (j .GT. j_start) THEN
576 ! ADT eqn 44, 2nd term on RHS
577 mrdy = msfux(i, j-1)*rdy
578 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
579 & k, jp1)-fqyd(i, k, jp0))
580 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
581 & jp1)-fqy(i, k, jp0))
588 END DO j_loop_y_flux_5
589 ! next, x - flux divergence
593 IF (jte .GT. jde - 1) THEN
598 ! higher order flux has a 5 or 7 point stencil, so compute
599 ! bounds so we can switch to second order flux close to the boundary
603 IF (ids + 1 .LT. its) THEN
611 IF (ide - 1 .GT. ite) THEN
623 ! 5th or 6th order flux
625 DO i=i_start_f,i_end_f
626 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
627 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
628 fqxd(i, k) = veld*((37.*(u(i, k, j)+u(i-1, k, j))-8.*(u(i+1, k&
629 & , j)+u(i-2, k, j))+(u(i+2, k, j)+u(i-3, k, j)))/60.0-SIGN(1&
630 & , time_step)*SIGN(1., vel)*(u(i+2, k, j)-u(i-3, k, j)-5.*(u(&
631 & i+1, k, j)-u(i-2, k, j))+10.*(u(i, k, j)-u(i-1, k, j)))/60.0&
632 & ) + vel*((37.*(ud(i, k, j)+ud(i-1, k, j))-8.*(ud(i+1, k, j)+&
633 & ud(i-2, k, j))+ud(i+2, k, j)+ud(i-3, k, j))/60.0-SIGN(1, &
634 & time_step)*SIGN(1., vel)*(ud(i+2, k, j)-ud(i-3, k, j)-5.*(ud&
635 & (i+1, k, j)-ud(i-2, k, j))+10.*(ud(i, k, j)-ud(i-1, k, j)))/&
637 fqx(i, k) = vel*((37.*(u(i, k, j)+u(i-1, k, j))-8.*(u(i+1, k, &
638 & j)+u(i-2, k, j))+(u(i+2, k, j)+u(i-3, k, j)))/60.0-SIGN(1, &
639 & time_step)*SIGN(1., vel)*(u(i+2, k, j)-u(i-3, k, j)-5.*(u(i+&
640 & 1, k, j)-u(i-2, k, j))+10.*(u(i, k, j)-u(i-1, k, j)))/60.0)
643 ! lower order fluxes close to boundaries (if not periodic or symmetric)
644 ! specified uses upstream normal wind at boundaries
646 IF (i_start .EQ. ids + 1) THEN
647 ! second order flux next to the boundary
652 IF (specified .AND. u(i, k, j) .LT. 0.) THEN
656 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i, k, j)&
657 & +ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)+ubd))
658 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i, k, j)+ub)
663 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
664 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
665 fqxd(i, k) = veld*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)&
666 & +u(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1&
667 & , k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0) + &
668 & vel*((7.*(ud(i, k, j)+ud(i-1, k, j))-ud(i+1, k, j)-ud(i-2, k&
669 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i+1, k, j)-&
670 & ud(i-2, k, j)-3.*(ud(i, k, j)-ud(i-1, k, j)))/12.0)
671 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
672 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, &
673 & k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0)
677 IF (i_end .EQ. ide - 1) THEN
678 ! second order flux next to the boundary
683 IF (specified .AND. u(i-1, k, j) .GT. 0.) THEN
687 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i-1, k, &
688 & j)+ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i-1, k, j)+ubd))
689 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i-1, k, j)+&
695 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
696 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
697 fqxd(i, k) = veld*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)&
698 & +u(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1&
699 & , k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0) + &
700 & vel*((7.*(ud(i, k, j)+ud(i-1, k, j))-ud(i+1, k, j)-ud(i-2, k&
701 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i+1, k, j)-&
702 & ud(i-2, k, j)-3.*(ud(i, k, j)-ud(i-1, k, j)))/12.0)
703 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
704 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, &
705 & k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0)
708 ! x flux-divergence into tendency
711 ! ADT eqn 44, 1st term on RHS
712 mrdx = msfux(i, j)*rdx
713 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
715 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
720 ELSE IF (horz_order .EQ. 4) THEN
721 ! determine boundary mods for flux operators
722 ! We degrade the flux operators from 3rd/4th order
723 ! to second order one gridpoint in from the boundaries for
724 ! all boundary conditions except periodic and symmetry - these
725 ! conditions have boundary zone data fill for correct application
726 ! of the higher order flux stencils
731 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
732 & its .GT. ids + 2) degrade_xs = .false.
733 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
734 & ite .LT. ide - 1) degrade_xe = .false.
735 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
736 & jts .GT. jds + 2) degrade_ys = .false.
737 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
738 & jte .LT. jde - 3) degrade_ye = .false.
739 !--------------- x - advection first
743 IF (jte .GT. jde - 1) THEN
748 ! 3rd or 4th order flux has a 5 point stencil, so compute
749 ! bounds so we can switch to second order flux close to the boundary
754 i_start_f = i_start + 1
766 DO i=i_start_f,i_end_f
767 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
768 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
769 fqxd(i, k) = veld*(7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+&
770 & u(i-2, k, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i-1, k, j))-ud&
771 & (i+1, k, j)-ud(i-2, k, j))/12.0
772 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
773 & (i-2, k, j)))/12.0)
776 ! second order flux close to boundaries (if not periodic or symmetric)
777 ! specified uses upstream normal wind at boundaries
783 IF (specified .AND. u(i, k, j) .LT. 0.) THEN
787 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i, k, j)+&
788 & ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)+ubd))
789 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i, k, j)+ub)
797 IF (specified .AND. u(i-1, k, j) .GT. 0.) THEN
801 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i-1, k, j)&
802 & +ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i-1, k, j)+ubd))
803 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i-1, k, j)+ub)
806 ! x flux-divergence into tendency
809 ! ADT eqn 44, 1st term on RHS
810 mrdx = msfux(i, j)*rdx
811 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
813 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
821 IF (config_flags%open_xs .OR. specified) THEN
822 IF (ids + 1 .LT. its) THEN
828 IF (config_flags%open_xe .OR. specified) THEN
829 IF (ide - 1 .GT. ite) THEN
835 IF (config_flags%periodic_x) i_start = its
836 IF (config_flags%periodic_x) i_end = ite
838 IF (jte .GT. jde - 1) THEN
843 ! 3rd or 4th order flux has a 5 point stencil, so compute
844 ! bounds so we can switch to second order flux close to the boundary
847 !CJM these may not work with tiling because they define j_start and end in terms of domain dim
850 j_start_f = j_start + 1
856 IF (config_flags%polar) THEN
857 IF (jte .GT. jde - 1) THEN
863 ! j flux loop for v flux of u momentum
868 IF (j .LT. j_start_f .AND. degrade_ys) THEN
871 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j_start)+rvd(i-1, k, &
872 & j_start))*(u(i, k, j_start)+u(i, k, j_start-1))+(rv(i, k, &
873 & j_start)+rv(i-1, k, j_start))*(ud(i, k, j_start)+ud(i, k, &
875 fqy(i, k, jp1) = 0.25*(rv(i, k, j_start)+rv(i-1, k, j_start)&
876 & )*(u(i, k, j_start)+u(i, k, j_start-1))
879 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
882 ! Assumes j>j_end_f is ONLY j_end+1 ...
883 ! fqy(i, k, jp1) = 0.25*(rv(i,k,j_end+1)+rv(i-1,k,j_end+1)) &
884 ! *(u(i,k,j_end+1)+u(i,k,j_end))
885 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
886 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
888 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
893 ! 3rd or 4th order flux
896 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
897 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
898 fqyd(i, k, jp1) = veld*(7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
899 & , j+1)+u(i, k, j-2)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k&
900 & , j-1))-ud(i, k, j+1)-ud(i, k, j-2))/12.0
901 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
902 & , j+1)+u(i, k, j-2)))/12.0)
906 ! y flux-divergence into tendency
907 ! (j > j_start) will miss the u(,,jds) tendency
908 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
911 ! ADT eqn 44, 2nd term on RHS
912 mrdy = msfux(i, j-1)*rdy
913 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
915 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
919 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
920 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
923 ! ADT eqn 44, 2nd term on RHS
924 mrdy = msfux(i, j-1)*rdy
925 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
927 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
931 ELSE IF (j .GT. j_start) THEN
935 ! ADT eqn 44, 2nd term on RHS
936 mrdy = msfux(i, j-1)*rdy
937 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
938 & k, jp1)-fqyd(i, k, jp0))
939 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
940 & jp1)-fqy(i, k, jp0))
948 ELSE IF (horz_order .EQ. 3) THEN
949 ! As with the 5th and 6th order flux chioces, the 3rd and 4th order
950 ! code is EXACTLY the same EXCEPT for the flux operator.
951 ! determine boundary mods for flux operators
952 ! We degrade the flux operators from 3rd/4th order
953 ! to second order one gridpoint in from the boundaries for
954 ! all boundary conditions except periodic and symmetry - these
955 ! conditions have boundary zone data fill for correct application
956 ! of the higher order flux stencils
961 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
962 & its .GT. ids + 2) degrade_xs = .false.
963 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
964 & ite .LT. ide - 1) degrade_xe = .false.
965 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
966 & jts .GT. jds + 2) degrade_ys = .false.
967 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
968 & jte .LT. jde - 3) degrade_ye = .false.
969 !--------------- x - advection first
973 IF (jte .GT. jde - 1) THEN
978 ! 3rd or 4th order flux has a 5 point stencil, so compute
979 ! bounds so we can switch to second order flux close to the boundary
984 i_start_f = i_start + 1
996 DO i=i_start_f,i_end_f
997 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
998 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
999 fqxd(i, k) = veld*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)&
1000 & +u(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1&
1001 & , k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0) + &
1002 & vel*((7.*(ud(i, k, j)+ud(i-1, k, j))-ud(i+1, k, j)-ud(i-2, k&
1003 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i+1, k, j)-&
1004 & ud(i-2, k, j)-3.*(ud(i, k, j)-ud(i-1, k, j)))/12.0)
1005 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
1006 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, &
1007 & k, j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0)
1010 ! second order flux close to boundaries (if not periodic or symmetric)
1011 ! specified uses upstream normal wind at boundaries
1012 IF (degrade_xs) THEN
1017 IF (specified .AND. u(i, k, j) .LT. 0.) THEN
1021 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i, k, j)+&
1022 & ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)+ubd))
1023 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i, k, j)+ub)
1026 IF (degrade_xe) THEN
1031 IF (specified .AND. u(i-1, k, j) .GT. 0.) THEN
1035 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i-1, k, j)&
1036 & +ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i-1, k, j)+ubd))
1037 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i-1, k, j)+ub)
1040 ! x flux-divergence into tendency
1043 ! ADT eqn 44, 1st term on RHS
1044 mrdx = msfux(i, j)*rdx
1045 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
1047 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
1055 IF (config_flags%open_xs .OR. specified) THEN
1056 IF (ids + 1 .LT. its) THEN
1062 IF (config_flags%open_xe .OR. specified) THEN
1063 IF (ide - 1 .GT. ite) THEN
1069 IF (config_flags%periodic_x) i_start = its
1070 IF (config_flags%periodic_x) i_end = ite
1072 IF (jte .GT. jde - 1) THEN
1077 ! 3rd or 4th order flux has a 5 point stencil, so compute
1078 ! bounds so we can switch to second order flux close to the boundary
1081 !CJM these may not work with tiling because they define j_start and end in terms of domain dim
1082 IF (degrade_ys) THEN
1084 j_start_f = j_start + 1
1086 IF (degrade_ye) THEN
1090 IF (config_flags%polar) THEN
1091 IF (jte .GT. jde - 1) THEN
1097 ! j flux loop for v flux of u momentum
1101 DO j=j_start,j_end+1
1102 IF (j .LT. j_start_f .AND. degrade_ys) THEN
1105 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j_start)+rvd(i-1, k, &
1106 & j_start))*(u(i, k, j_start)+u(i, k, j_start-1))+(rv(i, k, &
1107 & j_start)+rv(i-1, k, j_start))*(ud(i, k, j_start)+ud(i, k, &
1109 fqy(i, k, jp1) = 0.25*(rv(i, k, j_start)+rv(i-1, k, j_start)&
1110 & )*(u(i, k, j_start)+u(i, k, j_start-1))
1113 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
1116 ! Assumes j>j_end_f is ONLY j_end+1 ...
1117 ! fqy(i, k, jp1) = 0.25*(rv(i,k,j_end+1)+rv(i-1,k,j_end+1)) &
1118 ! *(u(i,k,j_end+1)+u(i,k,j_end))
1119 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, &
1120 & k, j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, &
1121 & j)+ud(i, k, j-1)))
1122 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j&
1127 ! 3rd or 4th order flux
1130 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
1131 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
1132 fqyd(i, k, jp1) = veld*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, &
1133 & k, j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
1134 & vel)*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1&
1135 & )))/12.0) + vel*((7.*(ud(i, k, j)+ud(i, k, j-1))-ud(i, k, &
1136 & j+1)-ud(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
1137 & (ud(i, k, j+1)-ud(i, k, j-2)-3.*(ud(i, k, j)-ud(i, k, j-1)&
1139 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
1140 & , j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
1141 & )*(u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))&
1146 ! y flux-divergence into tendency
1147 ! (j > j_start) will miss the u(,,jds) tendency
1148 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
1151 ! ADT eqn 44, 2nd term on RHS
1152 mrdy = msfux(i, j-1)*rdy
1153 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
1155 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
1159 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
1160 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
1163 ! ADT eqn 44, 2nd term on RHS
1164 mrdy = msfux(i, j-1)*rdy
1165 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
1167 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
1171 ELSE IF (j .GT. j_start) THEN
1175 ! ADT eqn 44, 2nd term on RHS
1176 mrdy = msfux(i, j-1)*rdy
1177 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
1178 & k, jp1)-fqyd(i, k, jp0))
1179 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
1180 & jp1)-fqy(i, k, jp0))
1188 ELSE IF (horz_order .EQ. 2) THEN
1192 IF (jte .GT. jde - 1) THEN
1197 IF (config_flags%open_xs) THEN
1198 IF (ids + 1 .LT. its) THEN
1204 IF (config_flags%open_xe) THEN
1205 IF (ide - 1 .GT. ite) THEN
1212 IF (ids + 2 .LT. its) THEN
1219 IF (ide - 2 .GT. ite) THEN
1225 IF (config_flags%periodic_x) i_start = its
1226 IF (config_flags%periodic_x) i_end = ite
1230 ! ADT eqn 44, 1st term on RHS
1231 mrdx = msfux(i, j)*rdx
1232 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.25*((rud(i+1&
1233 & , k, j)+rud(i, k, j))*(u(i+1, k, j)+u(i, k, j))+(ru(i+1, k, &
1234 & j)+ru(i, k, j))*(ud(i+1, k, j)+ud(i, k, j))-(rud(i, k, j)+&
1235 & rud(i-1, k, j))*(u(i, k, j)+u(i-1, k, j))-(ru(i, k, j)+ru(i-&
1236 & 1, k, j))*(ud(i, k, j)+ud(i-1, k, j)))
1237 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.25*((ru(i+1, k&
1238 & , j)+ru(i, k, j))*(u(i+1, k, j)+u(i, k, j))-(ru(i, k, j)+ru(&
1239 & i-1, k, j))*(u(i, k, j)+u(i-1, k, j)))
1243 IF (specified .AND. its .LE. ids + 1 .AND. (.NOT.config_flags%&
1248 ! ADT eqn 44, 1st term on RHS
1249 mrdx = msfux(i, j)*rdx
1252 IF (u(i, k, j) .LT. 0.) THEN
1256 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.25*((rud(i+1&
1257 & , k, j)+rud(i, k, j))*(u(i+1, k, j)+u(i, k, j))+(ru(i+1, k, &
1258 & j)+ru(i, k, j))*(ud(i+1, k, j)+ud(i, k, j))-(rud(i, k, j)+&
1259 & rud(i-1, k, j))*(u(i, k, j)+ub)-(ru(i, k, j)+ru(i-1, k, j))*&
1260 & (ud(i, k, j)+ubd))
1261 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.25*((ru(i+1, k&
1262 & , j)+ru(i, k, j))*(u(i+1, k, j)+u(i, k, j))-(ru(i, k, j)+ru(&
1263 & i-1, k, j))*(u(i, k, j)+ub))
1267 IF (specified .AND. ite .GE. ide - 1 .AND. (.NOT.config_flags%&
1272 ! ADT eqn 44, 1st term on RHS
1273 mrdx = msfux(i, j)*rdx
1276 IF (u(i, k, j) .GT. 0.) THEN
1280 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.25*((rud(i+1&
1281 & , k, j)+rud(i, k, j))*(ub+u(i, k, j))+(ru(i+1, k, j)+ru(i, k&
1282 & , j))*(ubd+ud(i, k, j))-(rud(i, k, j)+rud(i-1, k, j))*(u(i, &
1283 & k, j)+u(i-1, k, j))-(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)&
1285 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.25*((ru(i+1, k&
1286 & , j)+ru(i, k, j))*(ub+u(i, k, j))-(ru(i, k, j)+ru(i-1, k, j)&
1287 & )*(u(i, k, j)+u(i-1, k, j)))
1291 IF (config_flags%open_ys .OR. specified) THEN
1292 IF (jds + 1 .LT. jts) THEN
1298 IF (config_flags%open_ye .OR. specified) THEN
1299 IF (jde - 2 .GT. jte) THEN
1308 ! ADT eqn 44, 1st term on RHS
1309 mrdy = msfux(i, j)*rdy
1310 ! Comments for polar boundary condition
1311 ! Flow is only from one side for points next to poles
1312 IF (config_flags%polar .AND. j .EQ. jds) THEN
1313 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.25*((rvd(i&
1314 & , k, j+1)+rvd(i-1, k, j+1))*(u(i, k, j+1)+u(i, k, j))+(rv(&
1315 & i, k, j+1)+rv(i-1, k, j+1))*(ud(i, k, j+1)+ud(i, k, j)))
1316 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.25*(rv(i, k, &
1317 & j+1)+rv(i-1, k, j+1))*(u(i, k, j+1)+u(i, k, j))
1318 ELSE IF (config_flags%polar .AND. j .EQ. jde - 1) THEN
1319 tendencyd(i, k, j) = tendencyd(i, k, j) + mrdy*0.25*((rvd(i&
1320 & , k, j)+rvd(i-1, k, j))*(u(i, k, j)+u(i, k, j-1))+(rv(i, k&
1321 & , j)+rv(i-1, k, j))*(ud(i, k, j)+ud(i, k, j-1)))
1322 tendency(i, k, j) = tendency(i, k, j) + mrdy*0.25*(rv(i, k, &
1323 & j)+rv(i-1, k, j))*(u(i, k, j)+u(i, k, j-1))
1326 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.25*((rvd(i&
1327 & , k, j+1)+rvd(i-1, k, j+1))*(u(i, k, j+1)+u(i, k, j))+(rv(&
1328 & i, k, j+1)+rv(i-1, k, j+1))*(ud(i, k, j+1)+ud(i, k, j))-(&
1329 & rvd(i, k, j)+rvd(i-1, k, j))*(u(i, k, j)+u(i, k, j-1))-(rv&
1330 & (i, k, j)+rv(i-1, k, j))*(ud(i, k, j)+ud(i, k, j-1)))
1331 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.25*((rv(i, k&
1332 & , j+1)+rv(i-1, k, j+1))*(u(i, k, j+1)+u(i, k, j))-(rv(i, k&
1333 & , j)+rv(i-1, k, j))*(u(i, k, j)+u(i, k, j-1)))
1338 ELSE IF (horz_order .NE. 0) THEN
1339 ! Just in case we want to turn horizontal advection off, we can do it
1340 WRITE(wrf_err_message, *) &
1341 & 'module_advect: advect_u_6a: h_order not known ', horz_order
1342 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
1344 ! radiative lateral boundary condition in x for normal velocity (u)
1345 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
1347 IF (jte .GT. jde - 1) THEN
1354 IF (ru(its, k, j) - cb*mut(its, j) .GT. 0.) THEN
1358 ubd = rud(its, k, j) - cb*mutd(its, j)
1359 ub = ru(its, k, j) - cb*mut(its, j)
1361 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(u_old(&
1362 & its+1, k, j)-u_old(its, k, j))+ub*(u_oldd(its+1, k, j)-u_oldd(&
1364 tendency(its, k, j) = tendency(its, k, j) - rdx*ub*(u_old(its+1&
1365 & , k, j)-u_old(its, k, j))
1369 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
1371 IF (jte .GT. jde - 1) THEN
1378 IF (ru(ite, k, j) + cb*mut(ite-1, j) .LT. 0.) THEN
1382 ubd = rud(ite, k, j) + cb*mutd(ite-1, j)
1383 ub = ru(ite, k, j) + cb*mut(ite-1, j)
1385 tendencyd(ite, k, j) = tendencyd(ite, k, j) - rdx*(ubd*(u_old(&
1386 & ite, k, j)-u_old(ite-1, k, j))+ub*(u_oldd(ite, k, j)-u_oldd(&
1388 tendency(ite, k, j) = tendency(ite, k, j) - rdx*ub*(u_old(ite, k&
1389 & , j)-u_old(ite-1, k, j))
1393 ! pick up the rest of the horizontal radiation boundary conditions.
1394 ! (these are the computations that don't require 'cb')
1395 ! first, set to index ranges
1397 IF (ite .GT. ide) THEN
1404 IF (config_flags%open_xs) THEN
1405 IF (ids + 1 .LT. its) THEN
1412 IF (config_flags%open_xe) THEN
1413 IF (ite .GT. ide - 1) THEN
1420 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
1422 ! ADT eqn 44, 2nd term on RHS
1423 mrdy = msfux(i, jts)*rdy
1424 IF (imax .GT. i) THEN
1429 IF (imin .LT. i - 1) THEN
1435 vwd = 0.5*(rvd(ip, k, jts)+rvd(im, k, jts))
1436 vw = 0.5*(rv(ip, k, jts)+rv(im, k, jts))
1437 IF (vw .GT. 0.) THEN
1444 dvmd = rvd(ip, k, jts+1) - rvd(ip, k, jts)
1445 dvm = rv(ip, k, jts+1) - rv(ip, k, jts)
1446 dvpd = rvd(im, k, jts+1) - rvd(im, k, jts)
1447 dvp = rv(im, k, jts+1) - rv(im, k, jts)
1448 tendencyd(i, k, jts) = tendencyd(i, k, jts) - mrdy*(vbd*(u_old(i&
1449 & , k, jts+1)-u_old(i, k, jts))+vb*(u_oldd(i, k, jts+1)-u_oldd(i&
1450 & , k, jts))+0.5*(ud(i, k, jts)*(dvm+dvp)+u(i, k, jts)*(dvmd+&
1452 tendency(i, k, jts) = tendency(i, k, jts) - mrdy*(vb*(u_old(i, k&
1453 & , jts+1)-u_old(i, k, jts))+0.5*u(i, k, jts)*(dvm+dvp))
1457 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
1459 ! ADT eqn 44, 2nd term on RHS
1460 mrdy = msfux(i, jte-1)*rdy
1461 IF (imax .GT. i) THEN
1466 IF (imin .LT. i - 1) THEN
1472 vwd = 0.5*(rvd(ip, k, jte)+rvd(im, k, jte))
1473 vw = 0.5*(rv(ip, k, jte)+rv(im, k, jte))
1474 IF (vw .LT. 0.) THEN
1481 dvmd = rvd(ip, k, jte) - rvd(ip, k, jte-1)
1482 dvm = rv(ip, k, jte) - rv(ip, k, jte-1)
1483 dvpd = rvd(im, k, jte) - rvd(im, k, jte-1)
1484 dvp = rv(im, k, jte) - rv(im, k, jte-1)
1485 tendencyd(i, k, jte-1) = tendencyd(i, k, jte-1) - mrdy*(vbd*(&
1486 & u_old(i, k, jte-1)-u_old(i, k, jte-2))+vb*(u_oldd(i, k, jte-1)&
1487 & -u_oldd(i, k, jte-2))+0.5*(ud(i, k, jte-1)*(dvm+dvp)+u(i, k, &
1488 & jte-1)*(dvmd+dvpd)))
1489 tendency(i, k, jte-1) = tendency(i, k, jte-1) - mrdy*(vb*(u_old(&
1490 & i, k, jte-1)-u_old(i, k, jte-2))+0.5*u(i, k, jte-1)*(dvm+dvp))
1494 !-------------------- vertical advection
1495 ! ADT eqn 44 has 3rd term on RHS = -(1/my) partial d/dz (rho u w)
1496 ! Here we have: - partial d/dz (u*rom) = - partial d/dz (u rho w / my)
1497 ! Since 'my' (map scale factor in y-direction) isn't a function of z,
1498 ! this is what we need, so leave unchanged in advect_u
1502 IF (jte .GT. jde - 1) THEN
1507 ! IF ( config_flags%open_xs ) i_start = MAX(ids+1,its)
1508 ! IF ( config_flags%open_xe ) i_end = MIN(ide-1,ite)
1509 IF (config_flags%open_ys .OR. specified) THEN
1510 IF (ids + 1 .LT. its) THEN
1516 IF (config_flags%open_ye .OR. specified) THEN
1517 IF (ide - 1 .GT. ite) THEN
1523 IF (config_flags%periodic_x) i_start = its
1524 IF (config_flags%periodic_x) i_end = ite
1526 vfluxd(i, kts) = 0.0
1528 vfluxd(i, kte) = 0.0
1531 IF (vert_order .EQ. 6) THEN
1536 veld = 0.5*(romd(i-1, k, j)+romd(i, k, j))
1537 vel = 0.5*(rom(i-1, k, j)+rom(i, k, j))
1538 vfluxd(i, k) = veld*(37.*(u(i, k, j)+u(i, k-1, j))-8.*(u(i, k+&
1539 & 1, j)+u(i, k-2, j))+(u(i, k+2, j)+u(i, k-3, j)))/60.0 + vel*&
1540 & (37.*(ud(i, k, j)+ud(i, k-1, j))-8.*(ud(i, k+1, j)+ud(i, k-2&
1541 & , j))+ud(i, k+2, j)+ud(i, k-3, j))/60.0
1542 vflux(i, k) = vel*((37.*(u(i, k, j)+u(i, k-1, j))-8.*(u(i, k+1&
1543 & , j)+u(i, k-2, j))+(u(i, k+2, j)+u(i, k-3, j)))/60.0)
1548 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1549 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1550 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1551 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1552 & j)+fzp(k)*u(i, k-1, j))
1554 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
1555 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
1556 vfluxd(i, k) = veld*(7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+&
1557 & u(i, k-2, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k-1, j))-ud(i&
1558 & , k+1, j)-ud(i, k-2, j))/12.0
1559 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
1560 & (i, k-2, j)))/12.0)
1562 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
1563 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
1564 vfluxd(i, k) = veld*(7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+&
1565 & u(i, k-2, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k-1, j))-ud(i&
1566 & , k+1, j)-ud(i, k-2, j))/12.0
1567 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
1568 & (i, k-2, j)))/12.0)
1570 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1571 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1572 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1573 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1574 & j)+fzp(k)*u(i, k-1, j))
1578 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
1580 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
1585 ELSE IF (vert_order .EQ. 5) THEN
1590 veld = 0.5*(romd(i-1, k, j)+romd(i, k, j))
1591 vel = 0.5*(rom(i-1, k, j)+rom(i, k, j))
1592 vfluxd(i, k) = veld*((37.*(u(i, k, j)+u(i, k-1, j))-8.*(u(i, k&
1593 & +1, j)+u(i, k-2, j))+(u(i, k+2, j)+u(i, k-3, j)))/60.0-SIGN(&
1594 & 1, time_step)*SIGN(1., -vel)*(u(i, k+2, j)-u(i, k-3, j)-5.*(&
1595 & u(i, k+1, j)-u(i, k-2, j))+10.*(u(i, k, j)-u(i, k-1, j)))/&
1596 & 60.0) + vel*((37.*(ud(i, k, j)+ud(i, k-1, j))-8.*(ud(i, k+1&
1597 & , j)+ud(i, k-2, j))+ud(i, k+2, j)+ud(i, k-3, j))/60.0-SIGN(1&
1598 & , time_step)*SIGN(1., -vel)*(ud(i, k+2, j)-ud(i, k-3, j)-5.*&
1599 & (ud(i, k+1, j)-ud(i, k-2, j))+10.*(ud(i, k, j)-ud(i, k-1, j)&
1601 vflux(i, k) = vel*((37.*(u(i, k, j)+u(i, k-1, j))-8.*(u(i, k+1&
1602 & , j)+u(i, k-2, j))+(u(i, k+2, j)+u(i, k-3, j)))/60.0-SIGN(1&
1603 & , time_step)*SIGN(1., -vel)*(u(i, k+2, j)-u(i, k-3, j)-5.*(u&
1604 & (i, k+1, j)-u(i, k-2, j))+10.*(u(i, k, j)-u(i, k-1, j)))/&
1610 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1611 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1612 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1613 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1614 & j)+fzp(k)*u(i, k-1, j))
1616 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
1617 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
1618 vfluxd(i, k) = veld*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)&
1619 & +u(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k&
1620 & +1, j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0) + vel*&
1621 & ((7.*(ud(i, k, j)+ud(i, k-1, j))-ud(i, k+1, j)-ud(i, k-2, j))/&
1622 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(ud(i, k+1, j)-ud(i, k-&
1623 & 2, j)-3.*(ud(i, k, j)-ud(i, k-1, j)))/12.0)
1624 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
1625 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1&
1626 & , j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0)
1628 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
1629 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
1630 vfluxd(i, k) = veld*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)&
1631 & +u(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k&
1632 & +1, j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0) + vel*&
1633 & ((7.*(ud(i, k, j)+ud(i, k-1, j))-ud(i, k+1, j)-ud(i, k-2, j))/&
1634 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(ud(i, k+1, j)-ud(i, k-&
1635 & 2, j)-3.*(ud(i, k, j)-ud(i, k-1, j)))/12.0)
1636 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
1637 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1&
1638 & , j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0)
1640 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1641 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1642 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1643 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1644 & j)+fzp(k)*u(i, k-1, j))
1648 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
1650 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
1655 ELSE IF (vert_order .EQ. 4) THEN
1660 veld = 0.5*(romd(i-1, k, j)+romd(i, k, j))
1661 vel = 0.5*(rom(i-1, k, j)+rom(i, k, j))
1662 vfluxd(i, k) = veld*(7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j&
1663 & )+u(i, k-2, j)))/12.0 + vel*(7.*(ud(i, k, j)+ud(i, k-1, j))-&
1664 & ud(i, k+1, j)-ud(i, k-2, j))/12.0
1665 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)&
1666 & +u(i, k-2, j)))/12.0)
1671 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1672 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1673 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1674 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1675 & j)+fzp(k)*u(i, k-1, j))
1677 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1678 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1679 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1680 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1681 & j)+fzp(k)*u(i, k-1, j))
1685 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
1687 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
1692 ELSE IF (vert_order .EQ. 3) THEN
1697 veld = 0.5*(romd(i-1, k, j)+romd(i, k, j))
1698 vel = 0.5*(rom(i-1, k, j)+rom(i, k, j))
1699 vfluxd(i, k) = veld*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, &
1700 & j)+u(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(&
1701 & i, k+1, j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0) &
1702 & + vel*((7.*(ud(i, k, j)+ud(i, k-1, j))-ud(i, k+1, j)-ud(i, k&
1703 & -2, j))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(ud(i, k+1, j&
1704 & )-ud(i, k-2, j)-3.*(ud(i, k, j)-ud(i, k-1, j)))/12.0)
1705 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)&
1706 & +u(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i&
1707 & , k+1, j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0)
1712 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1713 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1714 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1715 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1716 & j)+fzp(k)*u(i, k-1, j))
1718 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i&
1719 & , k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(&
1720 & fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1721 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, &
1722 & j)+fzp(k)*u(i, k-1, j))
1726 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
1728 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
1733 ELSE IF (vert_order .EQ. 2) THEN
1738 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(&
1739 & i, k, j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*&
1740 & (fzm(k)*ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
1741 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k&
1742 & , j)+fzp(k)*u(i, k-1, j))
1747 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
1749 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
1755 WRITE(wrf_err_message, *) &
1756 & 'module_advect: advect_u_6a: v_order not known ', vert_order
1757 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
1759 END SUBROUTINE G_ADVECT_U
1761 ! Generated by TAPENADE (INRIA, Tropics team)
1762 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
1764 ! Differentiation of advect_v in forward (tangent) mode:
1765 ! variations of useful results: tendency
1766 ! with respect to varying inputs: rom tendency v v_old ru rv
1768 ! RW status of diff variables: rom:in tendency:in-out v:in v_old:in
1769 ! ru:in rv:in mut:in
1770 SUBROUTINE G_ADVECT_V(v, vd, v_old, v_oldd, tendency, tendencyd, ru, rud&
1771 & , rv, rvd, rom, romd, mut, mutd, time_step, config_flags, msfux, msfuy&
1772 & , msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzw, ids, ide, jds&
1773 & , jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts&
1777 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
1778 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
1779 & jme, kms, kme, its, ite, jts, jte, kts, kte
1780 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: v, v_old, ru&
1782 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: vd, v_oldd, &
1784 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
1785 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd
1786 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
1787 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
1788 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
1789 & msfvy, msftx, msfty
1790 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
1791 REAL, INTENT(IN) :: rdx, rdy
1792 INTEGER, INTENT(IN) :: time_step
1794 INTEGER :: i, j, k, itf, jtf, ktf
1795 INTEGER :: i_start, i_end, j_start, j_end
1796 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
1797 INTEGER :: jmin, jmax, jp, jm, imin, imax
1798 REAL :: mrdx, mrdy, ub, vb, uw, vw, dup, dum
1799 REAL :: ubd, vbd, uwd, dupd, dumd
1800 REAL, DIMENSION(its:ite, kts:kte) :: vflux
1801 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
1802 REAL, DIMENSION(its:ite + 1, kts:kte) :: fqx
1803 REAL, DIMENSION(its:ite+1, kts:kte) :: fqxd
1804 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
1805 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
1806 INTEGER :: horz_order
1807 INTEGER :: vert_order
1808 LOGICAL :: degrade_xs, degrade_ys
1809 LOGICAL :: degrade_xe, degrade_ye
1810 INTEGER :: jp1, jp0, jtmp
1811 ! definition of flux operators, 3rd, 4th, 5th or 6th order
1812 REAL :: flux3, flux4, flux5, flux6
1813 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
1815 LOGICAL :: specified
1820 IF (config_flags%specified .OR. config_flags%nested) specified = &
1822 IF (kte .GT. kde - 1) THEN
1827 horz_order = config_flags%h_mom_adv_order
1828 vert_order = config_flags%v_mom_adv_order
1829 ! here is the choice of flux operators
1830 IF (horz_order .EQ. 6) THEN
1831 ! determine boundary mods for flux operators
1832 ! We degrade the flux operators from 3rd/4th order
1833 ! to second order one gridpoint in from the boundaries for
1834 ! all boundary conditions except periodic and symmetry - these
1835 ! conditions have boundary zone data fill for correct application
1836 ! of the higher order flux stencils
1841 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
1842 & its .GT. ids + 3) degrade_xs = .false.
1843 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
1844 & ite .LT. ide - 3) degrade_xe = .false.
1845 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
1846 & jts .GT. jds + 3) degrade_ys = .false.
1847 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
1848 & jte .LT. jde - 3) degrade_ye = .false.
1849 !--------------- y - advection first
1851 IF (ite .GT. ide - 1) THEN
1858 ! higher order flux has a 5 or 7 point stencil, so compute
1859 ! bounds so we can switch to second order flux close to the boundary
1862 IF (degrade_ys) THEN
1863 IF (jts .LT. jds + 1) THEN
1870 IF (degrade_ye) THEN
1871 IF (jte .GT. jde - 1) THEN
1878 ! compute fluxes, 5th or 6th order
1882 j_loop_y_flux_6:DO j=j_start,j_end+1
1883 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
1886 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
1887 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
1888 fqyd(i, k, jp1) = veld*(37.*(v(i, k, j)+v(i, k, j-1))-8.*(v(&
1889 & i, k, j+1)+v(i, k, j-2))+(v(i, k, j+2)+v(i, k, j-3)))/60.0&
1890 & + vel*(37.*(vd(i, k, j)+vd(i, k, j-1))-8.*(vd(i, k, j+1)+&
1891 & vd(i, k, j-2))+vd(i, k, j+2)+vd(i, k, j-3))/60.0
1892 fqy(i, k, jp1) = vel*((37.*(v(i, k, j)+v(i, k, j-1))-8.*(v(i&
1893 & , k, j+1)+v(i, k, j-2))+(v(i, k, j+2)+v(i, k, j-3)))/60.0)
1896 ELSE IF (j .EQ. jds + 1) THEN
1897 ! we must be close to some boundary where we need to reduce the order of the stencil
1898 ! specified uses upstream normal wind at boundaries
1899 ! 2nd order flux next to south boundary
1904 IF (specified .AND. v(i, k, j) .LT. 0.) THEN
1908 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(v(i, &
1909 & k, j)+vb)+(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)+vbd))
1910 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(v(i, k, j&
1914 ELSE IF (j .EQ. jds + 2) THEN
1915 ! third of 4th order flux 2 in from south boundary
1918 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
1919 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
1920 fqyd(i, k, jp1) = veld*(7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
1921 & , j+1)+v(i, k, j-2)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k&
1922 & , j-1))-vd(i, k, j+1)-vd(i, k, j-2))/12.0
1923 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
1924 & , j+1)+v(i, k, j-2)))/12.0)
1927 ELSE IF (j .EQ. jde) THEN
1928 ! 2nd order flux next to north boundary
1933 IF (specified .AND. v(i, k, j-1) .GT. 0.) THEN
1937 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(vb+v(&
1938 & i, k, j-1))+(rv(i, k, j)+rv(i, k, j-1))*(vbd+vd(i, k, j-1)&
1940 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(vb+v(i, k&
1944 ELSE IF (j .EQ. jde - 1) THEN
1945 ! 3rd or 4th order flux 2 in from north boundary
1948 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
1949 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
1950 fqyd(i, k, jp1) = veld*(7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
1951 & , j+1)+v(i, k, j-2)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k&
1952 & , j-1))-vd(i, k, j+1)-vd(i, k, j-2))/12.0
1953 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
1954 & , j+1)+v(i, k, j-2)))/12.0)
1958 ! y flux-divergence into tendency
1959 ! Comments on polar boundary conditions
1960 ! No advection over the poles means tendencies (held from jds [S. pole]
1961 ! to jde [N pole], i.e., on v grid) must be zero at poles
1962 ! [tendency(jds) and tendency(jde)=0]
1963 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
1966 tendencyd(i, k, j-1) = 0.0
1967 tendency(i, k, j-1) = 0.
1970 ELSE IF (config_flags%polar .AND. j .EQ. jde + 1) THEN
1971 ! If j_end were set to jde in a special if statement apart from
1972 ! degrade_ye, then we would hit the next conditional. But since
1973 ! we want the tendency to be zero anyway, not looping to jde+1
1974 ! will produce the same effect.
1977 tendencyd(i, k, j-1) = 0.0
1978 tendency(i, k, j-1) = 0.
1981 ELSE IF (j .GT. j_start) THEN
1985 ! ADT eqn 45, 2nd term on RHS
1986 mrdy = msfvy(i, j-1)*rdy
1987 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
1988 & k, jp1)-fqyd(i, k, jp0))
1989 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
1990 & jp1)-fqy(i, k, jp0))
1997 END DO j_loop_y_flux_6
1998 ! next, x - flux divergence
2000 IF (ite .GT. ide - 1) THEN
2007 ! Polar boundary conditions are like open or specified
2008 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
2010 IF (jds + 1 .LT. jts) THEN
2016 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
2018 IF (jde - 1 .GT. jte) THEN
2024 ! higher order flux has a 5 or 7 point stencil, so compute
2025 ! bounds so we can switch to second order flux close to the boundary
2028 IF (degrade_xs) THEN
2029 IF (ids + 1 .LT. its) THEN
2034 IF (i_start + 2 .GT. ids + 3) THEN
2037 i_start_f = i_start + 2
2040 IF (degrade_xe) THEN
2041 IF (ide - 2 .GT. ite) THEN
2053 ! 5th or 6th order flux
2055 DO i=i_start_f,i_end_f
2056 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2057 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2058 fqxd(i, k) = veld*(37.*(v(i, k, j)+v(i-1, k, j))-8.*(v(i+1, k&
2059 & , j)+v(i-2, k, j))+(v(i+2, k, j)+v(i-3, k, j)))/60.0 + vel*(&
2060 & 37.*(vd(i, k, j)+vd(i-1, k, j))-8.*(vd(i+1, k, j)+vd(i-2, k&
2061 & , j))+vd(i+2, k, j)+vd(i-3, k, j))/60.0
2062 fqx(i, k) = vel*((37.*(v(i, k, j)+v(i-1, k, j))-8.*(v(i+1, k, &
2063 & j)+v(i-2, k, j))+(v(i+2, k, j)+v(i-3, k, j)))/60.0)
2066 ! lower order fluxes close to boundaries (if not periodic or symmetric)
2067 IF (degrade_xs) THEN
2068 DO i=i_start,i_start_f-1
2069 IF (i .EQ. ids + 1) THEN
2072 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i, k, j-1))*(v(i, k, &
2073 & j)+v(i-1, k, j))+(ru(i, k, j)+ru(i, k, j-1))*(vd(i, k, j&
2075 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i, k, j-1))*(v(i, k, j)+v&
2079 IF (i .EQ. ids + 2) THEN
2082 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2083 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2084 fqxd(i, k) = veld*(7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k&
2085 & , j)+v(i-2, k, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i-1, &
2086 & k, j))-vd(i+1, k, j)-vd(i-2, k, j))/12.0
2087 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
2088 & j)+v(i-2, k, j)))/12.0)
2093 IF (degrade_xe) THEN
2094 DO i=i_end_f+1,i_end+1
2095 IF (i .EQ. ide - 1) THEN
2096 ! second order flux next to the boundary
2098 fqxd(i, k) = 0.25*((rud(i_end+1, k, j)+rud(i_end+1, k, j-1&
2099 & ))*(v(i_end+1, k, j)+v(i_end, k, j))+(ru(i_end+1, k, j)+&
2100 & ru(i_end+1, k, j-1))*(vd(i_end+1, k, j)+vd(i_end, k, j))&
2102 fqx(i, k) = 0.25*(ru(i_end+1, k, j)+ru(i_end+1, k, j-1))*(&
2103 & v(i_end+1, k, j)+v(i_end, k, j))
2106 IF (i .EQ. ide - 2) THEN
2107 ! third order flux one in from the boundary
2109 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2110 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2111 fqxd(i, k) = veld*(7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k&
2112 & , j)+v(i-2, k, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i-1, &
2113 & k, j))-vd(i+1, k, j)-vd(i-2, k, j))/12.0
2114 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
2115 & j)+v(i-2, k, j)))/12.0)
2120 ! x flux-divergence into tendency
2123 ! ADT eqn 45, 1st term on RHS
2124 mrdx = msfvy(i, j)*rdx
2125 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
2127 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
2132 ELSE IF (horz_order .EQ. 5) THEN
2133 ! 5th order horizontal flux calculation
2134 ! This code is EXACTLY the same as the 6th order code
2135 ! EXCEPT the 5th order and 3rd operators are used in
2136 ! place of the 6th and 4th order operators
2137 ! determine boundary mods for flux operators
2138 ! We degrade the flux operators from 3rd/4th order
2139 ! to second order one gridpoint in from the boundaries for
2140 ! all boundary conditions except periodic and symmetry - these
2141 ! conditions have boundary zone data fill for correct application
2142 ! of the higher order flux stencils
2147 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
2148 & its .GT. ids + 3) degrade_xs = .false.
2149 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
2150 & ite .LT. ide - 3) degrade_xe = .false.
2151 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
2152 & jts .GT. jds + 3) degrade_ys = .false.
2153 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
2154 & jte .LT. jde - 3) degrade_ye = .false.
2155 !--------------- y - advection first
2157 IF (ite .GT. ide - 1) THEN
2164 ! higher order flux has a 5 or 7 point stencil, so compute
2165 ! bounds so we can switch to second order flux close to the boundary
2168 IF (degrade_ys) THEN
2169 IF (jts .LT. jds + 1) THEN
2176 IF (degrade_ye) THEN
2177 IF (jte .GT. jde - 1) THEN
2184 ! compute fluxes, 5th or 6th order
2188 j_loop_y_flux_5:DO j=j_start,j_end+1
2189 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
2192 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
2193 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
2194 fqyd(i, k, jp1) = veld*((37.*(v(i, k, j)+v(i, k, j-1))-8.*(v&
2195 & (i, k, j+1)+v(i, k, j-2))+(v(i, k, j+2)+v(i, k, j-3)))/&
2196 & 60.0-SIGN(1, time_step)*SIGN(1., vel)*(v(i, k, j+2)-v(i, k&
2197 & , j-3)-5.*(v(i, k, j+1)-v(i, k, j-2))+10.*(v(i, k, j)-v(i&
2198 & , k, j-1)))/60.0) + vel*((37.*(vd(i, k, j)+vd(i, k, j-1))-&
2199 & 8.*(vd(i, k, j+1)+vd(i, k, j-2))+vd(i, k, j+2)+vd(i, k, j-&
2200 & 3))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(vd(i, k, j+2)-&
2201 & vd(i, k, j-3)-5.*(vd(i, k, j+1)-vd(i, k, j-2))+10.*(vd(i, &
2202 & k, j)-vd(i, k, j-1)))/60.0)
2203 fqy(i, k, jp1) = vel*((37.*(v(i, k, j)+v(i, k, j-1))-8.*(v(i&
2204 & , k, j+1)+v(i, k, j-2))+(v(i, k, j+2)+v(i, k, j-3)))/60.0-&
2205 & SIGN(1, time_step)*SIGN(1., vel)*(v(i, k, j+2)-v(i, k, j-3&
2206 & )-5.*(v(i, k, j+1)-v(i, k, j-2))+10.*(v(i, k, j)-v(i, k, j&
2210 ELSE IF (j .EQ. jds + 1) THEN
2211 ! we must be close to some boundary where we need to reduce the order of the stencil
2212 ! specified uses upstream normal wind at boundaries
2213 ! 2nd order flux next to south boundary
2218 IF (specified .AND. v(i, k, j) .LT. 0.) THEN
2222 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(v(i, &
2223 & k, j)+vb)+(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)+vbd))
2224 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(v(i, k, j&
2228 ELSE IF (j .EQ. jds + 2) THEN
2229 ! third of 4th order flux 2 in from south boundary
2232 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
2233 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
2234 fqyd(i, k, jp1) = veld*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, &
2235 & k, j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
2236 & vel)*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1&
2237 & )))/12.0) + vel*((7.*(vd(i, k, j)+vd(i, k, j-1))-vd(i, k, &
2238 & j+1)-vd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
2239 & (vd(i, k, j+1)-vd(i, k, j-2)-3.*(vd(i, k, j)-vd(i, k, j-1)&
2241 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
2242 & , j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
2243 & )*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))&
2247 ELSE IF (j .EQ. jde) THEN
2248 ! 2nd order flux next to north boundary
2253 IF (specified .AND. v(i, k, j-1) .GT. 0.) THEN
2257 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(vb+v(&
2258 & i, k, j-1))+(rv(i, k, j)+rv(i, k, j-1))*(vbd+vd(i, k, j-1)&
2260 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(vb+v(i, k&
2264 ELSE IF (j .EQ. jde - 1) THEN
2265 ! 3rd or 4th order flux 2 in from north boundary
2268 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
2269 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
2270 fqyd(i, k, jp1) = veld*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, &
2271 & k, j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
2272 & vel)*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1&
2273 & )))/12.0) + vel*((7.*(vd(i, k, j)+vd(i, k, j-1))-vd(i, k, &
2274 & j+1)-vd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
2275 & (vd(i, k, j+1)-vd(i, k, j-2)-3.*(vd(i, k, j)-vd(i, k, j-1)&
2277 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
2278 & , j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
2279 & )*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))&
2284 ! y flux-divergence into tendency
2285 ! Comments on polar boundary conditions
2286 ! No advection over the poles means tendencies (held from jds [S. pole]
2287 ! to jde [N pole], i.e., on v grid) must be zero at poles
2288 ! [tendency(jds) and tendency(jde)=0]
2289 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
2292 tendencyd(i, k, j-1) = 0.0
2293 tendency(i, k, j-1) = 0.
2296 ELSE IF (config_flags%polar .AND. j .EQ. jde + 1) THEN
2297 ! If j_end were set to jde in a special if statement apart from
2298 ! degrade_ye, then we would hit the next conditional. But since
2299 ! we want the tendency to be zero anyway, not looping to jde+1
2300 ! will produce the same effect.
2303 tendencyd(i, k, j-1) = 0.0
2304 tendency(i, k, j-1) = 0.
2307 ELSE IF (j .GT. j_start) THEN
2311 ! ADT eqn 45, 2nd term on RHS
2312 mrdy = msfvy(i, j-1)*rdy
2313 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
2314 & k, jp1)-fqyd(i, k, jp0))
2315 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
2316 & jp1)-fqy(i, k, jp0))
2323 END DO j_loop_y_flux_5
2324 ! next, x - flux divergence
2326 IF (ite .GT. ide - 1) THEN
2333 ! Polar boundary conditions are like open or specified
2334 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
2336 IF (jds + 1 .LT. jts) THEN
2342 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
2344 IF (jde - 1 .GT. jte) THEN
2350 ! higher order flux has a 5 or 7 point stencil, so compute
2351 ! bounds so we can switch to second order flux close to the boundary
2354 IF (degrade_xs) THEN
2355 IF (ids + 1 .LT. its) THEN
2360 IF (i_start + 2 .GT. ids + 3) THEN
2363 i_start_f = i_start + 2
2366 IF (degrade_xe) THEN
2367 IF (ide - 2 .GT. ite) THEN
2379 ! 5th or 6th order flux
2381 DO i=i_start_f,i_end_f
2382 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2383 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2384 fqxd(i, k) = veld*((37.*(v(i, k, j)+v(i-1, k, j))-8.*(v(i+1, k&
2385 & , j)+v(i-2, k, j))+(v(i+2, k, j)+v(i-3, k, j)))/60.0-SIGN(1&
2386 & , time_step)*SIGN(1., vel)*(v(i+2, k, j)-v(i-3, k, j)-5.*(v(&
2387 & i+1, k, j)-v(i-2, k, j))+10.*(v(i, k, j)-v(i-1, k, j)))/60.0&
2388 & ) + vel*((37.*(vd(i, k, j)+vd(i-1, k, j))-8.*(vd(i+1, k, j)+&
2389 & vd(i-2, k, j))+vd(i+2, k, j)+vd(i-3, k, j))/60.0-SIGN(1, &
2390 & time_step)*SIGN(1., vel)*(vd(i+2, k, j)-vd(i-3, k, j)-5.*(vd&
2391 & (i+1, k, j)-vd(i-2, k, j))+10.*(vd(i, k, j)-vd(i-1, k, j)))/&
2393 fqx(i, k) = vel*((37.*(v(i, k, j)+v(i-1, k, j))-8.*(v(i+1, k, &
2394 & j)+v(i-2, k, j))+(v(i+2, k, j)+v(i-3, k, j)))/60.0-SIGN(1, &
2395 & time_step)*SIGN(1., vel)*(v(i+2, k, j)-v(i-3, k, j)-5.*(v(i+&
2396 & 1, k, j)-v(i-2, k, j))+10.*(v(i, k, j)-v(i-1, k, j)))/60.0)
2399 ! lower order fluxes close to boundaries (if not periodic or symmetric)
2400 IF (degrade_xs) THEN
2401 DO i=i_start,i_start_f-1
2402 IF (i .EQ. ids + 1) THEN
2405 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i, k, j-1))*(v(i, k, &
2406 & j)+v(i-1, k, j))+(ru(i, k, j)+ru(i, k, j-1))*(vd(i, k, j&
2408 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i, k, j-1))*(v(i, k, j)+v&
2412 IF (i .EQ. ids + 2) THEN
2415 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2416 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2417 fqxd(i, k) = veld*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k&
2418 & , j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
2419 & )*(v(i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)&
2420 & ))/12.0) + vel*((7.*(vd(i, k, j)+vd(i-1, k, j))-vd(i+1, &
2421 & k, j)-vd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
2422 & vel)*(vd(i+1, k, j)-vd(i-2, k, j)-3.*(vd(i, k, j)-vd(i-1&
2424 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
2425 & j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
2426 & (v(i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))&
2432 IF (degrade_xe) THEN
2433 DO i=i_end_f+1,i_end+1
2434 IF (i .EQ. ide - 1) THEN
2435 ! second order flux next to the boundary
2437 fqxd(i, k) = 0.25*((rud(i_end+1, k, j)+rud(i_end+1, k, j-1&
2438 & ))*(v(i_end+1, k, j)+v(i_end, k, j))+(ru(i_end+1, k, j)+&
2439 & ru(i_end+1, k, j-1))*(vd(i_end+1, k, j)+vd(i_end, k, j))&
2441 fqx(i, k) = 0.25*(ru(i_end+1, k, j)+ru(i_end+1, k, j-1))*(&
2442 & v(i_end+1, k, j)+v(i_end, k, j))
2445 IF (i .EQ. ide - 2) THEN
2446 ! third order flux one in from the boundary
2448 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2449 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2450 fqxd(i, k) = veld*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k&
2451 & , j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
2452 & )*(v(i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)&
2453 & ))/12.0) + vel*((7.*(vd(i, k, j)+vd(i-1, k, j))-vd(i+1, &
2454 & k, j)-vd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
2455 & vel)*(vd(i+1, k, j)-vd(i-2, k, j)-3.*(vd(i, k, j)-vd(i-1&
2457 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
2458 & j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
2459 & (v(i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))&
2465 ! x flux-divergence into tendency
2468 ! ADT eqn 45, 1st term on RHS
2469 mrdx = msfvy(i, j)*rdx
2470 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
2472 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
2477 ELSE IF (horz_order .EQ. 4) THEN
2478 ! determine boundary mods for flux operators
2479 ! We degrade the flux operators from 3rd/4th order
2480 ! to second order one gridpoint in from the boundaries for
2481 ! all boundary conditions except periodic and symmetry - these
2482 ! conditions have boundary zone data fill for correct application
2483 ! of the higher order flux stencils
2488 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
2489 & its .GT. ids + 2) degrade_xs = .false.
2490 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
2491 & ite .LT. ide - 2) degrade_xe = .false.
2492 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
2493 & jts .GT. jds + 2) degrade_ys = .false.
2494 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
2495 & jte .LT. jde - 2) degrade_ye = .false.
2496 IF (kte .GT. kde - 1) THEN
2502 IF (ite .GT. ide - 1) THEN
2509 ! 3rd or 4th order flux has a 5 point stencil, so compute
2510 ! bounds so we can switch to second order flux close to the boundary
2513 !CJM May not work with tiling because defined in terms of domain dims
2514 IF (degrade_ys) THEN
2516 j_start_f = j_start + 1
2518 IF (degrade_ye) THEN
2523 ! specified uses upstream normal wind at boundaries
2527 DO j=j_start,j_end+1
2528 IF (j .EQ. j_start .AND. degrade_ys) THEN
2533 IF (specified .AND. v(i, k, j) .LT. 0.) THEN
2537 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(v(i, &
2538 & k, j)+vb)+(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)+vbd))
2539 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(v(i, k, j&
2543 ELSE IF (j .EQ. j_end + 1 .AND. degrade_ye) THEN
2548 IF (specified .AND. v(i, k, j-1) .GT. 0.) THEN
2552 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(vb+v(&
2553 & i, k, j-1))+(rv(i, k, j)+rv(i, k, j-1))*(vbd+vd(i, k, j-1)&
2555 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(vb+v(i, k&
2562 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
2563 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
2564 fqyd(i, k, jp1) = veld*(7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
2565 & , j+1)+v(i, k, j-2)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k&
2566 & , j-1))-vd(i, k, j+1)-vd(i, k, j-2))/12.0
2567 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
2568 & , j+1)+v(i, k, j-2)))/12.0)
2572 ! Comments on polar boundary conditions
2573 ! No advection over the poles means tendencies (held from jds [S. pole]
2574 ! to jde [N pole], i.e., on v grid) must be zero at poles
2575 ! [tendency(jds) and tendency(jde)=0]
2576 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
2579 tendencyd(i, k, j-1) = 0.0
2580 tendency(i, k, j-1) = 0.
2583 ELSE IF (config_flags%polar .AND. j .EQ. jde + 1) THEN
2584 ! If j_end were set to jde in a special if statement apart from
2585 ! degrade_ye, then we would hit the next conditional. But since
2586 ! we want the tendency to be zero anyway, not looping to jde+1
2587 ! will produce the same effect.
2590 tendencyd(i, k, j-1) = 0.0
2591 tendency(i, k, j-1) = 0.
2594 ELSE IF (j .GT. j_start) THEN
2598 ! ADT eqn 45, 2nd term on RHS
2599 mrdy = msfvy(i, j-1)*rdy
2600 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
2601 & k, jp1)-fqyd(i, k, jp0))
2602 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
2603 & jp1)-fqy(i, k, jp0))
2611 ! next, x - flux divergence
2613 IF (ite .GT. ide - 1) THEN
2620 ! Polar boundary conditions are like open or specified
2621 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
2623 IF (jds + 1 .LT. jts) THEN
2629 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
2631 IF (jde - 1 .GT. jte) THEN
2637 ! 3rd or 4th order flux has a 5 point stencil, so compute
2638 ! bounds so we can switch to second order flux close to the boundary
2641 IF (degrade_xs) THEN
2643 i_start_f = i_start + 1
2645 IF (degrade_xe) THEN
2654 ! 3rd or 4th order flux
2656 DO i=i_start_f,i_end_f
2657 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2658 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2659 fqxd(i, k) = veld*(7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)+&
2660 & v(i-2, k, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i-1, k, j))-vd&
2661 & (i+1, k, j)-vd(i-2, k, j))/12.0
2662 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)+v&
2663 & (i-2, k, j)))/12.0)
2666 ! second order flux close to boundaries (if not periodic or symmetric)
2667 IF (degrade_xs) THEN
2669 fqxd(i_start, k) = 0.25*((rud(i_start, k, j)+rud(i_start, k, j&
2670 & -1))*(v(i_start, k, j)+v(i_start-1, k, j))+(ru(i_start, k, j&
2671 & )+ru(i_start, k, j-1))*(vd(i_start, k, j)+vd(i_start-1, k, j&
2673 fqx(i_start, k) = 0.25*(ru(i_start, k, j)+ru(i_start, k, j-1))&
2674 & *(v(i_start, k, j)+v(i_start-1, k, j))
2677 IF (degrade_xe) THEN
2679 fqxd(i_end+1, k) = 0.25*((rud(i_end+1, k, j)+rud(i_end+1, k, j&
2680 & -1))*(v(i_end+1, k, j)+v(i_end, k, j))+(ru(i_end+1, k, j)+ru&
2681 & (i_end+1, k, j-1))*(vd(i_end+1, k, j)+vd(i_end, k, j)))
2682 fqx(i_end+1, k) = 0.25*(ru(i_end+1, k, j)+ru(i_end+1, k, j-1))&
2683 & *(v(i_end+1, k, j)+v(i_end, k, j))
2686 ! x flux-divergence into tendency
2689 ! ADT eqn 45, 1st term on RHS
2690 mrdx = msfvy(i, j)*rdx
2691 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
2693 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
2698 ELSE IF (horz_order .EQ. 3) THEN
2699 ! determine boundary mods for flux operators
2700 ! We degrade the flux operators from 3rd/4th order
2701 ! to second order one gridpoint in from the boundaries for
2702 ! all boundary conditions except periodic and symmetry - these
2703 ! conditions have boundary zone data fill for correct application
2704 ! of the higher order flux stencils
2709 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
2710 & its .GT. ids + 2) degrade_xs = .false.
2711 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
2712 & ite .LT. ide - 2) degrade_xe = .false.
2713 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
2714 & jts .GT. jds + 2) degrade_ys = .false.
2715 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
2716 & jte .LT. jde - 2) degrade_ye = .false.
2717 IF (kte .GT. kde - 1) THEN
2723 IF (ite .GT. ide - 1) THEN
2730 ! 3rd or 4th order flux has a 5 point stencil, so compute
2731 ! bounds so we can switch to second order flux close to the boundary
2734 !CJM May not work with tiling because defined in terms of domain dims
2735 IF (degrade_ys) THEN
2737 j_start_f = j_start + 1
2739 IF (degrade_ye) THEN
2744 ! specified uses upstream normal wind at boundaries
2748 DO j=j_start,j_end+1
2749 IF (j .EQ. j_start .AND. degrade_ys) THEN
2754 IF (specified .AND. v(i, k, j) .LT. 0.) THEN
2758 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(v(i, &
2759 & k, j)+vb)+(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)+vbd))
2760 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(v(i, k, j&
2764 ELSE IF (j .EQ. j_end + 1 .AND. degrade_ye) THEN
2769 IF (specified .AND. v(i, k, j-1) .GT. 0.) THEN
2773 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(vb+v(&
2774 & i, k, j-1))+(rv(i, k, j)+rv(i, k, j-1))*(vbd+vd(i, k, j-1)&
2776 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(vb+v(i, k&
2783 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
2784 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
2785 fqyd(i, k, jp1) = veld*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, &
2786 & k, j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
2787 & vel)*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1&
2788 & )))/12.0) + vel*((7.*(vd(i, k, j)+vd(i, k, j-1))-vd(i, k, &
2789 & j+1)-vd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
2790 & (vd(i, k, j+1)-vd(i, k, j-2)-3.*(vd(i, k, j)-vd(i, k, j-1)&
2792 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
2793 & , j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
2794 & )*(v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))&
2799 ! Comments on polar boundary conditions
2800 ! No advection over the poles means tendencies (held from jds [S. pole]
2801 ! to jde [N pole], i.e., on v grid) must be zero at poles
2802 ! [tendency(jds) and tendency(jde)=0]
2803 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
2806 tendencyd(i, k, j-1) = 0.0
2807 tendency(i, k, j-1) = 0.
2810 ELSE IF (config_flags%polar .AND. j .EQ. jde + 1) THEN
2811 ! If j_end were set to jde in a special if statement apart from
2812 ! degrade_ye, then we would hit the next conditional. But since
2813 ! we want the tendency to be zero anyway, not looping to jde+1
2814 ! will produce the same effect.
2817 tendencyd(i, k, j-1) = 0.0
2818 tendency(i, k, j-1) = 0.
2821 ELSE IF (j .GT. j_start) THEN
2825 ! ADT eqn 45, 2nd term on RHS
2826 mrdy = msfvy(i, j-1)*rdy
2827 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
2828 & k, jp1)-fqyd(i, k, jp0))
2829 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
2830 & jp1)-fqy(i, k, jp0))
2838 ! next, x - flux divergence
2840 IF (ite .GT. ide - 1) THEN
2847 ! Polar boundary conditions are like open or specified
2848 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
2850 IF (jds + 1 .LT. jts) THEN
2856 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
2858 IF (jde - 1 .GT. jte) THEN
2864 ! 3rd or 4th order flux has a 5 point stencil, so compute
2865 ! bounds so we can switch to second order flux close to the boundary
2868 IF (degrade_xs) THEN
2870 i_start_f = i_start + 1
2872 IF (degrade_xe) THEN
2881 ! 3rd or 4th order flux
2883 DO i=i_start_f,i_end_f
2884 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
2885 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
2886 fqxd(i, k) = veld*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)&
2887 & +v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(i+1&
2888 & , k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/12.0) + &
2889 & vel*((7.*(vd(i, k, j)+vd(i-1, k, j))-vd(i+1, k, j)-vd(i-2, k&
2890 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(vd(i+1, k, j)-&
2891 & vd(i-2, k, j)-3.*(vd(i, k, j)-vd(i-1, k, j)))/12.0)
2892 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)+v&
2893 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(i+1, &
2894 & k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/12.0)
2897 ! second order flux close to boundaries (if not periodic or symmetric)
2898 IF (degrade_xs) THEN
2900 fqxd(i_start, k) = 0.25*((rud(i_start, k, j)+rud(i_start, k, j&
2901 & -1))*(v(i_start, k, j)+v(i_start-1, k, j))+(ru(i_start, k, j&
2902 & )+ru(i_start, k, j-1))*(vd(i_start, k, j)+vd(i_start-1, k, j&
2904 fqx(i_start, k) = 0.25*(ru(i_start, k, j)+ru(i_start, k, j-1))&
2905 & *(v(i_start, k, j)+v(i_start-1, k, j))
2908 IF (degrade_xe) THEN
2910 fqxd(i_end+1, k) = 0.25*((rud(i_end+1, k, j)+rud(i_end+1, k, j&
2911 & -1))*(v(i_end+1, k, j)+v(i_end, k, j))+(ru(i_end+1, k, j)+ru&
2912 & (i_end+1, k, j-1))*(vd(i_end+1, k, j)+vd(i_end, k, j)))
2913 fqx(i_end+1, k) = 0.25*(ru(i_end+1, k, j)+ru(i_end+1, k, j-1))&
2914 & *(v(i_end+1, k, j)+v(i_end, k, j))
2917 ! x flux-divergence into tendency
2920 ! ADT eqn 45, 1st term on RHS
2921 mrdx = msfvy(i, j)*rdx
2922 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
2924 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
2929 ELSE IF (horz_order .EQ. 2) THEN
2931 IF (ite .GT. ide - 1) THEN
2938 IF (config_flags%open_ys) THEN
2939 IF (jds + 1 .LT. jts) THEN
2945 IF (config_flags%open_ye) THEN
2946 IF (jde - 1 .GT. jte) THEN
2953 IF (jds + 2 .LT. jts) THEN
2960 IF (jde - 2 .GT. jte) THEN
2966 IF (config_flags%polar) THEN
2967 IF (jds + 1 .LT. jts) THEN
2973 IF (config_flags%polar) THEN
2974 IF (jde - 1 .GT. jte) THEN
2983 ! ADT eqn 45, 2nd term on RHS
2984 mrdy = msfvy(i, j)*rdy
2985 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.25*((rvd(i, k&
2986 & , j+1)+rvd(i, k, j))*(v(i, k, j+1)+v(i, k, j))+(rv(i, k, j+1&
2987 & )+rv(i, k, j))*(vd(i, k, j+1)+vd(i, k, j))-(rvd(i, k, j)+rvd&
2988 & (i, k, j-1))*(v(i, k, j)+v(i, k, j-1))-(rv(i, k, j)+rv(i, k&
2989 & , j-1))*(vd(i, k, j)+vd(i, k, j-1)))
2990 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.25*((rv(i, k, j&
2991 & +1)+rv(i, k, j))*(v(i, k, j+1)+v(i, k, j))-(rv(i, k, j)+rv(i&
2992 & , k, j-1))*(v(i, k, j)+v(i, k, j-1)))
2996 ! Comments on polar boundary conditions
2997 ! tendencies = 0 at poles, and polar points do not contribute at points
2999 IF (config_flags%polar) THEN
3000 IF (jts .EQ. jds) THEN
3003 tendencyd(i, k, jds) = 0.0
3004 tendency(i, k, jds) = 0.
3008 IF (jte .EQ. jde) THEN
3011 tendencyd(i, k, jde) = 0.0
3012 tendency(i, k, jde) = 0.
3017 ! specified uses upstream normal wind at boundaries
3018 IF (specified .AND. jts .LE. jds + 1) THEN
3022 ! ADT eqn 45, 2nd term on RHS
3023 mrdy = msfvy(i, j)*rdy
3026 IF (v(i, k, j) .LT. 0.) THEN
3030 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.25*((rvd(i, k&
3031 & , j+1)+rvd(i, k, j))*(v(i, k, j+1)+v(i, k, j))+(rv(i, k, j+1&
3032 & )+rv(i, k, j))*(vd(i, k, j+1)+vd(i, k, j))-(rvd(i, k, j)+rvd&
3033 & (i, k, j-1))*(v(i, k, j)+vb)-(rv(i, k, j)+rv(i, k, j-1))*(vd&
3035 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.25*((rv(i, k, j&
3036 & +1)+rv(i, k, j))*(v(i, k, j+1)+v(i, k, j))-(rv(i, k, j)+rv(i&
3037 & , k, j-1))*(v(i, k, j)+vb))
3041 IF (specified .AND. jte .GE. jde - 1) THEN
3045 ! ADT eqn 45, 2nd term on RHS
3046 mrdy = msfvy(i, j)*rdy
3049 IF (v(i, k, j) .GT. 0.) THEN
3053 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.25*((rvd(i, k&
3054 & , j+1)+rvd(i, k, j))*(vb+v(i, k, j))+(rv(i, k, j+1)+rv(i, k&
3055 & , j))*(vbd+vd(i, k, j))-(rvd(i, k, j)+rvd(i, k, j-1))*(v(i, &
3056 & k, j)+v(i, k, j-1))-(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)&
3058 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.25*((rv(i, k, j&
3059 & +1)+rv(i, k, j))*(vb+v(i, k, j))-(rv(i, k, j)+rv(i, k, j-1))&
3060 & *(v(i, k, j)+v(i, k, j-1)))
3064 IF (.NOT.config_flags%periodic_x) THEN
3065 IF (config_flags%open_xs .OR. specified) THEN
3066 IF (ids + 1 .LT. its) THEN
3072 IF (config_flags%open_xe .OR. specified) THEN
3073 IF (ide - 2 .GT. ite) THEN
3080 IF (config_flags%polar) THEN
3081 IF (jds + 1 .LT. jts) THEN
3087 IF (config_flags%polar) THEN
3088 IF (jde - 1 .GT. jte) THEN
3097 ! ADT eqn 45, 1st term on RHS
3098 mrdx = msfvy(i, j)*rdx
3099 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.25*((rud(i+1&
3100 & , k, j)+rud(i+1, k, j-1))*(v(i+1, k, j)+v(i, k, j))+(ru(i+1&
3101 & , k, j)+ru(i+1, k, j-1))*(vd(i+1, k, j)+vd(i, k, j))-(rud(i&
3102 & , k, j)+rud(i, k, j-1))*(v(i, k, j)+v(i-1, k, j))-(ru(i, k, &
3103 & j)+ru(i, k, j-1))*(vd(i, k, j)+vd(i-1, k, j)))
3104 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.25*((ru(i+1, k&
3105 & , j)+ru(i+1, k, j-1))*(v(i+1, k, j)+v(i, k, j))-(ru(i, k, j)&
3106 & +ru(i, k, j-1))*(v(i, k, j)+v(i-1, k, j)))
3110 ELSE IF (horz_order .NE. 0) THEN
3111 ! Just in case we want to turn horizontal advection off, we can do it
3112 WRITE(wrf_err_message, *) &
3113 & 'module_advect: advect_v_6a: h_order not known ', horz_order
3114 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
3116 ! Comments on polar boundary condition
3117 ! Force tendency=0 at NP and SP
3118 ! We keep setting this everywhere, but it can't hurt...
3119 IF (config_flags%polar .AND. jts .EQ. jds) THEN
3122 tendencyd(i, k, jts) = 0.0
3123 tendency(i, k, jts) = 0.
3127 IF (config_flags%polar .AND. jte .EQ. jde) THEN
3130 tendencyd(i, k, jte) = 0.0
3131 tendency(i, k, jte) = 0.
3135 ! radiative lateral boundary condition in y for normal velocity (v)
3136 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
3138 IF (ite .GT. ide - 1) THEN
3145 IF (rv(i, k, jts) - cb*mut(i, jts) .GT. 0.) THEN
3149 vbd = rvd(i, k, jts) - cb*mutd(i, jts)
3150 vb = rv(i, k, jts) - cb*mut(i, jts)
3152 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(v_old(i&
3153 & , k, jts+1)-v_old(i, k, jts))+vb*(v_oldd(i, k, jts+1)-v_oldd(i&
3155 tendency(i, k, jts) = tendency(i, k, jts) - rdy*vb*(v_old(i, k, &
3156 & jts+1)-v_old(i, k, jts))
3160 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
3162 IF (ite .GT. ide - 1) THEN
3169 IF (rv(i, k, jte) + cb*mut(i, jte-1) .LT. 0.) THEN
3173 vbd = rvd(i, k, jte) + cb*mutd(i, jte-1)
3174 vb = rv(i, k, jte) + cb*mut(i, jte-1)
3176 tendencyd(i, k, jte) = tendencyd(i, k, jte) - rdy*(vbd*(v_old(i&
3177 & , k, jte)-v_old(i, k, jte-1))+vb*(v_oldd(i, k, jte)-v_oldd(i, &
3179 tendency(i, k, jte) = tendency(i, k, jte) - rdy*vb*(v_old(i, k, &
3180 & jte)-v_old(i, k, jte-1))
3184 ! pick up the rest of the horizontal radiation boundary conditions.
3185 ! (these are the computations that don't require 'cb'.
3186 ! first, set to index ranges
3188 IF (jte .GT. jde) THEN
3195 IF (config_flags%open_ys) THEN
3196 IF (jds + 1 .LT. jts) THEN
3203 IF (config_flags%open_ye) THEN
3204 IF (jte .GT. jde - 1) THEN
3211 ! compute x (u) conditions for v, w, or scalar
3212 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
3214 ! ADT eqn 45, 1st term on RHS
3215 mrdx = msfvy(its, j)*rdx
3216 IF (jmax .GT. j) THEN
3221 IF (jmin .LT. j - 1) THEN
3227 uwd = 0.5*(rud(its, k, jp)+rud(its, k, jm))
3228 uw = 0.5*(ru(its, k, jp)+ru(its, k, jm))
3229 IF (uw .GT. 0.) THEN
3236 dupd = rud(its+1, k, jp) - rud(its, k, jp)
3237 dup = ru(its+1, k, jp) - ru(its, k, jp)
3238 dumd = rud(its+1, k, jm) - rud(its, k, jm)
3239 dum = ru(its+1, k, jm) - ru(its, k, jm)
3240 tendencyd(its, k, j) = tendencyd(its, k, j) - mrdx*(ubd*(v_old(&
3241 & its+1, k, j)-v_old(its, k, j))+ub*(v_oldd(its+1, k, j)-v_oldd(&
3242 & its, k, j))+0.5*(vd(its, k, j)*(dup+dum)+v(its, k, j)*(dupd+&
3244 tendency(its, k, j) = tendency(its, k, j) - mrdx*(ub*(v_old(its+&
3245 & 1, k, j)-v_old(its, k, j))+0.5*v(its, k, j)*(dup+dum))
3249 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
3251 ! ADT eqn 45, 1st term on RHS
3252 mrdx = msfvy(ite-1, j)*rdx
3253 IF (jmax .GT. j) THEN
3258 IF (jmin .LT. j - 1) THEN
3264 uwd = 0.5*(rud(ite, k, jp)+rud(ite, k, jm))
3265 uw = 0.5*(ru(ite, k, jp)+ru(ite, k, jm))
3266 IF (uw .LT. 0.) THEN
3273 dupd = rud(ite, k, jp) - rud(ite-1, k, jp)
3274 dup = ru(ite, k, jp) - ru(ite-1, k, jp)
3275 dumd = rud(ite, k, jm) - rud(ite-1, k, jm)
3276 dum = ru(ite, k, jm) - ru(ite-1, k, jm)
3277 ! tendency(ite-1,k,j)=tendency(ite-1,k,j)-mrdx*( &
3278 ! ub*(v_old(ite-1,k,j)-v_old(ite-2,k,j)) &
3279 ! +0.5*v(ite-1,k,j)* &
3280 ! ( ru(ite,k,jp)-ru(ite-1,k,jp) &
3281 ! +ru(ite,k,jm)-ru(ite-1,k,jm)) )
3282 tendencyd(ite-1, k, j) = tendencyd(ite-1, k, j) - mrdx*(ubd*(&
3283 & v_old(ite-1, k, j)-v_old(ite-2, k, j))+ub*(v_oldd(ite-1, k, j)&
3284 & -v_oldd(ite-2, k, j))+0.5*(vd(ite-1, k, j)*(dup+dum)+v(ite-1, &
3285 & k, j)*(dupd+dumd)))
3286 tendency(ite-1, k, j) = tendency(ite-1, k, j) - mrdx*(ub*(v_old(&
3287 & ite-1, k, j)-v_old(ite-2, k, j))+0.5*v(ite-1, k, j)*(dup+dum))
3291 !-------------------- vertical advection
3292 ! ADT eqn 45 has 3rd term on RHS = -(1/mx) partial d/dz (rho v w)
3293 ! Here we have: - partial d/dz (v*rom) = - partial d/dz (v rho w / my)
3294 ! We therefore need to make a correction for advect_v
3295 ! since 'my' (map scale factor in y direction) isn't a function of z,
3296 ! we can do this using *(my/mx) (see eqn. 45 for example)
3298 IF (ite .GT. ide - 1) THEN
3306 vfluxd(i, kts) = 0.0
3308 vfluxd(i, kte) = 0.0
3311 ! Polar boundary conditions are like open or specified
3312 ! We don't want to calculate vertical v tendencies at the N or S pole
3313 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
3315 IF (jds + 1 .LT. jts) THEN
3321 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
3323 IF (jde - 1 .GT. jte) THEN
3329 IF (vert_order .EQ. 6) THEN
3334 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3335 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3336 vfluxd(i, k) = veld*(37.*(v(i, k, j)+v(i, k-1, j))-8.*(v(i, k+&
3337 & 1, j)+v(i, k-2, j))+(v(i, k+2, j)+v(i, k-3, j)))/60.0 + vel*&
3338 & (37.*(vd(i, k, j)+vd(i, k-1, j))-8.*(vd(i, k+1, j)+vd(i, k-2&
3339 & , j))+vd(i, k+2, j)+vd(i, k-3, j))/60.0
3340 vflux(i, k) = vel*((37.*(v(i, k, j)+v(i, k-1, j))-8.*(v(i, k+1&
3341 & , j)+v(i, k-2, j))+(v(i, k+2, j)+v(i, k-3, j)))/60.0)
3346 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3347 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3348 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3349 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3350 & j)+fzp(k)*v(i, k-1, j))
3352 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3353 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3354 vfluxd(i, k) = veld*(7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+&
3355 & v(i, k-2, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k-1, j))-vd(i&
3356 & , k+1, j)-vd(i, k-2, j))/12.0
3357 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
3358 & (i, k-2, j)))/12.0)
3360 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3361 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3362 vfluxd(i, k) = veld*(7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+&
3363 & v(i, k-2, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k-1, j))-vd(i&
3364 & , k+1, j)-vd(i, k-2, j))/12.0
3365 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
3366 & (i, k-2, j)))/12.0)
3368 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3369 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3370 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3371 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3372 & j)+fzp(k)*v(i, k-1, j))
3376 ! We are calculating vertical fluxes on v points,
3377 ! so we must mean msf_v_x/y variables
3378 ! ADT eqn 45, 3rd term on RHS
3379 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*&
3380 & (vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
3381 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j&
3382 & )*rdzw(k)*(vflux(i, k+1)-vflux(i, k))
3386 ELSE IF (vert_order .EQ. 5) THEN
3391 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3392 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3393 vfluxd(i, k) = veld*((37.*(v(i, k, j)+v(i, k-1, j))-8.*(v(i, k&
3394 & +1, j)+v(i, k-2, j))+(v(i, k+2, j)+v(i, k-3, j)))/60.0-SIGN(&
3395 & 1, time_step)*SIGN(1., -vel)*(v(i, k+2, j)-v(i, k-3, j)-5.*(&
3396 & v(i, k+1, j)-v(i, k-2, j))+10.*(v(i, k, j)-v(i, k-1, j)))/&
3397 & 60.0) + vel*((37.*(vd(i, k, j)+vd(i, k-1, j))-8.*(vd(i, k+1&
3398 & , j)+vd(i, k-2, j))+vd(i, k+2, j)+vd(i, k-3, j))/60.0-SIGN(1&
3399 & , time_step)*SIGN(1., -vel)*(vd(i, k+2, j)-vd(i, k-3, j)-5.*&
3400 & (vd(i, k+1, j)-vd(i, k-2, j))+10.*(vd(i, k, j)-vd(i, k-1, j)&
3402 vflux(i, k) = vel*((37.*(v(i, k, j)+v(i, k-1, j))-8.*(v(i, k+1&
3403 & , j)+v(i, k-2, j))+(v(i, k+2, j)+v(i, k-3, j)))/60.0-SIGN(1&
3404 & , time_step)*SIGN(1., -vel)*(v(i, k+2, j)-v(i, k-3, j)-5.*(v&
3405 & (i, k+1, j)-v(i, k-2, j))+10.*(v(i, k, j)-v(i, k-1, j)))/&
3411 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3412 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3413 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3414 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3415 & j)+fzp(k)*v(i, k-1, j))
3417 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3418 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3419 vfluxd(i, k) = veld*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)&
3420 & +v(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k&
3421 & +1, j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0) + vel*&
3422 & ((7.*(vd(i, k, j)+vd(i, k-1, j))-vd(i, k+1, j)-vd(i, k-2, j))/&
3423 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(vd(i, k+1, j)-vd(i, k-&
3424 & 2, j)-3.*(vd(i, k, j)-vd(i, k-1, j)))/12.0)
3425 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
3426 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1&
3427 & , j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0)
3429 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3430 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3431 vfluxd(i, k) = veld*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)&
3432 & +v(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k&
3433 & +1, j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0) + vel*&
3434 & ((7.*(vd(i, k, j)+vd(i, k-1, j))-vd(i, k+1, j)-vd(i, k-2, j))/&
3435 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(vd(i, k+1, j)-vd(i, k-&
3436 & 2, j)-3.*(vd(i, k, j)-vd(i, k-1, j)))/12.0)
3437 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
3438 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1&
3439 & , j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0)
3441 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3442 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3443 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3444 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3445 & j)+fzp(k)*v(i, k-1, j))
3449 ! We are calculating vertical fluxes on v points,
3450 ! so we must mean msf_v_x/y variables
3451 ! ADT eqn 45, 3rd term on RHS
3452 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*&
3453 & (vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
3454 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j&
3455 & )*rdzw(k)*(vflux(i, k+1)-vflux(i, k))
3459 ELSE IF (vert_order .EQ. 4) THEN
3464 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3465 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3466 vfluxd(i, k) = veld*(7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j&
3467 & )+v(i, k-2, j)))/12.0 + vel*(7.*(vd(i, k, j)+vd(i, k-1, j))-&
3468 & vd(i, k+1, j)-vd(i, k-2, j))/12.0
3469 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)&
3470 & +v(i, k-2, j)))/12.0)
3475 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3476 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3477 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3478 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3479 & j)+fzp(k)*v(i, k-1, j))
3481 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3482 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3483 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3484 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3485 & j)+fzp(k)*v(i, k-1, j))
3489 ! We are calculating vertical fluxes on v points,
3490 ! so we must mean msf_v_x/y variables
3491 ! ADT eqn 45, 3rd term on RHS
3492 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*&
3493 & (vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
3494 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j&
3495 & )*rdzw(k)*(vflux(i, k+1)-vflux(i, k))
3499 ELSE IF (vert_order .EQ. 3) THEN
3504 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
3505 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
3506 vfluxd(i, k) = veld*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, &
3507 & j)+v(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(&
3508 & i, k+1, j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0) &
3509 & + vel*((7.*(vd(i, k, j)+vd(i, k-1, j))-vd(i, k+1, j)-vd(i, k&
3510 & -2, j))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(vd(i, k+1, j&
3511 & )-vd(i, k-2, j)-3.*(vd(i, k, j)-vd(i, k-1, j)))/12.0)
3512 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)&
3513 & +v(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i&
3514 & , k+1, j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0)
3519 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3520 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3521 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3522 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3523 & j)+fzp(k)*v(i, k-1, j))
3525 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i&
3526 & , k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(&
3527 & fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3528 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, &
3529 & j)+fzp(k)*v(i, k-1, j))
3533 ! We are calculating vertical fluxes on v points,
3534 ! so we must mean msf_v_x/y variables
3535 ! ADT eqn 45, 3rd term on RHS
3536 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*&
3537 & (vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
3538 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j&
3539 & )*rdzw(k)*(vflux(i, k+1)-vflux(i, k))
3543 ELSE IF (vert_order .EQ. 2) THEN
3548 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(&
3549 & i, k, j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*&
3550 & (fzm(k)*vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
3551 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k&
3552 & , j)+fzp(k)*v(i, k-1, j))
3557 ! We are calculating vertical fluxes on v points,
3558 ! so we must mean msf_v_x/y variables
3559 ! ADT eqn 45, 3rd term on RHS
3560 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*&
3561 & (vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
3562 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j&
3563 & )*rdzw(k)*(vflux(i, k+1)-vflux(i, k))
3568 WRITE(wrf_err_message, *) &
3569 & 'module_advect: advect_v_6a: v_order not known ', vert_order
3570 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
3572 END SUBROUTINE G_ADVECT_V
3574 ! Generated by TAPENADE (INRIA, Tropics team)
3575 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
3577 ! Differentiation of advect_scalar in forward (tangent) mode:
3578 ! variations of useful results: tendency
3579 ! with respect to varying inputs: rom field tendency ru rv field_old
3580 ! RW status of diff variables: rom:in field:in tendency:in-out
3581 ! ru:in rv:in field_old:in
3582 SUBROUTINE G_ADVECT_SCALAR(field, fieldd, field_old, field_oldd, &
3583 & tendency, tendencyd, ru, rud, rv, rvd, rom, romd, mut, time_step, &
3584 & config_flags, msfux, msfuy, msfvx, msfvy, msftx, msfty, fzm, fzp, rdx&
3585 & , rdy, rdzw, ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, &
3586 & kme, its, ite, jts, jte, kts, kte)
3589 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
3590 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
3591 & jme, kms, kme, its, ite, jts, jte, kts, kte
3592 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: field, &
3593 & field_old, ru, rv, rom
3594 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: fieldd, &
3595 & field_oldd, rud, rvd, romd
3596 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
3597 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
3598 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
3599 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
3600 & msfvy, msftx, msfty
3601 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
3602 REAL, INTENT(IN) :: rdx, rdy
3603 INTEGER, INTENT(IN) :: time_step
3605 INTEGER :: i, j, k, itf, jtf, ktf
3606 INTEGER :: i_start, i_end, j_start, j_end
3607 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
3608 INTEGER :: jmin, jmax, jp, jm, imin, imax
3609 REAL :: mrdx, mrdy, ub, vb, uw, vw
3611 REAL, DIMENSION(its:ite, kts:kte) :: vflux
3612 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
3613 REAL, DIMENSION(its:ite + 1, kts:kte) :: fqx
3614 REAL, DIMENSION(its:ite+1, kts:kte) :: fqxd
3615 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
3616 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
3617 INTEGER :: horz_order, vert_order
3618 LOGICAL :: degrade_xs, degrade_ys
3619 LOGICAL :: degrade_xe, degrade_ye
3620 INTEGER :: jp1, jp0, jtmp
3621 ! definition of flux operators, 3rd, 4th, 5th or 6th order
3622 REAL :: flux3, flux4, flux5, flux6
3623 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
3625 LOGICAL :: specified
3628 IF (config_flags%specified .OR. config_flags%nested) specified = &
3630 IF (kte .GT. kde - 1) THEN
3635 horz_order = config_flags%h_sca_adv_order
3636 vert_order = config_flags%v_sca_adv_order
3637 ! begin with horizontal flux divergence
3638 ! here is the choice of flux operators
3639 IF (horz_order .EQ. 6) THEN
3640 ! determine boundary mods for flux operators
3641 ! We degrade the flux operators from 3rd/4th order
3642 ! to second order one gridpoint in from the boundaries for
3643 ! all boundary conditions except periodic and symmetry - these
3644 ! conditions have boundary zone data fill for correct application
3645 ! of the higher order flux stencils
3650 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
3651 & its .GT. ids + 3) degrade_xs = .false.
3652 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
3653 & ite .LT. ide - 3) degrade_xe = .false.
3654 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
3655 & jts .GT. jds + 3) degrade_ys = .false.
3656 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
3657 & jte .LT. jde - 4) degrade_ye = .false.
3658 IF (kte .GT. kde - 1) THEN
3664 IF (ite .GT. ide - 1) THEN
3670 IF (jte .GT. jde - 1) THEN
3675 ! higher order flux has a 5 or 7 point stencil, so compute
3676 ! bounds so we can switch to second order flux close to the boundary
3679 IF (degrade_ys) THEN
3680 IF (jts .LT. jds + 1) THEN
3687 IF (degrade_ye) THEN
3688 IF (jte .GT. jde - 2) THEN
3695 IF (config_flags%polar) THEN
3696 IF (jte .GT. jde - 1) THEN
3702 ! compute fluxes, 5th or 6th order
3706 j_loop_y_flux_6:DO j=j_start,j_end+1
3707 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
3713 fqyd(i, k, jp1) = veld*(37.*(field(i, k, j)+field(i, k, j-1)&
3714 & )-8.*(field(i, k, j+1)+field(i, k, j-2))+(field(i, k, j+2)&
3715 & +field(i, k, j-3)))/60.0 + vel*(37.*(fieldd(i, k, j)+&
3716 & fieldd(i, k, j-1))-8.*(fieldd(i, k, j+1)+fieldd(i, k, j-2)&
3717 & )+fieldd(i, k, j+2)+fieldd(i, k, j-3))/60.0
3718 fqy(i, k, jp1) = vel*((37.*(field(i, k, j)+field(i, k, j-1))&
3719 & -8.*(field(i, k, j+1)+field(i, k, j-2))+(field(i, k, j+2)+&
3720 & field(i, k, j-3)))/60.0)
3723 ELSE IF (j .EQ. jds + 1) THEN
3724 ! 2nd order flux next to south boundary
3727 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
3728 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
3730 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
3734 ELSE IF (j .EQ. jds + 2) THEN
3735 ! 4th order flux 2 in from south boundary
3740 fqyd(i, k, jp1) = veld*(7.*(field(i, k, j)+field(i, k, j-1))&
3741 & -(field(i, k, j+1)+field(i, k, j-2)))/12.0 + vel*(7.*(&
3742 & fieldd(i, k, j)+fieldd(i, k, j-1))-fieldd(i, k, j+1)-&
3743 & fieldd(i, k, j-2))/12.0
3744 fqy(i, k, jp1) = vel*((7.*(field(i, k, j)+field(i, k, j-1))-&
3745 & (field(i, k, j+1)+field(i, k, j-2)))/12.0)
3748 ELSE IF (j .EQ. jde - 1) THEN
3749 ! 2nd order flux next to north boundary
3752 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
3753 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
3755 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
3759 ELSE IF (j .EQ. jde - 2) THEN
3760 ! 3rd or 4th order flux 2 in from north boundary
3765 fqyd(i, k, jp1) = veld*(7.*(field(i, k, j)+field(i, k, j-1))&
3766 & -(field(i, k, j+1)+field(i, k, j-2)))/12.0 + vel*(7.*(&
3767 & fieldd(i, k, j)+fieldd(i, k, j-1))-fieldd(i, k, j+1)-&
3768 & fieldd(i, k, j-2))/12.0
3769 fqy(i, k, jp1) = vel*((7.*(field(i, k, j)+field(i, k, j-1))-&
3770 & (field(i, k, j+1)+field(i, k, j-2)))/12.0)
3774 ! y flux-divergence into tendency
3775 ! Comments on polar boundary conditions
3776 ! Same process as for advect_u - tendencies run from jds to jde-1
3777 ! (latitudes are as for u grid, longitudes are displaced)
3778 ! Therefore: flow is only from one side for points next to poles
3779 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
3782 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
3783 mrdy = msftx(i, j-1)*rdy
3784 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
3786 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
3790 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
3793 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
3794 mrdy = msftx(i, j-1)*rdy
3795 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
3797 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
3801 ELSE IF (j .GT. j_start) THEN
3805 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
3806 mrdy = msftx(i, j-1)*rdy
3807 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
3808 & k, jp1)-fqyd(i, k, jp0))
3809 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
3810 & jp1)-fqy(i, k, jp0))
3817 END DO j_loop_y_flux_6
3818 ! next, x - flux divergence
3820 IF (ite .GT. ide - 1) THEN
3826 IF (jte .GT. jde - 1) THEN
3831 ! higher order flux has a 5 or 7 point stencil, so compute
3832 ! bounds so we can switch to second order flux close to the boundary
3835 IF (degrade_xs) THEN
3836 IF (ids + 1 .LT. its) THEN
3841 IF (i_start + 2 .GT. ids + 3) THEN
3844 i_start_f = i_start + 2
3847 IF (degrade_xe) THEN
3848 IF (ide - 2 .GT. ite) THEN
3860 ! 5th or 6th order flux
3862 DO i=i_start_f,i_end_f
3865 fqxd(i, k) = veld*(37.*(field(i, k, j)+field(i-1, k, j))-8.*(&
3866 & field(i+1, k, j)+field(i-2, k, j))+(field(i+2, k, j)+field(i&
3867 & -3, k, j)))/60.0 + vel*(37.*(fieldd(i, k, j)+fieldd(i-1, k, &
3868 & j))-8.*(fieldd(i+1, k, j)+fieldd(i-2, k, j))+fieldd(i+2, k, &
3869 & j)+fieldd(i-3, k, j))/60.0
3870 fqx(i, k) = vel*((37.*(field(i, k, j)+field(i-1, k, j))-8.*(&
3871 & field(i+1, k, j)+field(i-2, k, j))+(field(i+2, k, j)+field(i&
3875 ! lower order fluxes close to boundaries (if not periodic or symmetric)
3876 IF (degrade_xs) THEN
3877 DO i=i_start,i_start_f-1
3878 IF (i .EQ. ids + 1) THEN
3881 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
3882 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
3883 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
3887 IF (i .EQ. ids + 2) THEN
3892 fqxd(i, k) = veld*(7.*(field(i, k, j)+field(i-1, k, j))-(&
3893 & field(i+1, k, j)+field(i-2, k, j)))/12.0 + vel*(7.*(&
3894 & fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k, j)-&
3895 & fieldd(i-2, k, j))/12.0
3896 fqx(i, k) = vel*((7.*(field(i, k, j)+field(i-1, k, j))-(&
3897 & field(i+1, k, j)+field(i-2, k, j)))/12.0)
3902 IF (degrade_xe) THEN
3903 DO i=i_end_f+1,i_end+1
3904 IF (i .EQ. ide - 1) THEN
3905 ! second order flux next to the boundary
3907 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
3908 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
3909 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
3913 IF (i .EQ. ide - 2) THEN
3914 ! third order flux one in from the boundary
3918 fqxd(i, k) = veld*(7.*(field(i, k, j)+field(i-1, k, j))-(&
3919 & field(i+1, k, j)+field(i-2, k, j)))/12.0 + vel*(7.*(&
3920 & fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k, j)-&
3921 & fieldd(i-2, k, j))/12.0
3922 fqx(i, k) = vel*((7.*(field(i, k, j)+field(i-1, k, j))-(&
3923 & field(i+1, k, j)+field(i-2, k, j)))/12.0)
3928 ! x flux-divergence into tendency
3931 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
3932 mrdx = msftx(i, j)*rdx
3933 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
3935 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
3940 ELSE IF (horz_order .EQ. 5) THEN
3941 ! determine boundary mods for flux operators
3942 ! We degrade the flux operators from 3rd/4th order
3943 ! to second order one gridpoint in from the boundaries for
3944 ! all boundary conditions except periodic and symmetry - these
3945 ! conditions have boundary zone data fill for correct application
3946 ! of the higher order flux stencils
3951 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
3952 & its .GT. ids + 3) degrade_xs = .false.
3953 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
3954 & ite .LT. ide - 3) degrade_xe = .false.
3955 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
3956 & jts .GT. jds + 3) degrade_ys = .false.
3957 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
3958 & jte .LT. jde - 4) degrade_ye = .false.
3959 IF (kte .GT. kde - 1) THEN
3965 IF (ite .GT. ide - 1) THEN
3971 IF (jte .GT. jde - 1) THEN
3976 ! higher order flux has a 5 or 7 point stencil, so compute
3977 ! bounds so we can switch to second order flux close to the boundary
3980 IF (degrade_ys) THEN
3981 IF (jts .LT. jds + 1) THEN
3988 IF (degrade_ye) THEN
3989 IF (jte .GT. jde - 2) THEN
3996 IF (config_flags%polar) THEN
3997 IF (jte .GT. jde - 1) THEN
4003 ! compute fluxes, 5th or 6th order
4007 j_loop_y_flux_5:DO j=j_start,j_end+1
4008 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
4014 fqyd(i, k, jp1) = veld*((37.*(field(i, k, j)+field(i, k, j-1&
4015 & ))-8.*(field(i, k, j+1)+field(i, k, j-2))+(field(i, k, j+2&
4016 & )+field(i, k, j-3)))/60.0-SIGN(1, time_step)*SIGN(1., vel)&
4017 & *(field(i, k, j+2)-field(i, k, j-3)-5.*(field(i, k, j+1)-&
4018 & field(i, k, j-2))+10.*(field(i, k, j)-field(i, k, j-1)))/&
4019 & 60.0) + vel*((37.*(fieldd(i, k, j)+fieldd(i, k, j-1))-8.*(&
4020 & fieldd(i, k, j+1)+fieldd(i, k, j-2))+fieldd(i, k, j+2)+&
4021 & fieldd(i, k, j-3))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(&
4022 & fieldd(i, k, j+2)-fieldd(i, k, j-3)-5.*(fieldd(i, k, j+1)-&
4023 & fieldd(i, k, j-2))+10.*(fieldd(i, k, j)-fieldd(i, k, j-1))&
4025 fqy(i, k, jp1) = vel*((37.*(field(i, k, j)+field(i, k, j-1))&
4026 & -8.*(field(i, k, j+1)+field(i, k, j-2))+(field(i, k, j+2)+&
4027 & field(i, k, j-3)))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(&
4028 & field(i, k, j+2)-field(i, k, j-3)-5.*(field(i, k, j+1)-&
4029 & field(i, k, j-2))+10.*(field(i, k, j)-field(i, k, j-1)))/&
4033 ELSE IF (j .EQ. jds + 1) THEN
4034 ! 2nd order flux next to south boundary
4037 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
4038 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
4040 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
4044 ELSE IF (j .EQ. jds + 2) THEN
4045 ! third of 4th order flux 2 in from south boundary
4050 fqyd(i, k, jp1) = veld*((7.*(field(i, k, j)+field(i, k, j-1)&
4051 & )-(field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(1, &
4052 & time_step)*SIGN(1., vel)*(field(i, k, j+1)-field(i, k, j-2&
4053 & )-3.*(field(i, k, j)-field(i, k, j-1)))/12.0) + vel*((7.*(&
4054 & fieldd(i, k, j)+fieldd(i, k, j-1))-fieldd(i, k, j+1)-&
4055 & fieldd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(&
4056 & fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)-&
4057 & fieldd(i, k, j-1)))/12.0)
4058 fqy(i, k, jp1) = vel*((7.*(field(i, k, j)+field(i, k, j-1))-&
4059 & (field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(1, &
4060 & time_step)*SIGN(1., vel)*(field(i, k, j+1)-field(i, k, j-2&
4061 & )-3.*(field(i, k, j)-field(i, k, j-1)))/12.0)
4064 ELSE IF (j .EQ. jde - 1) THEN
4065 ! 2nd order flux next to north boundary
4068 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
4069 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
4071 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
4075 ELSE IF (j .EQ. jde - 2) THEN
4076 ! 3rd or 4th order flux 2 in from north boundary
4081 fqyd(i, k, jp1) = veld*((7.*(field(i, k, j)+field(i, k, j-1)&
4082 & )-(field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(1, &
4083 & time_step)*SIGN(1., vel)*(field(i, k, j+1)-field(i, k, j-2&
4084 & )-3.*(field(i, k, j)-field(i, k, j-1)))/12.0) + vel*((7.*(&
4085 & fieldd(i, k, j)+fieldd(i, k, j-1))-fieldd(i, k, j+1)-&
4086 & fieldd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(&
4087 & fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)-&
4088 & fieldd(i, k, j-1)))/12.0)
4089 fqy(i, k, jp1) = vel*((7.*(field(i, k, j)+field(i, k, j-1))-&
4090 & (field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(1, &
4091 & time_step)*SIGN(1., vel)*(field(i, k, j+1)-field(i, k, j-2&
4092 & )-3.*(field(i, k, j)-field(i, k, j-1)))/12.0)
4096 ! y flux-divergence into tendency
4097 ! Comments on polar boundary conditions
4098 ! Same process as for advect_u - tendencies run from jds to jde-1
4099 ! (latitudes are as for u grid, longitudes are displaced)
4100 ! Therefore: flow is only from one side for points next to poles
4101 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
4104 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4105 mrdy = msftx(i, j-1)*rdy
4106 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
4108 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
4112 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
4115 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4116 mrdy = msftx(i, j-1)*rdy
4117 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
4119 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
4123 ELSE IF (j .GT. j_start) THEN
4127 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4128 mrdy = msftx(i, j-1)*rdy
4129 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
4130 & k, jp1)-fqyd(i, k, jp0))
4131 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
4132 & jp1)-fqy(i, k, jp0))
4139 END DO j_loop_y_flux_5
4140 ! next, x - flux divergence
4142 IF (ite .GT. ide - 1) THEN
4148 IF (jte .GT. jde - 1) THEN
4153 ! higher order flux has a 5 or 7 point stencil, so compute
4154 ! bounds so we can switch to second order flux close to the boundary
4157 IF (degrade_xs) THEN
4158 IF (ids + 1 .LT. its) THEN
4163 IF (i_start + 2 .GT. ids + 3) THEN
4166 i_start_f = i_start + 2
4169 IF (degrade_xe) THEN
4170 IF (ide - 2 .GT. ite) THEN
4182 ! 5th or 6th order flux
4184 DO i=i_start_f,i_end_f
4187 fqxd(i, k) = veld*((37.*(field(i, k, j)+field(i-1, k, j))-8.*(&
4188 & field(i+1, k, j)+field(i-2, k, j))+(field(i+2, k, j)+field(i&
4189 & -3, k, j)))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(field(i+2&
4190 & , k, j)-field(i-3, k, j)-5.*(field(i+1, k, j)-field(i-2, k, &
4191 & j))+10.*(field(i, k, j)-field(i-1, k, j)))/60.0) + vel*((37.&
4192 & *(fieldd(i, k, j)+fieldd(i-1, k, j))-8.*(fieldd(i+1, k, j)+&
4193 & fieldd(i-2, k, j))+fieldd(i+2, k, j)+fieldd(i-3, k, j))/60.0&
4194 & -SIGN(1, time_step)*SIGN(1., vel)*(fieldd(i+2, k, j)-fieldd(&
4195 & i-3, k, j)-5.*(fieldd(i+1, k, j)-fieldd(i-2, k, j))+10.*(&
4196 & fieldd(i, k, j)-fieldd(i-1, k, j)))/60.0)
4197 fqx(i, k) = vel*((37.*(field(i, k, j)+field(i-1, k, j))-8.*(&
4198 & field(i+1, k, j)+field(i-2, k, j))+(field(i+2, k, j)+field(i&
4199 & -3, k, j)))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(field(i+2&
4200 & , k, j)-field(i-3, k, j)-5.*(field(i+1, k, j)-field(i-2, k, &
4201 & j))+10.*(field(i, k, j)-field(i-1, k, j)))/60.0)
4204 ! lower order fluxes close to boundaries (if not periodic or symmetric)
4205 IF (degrade_xs) THEN
4206 DO i=i_start,i_start_f-1
4207 IF (i .EQ. ids + 1) THEN
4210 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
4211 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
4212 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
4216 IF (i .EQ. ids + 2) THEN
4221 fqxd(i, k) = veld*((7.*(field(i, k, j)+field(i-1, k, j))-(&
4222 & field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, &
4223 & time_step)*SIGN(1., vel)*(field(i+1, k, j)-field(i-2, k&
4224 & , j)-3.*(field(i, k, j)-field(i-1, k, j)))/12.0) + vel*(&
4225 & (7.*(fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k, j&
4226 & )-fieldd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
4227 & vel)*(fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i, &
4228 & k, j)-fieldd(i-1, k, j)))/12.0)
4229 fqx(i, k) = vel*((7.*(field(i, k, j)+field(i-1, k, j))-(&
4230 & field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, &
4231 & time_step)*SIGN(1., vel)*(field(i+1, k, j)-field(i-2, k&
4232 & , j)-3.*(field(i, k, j)-field(i-1, k, j)))/12.0)
4237 IF (degrade_xe) THEN
4238 DO i=i_end_f+1,i_end+1
4239 IF (i .EQ. ide - 1) THEN
4240 ! second order flux next to the boundary
4242 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
4243 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
4244 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
4248 IF (i .EQ. ide - 2) THEN
4249 ! third order flux one in from the boundary
4253 fqxd(i, k) = veld*((7.*(field(i, k, j)+field(i-1, k, j))-(&
4254 & field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, &
4255 & time_step)*SIGN(1., vel)*(field(i+1, k, j)-field(i-2, k&
4256 & , j)-3.*(field(i, k, j)-field(i-1, k, j)))/12.0) + vel*(&
4257 & (7.*(fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k, j&
4258 & )-fieldd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
4259 & vel)*(fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i, &
4260 & k, j)-fieldd(i-1, k, j)))/12.0)
4261 fqx(i, k) = vel*((7.*(field(i, k, j)+field(i-1, k, j))-(&
4262 & field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, &
4263 & time_step)*SIGN(1., vel)*(field(i+1, k, j)-field(i-2, k&
4264 & , j)-3.*(field(i, k, j)-field(i-1, k, j)))/12.0)
4269 ! x flux-divergence into tendency
4272 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
4273 mrdx = msftx(i, j)*rdx
4274 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
4276 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
4281 ELSE IF (horz_order .EQ. 4) THEN
4286 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
4287 & its .GT. ids + 2) degrade_xs = .false.
4288 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
4289 & ite .LT. ide - 2) degrade_xe = .false.
4290 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
4291 & jts .GT. jds + 2) degrade_ys = .false.
4292 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
4293 & jte .LT. jde - 3) degrade_ye = .false.
4294 IF (kte .GT. kde - 1) THEN
4300 IF (ite .GT. ide - 1) THEN
4306 IF (jte .GT. jde - 1) THEN
4311 ! 3rd or 4th order flux has a 5 point stencil, so compute
4312 ! bounds so we can switch to second order flux close to the boundary
4315 IF (degrade_xs) THEN
4317 i_start_f = i_start + 1
4319 IF (degrade_xe) THEN
4328 ! 3rd or 4th order flux
4330 DO i=i_start_f,i_end_f
4331 fqxd(i, k) = rud(i, k, j)*(7.*(field(i, k, j)+field(i-1, k, j)&
4332 & )-(field(i+1, k, j)+field(i-2, k, j)))/12.0 + ru(i, k, j)*(&
4333 & 7.*(fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k, j)-&
4334 & fieldd(i-2, k, j))/12.0
4335 fqx(i, k) = ru(i, k, j)*((7.*(field(i, k, j)+field(i-1, k, j))&
4336 & -(field(i+1, k, j)+field(i-2, k, j)))/12.0)
4339 ! second order flux close to boundaries (if not periodic or symmetric)
4340 IF (degrade_xs) THEN
4342 fqxd(i_start, k) = 0.5*(rud(i_start, k, j)*(field(i_start, k, &
4343 & j)+field(i_start-1, k, j))+ru(i_start, k, j)*(fieldd(i_start&
4344 & , k, j)+fieldd(i_start-1, k, j)))
4345 fqx(i_start, k) = 0.5*ru(i_start, k, j)*(field(i_start, k, j)+&
4346 & field(i_start-1, k, j))
4349 IF (degrade_xe) THEN
4351 fqxd(i_end+1, k) = 0.5*(rud(i_end+1, k, j)*(field(i_end+1, k, &
4352 & j)+field(i_end, k, j))+ru(i_end+1, k, j)*(fieldd(i_end+1, k&
4353 & , j)+fieldd(i_end, k, j)))
4354 fqx(i_end+1, k) = 0.5*ru(i_end+1, k, j)*(field(i_end+1, k, j)+&
4355 & field(i_end, k, j))
4358 ! x flux-divergence into tendency
4361 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
4362 mrdx = msftx(i, j)*rdx
4363 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
4365 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
4370 ! next -> y flux divergence calculation
4372 IF (ite .GT. ide - 1) THEN
4378 IF (jte .GT. jde - 1) THEN
4383 ! 3rd or 4th order flux has a 5 point stencil, so compute
4384 ! bounds so we can switch to second order flux close to the boundary
4387 IF (degrade_ys) THEN
4389 j_start_f = j_start + 1
4391 IF (degrade_ye) THEN
4395 IF (config_flags%polar) THEN
4396 IF (jte .GT. jde - 1) THEN
4405 DO j=j_start,j_end+1
4406 IF (j .LT. j_start_f .AND. degrade_ys) THEN
4409 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j_start)*(field(i, k, &
4410 & j_start)+field(i, k, j_start-1))+rv(i, k, j_start)*(fieldd&
4411 & (i, k, j_start)+fieldd(i, k, j_start-1)))
4412 fqy(i, k, jp1) = 0.5*rv(i, k, j_start)*(field(i, k, j_start)&
4413 & +field(i, k, j_start-1))
4416 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
4419 ! Assumes j>j_end_f is ONLY j_end+1 ...
4420 ! fqy(i,k,jp1) = 0.5*rv(i,k,j_end+1) &
4421 ! *(field(i,k,j_end+1)+field(i,k,j_end))
4422 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
4423 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
4425 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
4430 ! 3rd or 4th order flux
4433 fqyd(i, k, jp1) = rvd(i, k, j)*(7.*(field(i, k, j)+field(i, &
4434 & k, j-1))-(field(i, k, j+1)+field(i, k, j-2)))/12.0 + rv(i&
4435 & , k, j)*(7.*(fieldd(i, k, j)+fieldd(i, k, j-1))-fieldd(i, &
4436 & k, j+1)-fieldd(i, k, j-2))/12.0
4437 fqy(i, k, jp1) = rv(i, k, j)*((7.*(field(i, k, j)+field(i, k&
4438 & , j-1))-(field(i, k, j+1)+field(i, k, j-2)))/12.0)
4442 ! y flux-divergence into tendency
4443 ! Comments on polar boundary conditions
4444 ! Same process as for advect_u - tendencies run from jds to jde-1
4445 ! (latitudes are as for u grid, longitudes are displaced)
4446 ! Therefore: flow is only from one side for points next to poles
4447 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
4450 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4451 mrdy = msftx(i, j-1)*rdy
4452 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
4454 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
4458 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
4461 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4462 mrdy = msftx(i, j-1)*rdy
4463 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
4465 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
4469 ELSE IF (j .GT. j_start) THEN
4473 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4474 mrdy = msftx(i, j-1)*rdy
4475 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
4476 & k, jp1)-fqyd(i, k, jp0))
4477 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
4478 & jp1)-fqy(i, k, jp0))
4486 ELSE IF (horz_order .EQ. 3) THEN
4491 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
4492 & its .GT. ids + 2) degrade_xs = .false.
4493 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
4494 & ite .LT. ide - 2) degrade_xe = .false.
4495 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
4496 & jts .GT. jds + 2) degrade_ys = .false.
4497 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
4498 & jte .LT. jde - 3) degrade_ye = .false.
4499 IF (kte .GT. kde - 1) THEN
4505 IF (ite .GT. ide - 1) THEN
4511 IF (jte .GT. jde - 1) THEN
4516 ! 3rd or 4th order flux has a 5 point stencil, so compute
4517 ! bounds so we can switch to second order flux close to the boundary
4520 IF (degrade_xs) THEN
4522 i_start_f = i_start + 1
4524 IF (degrade_xe) THEN
4533 ! 3rd or 4th order flux
4535 DO i=i_start_f,i_end_f
4536 fqxd(i, k) = rud(i, k, j)*((7.*(field(i, k, j)+field(i-1, k, j&
4537 & ))-(field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, &
4538 & time_step)*SIGN(1., ru(i, k, j))*(field(i+1, k, j)-field(i-2&
4539 & , k, j)-3.*(field(i, k, j)-field(i-1, k, j)))/12.0) + ru(i, &
4540 & k, j)*((7.*(fieldd(i, k, j)+fieldd(i-1, k, j))-fieldd(i+1, k&
4541 & , j)-fieldd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., ru(&
4542 & i, k, j))*(fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i&
4543 & , k, j)-fieldd(i-1, k, j)))/12.0)
4544 fqx(i, k) = ru(i, k, j)*((7.*(field(i, k, j)+field(i-1, k, j))&
4545 & -(field(i+1, k, j)+field(i-2, k, j)))/12.0+SIGN(1, time_step&
4546 & )*SIGN(1., ru(i, k, j))*(field(i+1, k, j)-field(i-2, k, j)-&
4547 & 3.*(field(i, k, j)-field(i-1, k, j)))/12.0)
4550 ! second order flux close to boundaries (if not periodic or symmetric)
4551 IF (degrade_xs) THEN
4553 fqxd(i_start, k) = 0.5*(rud(i_start, k, j)*(field(i_start, k, &
4554 & j)+field(i_start-1, k, j))+ru(i_start, k, j)*(fieldd(i_start&
4555 & , k, j)+fieldd(i_start-1, k, j)))
4556 fqx(i_start, k) = 0.5*ru(i_start, k, j)*(field(i_start, k, j)+&
4557 & field(i_start-1, k, j))
4560 IF (degrade_xe) THEN
4562 fqxd(i_end+1, k) = 0.5*(rud(i_end+1, k, j)*(field(i_end+1, k, &
4563 & j)+field(i_end, k, j))+ru(i_end+1, k, j)*(fieldd(i_end+1, k&
4564 & , j)+fieldd(i_end, k, j)))
4565 fqx(i_end+1, k) = 0.5*ru(i_end+1, k, j)*(field(i_end+1, k, j)+&
4566 & field(i_end, k, j))
4569 ! x flux-divergence into tendency
4572 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
4573 mrdx = msftx(i, j)*rdx
4574 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
4576 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
4581 ! next -> y flux divergence calculation
4583 IF (ite .GT. ide - 1) THEN
4589 IF (jte .GT. jde - 1) THEN
4594 ! 3rd or 4th order flux has a 5 point stencil, so compute
4595 ! bounds so we can switch to second order flux close to the boundary
4598 IF (degrade_ys) THEN
4600 j_start_f = j_start + 1
4602 IF (degrade_ye) THEN
4606 IF (config_flags%polar) THEN
4607 IF (jte .GT. jde - 1) THEN
4616 DO j=j_start,j_end+1
4617 IF (j .LT. j_start_f .AND. degrade_ys) THEN
4620 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j_start)*(field(i, k, &
4621 & j_start)+field(i, k, j_start-1))+rv(i, k, j_start)*(fieldd&
4622 & (i, k, j_start)+fieldd(i, k, j_start-1)))
4623 fqy(i, k, jp1) = 0.5*rv(i, k, j_start)*(field(i, k, j_start)&
4624 & +field(i, k, j_start-1))
4627 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
4630 ! Assumes j>j_end_f is ONLY j_end+1 ...
4631 ! fqy(i,k,jp1) = 0.5*rv(i,k,j_end+1) &
4632 ! *(field(i,k,j_end+1)+field(i,k,j_end))
4633 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
4634 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
4636 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
4641 ! 3rd or 4th order flux
4644 fqyd(i, k, jp1) = rvd(i, k, j)*((7.*(field(i, k, j)+field(i&
4645 & , k, j-1))-(field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(&
4646 & 1, time_step)*SIGN(1., rv(i, k, j))*(field(i, k, j+1)-&
4647 & field(i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))/&
4648 & 12.0) + rv(i, k, j)*((7.*(fieldd(i, k, j)+fieldd(i, k, j-1&
4649 & ))-fieldd(i, k, j+1)-fieldd(i, k, j-2))/12.0+SIGN(1, &
4650 & time_step)*SIGN(1., rv(i, k, j))*(fieldd(i, k, j+1)-fieldd&
4651 & (i, k, j-2)-3.*(fieldd(i, k, j)-fieldd(i, k, j-1)))/12.0)
4652 fqy(i, k, jp1) = rv(i, k, j)*((7.*(field(i, k, j)+field(i, k&
4653 & , j-1))-(field(i, k, j+1)+field(i, k, j-2)))/12.0+SIGN(1, &
4654 & time_step)*SIGN(1., rv(i, k, j))*(field(i, k, j+1)-field(i&
4655 & , k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))/12.0)
4659 ! y flux-divergence into tendency
4660 ! Comments on polar boundary conditions
4661 ! Same process as for advect_u - tendencies run from jds to jde-1
4662 ! (latitudes are as for u grid, longitudes are displaced)
4663 ! Therefore: flow is only from one side for points next to poles
4664 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
4667 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4668 mrdy = msftx(i, j-1)*rdy
4669 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
4671 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
4675 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
4678 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4679 mrdy = msftx(i, j-1)*rdy
4680 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
4682 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
4686 ELSE IF (j .GT. j_start) THEN
4690 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4691 mrdy = msftx(i, j-1)*rdy
4692 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
4693 & k, jp1)-fqyd(i, k, jp0))
4694 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
4695 & jp1)-fqy(i, k, jp0))
4703 ELSE IF (horz_order .EQ. 2) THEN
4705 IF (ite .GT. ide - 1) THEN
4711 IF (jte .GT. jde - 1) THEN
4716 IF (.NOT.config_flags%periodic_x) THEN
4717 IF (config_flags%open_xs .OR. specified) THEN
4718 IF (ids + 1 .LT. its) THEN
4724 IF (config_flags%open_xe .OR. specified) THEN
4725 IF (ide - 2 .GT. ite) THEN
4735 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
4736 mrdx = msftx(i, j)*rdx
4737 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.5*(rud(i+1, k&
4738 & , j)*(field(i+1, k, j)+field(i, k, j))+ru(i+1, k, j)*(fieldd&
4739 & (i+1, k, j)+fieldd(i, k, j))-rud(i, k, j)*(field(i, k, j)+&
4740 & field(i-1, k, j))-ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k&
4742 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.5*(ru(i+1, k, j&
4743 & )*(field(i+1, k, j)+field(i, k, j))-ru(i, k, j)*(field(i, k&
4744 & , j)+field(i-1, k, j)))
4749 IF (ite .GT. ide - 1) THEN
4754 ! Polar boundary conditions are like open or specified
4755 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
4757 IF (jds + 1 .LT. jts) THEN
4763 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
4765 IF (jde - 2 .GT. jte) THEN
4774 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4775 mrdy = msftx(i, j)*rdy
4776 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.5*(rvd(i, k, &
4777 & j+1)*(field(i, k, j+1)+field(i, k, j))+rv(i, k, j+1)*(fieldd&
4778 & (i, k, j+1)+fieldd(i, k, j))-rvd(i, k, j)*(field(i, k, j)+&
4779 & field(i, k, j-1))-rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, &
4781 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.5*(rv(i, k, j+1&
4782 & )*(field(i, k, j+1)+field(i, k, j))-rv(i, k, j)*(field(i, k&
4783 & , j)+field(i, k, j-1)))
4787 ! Polar boundary condtions
4788 ! These won't be covered in the loop above...
4789 IF (config_flags%polar) THEN
4790 IF (jts .EQ. jds) THEN
4793 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4794 mrdy = msftx(i, jds)*rdy
4795 tendencyd(i, k, jds) = tendencyd(i, k, jds) - mrdy*0.5*(rvd(&
4796 & i, k, jds+1)*(field(i, k, jds+1)+field(i, k, jds))+rv(i, k&
4797 & , jds+1)*(fieldd(i, k, jds+1)+fieldd(i, k, jds)))
4798 tendency(i, k, jds) = tendency(i, k, jds) - mrdy*0.5*rv(i, k&
4799 & , jds+1)*(field(i, k, jds+1)+field(i, k, jds))
4803 IF (jte .EQ. jde) THEN
4806 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
4807 mrdy = msftx(i, jde-1)*rdy
4808 tendencyd(i, k, jde-1) = tendencyd(i, k, jde-1) + mrdy*0.5*(&
4809 & rvd(i, k, jde-1)*(field(i, k, jde-1)+field(i, k, jde-2))+&
4810 & rv(i, k, jde-1)*(fieldd(i, k, jde-1)+fieldd(i, k, jde-2)))
4811 tendency(i, k, jde-1) = tendency(i, k, jde-1) + mrdy*0.5*rv(&
4812 & i, k, jde-1)*(field(i, k, jde-1)+field(i, k, jde-2))
4817 ELSE IF (horz_order .NE. 0) THEN
4818 ! Just in case we want to turn horizontal advection off, we can do it
4819 WRITE(wrf_err_message, *) &
4820 & 'module_advect: advect_scalar_6a, h_order not known ', horz_order
4821 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
4823 ! pick up the rest of the horizontal radiation boundary conditions.
4824 ! (these are the computations that don't require 'cb'.
4825 ! first, set to index ranges
4827 IF (ite .GT. ide - 1) THEN
4833 IF (jte .GT. jde - 1) THEN
4838 ! compute x (u) conditions for v, w, or scalar
4839 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
4842 IF (0.5*(ru(its, k, j)+ru(its+1, k, j)) .GT. 0.) THEN
4846 ubd = 0.5*(rud(its, k, j)+rud(its+1, k, j))
4847 ub = 0.5*(ru(its, k, j)+ru(its+1, k, j))
4849 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(&
4850 & field_old(its+1, k, j)-field_old(its, k, j))+ub*(field_oldd(&
4851 & its+1, k, j)-field_oldd(its, k, j))+fieldd(its, k, j)*(ru(its+&
4852 & 1, k, j)-ru(its, k, j))+field(its, k, j)*(rud(its+1, k, j)-rud&
4854 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(field_old(&
4855 & its+1, k, j)-field_old(its, k, j))+field(its, k, j)*(ru(its+1&
4856 & , k, j)-ru(its, k, j)))
4860 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
4863 IF (0.5*(ru(ite-1, k, j)+ru(ite, k, j)) .LT. 0.) THEN
4867 ubd = 0.5*(rud(ite-1, k, j)+rud(ite, k, j))
4868 ub = 0.5*(ru(ite-1, k, j)+ru(ite, k, j))
4870 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
4871 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+ub*(&
4872 & field_oldd(i_end, k, j)-field_oldd(i_end-1, k, j))+fieldd(&
4873 & i_end, k, j)*(ru(ite, k, j)-ru(ite-1, k, j))+field(i_end, k, j&
4874 & )*(rud(ite, k, j)-rud(ite-1, k, j)))
4875 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(&
4876 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+field(i_end, &
4877 & k, j)*(ru(ite, k, j)-ru(ite-1, k, j)))
4881 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
4884 IF (0.5*(rv(i, k, jts)+rv(i, k, jts+1)) .GT. 0.) THEN
4888 vbd = 0.5*(rvd(i, k, jts)+rvd(i, k, jts+1))
4889 vb = 0.5*(rv(i, k, jts)+rv(i, k, jts+1))
4891 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
4892 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
4893 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*(rv(i, k&
4894 & , jts+1)-rv(i, k, jts))+field(i, k, jts)*(rvd(i, k, jts+1)-rvd&
4896 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
4897 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*(rv(i, k, &
4898 & jts+1)-rv(i, k, jts)))
4902 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
4905 IF (0.5*(rv(i, k, jte-1)+rv(i, k, jte)) .LT. 0.) THEN
4909 vbd = 0.5*(rvd(i, k, jte-1)+rvd(i, k, jte))
4910 vb = 0.5*(rv(i, k, jte-1)+rv(i, k, jte))
4912 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
4913 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
4914 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))+fieldd(i, k&
4915 & , j_end)*(rv(i, k, jte)-rv(i, k, jte-1))+field(i, k, j_end)*(&
4916 & rvd(i, k, jte)-rvd(i, k, jte-1)))
4917 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
4918 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
4919 & j_end)*(rv(i, k, jte)-rv(i, k, jte-1)))
4923 !-------------------- vertical advection
4924 ! Scalar equation has 3rd term on RHS = - partial d/dz (q rho w /my)
4925 ! Here we have: - partial d/dz (q*rom) = - partial d/dz (q rho w / my)
4926 ! So we don't need to make a correction for advect_scalar
4928 IF (ite .GT. ide - 1) THEN
4934 IF (jte .GT. jde - 1) THEN
4940 vfluxd(i, kts) = 0.0
4942 vfluxd(i, kte) = 0.0
4945 IF (vert_order .EQ. 6) THEN
4950 veld = romd(i, k, j)
4952 vfluxd(i, k) = veld*(37.*(field(i, k, j)+field(i, k-1, j))-8.*&
4953 & (field(i, k+1, j)+field(i, k-2, j))+(field(i, k+2, j)+field(&
4954 & i, k-3, j)))/60.0 + vel*(37.*(fieldd(i, k, j)+fieldd(i, k-1&
4955 & , j))-8.*(fieldd(i, k+1, j)+fieldd(i, k-2, j))+fieldd(i, k+2&
4956 & , j)+fieldd(i, k-3, j))/60.0
4957 vflux(i, k) = vel*((37.*(field(i, k, j)+field(i, k-1, j))-8.*(&
4958 & field(i, k+1, j)+field(i, k-2, j))+(field(i, k+2, j)+field(i&
4964 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
4965 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
4966 & fieldd(i, k-1, j))
4967 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
4970 veld = romd(i, k, j)
4972 vfluxd(i, k) = veld*(7.*(field(i, k, j)+field(i, k-1, j))-(field&
4973 & (i, k+1, j)+field(i, k-2, j)))/12.0 + vel*(7.*(fieldd(i, k, j)&
4974 & +fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, j))/12.0
4975 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(field(&
4976 & i, k+1, j)+field(i, k-2, j)))/12.0)
4978 veld = romd(i, k, j)
4980 vfluxd(i, k) = veld*(7.*(field(i, k, j)+field(i, k-1, j))-(field&
4981 & (i, k+1, j)+field(i, k-2, j)))/12.0 + vel*(7.*(fieldd(i, k, j)&
4982 & +fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, j))/12.0
4983 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(field(&
4984 & i, k+1, j)+field(i, k-2, j)))/12.0)
4986 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
4987 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
4988 & fieldd(i, k-1, j))
4989 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
4994 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
4996 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
5001 ELSE IF (vert_order .EQ. 5) THEN
5006 veld = romd(i, k, j)
5008 vfluxd(i, k) = veld*((37.*(field(i, k, j)+field(i, k-1, j))-8.&
5009 & *(field(i, k+1, j)+field(i, k-2, j))+(field(i, k+2, j)+field&
5010 & (i, k-3, j)))/60.0-SIGN(1, time_step)*SIGN(1., -vel)*(field(&
5011 & i, k+2, j)-field(i, k-3, j)-5.*(field(i, k+1, j)-field(i, k-&
5012 & 2, j))+10.*(field(i, k, j)-field(i, k-1, j)))/60.0) + vel*((&
5013 & 37.*(fieldd(i, k, j)+fieldd(i, k-1, j))-8.*(fieldd(i, k+1, j&
5014 & )+fieldd(i, k-2, j))+fieldd(i, k+2, j)+fieldd(i, k-3, j))/&
5015 & 60.0-SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+2, j)-&
5016 & fieldd(i, k-3, j)-5.*(fieldd(i, k+1, j)-fieldd(i, k-2, j))+&
5017 & 10.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/60.0)
5018 vflux(i, k) = vel*((37.*(field(i, k, j)+field(i, k-1, j))-8.*(&
5019 & field(i, k+1, j)+field(i, k-2, j))+(field(i, k+2, j)+field(i&
5020 & , k-3, j)))/60.0-SIGN(1, time_step)*SIGN(1., -vel)*(field(i&
5021 & , k+2, j)-field(i, k-3, j)-5.*(field(i, k+1, j)-field(i, k-2&
5022 & , j))+10.*(field(i, k, j)-field(i, k-1, j)))/60.0)
5027 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5028 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5029 & fieldd(i, k-1, j))
5030 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5033 veld = romd(i, k, j)
5035 vfluxd(i, k) = veld*((7.*(field(i, k, j)+field(i, k-1, j))-(&
5036 & field(i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*&
5037 & SIGN(1., -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(i&
5038 & , k, j)-field(i, k-1, j)))/12.0) + vel*((7.*(fieldd(i, k, j)+&
5039 & fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, j))/12.0+&
5040 & SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-fieldd(i&
5041 & , k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.0)
5042 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(field(&
5043 & i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1.&
5044 & , -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-&
5045 & field(i, k-1, j)))/12.0)
5047 veld = romd(i, k, j)
5049 vfluxd(i, k) = veld*((7.*(field(i, k, j)+field(i, k-1, j))-(&
5050 & field(i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*&
5051 & SIGN(1., -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(i&
5052 & , k, j)-field(i, k-1, j)))/12.0) + vel*((7.*(fieldd(i, k, j)+&
5053 & fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, j))/12.0+&
5054 & SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-fieldd(i&
5055 & , k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.0)
5056 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(field(&
5057 & i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1.&
5058 & , -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-&
5059 & field(i, k-1, j)))/12.0)
5061 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5062 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5063 & fieldd(i, k-1, j))
5064 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5069 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
5071 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
5076 ELSE IF (vert_order .EQ. 4) THEN
5081 veld = romd(i, k, j)
5083 vfluxd(i, k) = veld*(7.*(field(i, k, j)+field(i, k-1, j))-(&
5084 & field(i, k+1, j)+field(i, k-2, j)))/12.0 + vel*(7.*(fieldd(i&
5085 & , k, j)+fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, &
5087 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(&
5088 & field(i, k+1, j)+field(i, k-2, j)))/12.0)
5093 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5094 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5095 & fieldd(i, k-1, j))
5096 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5099 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5100 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5101 & fieldd(i, k-1, j))
5102 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5107 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
5109 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
5114 ELSE IF (vert_order .EQ. 3) THEN
5119 veld = romd(i, k, j)
5121 vfluxd(i, k) = veld*((7.*(field(i, k, j)+field(i, k-1, j))-(&
5122 & field(i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*&
5123 & SIGN(1., -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
5124 & i, k, j)-field(i, k-1, j)))/12.0) + vel*((7.*(fieldd(i, k, j&
5125 & )+fieldd(i, k-1, j))-fieldd(i, k+1, j)-fieldd(i, k-2, j))/&
5126 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-&
5127 & fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/&
5129 vflux(i, k) = vel*((7.*(field(i, k, j)+field(i, k-1, j))-(&
5130 & field(i, k+1, j)+field(i, k-2, j)))/12.0+SIGN(1, time_step)*&
5131 & SIGN(1., -vel)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
5132 & i, k, j)-field(i, k-1, j)))/12.0)
5137 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5138 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5139 & fieldd(i, k-1, j))
5140 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5143 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5144 & (i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*&
5145 & fieldd(i, k-1, j))
5146 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
5151 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
5153 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
5158 ELSE IF (vert_order .EQ. 2) THEN
5163 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
5164 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp&
5165 & (k)*fieldd(i, k-1, j))
5166 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field&
5172 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k&
5174 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)&
5180 WRITE(wrf_err_message, *) ' advect_scalar_6a, v_order not known ', &
5182 CALL WRF_ERROR_FATAL(wrf_err_message)
5184 END SUBROUTINE G_ADVECT_SCALAR
5186 ! Generated by TAPENADE (INRIA, Tropics team)
5187 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
5189 ! Differentiation of advect_w in forward (tangent) mode:
5190 ! variations of useful results: tendency
5191 ! with respect to varying inputs: rom tendency w ru rv w_old
5192 ! RW status of diff variables: rom:in tendency:in-out w:in ru:in
5194 SUBROUTINE G_ADVECT_W(w, wd, w_old, w_oldd, tendency, tendencyd, ru, rud&
5195 & , rv, rvd, rom, romd, mut, time_step, config_flags, msfux, msfuy, &
5196 & msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzu, ids, ide, jds, &
5197 & jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, &
5201 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
5202 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
5203 & jme, kms, kme, its, ite, jts, jte, kts, kte
5204 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: w, w_old, ru&
5206 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: wd, w_oldd, &
5208 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
5209 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
5210 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
5211 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
5212 & msfvy, msftx, msfty
5213 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzu
5214 REAL, INTENT(IN) :: rdx, rdy
5215 INTEGER, INTENT(IN) :: time_step
5217 INTEGER :: i, j, k, itf, jtf, ktf
5218 INTEGER :: i_start, i_end, j_start, j_end
5219 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
5220 INTEGER :: jmin, jmax, jp, jm, imin, imax
5221 REAL :: mrdx, mrdy, ub, vb, uw, vw
5222 REAL :: ubd, vbd, uwd, vwd
5223 REAL, DIMENSION(its:ite, kts:kte) :: vflux
5224 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
5225 INTEGER :: horz_order, vert_order
5226 REAL, DIMENSION(its:ite + 1, kts:kte) :: fqx
5227 REAL, DIMENSION(its:ite+1, kts:kte) :: fqxd
5228 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
5229 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
5230 LOGICAL :: degrade_xs, degrade_ys
5231 LOGICAL :: degrade_xe, degrade_ye
5232 INTEGER :: jp1, jp0, jtmp
5233 ! definition of flux operators, 3rd, 4th, 5th or 6th order
5234 REAL :: flux3, flux4, flux5, flux6
5235 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
5237 LOGICAL :: specified
5243 IF (config_flags%specified .OR. config_flags%nested) specified = &
5245 IF (kte .GT. kde - 1) THEN
5250 horz_order = config_flags%h_sca_adv_order
5251 vert_order = config_flags%v_sca_adv_order
5252 ! here is the choice of flux operators
5253 ! begin with horizontal flux divergence
5254 IF (horz_order .EQ. 6) THEN
5255 ! determine boundary mods for flux operators
5256 ! We degrade the flux operators from 3rd/4th order
5257 ! to second order one gridpoint in from the boundaries for
5258 ! all boundary conditions except periodic and symmetry - these
5259 ! conditions have boundary zone data fill for correct application
5260 ! of the higher order flux stencils
5265 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
5266 & its .GT. ids + 3) degrade_xs = .false.
5267 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
5268 & ite .LT. ide - 3) degrade_xe = .false.
5269 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
5270 & jts .GT. jds + 3) degrade_ys = .false.
5271 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
5272 & jte .LT. jde - 4) degrade_ye = .false.
5273 !--------------- y - advection first
5275 IF (ite .GT. ide - 1) THEN
5281 IF (jte .GT. jde - 1) THEN
5286 ! higher order flux has a 5 or 7 point stencil, so compute
5287 ! bounds so we can switch to second order flux close to the boundary
5290 IF (degrade_ys) THEN
5291 IF (jts .LT. jds + 1) THEN
5298 IF (degrade_ye) THEN
5299 IF (jte .GT. jde - 2) THEN
5306 IF (config_flags%polar) THEN
5307 IF (jte .GT. jde - 1) THEN
5313 ! compute fluxes, 5th or 6th order
5317 j_loop_y_flux_6:DO j=j_start,j_end+1
5318 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
5321 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5322 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5323 fqyd(i, k, jp1) = veld*(37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(&
5324 & i, k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0&
5325 & + vel*(37.*(wd(i, k, j)+wd(i, k, j-1))-8.*(wd(i, k, j+1)+&
5326 & wd(i, k, j-2))+wd(i, k, j+2)+wd(i, k, j-3))/60.0
5327 fqy(i, k, jp1) = vel*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i&
5328 & , k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0)
5333 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5334 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5335 fqyd(i, k, jp1) = veld*(37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i&
5336 & , k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0 + &
5337 & vel*(37.*(wd(i, k, j)+wd(i, k, j-1))-8.*(wd(i, k, j+1)+wd(i&
5338 & , k, j-2))+wd(i, k, j+2)+wd(i, k, j-3))/60.0
5339 fqy(i, k, jp1) = vel*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i, &
5340 & k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0)
5342 ELSE IF (j .EQ. jds + 1) THEN
5343 ! 2nd order flux next to south boundary
5346 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
5347 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
5348 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
5349 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
5350 & ))*(w(i, k, j)+w(i, k, j-1))
5355 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
5356 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
5357 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
5359 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
5360 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
5362 ELSE IF (j .EQ. jds + 2) THEN
5363 ! third of 4th order flux 2 in from south boundary
5366 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5367 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5368 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5369 & , j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k&
5370 & , j-1))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
5371 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5372 & , j+1)+w(i, k, j-2)))/12.0)
5377 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5378 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5379 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, &
5380 & j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k, j-1&
5381 & ))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
5382 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
5383 & +1)+w(i, k, j-2)))/12.0)
5385 ELSE IF (j .EQ. jde - 1) THEN
5386 ! 2nd order flux next to north boundary
5389 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
5390 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
5391 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
5392 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
5393 & ))*(w(i, k, j)+w(i, k, j-1))
5398 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
5399 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
5400 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
5402 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
5403 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
5405 ELSE IF (j .EQ. jde - 2) THEN
5406 ! 3rd or 4th order flux 2 in from north boundary
5409 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5410 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5411 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5412 & , j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k&
5413 & , j-1))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
5414 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5415 & , j+1)+w(i, k, j-2)))/12.0)
5420 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5421 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5422 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, &
5423 & j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k, j-1&
5424 & ))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
5425 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
5426 & +1)+w(i, k, j-2)))/12.0)
5429 ! y flux-divergence into tendency
5430 ! Comments for polar boundary conditions
5431 ! Same process as for advect_u - tendencies run from jds to jde-1
5432 ! (latitudes are as for u grid, longitudes are displaced)
5433 ! Therefore: flow is only from one side for points next to poles
5434 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
5437 ! see ADT eqn 46 dividing by my, 2nd term RHS
5438 mrdy = msftx(i, j-1)*rdy
5439 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
5441 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
5445 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
5448 ! see ADT eqn 46 dividing by my, 2nd term RHS
5449 mrdy = msftx(i, j-1)*rdy
5450 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
5452 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
5456 ELSE IF (j .GT. j_start) THEN
5460 ! see ADT eqn 46 dividing by my, 2nd term RHS
5461 mrdy = msftx(i, j-1)*rdy
5462 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
5463 & k, jp1)-fqyd(i, k, jp0))
5464 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
5465 & jp1)-fqy(i, k, jp0))
5472 END DO j_loop_y_flux_6
5473 ! next, x - flux divergence
5475 IF (ite .GT. ide - 1) THEN
5481 IF (jte .GT. jde - 1) THEN
5486 ! higher order flux has a 5 or 7 point stencil, so compute
5487 ! bounds so we can switch to second order flux close to the boundary
5490 IF (degrade_xs) THEN
5491 IF (ids + 1 .LT. its) THEN
5496 IF (i_start + 2 .GT. ids + 3) THEN
5499 i_start_f = i_start + 2
5502 IF (degrade_xe) THEN
5503 IF (ide - 2 .GT. ite) THEN
5515 ! 5th or 6th order flux
5517 DO i=i_start_f,i_end_f
5518 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
5519 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
5520 fqxd(i, k) = veld*(37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k&
5521 & , j)+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0 + vel*(&
5522 & 37.*(wd(i, k, j)+wd(i-1, k, j))-8.*(wd(i+1, k, j)+wd(i-2, k&
5523 & , j))+wd(i+2, k, j)+wd(i-3, k, j))/60.0
5524 fqx(i, k) = vel*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, &
5525 & j)+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0)
5529 DO i=i_start_f,i_end_f
5530 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
5531 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
5532 fqxd(i, k) = veld*(37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, j&
5533 & )+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0 + vel*(37.*(&
5534 & wd(i, k, j)+wd(i-1, k, j))-8.*(wd(i+1, k, j)+wd(i-2, k, j))+wd&
5535 & (i+2, k, j)+wd(i-3, k, j))/60.0
5536 fqx(i, k) = vel*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, j)&
5537 & +w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0)
5539 ! lower order fluxes close to boundaries (if not periodic or symmetric)
5540 IF (degrade_xs) THEN
5541 DO i=i_start,i_start_f-1
5542 IF (i .EQ. ids + 1) THEN
5545 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, &
5546 & j))*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)&
5547 & *ru(i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
5548 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*&
5549 & (w(i, k, j)+w(i-1, k, j))
5552 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud&
5553 & (i, k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i&
5554 & , k-1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, &
5556 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, &
5557 & k-2, j))*(w(i, k, j)+w(i-1, k, j))
5559 IF (i .EQ. ids + 2) THEN
5562 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
5563 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
5564 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k&
5565 & , j)+w(i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, &
5566 & k, j))-wd(i+1, k, j)-wd(i-2, k, j))/12.0
5567 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
5568 & j)+w(i-2, k, j)))/12.0)
5571 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j&
5573 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
5574 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j&
5575 & )+w(i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, k, j)&
5576 & )-wd(i+1, k, j)-wd(i-2, k, j))/12.0
5577 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
5578 & +w(i-2, k, j)))/12.0)
5582 IF (degrade_xe) THEN
5583 DO i=i_end_f+1,i_end+1
5584 IF (i .EQ. ide - 1) THEN
5585 ! second order flux next to the boundary
5587 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, &
5588 & j))*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)&
5589 & *ru(i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
5590 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*&
5591 & (w(i, k, j)+w(i-1, k, j))
5594 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud&
5595 & (i, k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i&
5596 & , k-1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, &
5598 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, &
5599 & k-2, j))*(w(i, k, j)+w(i-1, k, j))
5601 IF (i .EQ. ide - 2) THEN
5602 ! third order flux one in from the boundary
5604 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
5605 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
5606 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k&
5607 & , j)+w(i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, &
5608 & k, j))-wd(i+1, k, j)-wd(i-2, k, j))/12.0
5609 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
5610 & j)+w(i-2, k, j)))/12.0)
5613 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j&
5615 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
5616 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j&
5617 & )+w(i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, k, j)&
5618 & )-wd(i+1, k, j)-wd(i-2, k, j))/12.0
5619 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
5620 & +w(i-2, k, j)))/12.0)
5624 ! x flux-divergence into tendency
5627 ! see ADT eqn 46 dividing by my, 1st term RHS
5628 mrdx = msftx(i, j)*rdx
5629 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
5631 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
5636 ELSE IF (horz_order .EQ. 5) THEN
5637 ! determine boundary mods for flux operators
5638 ! We degrade the flux operators from 3rd/4th order
5639 ! to second order one gridpoint in from the boundaries for
5640 ! all boundary conditions except periodic and symmetry - these
5641 ! conditions have boundary zone data fill for correct application
5642 ! of the higher order flux stencils
5647 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
5648 & its .GT. ids + 3) degrade_xs = .false.
5649 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
5650 & ite .LT. ide - 3) degrade_xe = .false.
5651 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
5652 & jts .GT. jds + 3) degrade_ys = .false.
5653 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
5654 & jte .LT. jde - 4) degrade_ye = .false.
5655 !--------------- y - advection first
5657 IF (ite .GT. ide - 1) THEN
5663 IF (jte .GT. jde - 1) THEN
5668 ! higher order flux has a 5 or 7 point stencil, so compute
5669 ! bounds so we can switch to second order flux close to the boundary
5672 IF (degrade_ys) THEN
5673 IF (jts .LT. jds + 1) THEN
5680 IF (degrade_ye) THEN
5681 IF (jte .GT. jde - 2) THEN
5688 IF (config_flags%polar) THEN
5689 IF (jte .GT. jde - 1) THEN
5695 ! compute fluxes, 5th or 6th order
5699 j_loop_y_flux_5:DO j=j_start,j_end+1
5700 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
5703 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5704 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5705 fqyd(i, k, jp1) = veld*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w&
5706 & (i, k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/&
5707 & 60.0-SIGN(1, time_step)*SIGN(1., vel)*(w(i, k, j+2)-w(i, k&
5708 & , j-3)-5.*(w(i, k, j+1)-w(i, k, j-2))+10.*(w(i, k, j)-w(i&
5709 & , k, j-1)))/60.0) + vel*((37.*(wd(i, k, j)+wd(i, k, j-1))-&
5710 & 8.*(wd(i, k, j+1)+wd(i, k, j-2))+wd(i, k, j+2)+wd(i, k, j-&
5711 & 3))/60.0-SIGN(1, time_step)*SIGN(1., vel)*(wd(i, k, j+2)-&
5712 & wd(i, k, j-3)-5.*(wd(i, k, j+1)-wd(i, k, j-2))+10.*(wd(i, &
5713 & k, j)-wd(i, k, j-1)))/60.0)
5714 fqy(i, k, jp1) = vel*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i&
5715 & , k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0-&
5716 & SIGN(1, time_step)*SIGN(1., vel)*(w(i, k, j+2)-w(i, k, j-3&
5717 & )-5.*(w(i, k, j+1)-w(i, k, j-2))+10.*(w(i, k, j)-w(i, k, j&
5723 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5724 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5725 fqyd(i, k, jp1) = veld*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i&
5726 & , k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0-&
5727 & SIGN(1, time_step)*SIGN(1., vel)*(w(i, k, j+2)-w(i, k, j-3)-&
5728 & 5.*(w(i, k, j+1)-w(i, k, j-2))+10.*(w(i, k, j)-w(i, k, j-1))&
5729 & )/60.0) + vel*((37.*(wd(i, k, j)+wd(i, k, j-1))-8.*(wd(i, k&
5730 & , j+1)+wd(i, k, j-2))+wd(i, k, j+2)+wd(i, k, j-3))/60.0-SIGN&
5731 & (1, time_step)*SIGN(1., vel)*(wd(i, k, j+2)-wd(i, k, j-3)-5.&
5732 & *(wd(i, k, j+1)-wd(i, k, j-2))+10.*(wd(i, k, j)-wd(i, k, j-1&
5734 fqy(i, k, jp1) = vel*((37.*(w(i, k, j)+w(i, k, j-1))-8.*(w(i, &
5735 & k, j+1)+w(i, k, j-2))+(w(i, k, j+2)+w(i, k, j-3)))/60.0-SIGN&
5736 & (1, time_step)*SIGN(1., vel)*(w(i, k, j+2)-w(i, k, j-3)-5.*(&
5737 & w(i, k, j+1)-w(i, k, j-2))+10.*(w(i, k, j)-w(i, k, j-1)))/&
5740 ELSE IF (j .EQ. jds + 1) THEN
5741 ! 2nd order flux next to south boundary
5744 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
5745 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
5746 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
5747 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
5748 & ))*(w(i, k, j)+w(i, k, j-1))
5753 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
5754 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
5755 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
5757 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
5758 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
5760 ELSE IF (j .EQ. jds + 2) THEN
5761 ! third of 4th order flux 2 in from south boundary
5764 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5765 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5766 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, &
5767 & k, j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
5768 & vel)*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1&
5769 & )))/12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, &
5770 & j+1)-wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
5771 & (wd(i, k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)&
5773 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5774 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
5775 & )*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))&
5781 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5782 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5783 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5784 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
5785 & (w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/&
5786 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-&
5787 & wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, &
5788 & k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
5789 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
5790 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(&
5791 & i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
5793 ELSE IF (j .EQ. jde - 1) THEN
5794 ! 2nd order flux next to north boundary
5797 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
5798 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
5799 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
5800 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
5801 & ))*(w(i, k, j)+w(i, k, j-1))
5806 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
5807 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
5808 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
5810 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
5811 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
5813 ELSE IF (j .EQ. jde - 2) THEN
5814 ! 3rd or 4th order flux 2 in from north boundary
5817 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
5818 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
5819 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, &
5820 & k, j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
5821 & vel)*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1&
5822 & )))/12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, &
5823 & j+1)-wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
5824 & (wd(i, k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)&
5826 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5827 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
5828 & )*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))&
5834 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
5835 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
5836 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
5837 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
5838 & (w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/&
5839 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-&
5840 & wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, &
5841 & k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
5842 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
5843 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(&
5844 & i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
5847 ! y flux-divergence into tendency
5848 ! Comments for polar boundary conditions
5849 ! Same process as for advect_u - tendencies run from jds to jde-1
5850 ! (latitudes are as for u grid, longitudes are displaced)
5851 ! Therefore: flow is only from one side for points next to poles
5852 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
5855 ! see ADT eqn 46 dividing by my, 2nd term RHS
5856 mrdy = msftx(i, j-1)*rdy
5857 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
5859 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
5863 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
5866 ! see ADT eqn 46 dividing by my, 2nd term RHS
5867 mrdy = msftx(i, j-1)*rdy
5868 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
5870 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
5874 ELSE IF (j .GT. j_start) THEN
5878 ! see ADT eqn 46 dividing by my, 2nd term RHS
5879 mrdy = msftx(i, j-1)*rdy
5880 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
5881 & k, jp1)-fqyd(i, k, jp0))
5882 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
5883 & jp1)-fqy(i, k, jp0))
5890 END DO j_loop_y_flux_5
5891 ! next, x - flux divergence
5893 IF (ite .GT. ide - 1) THEN
5899 IF (jte .GT. jde - 1) THEN
5904 ! higher order flux has a 5 or 7 point stencil, so compute
5905 ! bounds so we can switch to second order flux close to the boundary
5908 IF (degrade_xs) THEN
5909 IF (ids + 1 .LT. its) THEN
5914 IF (i_start + 2 .GT. ids + 3) THEN
5917 i_start_f = i_start + 2
5920 IF (degrade_xe) THEN
5921 IF (ide - 2 .GT. ite) THEN
5933 ! 5th or 6th order flux
5935 DO i=i_start_f,i_end_f
5936 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
5937 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
5938 fqxd(i, k) = veld*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k&
5939 & , j)+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0-SIGN(1&
5940 & , time_step)*SIGN(1., vel)*(w(i+2, k, j)-w(i-3, k, j)-5.*(w(&
5941 & i+1, k, j)-w(i-2, k, j))+10.*(w(i, k, j)-w(i-1, k, j)))/60.0&
5942 & ) + vel*((37.*(wd(i, k, j)+wd(i-1, k, j))-8.*(wd(i+1, k, j)+&
5943 & wd(i-2, k, j))+wd(i+2, k, j)+wd(i-3, k, j))/60.0-SIGN(1, &
5944 & time_step)*SIGN(1., vel)*(wd(i+2, k, j)-wd(i-3, k, j)-5.*(wd&
5945 & (i+1, k, j)-wd(i-2, k, j))+10.*(wd(i, k, j)-wd(i-1, k, j)))/&
5947 fqx(i, k) = vel*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, &
5948 & j)+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0-SIGN(1, &
5949 & time_step)*SIGN(1., vel)*(w(i+2, k, j)-w(i-3, k, j)-5.*(w(i+&
5950 & 1, k, j)-w(i-2, k, j))+10.*(w(i, k, j)-w(i-1, k, j)))/60.0)
5954 DO i=i_start_f,i_end_f
5955 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
5956 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
5957 fqxd(i, k) = veld*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, &
5958 & j)+w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0-SIGN(1, &
5959 & time_step)*SIGN(1., vel)*(w(i+2, k, j)-w(i-3, k, j)-5.*(w(i+1&
5960 & , k, j)-w(i-2, k, j))+10.*(w(i, k, j)-w(i-1, k, j)))/60.0) + &
5961 & vel*((37.*(wd(i, k, j)+wd(i-1, k, j))-8.*(wd(i+1, k, j)+wd(i-2&
5962 & , k, j))+wd(i+2, k, j)+wd(i-3, k, j))/60.0-SIGN(1, time_step)*&
5963 & SIGN(1., vel)*(wd(i+2, k, j)-wd(i-3, k, j)-5.*(wd(i+1, k, j)-&
5964 & wd(i-2, k, j))+10.*(wd(i, k, j)-wd(i-1, k, j)))/60.0)
5965 fqx(i, k) = vel*((37.*(w(i, k, j)+w(i-1, k, j))-8.*(w(i+1, k, j)&
5966 & +w(i-2, k, j))+(w(i+2, k, j)+w(i-3, k, j)))/60.0-SIGN(1, &
5967 & time_step)*SIGN(1., vel)*(w(i+2, k, j)-w(i-3, k, j)-5.*(w(i+1&
5968 & , k, j)-w(i-2, k, j))+10.*(w(i, k, j)-w(i-1, k, j)))/60.0)
5970 ! lower order fluxes close to boundaries (if not periodic or symmetric)
5971 IF (degrade_xs) THEN
5972 DO i=i_start,i_start_f-1
5973 IF (i .EQ. ids + 1) THEN
5976 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, &
5977 & j))*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)&
5978 & *ru(i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
5979 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*&
5980 & (w(i, k, j)+w(i-1, k, j))
5983 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud&
5984 & (i, k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i&
5985 & , k-1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, &
5987 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, &
5988 & k-2, j))*(w(i, k, j)+w(i-1, k, j))
5990 IF (i .EQ. ids + 2) THEN
5993 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
5994 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
5995 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k&
5996 & , j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
5997 & )*(w(i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)&
5998 & ))/12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, &
5999 & k, j)-wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
6000 & vel)*(wd(i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1&
6002 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
6003 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
6004 & (w(i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))&
6008 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j&
6010 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
6011 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
6012 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w&
6013 & (i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/&
6014 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)&
6015 & -wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(&
6016 & i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/&
6018 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
6019 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
6020 & +1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
6024 IF (degrade_xe) THEN
6025 DO i=i_end_f+1,i_end+1
6026 IF (i .EQ. ide - 1) THEN
6027 ! second order flux next to the boundary
6029 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, &
6030 & j))*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)&
6031 & *ru(i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
6032 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*&
6033 & (w(i, k, j)+w(i-1, k, j))
6036 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud&
6037 & (i, k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i&
6038 & , k-1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, &
6040 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, &
6041 & k-2, j))*(w(i, k, j)+w(i-1, k, j))
6043 IF (i .EQ. ide - 2) THEN
6044 ! third order flux one in from the boundary
6046 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
6047 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
6048 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k&
6049 & , j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
6050 & )*(w(i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)&
6051 & ))/12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, &
6052 & k, j)-wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., &
6053 & vel)*(wd(i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1&
6055 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
6056 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
6057 & (w(i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))&
6061 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j&
6063 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
6064 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
6065 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w&
6066 & (i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/&
6067 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)&
6068 & -wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(&
6069 & i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/&
6071 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
6072 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
6073 & +1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
6077 ! x flux-divergence into tendency
6080 ! see ADT eqn 46 dividing by my, 1st term RHS
6081 mrdx = msftx(i, j)*rdx
6082 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
6084 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
6089 ELSE IF (horz_order .EQ. 4) THEN
6094 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
6095 & its .GT. ids + 2) degrade_xs = .false.
6096 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
6097 & ite .LT. ide - 2) degrade_xe = .false.
6098 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
6099 & jts .GT. jds + 2) degrade_ys = .false.
6100 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
6101 & jte .LT. jde - 3) degrade_ye = .false.
6102 IF (kte .GT. kde - 1) THEN
6108 IF (ite .GT. ide - 1) THEN
6114 IF (jte .GT. jde - 1) THEN
6119 ! 3rd or 4th order flux has a 5 point stencil, so compute
6120 ! bounds so we can switch to second order flux close to the boundary
6123 IF (degrade_xs) THEN
6125 i_start_f = i_start + 1
6127 IF (degrade_xe) THEN
6137 DO i=i_start_f,i_end_f
6138 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
6139 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
6140 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+&
6141 & w(i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, k, j))-wd&
6142 & (i+1, k, j)-wd(i-2, k, j))/12.0
6143 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w&
6144 & (i-2, k, j)))/12.0)
6148 DO i=i_start_f,i_end_f
6149 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
6150 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
6151 fqxd(i, k) = veld*(7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w(&
6152 & i-2, k, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1&
6153 & , k, j)-wd(i-2, k, j))/12.0
6154 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w(i&
6157 ! second order flux close to boundaries (if not periodic or symmetric)
6158 IF (degrade_xs) THEN
6160 fqxd(i_start, k) = 0.5*((fzm(k)*rud(i_start, k, j)+fzp(k)*rud(&
6161 & i_start, k-1, j))*(w(i_start, k, j)+w(i_start-1, k, j))+(fzm&
6162 & (k)*ru(i_start, k, j)+fzp(k)*ru(i_start, k-1, j))*(wd(&
6163 & i_start, k, j)+wd(i_start-1, k, j)))
6164 fqx(i_start, k) = 0.5*(fzm(k)*ru(i_start, k, j)+fzp(k)*ru(&
6165 & i_start, k-1, j))*(w(i_start, k, j)+w(i_start-1, k, j))
6168 fqxd(i_start, k) = 0.5*(((2.-fzm(k-1))*rud(i_start, k-1, j)-fzp(&
6169 & k-1)*rud(i_start, k-2, j))*(w(i_start, k, j)+w(i_start-1, k, j&
6170 & ))+((2.-fzm(k-1))*ru(i_start, k-1, j)-fzp(k-1)*ru(i_start, k-2&
6171 & , j))*(wd(i_start, k, j)+wd(i_start-1, k, j)))
6172 fqx(i_start, k) = 0.5*((2.-fzm(k-1))*ru(i_start, k-1, j)-fzp(k-1&
6173 & )*ru(i_start, k-2, j))*(w(i_start, k, j)+w(i_start-1, k, j))
6175 IF (degrade_xe) THEN
6177 fqxd(i_end+1, k) = 0.5*((fzm(k)*rud(i_end+1, k, j)+fzp(k)*rud(&
6178 & i_end+1, k-1, j))*(w(i_end+1, k, j)+w(i_end, k, j))+(fzm(k)*&
6179 & ru(i_end+1, k, j)+fzp(k)*ru(i_end+1, k-1, j))*(wd(i_end+1, k&
6180 & , j)+wd(i_end, k, j)))
6181 fqx(i_end+1, k) = 0.5*(fzm(k)*ru(i_end+1, k, j)+fzp(k)*ru(&
6182 & i_end+1, k-1, j))*(w(i_end+1, k, j)+w(i_end, k, j))
6185 fqxd(i_end+1, k) = 0.5*(((2.-fzm(k-1))*rud(i_end+1, k-1, j)-fzp(&
6186 & k-1)*rud(i_end+1, k-2, j))*(w(i_end+1, k, j)+w(i_end, k, j))+(&
6187 & (2.-fzm(k-1))*ru(i_end+1, k-1, j)-fzp(k-1)*ru(i_end+1, k-2, j)&
6188 & )*(wd(i_end+1, k, j)+wd(i_end, k, j)))
6189 fqx(i_end+1, k) = 0.5*((2.-fzm(k-1))*ru(i_end+1, k-1, j)-fzp(k-1&
6190 & )*ru(i_end+1, k-2, j))*(w(i_end+1, k, j)+w(i_end, k, j))
6192 ! x flux-divergence into tendency
6195 ! see ADT eqn 46 dividing by my, 1st term RHS
6196 mrdx = msftx(i, j)*rdx
6197 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
6199 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
6204 ! next -> y flux divergence calculation
6206 IF (ite .GT. ide - 1) THEN
6212 IF (jte .GT. jde - 1) THEN
6217 ! 3rd or 4th order flux has a 5 point stencil, so compute
6218 ! bounds so we can switch to second order flux close to the boundary
6221 IF (degrade_ys) THEN
6223 j_start_f = j_start + 1
6225 IF (degrade_ye) THEN
6229 IF (config_flags%polar) THEN
6230 IF (jte .GT. jde - 1) THEN
6239 DO j=j_start,j_end+1
6240 IF (j .LT. j_start_f .AND. degrade_ys) THEN
6243 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j_start)+fzp(k)*rvd&
6244 & (i, k-1, j_start))*(w(i, k, j_start)+w(i, k, j_start-1))+(&
6245 & fzm(k)*rv(i, k, j_start)+fzp(k)*rv(i, k-1, j_start))*(wd(i&
6246 & , k, j_start)+wd(i, k, j_start-1)))
6247 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j_start)+fzp(k)*rv(i, &
6248 & k-1, j_start))*(w(i, k, j_start)+w(i, k, j_start-1))
6253 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j_start)-fzp&
6254 & (k-1)*rvd(i, k-2, j_start))*(w(i, k, j_start)+w(i, k, &
6255 & j_start-1))+((2.-fzm(k-1))*rv(i, k-1, j_start)-fzp(k-1)*rv(i&
6256 & , k-2, j_start))*(wd(i, k, j_start)+wd(i, k, j_start-1)))
6257 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j_start)-fzp(k-&
6258 & 1)*rv(i, k-2, j_start))*(w(i, k, j_start)+w(i, k, j_start-1)&
6261 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
6264 ! Assumes j>j_end_f is ONLY j_end+1 ...
6265 ! fqy(i, k, jp1) = &
6266 ! 0.5*(fzm(k)*rv(i,k,j_end+1)+fzp(k)*rv(i,k-1,j_end+1)) &
6267 ! *(w(i,k,j_end+1)+w(i,k,j_end))
6268 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
6269 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
6270 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
6271 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
6272 & ))*(w(i, k, j)+w(i, k, j-1))
6277 ! Assumes j>j_end_f is ONLY j_end+1 ...
6278 ! fqy(i, k, jp1) = &
6279 ! 0.5*((2.-fzm(k-1))*rv(i,k-1,j_end+1)-fzp(k-1)*rv(i,k-2,j_end+1)) &
6280 ! *(w(i,k,j_end+1)+w(i,k,j_end))
6281 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
6282 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
6283 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
6285 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
6286 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
6289 ! 3rd or 4th order flux
6292 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
6293 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
6294 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
6295 & , j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k&
6296 & , j-1))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
6297 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
6298 & , j+1)+w(i, k, j-2)))/12.0)
6303 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
6304 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
6305 fqyd(i, k, jp1) = veld*(7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, &
6306 & j+1)+w(i, k, j-2)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k, j-1&
6307 & ))-wd(i, k, j+1)-wd(i, k, j-2))/12.0
6308 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
6309 & +1)+w(i, k, j-2)))/12.0)
6312 ! y flux-divergence into tendency
6313 ! Comments for polar boundary conditions
6314 ! Same process as for advect_u - tendencies run from jds to jde-1
6315 ! (latitudes are as for u grid, longitudes are displaced)
6316 ! Therefore: flow is only from one side for points next to poles
6317 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
6320 ! see ADT eqn 46 dividing by my, 2nd term RHS
6321 mrdy = msftx(i, j-1)*rdy
6322 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
6324 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
6328 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
6331 ! see ADT eqn 46 dividing by my, 2nd term RHS
6332 mrdy = msftx(i, j-1)*rdy
6333 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
6335 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
6339 ELSE IF (j .GT. j_start) THEN
6343 ! see ADT eqn 46 dividing by my, 2nd term RHS
6344 mrdy = msftx(i, j-1)*rdy
6345 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
6346 & k, jp1)-fqyd(i, k, jp0))
6347 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
6348 & jp1)-fqy(i, k, jp0))
6356 ELSE IF (horz_order .EQ. 3) THEN
6361 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
6362 & its .GT. ids + 2) degrade_xs = .false.
6363 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
6364 & ite .LT. ide - 2) degrade_xe = .false.
6365 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
6366 & jts .GT. jds + 2) degrade_ys = .false.
6367 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
6368 & jte .LT. jde - 3) degrade_ye = .false.
6369 IF (kte .GT. kde - 1) THEN
6375 IF (ite .GT. ide - 1) THEN
6381 IF (jte .GT. jde - 1) THEN
6386 ! 3rd or 4th order flux has a 5 point stencil, so compute
6387 ! bounds so we can switch to second order flux close to the boundary
6390 IF (degrade_xs) THEN
6392 i_start_f = i_start + 1
6394 IF (degrade_xe) THEN
6404 DO i=i_start_f,i_end_f
6405 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
6406 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
6407 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
6408 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1&
6409 & , k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0) + &
6410 & vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)-wd(i-2, k&
6411 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i+1, k, j)-&
6412 & wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/12.0)
6413 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w&
6414 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1, &
6415 & k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
6419 DO i=i_start_f,i_end_f
6420 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
6421 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
6422 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w&
6423 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1, k&
6424 & , j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0) + vel*((&
6425 & 7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)-wd(i-2, k, j))/&
6426 & 12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i+1, k, j)-wd(i-2, k&
6427 & , j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/12.0)
6428 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w(i&
6429 & -2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1, k, j&
6430 & )-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
6432 ! second order flux close to boundaries (if not periodic or symmetric)
6433 IF (degrade_xs) THEN
6435 fqxd(i_start, k) = 0.5*((fzm(k)*rud(i_start, k, j)+fzp(k)*rud(&
6436 & i_start, k-1, j))*(w(i_start, k, j)+w(i_start-1, k, j))+(fzm&
6437 & (k)*ru(i_start, k, j)+fzp(k)*ru(i_start, k-1, j))*(wd(&
6438 & i_start, k, j)+wd(i_start-1, k, j)))
6439 fqx(i_start, k) = 0.5*(fzm(k)*ru(i_start, k, j)+fzp(k)*ru(&
6440 & i_start, k-1, j))*(w(i_start, k, j)+w(i_start-1, k, j))
6443 fqxd(i_start, k) = 0.5*(((2.-fzm(k-1))*rud(i_start, k-1, j)-fzp(&
6444 & k-1)*rud(i_start, k-2, j))*(w(i_start, k, j)+w(i_start-1, k, j&
6445 & ))+((2.-fzm(k-1))*ru(i_start, k-1, j)-fzp(k-1)*ru(i_start, k-2&
6446 & , j))*(wd(i_start, k, j)+wd(i_start-1, k, j)))
6447 fqx(i_start, k) = 0.5*((2.-fzm(k-1))*ru(i_start, k-1, j)-fzp(k-1&
6448 & )*ru(i_start, k-2, j))*(w(i_start, k, j)+w(i_start-1, k, j))
6450 IF (degrade_xe) THEN
6452 fqxd(i_end+1, k) = 0.5*((fzm(k)*rud(i_end+1, k, j)+fzp(k)*rud(&
6453 & i_end+1, k-1, j))*(w(i_end+1, k, j)+w(i_end, k, j))+(fzm(k)*&
6454 & ru(i_end+1, k, j)+fzp(k)*ru(i_end+1, k-1, j))*(wd(i_end+1, k&
6455 & , j)+wd(i_end, k, j)))
6456 fqx(i_end+1, k) = 0.5*(fzm(k)*ru(i_end+1, k, j)+fzp(k)*ru(&
6457 & i_end+1, k-1, j))*(w(i_end+1, k, j)+w(i_end, k, j))
6460 fqxd(i_end+1, k) = 0.5*(((2.-fzm(k-1))*rud(i_end+1, k-1, j)-fzp(&
6461 & k-1)*rud(i_end+1, k-2, j))*(w(i_end+1, k, j)+w(i_end, k, j))+(&
6462 & (2.-fzm(k-1))*ru(i_end+1, k-1, j)-fzp(k-1)*ru(i_end+1, k-2, j)&
6463 & )*(wd(i_end+1, k, j)+wd(i_end, k, j)))
6464 fqx(i_end+1, k) = 0.5*((2.-fzm(k-1))*ru(i_end+1, k-1, j)-fzp(k-1&
6465 & )*ru(i_end+1, k-2, j))*(w(i_end+1, k, j)+w(i_end, k, j))
6467 ! x flux-divergence into tendency
6470 ! see ADT eqn 46 dividing by my, 1st term RHS
6471 mrdx = msftx(i, j)*rdx
6472 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
6474 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(&
6479 ! next -> y flux divergence calculation
6481 IF (ite .GT. ide - 1) THEN
6487 IF (jte .GT. jde - 1) THEN
6492 ! 3rd or 4th order flux has a 5 point stencil, so compute
6493 ! bounds so we can switch to second order flux close to the boundary
6496 IF (degrade_ys) THEN
6498 j_start_f = j_start + 1
6500 IF (degrade_ye) THEN
6504 IF (config_flags%polar) THEN
6505 IF (jte .GT. jde - 1) THEN
6514 DO j=j_start,j_end+1
6515 IF (j .LT. j_start_f .AND. degrade_ys) THEN
6518 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j_start)+fzp(k)*rvd&
6519 & (i, k-1, j_start))*(w(i, k, j_start)+w(i, k, j_start-1))+(&
6520 & fzm(k)*rv(i, k, j_start)+fzp(k)*rv(i, k-1, j_start))*(wd(i&
6521 & , k, j_start)+wd(i, k, j_start-1)))
6522 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j_start)+fzp(k)*rv(i, &
6523 & k-1, j_start))*(w(i, k, j_start)+w(i, k, j_start-1))
6528 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j_start)-fzp&
6529 & (k-1)*rvd(i, k-2, j_start))*(w(i, k, j_start)+w(i, k, &
6530 & j_start-1))+((2.-fzm(k-1))*rv(i, k-1, j_start)-fzp(k-1)*rv(i&
6531 & , k-2, j_start))*(wd(i, k, j_start)+wd(i, k, j_start-1)))
6532 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j_start)-fzp(k-&
6533 & 1)*rv(i, k-2, j_start))*(w(i, k, j_start)+w(i, k, j_start-1)&
6536 ELSE IF (j .GT. j_end_f .AND. degrade_ye) THEN
6539 ! Assumes j>j_end_f is ONLY j_end+1 ...
6540 ! fqy(i, k, jp1) = &
6541 ! 0.5*(fzm(k)*rv(i,k,j_end+1)+fzp(k)*rv(i,k-1,j_end+1)) &
6542 ! *(w(i,k,j_end+1)+w(i,k,j_end))
6543 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-&
6544 & 1, j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k&
6545 & )*rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
6546 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j&
6547 & ))*(w(i, k, j)+w(i, k, j-1))
6552 ! Assumes j>j_end_f is ONLY j_end+1 ...
6553 ! fqy(i, k, jp1) = &
6554 ! 0.5*((2.-fzm(k-1))*rv(i,k-1,j_end+1)-fzp(k-1)*rv(i,k-2,j_end+1)) &
6555 ! *(w(i,k,j_end+1)+w(i,k,j_end))
6556 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
6557 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(&
6558 & i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1&
6560 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(&
6561 & i, k-2, j))*(w(i, k, j)+w(i, k, j-1))
6564 ! 3rd or 4th order flux
6567 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
6568 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
6569 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, &
6570 & k, j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., &
6571 & vel)*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1&
6572 & )))/12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, &
6573 & j+1)-wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
6574 & (wd(i, k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)&
6576 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
6577 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel&
6578 & )*(w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))&
6584 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
6585 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
6586 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
6587 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
6588 & (w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/&
6589 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-&
6590 & wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, &
6591 & k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
6592 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
6593 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(&
6594 & i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
6597 ! y flux-divergence into tendency
6598 ! Comments for polar boundary conditions
6599 ! Same process as for advect_u - tendencies run from jds to jde-1
6600 ! (latitudes are as for u grid, longitudes are displaced)
6601 ! Therefore: flow is only from one side for points next to poles
6602 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
6605 ! see ADT eqn 46 dividing by my, 2nd term RHS
6606 mrdy = msftx(i, j-1)*rdy
6607 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k&
6609 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, &
6613 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
6616 ! see ADT eqn 46 dividing by my, 2nd term RHS
6617 mrdy = msftx(i, j-1)*rdy
6618 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k&
6620 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, &
6624 ELSE IF (j .GT. j_start) THEN
6628 ! see ADT eqn 46 dividing by my, 2nd term RHS
6629 mrdy = msftx(i, j-1)*rdy
6630 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, &
6631 & k, jp1)-fqyd(i, k, jp0))
6632 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
6633 & jp1)-fqy(i, k, jp0))
6641 ELSE IF (horz_order .EQ. 2) THEN
6643 IF (ite .GT. ide - 1) THEN
6649 IF (jte .GT. jde - 1) THEN
6654 IF (.NOT.config_flags%periodic_x) THEN
6655 IF (config_flags%open_xs .OR. specified) THEN
6656 IF (ids + 1 .LT. its) THEN
6662 IF (config_flags%open_xe .OR. specified) THEN
6663 IF (ide - 2 .GT. ite) THEN
6673 ! see ADT eqn 46 dividing by my, 1st term RHS
6674 mrdx = msftx(i, j)*rdx
6675 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.5*((fzm(k)*&
6676 & rud(i+1, k, j)+fzp(k)*rud(i+1, k-1, j))*(w(i+1, k, j)+w(i, k&
6677 & , j))+(fzm(k)*ru(i+1, k, j)+fzp(k)*ru(i+1, k-1, j))*(wd(i+1&
6678 & , k, j)+wd(i, k, j))-(fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1&
6679 & , j))*(w(i, k, j)+w(i-1, k, j))-(fzm(k)*ru(i, k, j)+fzp(k)*&
6680 & ru(i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
6681 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.5*((fzm(k)*ru(i&
6682 & +1, k, j)+fzp(k)*ru(i+1, k-1, j))*(w(i+1, k, j)+w(i, k, j))-&
6683 & (fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*(w(i, k, j)+w(i-1&
6689 ! see ADT eqn 46 dividing by my, 1st term RHS
6690 mrdx = msftx(i, j)*rdx
6691 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*0.5*(((2.-fzm(k-1&
6692 & ))*rud(i+1, k-1, j)-fzp(k-1)*rud(i+1, k-2, j))*(w(i+1, k, j)+w&
6693 & (i, k, j))+((2.-fzm(k-1))*ru(i+1, k-1, j)-fzp(k-1)*ru(i+1, k-2&
6694 & , j))*(wd(i+1, k, j)+wd(i, k, j))-((2.-fzm(k-1))*rud(i, k-1, j&
6695 & )-fzp(k-1)*rud(i, k-2, j))*(w(i, k, j)+w(i-1, k, j))-((2.-fzm(&
6696 & k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-&
6698 tendency(i, k, j) = tendency(i, k, j) - mrdx*0.5*(((2.-fzm(k-1))&
6699 & *ru(i+1, k-1, j)-fzp(k-1)*ru(i+1, k-2, j))*(w(i+1, k, j)+w(i, &
6700 & k, j))-((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, k-2, j))*(w&
6701 & (i, k, j)+w(i-1, k, j)))
6705 IF (ite .GT. ide - 1) THEN
6710 ! Polar boundary conditions are like open or specified
6711 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
6713 IF (jds + 1 .LT. jts) THEN
6719 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
6721 IF (jde - 2 .GT. jte) THEN
6730 ! see ADT eqn 46 dividing by my, 2nd term RHS
6731 mrdy = msftx(i, j)*rdy
6732 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.5*((fzm(k)*&
6733 & rvd(i, k, j+1)+fzp(k)*rvd(i, k-1, j+1))*(w(i, k, j+1)+w(i, k&
6734 & , j))+(fzm(k)*rv(i, k, j+1)+fzp(k)*rv(i, k-1, j+1))*(wd(i, k&
6735 & , j+1)+wd(i, k, j))-(fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-1, &
6736 & j))*(w(i, k, j)+w(i, k, j-1))-(fzm(k)*rv(i, k, j)+fzp(k)*rv(&
6737 & i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
6738 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.5*((fzm(k)*rv(i&
6739 & , k, j+1)+fzp(k)*rv(i, k-1, j+1))*(w(i, k, j+1)+w(i, k, j))-&
6740 & (fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j))*(w(i, k, j)+w(i, k&
6746 ! see ADT eqn 46 dividing by my, 2nd term RHS
6747 mrdy = msftx(i, j)*rdy
6748 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdy*0.5*(((2.-fzm(k-1&
6749 & ))*rvd(i, k-1, j+1)-fzp(k-1)*rvd(i, k-2, j+1))*(w(i, k, j+1)+w&
6750 & (i, k, j))+((2.-fzm(k-1))*rv(i, k-1, j+1)-fzp(k-1)*rv(i, k-2, &
6751 & j+1))*(wd(i, k, j+1)+wd(i, k, j))-((2.-fzm(k-1))*rvd(i, k-1, j&
6752 & )-fzp(k-1)*rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))-((2.-fzm(&
6753 & k-1))*rv(i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i&
6755 tendency(i, k, j) = tendency(i, k, j) - mrdy*0.5*(((2.-fzm(k-1))&
6756 & *rv(i, k-1, j+1)-fzp(k-1)*rv(i, k-2, j+1))*(w(i, k, j+1)+w(i, &
6757 & k, j))-((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(i, k-2, j))*(w&
6758 & (i, k, j)+w(i, k, j-1)))
6761 ! Polar boundary condition ... not covered in above j-loop
6762 IF (config_flags%polar) THEN
6763 IF (jts .EQ. jds) THEN
6766 ! see ADT eqn 46 dividing by my, 2nd term RHS
6767 mrdy = msftx(i, jds)*rdy
6768 tendencyd(i, k, jds) = tendencyd(i, k, jds) - mrdy*0.5*((fzm&
6769 & (k)*rvd(i, k, jds+1)+fzp(k)*rvd(i, k-1, jds+1))*(w(i, k, &
6770 & jds+1)+w(i, k, jds))+(fzm(k)*rv(i, k, jds+1)+fzp(k)*rv(i, &
6771 & k-1, jds+1))*(wd(i, k, jds+1)+wd(i, k, jds)))
6772 tendency(i, k, jds) = tendency(i, k, jds) - mrdy*0.5*((fzm(k&
6773 & )*rv(i, k, jds+1)+fzp(k)*rv(i, k-1, jds+1))*(w(i, k, jds+1&
6779 ! see ADT eqn 46 dividing by my, 2nd term RHS
6780 mrdy = msftx(i, jds)*rdy
6781 tendencyd(i, k, jds) = tendencyd(i, k, jds) - mrdy*0.5*(((2.-&
6782 & fzm(k-1))*rvd(i, k-1, jds+1)-fzp(k-1)*rvd(i, k-2, jds+1))*(w&
6783 & (i, k, jds+1)+w(i, k, jds))+((2.-fzm(k-1))*rv(i, k-1, jds+1)&
6784 & -fzp(k-1)*rv(i, k-2, jds+1))*(wd(i, k, jds+1)+wd(i, k, jds))&
6786 tendency(i, k, jds) = tendency(i, k, jds) - mrdy*0.5*((2.-fzm(&
6787 & k-1))*rv(i, k-1, jds+1)-fzp(k-1)*rv(i, k-2, jds+1))*(w(i, k&
6788 & , jds+1)+w(i, k, jds))
6791 IF (jte .EQ. jde) THEN
6794 ! see ADT eqn 46 dividing by my, 2nd term RHS
6795 mrdy = msftx(i, jde-1)*rdy
6796 tendencyd(i, k, jde-1) = tendencyd(i, k, jde-1) + mrdy*0.5*(&
6797 & (fzm(k)*rvd(i, k, jde-1)+fzp(k)*rvd(i, k-1, jde-1))*(w(i, &
6798 & k, jde-1)+w(i, k, jde-2))+(fzm(k)*rv(i, k, jde-1)+fzp(k)*&
6799 & rv(i, k-1, jde-1))*(wd(i, k, jde-1)+wd(i, k, jde-2)))
6800 tendency(i, k, jde-1) = tendency(i, k, jde-1) + mrdy*0.5*((&
6801 & fzm(k)*rv(i, k, jde-1)+fzp(k)*rv(i, k-1, jde-1))*(w(i, k, &
6802 & jde-1)+w(i, k, jde-2)))
6807 ! see ADT eqn 46 dividing by my, 2nd term RHS
6808 mrdy = msftx(i, jde-1)*rdy
6809 tendencyd(i, k, jde-1) = tendencyd(i, k, jde-1) + mrdy*0.5*(((&
6810 & 2.-fzm(k-1))*rvd(i, k-1, jde-1)-fzp(k-1)*rvd(i, k-2, jde-1))&
6811 & *(w(i, k, jde-1)+w(i, k, jde-2))+((2.-fzm(k-1))*rv(i, k-1, &
6812 & jde-1)-fzp(k-1)*rv(i, k-2, jde-1))*(wd(i, k, jde-1)+wd(i, k&
6814 tendency(i, k, jde-1) = tendency(i, k, jde-1) + mrdy*0.5*((2.-&
6815 & fzm(k-1))*rv(i, k-1, jde-1)-fzp(k-1)*rv(i, k-2, jde-1))*(w(i&
6816 & , k, jde-1)+w(i, k, jde-2))
6820 ELSE IF (horz_order .NE. 0) THEN
6821 ! Just in case we want to turn horizontal advection off, we can do it
6822 WRITE(wrf_err_message, *) ' advect_w_6a, h_order not known ', &
6824 CALL WRF_ERROR_FATAL(wrf_err_message)
6826 ! pick up the the horizontal radiation boundary conditions.
6827 ! (these are the computations that don't require 'cb'.
6828 ! first, set to index ranges
6830 IF (ite .GT. ide - 1) THEN
6836 IF (jte .GT. jde - 1) THEN
6841 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
6844 uwd = 0.5*(fzm(k)*(rud(its, k, j)+rud(its+1, k, j))+fzp(k)*(rud(&
6845 & its, k-1, j)+rud(its+1, k-1, j)))
6846 uw = 0.5*(fzm(k)*(ru(its, k, j)+ru(its+1, k, j))+fzp(k)*(ru(its&
6847 & , k-1, j)+ru(its+1, k-1, j)))
6848 IF (uw .GT. 0.) THEN
6855 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(w_old(&
6856 & its+1, k, j)-w_old(its, k, j))+ub*(w_oldd(its+1, k, j)-w_oldd(&
6857 & its, k, j))+wd(its, k, j)*(fzm(k)*(ru(its+1, k, j)-ru(its, k, &
6858 & j))+fzp(k)*(ru(its+1, k-1, j)-ru(its, k-1, j)))+w(its, k, j)*(&
6859 & fzm(k)*(rud(its+1, k, j)-rud(its, k, j))+fzp(k)*(rud(its+1, k-&
6860 & 1, j)-rud(its, k-1, j))))
6861 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(w_old(its+1&
6862 & , k, j)-w_old(its, k, j))+w(its, k, j)*(fzm(k)*(ru(its+1, k, j&
6863 & )-ru(its, k, j))+fzp(k)*(ru(its+1, k-1, j)-ru(its, k-1, j))))
6868 uwd = 0.5*((2.-fzm(k-1))*(rud(its, k-1, j)+rud(its+1, k-1, j))-fzp&
6869 & (k-1)*(rud(its, k-2, j)+rud(its+1, k-2, j)))
6870 uw = 0.5*((2.-fzm(k-1))*(ru(its, k-1, j)+ru(its+1, k-1, j))-fzp(k-&
6871 & 1)*(ru(its, k-2, j)+ru(its+1, k-2, j)))
6872 IF (uw .GT. 0.) THEN
6879 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(w_old(its+&
6880 & 1, k, j)-w_old(its, k, j))+ub*(w_oldd(its+1, k, j)-w_oldd(its, k&
6881 & , j))+wd(its, k, j)*((2.-fzm(k-1))*(ru(its+1, k-1, j)-ru(its, k-&
6882 & 1, j))-fzp(k-1)*(ru(its+1, k-2, j)-ru(its, k-2, j)))+w(its, k, j&
6883 & )*((2.-fzm(k-1))*(rud(its+1, k-1, j)-rud(its, k-1, j))-fzp(k-1)*&
6884 & (rud(its+1, k-2, j)-rud(its, k-2, j))))
6885 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(w_old(its+1, &
6886 & k, j)-w_old(its, k, j))+w(its, k, j)*((2.-fzm(k-1))*(ru(its+1, k&
6887 & -1, j)-ru(its, k-1, j))-fzp(k-1)*(ru(its+1, k-2, j)-ru(its, k-2&
6891 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
6894 uwd = 0.5*(fzm(k)*(rud(ite-1, k, j)+rud(ite, k, j))+fzp(k)*(rud(&
6895 & ite-1, k-1, j)+rud(ite, k-1, j)))
6896 uw = 0.5*(fzm(k)*(ru(ite-1, k, j)+ru(ite, k, j))+fzp(k)*(ru(ite-&
6897 & 1, k-1, j)+ru(ite, k-1, j)))
6898 IF (uw .LT. 0.) THEN
6905 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
6906 & w_old(i_end, k, j)-w_old(i_end-1, k, j))+ub*(w_oldd(i_end, k, &
6907 & j)-w_oldd(i_end-1, k, j))+wd(i_end, k, j)*(fzm(k)*(ru(ite, k, &
6908 & j)-ru(ite-1, k, j))+fzp(k)*(ru(ite, k-1, j)-ru(ite-1, k-1, j))&
6909 & )+w(i_end, k, j)*(fzm(k)*(rud(ite, k, j)-rud(ite-1, k, j))+fzp&
6910 & (k)*(rud(ite, k-1, j)-rud(ite-1, k-1, j))))
6911 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(w_old(&
6912 & i_end, k, j)-w_old(i_end-1, k, j))+w(i_end, k, j)*(fzm(k)*(ru(&
6913 & ite, k, j)-ru(ite-1, k, j))+fzp(k)*(ru(ite, k-1, j)-ru(ite-1, &
6919 uwd = 0.5*((2.-fzm(k-1))*(rud(ite-1, k-1, j)+rud(ite, k-1, j))-fzp&
6920 & (k-1)*(rud(ite-1, k-2, j)+rud(ite, k-2, j)))
6921 uw = 0.5*((2.-fzm(k-1))*(ru(ite-1, k-1, j)+ru(ite, k-1, j))-fzp(k-&
6922 & 1)*(ru(ite-1, k-2, j)+ru(ite, k-2, j)))
6923 IF (uw .LT. 0.) THEN
6930 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(w_old(&
6931 & i_end, k, j)-w_old(i_end-1, k, j))+ub*(w_oldd(i_end, k, j)-&
6932 & w_oldd(i_end-1, k, j))+wd(i_end, k, j)*((2.-fzm(k-1))*(ru(ite, k&
6933 & -1, j)-ru(ite-1, k-1, j))-fzp(k-1)*(ru(ite, k-2, j)-ru(ite-1, k-&
6934 & 2, j)))+w(i_end, k, j)*((2.-fzm(k-1))*(rud(ite, k-1, j)-rud(ite-&
6935 & 1, k-1, j))-fzp(k-1)*(rud(ite, k-2, j)-rud(ite-1, k-2, j))))
6936 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(w_old(&
6937 & i_end, k, j)-w_old(i_end-1, k, j))+w(i_end, k, j)*((2.-fzm(k-1))&
6938 & *(ru(ite, k-1, j)-ru(ite-1, k-1, j))-fzp(k-1)*(ru(ite, k-2, j)-&
6939 & ru(ite-1, k-2, j))))
6942 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
6945 vwd = 0.5*(fzm(k)*(rvd(i, k, jts)+rvd(i, k, jts+1))+fzp(k)*(rvd(&
6946 & i, k-1, jts)+rvd(i, k-1, jts+1)))
6947 vw = 0.5*(fzm(k)*(rv(i, k, jts)+rv(i, k, jts+1))+fzp(k)*(rv(i, k&
6948 & -1, jts)+rv(i, k-1, jts+1)))
6949 IF (vw .GT. 0.) THEN
6956 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(w_old(i&
6957 & , k, jts+1)-w_old(i, k, jts))+vb*(w_oldd(i, k, jts+1)-w_oldd(i&
6958 & , k, jts))+wd(i, k, jts)*(fzm(k)*(rv(i, k, jts+1)-rv(i, k, jts&
6959 & ))+fzp(k)*(rv(i, k-1, jts+1)-rv(i, k-1, jts)))+w(i, k, jts)*(&
6960 & fzm(k)*(rvd(i, k, jts+1)-rvd(i, k, jts))+fzp(k)*(rvd(i, k-1, &
6961 & jts+1)-rvd(i, k-1, jts))))
6962 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(w_old(i, k&
6963 & , jts+1)-w_old(i, k, jts))+w(i, k, jts)*(fzm(k)*(rv(i, k, jts+&
6964 & 1)-rv(i, k, jts))+fzp(k)*(rv(i, k-1, jts+1)-rv(i, k-1, jts))))
6969 vwd = 0.5*((2.-fzm(k-1))*(rvd(i, k-1, jts)+rvd(i, k-1, jts+1))-fzp&
6970 & (k-1)*(rvd(i, k-2, jts)+rvd(i, k-2, jts+1)))
6971 vw = 0.5*((2.-fzm(k-1))*(rv(i, k-1, jts)+rv(i, k-1, jts+1))-fzp(k-&
6972 & 1)*(rv(i, k-2, jts)+rv(i, k-2, jts+1)))
6973 IF (vw .GT. 0.) THEN
6980 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(w_old(i, k&
6981 & , jts+1)-w_old(i, k, jts))+vb*(w_oldd(i, k, jts+1)-w_oldd(i, k, &
6982 & jts))+wd(i, k, jts)*((2.-fzm(k-1))*(rv(i, k-1, jts+1)-rv(i, k-1&
6983 & , jts))-fzp(k-1)*(rv(i, k-2, jts+1)-rv(i, k-2, jts)))+w(i, k, &
6984 & jts)*((2.-fzm(k-1))*(rvd(i, k-1, jts+1)-rvd(i, k-1, jts))-fzp(k-&
6985 & 1)*(rvd(i, k-2, jts+1)-rvd(i, k-2, jts))))
6986 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(w_old(i, k, &
6987 & jts+1)-w_old(i, k, jts))+w(i, k, jts)*((2.-fzm(k-1))*(rv(i, k-1&
6988 & , jts+1)-rv(i, k-1, jts))-fzp(k-1)*(rv(i, k-2, jts+1)-rv(i, k-2&
6992 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
6995 vwd = 0.5*(fzm(k)*(rvd(i, k, jte-1)+rvd(i, k, jte))+fzp(k)*(rvd(&
6996 & i, k-1, jte-1)+rvd(i, k-1, jte)))
6997 vw = 0.5*(fzm(k)*(rv(i, k, jte-1)+rv(i, k, jte))+fzp(k)*(rv(i, k&
6998 & -1, jte-1)+rv(i, k-1, jte)))
6999 IF (vw .LT. 0.) THEN
7006 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
7007 & w_old(i, k, j_end)-w_old(i, k, j_end-1))+vb*(w_oldd(i, k, &
7008 & j_end)-w_oldd(i, k, j_end-1))+wd(i, k, j_end)*(fzm(k)*(rv(i, k&
7009 & , jte)-rv(i, k, jte-1))+fzp(k)*(rv(i, k-1, jte)-rv(i, k-1, jte&
7010 & -1)))+w(i, k, j_end)*(fzm(k)*(rvd(i, k, jte)-rvd(i, k, jte-1))&
7011 & +fzp(k)*(rvd(i, k-1, jte)-rvd(i, k-1, jte-1))))
7012 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(w_old(i&
7013 & , k, j_end)-w_old(i, k, j_end-1))+w(i, k, j_end)*(fzm(k)*(rv(i&
7014 & , k, jte)-rv(i, k, jte-1))+fzp(k)*(rv(i, k-1, jte)-rv(i, k-1, &
7020 vwd = 0.5*((2.-fzm(k-1))*(rvd(i, k-1, jte-1)+rvd(i, k-1, jte))-fzp&
7021 & (k-1)*(rvd(i, k-2, jte-1)+rvd(i, k-2, jte)))
7022 vw = 0.5*((2.-fzm(k-1))*(rv(i, k-1, jte-1)+rv(i, k-1, jte))-fzp(k-&
7023 & 1)*(rv(i, k-2, jte-1)+rv(i, k-2, jte)))
7024 IF (vw .LT. 0.) THEN
7031 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(w_old(&
7032 & i, k, j_end)-w_old(i, k, j_end-1))+vb*(w_oldd(i, k, j_end)-&
7033 & w_oldd(i, k, j_end-1))+wd(i, k, j_end)*((2.-fzm(k-1))*(rv(i, k-1&
7034 & , jte)-rv(i, k-1, jte-1))-fzp(k-1)*(rv(i, k-2, jte)-rv(i, k-2, &
7035 & jte-1)))+w(i, k, j_end)*((2.-fzm(k-1))*(rvd(i, k-1, jte)-rvd(i, &
7036 & k-1, jte-1))-fzp(k-1)*(rvd(i, k-2, jte)-rvd(i, k-2, jte-1))))
7037 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(w_old(i, &
7038 & k, j_end)-w_old(i, k, j_end-1))+w(i, k, j_end)*((2.-fzm(k-1))*(&
7039 & rv(i, k-1, jte)-rv(i, k-1, jte-1))-fzp(k-1)*(rv(i, k-2, jte)-rv(&
7043 !-------------------- vertical advection
7044 ! ADT eqn 46 has 3rd term on RHS (dividing through by my) = - partial d/dz (w rho w /my)
7045 ! Here we have: - partial d/dz (w*rom) = - partial d/dz (w rho w / my)
7046 ! Therefore we don't need to make a correction for advect_w
7048 IF (ite .GT. ide - 1) THEN
7054 IF (jte .GT. jde - 1) THEN
7060 vfluxd(i, kts) = 0.0
7062 vfluxd(i, kte) = 0.0
7065 IF (vert_order .EQ. 6) THEN
7070 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7071 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7072 vfluxd(i, k) = veld*(37.*(w(i, k, j)+w(i, k-1, j))-8.*(w(i, k+&
7073 & 1, j)+w(i, k-2, j))+(w(i, k+2, j)+w(i, k-3, j)))/60.0 + vel*&
7074 & (37.*(wd(i, k, j)+wd(i, k-1, j))-8.*(wd(i, k+1, j)+wd(i, k-2&
7075 & , j))+wd(i, k+2, j)+wd(i, k-3, j))/60.0
7076 vflux(i, k) = vel*((37.*(w(i, k, j)+w(i, k-1, j))-8.*(w(i, k+1&
7077 & , j)+w(i, k-2, j))+(w(i, k+2, j)+w(i, k-3, j)))/60.0)
7082 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7083 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7085 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7088 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7089 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7090 vfluxd(i, k) = veld*(7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+&
7091 & w(i, k-2, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k-1, j))-wd(i&
7092 & , k+1, j)-wd(i, k-2, j))/12.0
7093 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
7094 & (i, k-2, j)))/12.0)
7096 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7097 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7098 vfluxd(i, k) = veld*(7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+&
7099 & w(i, k-2, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k-1, j))-wd(i&
7100 & , k+1, j)-wd(i, k-2, j))/12.0
7101 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
7102 & (i, k-2, j)))/12.0)
7104 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7105 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7107 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7112 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k&
7114 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)&
7118 ! pick up flux contribution for w at the lid. wcs, 13 march 2004
7121 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i&
7123 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
7126 ELSE IF (vert_order .EQ. 5) THEN
7131 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7132 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7133 vfluxd(i, k) = veld*((37.*(w(i, k, j)+w(i, k-1, j))-8.*(w(i, k&
7134 & +1, j)+w(i, k-2, j))+(w(i, k+2, j)+w(i, k-3, j)))/60.0-SIGN(&
7135 & 1, time_step)*SIGN(1., -vel)*(w(i, k+2, j)-w(i, k-3, j)-5.*(&
7136 & w(i, k+1, j)-w(i, k-2, j))+10.*(w(i, k, j)-w(i, k-1, j)))/&
7137 & 60.0) + vel*((37.*(wd(i, k, j)+wd(i, k-1, j))-8.*(wd(i, k+1&
7138 & , j)+wd(i, k-2, j))+wd(i, k+2, j)+wd(i, k-3, j))/60.0-SIGN(1&
7139 & , time_step)*SIGN(1., -vel)*(wd(i, k+2, j)-wd(i, k-3, j)-5.*&
7140 & (wd(i, k+1, j)-wd(i, k-2, j))+10.*(wd(i, k, j)-wd(i, k-1, j)&
7142 vflux(i, k) = vel*((37.*(w(i, k, j)+w(i, k-1, j))-8.*(w(i, k+1&
7143 & , j)+w(i, k-2, j))+(w(i, k+2, j)+w(i, k-3, j)))/60.0-SIGN(1&
7144 & , time_step)*SIGN(1., -vel)*(w(i, k+2, j)-w(i, k-3, j)-5.*(w&
7145 & (i, k+1, j)-w(i, k-2, j))+10.*(w(i, k, j)-w(i, k-1, j)))/&
7151 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7152 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7154 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7157 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7158 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7159 vfluxd(i, k) = veld*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)&
7160 & +w(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k&
7161 & +1, j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0) + vel*&
7162 & ((7.*(wd(i, k, j)+wd(i, k-1, j))-wd(i, k+1, j)-wd(i, k-2, j))/&
7163 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(wd(i, k+1, j)-wd(i, k-&
7164 & 2, j)-3.*(wd(i, k, j)-wd(i, k-1, j)))/12.0)
7165 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
7166 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1&
7167 & , j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0)
7169 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7170 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7171 vfluxd(i, k) = veld*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)&
7172 & +w(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k&
7173 & +1, j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0) + vel*&
7174 & ((7.*(wd(i, k, j)+wd(i, k-1, j))-wd(i, k+1, j)-wd(i, k-2, j))/&
7175 & 12.0+SIGN(1, time_step)*SIGN(1., -vel)*(wd(i, k+1, j)-wd(i, k-&
7176 & 2, j)-3.*(wd(i, k, j)-wd(i, k-1, j)))/12.0)
7177 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
7178 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1&
7179 & , j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0)
7181 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7182 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7184 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7189 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k&
7191 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)&
7195 ! pick up flux contribution for w at the lid, wcs. 13 march 2004
7198 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i&
7200 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
7203 ELSE IF (vert_order .EQ. 4) THEN
7208 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7209 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7210 vfluxd(i, k) = veld*(7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j&
7211 & )+w(i, k-2, j)))/12.0 + vel*(7.*(wd(i, k, j)+wd(i, k-1, j))-&
7212 & wd(i, k+1, j)-wd(i, k-2, j))/12.0
7213 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)&
7214 & +w(i, k-2, j)))/12.0)
7219 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7220 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7222 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7225 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7226 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7228 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7233 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k&
7235 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)&
7239 ! pick up flux contribution for w at the lid, wcs. 13 march 2004
7242 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i&
7244 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
7247 ELSE IF (vert_order .EQ. 3) THEN
7252 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
7253 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
7254 vfluxd(i, k) = veld*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, &
7255 & j)+w(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(&
7256 & i, k+1, j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0) &
7257 & + vel*((7.*(wd(i, k, j)+wd(i, k-1, j))-wd(i, k+1, j)-wd(i, k&
7258 & -2, j))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(wd(i, k+1, j&
7259 & )-wd(i, k-2, j)-3.*(wd(i, k, j)-wd(i, k-1, j)))/12.0)
7260 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)&
7261 & +w(i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i&
7262 & , k+1, j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0)
7267 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7268 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7270 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7273 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)&
7274 & +w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i&
7276 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i&
7281 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k&
7283 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)&
7287 ! pick up flux contribution for w at the lid, wcs. 13 march 2004
7290 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i&
7292 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
7295 ELSE IF (vert_order .EQ. 2) THEN
7300 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, &
7301 & j)+w(i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+&
7303 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w&
7309 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k&
7311 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)&
7315 ! pick up flux contribution for w at the lid, wcs. 13 march 2004
7318 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i&
7320 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
7324 WRITE(wrf_err_message, *) ' advect_w, v_order not known ', &
7326 CALL WRF_ERROR_FATAL(wrf_err_message)
7328 END SUBROUTINE G_ADVECT_W
7330 ! Generated by TAPENADE (INRIA, Tropics team)
7331 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
7333 ! Differentiation of advect_scalar_pd in forward (tangent) mode:
7334 ! variations of useful results: tendency h_tendency z_tendency
7335 ! with respect to varying inputs: rom field tendency h_tendency
7336 ! z_tendency ru rv mu_old field_old mut
7337 ! RW status of diff variables: rom:in field:in tendency:in-out
7338 ! h_tendency:in-out z_tendency:in-out ru:in rv:in
7339 ! mu_old:in field_old:in mut:in
7340 SUBROUTINE G_ADVECT_SCALAR_PD(field, fieldd, field_old, field_oldd, &
7341 & tendency, tendencyd, h_tendency, h_tendencyd, z_tendency, z_tendencyd&
7342 & , ru, rud, rv, rvd, rom, romd, mut, mutd, mub, mu_old, mu_oldd, &
7343 & time_step, config_flags, tenddec, msfux, msfuy, msfvx, msfvy, msftx, &
7344 & msfty, fzm, fzp, rdx, rdy, rdzw, dt, ids, ide, jds, jde, kds, kde, ims&
7345 & , ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
7348 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
7350 LOGICAL, INTENT(IN) :: tenddec
7351 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
7352 & jme, kms, kme, its, ite, jts, jte, kts, kte
7353 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: field, &
7354 & field_old, ru, rv, rom
7355 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: fieldd, &
7356 & field_oldd, rud, rvd, romd
7357 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut, mub, mu_old
7358 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd, mu_oldd
7359 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
7360 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
7361 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(OUT) :: h_tendency&
7363 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(OUT) :: h_tendencyd&
7365 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
7366 & msfvy, msftx, msfty
7367 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
7368 REAL, INTENT(IN) :: rdx, rdy, dt
7369 INTEGER, INTENT(IN) :: time_step
7371 INTEGER :: i, j, k, itf, jtf, ktf
7372 INTEGER :: i_start, i_end, j_start, j_end
7373 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
7374 INTEGER :: jmin, jmax, jp, jm, imin, imax
7375 REAL :: mrdx, mrdy, ub, vb, uw, vw, mu
7376 REAL :: ubd, vbd, mud
7377 ! storage for high and low order fluxes
7378 REAL, DIMENSION(its - 1:ite + 2, kts:kte, jts - 1:jte + 2) :: fqx, fqy&
7380 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: fqxd, fqyd, fqzd
7381 REAL, DIMENSION(its - 1:ite + 2, kts:kte, jts - 1:jte + 2) :: fqxl, &
7383 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: fqxld, fqyld, &
7385 INTEGER :: horz_order, vert_order
7386 LOGICAL :: degrade_xs, degrade_ys
7387 LOGICAL :: degrade_xe, degrade_ye
7388 INTEGER :: jp1, jp0, jtmp
7389 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: flux_out, ph_low
7390 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: flux_outd, ph_lowd
7393 REAL, PARAMETER :: eps=1.e-20
7394 ! definition of flux operators, 3rd, 4th, 5th or 6th order
7395 REAL :: flux3, flux4, flux5, flux6, flux_upwind
7396 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel, cr
7398 ! flux_upwind(q_im1, q_i, cr ) = 0.5*(1.+sign(1.,cr))*q_im1 &
7399 ! +0.5*(1.-sign(1.,cr))*q_i
7400 ! flux_upwind(q_im1, q_i, cr ) = 0.
7402 LOGICAL, PARAMETER :: pd_limit=.true.
8054 ! set order for the advection schemes
8055 ! write(6,*) ' in pd advection routine '
8056 ! Empty arrays just in case:
8057 IF (config_flags%polar) THEN
8065 IF (kte .GT. kde - 1) THEN
8070 horz_order = config_flags%h_sca_adv_order
8071 vert_order = config_flags%v_sca_adv_order
8072 ! determine boundary mods for flux operators
8073 ! We degrade the flux operators from 3rd/4th order
8074 ! to second order one gridpoint in from the boundaries for
8075 ! all boundary conditions except periodic and symmetry - these
8076 ! conditions have boundary zone data fill for correct application
8077 ! of the higher order flux stencils
8082 ! begin with horizontal flux divergence
8083 ! here is the choice of flux operators
8084 IF (horz_order .EQ. 6) THEN
8085 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
8086 & its .GT. ids + 3) degrade_xs = .false.
8087 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
8088 & ite .LT. ide - 4) degrade_xe = .false.
8089 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
8090 & jts .GT. jds + 3) degrade_ys = .false.
8091 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
8092 & jte .LT. jde - 4) degrade_ye = .false.
8093 IF (kte .GT. kde - 1) THEN
8099 IF (ite .GT. ide - 1) THEN
8106 IF (jte .GT. jde - 1) THEN
8114 !-- modify loop bounds if open or specified
8115 ! IF(degrade_xs) i_start = MAX(its-1,ids-1)
8116 ! IF(degrade_xe) i_end = MIN(ite+1,ide-2)
8117 IF (degrade_xs) THEN
8118 IF (its - 1 .LT. ids) THEN
8124 IF (degrade_xe) THEN
8125 IF (ite + 1 .GT. ide - 1) THEN
8131 IF (degrade_ys) THEN
8132 IF (jts - 1 .LT. jds + 1) THEN
8139 IF (degrade_ye) THEN
8140 IF (jte + 1 .GT. jde - 2) THEN
8152 ! compute fluxes, 6th order
8153 j_loop_y_flux_6:DO j=j_start,j_end+1
8154 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
8159 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8160 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8161 mu = 0.5*(mut(i, j)+mut(i, j-1))
8164 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8166 IF (cr .GE. 0.) THEN
8175 IF (1.0 .GT. y1) THEN
8182 IF (cr .GE. 0.) THEN
8191 IF (-1.0 .LT. y52) THEN
8198 fqyld(i, k, j) = dy*(mud*(0.5*min3*field_old(i, k, j-1)+0.5*&
8199 & max2*field_old(i, k, j))+mu*(0.5*(min3d*field_old(i, k, j-&
8200 & 1)+min3*field_oldd(i, k, j-1))+0.5*(max2d*field_old(i, k, &
8201 & j)+max2*field_oldd(i, k, j))))/dt
8202 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min3*field_old(i, k, j-1)+&
8203 & 0.5*max2*field_old(i, k, j))
8204 fqyd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i, k, j-&
8205 & 1))-2./15.*(field(i, k, j+1)+field(i, k, j-2))+1./60.*(&
8206 & field(i, k, j+2)+field(i, k, j-3))) + vel*(37.*(fieldd(i, &
8207 & k, j)+fieldd(i, k, j-1))/60.-2.*(fieldd(i, k, j+1)+fieldd(&
8208 & i, k, j-2))/15.+(fieldd(i, k, j+2)+fieldd(i, k, j-3))/60.)
8209 fqy(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i, k, j-1)&
8210 & )-2./15.*(field(i, k, j+1)+field(i, k, j-2))+1./60.*(field&
8211 & (i, k, j+2)+field(i, k, j-3)))
8212 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8213 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8216 ELSE IF (j .EQ. jds + 1) THEN
8217 ! 2nd order flux next to south boundary
8221 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8222 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8223 mu = 0.5*(mut(i, j)+mut(i, j-1))
8226 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8228 IF (cr .GE. 0.) THEN
8237 IF (1.0 .GT. y2) THEN
8244 IF (cr .GE. 0.) THEN
8253 IF (-1.0 .LT. y53) THEN
8260 fqyld(i, k, j) = dy*(mud*(0.5*min4*field_old(i, k, j-1)+0.5*&
8261 & max3*field_old(i, k, j))+mu*(0.5*(min4d*field_old(i, k, j-&
8262 & 1)+min4*field_oldd(i, k, j-1))+0.5*(max3d*field_old(i, k, &
8263 & j)+max3*field_oldd(i, k, j))))/dt
8264 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min4*field_old(i, k, j-1)+&
8265 & 0.5*max3*field_old(i, k, j))
8266 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
8267 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
8268 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
8270 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8271 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8274 ELSE IF (j .EQ. jds + 2) THEN
8275 ! third of 4th order flux 2 in from south boundary
8279 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8280 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8281 mu = 0.5*(mut(i, j)+mut(i, j-1))
8284 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8286 IF (cr .GE. 0.) THEN
8295 IF (1.0 .GT. y3) THEN
8302 IF (cr .GE. 0.) THEN
8311 IF (-1.0 .LT. y54) THEN
8318 fqyld(i, k, j) = dy*(mud*(0.5*min5*field_old(i, k, j-1)+0.5*&
8319 & max4*field_old(i, k, j))+mu*(0.5*(min5d*field_old(i, k, j-&
8320 & 1)+min5*field_oldd(i, k, j-1))+0.5*(max4d*field_old(i, k, &
8321 & j)+max4*field_oldd(i, k, j))))/dt
8322 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min5*field_old(i, k, j-1)+&
8323 & 0.5*max4*field_old(i, k, j))
8324 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
8325 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))) + vel*(7.*(&
8326 & fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+&
8327 & fieldd(i, k, j-2))/12.)
8328 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
8329 & -1./12.*(field(i, k, j+1)+field(i, k, j-2)))
8330 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8331 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8334 ELSE IF (j .EQ. jde - 1) THEN
8335 ! 2nd order flux next to north boundary
8339 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8340 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8341 mu = 0.5*(mut(i, j)+mut(i, j-1))
8344 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8346 IF (cr .GE. 0.) THEN
8355 IF (1.0 .GT. y4) THEN
8362 IF (cr .GE. 0.) THEN
8371 IF (-1.0 .LT. y55) THEN
8378 fqyld(i, k, j) = dy*(mud*(0.5*min6*field_old(i, k, j-1)+0.5*&
8379 & max5*field_old(i, k, j))+mu*(0.5*(min6d*field_old(i, k, j-&
8380 & 1)+min6*field_oldd(i, k, j-1))+0.5*(max5d*field_old(i, k, &
8381 & j)+max5*field_oldd(i, k, j))))/dt
8382 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min6*field_old(i, k, j-1)+&
8383 & 0.5*max5*field_old(i, k, j))
8384 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
8385 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
8386 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
8388 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8389 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8392 ELSE IF (j .EQ. jde - 2) THEN
8393 ! 3rd or 4th order flux 2 in from north boundary
8397 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8398 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8399 mu = 0.5*(mut(i, j)+mut(i, j-1))
8402 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8404 IF (cr .GE. 0.) THEN
8413 IF (1.0 .GT. y5) THEN
8420 IF (cr .GE. 0.) THEN
8429 IF (-1.0 .LT. y56) THEN
8436 fqyld(i, k, j) = dy*(mud*(0.5*min7*field_old(i, k, j-1)+0.5*&
8437 & max6*field_old(i, k, j))+mu*(0.5*(min7d*field_old(i, k, j-&
8438 & 1)+min7*field_oldd(i, k, j-1))+0.5*(max6d*field_old(i, k, &
8439 & j)+max6*field_oldd(i, k, j))))/dt
8440 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min7*field_old(i, k, j-1)+&
8441 & 0.5*max6*field_old(i, k, j))
8442 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
8443 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))) + vel*(7.*(&
8444 & fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+&
8445 & fieldd(i, k, j-2))/12.)
8446 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
8447 & -1./12.*(field(i, k, j+1)+field(i, k, j-2)))
8448 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8449 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8453 END DO j_loop_y_flux_6
8455 !-- these bounds are for periodic and sym conditions
8457 IF (ite .GT. ide - 1) THEN
8466 IF (jte .GT. jde - 1) THEN
8472 !-- modify loop bounds for open and specified b.c
8473 ! IF(degrade_ys) j_start = MAX(jts-1,jds+1)
8474 ! IF(degrade_ye) j_end = MIN(jte+1,jde-2)
8475 IF (degrade_ys) THEN
8476 IF (jts - 1 .LT. jds) THEN
8482 IF (degrade_ye) THEN
8483 IF (jte + 1 .GT. jde - 1) THEN
8489 IF (degrade_xs) THEN
8490 IF (ids + 1 .LT. its - 1) THEN
8497 IF (degrade_xe) THEN
8498 IF (ide - 2 .GT. ite + 1) THEN
8514 DO i=i_start_f,i_end_f
8516 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
8517 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
8518 mu = 0.5*(mut(i, j)+mut(i-1, j))
8521 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
8523 IF (cr .GE. 0.) THEN
8532 IF (1.0 .GT. y6) THEN
8539 IF (cr .GE. 0.) THEN
8548 IF (-1.0 .LT. y57) THEN
8555 fqxld(i, k, j) = dx*(mud*(0.5*min10*field_old(i-1, k, j)+0.5*&
8556 & max7*field_old(i, k, j))+mu*(0.5*(min10d*field_old(i-1, k, j&
8557 & )+min10*field_oldd(i-1, k, j))+0.5*(max7d*field_old(i, k, j)&
8558 & +max7*field_oldd(i, k, j))))/dt
8559 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min10*field_old(i-1, k, j)+0.5&
8560 & *max7*field_old(i, k, j))
8561 fqxd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i-1, k, j)&
8562 & )-2./15.*(field(i+1, k, j)+field(i-2, k, j))+1./60.*(field(i&
8563 & +2, k, j)+field(i-3, k, j))) + vel*(37.*(fieldd(i, k, j)+&
8564 & fieldd(i-1, k, j))/60.-2.*(fieldd(i+1, k, j)+fieldd(i-2, k, &
8565 & j))/15.+(fieldd(i+2, k, j)+fieldd(i-3, k, j))/60.)
8566 fqx(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i-1, k, j))-&
8567 & 2./15.*(field(i+1, k, j)+field(i-2, k, j))+1./60.*(field(i+2&
8568 & , k, j)+field(i-3, k, j)))
8569 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
8570 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
8573 ! lower order fluxes close to boundaries (if not periodic or symmetric)
8574 IF (degrade_xs) THEN
8575 DO i=i_start,i_start_f-1
8576 IF (i .EQ. ids + 1) THEN
8580 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
8581 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
8582 mu = 0.5*(mut(i, j)+mut(i-1, j))
8583 veld = (rud(i, k, j)*mu-ru(i, k, j)*mud)/mu**2
8584 vel = ru(i, k, j)/mu
8587 IF (cr .GE. 0.) THEN
8596 IF (1.0 .GT. y7) THEN
8603 IF (cr .GE. 0.) THEN
8612 IF (-1.0 .LT. y58) THEN
8619 fqxld(i, k, j) = dx*(mud*(0.5*min11*field_old(i-1, k, j)+&
8620 & 0.5*max8*field_old(i, k, j))+mu*(0.5*(min11d*field_old(i&
8621 & -1, k, j)+min11*field_oldd(i-1, k, j))+0.5*(max8d*&
8622 & field_old(i, k, j)+max8*field_oldd(i, k, j))))/dt
8623 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min11*field_old(i-1, k, j)&
8624 & +0.5*max8*field_old(i, k, j))
8625 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-&
8626 & 1, k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)&
8628 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, &
8630 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
8631 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
8634 IF (i .EQ. ids + 2) THEN
8638 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
8639 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
8640 mu = 0.5*(mut(i, j)+mut(i-1, j))
8643 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
8645 IF (cr .GE. 0.) THEN
8654 IF (1.0 .GT. y8) THEN
8661 IF (cr .GE. 0.) THEN
8670 IF (-1.0 .LT. y59) THEN
8677 fqxld(i, k, j) = dx*(mud*(0.5*min12*field_old(i-1, k, j)+&
8678 & 0.5*max9*field_old(i, k, j))+mu*(0.5*(min12d*field_old(i&
8679 & -1, k, j)+min12*field_oldd(i-1, k, j))+0.5*(max9d*&
8680 & field_old(i, k, j)+max9*field_oldd(i, k, j))))/dt
8681 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min12*field_old(i-1, k, j)&
8682 & +0.5*max9*field_old(i, k, j))
8683 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k&
8684 & , j))-1./12.*(field(i+1, k, j)+field(i-2, k, j))) + vel*&
8685 & (7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1&
8686 & , k, j)+fieldd(i-2, k, j))/12.)
8687 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j&
8688 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j)))
8689 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
8690 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
8695 IF (degrade_xe) THEN
8696 DO i=i_end_f+1,i_end+1
8697 IF (i .EQ. ide - 1) THEN
8698 ! second order flux next to the boundary
8701 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
8702 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
8703 mu = 0.5*(mut(i, j)+mut(i-1, j))
8706 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
8708 IF (cr .GE. 0.) THEN
8717 IF (1.0 .GT. y9) THEN
8724 IF (cr .GE. 0.) THEN
8733 IF (-1.0 .LT. y60) THEN
8740 fqxld(i, k, j) = dx*(mud*(0.5*min13*field_old(i-1, k, j)+&
8741 & 0.5*max10*field_old(i, k, j))+mu*(0.5*(min13d*field_old(&
8742 & i-1, k, j)+min13*field_oldd(i-1, k, j))+0.5*(max10d*&
8743 & field_old(i, k, j)+max10*field_oldd(i, k, j))))/dt
8744 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min13*field_old(i-1, k, j)&
8745 & +0.5*max10*field_old(i, k, j))
8746 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-&
8747 & 1, k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)&
8749 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, &
8751 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
8752 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
8755 IF (i .EQ. ide - 2) THEN
8756 ! fourth order flux one in from the boundary
8759 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
8760 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
8761 mu = 0.5*(mut(i, j)+mut(i-1, j))
8764 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
8766 IF (cr .GE. 0.) THEN
8775 IF (1.0 .GT. y10) THEN
8782 IF (cr .GE. 0.) THEN
8791 IF (-1.0 .LT. y61) THEN
8798 fqxld(i, k, j) = dx*(mud*(0.5*min14*field_old(i-1, k, j)+&
8799 & 0.5*max11*field_old(i, k, j))+mu*(0.5*(min14d*field_old(&
8800 & i-1, k, j)+min14*field_oldd(i-1, k, j))+0.5*(max11d*&
8801 & field_old(i, k, j)+max11*field_oldd(i, k, j))))/dt
8802 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min14*field_old(i-1, k, j)&
8803 & +0.5*max11*field_old(i, k, j))
8804 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k&
8805 & , j))-1./12.*(field(i+1, k, j)+field(i-2, k, j))) + vel*&
8806 & (7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1&
8807 & , k, j)+fieldd(i-2, k, j))/12.)
8808 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j&
8809 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j)))
8810 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
8811 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
8817 ELSE IF (horz_order .EQ. 5) THEN
8818 ! enddo for outer J loop
8819 !--- end of 6th order horizontal flux calculation
8820 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
8821 & its .GT. ids + 3) degrade_xs = .false.
8822 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
8823 & ite .LT. ide - 4) degrade_xe = .false.
8824 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
8825 & jts .GT. jds + 3) degrade_ys = .false.
8826 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
8827 & jte .LT. jde - 4) degrade_ye = .false.
8828 IF (kte .GT. kde - 1) THEN
8834 IF (ite .GT. ide - 1) THEN
8841 IF (jte .GT. jde - 1) THEN
8849 !-- modify loop bounds if open or specified
8850 ! IF(degrade_xs) i_start = MAX(its-1,ids-1)
8851 ! IF(degrade_xe) i_end = MIN(ite+1,ide-2)
8852 IF (degrade_xs) THEN
8853 IF (its - 1 .LT. ids) THEN
8859 IF (degrade_xe) THEN
8860 IF (ite + 1 .GT. ide - 1) THEN
8866 IF (degrade_ys) THEN
8867 IF (jts - 1 .LT. jds + 1) THEN
8874 IF (degrade_ye) THEN
8875 IF (jte + 1 .GT. jde - 2) THEN
8887 ! compute fluxes, 5th order
8888 j_loop_y_flux_5:DO j=j_start,j_end+1
8889 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
8894 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8895 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8896 mu = 0.5*(mut(i, j)+mut(i, j-1))
8899 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8901 IF (cr .GE. 0.) THEN
8910 IF (1.0 .GT. y11) THEN
8917 IF (cr .GE. 0.) THEN
8926 IF (-1.0 .LT. y62) THEN
8933 fqyld(i, k, j) = dy*(mud*(0.5*min17*field_old(i, k, j-1)+0.5&
8934 & *max12*field_old(i, k, j))+mu*(0.5*(min17d*field_old(i, k&
8935 & , j-1)+min17*field_oldd(i, k, j-1))+0.5*(max12d*field_old(&
8936 & i, k, j)+max12*field_oldd(i, k, j))))/dt
8937 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min17*field_old(i, k, j-1)+&
8938 & 0.5*max12*field_old(i, k, j))
8939 fqyd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i, k, j-&
8940 & 1))-2./15.*(field(i, k, j+1)+field(i, k, j-2))+1./60.*(&
8941 & field(i, k, j+2)+field(i, k, j-3))-SIGN(1, time_step)*SIGN&
8942 & (1., vel)*(1./60.)*(field(i, k, j+2)-field(i, k, j-3)-5.*(&
8943 & field(i, k, j+1)-field(i, k, j-2))+10.*(field(i, k, j)-&
8944 & field(i, k, j-1)))) + vel*(37.*(fieldd(i, k, j)+fieldd(i, &
8945 & k, j-1))/60.-2.*(fieldd(i, k, j+1)+fieldd(i, k, j-2))/15.+&
8946 & (fieldd(i, k, j+2)+fieldd(i, k, j-3))/60.-SIGN(1, &
8947 & time_step)*SIGN(1., vel)*(fieldd(i, k, j+2)-fieldd(i, k, j&
8948 & -3)-5.*(fieldd(i, k, j+1)-fieldd(i, k, j-2))+10.*(fieldd(i&
8949 & , k, j)-fieldd(i, k, j-1)))/60.)
8950 fqy(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i, k, j-1)&
8951 & )-2./15.*(field(i, k, j+1)+field(i, k, j-2))+1./60.*(field&
8952 & (i, k, j+2)+field(i, k, j-3))-SIGN(1, time_step)*SIGN(1., &
8953 & vel)*(1./60.)*(field(i, k, j+2)-field(i, k, j-3)-5.*(field&
8954 & (i, k, j+1)-field(i, k, j-2))+10.*(field(i, k, j)-field(i&
8956 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
8957 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
8960 ELSE IF (j .EQ. jds + 1) THEN
8961 ! 2nd order flux next to south boundary
8965 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
8966 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
8967 mu = 0.5*(mut(i, j)+mut(i, j-1))
8970 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
8972 IF (cr .GE. 0.) THEN
8981 IF (1.0 .GT. y12) THEN
8988 IF (cr .GE. 0.) THEN
8997 IF (-1.0 .LT. y63) THEN
9004 fqyld(i, k, j) = dy*(mud*(0.5*min18*field_old(i, k, j-1)+0.5&
9005 & *max13*field_old(i, k, j))+mu*(0.5*(min18d*field_old(i, k&
9006 & , j-1)+min18*field_oldd(i, k, j-1))+0.5*(max13d*field_old(&
9007 & i, k, j)+max13*field_oldd(i, k, j))))/dt
9008 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min18*field_old(i, k, j-1)+&
9009 & 0.5*max13*field_old(i, k, j))
9010 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
9011 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
9012 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
9014 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9015 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9018 ELSE IF (j .EQ. jds + 2) THEN
9019 ! third of 4th order flux 2 in from south boundary
9023 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9024 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9025 mu = 0.5*(mut(i, j)+mut(i, j-1))
9028 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9030 IF (cr .GE. 0.) THEN
9039 IF (1.0 .GT. y13) THEN
9046 IF (cr .GE. 0.) THEN
9055 IF (-1.0 .LT. y64) THEN
9062 fqyld(i, k, j) = dy*(mud*(0.5*min19*field_old(i, k, j-1)+0.5&
9063 & *max14*field_old(i, k, j))+mu*(0.5*(min19d*field_old(i, k&
9064 & , j-1)+min19*field_oldd(i, k, j-1))+0.5*(max14d*field_old(&
9065 & i, k, j)+max14*field_oldd(i, k, j))))/dt
9066 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min19*field_old(i, k, j-1)+&
9067 & 0.5*max14*field_old(i, k, j))
9068 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
9069 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
9070 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
9071 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))) + vel*(&
9072 & 7.*(fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j&
9073 & +1)+fieldd(i, k, j-2))/12.+SIGN(1, time_step)*SIGN(1., vel&
9074 & )*(fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)&
9075 & -fieldd(i, k, j-1)))/12.)
9076 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
9077 & -1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
9078 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
9079 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1))))
9080 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9081 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9084 ELSE IF (j .EQ. jde - 1) THEN
9085 ! 2nd order flux next to north boundary
9089 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9090 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9091 mu = 0.5*(mut(i, j)+mut(i, j-1))
9094 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9096 IF (cr .GE. 0.) THEN
9105 IF (1.0 .GT. y14) THEN
9112 IF (cr .GE. 0.) THEN
9121 IF (-1.0 .LT. y65) THEN
9128 fqyld(i, k, j) = dy*(mud*(0.5*min20*field_old(i, k, j-1)+0.5&
9129 & *max15*field_old(i, k, j))+mu*(0.5*(min20d*field_old(i, k&
9130 & , j-1)+min20*field_oldd(i, k, j-1))+0.5*(max15d*field_old(&
9131 & i, k, j)+max15*field_oldd(i, k, j))))/dt
9132 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min20*field_old(i, k, j-1)+&
9133 & 0.5*max15*field_old(i, k, j))
9134 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
9135 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
9136 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
9138 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9139 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9142 ELSE IF (j .EQ. jde - 2) THEN
9143 ! 3rd or 4th order flux 2 in from north boundary
9147 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9148 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9149 mu = 0.5*(mut(i, j)+mut(i, j-1))
9152 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9154 IF (cr .GE. 0.) THEN
9163 IF (1.0 .GT. y15) THEN
9170 IF (cr .GE. 0.) THEN
9179 IF (-1.0 .LT. y66) THEN
9186 fqyld(i, k, j) = dy*(mud*(0.5*min21*field_old(i, k, j-1)+0.5&
9187 & *max16*field_old(i, k, j))+mu*(0.5*(min21d*field_old(i, k&
9188 & , j-1)+min21*field_oldd(i, k, j-1))+0.5*(max16d*field_old(&
9189 & i, k, j)+max16*field_oldd(i, k, j))))/dt
9190 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min21*field_old(i, k, j-1)+&
9191 & 0.5*max16*field_old(i, k, j))
9192 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
9193 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
9194 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
9195 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))) + vel*(&
9196 & 7.*(fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j&
9197 & +1)+fieldd(i, k, j-2))/12.+SIGN(1, time_step)*SIGN(1., vel&
9198 & )*(fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)&
9199 & -fieldd(i, k, j-1)))/12.)
9200 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
9201 & -1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
9202 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
9203 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1))))
9204 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9205 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9209 END DO j_loop_y_flux_5
9211 !-- these bounds are for periodic and sym conditions
9213 IF (ite .GT. ide - 1) THEN
9222 IF (jte .GT. jde - 1) THEN
9228 !-- modify loop bounds for open and specified b.c
9229 ! IF(degrade_ys) j_start = MAX(jts-1,jds+1)
9230 ! IF(degrade_ye) j_end = MIN(jte+1,jde-2)
9231 IF (degrade_ys) THEN
9232 IF (jts - 1 .LT. jds) THEN
9238 IF (degrade_ye) THEN
9239 IF (jte + 1 .GT. jde - 1) THEN
9245 IF (degrade_xs) THEN
9246 IF (ids + 1 .LT. its - 1) THEN
9253 IF (degrade_xe) THEN
9254 IF (ide - 2 .GT. ite + 1) THEN
9270 DO i=i_start_f,i_end_f
9272 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9273 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9274 mu = 0.5*(mut(i, j)+mut(i-1, j))
9277 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
9279 IF (cr .GE. 0.) THEN
9288 IF (1.0 .GT. y16) THEN
9295 IF (cr .GE. 0.) THEN
9304 IF (-1.0 .LT. y67) THEN
9311 fqxld(i, k, j) = dx*(mud*(0.5*min24*field_old(i-1, k, j)+0.5*&
9312 & max17*field_old(i, k, j))+mu*(0.5*(min24d*field_old(i-1, k, &
9313 & j)+min24*field_oldd(i-1, k, j))+0.5*(max17d*field_old(i, k, &
9314 & j)+max17*field_oldd(i, k, j))))/dt
9315 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min24*field_old(i-1, k, j)+0.5&
9316 & *max17*field_old(i, k, j))
9317 fqxd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i-1, k, j)&
9318 & )-2./15.*(field(i+1, k, j)+field(i-2, k, j))+1./60.*(field(i&
9319 & +2, k, j)+field(i-3, k, j))-SIGN(1, time_step)*SIGN(1., vel)&
9320 & *(1./60.)*(field(i+2, k, j)-field(i-3, k, j)-5.*(field(i+1, &
9321 & k, j)-field(i-2, k, j))+10.*(field(i, k, j)-field(i-1, k, j)&
9322 & ))) + vel*(37.*(fieldd(i, k, j)+fieldd(i-1, k, j))/60.-2.*(&
9323 & fieldd(i+1, k, j)+fieldd(i-2, k, j))/15.+(fieldd(i+2, k, j)+&
9324 & fieldd(i-3, k, j))/60.-SIGN(1, time_step)*SIGN(1., vel)*(&
9325 & fieldd(i+2, k, j)-fieldd(i-3, k, j)-5.*(fieldd(i+1, k, j)-&
9326 & fieldd(i-2, k, j))+10.*(fieldd(i, k, j)-fieldd(i-1, k, j)))/&
9328 fqx(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i-1, k, j))-&
9329 & 2./15.*(field(i+1, k, j)+field(i-2, k, j))+1./60.*(field(i+2&
9330 & , k, j)+field(i-3, k, j))-SIGN(1, time_step)*SIGN(1., vel)*(&
9331 & 1./60.)*(field(i+2, k, j)-field(i-3, k, j)-5.*(field(i+1, k&
9332 & , j)-field(i-2, k, j))+10.*(field(i, k, j)-field(i-1, k, j))&
9334 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9335 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9338 ! lower order fluxes close to boundaries (if not periodic or symmetric)
9339 IF (degrade_xs) THEN
9340 DO i=i_start,i_start_f-1
9341 IF (i .EQ. ids + 1) THEN
9345 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9346 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9347 mu = 0.5*(mut(i, j)+mut(i-1, j))
9348 veld = (rud(i, k, j)*mu-ru(i, k, j)*mud)/mu**2
9349 vel = ru(i, k, j)/mu
9352 IF (cr .GE. 0.) THEN
9361 IF (1.0 .GT. y17) THEN
9368 IF (cr .GE. 0.) THEN
9377 IF (-1.0 .LT. y68) THEN
9384 fqxld(i, k, j) = dx*(mud*(0.5*min25*field_old(i-1, k, j)+&
9385 & 0.5*max18*field_old(i, k, j))+mu*(0.5*(min25d*field_old(&
9386 & i-1, k, j)+min25*field_oldd(i-1, k, j))+0.5*(max18d*&
9387 & field_old(i, k, j)+max18*field_oldd(i, k, j))))/dt
9388 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min25*field_old(i-1, k, j)&
9389 & +0.5*max18*field_old(i, k, j))
9390 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-&
9391 & 1, k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)&
9393 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, &
9395 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9396 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9399 IF (i .EQ. ids + 2) THEN
9403 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9404 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9405 mu = 0.5*(mut(i, j)+mut(i-1, j))
9408 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
9410 IF (cr .GE. 0.) THEN
9419 IF (1.0 .GT. y18) THEN
9426 IF (cr .GE. 0.) THEN
9435 IF (-1.0 .LT. y69) THEN
9442 fqxld(i, k, j) = dx*(mud*(0.5*min26*field_old(i-1, k, j)+&
9443 & 0.5*max19*field_old(i, k, j))+mu*(0.5*(min26d*field_old(&
9444 & i-1, k, j)+min26*field_oldd(i-1, k, j))+0.5*(max19d*&
9445 & field_old(i, k, j)+max19*field_oldd(i, k, j))))/dt
9446 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min26*field_old(i-1, k, j)&
9447 & +0.5*max19*field_old(i, k, j))
9448 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k&
9449 & , j))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1&
9450 & , time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-&
9451 & field(i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j)))) &
9452 & + vel*(7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(&
9453 & fieldd(i+1, k, j)+fieldd(i-2, k, j))/12.+SIGN(1, &
9454 & time_step)*SIGN(1., vel)*(fieldd(i+1, k, j)-fieldd(i-2, &
9455 & k, j)-3.*(fieldd(i, k, j)-fieldd(i-1, k, j)))/12.)
9456 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j&
9457 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
9458 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-&
9459 & field(i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j))))
9460 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9461 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9466 IF (degrade_xe) THEN
9467 DO i=i_end_f+1,i_end+1
9468 IF (i .EQ. ide - 1) THEN
9469 ! second order flux next to the boundary
9472 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9473 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9474 mu = 0.5*(mut(i, j)+mut(i-1, j))
9477 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
9479 IF (cr .GE. 0.) THEN
9488 IF (1.0 .GT. y19) THEN
9495 IF (cr .GE. 0.) THEN
9504 IF (-1.0 .LT. y70) THEN
9511 fqxld(i, k, j) = dx*(mud*(0.5*min27*field_old(i-1, k, j)+&
9512 & 0.5*max20*field_old(i, k, j))+mu*(0.5*(min27d*field_old(&
9513 & i-1, k, j)+min27*field_oldd(i-1, k, j))+0.5*(max20d*&
9514 & field_old(i, k, j)+max20*field_oldd(i, k, j))))/dt
9515 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min27*field_old(i-1, k, j)&
9516 & +0.5*max20*field_old(i, k, j))
9517 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-&
9518 & 1, k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)&
9520 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, &
9522 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9523 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9526 IF (i .EQ. ide - 2) THEN
9527 ! third order flux one in from the boundary
9530 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9531 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9532 mu = 0.5*(mut(i, j)+mut(i-1, j))
9535 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
9537 IF (cr .GE. 0.) THEN
9546 IF (1.0 .GT. y20) THEN
9553 IF (cr .GE. 0.) THEN
9562 IF (-1.0 .LT. y71) THEN
9569 fqxld(i, k, j) = dx*(mud*(0.5*min28*field_old(i-1, k, j)+&
9570 & 0.5*max21*field_old(i, k, j))+mu*(0.5*(min28d*field_old(&
9571 & i-1, k, j)+min28*field_oldd(i-1, k, j))+0.5*(max21d*&
9572 & field_old(i, k, j)+max21*field_oldd(i, k, j))))/dt
9573 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min28*field_old(i-1, k, j)&
9574 & +0.5*max21*field_old(i, k, j))
9575 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k&
9576 & , j))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1&
9577 & , time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-&
9578 & field(i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j)))) &
9579 & + vel*(7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(&
9580 & fieldd(i+1, k, j)+fieldd(i-2, k, j))/12.+SIGN(1, &
9581 & time_step)*SIGN(1., vel)*(fieldd(i+1, k, j)-fieldd(i-2, &
9582 & k, j)-3.*(fieldd(i, k, j)-fieldd(i-1, k, j)))/12.)
9583 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j&
9584 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
9585 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-&
9586 & field(i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j))))
9587 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9588 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9594 ELSE IF (horz_order .EQ. 4) THEN
9595 ! enddo for outer J loop
9596 !--- end of 5th order horizontal flux calculation
9597 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
9598 & its .GT. ids + 1) degrade_xs = .false.
9599 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
9600 & ite .LT. ide - 2) degrade_xe = .false.
9601 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
9602 & jts .GT. jds + 1) degrade_ys = .false.
9603 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
9604 & jte .LT. jde - 2) degrade_ye = .false.
9605 IF (kte .GT. kde - 1) THEN
9611 IF (ite .GT. ide - 1) THEN
9618 IF (jte .GT. jde - 1) THEN
9626 !-- modify loop bounds if open or specified
9627 IF (degrade_xs) i_start = its
9628 IF (degrade_xe) THEN
9629 IF (ite .GT. ide - 1) THEN
9635 IF (degrade_ys) THEN
9636 IF (jts .LT. jds + 1) THEN
9643 IF (degrade_ye) THEN
9644 IF (jte .GT. jde - 2) THEN
9656 ! compute fluxes, 4th order
9657 j_loop_y_flux_4:DO j=j_start,j_end+1
9658 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
9663 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9664 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9665 mu = 0.5*(mut(i, j)+mut(i, j-1))
9668 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9670 IF (cr .GE. 0.) THEN
9679 IF (1.0 .GT. y21) THEN
9686 IF (cr .GE. 0.) THEN
9695 IF (-1.0 .LT. y72) THEN
9702 fqyld(i, k, j) = dy*(mud*(0.5*min31*field_old(i, k, j-1)+0.5&
9703 & *max22*field_old(i, k, j))+mu*(0.5*(min31d*field_old(i, k&
9704 & , j-1)+min31*field_oldd(i, k, j-1))+0.5*(max22d*field_old(&
9705 & i, k, j)+max22*field_oldd(i, k, j))))/dt
9706 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min31*field_old(i, k, j-1)+&
9707 & 0.5*max22*field_old(i, k, j))
9708 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
9709 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))) + vel*(7.*(&
9710 & fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+&
9711 & fieldd(i, k, j-2))/12.)
9712 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
9713 & -1./12.*(field(i, k, j+1)+field(i, k, j-2)))
9714 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9715 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9718 ELSE IF (j .EQ. jds + 1) THEN
9719 ! 2nd order flux next to south boundary
9723 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9724 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9725 mu = 0.5*(mut(i, j)+mut(i, j-1))
9728 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9730 IF (cr .GE. 0.) THEN
9739 IF (1.0 .GT. y22) THEN
9746 IF (cr .GE. 0.) THEN
9755 IF (-1.0 .LT. y73) THEN
9762 fqyld(i, k, j) = dy*(mud*(0.5*min32*field_old(i, k, j-1)+0.5&
9763 & *max23*field_old(i, k, j))+mu*(0.5*(min32d*field_old(i, k&
9764 & , j-1)+min32*field_oldd(i, k, j-1))+0.5*(max23d*field_old(&
9765 & i, k, j)+max23*field_oldd(i, k, j))))/dt
9766 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min32*field_old(i, k, j-1)+&
9767 & 0.5*max23*field_old(i, k, j))
9768 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
9769 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
9770 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
9772 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9773 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9776 ELSE IF (j .EQ. jde - 1) THEN
9777 ! 2nd order flux next to north boundary
9781 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
9782 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
9783 mu = 0.5*(mut(i, j)+mut(i, j-1))
9786 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
9788 IF (cr .GE. 0.) THEN
9797 IF (1.0 .GT. y23) THEN
9804 IF (cr .GE. 0.) THEN
9813 IF (-1.0 .LT. y74) THEN
9820 fqyld(i, k, j) = dy*(mud*(0.5*min33*field_old(i, k, j-1)+0.5&
9821 & *max24*field_old(i, k, j))+mu*(0.5*(min33d*field_old(i, k&
9822 & , j-1)+min33*field_oldd(i, k, j-1))+0.5*(max24d*field_old(&
9823 & i, k, j)+max24*field_oldd(i, k, j))))/dt
9824 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min33*field_old(i, k, j-1)+&
9825 & 0.5*max24*field_old(i, k, j))
9826 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
9827 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
9828 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
9830 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
9831 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
9835 END DO j_loop_y_flux_4
9837 !-- these bounds are for periodic and sym conditions
9839 IF (ite .GT. ide - 1) THEN
9848 IF (jte .GT. jde - 1) THEN
9854 !-- modify loop bounds for open and specified b.c
9855 IF (degrade_ys) j_start = jts
9856 IF (degrade_ye) THEN
9857 IF (jte .GT. jde - 1) THEN
9863 IF (degrade_xs) THEN
9864 IF (ids + 1 .LT. its) THEN
9869 i_start_f = i_start + 1
9871 IF (degrade_xe) THEN
9872 IF (ide - 2 .GT. ite) THEN
9888 DO i=i_start_f,i_end_f
9890 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9891 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9892 mu = 0.5*(mut(i, j)+mut(i-1, j))
9895 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
9897 IF (cr .GE. 0.) THEN
9906 IF (1.0 .GT. y24) THEN
9913 IF (cr .GE. 0.) THEN
9922 IF (-1.0 .LT. y75) THEN
9929 fqxld(i, k, j) = dx*(mud*(0.5*min36*field_old(i-1, k, j)+0.5*&
9930 & max25*field_old(i, k, j))+mu*(0.5*(min36d*field_old(i-1, k, &
9931 & j)+min36*field_oldd(i-1, k, j))+0.5*(max25d*field_old(i, k, &
9932 & j)+max25*field_oldd(i, k, j))))/dt
9933 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min36*field_old(i-1, k, j)+0.5&
9934 & *max25*field_old(i, k, j))
9935 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j))&
9936 & -1./12.*(field(i+1, k, j)+field(i-2, k, j))) + vel*(7.*(&
9937 & fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k, j)+&
9938 & fieldd(i-2, k, j))/12.)
9939 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))-&
9940 & 1./12.*(field(i+1, k, j)+field(i-2, k, j)))
9941 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
9942 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
9945 ! lower order fluxes close to boundaries (if not periodic or symmetric)
9946 IF (degrade_xs) THEN
9947 IF (i_start .EQ. ids + 1) THEN
9948 ! second order flux next to the boundary
9952 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
9953 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
9954 mu = 0.5*(mut(i, j)+mut(i-1, j))
9955 veld = (rud(i, k, j)*mu-ru(i, k, j)*mud)/mu**2
9956 vel = ru(i, k, j)/mu
9959 IF (cr .GE. 0.) THEN
9968 IF (1.0 .GT. y25) THEN
9975 IF (cr .GE. 0.) THEN
9984 IF (-1.0 .LT. y76) THEN
9991 fqxld(i, k, j) = dx*(mud*(0.5*min37*field_old(i-1, k, j)+0.5&
9992 & *max26*field_old(i, k, j))+mu*(0.5*(min37d*field_old(i-1, &
9993 & k, j)+min37*field_oldd(i-1, k, j))+0.5*(max26d*field_old(i&
9994 & , k, j)+max26*field_oldd(i, k, j))))/dt
9995 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min37*field_old(i-1, k, j)+&
9996 & 0.5*max26*field_old(i, k, j))
9997 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
9998 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
9999 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
10001 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10002 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10006 IF (degrade_xe) THEN
10007 IF (i_end .EQ. ide - 2) THEN
10008 ! second order flux next to the boundary
10012 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
10013 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
10014 mu = 0.5*(mut(i, j)+mut(i-1, j))
10015 veld = rud(i, k, j)
10017 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
10019 IF (cr .GE. 0.) THEN
10026 y26d = crd + abs26d
10028 IF (1.0 .GT. y26) THEN
10035 IF (cr .GE. 0.) THEN
10042 y77d = crd - abs77d
10044 IF (-1.0 .LT. y77) THEN
10051 fqxld(i, k, j) = dx*(mud*(0.5*min38*field_old(i-1, k, j)+0.5&
10052 & *max27*field_old(i, k, j))+mu*(0.5*(min38d*field_old(i-1, &
10053 & k, j)+min38*field_oldd(i-1, k, j))+0.5*(max27d*field_old(i&
10054 & , k, j)+max27*field_oldd(i, k, j))))/dt
10055 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min38*field_old(i-1, k, j)+&
10056 & 0.5*max27*field_old(i, k, j))
10057 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
10058 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
10059 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
10061 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10062 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10067 ELSE IF (horz_order .EQ. 3) THEN
10068 ! enddo for outer J loop
10069 !--- end of 4th order horizontal flux calculation
10070 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
10071 & its .GT. ids + 2) degrade_xs = .false.
10072 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
10073 & ite .LT. ide - 1) degrade_xe = .false.
10074 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
10075 & jts .GT. jds + 2) degrade_ys = .false.
10076 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
10077 & jte .LT. jde - 1) degrade_ye = .false.
10078 IF (kte .GT. kde - 1) THEN
10084 IF (ite .GT. ide - 1) THEN
10091 IF (jte .GT. jde - 1) THEN
10097 j_start_f = j_start
10098 j_end_f = j_end + 1
10099 !-- modify loop bounds if open or specified
10100 IF (degrade_xs) i_start = its
10101 IF (degrade_xe) THEN
10102 IF (ite .GT. ide - 1) THEN
10108 IF (degrade_ys) THEN
10109 IF (jts .LT. jds + 1) THEN
10114 j_start_f = jds + 2
10116 IF (degrade_ye) THEN
10117 IF (jte .GT. jde - 2) THEN
10129 ! compute fluxes, 3rd order
10130 j_loop_y_flux_3:DO j=j_start,j_end+1
10131 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
10136 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
10137 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
10138 mu = 0.5*(mut(i, j)+mut(i, j-1))
10139 veld = rvd(i, k, j)
10141 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
10143 IF (cr .GE. 0.) THEN
10150 y27d = crd + abs27d
10152 IF (1.0 .GT. y27) THEN
10159 IF (cr .GE. 0.) THEN
10166 y78d = crd - abs78d
10168 IF (-1.0 .LT. y78) THEN
10175 fqyld(i, k, j) = dy*(mud*(0.5*min41*field_old(i, k, j-1)+0.5&
10176 & *max28*field_old(i, k, j))+mu*(0.5*(min41d*field_old(i, k&
10177 & , j-1)+min41*field_oldd(i, k, j-1))+0.5*(max28d*field_old(&
10178 & i, k, j)+max28*field_oldd(i, k, j))))/dt
10179 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min41*field_old(i, k, j-1)+&
10180 & 0.5*max28*field_old(i, k, j))
10181 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1&
10182 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
10183 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
10184 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))) + vel*(&
10185 & 7.*(fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j&
10186 & +1)+fieldd(i, k, j-2))/12.+SIGN(1, time_step)*SIGN(1., vel&
10187 & )*(fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)&
10188 & -fieldd(i, k, j-1)))/12.)
10189 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))&
10190 & -1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
10191 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(&
10192 & i, k, j-2)-3.*(field(i, k, j)-field(i, k, j-1))))
10193 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
10194 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
10197 ELSE IF (j .EQ. jds + 1) THEN
10198 ! 2nd order flux next to south boundary
10202 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
10203 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
10204 mu = 0.5*(mut(i, j)+mut(i, j-1))
10205 veld = rvd(i, k, j)
10207 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
10209 IF (cr .GE. 0.) THEN
10216 y28d = crd + abs28d
10218 IF (1.0 .GT. y28) THEN
10225 IF (cr .GE. 0.) THEN
10232 y79d = crd - abs79d
10234 IF (-1.0 .LT. y79) THEN
10241 fqyld(i, k, j) = dy*(mud*(0.5*min42*field_old(i, k, j-1)+0.5&
10242 & *max29*field_old(i, k, j))+mu*(0.5*(min42d*field_old(i, k&
10243 & , j-1)+min42*field_oldd(i, k, j-1))+0.5*(max29d*field_old(&
10244 & i, k, j)+max29*field_oldd(i, k, j))))/dt
10245 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min42*field_old(i, k, j-1)+&
10246 & 0.5*max29*field_old(i, k, j))
10247 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
10248 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
10249 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
10251 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
10252 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
10255 ELSE IF (j .EQ. jde - 1) THEN
10256 ! 2nd order flux next to north boundary
10260 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
10261 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
10262 mu = 0.5*(mut(i, j)+mut(i, j-1))
10263 veld = rvd(i, k, j)
10265 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
10267 IF (cr .GE. 0.) THEN
10274 y29d = crd + abs29d
10276 IF (1.0 .GT. y29) THEN
10283 IF (cr .GE. 0.) THEN
10290 y80d = crd - abs80d
10292 IF (-1.0 .LT. y80) THEN
10299 fqyld(i, k, j) = dy*(mud*(0.5*min43*field_old(i, k, j-1)+0.5&
10300 & *max30*field_old(i, k, j))+mu*(0.5*(min43d*field_old(i, k&
10301 & , j-1)+min43*field_oldd(i, k, j-1))+0.5*(max30d*field_old(&
10302 & i, k, j)+max30*field_oldd(i, k, j))))/dt
10303 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min43*field_old(i, k, j-1)+&
10304 & 0.5*max30*field_old(i, k, j))
10305 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k&
10306 & , j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
10307 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j&
10309 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
10310 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
10314 END DO j_loop_y_flux_3
10316 !-- these bounds are for periodic and sym conditions
10318 IF (ite .GT. ide - 1) THEN
10324 i_start_f = i_start
10325 i_end_f = i_end + 1
10327 IF (jte .GT. jde - 1) THEN
10333 !-- modify loop bounds for open and specified b.c
10334 IF (degrade_ys) j_start = jts
10335 IF (degrade_ye) THEN
10336 IF (jte .GT. jde - 1) THEN
10342 IF (degrade_xs) THEN
10343 IF (ids + 1 .LT. its) THEN
10348 i_start_f = i_start + 1
10350 IF (degrade_xe) THEN
10351 IF (ide - 2 .GT. ite) THEN
10367 DO i=i_start_f,i_end_f
10369 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
10370 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
10371 mu = 0.5*(mut(i, j)+mut(i-1, j))
10372 veld = rud(i, k, j)
10374 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
10376 IF (cr .GE. 0.) THEN
10383 y30d = crd + abs30d
10385 IF (1.0 .GT. y30) THEN
10392 IF (cr .GE. 0.) THEN
10399 y81d = crd - abs81d
10401 IF (-1.0 .LT. y81) THEN
10408 fqxld(i, k, j) = dx*(mud*(0.5*min46*field_old(i-1, k, j)+0.5*&
10409 & max31*field_old(i, k, j))+mu*(0.5*(min46d*field_old(i-1, k, &
10410 & j)+min46*field_oldd(i-1, k, j))+0.5*(max31d*field_old(i, k, &
10411 & j)+max31*field_oldd(i, k, j))))/dt
10412 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min46*field_old(i-1, k, j)+0.5&
10413 & *max31*field_old(i, k, j))
10414 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j))&
10415 & -1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
10416 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(i-&
10417 & 2, k, j)-3.*(field(i, k, j)-field(i-1, k, j)))) + vel*(7.*(&
10418 & fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k, j)+&
10419 & fieldd(i-2, k, j))/12.+SIGN(1, time_step)*SIGN(1., vel)*(&
10420 & fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i, k, j)-&
10421 & fieldd(i-1, k, j)))/12.)
10422 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))-&
10423 & 1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, time_step&
10424 & )*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(i-2, k, j)-&
10425 & 3.*(field(i, k, j)-field(i-1, k, j))))
10426 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10427 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10430 ! lower order fluxes close to boundaries (if not periodic or symmetric)
10431 IF (degrade_xs) THEN
10432 IF (i_start .EQ. ids + 1) THEN
10433 ! second order flux next to the boundary
10437 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
10438 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
10439 mu = 0.5*(mut(i, j)+mut(i-1, j))
10440 veld = (rud(i, k, j)*mu-ru(i, k, j)*mud)/mu**2
10441 vel = ru(i, k, j)/mu
10444 IF (cr .GE. 0.) THEN
10451 y31d = crd + abs31d
10453 IF (1.0 .GT. y31) THEN
10460 IF (cr .GE. 0.) THEN
10467 y82d = crd - abs82d
10469 IF (-1.0 .LT. y82) THEN
10476 fqxld(i, k, j) = dx*(mud*(0.5*min47*field_old(i-1, k, j)+0.5&
10477 & *max32*field_old(i, k, j))+mu*(0.5*(min47d*field_old(i-1, &
10478 & k, j)+min47*field_oldd(i-1, k, j))+0.5*(max32d*field_old(i&
10479 & , k, j)+max32*field_oldd(i, k, j))))/dt
10480 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min47*field_old(i-1, k, j)+&
10481 & 0.5*max32*field_old(i, k, j))
10482 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
10483 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
10484 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
10486 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10487 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10491 IF (degrade_xe) THEN
10492 IF (i_end .EQ. ide - 2) THEN
10493 ! second order flux next to the boundary
10497 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
10498 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
10499 mu = 0.5*(mut(i, j)+mut(i-1, j))
10500 veld = rud(i, k, j)
10502 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
10504 IF (cr .GE. 0.) THEN
10511 y32d = crd + abs32d
10513 IF (1.0 .GT. y32) THEN
10520 IF (cr .GE. 0.) THEN
10527 y83d = crd - abs83d
10529 IF (-1.0 .LT. y83) THEN
10536 fqxld(i, k, j) = dx*(mud*(0.5*min48*field_old(i-1, k, j)+0.5&
10537 & *max33*field_old(i, k, j))+mu*(0.5*(min48d*field_old(i-1, &
10538 & k, j)+min48*field_oldd(i-1, k, j))+0.5*(max33d*field_old(i&
10539 & , k, j)+max33*field_oldd(i, k, j))))/dt
10540 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min48*field_old(i-1, k, j)+&
10541 & 0.5*max33*field_old(i, k, j))
10542 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
10543 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
10544 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
10546 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10547 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10552 ELSE IF (horz_order .EQ. 2) THEN
10553 ! enddo for outer J loop
10554 !--- end of 3rd order horizontal flux calculation
10555 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
10556 & its .GT. ids + 1) degrade_xs = .false.
10557 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
10558 & ite .LT. ide - 2) degrade_xe = .false.
10559 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
10560 & jts .GT. jds + 1) degrade_ys = .false.
10561 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
10562 & jte .LT. jde - 2) degrade_ye = .false.
10563 IF (kte .GT. kde - 1) THEN
10569 IF (ite .GT. ide - 1) THEN
10576 IF (jte .GT. jde - 1) THEN
10582 !-- modify loop bounds if open or specified
10583 IF (degrade_xs) i_start = its
10584 IF (degrade_xe) THEN
10585 IF (ite .GT. ide - 1) THEN
10591 IF (degrade_ys) THEN
10592 IF (jts .LT. jds + 1) THEN
10598 IF (degrade_ye) THEN
10599 IF (jte .GT. jde - 2) THEN
10610 ! compute fluxes, 2nd order, y flux
10611 DO j=j_start,j_end+1
10615 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
10616 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
10617 mu = 0.5*(mut(i, j)+mut(i, j-1))
10618 veld = rvd(i, k, j)
10620 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
10622 IF (cr .GE. 0.) THEN
10629 y33d = crd + abs33d
10631 IF (1.0 .GT. y33) THEN
10638 IF (cr .GE. 0.) THEN
10645 y84d = crd - abs84d
10647 IF (-1.0 .LT. y84) THEN
10654 fqyld(i, k, j) = dy*(mud*(0.5*min51*field_old(i, k, j-1)+0.5*&
10655 & max34*field_old(i, k, j))+mu*(0.5*(min51d*field_old(i, k, j-&
10656 & 1)+min51*field_oldd(i, k, j-1))+0.5*(max34d*field_old(i, k, &
10657 & j)+max34*field_oldd(i, k, j))))/dt
10658 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min51*field_old(i, k, j-1)+0.5&
10659 & *max34*field_old(i, k, j))
10660 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k, &
10661 & j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
10662 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j-1&
10664 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
10665 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
10674 DO i=i_start,i_end+1
10676 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
10677 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
10678 mu = 0.5*(mut(i, j)+mut(i-1, j))
10679 veld = rud(i, k, j)
10681 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
10683 IF (cr .GE. 0.) THEN
10690 y34d = crd + abs34d
10692 IF (1.0 .GT. y34) THEN
10699 IF (cr .GE. 0.) THEN
10706 y85d = crd - abs85d
10708 IF (-1.0 .LT. y85) THEN
10715 fqxld(i, k, j) = dx*(mud*(0.5*min52*field_old(i-1, k, j)+0.5*&
10716 & max35*field_old(i, k, j))+mu*(0.5*(min52d*field_old(i-1, k, &
10717 & j)+min52*field_oldd(i-1, k, j))+0.5*(max35d*field_old(i, k, &
10718 & j)+max35*field_oldd(i, k, j))))/dt
10719 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min52*field_old(i-1, k, j)+0.5&
10720 & *max35*field_old(i, k, j))
10721 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, k&
10722 & , j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
10723 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, j&
10725 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
10726 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
10731 !--- end of 2nd order horizontal flux calculation
10732 WRITE(wrf_err_message, *) &
10733 & 'module_advect: advect_scalar_pd, h_order not known ', horz_order
10734 CALL WRF_ERROR_FATAL(TRIM(wrf_err_message))
10740 ! pick up the rest of the horizontal radiation boundary conditions.
10741 ! (these are the computations that don't require 'cb'.
10742 ! first, set to index ranges
10744 IF (ite .GT. ide - 1) THEN
10750 IF (jte .GT. jde - 1) THEN
10755 ! compute x (u) conditions for v, w, or scalar
10756 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
10759 IF (0.5*(ru(its, k, j)+ru(its+1, k, j)) .GT. 0.) THEN
10763 ubd = 0.5*(rud(its, k, j)+rud(its+1, k, j))
10764 ub = 0.5*(ru(its, k, j)+ru(its+1, k, j))
10766 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(&
10767 & field_old(its+1, k, j)-field_old(its, k, j))+ub*(field_oldd(&
10768 & its+1, k, j)-field_oldd(its, k, j))+fieldd(its, k, j)*(ru(its+&
10769 & 1, k, j)-ru(its, k, j))+field(its, k, j)*(rud(its+1, k, j)-rud&
10771 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(field_old(&
10772 & its+1, k, j)-field_old(its, k, j))+field(its, k, j)*(ru(its+1&
10773 & , k, j)-ru(its, k, j)))
10777 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
10780 IF (0.5*(ru(ite-1, k, j)+ru(ite, k, j)) .LT. 0.) THEN
10784 ubd = 0.5*(rud(ite-1, k, j)+rud(ite, k, j))
10785 ub = 0.5*(ru(ite-1, k, j)+ru(ite, k, j))
10787 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
10788 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+ub*(&
10789 & field_oldd(i_end, k, j)-field_oldd(i_end-1, k, j))+fieldd(&
10790 & i_end, k, j)*(ru(ite, k, j)-ru(ite-1, k, j))+field(i_end, k, j&
10791 & )*(rud(ite, k, j)-rud(ite-1, k, j)))
10792 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(&
10793 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+field(i_end, &
10794 & k, j)*(ru(ite, k, j)-ru(ite-1, k, j)))
10798 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
10801 IF (0.5*(rv(i, k, jts)+rv(i, k, jts+1)) .GT. 0.) THEN
10805 vbd = 0.5*(rvd(i, k, jts)+rvd(i, k, jts+1))
10806 vb = 0.5*(rv(i, k, jts)+rv(i, k, jts+1))
10808 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
10809 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
10810 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*(rv(i, k&
10811 & , jts+1)-rv(i, k, jts))+field(i, k, jts)*(rvd(i, k, jts+1)-rvd&
10813 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
10814 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*(rv(i, k, &
10815 & jts+1)-rv(i, k, jts)))
10819 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
10822 IF (0.5*(rv(i, k, jte-1)+rv(i, k, jte)) .LT. 0.) THEN
10826 vbd = 0.5*(rvd(i, k, jte-1)+rvd(i, k, jte))
10827 vb = 0.5*(rv(i, k, jte-1)+rv(i, k, jte))
10829 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
10830 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
10831 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))+fieldd(i, k&
10832 & , j_end)*(rv(i, k, jte)-rv(i, k, jte-1))+field(i, k, j_end)*(&
10833 & rvd(i, k, jte)-rvd(i, k, jte-1)))
10834 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
10835 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
10836 & j_end)*(rv(i, k, jte)-rv(i, k, jte-1)))
10840 IF (config_flags%polar .AND. jts .EQ. jds) THEN
10841 ! Assuming rv(i,k,jds) = 0.
10844 IF (0.5*rv(i, k, jts+1) .GT. 0.) THEN
10848 vbd = 0.5*rvd(i, k, jts+1)
10849 vb = 0.5*rv(i, k, jts+1)
10851 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
10852 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
10853 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*rv(i, k, &
10854 & jts+1)+field(i, k, jts)*rvd(i, k, jts+1))
10855 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
10856 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*rv(i, k, &
10861 IF (config_flags%polar .AND. jte .EQ. jde) THEN
10862 ! Assuming rv(i,k,jde) = 0.
10865 IF (0.5*rv(i, k, jte-1) .LT. 0.) THEN
10869 vbd = 0.5*rvd(i, k, jte-1)
10870 vb = 0.5*rv(i, k, jte-1)
10872 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
10873 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
10874 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))-fieldd(i, k&
10875 & , j_end)*rv(i, k, jte-1)-field(i, k, j_end)*rvd(i, k, jte-1))
10876 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
10877 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
10878 & j_end)*(-rv(i, k, jte-1)))
10882 !-------------------- vertical advection
10883 !-- loop bounds for periodic or sym conditions
10885 IF (ite .GT. ide - 1) THEN
10892 IF (jte .GT. jde - 1) THEN
10898 !-- loop bounds for open or specified conditions
10899 IF (degrade_xs) THEN
10900 IF (its - 1 .LT. ids) THEN
10906 IF (degrade_xe) THEN
10907 IF (ite + 1 .GT. ide - 1) THEN
10913 IF (degrade_ys) THEN
10914 IF (jts - 1 .LT. jds) THEN
10920 IF (degrade_ye) THEN
10921 IF (jte + 1 .GT. jde - 1) THEN
10927 IF (vert_order .EQ. 6) THEN
10932 fqzd(i, 1, j) = 0.0
10934 fqzld(i, 1, j) = 0.0
10936 fqzd(i, kde, j) = 0.0
10937 fqz(i, kde, j) = 0.
10938 fqzld(i, kde, j) = 0.0
10939 fqzl(i, kde, j) = 0.
10943 dz = 2./(rdzw(k)+rdzw(k-1))
10944 mud = 0.5*2*mutd(i, j)
10945 mu = 0.5*(mut(i, j)+mut(i, j))
10946 veld = romd(i, k, j)
10948 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
10950 IF (cr .GE. 0.) THEN
10957 y35d = crd + abs35d
10959 IF (1.0 .GT. y35) THEN
10966 IF (cr .GE. 0.) THEN
10973 y86d = crd - abs86d
10975 IF (-1.0 .LT. y86) THEN
10982 fqzld(i, k, j) = dz*(mud*(0.5*min55*field_old(i, k-1, j)+0.5*&
10983 & max36*field_old(i, k, j))+mu*(0.5*(min55d*field_old(i, k-1, &
10984 & j)+min55*field_oldd(i, k-1, j))+0.5*(max36d*field_old(i, k, &
10985 & j)+max36*field_oldd(i, k, j))))/dt
10986 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min55*field_old(i, k-1, j)+0.5&
10987 & *max36*field_old(i, k, j))
10988 fqzd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i, k-1, j)&
10989 & )-2./15.*(field(i, k+1, j)+field(i, k-2, j))+1./60.*(field(i&
10990 & , k+2, j)+field(i, k-3, j))) + vel*(37.*(fieldd(i, k, j)+&
10991 & fieldd(i, k-1, j))/60.-2.*(fieldd(i, k+1, j)+fieldd(i, k-2, &
10992 & j))/15.+(fieldd(i, k+2, j)+fieldd(i, k-3, j))/60.)
10993 fqz(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i, k-1, j))-&
10994 & 2./15.*(field(i, k+1, j)+field(i, k-2, j))+1./60.*(field(i, &
10995 & k+2, j)+field(i, k-3, j)))
10996 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
10997 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11002 dz = 2./(rdzw(k)+rdzw(k-1))
11003 mud = 0.5*2*mutd(i, j)
11004 mu = 0.5*(mut(i, j)+mut(i, j))
11005 veld = romd(i, k, j)
11007 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11009 IF (cr .GE. 0.) THEN
11016 y36d = crd + abs36d
11018 IF (1.0 .GT. y36) THEN
11025 IF (cr .GE. 0.) THEN
11032 y87d = crd - abs87d
11034 IF (-1.0 .LT. y87) THEN
11041 fqzld(i, k, j) = dz*(mud*(0.5*min56*field_old(i, k-1, j)+0.5*&
11042 & max37*field_old(i, k, j))+mu*(0.5*(min56d*field_old(i, k-1, j)&
11043 & +min56*field_oldd(i, k-1, j))+0.5*(max37d*field_old(i, k, j)+&
11044 & max37*field_oldd(i, k, j))))/dt
11045 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min56*field_old(i, k-1, j)+0.5*&
11046 & max37*field_old(i, k, j))
11047 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11048 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11049 & )*fieldd(i, k-1, j))
11050 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11052 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11053 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11055 dz = 2./(rdzw(k)+rdzw(k-1))
11056 mud = 0.5*2*mutd(i, j)
11057 mu = 0.5*(mut(i, j)+mut(i, j))
11058 veld = romd(i, k, j)
11060 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11062 IF (cr .GE. 0.) THEN
11069 y37d = crd + abs37d
11071 IF (1.0 .GT. y37) THEN
11078 IF (cr .GE. 0.) THEN
11085 y88d = crd - abs88d
11087 IF (-1.0 .LT. y88) THEN
11094 fqzld(i, k, j) = dz*(mud*(0.5*min57*field_old(i, k-1, j)+0.5*&
11095 & max38*field_old(i, k, j))+mu*(0.5*(min57d*field_old(i, k-1, j)&
11096 & +min57*field_oldd(i, k-1, j))+0.5*(max38d*field_old(i, k, j)+&
11097 & max38*field_oldd(i, k, j))))/dt
11098 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min57*field_old(i, k-1, j)+0.5*&
11099 & max38*field_old(i, k, j))
11100 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11101 & 1./12.*(field(i, k+1, j)+field(i, k-2, j))) + vel*(7.*(fieldd(&
11102 & i, k, j)+fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k&
11104 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
11105 & 12.*(field(i, k+1, j)+field(i, k-2, j)))
11106 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11107 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11109 dz = 2./(rdzw(k)+rdzw(k-1))
11110 mud = 0.5*2*mutd(i, j)
11111 mu = 0.5*(mut(i, j)+mut(i, j))
11112 veld = romd(i, k, j)
11114 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11116 IF (cr .GE. 0.) THEN
11123 y38d = crd + abs38d
11125 IF (1.0 .GT. y38) THEN
11132 IF (cr .GE. 0.) THEN
11139 y89d = crd - abs89d
11141 IF (-1.0 .LT. y89) THEN
11148 fqzld(i, k, j) = dz*(mud*(0.5*min58*field_old(i, k-1, j)+0.5*&
11149 & max39*field_old(i, k, j))+mu*(0.5*(min58d*field_old(i, k-1, j)&
11150 & +min58*field_oldd(i, k-1, j))+0.5*(max39d*field_old(i, k, j)+&
11151 & max39*field_oldd(i, k, j))))/dt
11152 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min58*field_old(i, k-1, j)+0.5*&
11153 & max39*field_old(i, k, j))
11154 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11155 & 1./12.*(field(i, k+1, j)+field(i, k-2, j))) + vel*(7.*(fieldd(&
11156 & i, k, j)+fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k&
11158 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
11159 & 12.*(field(i, k+1, j)+field(i, k-2, j)))
11160 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11161 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11163 dz = 2./(rdzw(k)+rdzw(k-1))
11164 mud = 0.5*2*mutd(i, j)
11165 mu = 0.5*(mut(i, j)+mut(i, j))
11166 veld = romd(i, k, j)
11168 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11170 IF (cr .GE. 0.) THEN
11177 y39d = crd + abs39d
11179 IF (1.0 .GT. y39) THEN
11186 IF (cr .GE. 0.) THEN
11193 y90d = crd - abs90d
11195 IF (-1.0 .LT. y90) THEN
11202 fqzld(i, k, j) = dz*(mud*(0.5*min59*field_old(i, k-1, j)+0.5*&
11203 & max40*field_old(i, k, j))+mu*(0.5*(min59d*field_old(i, k-1, j)&
11204 & +min59*field_oldd(i, k-1, j))+0.5*(max40d*field_old(i, k, j)+&
11205 & max40*field_oldd(i, k, j))))/dt
11206 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min59*field_old(i, k-1, j)+0.5*&
11207 & max40*field_old(i, k, j))
11208 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11209 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11210 & )*fieldd(i, k-1, j))
11211 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11213 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11214 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11217 ELSE IF (vert_order .EQ. 5) THEN
11222 fqzd(i, 1, j) = 0.0
11224 fqzld(i, 1, j) = 0.0
11226 fqzd(i, kde, j) = 0.0
11227 fqz(i, kde, j) = 0.
11228 fqzld(i, kde, j) = 0.0
11229 fqzl(i, kde, j) = 0.
11233 dz = 2./(rdzw(k)+rdzw(k-1))
11234 mud = 0.5*2*mutd(i, j)
11235 mu = 0.5*(mut(i, j)+mut(i, j))
11236 veld = romd(i, k, j)
11238 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11240 IF (cr .GE. 0.) THEN
11247 y40d = crd + abs40d
11249 IF (1.0 .GT. y40) THEN
11256 IF (cr .GE. 0.) THEN
11263 y91d = crd - abs91d
11265 IF (-1.0 .LT. y91) THEN
11272 fqzld(i, k, j) = dz*(mud*(0.5*min60*field_old(i, k-1, j)+0.5*&
11273 & max41*field_old(i, k, j))+mu*(0.5*(min60d*field_old(i, k-1, &
11274 & j)+min60*field_oldd(i, k-1, j))+0.5*(max41d*field_old(i, k, &
11275 & j)+max41*field_oldd(i, k, j))))/dt
11276 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min60*field_old(i, k-1, j)+0.5&
11277 & *max41*field_old(i, k, j))
11278 fqzd(i, k, j) = veld*(37./60.*(field(i, k, j)+field(i, k-1, j)&
11279 & )-2./15.*(field(i, k+1, j)+field(i, k-2, j))+1./60.*(field(i&
11280 & , k+2, j)+field(i, k-3, j))-SIGN(1, time_step)*SIGN(1., -vel&
11281 & )*(1./60.)*(field(i, k+2, j)-field(i, k-3, j)-5.*(field(i, k&
11282 & +1, j)-field(i, k-2, j))+10.*(field(i, k, j)-field(i, k-1, j&
11283 & )))) + vel*(37.*(fieldd(i, k, j)+fieldd(i, k-1, j))/60.-2.*(&
11284 & fieldd(i, k+1, j)+fieldd(i, k-2, j))/15.+(fieldd(i, k+2, j)+&
11285 & fieldd(i, k-3, j))/60.-SIGN(1, time_step)*SIGN(1., -vel)*(&
11286 & fieldd(i, k+2, j)-fieldd(i, k-3, j)-5.*(fieldd(i, k+1, j)-&
11287 & fieldd(i, k-2, j))+10.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/&
11289 fqz(i, k, j) = vel*(37./60.*(field(i, k, j)+field(i, k-1, j))-&
11290 & 2./15.*(field(i, k+1, j)+field(i, k-2, j))+1./60.*(field(i, &
11291 & k+2, j)+field(i, k-3, j))-SIGN(1, time_step)*SIGN(1., -vel)*&
11292 & (1./60.)*(field(i, k+2, j)-field(i, k-3, j)-5.*(field(i, k+1&
11293 & , j)-field(i, k-2, j))+10.*(field(i, k, j)-field(i, k-1, j))&
11295 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11296 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11301 dz = 2./(rdzw(k)+rdzw(k-1))
11302 mud = 0.5*2*mutd(i, j)
11303 mu = 0.5*(mut(i, j)+mut(i, j))
11304 veld = romd(i, k, j)
11306 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11308 IF (cr .GE. 0.) THEN
11315 y41d = crd + abs41d
11317 IF (1.0 .GT. y41) THEN
11324 IF (cr .GE. 0.) THEN
11331 y92d = crd - abs92d
11333 IF (-1.0 .LT. y92) THEN
11340 fqzld(i, k, j) = dz*(mud*(0.5*min61*field_old(i, k-1, j)+0.5*&
11341 & max42*field_old(i, k, j))+mu*(0.5*(min61d*field_old(i, k-1, j)&
11342 & +min61*field_oldd(i, k-1, j))+0.5*(max42d*field_old(i, k, j)+&
11343 & max42*field_oldd(i, k, j))))/dt
11344 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min61*field_old(i, k-1, j)+0.5*&
11345 & max42*field_old(i, k, j))
11346 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11347 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11348 & )*fieldd(i, k-1, j))
11349 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11351 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11352 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11354 dz = 2./(rdzw(k)+rdzw(k-1))
11355 mud = 0.5*2*mutd(i, j)
11356 mu = 0.5*(mut(i, j)+mut(i, j))
11357 veld = romd(i, k, j)
11359 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11361 IF (cr .GE. 0.) THEN
11368 y42d = crd + abs42d
11370 IF (1.0 .GT. y42) THEN
11377 IF (cr .GE. 0.) THEN
11384 y93d = crd - abs93d
11386 IF (-1.0 .LT. y93) THEN
11393 fqzld(i, k, j) = dz*(mud*(0.5*min62*field_old(i, k-1, j)+0.5*&
11394 & max43*field_old(i, k, j))+mu*(0.5*(min62d*field_old(i, k-1, j)&
11395 & +min62*field_oldd(i, k-1, j))+0.5*(max43d*field_old(i, k, j)+&
11396 & max43*field_oldd(i, k, j))))/dt
11397 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min62*field_old(i, k-1, j)+0.5*&
11398 & max43*field_old(i, k, j))
11399 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11400 & 1./12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*&
11401 & SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*&
11402 & (field(i, k, j)-field(i, k-1, j)))) + vel*(7.*(fieldd(i, k, j)&
11403 & +fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k-2, j))/&
11404 & 12.+SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-&
11405 & fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.)
11406 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
11407 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*&
11408 & SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*&
11409 & (field(i, k, j)-field(i, k-1, j))))
11410 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11411 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11413 dz = 2./(rdzw(k)+rdzw(k-1))
11414 mud = 0.5*2*mutd(i, j)
11415 mu = 0.5*(mut(i, j)+mut(i, j))
11416 veld = romd(i, k, j)
11418 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11420 IF (cr .GE. 0.) THEN
11427 y43d = crd + abs43d
11429 IF (1.0 .GT. y43) THEN
11436 IF (cr .GE. 0.) THEN
11443 y94d = crd - abs94d
11445 IF (-1.0 .LT. y94) THEN
11452 fqzld(i, k, j) = dz*(mud*(0.5*min63*field_old(i, k-1, j)+0.5*&
11453 & max44*field_old(i, k, j))+mu*(0.5*(min63d*field_old(i, k-1, j)&
11454 & +min63*field_oldd(i, k-1, j))+0.5*(max44d*field_old(i, k, j)+&
11455 & max44*field_oldd(i, k, j))))/dt
11456 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min63*field_old(i, k-1, j)+0.5*&
11457 & max44*field_old(i, k, j))
11458 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11459 & 1./12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*&
11460 & SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*&
11461 & (field(i, k, j)-field(i, k-1, j)))) + vel*(7.*(fieldd(i, k, j)&
11462 & +fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k-2, j))/&
11463 & 12.+SIGN(1, time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-&
11464 & fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.)
11465 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
11466 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*&
11467 & SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*&
11468 & (field(i, k, j)-field(i, k-1, j))))
11469 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11470 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11472 dz = 2./(rdzw(k)+rdzw(k-1))
11473 mud = 0.5*2*mutd(i, j)
11474 mu = 0.5*(mut(i, j)+mut(i, j))
11475 veld = romd(i, k, j)
11477 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11479 IF (cr .GE. 0.) THEN
11486 y44d = crd + abs44d
11488 IF (1.0 .GT. y44) THEN
11495 IF (cr .GE. 0.) THEN
11502 y95d = crd - abs95d
11504 IF (-1.0 .LT. y95) THEN
11511 fqzld(i, k, j) = dz*(mud*(0.5*min64*field_old(i, k-1, j)+0.5*&
11512 & max45*field_old(i, k, j))+mu*(0.5*(min64d*field_old(i, k-1, j)&
11513 & +min64*field_oldd(i, k-1, j))+0.5*(max45d*field_old(i, k, j)+&
11514 & max45*field_oldd(i, k, j))))/dt
11515 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min64*field_old(i, k-1, j)+0.5*&
11516 & max45*field_old(i, k, j))
11517 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11518 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11519 & )*fieldd(i, k-1, j))
11520 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11522 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11523 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11526 ELSE IF (vert_order .EQ. 4) THEN
11531 fqzd(i, 1, j) = 0.0
11533 fqzld(i, 1, j) = 0.0
11535 fqzd(i, kde, j) = 0.0
11536 fqz(i, kde, j) = 0.
11537 fqzld(i, kde, j) = 0.0
11538 fqzl(i, kde, j) = 0.
11542 dz = 2./(rdzw(k)+rdzw(k-1))
11543 mud = 0.5*2*mutd(i, j)
11544 mu = 0.5*(mut(i, j)+mut(i, j))
11545 veld = romd(i, k, j)
11547 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11549 IF (cr .GE. 0.) THEN
11556 y45d = crd + abs45d
11558 IF (1.0 .GT. y45) THEN
11565 IF (cr .GE. 0.) THEN
11572 y96d = crd - abs96d
11574 IF (-1.0 .LT. y96) THEN
11581 fqzld(i, k, j) = dz*(mud*(0.5*min65*field_old(i, k-1, j)+0.5*&
11582 & max46*field_old(i, k, j))+mu*(0.5*(min65d*field_old(i, k-1, &
11583 & j)+min65*field_oldd(i, k-1, j))+0.5*(max46d*field_old(i, k, &
11584 & j)+max46*field_oldd(i, k, j))))/dt
11585 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min65*field_old(i, k-1, j)+0.5&
11586 & *max46*field_old(i, k, j))
11587 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))&
11588 & -1./12.*(field(i, k+1, j)+field(i, k-2, j))) + vel*(7.*(&
11589 & fieldd(i, k, j)+fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+&
11590 & fieldd(i, k-2, j))/12.)
11591 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11592 & 1./12.*(field(i, k+1, j)+field(i, k-2, j)))
11593 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11594 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11599 dz = 2./(rdzw(k)+rdzw(k-1))
11600 mud = 0.5*2*mutd(i, j)
11601 mu = 0.5*(mut(i, j)+mut(i, j))
11602 veld = romd(i, k, j)
11604 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11606 IF (cr .GE. 0.) THEN
11613 y46d = crd + abs46d
11615 IF (1.0 .GT. y46) THEN
11622 IF (cr .GE. 0.) THEN
11629 y97d = crd - abs97d
11631 IF (-1.0 .LT. y97) THEN
11638 fqzld(i, k, j) = dz*(mud*(0.5*min66*field_old(i, k-1, j)+0.5*&
11639 & max47*field_old(i, k, j))+mu*(0.5*(min66d*field_old(i, k-1, j)&
11640 & +min66*field_oldd(i, k-1, j))+0.5*(max47d*field_old(i, k, j)+&
11641 & max47*field_oldd(i, k, j))))/dt
11642 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min66*field_old(i, k-1, j)+0.5*&
11643 & max47*field_old(i, k, j))
11644 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11645 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11646 & )*fieldd(i, k-1, j))
11647 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11649 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11650 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11652 dz = 2./(rdzw(k)+rdzw(k-1))
11653 mud = 0.5*2*mutd(i, j)
11654 mu = 0.5*(mut(i, j)+mut(i, j))
11655 veld = romd(i, k, j)
11657 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11659 IF (cr .GE. 0.) THEN
11666 y47d = crd + abs47d
11668 IF (1.0 .GT. y47) THEN
11675 IF (cr .GE. 0.) THEN
11682 y98d = crd - abs98d
11684 IF (-1.0 .LT. y98) THEN
11691 fqzld(i, k, j) = dz*(mud*(0.5*min67*field_old(i, k-1, j)+0.5*&
11692 & max48*field_old(i, k, j))+mu*(0.5*(min67d*field_old(i, k-1, j)&
11693 & +min67*field_oldd(i, k-1, j))+0.5*(max48d*field_old(i, k, j)+&
11694 & max48*field_oldd(i, k, j))))/dt
11695 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min67*field_old(i, k-1, j)+0.5*&
11696 & max48*field_old(i, k, j))
11697 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11698 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11699 & )*fieldd(i, k-1, j))
11700 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11702 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11703 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11706 ELSE IF (vert_order .EQ. 3) THEN
11711 fqzd(i, 1, j) = 0.0
11713 fqzld(i, 1, j) = 0.0
11715 fqzd(i, kde, j) = 0.0
11716 fqz(i, kde, j) = 0.
11717 fqzld(i, kde, j) = 0.0
11718 fqzl(i, kde, j) = 0.
11722 dz = 2./(rdzw(k)+rdzw(k-1))
11723 mud = 0.5*2*mutd(i, j)
11724 mu = 0.5*(mut(i, j)+mut(i, j))
11725 veld = romd(i, k, j)
11727 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11729 IF (cr .GE. 0.) THEN
11736 y48d = crd + abs48d
11738 IF (1.0 .GT. y48) THEN
11745 IF (cr .GE. 0.) THEN
11752 y99d = crd - abs99d
11754 IF (-1.0 .LT. y99) THEN
11761 fqzld(i, k, j) = dz*(mud*(0.5*min68*field_old(i, k-1, j)+0.5*&
11762 & max49*field_old(i, k, j))+mu*(0.5*(min68d*field_old(i, k-1, &
11763 & j)+min68*field_oldd(i, k-1, j))+0.5*(max49d*field_old(i, k, &
11764 & j)+max49*field_oldd(i, k, j))))/dt
11765 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min68*field_old(i, k-1, j)+0.5&
11766 & *max49*field_old(i, k, j))
11767 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))&
11768 & -1./12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, &
11769 & time_step)*SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i&
11770 & , k-2, j)-3.*(field(i, k, j)-field(i, k-1, j)))) + vel*(7.*(&
11771 & fieldd(i, k, j)+fieldd(i, k-1, j))/12.-(fieldd(i, k+1, j)+&
11772 & fieldd(i, k-2, j))/12.+SIGN(1, time_step)*SIGN(1., -vel)*(&
11773 & fieldd(i, k+1, j)-fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-&
11774 & fieldd(i, k-1, j)))/12.)
11775 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-&
11776 & 1./12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step&
11777 & )*SIGN(1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)&
11778 & -3.*(field(i, k, j)-field(i, k-1, j))))
11779 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11780 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11785 dz = 2./(rdzw(k)+rdzw(k-1))
11786 mud = 0.5*2*mutd(i, j)
11787 mu = 0.5*(mut(i, j)+mut(i, j))
11788 veld = romd(i, k, j)
11790 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11792 IF (cr .GE. 0.) THEN
11799 y49d = crd + abs49d
11801 IF (1.0 .GT. y49) THEN
11808 IF (cr .GE. 0.) THEN
11815 y100d = crd - abs100d
11817 IF (-1.0 .LT. y100) THEN
11824 fqzld(i, k, j) = dz*(mud*(0.5*min69*field_old(i, k-1, j)+0.5*&
11825 & max50*field_old(i, k, j))+mu*(0.5*(min69d*field_old(i, k-1, j)&
11826 & +min69*field_oldd(i, k-1, j))+0.5*(max50d*field_old(i, k, j)+&
11827 & max50*field_oldd(i, k, j))))/dt
11828 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min69*field_old(i, k-1, j)+0.5*&
11829 & max50*field_old(i, k, j))
11830 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11831 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11832 & )*fieldd(i, k-1, j))
11833 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11835 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11836 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11838 dz = 2./(rdzw(k)+rdzw(k-1))
11839 mud = 0.5*2*mutd(i, j)
11840 mu = 0.5*(mut(i, j)+mut(i, j))
11841 veld = romd(i, k, j)
11843 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11845 IF (cr .GE. 0.) THEN
11852 y50d = crd + abs50d
11854 IF (1.0 .GT. y50) THEN
11861 IF (cr .GE. 0.) THEN
11868 y101d = crd - abs101d
11870 IF (-1.0 .LT. y101) THEN
11877 fqzld(i, k, j) = dz*(mud*(0.5*min70*field_old(i, k-1, j)+0.5*&
11878 & max51*field_old(i, k, j))+mu*(0.5*(min70d*field_old(i, k-1, j)&
11879 & +min70*field_oldd(i, k-1, j))+0.5*(max51d*field_old(i, k, j)+&
11880 & max51*field_oldd(i, k, j))))/dt
11881 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min70*field_old(i, k-1, j)+0.5*&
11882 & max51*field_old(i, k, j))
11883 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11884 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k&
11885 & )*fieldd(i, k-1, j))
11886 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
11888 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11889 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11892 ELSE IF (vert_order .EQ. 2) THEN
11897 fqzd(i, 1, j) = 0.0
11899 fqzld(i, 1, j) = 0.0
11901 fqzd(i, kde, j) = 0.0
11902 fqz(i, kde, j) = 0.
11903 fqzld(i, kde, j) = 0.0
11904 fqzl(i, kde, j) = 0.
11908 dz = 2./(rdzw(k)+rdzw(k-1))
11909 mud = 0.5*2*mutd(i, j)
11910 mu = 0.5*(mut(i, j)+mut(i, j))
11911 veld = romd(i, k, j)
11913 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
11915 IF (cr .GE. 0.) THEN
11922 y51d = crd + abs51d
11924 IF (1.0 .GT. y51) THEN
11931 IF (cr .GE. 0.) THEN
11938 y102d = crd - abs102d
11940 IF (-1.0 .LT. y102) THEN
11947 fqzld(i, k, j) = dz*(mud*(0.5*min71*field_old(i, k-1, j)+0.5*&
11948 & max52*field_old(i, k, j))+mu*(0.5*(min71d*field_old(i, k-1, &
11949 & j)+min71*field_oldd(i, k-1, j))+0.5*(max52d*field_old(i, k, &
11950 & j)+max52*field_oldd(i, k, j))))/dt
11951 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min71*field_old(i, k-1, j)+0.5&
11952 & *max52*field_old(i, k, j))
11953 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11954 & field(i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp&
11955 & (k)*fieldd(i, k-1, j))
11956 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*&
11957 & field(i, k-1, j))
11958 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
11959 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
11964 WRITE(wrf_err_message, *) ' advect_scalar_pd, v_order not known ', &
11966 CALL WRF_ERROR_FATAL(wrf_err_message)
11971 ! positive definite filter
11973 IF (ite .GT. ide - 1) THEN
11980 IF (jte .GT. jde - 1) THEN
11986 !-- loop bounds for open or specified conditions
11987 IF (degrade_xs) THEN
11988 IF (its - 1 .LT. ids) THEN
11994 IF (degrade_xe) THEN
11995 IF (ite + 1 .GT. ide - 1) THEN
12001 IF (degrade_ys) THEN
12002 IF (jts - 1 .LT. jds) THEN
12008 IF (degrade_ye) THEN
12009 IF (jte + 1 .GT. jde - 1) THEN
12015 IF (config_flags%specified .OR. config_flags%nested) THEN
12016 IF (degrade_xs) THEN
12017 IF (its - 1 .LT. ids + 1) THEN
12023 IF (degrade_xe) THEN
12024 IF (ite + 1 .GT. ide - 2) THEN
12030 IF (degrade_ys) THEN
12031 IF (jts - 1 .LT. jds + 1) THEN
12037 IF (degrade_ye) THEN
12038 IF (jte + 1 .GT. jde - 2) THEN
12045 IF (config_flags%open_xs) THEN
12046 IF (degrade_xs) THEN
12047 IF (its - 1 .LT. ids + 1) THEN
12054 IF (config_flags%open_xe) THEN
12055 IF (degrade_xe) THEN
12056 IF (ite + 1 .GT. ide - 2) THEN
12063 IF (config_flags%open_ys) THEN
12064 IF (degrade_ys) THEN
12065 IF (jts - 1 .LT. jds + 1) THEN
12072 IF (config_flags%open_ye) THEN
12073 IF (degrade_ye) THEN
12074 IF (jte + 1 .GT. jde - 2) THEN
12087 ! We don't want to change j_start and j_end
12088 ! for polar BC's since we want to calculate
12089 ! fluxes for directions other than y at the
12091 !-- here is the limiter...
12097 !DIR$ vector always
12100 ph_lowd(i,k,j) = mu_oldd(i, j)*field_old(i, k, j) + (mub(i, j)+mu_old&
12101 & (i, j))*field_oldd(i, k, j) - dt*(msftx(i, j)*msfty(i, j)*(&
12102 & rdx*(fqxld(i+1, k, j)-fqxld(i, k, j))+rdy*(fqyld(i, k, j+1)-&
12103 & fqyld(i, k, j)))+msfty(i, j)*rdzw(k)*(fqzld(i, k+1, j)-fqzld&
12105 ph_low(i,k,j) = (mub(i, j)+mu_old(i, j))*field_old(i, k, j) - dt*(&
12106 & msftx(i, j)*msfty(i, j)*(rdx*(fqxl(i+1, k, j)-fqxl(i, k, j))&
12107 & +rdy*(fqyl(i, k, j+1)-fqyl(i, k, j)))+msfty(i, j)*rdzw(k)*(&
12108 & fqzl(i, k+1, j)-fqzl(i, k, j)))
12115 !DIR$ vector always
12117 IF (0. .LT. fqx(i+1, k, j)) THEN
12118 max1d = fqxd(i+1, k, j)
12119 max1 = fqx(i+1, k, j)
12124 IF (0. .GT. fqx(i, k, j)) THEN
12125 min74d = fqxd(i, k, j)
12126 min74 = fqx(i, k, j)
12131 IF (0. .LT. fqy(i, k, j+1)) THEN
12132 max53d = fqyd(i, k, j+1)
12133 max53 = fqy(i, k, j+1)
12138 IF (0. .GT. fqy(i, k, j)) THEN
12139 min75d = fqyd(i, k, j)
12140 min75 = fqy(i, k, j)
12145 IF (0. .GT. fqz(i, k+1, j)) THEN
12146 min76d = fqzd(i, k+1, j)
12147 min76 = fqz(i, k+1, j)
12152 IF (0. .LT. fqz(i, k, j)) THEN
12153 max54d = fqzd(i, k, j)
12154 max54 = fqz(i, k, j)
12159 flux_outd(i,k,j) = dt*(msftx(i, j)*msfty(i, j)*(rdx*(max1d-min74d)+&
12160 & rdy*(max53d-min75d))+msfty(i, j)*rdzw(k)*(min76d-max54d))
12161 flux_out(i,k,j) = dt*(msftx(i, j)*msfty(i, j)*(rdx*(max1-min74)+rdy*(&
12162 & max53-min75))+msfty(i, j)*rdzw(k)*(min76-max54))
12168 !DIR$ vector always
12170 IF (flux_out(i,k,j) .GT. ph_low(i,k,j)) THEN
12171 y16d = (ph_lowd(i,k,j)*(flux_out(i,k,j)+eps)-ph_low(i,k,j)*flux_outd(i,k,j))/(&
12172 & flux_out(i,k,j)+eps)**2
12173 y16 = ph_low(i,k,j)/(flux_out(i,k,j)+eps)
12174 IF (0. .LT. y16) THEN
12181 IF (fqx(i+1, k, j) .GT. 0.) THEN
12182 fqxd(i+1, k, j) = scaled*fqx(i+1, k, j) + scale*fqxd(i+1, &
12184 fqx(i+1, k, j) = scale*fqx(i+1, k, j)
12186 IF (fqx(i, k, j) .LT. 0.) THEN
12187 fqxd(i, k, j) = scaled*fqx(i, k, j) + scale*fqxd(i, k, j)
12188 fqx(i, k, j) = scale*fqx(i, k, j)
12190 IF (fqy(i, k, j+1) .GT. 0.) THEN
12191 fqyd(i, k, j+1) = scaled*fqy(i, k, j+1) + scale*fqyd(i, k&
12193 fqy(i, k, j+1) = scale*fqy(i, k, j+1)
12195 IF (fqy(i, k, j) .LT. 0.) THEN
12196 fqyd(i, k, j) = scaled*fqy(i, k, j) + scale*fqyd(i, k, j)
12197 fqy(i, k, j) = scale*fqy(i, k, j)
12199 ! note: z flux is opposite sign in mass coordinate because
12200 ! vertical coordinate decreases with increasing k
12201 IF (fqz(i, k+1, j) .LT. 0.) THEN
12202 fqzd(i, k+1, j) = scaled*fqz(i, k+1, j) + scale*fqzd(i, k+&
12204 fqz(i, k+1, j) = scale*fqz(i, k+1, j)
12206 IF (fqz(i, k, j) .GT. 0.) THEN
12207 fqzd(i, k, j) = scaled*fqz(i, k, j) + scale*fqzd(i, k, j)
12208 fqz(i, k, j) = scale*fqz(i, k, j)
12215 ! add in the pd-limited flux divergence
12217 IF (ite .GT. ide - 1) THEN
12223 IF (jte .GT. jde - 1) THEN
12231 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(fqzd(i, k+1, &
12232 & j)-fqzd(i, k, j)+fqzld(i, k+1, j)-fqzld(i, k, j))
12233 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(fqz(i, k+1, j)-&
12234 & fqz(i, k, j)+fqzl(i, k+1, j)-fqzl(i, k, j))
12242 z_tendencyd(i, k, j) = -(rdzw(k)*(fqzd(i, k+1, j)-fqzd(i, k, j&
12243 & )+fqzld(i, k+1, j)-fqzld(i, k, j)))
12244 z_tendency(i, k, j) = 0. - rdzw(k)*(fqz(i, k+1, j)-fqz(i, k, j&
12245 & )+fqzl(i, k+1, j)-fqzl(i, k, j))
12250 ! x flux divergence
12252 IF (degrade_xs) THEN
12253 IF (its .LT. ids + 1) THEN
12259 IF (degrade_xe) THEN
12260 IF (ite .GT. ide - 2) THEN
12269 ! Un-"canceled" map scale factor, ADT Eq. 48
12270 tendencyd(i, k, j) = tendencyd(i, k, j) - msftx(i, j)*rdx*(fqxd(&
12271 & i+1, k, j)-fqxd(i, k, j)+fqxld(i+1, k, j)-fqxld(i, k, j))
12272 tendency(i, k, j) = tendency(i, k, j) - msftx(i, j)*(rdx*(fqx(i+&
12273 & 1, k, j)-fqx(i, k, j)+fqxl(i+1, k, j)-fqxl(i, k, j)))
12281 h_tendencyd(i, k, j) = -(msftx(i, j)*rdx*(fqxd(i+1, k, j)-fqxd&
12282 & (i, k, j)+fqxld(i+1, k, j)-fqxld(i, k, j)))
12283 h_tendency(i, k, j) = 0. - msftx(i, j)*(rdx*(fqx(i+1, k, j)-&
12284 & fqx(i, k, j)+fqxl(i+1, k, j)-fqxl(i, k, j)))
12289 ! y flux divergence
12292 IF (ite .GT. ide - 1) THEN
12297 IF (degrade_ys) THEN
12298 IF (jts .LT. jds + 1) THEN
12304 IF (degrade_ye) THEN
12305 IF (jte .GT. jde - 2) THEN
12314 ! Un-"canceled" map scale factor, ADT Eq. 48
12315 ! It is correct to use msftx (and not msfty), per W. Skamarock, 20080606
12316 tendencyd(i, k, j) = tendencyd(i, k, j) - msftx(i, j)*rdy*(fqyd(&
12317 & i, k, j+1)-fqyd(i, k, j)+fqyld(i, k, j+1)-fqyld(i, k, j))
12318 tendency(i, k, j) = tendency(i, k, j) - msftx(i, j)*(rdy*(fqy(i&
12319 & , k, j+1)-fqy(i, k, j)+fqyl(i, k, j+1)-fqyl(i, k, j)))
12327 h_tendencyd(i, k, j) = h_tendencyd(i, k, j) - msftx(i, j)*rdy*&
12328 & (fqyd(i, k, j+1)-fqyd(i, k, j)+fqyld(i, k, j+1)-fqyld(i, k, &
12330 h_tendency(i, k, j) = h_tendency(i, k, j) - msftx(i, j)*(rdy*(&
12331 & fqy(i, k, j+1)-fqy(i, k, j)+fqyl(i, k, j+1)-fqyl(i, k, j)))
12336 END SUBROUTINE G_ADVECT_SCALAR_PD
12338 ! Generated by TAPENADE (INRIA, Tropics team)
12339 ! Tapenade 3.6 (r4165) - 21 sep 2011 20:54
12341 ! Differentiation of advect_scalar_wenopd in forward (tangent) mode:
12342 ! variations of useful results: tendency
12343 ! with respect to varying inputs: rom field tendency ru rv mu_old
12345 ! RW status of diff variables: rom:in field:in tendency:in-out
12346 ! ru:in rv:in mu_old:in field_old:in mut:in
12347 SUBROUTINE G_ADVECT_SCALAR_WENOPD(field, fieldd, field_old, field_oldd, &
12348 & tendency, tendencyd, ru, rud, rv, rvd, rom, romd, mut, mutd, mub, &
12349 & mu_old, mu_oldd, time_step, config_flags, msfux, msfuy, msfvx, msfvy, &
12350 & msftx, msfty, fzm, fzp, rdx, rdy, rdzw, dt, ids, ide, jds, jde, kds, &
12351 & kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte)
12354 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
12355 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
12356 & jme, kms, kme, its, ite, jts, jte, kts, kte
12357 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: field, &
12358 & field_old, ru, rv, rom
12359 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: fieldd, &
12360 & field_oldd, rud, rvd, romd
12361 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut, mub, mu_old
12362 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd, mu_oldd
12363 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
12364 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
12365 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
12366 & msfvy, msftx, msfty
12367 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
12368 REAL, INTENT(IN) :: rdx, rdy, dt
12369 INTEGER, INTENT(IN) :: time_step
12371 INTEGER :: i, j, k, itf, jtf, ktf
12372 INTEGER :: i_start, i_end, j_start, j_end
12373 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
12374 INTEGER :: jmin, jmax, jp, jm, imin, imax
12375 REAL :: mrdx, mrdy, ub, vb, uw, vw, mu
12376 REAL :: ubd, vbd, mud
12377 ! storage for high and low order fluxes
12378 REAL, DIMENSION(its - 1:ite + 2, kts:kte, jts - 1:jte + 2) :: fqx, fqy&
12380 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: fqxd, fqyd, fqzd
12381 REAL, DIMENSION(its - 1:ite + 2, kts:kte, jts - 1:jte + 2) :: fqxl, &
12383 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: fqxld, fqyld, &
12385 INTEGER :: horz_order, vert_order
12386 LOGICAL :: degrade_xs, degrade_ys
12387 LOGICAL :: degrade_xe, degrade_ye
12388 INTEGER :: jp1, jp0, jtmp
12389 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: flux_out, ph_low
12390 REAL, DIMENSION(its-1:ite+2, kts:kte, jts-1:jte+2) :: flux_outd, ph_lowd
12393 REAL, PARAMETER :: eps=1.e-20
12395 REAL :: ue, vs, vn, wb, wt
12396 REAL, PARAMETER :: f30=7./12., f31=1./12.
12397 REAL, PARAMETER :: f50=37./60., f51=2./15., f52=1./60.
12398 REAL :: qim2, qim1, qi, qip1, qip2
12399 REAL :: qim2d, qim1d, qid, qip1d, qip2d
12400 DOUBLE PRECISION :: beta0, beta1, beta2, f0, f1, f2, wi0, wi1, wi2, &
12402 DOUBLE PRECISION :: beta0d, beta1d, beta2d, f0d, f1d, f2d, wi0d, wi1d&
12404 DOUBLE PRECISION, PARAMETER :: gi0=1.d0/10.d0, gi1=6.d0/10.d0, gi2=&
12405 & 3.d0/10.d0, eps1=1.0d-28
12406 INTEGER, PARAMETER :: pw=2
12407 ! definition of flux operators, 3rd, 4th, 5th or 6th order
12408 REAL :: flux3, flux4, flux5, flux6, flux_upwind
12409 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel, cr
12411 ! flux_upwind(q_im1, q_i, cr ) = 0.5*(1.+sign(1.,cr))*q_im1 &
12412 ! +0.5*(1.-sign(1.,cr))*q_i
12413 ! flux_upwind(q_im1, q_i, cr ) = 0.
12415 LOGICAL, PARAMETER :: pd_limit=.true.
12416 DOUBLE PRECISION :: pwx1
12417 DOUBLE PRECISION :: pwx1d
12418 DOUBLE PRECISION :: pwr1
12419 DOUBLE PRECISION :: pwr1d
12629 ! set order for the advection schemes
12630 ! write(6,*) ' in pd advection routine '
12631 ! Empty arrays just in case:
12632 IF (config_flags%polar) THEN
12640 IF (kte .GT. kde - 1) THEN
12645 horz_order = config_flags%h_sca_adv_order
12646 vert_order = config_flags%v_sca_adv_order
12647 ! determine boundary mods for flux operators
12648 ! We degrade the flux operators from 3rd/4th order
12649 ! to second order one gridpoint in from the boundaries for
12650 ! all boundary conditions except periodic and symmetry - these
12651 ! conditions have boundary zone data fill for correct application
12652 ! of the higher order flux stencils
12653 degrade_xs = .true.
12654 degrade_xe = .true.
12655 degrade_ys = .true.
12656 degrade_ye = .true.
12657 ! begin with horizontal flux divergence
12658 ! here is the choice of flux operators
12659 ! horizontal_order_test : IF( horz_order == 6 ) THEN
12660 ! ELSE IF( horz_order == 5 ) THEN
12661 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. its &
12662 & .GT. ids + 3) degrade_xs = .false.
12663 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. ite &
12664 & .LT. ide - 4) degrade_xe = .false.
12665 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. jts &
12666 & .GT. jds + 3) degrade_ys = .false.
12667 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. jte &
12668 & .LT. jde - 4) degrade_ye = .false.
12669 IF (kte .GT. kde - 1) THEN
12675 IF (ite .GT. ide - 1) THEN
12682 IF (jte .GT. jde - 1) THEN
12688 j_start_f = j_start
12689 j_end_f = j_end + 1
12690 !-- modify loop bounds if open or specified
12691 ! IF(degrade_xs) i_start = MAX(its-1,ids-1)
12692 ! IF(degrade_xe) i_end = MIN(ite+1,ide-2)
12693 IF (degrade_xs) THEN
12694 IF (its - 1 .LT. ids) THEN
12700 IF (degrade_xe) THEN
12701 IF (ite + 1 .GT. ide - 1) THEN
12707 IF (degrade_ys) THEN
12708 IF (jts - 1 .LT. jds + 1) THEN
12713 j_start_f = jds + 3
12715 IF (degrade_ye) THEN
12716 IF (jte + 1 .GT. jde - 2) THEN
12728 ! compute fluxes, 5th order
12729 j_loop_y_flux_5:DO j=j_start,j_end+1
12730 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
12735 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
12736 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
12737 mu = 0.5*(mut(i, j)+mut(i, j-1))
12738 veld = rvd(i, k, j)
12740 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
12742 IF (cr .GE. 0.) THEN
12751 IF (1.0 .GT. y1) THEN
12758 IF (cr .GE. 0.) THEN
12765 y16d = crd - abs15d
12767 IF (-1.0 .LT. y16) THEN
12774 fqyld(i, k, j) = dy*(mud*(0.5*min3*field_old(i, k, j-1)+0.5*&
12775 & max2*field_old(i, k, j))+mu*(0.5*(min3d*field_old(i, k, j-1)&
12776 & +min3*field_oldd(i, k, j-1))+0.5*(max2d*field_old(i, k, j)+&
12777 & max2*field_oldd(i, k, j))))/dt
12778 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min3*field_old(i, k, j-1)+0.5*&
12779 & max2*field_old(i, k, j))
12780 IF (vel*sign(1,time_step) .GE. 0.0) THEN
12781 qip2d = fieldd(i, k, j+1)
12782 qip2 = field(i, k, j+1)
12783 qip1d = fieldd(i, k, j)
12784 qip1 = field(i, k, j)
12785 qid = fieldd(i, k, j-1)
12786 qi = field(i, k, j-1)
12787 qim1d = fieldd(i, k, j-2)
12788 qim1 = field(i, k, j-2)
12789 qim2d = fieldd(i, k, j-3)
12790 qim2 = field(i, k, j-3)
12792 qip2d = fieldd(i, k, j-2)
12793 qip2 = field(i, k, j-2)
12794 qip1d = fieldd(i, k, j-1)
12795 qip1 = field(i, k, j-1)
12796 qid = fieldd(i, k, j)
12797 qi = field(i, k, j)
12798 qim1d = fieldd(i, k, j+1)
12799 qim1 = field(i, k, j+1)
12800 qim2d = fieldd(i, k, j+2)
12801 qim2 = field(i, k, j+2)
12803 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
12804 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
12805 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
12806 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
12807 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
12808 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
12809 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*&
12810 & (qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
12811 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*&
12813 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*&
12814 & (qim1-qip1)*(qim1d-qip1d)/4.
12815 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
12816 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*&
12817 & (qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
12818 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*&
12821 pwx1 = eps1 + beta0
12822 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
12824 pwr1d = pw*pwx1**(pw-1)*pwx1d
12825 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
12831 wi0d = -(gi0*pwr1d/pwr1**2)
12834 pwx1 = eps1 + beta1
12835 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
12837 pwr1d = pw*pwx1**(pw-1)*pwx1d
12838 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
12844 wi1d = -(gi1*pwr1d/pwr1**2)
12847 pwx1 = eps1 + beta2
12848 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
12850 pwr1d = pw*pwx1**(pw-1)*pwx1d
12851 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
12857 wi2d = -(gi2*pwr1d/pwr1**2)
12859 sumwkd = wi0d + wi1d + wi2d
12860 sumwk = wi0 + wi1 + wi2
12861 fqyd(i, k, j) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0&
12862 & *f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1&
12863 & *f1+wi2*f2)*sumwkd)/sumwk**2
12864 fqy(i, k, j) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
12865 ! fqy( i, k, j ) = vel*flux5( &
12866 ! field(i,k,j-3), field(i,k,j-2), field(i,k,j-1), &
12867 ! field(i,k,j ), field(i,k,j+1), field(i,k,j+2), vel )
12868 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
12869 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
12872 ELSE IF (j .EQ. jds + 1) THEN
12873 ! 2nd order flux next to south boundary
12877 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
12878 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
12879 mu = 0.5*(mut(i, j)+mut(i, j-1))
12880 veld = rvd(i, k, j)
12882 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
12884 IF (cr .GE. 0.) THEN
12893 IF (1.0 .GT. y2) THEN
12900 IF (cr .GE. 0.) THEN
12907 y17d = crd - abs16d
12909 IF (-1.0 .LT. y17) THEN
12916 fqyld(i, k, j) = dy*(mud*(0.5*min4*field_old(i, k, j-1)+0.5*&
12917 & max3*field_old(i, k, j))+mu*(0.5*(min4d*field_old(i, k, j-1)&
12918 & +min4*field_oldd(i, k, j-1))+0.5*(max3d*field_old(i, k, j)+&
12919 & max3*field_oldd(i, k, j))))/dt
12920 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min4*field_old(i, k, j-1)+0.5*&
12921 & max3*field_old(i, k, j))
12922 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k, &
12923 & j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
12924 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j-1&
12926 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
12927 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
12930 ELSE IF (j .EQ. jds + 2) THEN
12931 ! third of 4th order flux 2 in from south boundary
12935 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
12936 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
12937 mu = 0.5*(mut(i, j)+mut(i, j-1))
12938 veld = rvd(i, k, j)
12940 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
12942 IF (cr .GE. 0.) THEN
12951 IF (1.0 .GT. y3) THEN
12958 IF (cr .GE. 0.) THEN
12965 y18d = crd - abs17d
12967 IF (-1.0 .LT. y18) THEN
12974 fqyld(i, k, j) = dy*(mud*(0.5*min5*field_old(i, k, j-1)+0.5*&
12975 & max4*field_old(i, k, j))+mu*(0.5*(min5d*field_old(i, k, j-1)&
12976 & +min5*field_oldd(i, k, j-1))+0.5*(max4d*field_old(i, k, j)+&
12977 & max4*field_oldd(i, k, j))))/dt
12978 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min5*field_old(i, k, j-1)+0.5*&
12979 & max4*field_old(i, k, j))
12980 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1))&
12981 & -1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
12982 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(i&
12983 & , k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))) + vel*(7.*(&
12984 & fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+&
12985 & fieldd(i, k, j-2))/12.+SIGN(1, time_step)*SIGN(1., vel)*(&
12986 & fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)-&
12987 & fieldd(i, k, j-1)))/12.)
12988 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))-&
12989 & 1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, time_step&
12990 & )*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-&
12991 & 3.*(field(i, k, j)-field(i, k, j-1))))
12992 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
12993 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
12996 ELSE IF (j .EQ. jde - 1) THEN
12997 ! 2nd order flux next to north boundary
13001 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
13002 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
13003 mu = 0.5*(mut(i, j)+mut(i, j-1))
13004 veld = rvd(i, k, j)
13006 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
13008 IF (cr .GE. 0.) THEN
13017 IF (1.0 .GT. y4) THEN
13024 IF (cr .GE. 0.) THEN
13031 y19d = crd - abs18d
13033 IF (-1.0 .LT. y19) THEN
13040 fqyld(i, k, j) = dy*(mud*(0.5*min6*field_old(i, k, j-1)+0.5*&
13041 & max5*field_old(i, k, j))+mu*(0.5*(min6d*field_old(i, k, j-1)&
13042 & +min6*field_oldd(i, k, j-1))+0.5*(max5d*field_old(i, k, j)+&
13043 & max5*field_oldd(i, k, j))))/dt
13044 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min6*field_old(i, k, j-1)+0.5*&
13045 & max5*field_old(i, k, j))
13046 fqyd(i, k, j) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i, k, &
13047 & j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1)))
13048 fqy(i, k, j) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k, j-1&
13050 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
13051 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
13054 ELSE IF (j .EQ. jde - 2) THEN
13055 ! 3rd or 4th order flux 2 in from north boundary
13059 dy = 2./(msftx(i, j)+msftx(i, j-1))/rdy
13060 mud = 0.5*(mutd(i, j)+mutd(i, j-1))
13061 mu = 0.5*(mut(i, j)+mut(i, j-1))
13062 veld = rvd(i, k, j)
13064 crd = (dt*veld*mu/dy-vel*dt*mud/dy)/mu**2
13066 IF (cr .GE. 0.) THEN
13075 IF (1.0 .GT. y5) THEN
13082 IF (cr .GE. 0.) THEN
13089 y20d = crd - abs19d
13091 IF (-1.0 .LT. y20) THEN
13098 fqyld(i, k, j) = dy*(mud*(0.5*min7*field_old(i, k, j-1)+0.5*&
13099 & max6*field_old(i, k, j))+mu*(0.5*(min7d*field_old(i, k, j-1)&
13100 & +min7*field_oldd(i, k, j-1))+0.5*(max6d*field_old(i, k, j)+&
13101 & max6*field_oldd(i, k, j))))/dt
13102 fqyl(i, k, j) = mu*(dy/dt)*(0.5*min7*field_old(i, k, j-1)+0.5*&
13103 & max6*field_old(i, k, j))
13104 fqyd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k, j-1))&
13105 & -1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, &
13106 & time_step)*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(i&
13107 & , k, j-2)-3.*(field(i, k, j)-field(i, k, j-1)))) + vel*(7.*(&
13108 & fieldd(i, k, j)+fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+&
13109 & fieldd(i, k, j-2))/12.+SIGN(1, time_step)*SIGN(1., vel)*(&
13110 & fieldd(i, k, j+1)-fieldd(i, k, j-2)-3.*(fieldd(i, k, j)-&
13111 & fieldd(i, k, j-1)))/12.)
13112 fqy(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1))-&
13113 & 1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1, time_step&
13114 & )*SIGN(1., vel)*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-&
13115 & 3.*(field(i, k, j)-field(i, k, j-1))))
13116 fqyd(i, k, j) = fqyd(i, k, j) - fqyld(i, k, j)
13117 fqy(i, k, j) = fqy(i, k, j) - fqyl(i, k, j)
13121 END DO j_loop_y_flux_5
13123 !-- these bounds are for periodic and sym conditions
13125 IF (ite .GT. ide - 1) THEN
13131 i_start_f = i_start
13132 i_end_f = i_end + 1
13134 IF (jte .GT. jde - 1) THEN
13140 !-- modify loop bounds for open and specified b.c
13141 ! IF(degrade_ys) j_start = MAX(jts-1,jds+1)
13142 ! IF(degrade_ye) j_end = MIN(jte+1,jde-2)
13143 IF (degrade_ys) THEN
13144 IF (jts - 1 .LT. jds) THEN
13150 IF (degrade_ye) THEN
13151 IF (jte + 1 .GT. jde - 1) THEN
13157 IF (degrade_xs) THEN
13158 IF (ids + 1 .LT. its - 1) THEN
13163 i_start_f = ids + 3
13165 IF (degrade_xe) THEN
13166 IF (ide - 2 .GT. ite + 1) THEN
13182 DO i=i_start_f,i_end_f
13184 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
13185 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
13186 mu = 0.5*(mut(i, j)+mut(i-1, j))
13187 veld = rud(i, k, j)
13189 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
13191 IF (cr .GE. 0.) THEN
13200 IF (1.0 .GT. y6) THEN
13207 IF (cr .GE. 0.) THEN
13214 y21d = crd - abs20d
13216 IF (-1.0 .LT. y21) THEN
13223 fqxld(i, k, j) = dx*(mud*(0.5*min10*field_old(i-1, k, j)+0.5*&
13224 & max7*field_old(i, k, j))+mu*(0.5*(min10d*field_old(i-1, k, j)+&
13225 & min10*field_oldd(i-1, k, j))+0.5*(max7d*field_old(i, k, j)+&
13226 & max7*field_oldd(i, k, j))))/dt
13227 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min10*field_old(i-1, k, j)+0.5*&
13228 & max7*field_old(i, k, j))
13229 IF (vel*sign(1,time_step) .GE. 0.0) THEN
13230 qip2d = fieldd(i+1, k, j)
13231 qip2 = field(i+1, k, j)
13232 qip1d = fieldd(i, k, j)
13233 qip1 = field(i, k, j)
13234 qid = fieldd(i-1, k, j)
13235 qi = field(i-1, k, j)
13236 qim1d = fieldd(i-2, k, j)
13237 qim1 = field(i-2, k, j)
13238 qim2d = fieldd(i-3, k, j)
13239 qim2 = field(i-3, k, j)
13241 qip2d = fieldd(i-2, k, j)
13242 qip2 = field(i-2, k, j)
13243 qip1d = fieldd(i-1, k, j)
13244 qip1 = field(i-1, k, j)
13245 qid = fieldd(i, k, j)
13246 qi = field(i, k, j)
13247 qim1d = fieldd(i+1, k, j)
13248 qim1 = field(i+1, k, j)
13249 qim2d = fieldd(i+2, k, j)
13250 qim2 = field(i+2, k, j)
13252 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
13253 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
13254 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
13255 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
13256 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
13257 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
13258 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
13259 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
13260 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
13262 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
13263 & qim1-qip1)*(qim1d-qip1d)/4.
13264 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
13265 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
13266 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
13267 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
13270 pwx1 = eps1 + beta0
13271 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13273 pwr1d = pw*pwx1**(pw-1)*pwx1d
13274 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13280 wi0d = -(gi0*pwr1d/pwr1**2)
13283 pwx1 = eps1 + beta1
13284 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13286 pwr1d = pw*pwx1**(pw-1)*pwx1d
13287 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13293 wi1d = -(gi1*pwr1d/pwr1**2)
13296 pwx1 = eps1 + beta2
13297 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13299 pwr1d = pw*pwx1**(pw-1)*pwx1d
13300 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13306 wi2d = -(gi2*pwr1d/pwr1**2)
13308 sumwkd = wi0d + wi1d + wi2d
13309 sumwk = wi0 + wi1 + wi2
13310 fqxd(i, k, j) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
13311 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
13312 & +wi2*f2)*sumwkd)/sumwk**2
13313 fqx(i, k, j) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
13314 ! fqx( i,k,j ) = vel*flux5( field(i-3,k,j), field(i-2,k,j), &
13315 ! field(i-1,k,j), field(i ,k,j), &
13316 ! field(i+1,k,j), field(i+2,k,j), &
13318 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
13319 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
13322 ! lower order fluxes close to boundaries (if not periodic or symmetric)
13323 IF (degrade_xs) THEN
13324 DO i=i_start,i_start_f-1
13325 IF (i .EQ. ids + 1) THEN
13329 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
13330 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
13331 mu = 0.5*(mut(i, j)+mut(i-1, j))
13332 veld = (rud(i, k, j)*mu-ru(i, k, j)*mud)/mu**2
13333 vel = ru(i, k, j)/mu
13336 IF (cr .GE. 0.) THEN
13345 IF (1.0 .GT. y7) THEN
13352 IF (cr .GE. 0.) THEN
13359 y22d = crd - abs21d
13361 IF (-1.0 .LT. y22) THEN
13368 fqxld(i, k, j) = dx*(mud*(0.5*min11*field_old(i-1, k, j)+0.5&
13369 & *max8*field_old(i, k, j))+mu*(0.5*(min11d*field_old(i-1, k&
13370 & , j)+min11*field_oldd(i-1, k, j))+0.5*(max8d*field_old(i, &
13371 & k, j)+max8*field_oldd(i, k, j))))/dt
13372 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min11*field_old(i-1, k, j)+&
13373 & 0.5*max8*field_old(i, k, j))
13374 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
13375 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
13376 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
13378 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
13379 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
13382 IF (i .EQ. ids + 2) THEN
13386 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
13387 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
13388 mu = 0.5*(mut(i, j)+mut(i-1, j))
13389 veld = rud(i, k, j)
13391 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
13393 IF (cr .GE. 0.) THEN
13402 IF (1.0 .GT. y8) THEN
13409 IF (cr .GE. 0.) THEN
13416 y23d = crd - abs22d
13418 IF (-1.0 .LT. y23) THEN
13425 fqxld(i, k, j) = dx*(mud*(0.5*min12*field_old(i-1, k, j)+0.5&
13426 & *max9*field_old(i, k, j))+mu*(0.5*(min12d*field_old(i-1, k&
13427 & , j)+min12*field_oldd(i-1, k, j))+0.5*(max9d*field_old(i, &
13428 & k, j)+max9*field_oldd(i, k, j))))/dt
13429 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min12*field_old(i-1, k, j)+&
13430 & 0.5*max9*field_old(i, k, j))
13431 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j&
13432 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
13433 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(&
13434 & i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j)))) + vel*(&
13435 & 7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k&
13436 & , j)+fieldd(i-2, k, j))/12.+SIGN(1, time_step)*SIGN(1., &
13437 & vel)*(fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i, k&
13438 & , j)-fieldd(i-1, k, j)))/12.)
13439 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))&
13440 & -1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
13441 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(&
13442 & i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j))))
13443 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
13444 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
13449 IF (degrade_xe) THEN
13450 DO i=i_end_f+1,i_end+1
13451 IF (i .EQ. ide - 1) THEN
13452 ! second order flux next to the boundary
13455 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
13456 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
13457 mu = 0.5*(mut(i, j)+mut(i-1, j))
13458 veld = rud(i, k, j)
13460 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
13462 IF (cr .GE. 0.) THEN
13471 IF (1.0 .GT. y9) THEN
13478 IF (cr .GE. 0.) THEN
13485 y24d = crd - abs23d
13487 IF (-1.0 .LT. y24) THEN
13494 fqxld(i, k, j) = dx*(mud*(0.5*min13*field_old(i-1, k, j)+0.5&
13495 & *max10*field_old(i, k, j))+mu*(0.5*(min13d*field_old(i-1, &
13496 & k, j)+min13*field_oldd(i-1, k, j))+0.5*(max10d*field_old(i&
13497 & , k, j)+max10*field_oldd(i, k, j))))/dt
13498 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min13*field_old(i-1, k, j)+&
13499 & 0.5*max10*field_old(i, k, j))
13500 fqxd(i, k, j) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1&
13501 & , k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
13502 fqx(i, k, j) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k&
13504 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
13505 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
13508 IF (i .EQ. ide - 2) THEN
13509 ! third order flux one in from the boundary
13512 dx = 2./(msfty(i, j)+msfty(i-1, j))/rdx
13513 mud = 0.5*(mutd(i, j)+mutd(i-1, j))
13514 mu = 0.5*(mut(i, j)+mut(i-1, j))
13515 veld = rud(i, k, j)
13517 crd = (dt*veld*mu/dx-vel*dt*mud/dx)/mu**2
13519 IF (cr .GE. 0.) THEN
13528 IF (1.0 .GT. y10) THEN
13535 IF (cr .GE. 0.) THEN
13542 y25d = crd - abs24d
13544 IF (-1.0 .LT. y25) THEN
13551 fqxld(i, k, j) = dx*(mud*(0.5*min14*field_old(i-1, k, j)+0.5&
13552 & *max11*field_old(i, k, j))+mu*(0.5*(min14d*field_old(i-1, &
13553 & k, j)+min14*field_oldd(i-1, k, j))+0.5*(max11d*field_old(i&
13554 & , k, j)+max11*field_oldd(i, k, j))))/dt
13555 fqxl(i, k, j) = mu*(dx/dt)*(0.5*min14*field_old(i-1, k, j)+&
13556 & 0.5*max11*field_old(i, k, j))
13557 fqxd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j&
13558 & ))-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
13559 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(&
13560 & i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j)))) + vel*(&
13561 & 7.*(fieldd(i, k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k&
13562 & , j)+fieldd(i-2, k, j))/12.+SIGN(1, time_step)*SIGN(1., &
13563 & vel)*(fieldd(i+1, k, j)-fieldd(i-2, k, j)-3.*(fieldd(i, k&
13564 & , j)-fieldd(i-1, k, j)))/12.)
13565 fqx(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))&
13566 & -1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1, &
13567 & time_step)*SIGN(1., vel)*(1./12.)*(field(i+1, k, j)-field(&
13568 & i-2, k, j)-3.*(field(i, k, j)-field(i-1, k, j))))
13569 fqxd(i, k, j) = fqxd(i, k, j) - fqxld(i, k, j)
13570 fqx(i, k, j) = fqx(i, k, j) - fqxl(i, k, j)
13576 ! enddo for outer J loop
13577 !--- end of 5th order horizontal flux calculation
13579 ! WRITE ( wrf_err_message , * ) 'module_advect: advect_scalar_pd, h_order not known ',horz_order
13580 ! CALL wrf_error_fatal ( TRIM( wrf_err_message ) )
13581 ! ENDIF horizontal_order_test
13582 ! pick up the rest of the horizontal radiation boundary conditions.
13583 ! (these are the computations that don't require 'cb'.
13584 ! first, set to index ranges
13586 IF (ite .GT. ide - 1) THEN
13592 IF (jte .GT. jde - 1) THEN
13597 ! compute x (u) conditions for v, w, or scalar
13598 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
13601 IF (0.5*(ru(its, k, j)+ru(its+1, k, j)) .GT. 0.) THEN
13605 ubd = 0.5*(rud(its, k, j)+rud(its+1, k, j))
13606 ub = 0.5*(ru(its, k, j)+ru(its+1, k, j))
13608 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(&
13609 & field_old(its+1, k, j)-field_old(its, k, j))+ub*(field_oldd(&
13610 & its+1, k, j)-field_oldd(its, k, j))+fieldd(its, k, j)*(ru(its+&
13611 & 1, k, j)-ru(its, k, j))+field(its, k, j)*(rud(its+1, k, j)-rud&
13613 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(field_old(&
13614 & its+1, k, j)-field_old(its, k, j))+field(its, k, j)*(ru(its+1&
13615 & , k, j)-ru(its, k, j)))
13619 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
13622 IF (0.5*(ru(ite-1, k, j)+ru(ite, k, j)) .LT. 0.) THEN
13626 ubd = 0.5*(rud(ite-1, k, j)+rud(ite, k, j))
13627 ub = 0.5*(ru(ite-1, k, j)+ru(ite, k, j))
13629 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
13630 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+ub*(&
13631 & field_oldd(i_end, k, j)-field_oldd(i_end-1, k, j))+fieldd(&
13632 & i_end, k, j)*(ru(ite, k, j)-ru(ite-1, k, j))+field(i_end, k, j&
13633 & )*(rud(ite, k, j)-rud(ite-1, k, j)))
13634 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(&
13635 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+field(i_end, &
13636 & k, j)*(ru(ite, k, j)-ru(ite-1, k, j)))
13640 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
13643 IF (0.5*(rv(i, k, jts)+rv(i, k, jts+1)) .GT. 0.) THEN
13647 vbd = 0.5*(rvd(i, k, jts)+rvd(i, k, jts+1))
13648 vb = 0.5*(rv(i, k, jts)+rv(i, k, jts+1))
13650 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
13651 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
13652 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*(rv(i, k&
13653 & , jts+1)-rv(i, k, jts))+field(i, k, jts)*(rvd(i, k, jts+1)-rvd&
13655 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
13656 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*(rv(i, k, &
13657 & jts+1)-rv(i, k, jts)))
13661 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
13664 IF (0.5*(rv(i, k, jte-1)+rv(i, k, jte)) .LT. 0.) THEN
13668 vbd = 0.5*(rvd(i, k, jte-1)+rvd(i, k, jte))
13669 vb = 0.5*(rv(i, k, jte-1)+rv(i, k, jte))
13671 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
13672 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
13673 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))+fieldd(i, k&
13674 & , j_end)*(rv(i, k, jte)-rv(i, k, jte-1))+field(i, k, j_end)*(&
13675 & rvd(i, k, jte)-rvd(i, k, jte-1)))
13676 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
13677 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
13678 & j_end)*(rv(i, k, jte)-rv(i, k, jte-1)))
13682 IF (config_flags%polar .AND. jts .EQ. jds) THEN
13683 ! Assuming rv(i,k,jds) = 0.
13686 IF (0.5*rv(i, k, jts+1) .GT. 0.) THEN
13690 vbd = 0.5*rvd(i, k, jts+1)
13691 vb = 0.5*rv(i, k, jts+1)
13693 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
13694 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
13695 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*rv(i, k, &
13696 & jts+1)+field(i, k, jts)*rvd(i, k, jts+1))
13697 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
13698 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*rv(i, k, &
13703 IF (config_flags%polar .AND. jte .EQ. jde) THEN
13704 ! Assuming rv(i,k,jde) = 0.
13707 IF (0.5*rv(i, k, jte-1) .LT. 0.) THEN
13711 vbd = 0.5*rvd(i, k, jte-1)
13712 vb = 0.5*rv(i, k, jte-1)
13714 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
13715 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
13716 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))-fieldd(i, k&
13717 & , j_end)*rv(i, k, jte-1)-field(i, k, j_end)*rvd(i, k, jte-1))
13718 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
13719 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
13720 & j_end)*(-rv(i, k, jte-1)))
13724 !-------------------- vertical advection
13725 !-- loop bounds for periodic or sym conditions
13727 IF (ite .GT. ide - 1) THEN
13734 IF (jte .GT. jde - 1) THEN
13740 !-- loop bounds for open or specified conditions
13741 IF (degrade_xs) THEN
13742 IF (its - 1 .LT. ids) THEN
13748 IF (degrade_xe) THEN
13749 IF (ite + 1 .GT. ide - 1) THEN
13755 IF (degrade_ys) THEN
13756 IF (jts - 1 .LT. jds) THEN
13762 IF (degrade_ye) THEN
13763 IF (jte + 1 .GT. jde - 1) THEN
13774 ! vert_order_test : IF (vert_order == 6) THEN
13775 ! ELSE IF (vert_order == 5) THEN
13778 fqzd(i, 1, j) = 0.0
13780 fqzld(i, 1, j) = 0.0
13782 fqzd(i, kde, j) = 0.0
13783 fqz(i, kde, j) = 0.
13784 fqzld(i, kde, j) = 0.0
13785 fqzl(i, kde, j) = 0.
13789 dz = 2./(rdzw(k)+rdzw(k-1))
13790 mud = 0.5*2*mutd(i, j)
13791 mu = 0.5*(mut(i, j)+mut(i, j))
13792 veld = romd(i, k, j)
13794 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
13796 IF (cr .GE. 0.) THEN
13803 y11d = crd + abs10d
13805 IF (1.0 .GT. y11) THEN
13812 IF (cr .GE. 0.) THEN
13819 y26d = crd - abs25d
13821 IF (-1.0 .LT. y26) THEN
13828 fqzld(i, k, j) = dz*(mud*(0.5*min17*field_old(i, k-1, j)+0.5*&
13829 & max12*field_old(i, k, j))+mu*(0.5*(min17d*field_old(i, k-1, j)&
13830 & +min17*field_oldd(i, k-1, j))+0.5*(max12d*field_old(i, k, j)+&
13831 & max12*field_oldd(i, k, j))))/dt
13832 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min17*field_old(i, k-1, j)+0.5*&
13833 & max12*field_old(i, k, j))
13834 IF (-vel*sign(1,time_step) .GE. 0.0) THEN
13835 qip2d = fieldd(i, k+1, j)
13836 qip2 = field(i, k+1, j)
13837 qip1d = fieldd(i, k, j)
13838 qip1 = field(i, k, j)
13839 qid = fieldd(i, k-1, j)
13840 qi = field(i, k-1, j)
13841 qim1d = fieldd(i, k-2, j)
13842 qim1 = field(i, k-2, j)
13843 qim2d = fieldd(i, k-3, j)
13844 qim2 = field(i, k-3, j)
13846 qip2d = fieldd(i, k-2, j)
13847 qip2 = field(i, k-2, j)
13848 qip1d = fieldd(i, k-1, j)
13849 qip1 = field(i, k-1, j)
13850 qid = fieldd(i, k, j)
13851 qi = field(i, k, j)
13852 qim1d = fieldd(i, k+1, j)
13853 qim1 = field(i, k+1, j)
13854 qim2d = fieldd(i, k+2, j)
13855 qim2 = field(i, k+2, j)
13857 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
13858 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
13859 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
13860 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
13861 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
13862 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
13863 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
13864 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
13865 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
13867 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
13868 & qim1-qip1)*(qim1d-qip1d)/4.
13869 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
13870 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
13871 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
13872 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
13875 pwx1 = eps1 + beta0
13876 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13878 pwr1d = pw*pwx1**(pw-1)*pwx1d
13879 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13885 wi0d = -(gi0*pwr1d/pwr1**2)
13888 pwx1 = eps1 + beta1
13889 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13891 pwr1d = pw*pwx1**(pw-1)*pwx1d
13892 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13898 wi1d = -(gi1*pwr1d/pwr1**2)
13901 pwx1 = eps1 + beta2
13902 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
13904 pwr1d = pw*pwx1**(pw-1)*pwx1d
13905 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
13911 wi2d = -(gi2*pwr1d/pwr1**2)
13913 sumwkd = wi0d + wi1d + wi2d
13914 sumwk = wi0 + wi1 + wi2
13915 fqzd(i, k, j) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
13916 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
13917 & +wi2*f2)*sumwkd)/sumwk**2
13918 fqz(i, k, j) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
13919 ! fqz(i,k,j) = vel*flux5( field(i,k-3,j), field(i,k-2,j), field(i,k-1,j), &
13920 ! field(i,k ,j), field(i,k+1,j), field(i,k+2,j), -vel )
13921 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
13922 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
13927 dz = 2./(rdzw(k)+rdzw(k-1))
13928 mud = 0.5*2*mutd(i, j)
13929 mu = 0.5*(mut(i, j)+mut(i, j))
13930 veld = romd(i, k, j)
13932 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
13934 IF (cr .GE. 0.) THEN
13941 y12d = crd + abs11d
13943 IF (1.0 .GT. y12) THEN
13950 IF (cr .GE. 0.) THEN
13957 y27d = crd - abs26d
13959 IF (-1.0 .LT. y27) THEN
13966 fqzld(i, k, j) = dz*(mud*(0.5*min18*field_old(i, k-1, j)+0.5*max13&
13967 & *field_old(i, k, j))+mu*(0.5*(min18d*field_old(i, k-1, j)+min18*&
13968 & field_oldd(i, k-1, j))+0.5*(max13d*field_old(i, k, j)+max13*&
13969 & field_oldd(i, k, j))))/dt
13970 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min18*field_old(i, k-1, j)+0.5*&
13971 & max13*field_old(i, k, j))
13972 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
13973 & i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*fieldd&
13975 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
13977 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
13978 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
13980 dz = 2./(rdzw(k)+rdzw(k-1))
13981 mud = 0.5*2*mutd(i, j)
13982 mu = 0.5*(mut(i, j)+mut(i, j))
13983 veld = romd(i, k, j)
13985 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
13987 IF (cr .GE. 0.) THEN
13994 y13d = crd + abs12d
13996 IF (1.0 .GT. y13) THEN
14003 IF (cr .GE. 0.) THEN
14010 y28d = crd - abs27d
14012 IF (-1.0 .LT. y28) THEN
14019 fqzld(i, k, j) = dz*(mud*(0.5*min19*field_old(i, k-1, j)+0.5*max14&
14020 & *field_old(i, k, j))+mu*(0.5*(min19d*field_old(i, k-1, j)+min19*&
14021 & field_oldd(i, k-1, j))+0.5*(max14d*field_old(i, k, j)+max14*&
14022 & field_oldd(i, k, j))))/dt
14023 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min19*field_old(i, k-1, j)+0.5*&
14024 & max14*field_old(i, k, j))
14025 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
14026 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*SIGN(&
14027 & 1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
14028 & i, k, j)-field(i, k-1, j)))) + vel*(7.*(fieldd(i, k, j)+fieldd(i&
14029 & , k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k-2, j))/12.+SIGN(1&
14030 & , time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-fieldd(i, k-2, j)&
14031 & -3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.)
14032 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
14033 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*SIGN(&
14034 & 1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
14035 & i, k, j)-field(i, k-1, j))))
14036 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
14037 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
14039 dz = 2./(rdzw(k)+rdzw(k-1))
14040 mud = 0.5*2*mutd(i, j)
14041 mu = 0.5*(mut(i, j)+mut(i, j))
14042 veld = romd(i, k, j)
14044 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
14046 IF (cr .GE. 0.) THEN
14053 y14d = crd + abs13d
14055 IF (1.0 .GT. y14) THEN
14062 IF (cr .GE. 0.) THEN
14069 y29d = crd - abs28d
14071 IF (-1.0 .LT. y29) THEN
14078 fqzld(i, k, j) = dz*(mud*(0.5*min20*field_old(i, k-1, j)+0.5*max15&
14079 & *field_old(i, k, j))+mu*(0.5*(min20d*field_old(i, k-1, j)+min20*&
14080 & field_oldd(i, k-1, j))+0.5*(max15d*field_old(i, k, j)+max15*&
14081 & field_oldd(i, k, j))))/dt
14082 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min20*field_old(i, k-1, j)+0.5*&
14083 & max15*field_old(i, k, j))
14084 fqzd(i, k, j) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
14085 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*SIGN(&
14086 & 1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
14087 & i, k, j)-field(i, k-1, j)))) + vel*(7.*(fieldd(i, k, j)+fieldd(i&
14088 & , k-1, j))/12.-(fieldd(i, k+1, j)+fieldd(i, k-2, j))/12.+SIGN(1&
14089 & , time_step)*SIGN(1., -vel)*(fieldd(i, k+1, j)-fieldd(i, k-2, j)&
14090 & -3.*(fieldd(i, k, j)-fieldd(i, k-1, j)))/12.)
14091 fqz(i, k, j) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
14092 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1, time_step)*SIGN(&
14093 & 1., -vel)*(1./12.)*(field(i, k+1, j)-field(i, k-2, j)-3.*(field(&
14094 & i, k, j)-field(i, k-1, j))))
14095 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
14096 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
14098 dz = 2./(rdzw(k)+rdzw(k-1))
14099 mud = 0.5*2*mutd(i, j)
14100 mu = 0.5*(mut(i, j)+mut(i, j))
14101 veld = romd(i, k, j)
14103 crd = (dt*veld*mu/dz-vel*dt*mud/dz)/mu**2
14105 IF (cr .GE. 0.) THEN
14112 y15d = crd + abs14d
14114 IF (1.0 .GT. y15) THEN
14121 IF (cr .GE. 0.) THEN
14128 y30d = crd - abs29d
14130 IF (-1.0 .LT. y30) THEN
14137 fqzld(i, k, j) = dz*(mud*(0.5*min21*field_old(i, k-1, j)+0.5*max16&
14138 & *field_old(i, k, j))+mu*(0.5*(min21d*field_old(i, k-1, j)+min21*&
14139 & field_oldd(i, k-1, j))+0.5*(max16d*field_old(i, k, j)+max16*&
14140 & field_oldd(i, k, j))))/dt
14141 fqzl(i, k, j) = mu*(dz/dt)*(0.5*min21*field_old(i, k-1, j)+0.5*&
14142 & max16*field_old(i, k, j))
14143 fqzd(i, k, j) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(&
14144 & i, k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*fieldd&
14146 fqz(i, k, j) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
14148 fqzd(i, k, j) = fqzd(i, k, j) - fqzld(i, k, j)
14149 fqz(i, k, j) = fqz(i, k, j) - fqzl(i, k, j)
14153 ! WRITE (wrf_err_message,*) ' advect_scalar_pd, v_order not known ',vert_order
14154 ! CALL wrf_error_fatal ( wrf_err_message )
14155 ! ENDIF vert_order_test
14157 ! positive definite filter
14159 IF (ite .GT. ide - 1) THEN
14166 IF (jte .GT. jde - 1) THEN
14172 !-- loop bounds for open or specified conditions
14173 IF (degrade_xs) THEN
14174 IF (its - 1 .LT. ids) THEN
14180 IF (degrade_xe) THEN
14181 IF (ite + 1 .GT. ide - 1) THEN
14187 IF (degrade_ys) THEN
14188 IF (jts - 1 .LT. jds) THEN
14194 IF (degrade_ye) THEN
14195 IF (jte + 1 .GT. jde - 1) THEN
14201 IF (config_flags%specified .OR. config_flags%nested) THEN
14202 IF (degrade_xs) THEN
14203 IF (its - 1 .LT. ids + 1) THEN
14209 IF (degrade_xe) THEN
14210 IF (ite + 1 .GT. ide - 2) THEN
14216 IF (degrade_ys) THEN
14217 IF (jts - 1 .LT. jds + 1) THEN
14223 IF (degrade_ye) THEN
14224 IF (jte + 1 .GT. jde - 2) THEN
14231 IF (config_flags%open_xs) THEN
14232 IF (degrade_xs) THEN
14233 IF (its - 1 .LT. ids + 1) THEN
14240 IF (config_flags%open_xe) THEN
14241 IF (degrade_xe) THEN
14242 IF (ite + 1 .GT. ide - 2) THEN
14249 IF (config_flags%open_ys) THEN
14250 IF (degrade_ys) THEN
14251 IF (jts - 1 .LT. jds + 1) THEN
14258 IF (config_flags%open_ye) THEN
14259 IF (degrade_ye) THEN
14260 IF (jte + 1 .GT. jde - 2) THEN
14273 ! We don't want to change j_start and j_end
14274 ! for polar BC's since we want to calculate
14275 ! fluxes for directions other than y at the
14277 !-- here is the limiter...
14281 ph_lowd(i,k,j) = mu_oldd(i, j)*field_old(i, k, j) + (mub(i, j)+mu_old&
14282 & (i, j))*field_oldd(i, k, j) - dt*(msftx(i, j)*msfty(i, j)*(&
14283 & rdx*(fqxld(i+1, k, j)-fqxld(i, k, j))+rdy*(fqyld(i, k, j+1)-&
14284 & fqyld(i, k, j)))+msfty(i, j)*rdzw(k)*(fqzld(i, k+1, j)-fqzld&
14286 ph_low(i,k,j) = (mub(i, j)+mu_old(i, j))*field_old(i, k, j) - dt*(&
14287 & msftx(i, j)*msfty(i, j)*(rdx*(fqxl(i+1, k, j)-fqxl(i, k, j))&
14288 & +rdy*(fqyl(i, k, j+1)-fqyl(i, k, j)))+msfty(i, j)*rdzw(k)*(&
14289 & fqzl(i, k+1, j)-fqzl(i, k, j)))
14296 !DIR$ vector always
14298 IF (0. .LT. fqx(i+1, k, j)) THEN
14299 max1d = fqxd(i+1, k, j)
14300 max1 = fqx(i+1, k, j)
14305 IF (0. .GT. fqx(i, k, j)) THEN
14306 min24d = fqxd(i, k, j)
14307 min24 = fqx(i, k, j)
14312 IF (0. .LT. fqy(i, k, j+1)) THEN
14313 max17d = fqyd(i, k, j+1)
14314 max17 = fqy(i, k, j+1)
14319 IF (0. .GT. fqy(i, k, j)) THEN
14320 min25d = fqyd(i, k, j)
14321 min25 = fqy(i, k, j)
14326 IF (0. .GT. fqz(i, k+1, j)) THEN
14327 min26d = fqzd(i, k+1, j)
14328 min26 = fqz(i, k+1, j)
14333 IF (0. .LT. fqz(i, k, j)) THEN
14334 max18d = fqzd(i, k, j)
14335 max18 = fqz(i, k, j)
14340 flux_outd(i,k,j) = dt*(msftx(i, j)*msfty(i, j)*(rdx*(max1d-min24d)+&
14341 & rdy*(max17d-min25d))+msfty(i, j)*rdzw(k)*(min26d-max18d))
14342 flux_out(i,k,j) = dt*(msftx(i, j)*msfty(i, j)*(rdx*(max1-min24)+rdy*(&
14343 & max17-min25))+msfty(i, j)*rdzw(k)*(min26-max18))
14350 IF (flux_out(i,k,j) .GT. ph_low(i,k,j)) THEN
14351 IF (0. .LT. ph_low(i,k,j)/(flux_out(i,k,j)+eps)) THEN
14352 scaled = (ph_lowd(i,k,j)*(flux_out(i,k,j)+eps)-ph_low(i,k,j)*flux_outd(i,k,j))/(&
14353 & flux_out(i,k,j)+eps)**2
14354 scale = ph_low(i,k,j)/(flux_out(i,k,j)+eps)
14359 IF (fqx(i+1, k, j) .GT. 0.) THEN
14360 fqxd(i+1, k, j) = scaled*fqx(i+1, k, j) + scale*fqxd(i+1, &
14362 fqx(i+1, k, j) = scale*fqx(i+1, k, j)
14364 IF (fqx(i, k, j) .LT. 0.) THEN
14365 fqxd(i, k, j) = scaled*fqx(i, k, j) + scale*fqxd(i, k, j)
14366 fqx(i, k, j) = scale*fqx(i, k, j)
14368 IF (fqy(i, k, j+1) .GT. 0.) THEN
14369 fqyd(i, k, j+1) = scaled*fqy(i, k, j+1) + scale*fqyd(i, k&
14371 fqy(i, k, j+1) = scale*fqy(i, k, j+1)
14373 IF (fqy(i, k, j) .LT. 0.) THEN
14374 fqyd(i, k, j) = scaled*fqy(i, k, j) + scale*fqyd(i, k, j)
14375 fqy(i, k, j) = scale*fqy(i, k, j)
14377 ! note: z flux is opposite sign in mass coordinate because
14378 ! vertical coordinate decreases with increasing k
14379 IF (fqz(i, k+1, j) .LT. 0.) THEN
14380 fqzd(i, k+1, j) = scaled*fqz(i, k+1, j) + scale*fqzd(i, k+&
14382 fqz(i, k+1, j) = scale*fqz(i, k+1, j)
14384 IF (fqz(i, k, j) .GT. 0.) THEN
14385 fqzd(i, k, j) = scaled*fqz(i, k, j) + scale*fqzd(i, k, j)
14386 fqz(i, k, j) = scale*fqz(i, k, j)
14393 ! add in the pd-limited flux divergence
14395 IF (ite .GT. ide - 1) THEN
14401 IF (jte .GT. jde - 1) THEN
14409 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(fqzd(i, k+1, &
14410 & j)-fqzd(i, k, j)+fqzld(i, k+1, j)-fqzld(i, k, j))
14411 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(fqz(i, k+1, j)-&
14412 & fqz(i, k, j)+fqzl(i, k+1, j)-fqzl(i, k, j))
14416 ! x flux divergence
14418 IF (degrade_xs) THEN
14419 IF (its .LT. ids + 1) THEN
14425 IF (degrade_xe) THEN
14426 IF (ite .GT. ide - 2) THEN
14435 ! Un-"canceled" map scale factor, ADT Eq. 48
14436 tendencyd(i, k, j) = tendencyd(i, k, j) - msftx(i, j)*rdx*(fqxd(&
14437 & i+1, k, j)-fqxd(i, k, j)+fqxld(i+1, k, j)-fqxld(i, k, j))
14438 tendency(i, k, j) = tendency(i, k, j) - msftx(i, j)*(rdx*(fqx(i+&
14439 & 1, k, j)-fqx(i, k, j)+fqxl(i+1, k, j)-fqxl(i, k, j)))
14443 ! y flux divergence
14446 IF (ite .GT. ide - 1) THEN
14451 IF (degrade_ys) THEN
14452 IF (jts .LT. jds + 1) THEN
14458 IF (degrade_ye) THEN
14459 IF (jte .GT. jde - 2) THEN
14468 ! Un-"canceled" map scale factor, ADT Eq. 48
14469 ! It is correct to use msftx (and not msfty), per W. Skamarock, 20080606
14470 tendencyd(i, k, j) = tendencyd(i, k, j) - msftx(i, j)*rdy*(fqyd(&
14471 & i, k, j+1)-fqyd(i, k, j)+fqyld(i, k, j+1)-fqyld(i, k, j))
14472 tendency(i, k, j) = tendency(i, k, j) - msftx(i, j)*(rdy*(fqy(i&
14473 & , k, j+1)-fqy(i, k, j)+fqyl(i, k, j+1)-fqyl(i, k, j)))
14477 END SUBROUTINE G_ADVECT_SCALAR_WENOPD
14479 SUBROUTINE g_advect_scalar_mono(field,g_field,field_old,g_field_old, &
14480 tendency,g_tendency,h_tendency,g_h_tendency,z_tendency,g_z_tendency,ru,g_ru,rv,g_rv,rom,g_rom,mut,g_mut,mub,mu_old, &
14481 g_mu_old,config_flags,tenddec,msfux,msfuy,msfvx,msfvy,msftx,msfty,fzm,fzp,rdx,rdy,rdzw,dt, &
14482 ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
14486 REAL :: Tmpv1,g_Tmpv1,Tmpv2,g_Tmpv2,Tmpv3,g_Tmpv3,Tmpv4,g_Tmpv4,Tmpv5, &
14487 g_Tmpv5,Tmpv6,g_Tmpv6,Tmpv7,g_Tmpv7,Tmpv8,g_Tmpv8
14489 REAL g_FuncVal1,FuncVal1
14490 TYPE(grid_config_rec_type) :: config_flags
14492 INTEGER :: ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte
14493 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: field,g_field,field_old,g_field_old, &
14494 ru,g_ru,rv,g_rv,rom,g_rom
14495 REAL,DIMENSION(ims:ime,jms:jme) :: mut,g_mut,mub,mu_old,g_mu_old
14496 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: tendency,g_tendency
14497 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: h_tendency, z_tendency
14498 REAL,DIMENSION(ims:ime,kms:kme,jms:jme) :: g_h_tendency, g_z_tendency
14499 REAL,DIMENSION(ims:ime,jms:jme) :: msfux,msfuy,msfvx,msfvy,msftx,msfty
14500 REAL,DIMENSION(kms:kme) :: fzm,fzp,rdzw
14503 INTEGER :: i,j,k,itf,jtf,ktf
14504 INTEGER :: i_start,i_end,j_start,j_end
14505 INTEGER :: i_start_f,i_end_f,j_start_f,j_end_f
14506 INTEGER :: jmin,jmax,jp,jm,imin,imax
14507 REAL :: mrdx,g_mrdx,mrdy,g_mrdy,ub,g_ub,vb,g_vb,uw,g_uw,vw,g_vw,mu,g_mu
14508 REAL,DIMENSION(its:ite,kts:kte) :: vflux,g_vflux
14509 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: fqx,g_fqx,fqy,g_fqy,fqz,g_fqz
14510 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: fqxl,g_fqxl,fqyl,g_fqyl, &
14512 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: qmin,g_qmin,qmax,g_qmax
14513 REAL,DIMENSION(its-2:ite+2,kts:kte,jts-2:jte+2) :: scale_in,g_scale_in,scale_out, &
14515 REAL :: ph_upwind,g_ph_upwind
14516 INTEGER :: horz_order,vert_order
14517 LOGICAL :: degrade_xs,degrade_ys
14518 LOGICAL :: degrade_xe,degrade_ye
14519 INTEGER :: jp1,jp0,jtmp
14520 REAL :: flux_out,g_flux_out,ph_low,g_ph_low,flux_in,g_flux_in,ph_hi, &
14521 g_ph_hi,scale,g_scale
14522 REAL,PARAMETER :: eps =1.e-20
14523 REAL :: flux3,g_flux3,flux4,g_flux4,flux5,g_flux5,flux6,g_flux6, &
14524 flux_upwind,g_flux_upwind
14525 REAL :: q_im3,g_q_im3,q_im2,g_q_im2,q_im1,g_q_im1,q_i,g_q_i,q_ip1, &
14526 g_q_ip1,q_ip2,g_q_ip2,ua,g_ua,vel,g_vel,cr,g_cr
14528 ! Revised by Ning Pan, 2010-07-25
14529 ! g_flux4(g_q_im2, q_im2,g_q_im1, q_im1,g_q_i, q_i,g_q_ip1, q_ip1, &
14530 ! g_ua, ua) =(7./12.)*(g_q_i +g_q_im1) -(1./12.)*(g_q_ip1 +g_q_im2)
14531 g_flux4(q_im2, g_q_im2,q_im1, g_q_im1,q_i, g_q_i,q_ip1, g_q_ip1, &
14532 ua, g_ua) =(7./12.)*(g_q_i +g_q_im1) -(1./12.)*(g_q_ip1 +g_q_im2)
14533 flux4(q_im2,q_im1,q_i,q_ip1,ua) =(7./12.)*(q_i +q_im1) -(1./12.)*(q_ip1 +q_im2)
14535 ! Revised by Ning Pan, 2010-07-25
14536 ! g_flux3(g_q_im2, q_im2,g_q_im1, q_im1,g_q_i, q_i,g_q_ip1, q_ip1, &
14537 ! g_ua, ua) =g_flux4(q_im2,g_q_im2,q_im1,g_q_im1,q_i,g_q_i,q_ip1, &
14538 g_flux3(q_im2, g_q_im2,q_im1, g_q_im1,q_i, g_q_i,q_ip1, g_q_ip1, &
14539 ua, g_ua) =g_flux4(q_im2,g_q_im2,q_im1,g_q_im1,q_i,g_q_i,q_ip1, &
14540 g_q_ip1,ua,g_ua) +sign(1., ua) *(1./12.)*((g_q_ip1 -g_q_im2) &
14541 -3.*(g_q_i -g_q_im1))
14542 flux3(q_im2,q_im1,q_i,q_ip1,ua) =flux4(q_im2,q_im1,q_i,q_ip1,ua) +sign(1., ua) &
14543 *(1./12.)*((q_ip1 -q_im2) -3.*(q_i -q_im1))
14545 ! Revised by Ning Pan, 2010-07-25
14546 ! g_flux6(g_q_im3, q_im3,g_q_im2, q_im2,g_q_im1, q_im1,g_q_i, q_i, &
14547 ! g_q_ip1, q_ip1,g_q_ip2, q_ip2,g_ua, ua) =(37./60.)*(g_q_i +g_q_im1) &
14548 g_flux6(q_im3, g_q_im3,q_im2, g_q_im2,q_im1, g_q_im1,q_i, g_q_i, &
14549 q_ip1, g_q_ip1,q_ip2, g_q_ip2,ua, g_ua) =(37./60.)*(g_q_i +g_q_im1) &
14550 -(2./15.)*(g_q_ip1 +g_q_im2) +(1./60.)*(g_q_ip2 +g_q_im3)
14551 flux6(q_im3,q_im2,q_im1,q_i,q_ip1,q_ip2,ua) =(37./60.)*(q_i +q_im1) -(2./15.) &
14552 *(q_ip1 +q_im2) +(1./60.)*(q_ip2 +q_im3)
14554 ! Revised by Ning Pan, 2010-07-25
14555 ! g_flux5(g_q_im3, q_im3,g_q_im2, q_im2,g_q_im1, q_im1,g_q_i, q_i, &
14556 ! g_q_ip1, q_ip1,g_q_ip2, q_ip2,g_ua, ua) =g_flux6(q_im3,g_q_im3,q_im2, &
14557 g_flux5(q_im3, g_q_im3,q_im2, g_q_im2,q_im1, g_q_im1,q_i, g_q_i, &
14558 q_ip1, g_q_ip1,q_ip2, g_q_ip2,ua, g_ua) =g_flux6(q_im3,g_q_im3,q_im2, &
14559 g_q_im2,q_im1,g_q_im1,q_i,g_q_i,q_ip1,g_q_ip1,q_ip2,g_q_ip2,ua, &
14560 g_ua) -sign(1., ua) *(1./60.)*((g_q_ip2 -g_q_im3) -5.*(g_q_ip1 - &
14561 g_q_im2) +10.*(g_q_i -g_q_im1))
14562 flux5(q_im3,q_im2,q_im1,q_i,q_ip1,q_ip2,ua) =flux6(q_im3,q_im2,q_im1,q_i,q_ip1,q_ip2, &
14563 ua) -sign(1., ua) *(1./60.)*((q_ip2 -q_im3) -5.*(q_ip1 -q_im2) +10.*(q_i -q_im1))
14565 ! Revised by Ning Pan, 2010-07-25
14566 ! g_flux_upwind(g_q_im1, q_im1,g_q_i, q_i,g_cr, cr) =0.5 *(1.+sign(1., cr)) &
14567 g_flux_upwind(q_im1, g_q_im1,q_i, g_q_i,cr, g_cr) =0.5 *(1.+sign(1., cr)) &
14568 *g_q_im1 +0.5 *(1.-sign(1., cr))*g_q_i
14569 flux_upwind(q_im1,q_i,cr) =0.5 *(1.+sign(1., cr))*q_im1 +0.5 *(1.-sign(1., cr))*q_i
14571 LOGICAL,PARAMETER :: mono_limit =.true.
14573 ktf =min(kte,kde-1)
14575 horz_order =config_flags%h_sca_adv_order
14577 vert_order =config_flags%v_sca_adv_order
14579 ! Added by Ning Pan, 2010-07-27
14584 IF( config_flags%periodic_x .or. &
14585 config_flags%symmetric_xs .or. &
14586 (its > ids+3) ) degrade_xs =.false.
14587 IF( config_flags%periodic_x .or. &
14588 config_flags%symmetric_xe .or. &
14589 (ite < ide-4) ) degrade_xe =.false.
14590 IF( config_flags%periodic_y .or. &
14591 config_flags%symmetric_ys .or. &
14592 (jts > jds+3) ) degrade_ys =.false.
14593 IF( config_flags%periodic_y .or. &
14594 config_flags%symmetric_ye .or. &
14595 (jte < jde-4) ) degrade_ye =.false.
14601 g_qmin(i,k,j) =g_field_old(i,k,j)
14602 qmin(i,k,j) =field_old(i,k,j)
14604 g_qmax(i,k,j) =g_field_old(i,k,j)
14605 qmax(i,k,j) =field_old(i,k,j)
14607 g_scale_in(i,k,j) =0.0
14608 scale_in(i,k,j) =1.
14610 g_scale_out(i,k,j) =0.0
14611 scale_out(i,k,j) =1.
14635 IF( horz_order == 5 ) THEN
14637 ! degrade_xs =.true.
14639 ! degrade_xe =.true.
14641 ! degrade_ys =.true.
14643 ! degrade_ye =.true.
14645 ! IF( config_flags%periodic_x .or. &
14646 ! config_flags%symmetric_xs .or. &
14647 ! (its > ids+3) ) degrade_xs =.false.
14649 ! IF( config_flags%periodic_x .or. &
14650 ! config_flags%symmetric_xe .or. &
14651 ! (ite < ide-4) ) degrade_xe =.false.
14653 ! IF( config_flags%periodic_y .or. &
14654 ! config_flags%symmetric_ys .or. &
14655 ! (jts > jds+3) ) degrade_ys =.false.
14657 ! IF( config_flags%periodic_y .or. &
14658 ! config_flags%symmetric_ye .or. &
14659 ! (jte < jde-4) ) degrade_ye =.false.
14661 ktf =min(kte,kde-1)
14665 i_end =min(ite,ide-1) +1
14669 j_end =min(jte,jde-1) +1
14675 IF(degrade_xs) i_start =max(its-1,ids)
14677 IF(degrade_xe) i_end =min(ite+1,ide-1)
14679 IF(degrade_ys) THEN
14681 j_start =max(jts-1,jds+1)
14686 IF(degrade_ye) THEN
14688 j_end =min(jte+1,jde-2)
14693 DO j =j_start,j_end+1
14695 IF( (j >= j_start_f ) .and. (j <= j_end_f) ) THEN
14698 DO i =i_start,i_end
14706 g_FuncVal1=g_flux_upwind(field_old(i,k,j-1),g_field_old(i,k,j-1) &
14707 ,field_old(i,k,j),g_field_old(i,k,j),vel,g_vel)
14708 FuncVal1 =flux_upwind(field_old(i,k,j-1),field_old(i,k,j),vel)
14710 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14711 Tmpv1 =vel*FuncVal1
14713 g_fqyl(i,k,j) =g_Tmpv1
14716 g_FuncVal1=g_flux5(field(i,k,j-3),g_field(i,k,j-3),field(i,k,j-2) &
14717 ,g_field(i,k,j-2),field(i,k,j-1),g_field(i,k,j-1),field(i,k,j),g_field(i,k, &
14718 j),field(i,k,j+1),g_field(i,k,j+1),field(i,k,j+2),g_field(i,k,j+2),vel,g_vel)
14719 FuncVal1 =flux5(field(i,k,j-3),field(i,k,j-2),field(i,k,j-1),field(i,k,j) &
14720 ,field(i,k,j+1),field(i,k,j+2),vel)
14722 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14723 Tmpv1 =vel*FuncVal1
14725 g_fqy(i,k,j) =g_Tmpv1
14728 g_fqy(i,k,j) =g_fqy(i,k,j) -g_fqyl(i,k,j)
14729 fqy(i,k,j) =fqy(i,k,j) -fqyl(i,k,j)
14733 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k,j-1) +(g_qmax(i,k,j) &
14734 -g_field_old(i,k,j-1))*sign(1.0, qmax(i,k,j) -(field_old(i,k,j-1))))*0.5
14735 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k,j-1))
14737 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k,j-1) -(g_qmin(i,k,j) &
14738 -g_field_old(i,k,j-1))*sign(1.0, qmin(i,k,j) -(field_old(i,k,j-1))))*0.5
14739 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k,j-1))
14743 g_qmax(i,k,j-1) =(g_qmax(i,k,j-1) +g_field_old(i,k,j) +(g_qmax(i,k,j-1) &
14744 -g_field_old(i,k,j))*sign(1.0, qmax(i,k,j-1) -(field_old(i,k,j))))*0.5
14745 qmax(i,k,j-1) =max(qmax(i,k,j-1),field_old(i,k,j))
14747 g_qmin(i,k,j-1) =(g_qmin(i,k,j-1) +g_field_old(i,k,j) -(g_qmin(i,k,j-1) &
14748 -g_field_old(i,k,j))*sign(1.0, qmin(i,k,j-1) -(field_old(i,k,j))))*0.5
14749 qmin(i,k,j-1) =min(qmin(i,k,j-1),field_old(i,k,j))
14755 ELSE IF( j == jds+1 ) THEN
14758 DO i =i_start,i_end
14766 g_FuncVal1=g_flux_upwind(field_old(i,k,j-1),g_field_old(i,k,j-1) &
14767 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
14768 FuncVal1 =flux_upwind(field_old(i,k,j-1),field_old(i,k,j),cr)
14770 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14771 Tmpv1 =vel*FuncVal1
14773 g_fqyl(i,k,j) =g_Tmpv1
14776 g_Tmpv1 =0.5*rv(i,k,j)*(g_field(i,k,j) +g_field(i,k,j-1)) +0.5*g_rv(i,k, &
14777 j)*(field(i,k,j) +field(i,k,j-1))
14778 Tmpv1 =0.5*rv(i,k,j)*(field(i,k,j) +field(i,k,j-1))
14780 g_fqy(i,k,j) =g_Tmpv1
14783 g_fqy(i,k,j) =g_fqy(i,k,j) -g_fqyl(i,k,j)
14784 fqy(i,k,j) =fqy(i,k,j) -fqyl(i,k,j)
14788 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k,j-1) +(g_qmax(i,k,j) &
14789 -g_field_old(i,k,j-1))*sign(1.0, qmax(i,k,j) -(field_old(i,k,j-1))))*0.5
14790 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k,j-1))
14792 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k,j-1) -(g_qmin(i,k,j) &
14793 -g_field_old(i,k,j-1))*sign(1.0, qmin(i,k,j) -(field_old(i,k,j-1))))*0.5
14794 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k,j-1))
14798 g_qmax(i,k,j-1) =(g_qmax(i,k,j-1) +g_field_old(i,k,j) +(g_qmax(i,k,j-1) &
14799 -g_field_old(i,k,j))*sign(1.0, qmax(i,k,j-1) -(field_old(i,k,j))))*0.5
14800 qmax(i,k,j-1) =max(qmax(i,k,j-1),field_old(i,k,j))
14802 g_qmin(i,k,j-1) =(g_qmin(i,k,j-1) +g_field_old(i,k,j) -(g_qmin(i,k,j-1) &
14803 -g_field_old(i,k,j))*sign(1.0, qmin(i,k,j-1) -(field_old(i,k,j))))*0.5
14804 qmin(i,k,j-1) =min(qmin(i,k,j-1),field_old(i,k,j))
14810 ELSE IF( j == jds+2 ) THEN
14813 DO i =i_start,i_end
14821 g_FuncVal1=g_flux_upwind(field_old(i,k,j-1),g_field_old(i,k,j-1) &
14822 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
14823 FuncVal1 =flux_upwind(field_old(i,k,j-1),field_old(i,k,j),cr)
14825 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14826 Tmpv1 =vel*FuncVal1
14828 g_fqyl(i,k,j) =g_Tmpv1
14831 g_FuncVal1=g_flux3(field(i,k,j-2),g_field(i,k,j-2),field(i,k,j-1) &
14832 ,g_field(i,k,j-1),field(i,k,j),g_field(i,k,j),field(i,k,j+1),g_field(i,k,j+ &
14834 FuncVal1 =flux3(field(i,k,j-2),field(i,k,j-1),field(i,k,j),field(i,k,j+1),vel)
14836 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14837 Tmpv1 =vel*FuncVal1
14839 g_fqy(i,k,j) =g_Tmpv1
14842 g_fqy(i,k,j) =g_fqy(i,k,j) -g_fqyl(i,k,j)
14843 fqy(i,k,j) =fqy(i,k,j) -fqyl(i,k,j)
14847 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k,j-1) +(g_qmax(i,k,j) &
14848 -g_field_old(i,k,j-1))*sign(1.0, qmax(i,k,j) -(field_old(i,k,j-1))))*0.5
14849 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k,j-1))
14851 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k,j-1) -(g_qmin(i,k,j) &
14852 -g_field_old(i,k,j-1))*sign(1.0, qmin(i,k,j) -(field_old(i,k,j-1))))*0.5
14853 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k,j-1))
14857 g_qmax(i,k,j-1) =(g_qmax(i,k,j-1) +g_field_old(i,k,j) +(g_qmax(i,k,j-1) &
14858 -g_field_old(i,k,j))*sign(1.0, qmax(i,k,j-1) -(field_old(i,k,j))))*0.5
14859 qmax(i,k,j-1) =max(qmax(i,k,j-1),field_old(i,k,j))
14861 g_qmin(i,k,j-1) =(g_qmin(i,k,j-1) +g_field_old(i,k,j) -(g_qmin(i,k,j-1) &
14862 -g_field_old(i,k,j))*sign(1.0, qmin(i,k,j-1) -(field_old(i,k,j))))*0.5
14863 qmin(i,k,j-1) =min(qmin(i,k,j-1),field_old(i,k,j))
14869 ELSE IF( j == jde-1 ) THEN
14872 DO i =i_start,i_end
14880 g_FuncVal1=g_flux_upwind(field_old(i,k,j-1),g_field_old(i,k,j-1) &
14881 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
14882 FuncVal1 =flux_upwind(field_old(i,k,j-1),field_old(i,k,j),cr)
14884 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14885 Tmpv1 =vel*FuncVal1
14887 g_fqyl(i,k,j) =g_Tmpv1
14890 g_Tmpv1 =0.5*rv(i,k,j)*(g_field(i,k,j) +g_field(i,k,j-1)) +0.5*g_rv(i,k, &
14891 j)*(field(i,k,j) +field(i,k,j-1))
14892 Tmpv1 =0.5*rv(i,k,j)*(field(i,k,j) +field(i,k,j-1))
14894 g_fqy(i,k,j) =g_Tmpv1
14897 g_fqy(i,k,j) =g_fqy(i,k,j) -g_fqyl(i,k,j)
14898 fqy(i,k,j) =fqy(i,k,j) -fqyl(i,k,j)
14902 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k,j-1) +(g_qmax(i,k,j) &
14903 -g_field_old(i,k,j-1))*sign(1.0, qmax(i,k,j) -(field_old(i,k,j-1))))*0.5
14904 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k,j-1))
14906 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k,j-1) -(g_qmin(i,k,j) &
14907 -g_field_old(i,k,j-1))*sign(1.0, qmin(i,k,j) -(field_old(i,k,j-1))))*0.5
14908 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k,j-1))
14912 g_qmax(i,k,j-1) =(g_qmax(i,k,j-1) +g_field_old(i,k,j) +(g_qmax(i,k,j-1) &
14913 -g_field_old(i,k,j))*sign(1.0, qmax(i,k,j-1) -(field_old(i,k,j))))*0.5
14914 qmax(i,k,j-1) =max(qmax(i,k,j-1),field_old(i,k,j))
14916 g_qmin(i,k,j-1) =(g_qmin(i,k,j-1) +g_field_old(i,k,j) -(g_qmin(i,k,j-1) &
14917 -g_field_old(i,k,j))*sign(1.0, qmin(i,k,j-1) -(field_old(i,k,j))))*0.5
14918 qmin(i,k,j-1) =min(qmin(i,k,j-1),field_old(i,k,j))
14924 ELSE IF( j == jde-2 ) THEN
14927 DO i =i_start,i_end
14935 g_FuncVal1=g_flux_upwind(field_old(i,k,j-1),g_field_old(i,k,j-1) &
14936 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
14937 FuncVal1 =flux_upwind(field_old(i,k,j-1),field_old(i,k,j),cr)
14939 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14940 Tmpv1 =vel*FuncVal1
14942 g_fqyl(i,k,j) =g_Tmpv1
14945 g_FuncVal1=g_flux3(field(i,k,j-2),g_field(i,k,j-2),field(i,k,j-1) &
14946 ,g_field(i,k,j-1),field(i,k,j),g_field(i,k,j),field(i,k,j+1),g_field(i,k,j+ &
14948 FuncVal1 =flux3(field(i,k,j-2),field(i,k,j-1),field(i,k,j),field(i,k,j+1),vel)
14950 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
14951 Tmpv1 =vel*FuncVal1
14953 g_fqy(i,k,j) =g_Tmpv1
14956 g_fqy(i,k,j) =g_fqy(i,k,j) -g_fqyl(i,k,j)
14957 fqy(i,k,j) =fqy(i,k,j) -fqyl(i,k,j)
14961 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k,j-1) +(g_qmax(i,k,j) &
14962 -g_field_old(i,k,j-1))*sign(1.0, qmax(i,k,j) -(field_old(i,k,j-1))))*0.5
14963 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k,j-1))
14965 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k,j-1) -(g_qmin(i,k,j) &
14966 -g_field_old(i,k,j-1))*sign(1.0, qmin(i,k,j) -(field_old(i,k,j-1))))*0.5
14967 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k,j-1))
14971 g_qmax(i,k,j-1) =(g_qmax(i,k,j-1) +g_field_old(i,k,j) +(g_qmax(i,k,j-1) &
14972 -g_field_old(i,k,j))*sign(1.0, qmax(i,k,j-1) -(field_old(i,k,j))))*0.5
14973 qmax(i,k,j-1) =max(qmax(i,k,j-1),field_old(i,k,j))
14975 g_qmin(i,k,j-1) =(g_qmin(i,k,j-1) +g_field_old(i,k,j) -(g_qmin(i,k,j-1) &
14976 -g_field_old(i,k,j))*sign(1.0, qmin(i,k,j-1) -(field_old(i,k,j))))*0.5
14977 qmin(i,k,j-1) =min(qmin(i,k,j-1),field_old(i,k,j))
14987 i_end =min(ite,ide-1) +1
14995 j_end =min(jte,jde-1) +1
14997 IF(degrade_ys) j_start =max(jts-1,jds)
14999 IF(degrade_ye) j_end =min(jte+1,jde-1)
15001 IF(degrade_xs) THEN
15003 i_start =max(ids+1,its-1)
15008 IF(degrade_xe) THEN
15010 i_end =min(ide-2,ite+1)
15015 DO j =j_start,j_end
15017 DO i =i_start_f,i_end_f
15025 g_FuncVal1=g_flux_upwind(field_old(i-1,k,j),g_field_old(i-1,k,j) &
15026 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15027 FuncVal1 =flux_upwind(field_old(i-1,k,j),field_old(i,k,j),cr)
15029 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15030 Tmpv1 =vel*FuncVal1
15032 g_fqxl(i,k,j) =g_Tmpv1
15035 g_FuncVal1=g_flux5(field(i-3,k,j),g_field(i-3,k,j),field(i-2,k,j) &
15036 ,g_field(i-2,k,j),field(i-1,k,j),g_field(i-1,k,j),field(i,k,j),g_field(i,k, &
15037 j),field(i+1,k,j),g_field(i+1,k,j),field(i+2,k,j),g_field(i+2,k,j),vel,g_vel)
15038 FuncVal1 =flux5(field(i-3,k,j),field(i-2,k,j),field(i-1,k,j),field(i,k,j) &
15039 ,field(i+1,k,j),field(i+2,k,j),vel)
15041 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15042 Tmpv1 =vel*FuncVal1
15044 g_fqx(i,k,j) =g_Tmpv1
15047 g_fqx(i,k,j) =g_fqx(i,k,j) -g_fqxl(i,k,j)
15048 fqx(i,k,j) =fqx(i,k,j) -fqxl(i,k,j)
15052 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i-1,k,j) +(g_qmax(i,k,j) &
15053 -g_field_old(i-1,k,j))*sign(1.0, qmax(i,k,j) -(field_old(i-1,k,j))))*0.5
15054 qmax(i,k,j) =max(qmax(i,k,j),field_old(i-1,k,j))
15056 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i-1,k,j) -(g_qmin(i,k,j) &
15057 -g_field_old(i-1,k,j))*sign(1.0, qmin(i,k,j) -(field_old(i-1,k,j))))*0.5
15058 qmin(i,k,j) =min(qmin(i,k,j),field_old(i-1,k,j))
15062 g_qmax(i-1,k,j) =(g_qmax(i-1,k,j) +g_field_old(i,k,j) +(g_qmax(i-1,k,j) &
15063 -g_field_old(i,k,j))*sign(1.0, qmax(i-1,k,j) -(field_old(i,k,j))))*0.5
15064 qmax(i-1,k,j) =max(qmax(i-1,k,j),field_old(i,k,j))
15066 g_qmin(i-1,k,j) =(g_qmin(i-1,k,j) +g_field_old(i,k,j) -(g_qmin(i-1,k,j) &
15067 -g_field_old(i,k,j))*sign(1.0, qmin(i-1,k,j) -(field_old(i,k,j))))*0.5
15068 qmin(i-1,k,j) =min(qmin(i-1,k,j),field_old(i,k,j))
15074 IF( degrade_xs ) THEN
15076 DO i =i_start,i_start_f-1
15078 IF(i == ids+1) THEN
15088 g_FuncVal1=g_flux_upwind(field_old(i-1,k,j),g_field_old(i-1,k,j) &
15089 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15090 FuncVal1 =flux_upwind(field_old(i-1,k,j),field_old(i,k,j),cr)
15092 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15093 Tmpv1 =vel*FuncVal1
15095 g_fqxl(i,k,j) =g_Tmpv1
15098 g_Tmpv1 =0.5*(ru(i,k,j))*(g_field(i,k,j) +g_field(i-1,k,j)) +0.5*(g_ru( &
15099 i,k,j))*(field(i,k,j) +field(i-1,k,j))
15100 Tmpv1 =0.5*(ru(i,k,j))*(field(i,k,j) +field(i-1,k,j))
15102 g_fqx(i,k,j) =g_Tmpv1
15105 g_fqx(i,k,j) =g_fqx(i,k,j) -g_fqxl(i,k,j)
15106 fqx(i,k,j) =fqx(i,k,j) -fqxl(i,k,j)
15110 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i-1,k,j) +(g_qmax(i,k,j) &
15111 -g_field_old(i-1,k,j))*sign(1.0, qmax(i,k,j) -(field_old(i-1,k,j))))*0.5
15112 qmax(i,k,j) =max(qmax(i,k,j),field_old(i-1,k,j))
15114 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i-1,k,j) -(g_qmin(i,k,j) &
15115 -g_field_old(i-1,k,j))*sign(1.0, qmin(i,k,j) -(field_old(i-1,k,j))))*0.5
15116 qmin(i,k,j) =min(qmin(i,k,j),field_old(i-1,k,j))
15120 g_qmax(i-1,k,j) =(g_qmax(i-1,k,j) +g_field_old(i,k,j) +(g_qmax(i-1,k,j) &
15121 -g_field_old(i,k,j))*sign(1.0, qmax(i-1,k,j) -(field_old(i,k,j))))*0.5
15122 qmax(i-1,k,j) =max(qmax(i-1,k,j),field_old(i,k,j))
15124 g_qmin(i-1,k,j) =(g_qmin(i-1,k,j) +g_field_old(i,k,j) -(g_qmin(i-1,k,j) &
15125 -g_field_old(i,k,j))*sign(1.0, qmin(i-1,k,j) -(field_old(i,k,j))))*0.5
15126 qmin(i-1,k,j) =min(qmin(i-1,k,j),field_old(i,k,j))
15132 IF(i == ids+2) THEN
15142 g_FuncVal1=g_flux_upwind(field_old(i-1,k,j),g_field_old(i-1,k,j) &
15143 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15144 FuncVal1 =flux_upwind(field_old(i-1,k,j),field_old(i,k,j),cr)
15146 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15147 Tmpv1 =vel*FuncVal1
15149 g_fqxl(i,k,j) =g_Tmpv1
15152 g_FuncVal1=g_flux3(field(i-2,k,j),g_field(i-2,k,j),field(i-1,k,j) &
15153 ,g_field(i-1,k,j),field(i,k,j),g_field(i,k,j),field(i+1,k,j),g_field(i+1,k, &
15155 FuncVal1 =flux3(field(i-2,k,j),field(i-1,k,j),field(i,k,j),field(i+1,k,j),vel)
15157 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15158 Tmpv1 =vel*FuncVal1
15160 g_fqx(i,k,j) =g_Tmpv1
15163 g_fqx(i,k,j) =g_fqx(i,k,j) -g_fqxl(i,k,j)
15164 fqx(i,k,j) =fqx(i,k,j) -fqxl(i,k,j)
15168 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i-1,k,j) +(g_qmax(i,k,j) &
15169 -g_field_old(i-1,k,j))*sign(1.0, qmax(i,k,j) -(field_old(i-1,k,j))))*0.5
15170 qmax(i,k,j) =max(qmax(i,k,j),field_old(i-1,k,j))
15172 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i-1,k,j) -(g_qmin(i,k,j) &
15173 -g_field_old(i-1,k,j))*sign(1.0, qmin(i,k,j) -(field_old(i-1,k,j))))*0.5
15174 qmin(i,k,j) =min(qmin(i,k,j),field_old(i-1,k,j))
15178 g_qmax(i-1,k,j) =(g_qmax(i-1,k,j) +g_field_old(i,k,j) +(g_qmax(i-1,k,j) &
15179 -g_field_old(i,k,j))*sign(1.0, qmax(i-1,k,j) -(field_old(i,k,j))))*0.5
15180 qmax(i-1,k,j) =max(qmax(i-1,k,j),field_old(i,k,j))
15182 g_qmin(i-1,k,j) =(g_qmin(i-1,k,j) +g_field_old(i,k,j) -(g_qmin(i-1,k,j) &
15183 -g_field_old(i,k,j))*sign(1.0, qmin(i-1,k,j) -(field_old(i,k,j))))*0.5
15184 qmin(i-1,k,j) =min(qmin(i-1,k,j),field_old(i,k,j))
15192 IF( degrade_xe ) THEN
15194 DO i =i_end_f+1,i_end+1
15196 IF( i == ide-1 ) THEN
15206 g_FuncVal1=g_flux_upwind(field_old(i-1,k,j),g_field_old(i-1,k,j) &
15207 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15208 FuncVal1 =flux_upwind(field_old(i-1,k,j),field_old(i,k,j),cr)
15210 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15211 Tmpv1 =vel*FuncVal1
15213 g_fqxl(i,k,j) =g_Tmpv1
15216 g_Tmpv1 =0.5*(ru(i,k,j))*(g_field(i,k,j) +g_field(i-1,k,j)) +0.5*(g_ru( &
15217 i,k,j))*(field(i,k,j) +field(i-1,k,j))
15218 Tmpv1 =0.5*(ru(i,k,j))*(field(i,k,j) +field(i-1,k,j))
15220 g_fqx(i,k,j) =g_Tmpv1
15223 g_fqx(i,k,j) =g_fqx(i,k,j) -g_fqxl(i,k,j)
15224 fqx(i,k,j) =fqx(i,k,j) -fqxl(i,k,j)
15228 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i-1,k,j) +(g_qmax(i,k,j) &
15229 -g_field_old(i-1,k,j))*sign(1.0, qmax(i,k,j) -(field_old(i-1,k,j))))*0.5
15230 qmax(i,k,j) =max(qmax(i,k,j),field_old(i-1,k,j))
15232 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i-1,k,j) -(g_qmin(i,k,j) &
15233 -g_field_old(i-1,k,j))*sign(1.0, qmin(i,k,j) -(field_old(i-1,k,j))))*0.5
15234 qmin(i,k,j) =min(qmin(i,k,j),field_old(i-1,k,j))
15238 g_qmax(i-1,k,j) =(g_qmax(i-1,k,j) +g_field_old(i,k,j) +(g_qmax(i-1,k,j) &
15239 -g_field_old(i,k,j))*sign(1.0, qmax(i-1,k,j) -(field_old(i,k,j))))*0.5
15240 qmax(i-1,k,j) =max(qmax(i-1,k,j),field_old(i,k,j))
15242 g_qmin(i-1,k,j) =(g_qmin(i-1,k,j) +g_field_old(i,k,j) -(g_qmin(i-1,k,j) &
15243 -g_field_old(i,k,j))*sign(1.0, qmin(i-1,k,j) -(field_old(i,k,j))))*0.5
15244 qmin(i-1,k,j) =min(qmin(i-1,k,j),field_old(i,k,j))
15250 IF( i == ide-2 ) THEN
15260 g_FuncVal1=g_flux_upwind(field_old(i-1,k,j),g_field_old(i-1,k,j) &
15261 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15262 FuncVal1 =flux_upwind(field_old(i-1,k,j),field_old(i,k,j),cr)
15264 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15265 Tmpv1 =vel*FuncVal1
15267 g_fqxl(i,k,j) =g_Tmpv1
15270 g_FuncVal1=g_flux3(field(i-2,k,j),g_field(i-2,k,j),field(i-1,k,j) &
15271 ,g_field(i-1,k,j),field(i,k,j),g_field(i,k,j),field(i+1,k,j),g_field(i+1,k, &
15273 FuncVal1 =flux3(field(i-2,k,j),field(i-1,k,j),field(i,k,j),field(i+1,k,j),vel)
15275 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15276 Tmpv1 =vel*FuncVal1
15278 g_fqx(i,k,j) =g_Tmpv1
15281 g_fqx(i,k,j) =g_fqx(i,k,j) -g_fqxl(i,k,j)
15282 fqx(i,k,j) =fqx(i,k,j) -fqxl(i,k,j)
15286 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i-1,k,j) +(g_qmax(i,k,j) &
15287 -g_field_old(i-1,k,j))*sign(1.0, qmax(i,k,j) -(field_old(i-1,k,j))))*0.5
15288 qmax(i,k,j) =max(qmax(i,k,j),field_old(i-1,k,j))
15290 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i-1,k,j) -(g_qmin(i,k,j) &
15291 -g_field_old(i-1,k,j))*sign(1.0, qmin(i,k,j) -(field_old(i-1,k,j))))*0.5
15292 qmin(i,k,j) =min(qmin(i,k,j),field_old(i-1,k,j))
15296 g_qmax(i-1,k,j) =(g_qmax(i-1,k,j) +g_field_old(i,k,j) +(g_qmax(i-1,k,j) &
15297 -g_field_old(i,k,j))*sign(1.0, qmax(i-1,k,j) -(field_old(i,k,j))))*0.5
15298 qmax(i-1,k,j) =max(qmax(i-1,k,j),field_old(i,k,j))
15300 g_qmin(i-1,k,j) =(g_qmin(i-1,k,j) +g_field_old(i,k,j) -(g_qmin(i-1,k,j) &
15301 -g_field_old(i,k,j))*sign(1.0, qmin(i-1,k,j) -(field_old(i,k,j))))*0.5
15302 qmin(i-1,k,j) =min(qmin(i-1,k,j),field_old(i,k,j))
15313 ! Revised by Ning Pan, 2010-07-25
15314 ! WRITE (wrf_err_message,*) 'module_advect: advect_scalar_mono, h_order not known ',horz_order
15315 WRITE (wrf_err_message,*) 'g_module_advect: g_advect_scalar_mono, h_order not known ',horz_order
15318 !CALL g_wrf_error_fatal(Trim(wrf_err_message))
15319 CALL wrf_error_fatal(Trim(wrf_err_message)) ! Added by Ning Pan, 2010-07-25
15324 i_end =min(ite,ide-1)
15328 j_end =min(jte,jde-1)
15330 IF( (config_flags%open_xs) .and. (its == ids) ) THEN
15332 DO j =j_start,j_end
15335 g_ub =(0.5*(g_ru(its,k,j) +g_ru(its+1,k,j)) +0.0 -(0.5*(g_ru(its,k,j) &
15336 +g_ru(its+1,k,j)) -0.0)*sign(1.0, 0.5*(ru(its,k,j) +ru(its+1,k,j)) -(0.)))*0.5
15337 ub =min(0.5*(ru(its,k,j) +ru(its+1,k,j)),0.)
15339 g_Tmpv1 =ub*(g_field_old(its+1,k,j) -g_field_old(its,k,j)) +g_ub*( &
15340 field_old(its+1,k,j) -field_old(its,k,j))
15341 Tmpv1 =ub*(field_old(its+1,k,j) -field_old(its,k,j))
15343 g_Tmpv2 =field(its,k,j)*(g_ru(its+1,k,j) -g_ru(its,k,j)) +g_field(its,k, &
15344 j)*(ru(its+1,k,j) -ru(its,k,j))
15345 Tmpv2 =field(its,k,j)*(ru(its+1,k,j) -ru(its,k,j))
15347 g_tendency(its,k,j) =g_tendency(its,k,j) -rdx*(g_Tmpv1 +g_Tmpv2)
15348 tendency(its,k,j) =tendency(its,k,j) -rdx*(Tmpv1 +Tmpv2)
15354 IF( (config_flags%open_xe) .and. (ite == ide) ) THEN
15356 DO j =j_start,j_end
15359 g_ub =(0.5*(g_ru(ite-1,k,j) +g_ru(ite,k,j)) +0.0 +(0.5*(g_ru(ite-1,k,j) &
15360 +g_ru(ite,k,j)) -0.0)*sign(1.0, 0.5*(ru(ite-1,k,j) +ru(ite,k,j)) -(0.)))*0.5
15361 ub =max(0.5*(ru(ite-1,k,j) +ru(ite,k,j)),0.)
15363 g_Tmpv1 =ub*(g_field_old(i_end,k,j) -g_field_old(i_end-1,k,j)) &
15364 +g_ub*(field_old(i_end,k,j) -field_old(i_end-1,k,j))
15365 Tmpv1 =ub*(field_old(i_end,k,j) -field_old(i_end-1,k,j))
15367 g_Tmpv2 =field(i_end,k,j)*(g_ru(ite,k,j) -g_ru(ite-1,k,j)) +g_field( &
15368 i_end,k,j)*(ru(ite,k,j) -ru(ite-1,k,j))
15369 Tmpv2 =field(i_end,k,j)*(ru(ite,k,j) -ru(ite-1,k,j))
15371 g_tendency(i_end,k,j) =g_tendency(i_end,k,j) -rdx*(g_Tmpv1 +g_Tmpv2)
15372 tendency(i_end,k,j) =tendency(i_end,k,j) -rdx*(Tmpv1 +Tmpv2)
15378 IF( (config_flags%open_ys) .and. (jts == jds) ) THEN
15380 DO i =i_start,i_end
15383 g_vb =(0.5*(g_rv(i,k,jts) +g_rv(i,k,jts+1)) +0.0 -(0.5*(g_rv(i,k,jts) &
15384 +g_rv(i,k,jts+1)) -0.0)*sign(1.0, 0.5*(rv(i,k,jts) +rv(i,k,jts+1)) -(0.)))*0.5
15385 vb =min(0.5*(rv(i,k,jts) +rv(i,k,jts+1)),0.)
15387 g_Tmpv1 =vb*(g_field_old(i,k,jts+1) -g_field_old(i,k,jts)) +g_vb*( &
15388 field_old(i,k,jts+1) -field_old(i,k,jts))
15389 Tmpv1 =vb*(field_old(i,k,jts+1) -field_old(i,k,jts))
15391 g_Tmpv2 =field(i,k,jts)*(g_rv(i,k,jts+1) -g_rv(i,k,jts)) +g_field(i,k, &
15392 jts)*(rv(i,k,jts+1) -rv(i,k,jts))
15393 Tmpv2 =field(i,k,jts)*(rv(i,k,jts+1) -rv(i,k,jts))
15395 g_tendency(i,k,jts) =g_tendency(i,k,jts) -rdy*(g_Tmpv1 +g_Tmpv2)
15396 tendency(i,k,jts) =tendency(i,k,jts) -rdy*(Tmpv1 +Tmpv2)
15402 IF( (config_flags%open_ye) .and. (jte == jde)) THEN
15404 DO i =i_start,i_end
15407 g_vb =(0.5*(g_rv(i,k,jte-1) +g_rv(i,k,jte)) +0.0 +(0.5*(g_rv(i,k,jte-1) &
15408 +g_rv(i,k,jte)) -0.0)*sign(1.0, 0.5*(rv(i,k,jte-1) +rv(i,k,jte)) -(0.)))*0.5
15409 vb =max(0.5*(rv(i,k,jte-1) +rv(i,k,jte)),0.)
15411 g_Tmpv1 =vb*(g_field_old(i,k,j_end) -g_field_old(i,k,j_end-1)) &
15412 +g_vb*(field_old(i,k,j_end) -field_old(i,k,j_end-1))
15413 Tmpv1 =vb*(field_old(i,k,j_end) -field_old(i,k,j_end-1))
15415 g_Tmpv2 =field(i,k,j_end)*(g_rv(i,k,jte) -g_rv(i,k,jte-1)) +g_field(i,k, &
15416 j_end)*(rv(i,k,jte) -rv(i,k,jte-1))
15417 Tmpv2 =field(i,k,j_end)*(rv(i,k,jte) -rv(i,k,jte-1))
15419 g_tendency(i,k,j_end) =g_tendency(i,k,j_end) -rdy*(g_Tmpv1 +g_Tmpv2)
15420 tendency(i,k,j_end) =tendency(i,k,j_end) -rdy*(Tmpv1 +Tmpv2)
15428 i_end =min(ite,ide-1) +1
15432 j_end =min(jte,jde-1) +1
15434 IF(degrade_xs) i_start =max(its-1,ids)
15436 IF(degrade_xe) i_end =min(ite+1,ide-1)
15438 IF(degrade_ys) j_start =max(jts-1,jds)
15440 IF(degrade_ye) j_end =min(jte+1,jde-1)
15442 IF(vert_order == 3) THEN
15444 DO j =j_start,j_end
15445 DO i =i_start,i_end
15453 g_fqz(i,kde,j) =0.0
15456 g_fqzl(i,kde,j) =0.0
15462 DO i =i_start,i_end
15464 g_vel =g_rom(i,k,j)
15470 g_FuncVal1=g_flux_upwind(field_old(i,k-1,j),g_field_old(i,k-1,j) &
15471 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15472 FuncVal1 =flux_upwind(field_old(i,k-1,j),field_old(i,k,j),cr)
15474 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15475 Tmpv1 =vel*FuncVal1
15477 g_fqzl(i,k,j) =g_Tmpv1
15480 g_FuncVal1=g_flux3(field(i,k-2,j),g_field(i,k-2,j),field(i,k-1,j) &
15481 ,g_field(i,k-1,j),field(i,k,j),g_field(i,k,j),field(i,k+1,j),g_field(i,k+1, &
15483 FuncVal1 =flux3(field(i,k-2,j),field(i,k-1,j),field(i,k,j),field(i,k+1,j),-vel)
15485 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15486 Tmpv1 =vel*FuncVal1
15488 g_fqz(i,k,j) =g_Tmpv1
15491 g_fqz(i,k,j) =g_fqz(i,k,j) -g_fqzl(i,k,j)
15492 fqz(i,k,j) =fqz(i,k,j) -fqzl(i,k,j)
15496 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k-1,j) +(g_qmax(i,k,j) &
15497 -g_field_old(i,k-1,j))*sign(1.0, qmax(i,k,j) -(field_old(i,k-1,j))))*0.5
15498 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k-1,j))
15500 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k-1,j) -(g_qmin(i,k,j) &
15501 -g_field_old(i,k-1,j))*sign(1.0, qmin(i,k,j) -(field_old(i,k-1,j))))*0.5
15502 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k-1,j))
15506 g_qmax(i,k-1,j) =(g_qmax(i,k-1,j) +g_field_old(i,k,j) +(g_qmax(i,k-1,j) &
15507 -g_field_old(i,k,j))*sign(1.0, qmax(i,k-1,j) -(field_old(i,k,j))))*0.5
15508 qmax(i,k-1,j) =max(qmax(i,k-1,j),field_old(i,k,j))
15510 g_qmin(i,k-1,j) =(g_qmin(i,k-1,j) +g_field_old(i,k,j) -(g_qmin(i,k-1,j) &
15511 -g_field_old(i,k,j))*sign(1.0, qmin(i,k-1,j) -(field_old(i,k,j))))*0.5
15512 qmin(i,k-1,j) =min(qmin(i,k-1,j),field_old(i,k,j))
15518 DO i =i_start,i_end
15522 g_vel =g_rom(i,k,j)
15528 g_FuncVal1=g_flux_upwind(field_old(i,k-1,j),g_field_old(i,k-1,j) &
15529 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15530 FuncVal1 =flux_upwind(field_old(i,k-1,j),field_old(i,k,j),cr)
15532 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15533 Tmpv1 =vel*FuncVal1
15535 g_fqzl(i,k,j) =g_Tmpv1
15538 g_Tmpv1 =rom(i,k,j)*(fzm(k)*g_field(i,k,j) +fzp(k)*g_field(i,k-1,j)) &
15539 +g_rom(i,k,j)*(fzm(k)*field(i,k,j) +fzp(k)*field(i,k-1,j))
15540 Tmpv1 =rom(i,k,j)*(fzm(k)*field(i,k,j) +fzp(k)*field(i,k-1,j))
15542 g_fqz(i,k,j) =g_Tmpv1
15545 g_fqz(i,k,j) =g_fqz(i,k,j) -g_fqzl(i,k,j)
15546 fqz(i,k,j) =fqz(i,k,j) -fqzl(i,k,j)
15550 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k-1,j) +(g_qmax(i,k,j) &
15551 -g_field_old(i,k-1,j))*sign(1.0, qmax(i,k,j) -(field_old(i,k-1,j))))*0.5
15552 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k-1,j))
15554 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k-1,j) -(g_qmin(i,k,j) &
15555 -g_field_old(i,k-1,j))*sign(1.0, qmin(i,k,j) -(field_old(i,k-1,j))))*0.5
15556 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k-1,j))
15560 g_qmax(i,k-1,j) =(g_qmax(i,k-1,j) +g_field_old(i,k,j) +(g_qmax(i,k-1,j) &
15561 -g_field_old(i,k,j))*sign(1.0, qmax(i,k-1,j) -(field_old(i,k,j))))*0.5
15562 qmax(i,k-1,j) =max(qmax(i,k-1,j),field_old(i,k,j))
15564 g_qmin(i,k-1,j) =(g_qmin(i,k-1,j) +g_field_old(i,k,j) -(g_qmin(i,k-1,j) &
15565 -g_field_old(i,k,j))*sign(1.0, qmin(i,k-1,j) -(field_old(i,k,j))))*0.5
15566 qmin(i,k-1,j) =min(qmin(i,k-1,j),field_old(i,k,j))
15572 g_vel =g_rom(i,k,j)
15578 g_FuncVal1=g_flux_upwind(field_old(i,k-1,j),g_field_old(i,k-1,j) &
15579 ,field_old(i,k,j),g_field_old(i,k,j),cr,g_cr)
15580 FuncVal1 =flux_upwind(field_old(i,k-1,j),field_old(i,k,j),cr)
15582 g_Tmpv1 =vel*g_FuncVal1 +g_vel*FuncVal1
15583 Tmpv1 =vel*FuncVal1
15585 g_fqzl(i,k,j) =g_Tmpv1
15588 g_Tmpv1 =rom(i,k,j)*(fzm(k)*g_field(i,k,j) +fzp(k)*g_field(i,k-1,j)) &
15589 +g_rom(i,k,j)*(fzm(k)*field(i,k,j) +fzp(k)*field(i,k-1,j))
15590 Tmpv1 =rom(i,k,j)*(fzm(k)*field(i,k,j) +fzp(k)*field(i,k-1,j))
15592 g_fqz(i,k,j) =g_Tmpv1
15595 g_fqz(i,k,j) =g_fqz(i,k,j) -g_fqzl(i,k,j)
15596 fqz(i,k,j) =fqz(i,k,j) -fqzl(i,k,j)
15600 g_qmax(i,k,j) =(g_qmax(i,k,j) +g_field_old(i,k-1,j) +(g_qmax(i,k,j) &
15601 -g_field_old(i,k-1,j))*sign(1.0, qmax(i,k,j) -(field_old(i,k-1,j))))*0.5
15602 qmax(i,k,j) =max(qmax(i,k,j),field_old(i,k-1,j))
15604 g_qmin(i,k,j) =(g_qmin(i,k,j) +g_field_old(i,k-1,j) -(g_qmin(i,k,j) &
15605 -g_field_old(i,k-1,j))*sign(1.0, qmin(i,k,j) -(field_old(i,k-1,j))))*0.5
15606 qmin(i,k,j) =min(qmin(i,k,j),field_old(i,k-1,j))
15610 g_qmax(i,k-1,j) =(g_qmax(i,k-1,j) +g_field_old(i,k,j) +(g_qmax(i,k-1,j) &
15611 -g_field_old(i,k,j))*sign(1.0, qmax(i,k-1,j) -(field_old(i,k,j))))*0.5
15612 qmax(i,k-1,j) =max(qmax(i,k-1,j),field_old(i,k,j))
15614 g_qmin(i,k-1,j) =(g_qmin(i,k-1,j) +g_field_old(i,k,j) -(g_qmin(i,k-1,j) &
15615 -g_field_old(i,k,j))*sign(1.0, qmin(i,k-1,j) -(field_old(i,k,j))))*0.5
15616 qmin(i,k-1,j) =min(qmin(i,k-1,j),field_old(i,k,j))
15623 ! Revised by Ning Pan, 2010-07-25
15624 ! WRITE (wrf_err_message,*) ' advect_scalar_mono, v_order not known ',vert_order
15625 WRITE (wrf_err_message,*) ' g_advect_scalar_mono, v_order not known ',vert_order
15628 !CALL g_wrf_error_fatal(wrf_err_message)
15629 CALL wrf_error_fatal(wrf_err_message) ! Added by Ning Pan, 2010-07-25
15632 IF(mono_limit) THEN
15636 i_end =min(ite,ide-1) +1
15640 j_end =min(jte,jde-1) +1
15642 IF(degrade_xs) i_start =max(its-1,ids)
15644 IF(degrade_xe) i_end =min(ite+1,ide-1)
15646 IF(degrade_ys) j_start =max(jts-1,jds)
15648 IF(degrade_ye) j_end =min(jte+1,jde-1)
15650 IF(config_flags%specified .or. config_flags%nested) THEN
15652 IF(degrade_xs) i_start =max(its-1,ids+1)
15654 IF(degrade_xe) i_end =min(ite+1,ide-2)
15656 IF(degrade_ys) j_start =max(jts-1,jds+1)
15658 IF(degrade_ye) j_end =min(jte+1,jde-2)
15661 IF(config_flags%open_xs) THEN
15663 IF(degrade_xs) i_start =max(its-1,ids+1)
15666 IF(config_flags%open_xe) THEN
15668 IF(degrade_xe) i_end =min(ite+1,ide-2)
15671 IF(config_flags%open_ys) THEN
15673 IF(degrade_ys) j_start =max(jts-1,jds+1)
15676 IF(config_flags%open_ye) THEN
15678 IF(degrade_ye) j_end =min(jte+1,jde-2)
15681 DO j =j_start,j_end
15683 DO i =i_start,i_end
15685 g_Tmpv1 =(mub(i,j) +mu_old(i,j))*g_field_old(i,k,j) +(g_mu_old(i,j)) &
15687 Tmpv1 =(mub(i,j) +mu_old(i,j))*field_old(i,k,j)
15689 g_ph_upwind =g_Tmpv1 -dt*(msftx(i,j) *msfty(i,j)*(rdx*(g_fqxl(i+1,k,j) &
15690 -g_fqxl(i,k,j)) +rdy*(g_fqyl(i,k,j+1) -g_fqyl(i,k,j))) +msfty(i,j) *rdzw(k) &
15691 *(g_fqzl(i,k+1,j) -g_fqzl(i,k,j)))
15692 ph_upwind =Tmpv1 -dt*(msftx(i,j) *msfty(i,j)*(rdx*(fqxl(i+1,k,j) -fqxl(i,k,j)) &
15693 +rdy*(fqyl(i,k,j+1) -fqyl(i,k,j))) +msfty(i,j) *rdzw(k)*(fqzl(i,k+1,j) -fqzl(i,k,j)))
15695 g_flux_in =-dt*((msftx(i,j) *msfty(i,j))*(rdx*((0.0 +g_fqx(i+1,k,j) &
15696 -(0.0 -g_fqx(i+1,k,j))*sign(1.0, 0. -(fqx(i+1,k,j))))*0.5 -(0.0 +g_fqx(i,k,j) &
15697 +(0.0 -g_fqx(i,k,j))*sign(1.0, 0. -(fqx(i,k,j))))*0.5) +rdy*((0.0 +g_fqy(i,k, &
15698 j+1) -(0.0 -g_fqy(i,k,j+1))*sign(1.0, 0. -(fqy(i,k,j+1))))*0.5 -(0.0 +g_fqy(i, &
15699 k,j) +(0.0 -g_fqy(i,k,j))*sign(1.0, 0. -(fqy(i,k,j))))*0.5)) +msfty(i,j) *rdzw(k) &
15700 *((0.0 +g_fqz(i,k+1,j) +(0.0 -g_fqz(i,k+1,j))*sign(1.0, 0. -(fqz(i,k+1,j)))) &
15701 *0.5 -(0.0 +g_fqz(i,k,j) -(0.0 -g_fqz(i,k,j))*sign(1.0, 0. -(fqz(i,k,j))))*0.5))
15702 flux_in =-dt*((msftx(i,j) *msfty(i,j))*(rdx*(min(0.,fqx(i+1,k,j)) -max(0.,fqx(i,k, &
15703 j))) +rdy*(min(0.,fqy(i,k,j+1)) -max(0.,fqy(i,k,j)))) +msfty(i,j) *rdzw(k) &
15704 *(max(0.,fqz(i,k+1,j)) -min(0.,fqz(i,k,j))))
15706 g_Tmpv1 =mut(i,j)*g_qmax(i,k,j) +g_mut(i,j)*qmax(i,k,j)
15707 Tmpv1 =mut(i,j)*qmax(i,k,j)
15709 g_ph_hi =g_Tmpv1 -g_ph_upwind
15710 ph_hi =Tmpv1 -ph_upwind
15712 g_Tmpv1 =(g_ph_hi*(flux_in +eps) -(g_flux_in)*ph_hi)/((flux_in +eps)*(flux_in +eps))
15713 Tmpv1 =ph_hi/(flux_in +eps)
15715 IF( flux_in .gt. ph_hi ) g_scale_in(i,k,j) =(0.0 +g_Tmpv1 +(0.0 -g_Tmpv1) &
15716 *sign(1.0, 0. -(Tmpv1)))*0.5
15717 IF( flux_in .gt. ph_hi ) scale_in(i,k,j) =max(0.,Tmpv1)
15719 g_flux_out =dt*((msftx(i,j) *msfty(i,j))*(rdx*((0.0 +g_fqx(i+1,k,j) &
15720 +(0.0 -g_fqx(i+1,k,j))*sign(1.0, 0. -(fqx(i+1,k,j))))*0.5 -(0.0 +g_fqx(i,k,j) &
15721 -(0.0 -g_fqx(i,k,j))*sign(1.0, 0. -(fqx(i,k,j))))*0.5) +rdy*((0.0 +g_fqy(i,k, &
15722 j+1) +(0.0 -g_fqy(i,k,j+1))*sign(1.0, 0. -(fqy(i,k,j+1))))*0.5 -(0.0 +g_fqy(i, &
15723 k,j) -(0.0 -g_fqy(i,k,j))*sign(1.0, 0. -(fqy(i,k,j))))*0.5)) +msfty(i,j) *rdzw(k) &
15724 *((0.0 +g_fqz(i,k+1,j) -(0.0 -g_fqz(i,k+1,j))*sign(1.0, 0. -(fqz(i,k+1,j)))) &
15725 *0.5 -(0.0 +g_fqz(i,k,j) +(0.0 -g_fqz(i,k,j))*sign(1.0, 0. -(fqz(i,k,j))))*0.5))
15726 flux_out =dt*((msftx(i,j) *msfty(i,j))*(rdx*(max(0.,fqx(i+1,k,j)) -min(0.,fqx(i,k, &
15727 j))) +rdy*(max(0.,fqy(i,k,j+1)) -min(0.,fqy(i,k,j)))) +msfty(i,j) *rdzw(k) &
15728 *(min(0.,fqz(i,k+1,j)) -max(0.,fqz(i,k,j))))
15730 g_Tmpv1 =mut(i,j)*g_qmin(i,k,j) +g_mut(i,j)*qmin(i,k,j)
15731 Tmpv1 =mut(i,j)*qmin(i,k,j)
15733 g_ph_low =g_ph_upwind -g_Tmpv1
15734 ph_low =ph_upwind -Tmpv1
15736 g_Tmpv1 =(g_ph_low*(flux_out +eps) -(g_flux_out)*ph_low)/((flux_out +eps) &
15738 Tmpv1 =ph_low/(flux_out +eps)
15740 IF( flux_out .gt. ph_low ) g_scale_out(i,k,j) =(0.0 +g_Tmpv1 +(0.0 -g_Tmpv1) &
15741 *sign(1.0, 0. -(Tmpv1)))*0.5
15742 IF( flux_out .gt. ph_low ) scale_out(i,k,j) =max(0.,Tmpv1)
15747 DO j =j_start,j_end
15749 DO i =i_start,i_end+1
15751 IF( fqx (i,k,j) .gt. 0.) THEN
15753 g_Tmpv1 =min(scale_in(i,k,j),scale_out(i-1,k,j))*g_fqx(i,k,j) +(g_scale_in( &
15754 i,k,j) +g_scale_out(i-1,k,j) -(g_scale_in(i,k,j) -g_scale_out(i-1,k,j)) &
15755 *sign(1.0, scale_in(i,k,j) -(scale_out(i-1,k,j))))*0.5*fqx(i,k,j)
15756 Tmpv1 =min(scale_in(i,k,j),scale_out(i-1,k,j))*fqx(i,k,j)
15758 g_fqx(i,k,j) =g_Tmpv1
15763 g_Tmpv1 =min(scale_out(i,k,j),scale_in(i-1,k,j))*g_fqx(i,k,j) +( &
15764 g_scale_out(i,k,j) +g_scale_in(i-1,k,j) -(g_scale_out(i,k,j) -g_scale_in( &
15765 i-1,k,j))*sign(1.0, scale_out(i,k,j) -(scale_in(i-1,k,j))))*0.5*fqx(i,k,j)
15766 Tmpv1 =min(scale_out(i,k,j),scale_in(i-1,k,j))*fqx(i,k,j)
15768 g_fqx(i,k,j) =g_Tmpv1
15776 DO j =j_start,j_end+1
15778 DO i =i_start,i_end
15780 IF( fqy (i,k,j) .gt. 0.) THEN
15782 g_Tmpv1 =min(scale_in(i,k,j),scale_out(i,k,j-1))*g_fqy(i,k,j) +(g_scale_in( &
15783 i,k,j) +g_scale_out(i,k,j-1) -(g_scale_in(i,k,j) -g_scale_out(i,k,j-1)) &
15784 *sign(1.0, scale_in(i,k,j) -(scale_out(i,k,j-1))))*0.5*fqy(i,k,j)
15785 Tmpv1 =min(scale_in(i,k,j),scale_out(i,k,j-1))*fqy(i,k,j)
15787 g_fqy(i,k,j) =g_Tmpv1
15792 g_Tmpv1 =min(scale_out(i,k,j),scale_in(i,k,j-1))*g_fqy(i,k,j) +( &
15793 g_scale_out(i,k,j) +g_scale_in(i,k,j-1) -(g_scale_out(i,k,j) -g_scale_in( &
15794 i,k,j-1))*sign(1.0, scale_out(i,k,j) -(scale_in(i,k,j-1))))*0.5*fqy(i,k,j)
15795 Tmpv1 =min(scale_out(i,k,j),scale_in(i,k,j-1))*fqy(i,k,j)
15797 g_fqy(i,k,j) =g_Tmpv1
15805 DO j =j_start,j_end
15807 DO i =i_start,i_end
15809 IF( fqz (i,k,j) .lt. 0.) THEN
15811 g_Tmpv1 =min(scale_in(i,k,j),scale_out(i,k-1,j))*g_fqz(i,k,j) +(g_scale_in( &
15812 i,k,j) +g_scale_out(i,k-1,j) -(g_scale_in(i,k,j) -g_scale_out(i,k-1,j)) &
15813 *sign(1.0, scale_in(i,k,j) -(scale_out(i,k-1,j))))*0.5*fqz(i,k,j)
15814 Tmpv1 =min(scale_in(i,k,j),scale_out(i,k-1,j))*fqz(i,k,j)
15816 g_fqz(i,k,j) =g_Tmpv1
15821 g_Tmpv1 =min(scale_out(i,k,j),scale_in(i,k-1,j))*g_fqz(i,k,j) +( &
15822 g_scale_out(i,k,j) +g_scale_in(i,k-1,j) -(g_scale_out(i,k,j) -g_scale_in( &
15823 i,k-1,j))*sign(1.0, scale_out(i,k,j) -(scale_in(i,k-1,j))))*0.5*fqz(i,k,j)
15824 Tmpv1 =min(scale_out(i,k,j),scale_in(i,k-1,j))*fqz(i,k,j)
15826 g_fqz(i,k,j) =g_Tmpv1
15837 i_end =min(ite,ide-1)
15841 j_end =min(jte,jde-1)
15843 DO j =j_start,j_end
15845 DO i =i_start,i_end
15847 g_tendency(i,k,j) =g_tendency(i,k,j) -rdzw(k)*(g_fqz(i,k+1,j) -g_fqz(i,k, &
15848 j) +g_fqzl(i,k+1,j) -g_fqzl(i,k,j))
15849 tendency(i,k,j) =tendency(i,k,j) -rdzw(k)*(fqz(i,k+1,j) -fqz(i,k,j) +fqzl(i,k+1,j) &
15857 DO j = j_start, j_end
15859 DO i = i_start, i_end
15861 g_z_tendency (i,k,j) = -rdzw(k)*( g_fqz (i,k+1,j)-g_fqz (i,k,j) &
15862 +g_fqzl(i,k+1,j)-g_fqzl(i,k,j))
15864 z_tendency (i,k,j) = 0. -rdzw(k)*( fqz (i,k+1,j)-fqz (i,k,j) &
15865 +fqzl(i,k+1,j)-fqzl(i,k,j))
15872 IF(degrade_xs) i_start =max(its,ids+1)
15874 IF(degrade_xe) i_end =min(ite,ide-2)
15876 DO j =j_start,j_end
15878 DO i =i_start,i_end
15880 g_tendency(i,k,j) =g_tendency(i,k,j) -msftx(i,j)*(rdx*(g_fqx(i+1,k,j) &
15881 -g_fqx(i,k,j) +g_fqxl(i+1,k,j) -g_fqxl(i,k,j)))
15882 tendency(i,k,j) =tendency(i,k,j) -msftx(i,j)*(rdx*(fqx(i+1,k,j) -fqx(i,k,j) &
15883 +fqxl(i+1,k,j) -fqxl(i,k,j)))
15890 DO j = j_start, j_end
15892 DO i = i_start, i_end
15894 g_h_tendency (i,k,j) = &
15895 - msftx(i,j)*( rdx*( g_fqx (i+1,k,j)-g_fqx (i,k,j) &
15896 +g_fqxl(i+1,k,j)-g_fqxl(i,k,j)) )
15897 h_tendency (i,k,j) = 0. &
15898 - msftx(i,j)*( rdx*( fqx (i+1,k,j)-fqx (i,k,j) &
15899 +fqxl(i+1,k,j)-fqxl(i,k,j)) )
15908 i_end =min(ite,ide-1)
15910 IF(degrade_ys) j_start =max(jts,jds+1)
15912 IF(degrade_ye) j_end =min(jte,jde-2)
15914 DO j =j_start,j_end
15916 DO i =i_start,i_end
15918 g_tendency(i,k,j) =g_tendency(i,k,j) -msftx(i,j)*(rdy*(g_fqy(i,k,j+1) &
15919 -g_fqy(i,k,j) +g_fqyl(i,k,j+1) -g_fqyl(i,k,j)))
15920 tendency(i,k,j) =tendency(i,k,j) -msftx(i,j)*(rdy*(fqy(i,k,j+1) -fqy(i,k,j) &
15921 +fqyl(i,k,j+1) -fqyl(i,k,j)))
15928 DO j = j_start, j_end
15930 DO i = i_start, i_end
15932 g_h_tendency (i,k,j) = g_h_tendency (i,k,j) &
15933 - msftx(i,j)*( rdy*( g_fqy (i,k,j+1)-g_fqy (i,k,j) &
15934 +g_fqyl(i,k,j+1)-g_fqyl(i,k,j)) )
15935 h_tendency (i,k,j) = h_tendency (i,k,j) &
15936 - msftx(i,j)*( rdy*( fqy (i,k,j+1)-fqy (i,k,j) &
15937 +fqyl(i,k,j+1)-fqyl(i,k,j)) )
15944 END SUBROUTINE g_advect_scalar_mono
15947 ! Generated by TAPENADE (INRIA, Tropics team)
15948 ! Tapenade 3.6 (r4165) - 21 sep 2011 20:54
15950 ! Differentiation of advect_scalar_weno in forward (tangent) mode:
15951 ! variations of useful results: tendency
15952 ! with respect to varying inputs: rom field tendency ru rv field_old
15953 ! RW status of diff variables: rom:in field:in tendency:in-out
15954 ! ru:in rv:in field_old:in
15955 SUBROUTINE G_ADVECT_SCALAR_WENO(field, fieldd, field_old, field_oldd, &
15956 & tendency, tendencyd, ru, rud, rv, rvd, rom, romd, mut, time_step, &
15957 & config_flags, msfux, msfuy, msfvx, msfvy, msftx, msfty, fzm, fzp, rdx&
15958 & , rdy, rdzw, ids, ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, &
15959 & kme, its, ite, jts, jte, kts, kte)
15962 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
15963 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
15964 & jme, kms, kme, its, ite, jts, jte, kts, kte
15965 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: field, &
15966 & field_old, ru, rv, rom
15967 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: fieldd, &
15968 & field_oldd, rud, rvd, romd
15969 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
15970 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
15971 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
15972 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
15973 & msfvy, msftx, msfty
15974 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
15975 REAL, INTENT(IN) :: rdx, rdy
15976 INTEGER, INTENT(IN) :: time_step
15978 INTEGER :: i, j, k, itf, jtf, ktf
15979 INTEGER :: i_start, i_end, j_start, j_end
15980 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
15981 INTEGER :: jmin, jmax, jp, jm, imin, imax
15982 INTEGER, PARAMETER :: is=0, js=0, ks=0
15983 REAL :: mrdx, mrdy, ub, vb, vw
15985 REAL, DIMENSION(its:ite, kts:kte) :: vflux
15986 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
15987 REAL, DIMENSION(its - is:ite + 1, kts:kte) :: fqx
15988 REAL, DIMENSION(its-is:ite+1, kts:kte) :: fqxd
15989 ! REAL, DIMENSION( its:ite+1, kts:kte ) :: fqx
15990 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
15991 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
15992 INTEGER :: horz_order, vert_order
15993 LOGICAL :: degrade_xs, degrade_ys
15994 LOGICAL :: degrade_xe, degrade_ye
15995 INTEGER :: jp1, jp0, jtmp
15997 REAL :: ue, uw, vs, vn, wb, wt
15998 REAL, PARAMETER :: f30=7./12., f31=1./12.
15999 REAL, PARAMETER :: f50=37./60., f51=2./15., f52=1./60.
16001 REAL :: qim2, qim1, qi, qip1, qip2
16002 REAL :: qim2d, qim1d, qid, qip1d, qip2d
16003 DOUBLE PRECISION :: beta0, beta1, beta2, f0, f1, f2, wi0, wi1, wi2, &
16005 DOUBLE PRECISION :: beta0d, beta1d, beta2d, f0d, f1d, f2d, wi0d, wi1d&
16007 DOUBLE PRECISION, PARAMETER :: gi0=1.d0/10.d0, gi1=6.d0/10.d0, gi2=&
16008 & 3.d0/10.d0, eps=1.0d-28
16009 INTEGER, PARAMETER :: pw=2
16010 ! definition of flux operators, 3rd, 4th, 5th or 6th order
16011 REAL :: flux3, flux4, flux5, flux6
16012 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
16014 LOGICAL :: specified
16015 DOUBLE PRECISION :: pwx1
16016 DOUBLE PRECISION :: pwx1d
16017 DOUBLE PRECISION :: pwr1
16018 DOUBLE PRECISION :: pwr1d
16026 specified = .false.
16027 IF (config_flags%specified .OR. config_flags%nested) specified = &
16029 IF (kte .GT. kde - 1) THEN
16034 ! config_flags%h_sca_adv_order
16036 ! config_flags%v_sca_adv_order
16038 ! begin with horizontal flux divergence
16039 ! here is the choice of flux operators
16040 IF (horz_order .EQ. 5) THEN
16041 ! determine boundary mods for flux operators
16042 ! We degrade the flux operators from 3rd/4th order
16043 ! to second order one gridpoint in from the boundaries for
16044 ! all boundary conditions except periodic and symmetry - these
16045 ! conditions have boundary zone data fill for correct application
16046 ! of the higher order flux stencils
16047 degrade_xs = .true.
16048 degrade_xe = .true.
16049 degrade_ys = .true.
16050 degrade_ye = .true.
16051 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. &
16052 & its .GT. ids + 3) degrade_xs = .false.
16053 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. &
16054 & ite .LT. ide - 3) degrade_xe = .false.
16055 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. &
16056 & jts .GT. jds + 3) degrade_ys = .false.
16057 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. &
16058 & jte .LT. jde - 4) degrade_ye = .false.
16059 IF (kte .GT. kde - 1) THEN
16065 IF (ite .GT. ide - 1) THEN
16071 IF (is .EQ. 1) THEN
16074 IF (config_flags%open_xs .OR. specified) THEN
16075 IF (ids + 1 .LT. its) THEN
16081 IF (config_flags%open_xe .OR. specified) THEN
16082 IF (ide - 1 .GT. ite) THEN
16088 IF (config_flags%periodic_x) i_start = its
16089 IF (config_flags%periodic_x) i_end = ite
16092 IF (jte .GT. jde - 1) THEN
16097 ! higher order flux has a 5 or 7 point stencil, so compute
16098 ! bounds so we can switch to second order flux close to the boundary
16099 j_start_f = j_start
16100 j_end_f = j_end + 1
16101 IF (degrade_ys) THEN
16102 IF (jts .LT. jds + 1) THEN
16107 j_start_f = jds + 3
16109 IF (degrade_ye) THEN
16110 IF (jte .GT. jde - 2) THEN
16117 IF (config_flags%polar) THEN
16118 IF (jte .GT. jde - 1) THEN
16124 ! compute fluxes, 5th or 6th order
16128 j_loop_y_flux_5:DO j=j_start,j_end+1
16129 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
16134 veld = 0.5*(rvd(i, k, j)+rvd(i-is, k-ks, j-js))
16135 vel = 0.5*(rv(i, k, j)+rv(i-is, k-ks, j-js))
16136 IF (vel*sign(1,time_step) .GE. 0.0) THEN
16137 qip2d = fieldd(i, k, j+1)
16138 qip2 = field(i, k, j+1)
16139 qip1d = fieldd(i, k, j)
16140 qip1 = field(i, k, j)
16141 qid = fieldd(i, k, j-1)
16142 qi = field(i, k, j-1)
16143 qim1d = fieldd(i, k, j-2)
16144 qim1 = field(i, k, j-2)
16145 qim2d = fieldd(i, k, j-3)
16146 qim2 = field(i, k, j-3)
16148 qip2d = fieldd(i, k, j-2)
16149 qip2 = field(i, k, j-2)
16150 qip1d = fieldd(i, k, j-1)
16151 qip1 = field(i, k, j-1)
16152 qid = fieldd(i, k, j)
16153 qi = field(i, k, j)
16154 qim1d = fieldd(i, k, j+1)
16155 qim1 = field(i, k, j+1)
16156 qim2d = fieldd(i, k, j+2)
16157 qim2 = field(i, k, j+2)
16159 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
16160 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
16161 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
16162 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
16163 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
16164 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
16165 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + &
16166 & 2*(qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
16167 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+&
16169 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + &
16170 & 2*(qim1-qip1)*(qim1d-qip1d)/4.
16171 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
16172 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + &
16173 & 2*(qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
16174 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+&
16178 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))&
16180 pwr1d = pw*pwx1**(pw-1)*pwx1d
16181 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16187 wi0d = -(gi0*pwr1d/pwr1**2)
16191 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))&
16193 pwr1d = pw*pwx1**(pw-1)*pwx1d
16194 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16200 wi1d = -(gi1*pwr1d/pwr1**2)
16204 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))&
16206 pwr1d = pw*pwx1**(pw-1)*pwx1d
16207 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16213 wi2d = -(gi2*pwr1d/pwr1**2)
16215 sumwkd = wi0d + wi1d + wi2d
16216 sumwk = wi0 + wi1 + wi2
16217 fqyd(i, k, jp1) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0&
16218 & +wi0*f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*&
16219 & f0+wi1*f1+wi2*f2)*sumwkd)/sumwk**2
16220 fqy(i, k, jp1) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
16223 ELSE IF (j .EQ. jds + 1) THEN
16224 ! fqy( i, k, jp1 ) = vel*flux5( &
16225 ! field(i,k,j-3), field(i,k,j-2), field(i,k,j-1), &
16226 ! field(i,k,j ), field(i,k,j+1), field(i,k,j+2), vel )
16227 ! 2nd order flux next to south boundary
16230 ! fqy(i,k, jp1) = 0.5*0.5*( rv(i,k,j) + rv(i-is,k-ks,j-js) )* &
16231 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
16232 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
16234 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
16238 ELSE IF (j .EQ. jds + 2) THEN
16239 ! third of 4th order flux 2 in from south boundary
16242 ! vel = 0.5*( rv(i,k,j) + rv(i-is,k-ks,j-js) )
16243 veld = rvd(i, k, j)
16245 fqyd(i, k, jp1) = veld*(7./12.*(field(i, k, j)+field(i, k, j&
16246 & -1))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1., &
16247 & vel)*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-3.*(field&
16248 & (i, k, j)-field(i, k, j-1)))) + vel*(7.*(fieldd(i, k, j)+&
16249 & fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+fieldd(i, k, j-2&
16250 & ))/12.+SIGN(1., vel)*(fieldd(i, k, j+1)-fieldd(i, k, j-2)-&
16251 & 3.*(fieldd(i, k, j)-fieldd(i, k, j-1)))/12.)
16252 fqy(i, k, jp1) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1&
16253 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1., vel&
16254 & )*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-3.*(field(i&
16255 & , k, j)-field(i, k, j-1))))
16258 ELSE IF (j .EQ. jde - 1) THEN
16259 ! 2nd order flux next to north boundary
16262 ! fqy(i, k, jp1) = 0.5*0.5*( rv(i,k,j) + rv(i-is,k-ks,j-js) )* &
16263 fqyd(i, k, jp1) = 0.5*(rvd(i, k, j)*(field(i, k, j)+field(i&
16264 & , k, j-1))+rv(i, k, j)*(fieldd(i, k, j)+fieldd(i, k, j-1))&
16266 fqy(i, k, jp1) = 0.5*rv(i, k, j)*(field(i, k, j)+field(i, k&
16270 ELSE IF (j .EQ. jde - 2) THEN
16271 ! 3rd or 4th order flux 2 in from north boundary
16274 veld = rvd(i, k, j)
16276 ! vel = 0.5*( rv(i,k,j) + rv(i-is,k-ks,j-js) )
16277 fqyd(i, k, jp1) = veld*(7./12.*(field(i, k, j)+field(i, k, j&
16278 & -1))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1., &
16279 & vel)*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-3.*(field&
16280 & (i, k, j)-field(i, k, j-1)))) + vel*(7.*(fieldd(i, k, j)+&
16281 & fieldd(i, k, j-1))/12.-(fieldd(i, k, j+1)+fieldd(i, k, j-2&
16282 & ))/12.+SIGN(1., vel)*(fieldd(i, k, j+1)-fieldd(i, k, j-2)-&
16283 & 3.*(fieldd(i, k, j)-fieldd(i, k, j-1)))/12.)
16284 fqy(i, k, jp1) = vel*(7./12.*(field(i, k, j)+field(i, k, j-1&
16285 & ))-1./12.*(field(i, k, j+1)+field(i, k, j-2))+SIGN(1., vel&
16286 & )*(1./12.)*(field(i, k, j+1)-field(i, k, j-2)-3.*(field(i&
16287 & , k, j)-field(i, k, j-1))))
16291 ! y flux-divergence into tendency
16292 IF (is .EQ. 0) THEN
16293 ! Comments on polar boundary conditions
16294 ! Same process as for advect_u - tendencies run from jds to jde-1
16295 ! (latitudes are as for u grid, longitudes are displaced)
16296 ! Therefore: flow is only from one side for points next to poles
16297 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
16300 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
16301 mrdy = msftx(i, j-1)*rdy
16302 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i&
16304 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k&
16308 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
16311 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
16312 mrdy = msftx(i, j-1)*rdy
16313 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i&
16315 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k&
16319 ELSE IF (j .GT. j_start) THEN
16323 ! see ADT eqn 48 [rho->rho*q] dividing by my, 2nd term RHS
16324 mrdy = msftx(i, j-1)*rdy
16325 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i&
16326 & , k, jp1)-fqyd(i, k, jp0))
16327 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k&
16328 & , jp1)-fqy(i, k, jp0))
16332 ELSE IF (is .EQ. 1) THEN
16333 ! (j > j_start) will miss the u(,,jds) tendency
16334 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
16337 ! ADT eqn 44, 2nd term on RHS
16338 mrdy = msfux(i, j-1)*rdy
16339 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i&
16341 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k&
16345 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
16346 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
16349 ! ADT eqn 44, 2nd term on RHS
16350 mrdy = msfux(i, j-1)*rdy
16351 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i&
16353 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k&
16357 ELSE IF (j .GT. j_start) THEN
16361 ! ADT eqn 44, 2nd term on RHS
16362 mrdy = msfux(i, j-1)*rdy
16363 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i&
16364 & , k, jp1)-fqyd(i, k, jp0))
16365 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k&
16366 & , jp1)-fqy(i, k, jp0))
16374 END DO j_loop_y_flux_5
16375 ! next, x - flux divergence
16377 IF (ite .GT. ide - 1) THEN
16383 IF (jte .GT. jde - 1) THEN
16388 ! higher order flux has a 5 or 7 point stencil, so compute
16389 ! bounds so we can switch to second order flux close to the boundary
16390 i_start_f = i_start
16391 i_end_f = i_end + 1
16392 IF (degrade_xs) THEN
16393 IF (ids + 1 .LT. its) THEN
16398 IF (i_start + 2 .GT. ids + 3) THEN
16399 i_start_f = ids + 3
16401 i_start_f = i_start + 2
16404 IF (degrade_xe) THEN
16405 IF (ide - 2 .GT. ite) THEN
16417 ! 5th or 6th order flux
16419 DO i=i_start_f,i_end_f
16421 veld = 0.5*(rud(i, k, j)+rud(i-is, k-ks, j-js))
16422 vel = 0.5*(ru(i, k, j)+ru(i-is, k-ks, j-js))
16423 IF (vel*sign(1,time_step) .GE. 0.0) THEN
16424 qip2d = fieldd(i+1, k, j)
16425 qip2 = field(i+1, k, j)
16426 qip1d = fieldd(i, k, j)
16427 qip1 = field(i, k, j)
16428 qid = fieldd(i-1, k, j)
16429 qi = field(i-1, k, j)
16430 qim1d = fieldd(i-2, k, j)
16431 qim1 = field(i-2, k, j)
16432 qim2d = fieldd(i-3, k, j)
16433 qim2 = field(i-3, k, j)
16435 qip2d = fieldd(i-2, k, j)
16436 qip2 = field(i-2, k, j)
16437 qip1d = fieldd(i-1, k, j)
16438 qip1 = field(i-1, k, j)
16439 qid = fieldd(i, k, j)
16440 qi = field(i, k, j)
16441 qim1d = fieldd(i+1, k, j)
16442 qim1 = field(i+1, k, j)
16443 qim2d = fieldd(i+2, k, j)
16444 qim2 = field(i+2, k, j)
16446 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
16447 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
16448 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
16449 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
16450 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
16451 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
16452 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*&
16453 & (qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
16454 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*&
16456 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*&
16457 & (qim1-qip1)*(qim1d-qip1d)/4.
16458 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
16459 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*&
16460 & (qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
16461 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*&
16465 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16467 pwr1d = pw*pwx1**(pw-1)*pwx1d
16468 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16474 wi0d = -(gi0*pwr1d/pwr1**2)
16478 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16480 pwr1d = pw*pwx1**(pw-1)*pwx1d
16481 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16487 wi1d = -(gi1*pwr1d/pwr1**2)
16491 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16493 pwr1d = pw*pwx1**(pw-1)*pwx1d
16494 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16500 wi2d = -(gi2*pwr1d/pwr1**2)
16502 sumwkd = wi0d + wi1d + wi2d
16503 sumwk = wi0 + wi1 + wi2
16504 fqxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
16505 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*&
16506 & f1+wi2*f2)*sumwkd)/sumwk**2
16507 fqx(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
16510 ! fqx( i,k ) = vel*flux5( field(i-3,k,j), field(i-2,k,j), &
16511 ! field(i-1,k,j), field(i ,k,j), &
16512 ! field(i+1,k,j), field(i+2,k,j), &
16514 ! lower order fluxes close to boundaries (if not periodic or symmetric)
16515 IF (degrade_xs) THEN
16516 DO i=i_start,i_start_f-1
16517 IF (i .EQ. ids + 1) THEN
16520 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
16521 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
16522 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
16526 IF (i .EQ. ids + 2) THEN
16529 veld = rud(i, k, j)
16531 fqxd(i, k) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j)&
16532 & )-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1., &
16533 & vel)*(1./12.)*(field(i+1, k, j)-field(i-2, k, j)-3.*(&
16534 & field(i, k, j)-field(i-1, k, j)))) + vel*(7.*(fieldd(i, &
16535 & k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k, j)+fieldd(i&
16536 & -2, k, j))/12.+SIGN(1., vel)*(fieldd(i+1, k, j)-fieldd(i&
16537 & -2, k, j)-3.*(fieldd(i, k, j)-fieldd(i-1, k, j)))/12.)
16538 fqx(i, k) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))-&
16539 & 1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1., vel)&
16540 & *(1./12.)*(field(i+1, k, j)-field(i-2, k, j)-3.*(field(i&
16541 & , k, j)-field(i-1, k, j))))
16546 IF (degrade_xe) THEN
16547 DO i=i_end_f+1,i_end+1
16548 IF (i .EQ. ide - 1) THEN
16549 ! second order flux next to the boundary
16551 fqxd(i, k) = 0.5*(rud(i, k, j)*(field(i, k, j)+field(i-1, &
16552 & k, j))+ru(i, k, j)*(fieldd(i, k, j)+fieldd(i-1, k, j)))
16553 fqx(i, k) = 0.5*ru(i, k, j)*(field(i, k, j)+field(i-1, k, &
16557 IF (i .EQ. ide - 2) THEN
16558 ! third order flux one in from the boundary
16560 veld = rud(i, k, j)
16562 fqxd(i, k) = veld*(7./12.*(field(i, k, j)+field(i-1, k, j)&
16563 & )-1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1., &
16564 & vel)*(1./12.)*(field(i+1, k, j)-field(i-2, k, j)-3.*(&
16565 & field(i, k, j)-field(i-1, k, j)))) + vel*(7.*(fieldd(i, &
16566 & k, j)+fieldd(i-1, k, j))/12.-(fieldd(i+1, k, j)+fieldd(i&
16567 & -2, k, j))/12.+SIGN(1., vel)*(fieldd(i+1, k, j)-fieldd(i&
16568 & -2, k, j)-3.*(fieldd(i, k, j)-fieldd(i-1, k, j)))/12.)
16569 fqx(i, k) = vel*(7./12.*(field(i, k, j)+field(i-1, k, j))-&
16570 & 1./12.*(field(i+1, k, j)+field(i-2, k, j))+SIGN(1., vel)&
16571 & *(1./12.)*(field(i+1, k, j)-field(i-2, k, j)-3.*(field(i&
16572 & , k, j)-field(i-1, k, j))))
16577 ! x flux-divergence into tendency
16578 IF (is .EQ. 0) THEN
16581 ! see ADT eqn 48 [rho->rho*q] dividing by my, 1st term RHS
16582 mrdx = msftx(i, j)*rdx
16583 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)&
16585 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-&
16589 ELSE IF (is .EQ. 1) THEN
16592 ! ADT eqn 44, 1st term on RHS
16593 mrdx = msfux(i, j)*rdx
16594 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)&
16596 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-&
16603 ! pick up the rest of the horizontal radiation boundary conditions.
16604 ! (these are the computations that don't require 'cb'.
16605 ! first, set to index ranges
16607 IF (ite .GT. ide - 1) THEN
16613 IF (jte .GT. jde - 1) THEN
16618 ! compute x (u) conditions for v, w, or scalar
16619 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
16622 IF (0.5*(ru(its, k, j)+ru(its+1, k, j)) .GT. 0.) THEN
16626 ubd = 0.5*(rud(its, k, j)+rud(its+1, k, j))
16627 ub = 0.5*(ru(its, k, j)+ru(its+1, k, j))
16629 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(&
16630 & field_old(its+1, k, j)-field_old(its, k, j))+ub*(field_oldd(&
16631 & its+1, k, j)-field_oldd(its, k, j))+fieldd(its, k, j)*(ru(its+&
16632 & 1, k, j)-ru(its, k, j))+field(its, k, j)*(rud(its+1, k, j)-rud&
16634 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(field_old(&
16635 & its+1, k, j)-field_old(its, k, j))+field(its, k, j)*(ru(its+1&
16636 & , k, j)-ru(its, k, j)))
16640 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
16643 IF (0.5*(ru(ite-1, k, j)+ru(ite, k, j)) .LT. 0.) THEN
16647 ubd = 0.5*(rud(ite-1, k, j)+rud(ite, k, j))
16648 ub = 0.5*(ru(ite-1, k, j)+ru(ite, k, j))
16650 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
16651 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+ub*(&
16652 & field_oldd(i_end, k, j)-field_oldd(i_end-1, k, j))+fieldd(&
16653 & i_end, k, j)*(ru(ite, k, j)-ru(ite-1, k, j))+field(i_end, k, j&
16654 & )*(rud(ite, k, j)-rud(ite-1, k, j)))
16655 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(&
16656 & field_old(i_end, k, j)-field_old(i_end-1, k, j))+field(i_end, &
16657 & k, j)*(ru(ite, k, j)-ru(ite-1, k, j)))
16661 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
16664 IF (0.5*(rv(i, k, jts)+rv(i, k, jts+1)) .GT. 0.) THEN
16668 vbd = 0.5*(rvd(i, k, jts)+rvd(i, k, jts+1))
16669 vb = 0.5*(rv(i, k, jts)+rv(i, k, jts+1))
16671 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(&
16672 & field_old(i, k, jts+1)-field_old(i, k, jts))+vb*(field_oldd(i&
16673 & , k, jts+1)-field_oldd(i, k, jts))+fieldd(i, k, jts)*(rv(i, k&
16674 & , jts+1)-rv(i, k, jts))+field(i, k, jts)*(rvd(i, k, jts+1)-rvd&
16676 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(field_old(i&
16677 & , k, jts+1)-field_old(i, k, jts))+field(i, k, jts)*(rv(i, k, &
16678 & jts+1)-rv(i, k, jts)))
16682 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
16685 IF (0.5*(rv(i, k, jte-1)+rv(i, k, jte)) .LT. 0.) THEN
16689 vbd = 0.5*(rvd(i, k, jte-1)+rvd(i, k, jte))
16690 vb = 0.5*(rv(i, k, jte-1)+rv(i, k, jte))
16692 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
16693 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+vb*(&
16694 & field_oldd(i, k, j_end)-field_oldd(i, k, j_end-1))+fieldd(i, k&
16695 & , j_end)*(rv(i, k, jte)-rv(i, k, jte-1))+field(i, k, j_end)*(&
16696 & rvd(i, k, jte)-rvd(i, k, jte-1)))
16697 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(&
16698 & field_old(i, k, j_end)-field_old(i, k, j_end-1))+field(i, k, &
16699 & j_end)*(rv(i, k, jte)-rv(i, k, jte-1)))
16703 !-------------------- vertical advection
16704 ! Scalar equation has 3rd term on RHS = - partial d/dz (q rho w /my)
16705 ! Here we have: - partial d/dz (q*rom) = - partial d/dz (q rho w / my)
16706 ! So we don't need to make a correction for advect_scalar
16708 IF (ite .GT. ide - 1) THEN
16714 IF (jte .GT. jde - 1) THEN
16720 vfluxd(i, kts) = 0.0
16722 vfluxd(i, kte) = 0.0
16730 veld = 0.5*(romd(i, k, j)+romd(i-is, k-ks, j-js))
16731 vel = 0.5*(rom(i, k, j)+rom(i-is, k-ks, j-js))
16732 IF (-vel*sign(1,time_step) .GE. 0.0) THEN
16733 qip2d = fieldd(i, k+1, j)
16734 qip2 = field(i, k+1, j)
16735 qip1d = fieldd(i, k, j)
16736 qip1 = field(i, k, j)
16737 qid = fieldd(i, k-1, j)
16738 qi = field(i, k-1, j)
16739 qim1d = fieldd(i, k-2, j)
16740 qim1 = field(i, k-2, j)
16741 qim2d = fieldd(i, k-3, j)
16742 qim2 = field(i, k-3, j)
16744 qip2d = fieldd(i, k-2, j)
16745 qip2 = field(i, k-2, j)
16746 qip1d = fieldd(i, k-1, j)
16747 qip1 = field(i, k-1, j)
16748 qid = fieldd(i, k, j)
16749 qi = field(i, k, j)
16750 qim1d = fieldd(i, k+1, j)
16751 qim1 = field(i, k+1, j)
16752 qim2d = fieldd(i, k+2, j)
16753 qim2 = field(i, k+2, j)
16755 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
16756 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
16757 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
16758 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
16759 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
16760 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
16761 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
16762 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
16763 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
16765 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
16766 & qim1-qip1)*(qim1d-qip1d)/4.
16767 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
16768 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
16769 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
16770 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
16774 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16776 pwr1d = pw*pwx1**(pw-1)*pwx1d
16777 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16783 wi0d = -(gi0*pwr1d/pwr1**2)
16787 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16789 pwr1d = pw*pwx1**(pw-1)*pwx1d
16790 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16796 wi1d = -(gi1*pwr1d/pwr1**2)
16800 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
16802 pwr1d = pw*pwx1**(pw-1)*pwx1d
16803 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
16809 wi2d = -(gi2*pwr1d/pwr1**2)
16811 sumwkd = wi0d + wi1d + wi2d
16812 sumwk = wi0 + wi1 + wi2
16813 vfluxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
16814 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
16815 & +wi2*f2)*sumwkd)/sumwk**2
16816 vflux(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
16819 ! vflux(i,k) = vel*flux5( &
16820 ! field(i,k-3,j), field(i,k-2,j), field(i,k-1,j), &
16821 ! field(i,k ,j), field(i,k+1,j), field(i,k+2,j), -vel )
16824 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
16825 & , k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*fieldd(&
16827 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i, &
16830 veld = romd(i, k, j)
16832 vfluxd(i, k) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
16833 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1., -vel)*(1./12.)*&
16834 & (field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-field(i, k&
16835 & -1, j)))) + vel*(7.*(fieldd(i, k, j)+fieldd(i, k-1, j))/12.-(&
16836 & fieldd(i, k+1, j)+fieldd(i, k-2, j))/12.+SIGN(1., -vel)*(fieldd(&
16837 & i, k+1, j)-fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, &
16839 vflux(i, k) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./12.&
16840 & *(field(i, k+1, j)+field(i, k-2, j))+SIGN(1., -vel)*(1./12.)*(&
16841 & field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-field(i, k-&
16844 veld = romd(i, k, j)
16846 vfluxd(i, k) = veld*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./&
16847 & 12.*(field(i, k+1, j)+field(i, k-2, j))+SIGN(1., -vel)*(1./12.)*&
16848 & (field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-field(i, k&
16849 & -1, j)))) + vel*(7.*(fieldd(i, k, j)+fieldd(i, k-1, j))/12.-(&
16850 & fieldd(i, k+1, j)+fieldd(i, k-2, j))/12.+SIGN(1., -vel)*(fieldd(&
16851 & i, k+1, j)-fieldd(i, k-2, j)-3.*(fieldd(i, k, j)-fieldd(i, k-1, &
16853 vflux(i, k) = vel*(7./12.*(field(i, k, j)+field(i, k-1, j))-1./12.&
16854 & *(field(i, k+1, j)+field(i, k-2, j))+SIGN(1., -vel)*(1./12.)*(&
16855 & field(i, k+1, j)-field(i, k-2, j)-3.*(field(i, k, j)-field(i, k-&
16858 vfluxd(i, k) = romd(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i&
16859 & , k-1, j)) + rom(i, k, j)*(fzm(k)*fieldd(i, k, j)+fzp(k)*fieldd(&
16861 vflux(i, k) = rom(i, k, j)*(fzm(k)*field(i, k, j)+fzp(k)*field(i, &
16866 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k+1&
16868 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)-&
16873 END SUBROUTINE G_ADVECT_SCALAR_WENO
16875 ! Generated by TAPENADE (INRIA, Tropics team)
16876 ! Tapenade 3.6 (r4165) - 21 sep 2011 20:54
16878 ! Differentiation of advect_weno_u in forward (tangent) mode:
16879 ! variations of useful results: tendency
16880 ! with respect to varying inputs: rom u tendency u_old ru rv
16882 ! RW status of diff variables: rom:in u:in tendency:in-out u_old:in
16883 ! ru:in rv:in mut:in
16884 SUBROUTINE G_ADVECT_WENO_U(u, ud, u_old, u_oldd, tendency, tendencyd, ru&
16885 & , rud, rv, rvd, rom, romd, mut, mutd, time_step, config_flags, msfux, &
16886 & msfuy, msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzw, ids, ide&
16887 & , jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte&
16891 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
16892 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
16893 & jme, kms, kme, its, ite, jts, jte, kts, kte
16894 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: u, u_old, ru&
16896 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ud, u_oldd, &
16898 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
16899 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd
16900 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
16901 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
16902 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
16903 & msfvy, msftx, msfty
16904 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
16905 REAL, INTENT(IN) :: rdx, rdy
16906 INTEGER, INTENT(IN) :: time_step
16908 INTEGER :: i, j, k, itf, jtf, ktf
16909 INTEGER :: i_start, i_end, j_start, j_end
16910 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
16911 INTEGER :: jmin, jmax, jp, jm, imin, imax, im, ip
16912 INTEGER :: jp1, jp0, jtmp
16914 REAL :: ue, vs, vn, wb, wt
16915 REAL, PARAMETER :: f30=7./12., f31=1./12.
16916 REAL, PARAMETER :: f50=37./60., f51=2./15., f52=1./60.
16918 REAL :: qim2, qim1, qi, qip1, qip2
16919 REAL :: qim2d, qim1d, qid, qip1d, qip2d
16920 DOUBLE PRECISION :: beta0, beta1, beta2, f0, f1, f2, wi0, wi1, wi2, &
16922 DOUBLE PRECISION :: beta0d, beta1d, beta2d, f0d, f1d, f2d, wi0d, wi1d&
16924 DOUBLE PRECISION, PARAMETER :: gi0=1.d0/10.d0, gi1=6.d0/10.d0, gi2=&
16925 & 3.d0/10.d0, eps=1.0d-18
16926 INTEGER, PARAMETER :: pw=2
16927 INTEGER :: horz_order, vert_order
16928 REAL :: mrdx, mrdy, ub, vb, uw, vw, dvm, dvp
16929 REAL :: ubd, vbd, vwd, dvmd, dvpd
16930 REAL, DIMENSION(its:ite, kts:kte) :: vflux
16931 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
16932 REAL, DIMENSION(its - 1:ite + 1, kts:kte) :: fqx
16933 REAL, DIMENSION(its-1:ite+1, kts:kte) :: fqxd
16934 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
16935 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
16936 LOGICAL :: degrade_xs, degrade_ys
16937 LOGICAL :: degrade_xe, degrade_ye
16938 ! definition of flux operators, 3rd, 4th, 5th or 6th order
16939 REAL :: flux3, flux4, flux5, flux6
16940 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
16942 LOGICAL :: specified
16943 DOUBLE PRECISION :: pwx1
16944 DOUBLE PRECISION :: pwx1d
16945 DOUBLE PRECISION :: pwr1
16946 DOUBLE PRECISION :: pwr1d
16954 specified = .false.
16955 IF (config_flags%specified .OR. config_flags%nested) specified = &
16957 ! set order for vertical and horzontal flux operators
16958 horz_order = config_flags%h_mom_adv_order
16959 vert_order = config_flags%v_mom_adv_order
16960 IF (kte .GT. kde - 1) THEN
16965 ! begin with horizontal flux divergence
16966 ! horizontal_order_test : IF( horz_order == 6 ) THEN
16967 ! ELSE IF( horz_order == 5 ) THEN
16968 ! 5th order horizontal flux calculation
16969 ! This code is EXACTLY the same as the 6th order code
16970 ! EXCEPT the 5th order and 3rd operators are used in
16971 ! place of the 6th and 4th order operators
16972 ! determine boundary mods for flux operators
16973 ! We degrade the flux operators from 3rd/4th order
16974 ! to second order one gridpoint in from the boundaries for
16975 ! all boundary conditions except periodic and symmetry - these
16976 ! conditions have boundary zone data fill for correct application
16977 ! of the higher order flux stencils
16978 degrade_xs = .true.
16979 degrade_xe = .true.
16980 degrade_ys = .true.
16981 degrade_ye = .true.
16982 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. its &
16983 & .GT. ids + 3) degrade_xs = .false.
16984 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. ite &
16985 & .LT. ide - 2) degrade_xe = .false.
16986 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. jts &
16987 & .GT. jds + 3) degrade_ys = .false.
16988 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. jte &
16989 & .LT. jde - 4) degrade_ye = .false.
16990 !--------------- y - advection first
16993 IF (config_flags%open_xs .OR. specified) THEN
16994 IF (ids + 1 .LT. its) THEN
17000 IF (config_flags%open_xe .OR. specified) THEN
17001 IF (ide - 1 .GT. ite) THEN
17007 IF (config_flags%periodic_x) i_start = its
17008 IF (config_flags%periodic_x) i_end = ite
17010 IF (jte .GT. jde - 1) THEN
17015 ! higher order flux has a 5 or 7 point stencil, so compute
17016 ! bounds so we can switch to second order flux close to the boundary
17017 j_start_f = j_start
17018 j_end_f = j_end + 1
17019 IF (degrade_ys) THEN
17020 IF (jts .LT. jds + 1) THEN
17025 j_start_f = jds + 3
17027 IF (degrade_ye) THEN
17028 IF (jte .GT. jde - 2) THEN
17035 IF (config_flags%polar) THEN
17036 IF (jte .GT. jde - 1) THEN
17042 ! compute fluxes, 5th or 6th order
17046 j_loop_y_flux_5:DO j=j_start,j_end+1
17047 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
17051 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
17052 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
17053 IF (vel*sign(1,time_step) .GE. 0.0) THEN
17054 qip2d = ud(i, k, j+1)
17055 qip2 = u(i, k, j+1)
17056 qip1d = ud(i, k, j)
17058 qid = ud(i, k, j-1)
17060 qim1d = ud(i, k, j-2)
17061 qim1 = u(i, k, j-2)
17062 qim2d = ud(i, k, j-3)
17063 qim2 = u(i, k, j-3)
17065 qip2d = ud(i, k, j-2)
17066 qip2 = u(i, k, j-2)
17067 qip1d = ud(i, k, j-1)
17068 qip1 = u(i, k, j-1)
17071 qim1d = ud(i, k, j+1)
17072 qim1 = u(i, k, j+1)
17073 qim2d = ud(i, k, j+2)
17074 qim2 = u(i, k, j+2)
17076 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
17077 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
17078 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
17079 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
17080 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
17081 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
17082 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*&
17083 & (qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
17084 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*&
17086 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*&
17087 & (qim1-qip1)*(qim1d-qip1d)/4.
17088 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
17089 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*&
17090 & (qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
17091 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*&
17095 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17097 pwr1d = pw*pwx1**(pw-1)*pwx1d
17098 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17104 wi0d = -(gi0*pwr1d/pwr1**2)
17108 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17110 pwr1d = pw*pwx1**(pw-1)*pwx1d
17111 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17117 wi1d = -(gi1*pwr1d/pwr1**2)
17121 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17123 pwr1d = pw*pwx1**(pw-1)*pwx1d
17124 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17130 wi2d = -(gi2*pwr1d/pwr1**2)
17132 sumwkd = wi0d + wi1d + wi2d
17133 sumwk = wi0 + wi1 + wi2
17134 fqyd(i, k, jp1) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+&
17135 & wi0*f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+&
17136 & wi1*f1+wi2*f2)*sumwkd)/sumwk**2
17137 fqy(i, k, jp1) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
17140 ELSE IF (j .EQ. jds + 1) THEN
17141 ! fqy( i, k, jp1 ) = vel*flux5( &
17142 ! u(i,k,j-3), u(i,k,j-2), u(i,k,j-1), &
17143 ! u(i,k,j ), u(i,k,j+1), u(i,k,j+2), vel )
17144 ! we must be close to some boundary where we need to reduce the order of the stencil
17145 ! 2nd order flux next to south boundary
17148 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, k&
17149 & , j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, j)+&
17151 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j)+&
17155 ELSE IF (j .EQ. jds + 2) THEN
17156 ! third of 4th order flux 2 in from south boundary
17159 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
17160 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
17161 fqyd(i, k, jp1) = veld*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
17162 & , j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
17163 & (u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))/&
17164 & 12.0) + vel*((7.*(ud(i, k, j)+ud(i, k, j-1))-ud(i, k, j+1)-&
17165 & ud(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i, &
17166 & k, j+1)-ud(i, k, j-2)-3.*(ud(i, k, j)-ud(i, k, j-1)))/12.0)
17167 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k, j&
17168 & +1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(&
17169 & i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))/12.0)
17172 ELSE IF (j .EQ. jde - 1) THEN
17173 ! 2nd order flux next to north boundary
17176 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i-1, k, j))*(u(i, k&
17177 & , j)+u(i, k, j-1))+(rv(i, k, j)+rv(i-1, k, j))*(ud(i, k, j)+&
17179 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i-1, k, j))*(u(i, k, j)+&
17183 ELSE IF (j .EQ. jde - 2) THEN
17184 ! 3rd order flux 2 in from north boundary
17187 veld = 0.5*(rvd(i, k, j)+rvd(i-1, k, j))
17188 vel = 0.5*(rv(i, k, j)+rv(i-1, k, j))
17189 fqyd(i, k, jp1) = veld*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k&
17190 & , j+1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
17191 & (u(i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))/&
17192 & 12.0) + vel*((7.*(ud(i, k, j)+ud(i, k, j-1))-ud(i, k, j+1)-&
17193 & ud(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i, &
17194 & k, j+1)-ud(i, k, j-2)-3.*(ud(i, k, j)-ud(i, k, j-1)))/12.0)
17195 fqy(i, k, jp1) = vel*((7.*(u(i, k, j)+u(i, k, j-1))-(u(i, k, j&
17196 & +1)+u(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(&
17197 & i, k, j+1)-u(i, k, j-2)-3.*(u(i, k, j)-u(i, k, j-1)))/12.0)
17201 ! y flux-divergence into tendency
17202 ! (j > j_start) will miss the u(,,jds) tendency
17203 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
17206 ! ADT eqn 44, 2nd term on RHS
17207 mrdy = msfux(i, j-1)*rdy
17208 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k, &
17210 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, jp1&
17214 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
17215 ! This would be seen by (j > j_start) but we need to zero out the NP tendency
17218 ! ADT eqn 44, 2nd term on RHS
17219 mrdy = msfux(i, j-1)*rdy
17220 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k, &
17222 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, jp0&
17226 ELSE IF (j .GT. j_start) THEN
17230 ! ADT eqn 44, 2nd term on RHS
17231 mrdy = msfux(i, j-1)*rdy
17232 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, k&
17233 & , jp1)-fqyd(i, k, jp0))
17234 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
17235 & jp1)-fqy(i, k, jp0))
17242 END DO j_loop_y_flux_5
17243 ! next, x - flux divergence
17247 IF (jte .GT. jde - 1) THEN
17252 ! higher order flux has a 5 or 7 point stencil, so compute
17253 ! bounds so we can switch to second order flux close to the boundary
17254 i_start_f = i_start
17255 i_end_f = i_end + 1
17256 IF (degrade_xs) THEN
17257 IF (ids + 1 .LT. its) THEN
17262 i_start_f = ids + 3
17264 IF (degrade_xe) THEN
17265 IF (ide - 1 .GT. ite) THEN
17277 ! 5th or 6th order flux
17279 DO i=i_start_f,i_end_f
17280 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
17281 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
17282 IF (vel*sign(1,time_step) .GE. 0.0) THEN
17283 qip2d = ud(i+1, k, j)
17284 qip2 = u(i+1, k, j)
17285 qip1d = ud(i, k, j)
17287 qid = ud(i-1, k, j)
17289 qim1d = ud(i-2, k, j)
17290 qim1 = u(i-2, k, j)
17291 qim2d = ud(i-3, k, j)
17292 qim2 = u(i-3, k, j)
17294 qip2d = ud(i-2, k, j)
17295 qip2 = u(i-2, k, j)
17296 qip1d = ud(i-1, k, j)
17297 qip1 = u(i-1, k, j)
17300 qim1d = ud(i+1, k, j)
17301 qim1 = u(i+1, k, j)
17302 qim2d = ud(i+2, k, j)
17303 qim2 = u(i+2, k, j)
17305 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
17306 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
17307 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
17308 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
17309 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
17310 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
17311 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
17312 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
17313 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
17315 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
17316 & qim1-qip1)*(qim1d-qip1d)/4.
17317 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
17318 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
17319 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
17320 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
17324 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17326 pwr1d = pw*pwx1**(pw-1)*pwx1d
17327 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17333 wi0d = -(gi0*pwr1d/pwr1**2)
17337 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17339 pwr1d = pw*pwx1**(pw-1)*pwx1d
17340 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17346 wi1d = -(gi1*pwr1d/pwr1**2)
17350 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17352 pwr1d = pw*pwx1**(pw-1)*pwx1d
17353 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17359 wi2d = -(gi2*pwr1d/pwr1**2)
17361 sumwkd = wi0d + wi1d + wi2d
17362 sumwk = wi0 + wi1 + wi2
17363 fqxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*f0d+&
17364 & wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1+wi2&
17365 & *f2)*sumwkd)/sumwk**2
17366 fqx(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
17369 ! fqx( i,k ) = vel*flux5( u(i-3,k,j), u(i-2,k,j), &
17370 ! u(i-1,k,j), u(i ,k,j), &
17371 ! u(i+1,k,j), u(i+2,k,j), &
17373 ! lower order fluxes close to boundaries (if not periodic or symmetric)
17374 ! specified uses upstream normal wind at boundaries
17375 IF (degrade_xs) THEN
17376 IF (i_start .EQ. ids + 1) THEN
17377 ! second order flux next to the boundary
17380 ubd = ud(i-1, k, j)
17382 IF (specified .AND. u(i, k, j) .LT. 0.) THEN
17386 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i, k, j)+&
17387 & ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i, k, j)+ubd))
17388 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i, k, j)+ub)
17393 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
17394 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
17395 fqxd(i, k) = veld*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
17396 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, k&
17397 & , j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0) + vel*((&
17398 & 7.*(ud(i, k, j)+ud(i-1, k, j))-ud(i+1, k, j)-ud(i-2, k, j))/&
17399 & 12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i+1, k, j)-ud(i-2, k&
17400 & , j)-3.*(ud(i, k, j)-ud(i-1, k, j)))/12.0)
17401 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u(i&
17402 & -2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, k, j&
17403 & )-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0)
17406 IF (degrade_xe) THEN
17407 IF (i_end .EQ. ide - 1) THEN
17408 ! second order flux next to the boundary
17413 IF (specified .AND. u(i-1, k, j) .GT. 0.) THEN
17414 ubd = ud(i-1, k, j)
17417 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i-1, k, j))*(u(i-1, k, j)&
17418 & +ub)+(ru(i, k, j)+ru(i-1, k, j))*(ud(i-1, k, j)+ubd))
17419 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i-1, k, j))*(u(i-1, k, j)+ub)
17424 veld = 0.5*(rud(i, k, j)+rud(i-1, k, j))
17425 vel = 0.5*(ru(i, k, j)+ru(i-1, k, j))
17426 fqxd(i, k) = veld*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u&
17427 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, k&
17428 & , j)-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0) + vel*((&
17429 & 7.*(ud(i, k, j)+ud(i-1, k, j))-ud(i+1, k, j)-ud(i-2, k, j))/&
17430 & 12.0+SIGN(1, time_step)*SIGN(1., vel)*(ud(i+1, k, j)-ud(i-2, k&
17431 & , j)-3.*(ud(i, k, j)-ud(i-1, k, j)))/12.0)
17432 fqx(i, k) = vel*((7.*(u(i, k, j)+u(i-1, k, j))-(u(i+1, k, j)+u(i&
17433 & -2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(u(i+1, k, j&
17434 & )-u(i-2, k, j)-3.*(u(i, k, j)-u(i-1, k, j)))/12.0)
17437 ! x flux-divergence into tendency
17440 ! ADT eqn 44, 1st term on RHS
17441 mrdx = msfux(i, j)*rdx
17442 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
17444 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(i&
17449 ! radiative lateral boundary condition in x for normal velocity (u)
17450 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
17452 IF (jte .GT. jde - 1) THEN
17459 IF (ru(its, k, j) - cb*mut(its, j) .GT. 0.) THEN
17463 ubd = rud(its, k, j) - cb*mutd(its, j)
17464 ub = ru(its, k, j) - cb*mut(its, j)
17466 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(u_old(&
17467 & its+1, k, j)-u_old(its, k, j))+ub*(u_oldd(its+1, k, j)-u_oldd(&
17469 tendency(its, k, j) = tendency(its, k, j) - rdx*ub*(u_old(its+1&
17470 & , k, j)-u_old(its, k, j))
17474 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
17476 IF (jte .GT. jde - 1) THEN
17483 IF (ru(ite, k, j) + cb*mut(ite-1, j) .LT. 0.) THEN
17487 ubd = rud(ite, k, j) + cb*mutd(ite-1, j)
17488 ub = ru(ite, k, j) + cb*mut(ite-1, j)
17490 tendencyd(ite, k, j) = tendencyd(ite, k, j) - rdx*(ubd*(u_old(&
17491 & ite, k, j)-u_old(ite-1, k, j))+ub*(u_oldd(ite, k, j)-u_oldd(&
17493 tendency(ite, k, j) = tendency(ite, k, j) - rdx*ub*(u_old(ite, k&
17494 & , j)-u_old(ite-1, k, j))
17498 ! pick up the rest of the horizontal radiation boundary conditions.
17499 ! (these are the computations that don't require 'cb')
17500 ! first, set to index ranges
17502 IF (ite .GT. ide) THEN
17509 IF (config_flags%open_xs) THEN
17510 IF (ids + 1 .LT. its) THEN
17517 IF (config_flags%open_xe) THEN
17518 IF (ite .GT. ide - 1) THEN
17525 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
17527 ! ADT eqn 44, 2nd term on RHS
17528 mrdy = msfux(i, jts)*rdy
17529 IF (imax .GT. i) THEN
17534 IF (imin .LT. i - 1) THEN
17540 vwd = 0.5*(rvd(ip, k, jts)+rvd(im, k, jts))
17541 vw = 0.5*(rv(ip, k, jts)+rv(im, k, jts))
17542 IF (vw .GT. 0.) THEN
17549 dvmd = rvd(ip, k, jts+1) - rvd(ip, k, jts)
17550 dvm = rv(ip, k, jts+1) - rv(ip, k, jts)
17551 dvpd = rvd(im, k, jts+1) - rvd(im, k, jts)
17552 dvp = rv(im, k, jts+1) - rv(im, k, jts)
17553 tendencyd(i, k, jts) = tendencyd(i, k, jts) - mrdy*(vbd*(u_old(i&
17554 & , k, jts+1)-u_old(i, k, jts))+vb*(u_oldd(i, k, jts+1)-u_oldd(i&
17555 & , k, jts))+0.5*(ud(i, k, jts)*(dvm+dvp)+u(i, k, jts)*(dvmd+&
17557 tendency(i, k, jts) = tendency(i, k, jts) - mrdy*(vb*(u_old(i, k&
17558 & , jts+1)-u_old(i, k, jts))+0.5*u(i, k, jts)*(dvm+dvp))
17562 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
17564 ! ADT eqn 44, 2nd term on RHS
17565 mrdy = msfux(i, jte-1)*rdy
17566 IF (imax .GT. i) THEN
17571 IF (imin .LT. i - 1) THEN
17577 vwd = 0.5*(rvd(ip, k, jte)+rvd(im, k, jte))
17578 vw = 0.5*(rv(ip, k, jte)+rv(im, k, jte))
17579 IF (vw .LT. 0.) THEN
17586 dvmd = rvd(ip, k, jte) - rvd(ip, k, jte-1)
17587 dvm = rv(ip, k, jte) - rv(ip, k, jte-1)
17588 dvpd = rvd(im, k, jte) - rvd(im, k, jte-1)
17589 dvp = rv(im, k, jte) - rv(im, k, jte-1)
17590 tendencyd(i, k, jte-1) = tendencyd(i, k, jte-1) - mrdy*(vbd*(&
17591 & u_old(i, k, jte-1)-u_old(i, k, jte-2))+vb*(u_oldd(i, k, jte-1)&
17592 & -u_oldd(i, k, jte-2))+0.5*(ud(i, k, jte-1)*(dvm+dvp)+u(i, k, &
17593 & jte-1)*(dvmd+dvpd)))
17594 tendency(i, k, jte-1) = tendency(i, k, jte-1) - mrdy*(vb*(u_old(&
17595 & i, k, jte-1)-u_old(i, k, jte-2))+0.5*u(i, k, jte-1)*(dvm+dvp))
17599 !-------------------- vertical advection
17600 ! ADT eqn 44 has 3rd term on RHS = -(1/my) partial d/dz (rho u w)
17601 ! Here we have: - partial d/dz (u*rom) = - partial d/dz (u rho w / my)
17602 ! Since 'my' (map scale factor in y-direction) isn't a function of z,
17603 ! this is what we need, so leave unchanged in advect_u
17607 IF (jte .GT. jde - 1) THEN
17612 ! IF ( config_flags%open_xs ) i_start = MAX(ids+1,its)
17613 ! IF ( config_flags%open_xe ) i_end = MIN(ide-1,ite)
17614 IF (config_flags%open_ys .OR. specified) THEN
17615 IF (ids + 1 .LT. its) THEN
17621 IF (config_flags%open_ye .OR. specified) THEN
17622 IF (ide - 1 .GT. ite) THEN
17628 IF (config_flags%periodic_x) i_start = its
17629 IF (config_flags%periodic_x) i_end = ite
17631 vfluxd(i, kts) = 0.0
17633 vfluxd(i, kte) = 0.0
17637 ! vert_order_test : IF (vert_order == 6) THEN
17638 ! ELSE IF (vert_order == 5) THEN
17642 veld = 0.5*(romd(i-1, k, j)+romd(i, k, j))
17643 vel = 0.5*(rom(i-1, k, j)+rom(i, k, j))
17644 IF (-vel*sign(1,time_step) .GE. 0.0) THEN
17645 qip2d = ud(i, k+1, j)
17646 qip2 = u(i, k+1, j)
17647 qip1d = ud(i, k, j)
17649 qid = ud(i, k-1, j)
17651 qim1d = ud(i, k-2, j)
17652 qim1 = u(i, k-2, j)
17653 qim2d = ud(i, k-3, j)
17654 qim2 = u(i, k-3, j)
17656 qip2d = ud(i, k-2, j)
17657 qip2 = u(i, k-2, j)
17658 qip1d = ud(i, k-1, j)
17659 qip1 = u(i, k-1, j)
17662 qim1d = ud(i, k+1, j)
17663 qim1 = u(i, k+1, j)
17664 qim2d = ud(i, k+2, j)
17665 qim2 = u(i, k+2, j)
17667 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
17668 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
17669 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
17670 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
17671 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
17672 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
17673 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
17674 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
17675 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
17677 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
17678 & qim1-qip1)*(qim1d-qip1d)/4.
17679 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
17680 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
17681 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
17682 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
17686 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17688 pwr1d = pw*pwx1**(pw-1)*pwx1d
17689 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17695 wi0d = -(gi0*pwr1d/pwr1**2)
17699 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17701 pwr1d = pw*pwx1**(pw-1)*pwx1d
17702 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17708 wi1d = -(gi1*pwr1d/pwr1**2)
17712 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17714 pwr1d = pw*pwx1**(pw-1)*pwx1d
17715 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17721 wi2d = -(gi2*pwr1d/pwr1**2)
17723 sumwkd = wi0d + wi1d + wi2d
17724 sumwk = wi0 + wi1 + wi2
17725 vfluxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
17726 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
17727 & +wi2*f2)*sumwkd)/sumwk**2
17728 vflux(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
17731 ! vflux(i,k) = vel*flux5( &
17732 ! u(i,k-3,j), u(i,k-2,j), u(i,k-1,j), &
17733 ! u(i,k ,j), u(i,k+1,j), u(i,k+2,j), -vel )
17736 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i, k&
17737 & , j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*&
17738 & ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
17739 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, j)&
17740 & +fzp(k)*u(i, k-1, j))
17742 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
17743 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
17744 vfluxd(i, k) = veld*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
17745 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1, &
17746 & j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0) + vel*((7.*(&
17747 & ud(i, k, j)+ud(i, k-1, j))-ud(i, k+1, j)-ud(i, k-2, j))/12.0+&
17748 & SIGN(1, time_step)*SIGN(1., -vel)*(ud(i, k+1, j)-ud(i, k-2, j)-&
17749 & 3.*(ud(i, k, j)-ud(i, k-1, j)))/12.0)
17750 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u(i&
17751 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1, j)&
17752 & -u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0)
17754 veld = 0.5*(romd(i, k, j)+romd(i-1, k, j))
17755 vel = 0.5*(rom(i, k, j)+rom(i-1, k, j))
17756 vfluxd(i, k) = veld*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u&
17757 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1, &
17758 & j)-u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0) + vel*((7.*(&
17759 & ud(i, k, j)+ud(i, k-1, j))-ud(i, k+1, j)-ud(i, k-2, j))/12.0+&
17760 & SIGN(1, time_step)*SIGN(1., -vel)*(ud(i, k+1, j)-ud(i, k-2, j)-&
17761 & 3.*(ud(i, k, j)-ud(i, k-1, j)))/12.0)
17762 vflux(i, k) = vel*((7.*(u(i, k, j)+u(i, k-1, j))-(u(i, k+1, j)+u(i&
17763 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(u(i, k+1, j)&
17764 & -u(i, k-2, j)-3.*(u(i, k, j)-u(i, k-1, j)))/12.0)
17766 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i-1, k, j))*(fzm(k)*u(i, k&
17767 & , j)+fzp(k)*u(i, k-1, j))+(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*&
17768 & ud(i, k, j)+fzp(k)*ud(i, k-1, j)))
17769 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i-1, k, j))*(fzm(k)*u(i, k, j)&
17770 & +fzp(k)*u(i, k-1, j))
17774 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzw(k)*(vfluxd(i, k+1&
17776 tendency(i, k, j) = tendency(i, k, j) - rdzw(k)*(vflux(i, k+1)-&
17781 END SUBROUTINE G_ADVECT_WENO_U
17783 ! Generated by TAPENADE (INRIA, Tropics team)
17784 ! Tapenade 3.6 (r4165) - 21 sep 2011 20:54
17786 ! Differentiation of advect_weno_v in forward (tangent) mode:
17787 ! variations of useful results: tendency
17788 ! with respect to varying inputs: rom tendency v v_old ru rv
17790 ! RW status of diff variables: rom:in tendency:in-out v:in v_old:in
17791 ! ru:in rv:in mut:in
17792 SUBROUTINE G_ADVECT_WENO_V(v, vd, v_old, v_oldd, tendency, tendencyd, ru&
17793 & , rud, rv, rvd, rom, romd, mut, mutd, time_step, config_flags, msfux, &
17794 & msfuy, msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzw, ids, ide&
17795 & , jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte&
17799 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
17800 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
17801 & jme, kms, kme, its, ite, jts, jte, kts, kte
17802 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: v, v_old, ru&
17804 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: vd, v_oldd, &
17806 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
17807 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd
17808 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
17809 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
17810 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
17811 & msfvy, msftx, msfty
17812 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzw
17813 REAL, INTENT(IN) :: rdx, rdy
17814 INTEGER, INTENT(IN) :: time_step
17816 INTEGER :: i, j, k, itf, jtf, ktf
17817 INTEGER :: i_start, i_end, j_start, j_end
17818 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
17819 INTEGER :: jmin, jmax, jp, jm, imin, imax
17821 REAL :: ue, vs, vn, wb, wt
17822 REAL, PARAMETER :: f30=7./12., f31=1./12.
17823 REAL, PARAMETER :: f50=37./60., f51=2./15., f52=1./60.
17825 REAL :: qim2, qim1, qi, qip1, qip2
17826 REAL :: qim2d, qim1d, qid, qip1d, qip2d
17827 DOUBLE PRECISION :: beta0, beta1, beta2, f0, f1, f2, wi0, wi1, wi2, &
17829 DOUBLE PRECISION :: beta0d, beta1d, beta2d, f0d, f1d, f2d, wi0d, wi1d&
17831 DOUBLE PRECISION, PARAMETER :: gi0=1.d0/10.d0, gi1=6.d0/10.d0, gi2=&
17832 & 3.d0/10.d0, eps=1.0d-18
17833 INTEGER, PARAMETER :: pw=2
17834 REAL :: mrdx, mrdy, ub, vb, uw, vw, dup, dum
17835 REAL :: ubd, vbd, uwd, dupd, dumd
17836 REAL, DIMENSION(its:ite, kts:kte) :: vflux
17837 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
17838 REAL, DIMENSION(its:ite + 1, kts:kte) :: fqx
17839 REAL, DIMENSION(its:ite+1, kts:kte) :: fqxd
17840 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
17841 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
17842 INTEGER :: horz_order
17843 INTEGER :: vert_order
17844 LOGICAL :: degrade_xs, degrade_ys
17845 LOGICAL :: degrade_xe, degrade_ye
17846 INTEGER :: jp1, jp0, jtmp
17847 ! definition of flux operators, 3rd, 4th, 5th or 6th order
17848 REAL :: flux3, flux4, flux5, flux6
17849 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
17851 LOGICAL :: specified
17852 DOUBLE PRECISION :: pwx1
17853 DOUBLE PRECISION :: pwx1d
17854 DOUBLE PRECISION :: pwr1
17855 DOUBLE PRECISION :: pwr1d
17863 specified = .false.
17864 IF (config_flags%specified .OR. config_flags%nested) specified = &
17866 IF (kte .GT. kde - 1) THEN
17871 horz_order = config_flags%h_mom_adv_order
17872 vert_order = config_flags%v_mom_adv_order
17873 ! here is the choice of flux operators
17874 ! horizontal_order_test : IF( horz_order == 6 ) THEN
17875 ! ELSE IF( horz_order == 5 ) THEN
17876 ! 5th order horizontal flux calculation
17877 ! This code is EXACTLY the same as the 6th order code
17878 ! EXCEPT the 5th order and 3rd operators are used in
17879 ! place of the 6th and 4th order operators
17880 ! determine boundary mods for flux operators
17881 ! We degrade the flux operators from 3rd/4th order
17882 ! to second order one gridpoint in from the boundaries for
17883 ! all boundary conditions except periodic and symmetry - these
17884 ! conditions have boundary zone data fill for correct application
17885 ! of the higher order flux stencils
17886 degrade_xs = .true.
17887 degrade_xe = .true.
17888 degrade_ys = .true.
17889 degrade_ye = .true.
17890 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. its &
17891 & .GT. ids + 3) degrade_xs = .false.
17892 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. ite &
17893 & .LT. ide - 3) degrade_xe = .false.
17894 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. jts &
17895 & .GT. jds + 3) degrade_ys = .false.
17896 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. jte &
17897 & .LT. jde - 3) degrade_ye = .false.
17898 !--------------- y - advection first
17900 IF (ite .GT. ide - 1) THEN
17907 ! higher order flux has a 5 or 7 point stencil, so compute
17908 ! bounds so we can switch to second order flux close to the boundary
17909 j_start_f = j_start
17910 j_end_f = j_end + 1
17911 IF (degrade_ys) THEN
17912 IF (jts .LT. jds + 1) THEN
17917 j_start_f = jds + 3
17919 IF (degrade_ye) THEN
17920 IF (jte .GT. jde - 1) THEN
17927 ! compute fluxes, 5th or 6th order
17931 j_loop_y_flux_5:DO j=j_start,j_end+1
17932 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
17935 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
17936 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
17937 IF (vel*sign(1,time_step) .GE. 0.0) THEN
17938 qip2d = vd(i, k, j+1)
17939 qip2 = v(i, k, j+1)
17940 qip1d = vd(i, k, j)
17942 qid = vd(i, k, j-1)
17944 qim1d = vd(i, k, j-2)
17945 qim1 = v(i, k, j-2)
17946 qim2d = vd(i, k, j-3)
17947 qim2 = v(i, k, j-3)
17949 qip2d = vd(i, k, j-2)
17950 qip2 = v(i, k, j-2)
17951 qip1d = vd(i, k, j-1)
17952 qip1 = v(i, k, j-1)
17955 qim1d = vd(i, k, j+1)
17956 qim1 = v(i, k, j+1)
17957 qim2d = vd(i, k, j+2)
17958 qim2 = v(i, k, j+2)
17960 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
17961 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
17962 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
17963 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
17964 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
17965 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
17966 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*&
17967 & (qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
17968 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*&
17970 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*&
17971 & (qim1-qip1)*(qim1d-qip1d)/4.
17972 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
17973 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*&
17974 & (qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
17975 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*&
17979 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17981 pwr1d = pw*pwx1**(pw-1)*pwx1d
17982 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
17988 wi0d = -(gi0*pwr1d/pwr1**2)
17992 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
17994 pwr1d = pw*pwx1**(pw-1)*pwx1d
17995 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18001 wi1d = -(gi1*pwr1d/pwr1**2)
18005 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18007 pwr1d = pw*pwx1**(pw-1)*pwx1d
18008 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18014 wi2d = -(gi2*pwr1d/pwr1**2)
18016 sumwkd = wi0d + wi1d + wi2d
18017 sumwk = wi0 + wi1 + wi2
18018 fqyd(i, k, jp1) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+&
18019 & wi0*f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+&
18020 & wi1*f1+wi2*f2)*sumwkd)/sumwk**2
18021 fqy(i, k, jp1) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
18024 ELSE IF (j .EQ. jds + 1) THEN
18025 ! fqy( i, k, jp1 ) = vel*flux5( &
18026 ! v(i,k,j-3), v(i,k,j-2), v(i,k,j-1), &
18027 ! v(i,k,j ), v(i,k,j+1), v(i,k,j+2), vel )
18028 ! we must be close to some boundary where we need to reduce the order of the stencil
18029 ! specified uses upstream normal wind at boundaries
18030 ! 2nd order flux next to south boundary
18033 vbd = vd(i, k, j-1)
18035 IF (specified .AND. v(i, k, j) .LT. 0.) THEN
18039 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(v(i, k&
18040 & , j)+vb)+(rv(i, k, j)+rv(i, k, j-1))*(vd(i, k, j)+vbd))
18041 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(v(i, k, j)+&
18045 ELSE IF (j .EQ. jds + 2) THEN
18046 ! third of 4th order flux 2 in from south boundary
18049 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
18050 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
18051 fqyd(i, k, jp1) = veld*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
18052 & , j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
18053 & (v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))/&
18054 & 12.0) + vel*((7.*(vd(i, k, j)+vd(i, k, j-1))-vd(i, k, j+1)-&
18055 & vd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(vd(i, &
18056 & k, j+1)-vd(i, k, j-2)-3.*(vd(i, k, j)-vd(i, k, j-1)))/12.0)
18057 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k, j&
18058 & +1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(&
18059 & i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))/12.0)
18062 ELSE IF (j .EQ. jde) THEN
18063 ! 2nd order flux next to north boundary
18068 IF (specified .AND. v(i, k, j-1) .GT. 0.) THEN
18069 vbd = vd(i, k, j-1)
18072 fqyd(i, k, jp1) = 0.25*((rvd(i, k, j)+rvd(i, k, j-1))*(vb+v(i&
18073 & , k, j-1))+(rv(i, k, j)+rv(i, k, j-1))*(vbd+vd(i, k, j-1)))
18074 fqy(i, k, jp1) = 0.25*(rv(i, k, j)+rv(i, k, j-1))*(vb+v(i, k, &
18078 ELSE IF (j .EQ. jde - 1) THEN
18079 ! 3rd or 4th order flux 2 in from north boundary
18082 veld = 0.5*(rvd(i, k, j)+rvd(i, k, j-1))
18083 vel = 0.5*(rv(i, k, j)+rv(i, k, j-1))
18084 fqyd(i, k, jp1) = veld*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k&
18085 & , j+1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
18086 & (v(i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))/&
18087 & 12.0) + vel*((7.*(vd(i, k, j)+vd(i, k, j-1))-vd(i, k, j+1)-&
18088 & vd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(vd(i, &
18089 & k, j+1)-vd(i, k, j-2)-3.*(vd(i, k, j)-vd(i, k, j-1)))/12.0)
18090 fqy(i, k, jp1) = vel*((7.*(v(i, k, j)+v(i, k, j-1))-(v(i, k, j&
18091 & +1)+v(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(&
18092 & i, k, j+1)-v(i, k, j-2)-3.*(v(i, k, j)-v(i, k, j-1)))/12.0)
18096 ! y flux-divergence into tendency
18097 ! Comments on polar boundary conditions
18098 ! No advection over the poles means tendencies (held from jds [S. pole]
18099 ! to jde [N pole], i.e., on v grid) must be zero at poles
18100 ! [tendency(jds) and tendency(jde)=0]
18101 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
18104 tendencyd(i, k, j-1) = 0.0
18105 tendency(i, k, j-1) = 0.
18108 ELSE IF (config_flags%polar .AND. j .EQ. jde + 1) THEN
18109 ! If j_end were set to jde in a special if statement apart from
18110 ! degrade_ye, then we would hit the next conditional. But since
18111 ! we want the tendency to be zero anyway, not looping to jde+1
18112 ! will produce the same effect.
18115 tendencyd(i, k, j-1) = 0.0
18116 tendency(i, k, j-1) = 0.
18119 ELSE IF (j .GT. j_start) THEN
18123 ! ADT eqn 45, 2nd term on RHS
18124 mrdy = msfvy(i, j-1)*rdy
18125 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, k&
18126 & , jp1)-fqyd(i, k, jp0))
18127 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
18128 & jp1)-fqy(i, k, jp0))
18135 END DO j_loop_y_flux_5
18136 ! next, x - flux divergence
18138 IF (ite .GT. ide - 1) THEN
18145 ! Polar boundary conditions are like open or specified
18146 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
18148 IF (jds + 1 .LT. jts) THEN
18154 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
18156 IF (jde - 1 .GT. jte) THEN
18162 ! higher order flux has a 5 or 7 point stencil, so compute
18163 ! bounds so we can switch to second order flux close to the boundary
18164 i_start_f = i_start
18165 i_end_f = i_end + 1
18166 IF (degrade_xs) THEN
18167 IF (ids + 1 .LT. its) THEN
18172 IF (i_start + 2 .GT. ids + 3) THEN
18173 i_start_f = ids + 3
18175 i_start_f = i_start + 2
18178 IF (degrade_xe) THEN
18179 IF (ide - 2 .GT. ite) THEN
18191 ! 5th or 6th order flux
18193 DO i=i_start_f,i_end_f
18194 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
18195 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
18196 IF (vel*sign(1,time_step) .GE. 0.0) THEN
18197 qip2d = vd(i+1, k, j)
18198 qip2 = v(i+1, k, j)
18199 qip1d = vd(i, k, j)
18201 qid = vd(i-1, k, j)
18203 qim1d = vd(i-2, k, j)
18204 qim1 = v(i-2, k, j)
18205 qim2d = vd(i-3, k, j)
18206 qim2 = v(i-3, k, j)
18208 qip2d = vd(i-2, k, j)
18209 qip2 = v(i-2, k, j)
18210 qip1d = vd(i-1, k, j)
18211 qip1 = v(i-1, k, j)
18214 qim1d = vd(i+1, k, j)
18215 qim1 = v(i+1, k, j)
18216 qim2d = vd(i+2, k, j)
18217 qim2 = v(i+2, k, j)
18219 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
18220 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
18221 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
18222 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
18223 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
18224 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
18225 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
18226 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
18227 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
18229 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
18230 & qim1-qip1)*(qim1d-qip1d)/4.
18231 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
18232 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
18233 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
18234 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
18238 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18240 pwr1d = pw*pwx1**(pw-1)*pwx1d
18241 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18247 wi0d = -(gi0*pwr1d/pwr1**2)
18251 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18253 pwr1d = pw*pwx1**(pw-1)*pwx1d
18254 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18260 wi1d = -(gi1*pwr1d/pwr1**2)
18264 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18266 pwr1d = pw*pwx1**(pw-1)*pwx1d
18267 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18273 wi2d = -(gi2*pwr1d/pwr1**2)
18275 sumwkd = wi0d + wi1d + wi2d
18276 sumwk = wi0 + wi1 + wi2
18277 fqxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*f0d+&
18278 & wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1+wi2&
18279 & *f2)*sumwkd)/sumwk**2
18280 fqx(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
18283 ! fqx( i, k ) = vel*flux5( v(i-3,k,j), v(i-2,k,j), &
18284 ! v(i-1,k,j), v(i ,k,j), &
18285 ! v(i+1,k,j), v(i+2,k,j), &
18287 ! lower order fluxes close to boundaries (if not periodic or symmetric)
18288 IF (degrade_xs) THEN
18289 DO i=i_start,i_start_f-1
18290 IF (i .EQ. ids + 1) THEN
18293 fqxd(i, k) = 0.25*((rud(i, k, j)+rud(i, k, j-1))*(v(i, k, j)&
18294 & +v(i-1, k, j))+(ru(i, k, j)+ru(i, k, j-1))*(vd(i, k, j)+vd&
18296 fqx(i, k) = 0.25*(ru(i, k, j)+ru(i, k, j-1))*(v(i, k, j)+v(i&
18300 IF (i .EQ. ids + 2) THEN
18303 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
18304 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
18305 fqxd(i, k) = veld*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
18306 & j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v&
18307 & (i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/&
18308 & 12.0) + vel*((7.*(vd(i, k, j)+vd(i-1, k, j))-vd(i+1, k, j)&
18309 & -vd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(vd(&
18310 & i+1, k, j)-vd(i-2, k, j)-3.*(vd(i, k, j)-vd(i-1, k, j)))/&
18312 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)&
18313 & +v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(i&
18314 & +1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/12.0)
18319 IF (degrade_xe) THEN
18320 DO i=i_end_f+1,i_end+1
18321 IF (i .EQ. ide - 1) THEN
18322 ! second order flux next to the boundary
18324 fqxd(i, k) = 0.25*((rud(i_end+1, k, j)+rud(i_end+1, k, j-1))&
18325 & *(v(i_end+1, k, j)+v(i_end, k, j))+(ru(i_end+1, k, j)+ru(&
18326 & i_end+1, k, j-1))*(vd(i_end+1, k, j)+vd(i_end, k, j)))
18327 fqx(i, k) = 0.25*(ru(i_end+1, k, j)+ru(i_end+1, k, j-1))*(v(&
18328 & i_end+1, k, j)+v(i_end, k, j))
18331 IF (i .EQ. ide - 2) THEN
18332 ! third order flux one in from the boundary
18334 veld = 0.5*(rud(i, k, j)+rud(i, k, j-1))
18335 vel = 0.5*(ru(i, k, j)+ru(i, k, j-1))
18336 fqxd(i, k) = veld*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, &
18337 & j)+v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v&
18338 & (i+1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/&
18339 & 12.0) + vel*((7.*(vd(i, k, j)+vd(i-1, k, j))-vd(i+1, k, j)&
18340 & -vd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(vd(&
18341 & i+1, k, j)-vd(i-2, k, j)-3.*(vd(i, k, j)-vd(i-1, k, j)))/&
18343 fqx(i, k) = vel*((7.*(v(i, k, j)+v(i-1, k, j))-(v(i+1, k, j)&
18344 & +v(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(v(i&
18345 & +1, k, j)-v(i-2, k, j)-3.*(v(i, k, j)-v(i-1, k, j)))/12.0)
18350 ! x flux-divergence into tendency
18353 ! ADT eqn 45, 1st term on RHS
18354 mrdx = msfvy(i, j)*rdx
18355 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
18357 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(i&
18362 ! Comments on polar boundary condition
18363 ! Force tendency=0 at NP and SP
18364 ! We keep setting this everywhere, but it can't hurt...
18365 IF (config_flags%polar .AND. jts .EQ. jds) THEN
18368 tendencyd(i, k, jts) = 0.0
18369 tendency(i, k, jts) = 0.
18373 IF (config_flags%polar .AND. jte .EQ. jde) THEN
18376 tendencyd(i, k, jte) = 0.0
18377 tendency(i, k, jte) = 0.
18381 ! radiative lateral boundary condition in y for normal velocity (v)
18382 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
18384 IF (ite .GT. ide - 1) THEN
18391 IF (rv(i, k, jts) - cb*mut(i, jts) .GT. 0.) THEN
18395 vbd = rvd(i, k, jts) - cb*mutd(i, jts)
18396 vb = rv(i, k, jts) - cb*mut(i, jts)
18398 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(v_old(i&
18399 & , k, jts+1)-v_old(i, k, jts))+vb*(v_oldd(i, k, jts+1)-v_oldd(i&
18401 tendency(i, k, jts) = tendency(i, k, jts) - rdy*vb*(v_old(i, k, &
18402 & jts+1)-v_old(i, k, jts))
18406 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
18408 IF (ite .GT. ide - 1) THEN
18415 IF (rv(i, k, jte) + cb*mut(i, jte-1) .LT. 0.) THEN
18419 vbd = rvd(i, k, jte) + cb*mutd(i, jte-1)
18420 vb = rv(i, k, jte) + cb*mut(i, jte-1)
18422 tendencyd(i, k, jte) = tendencyd(i, k, jte) - rdy*(vbd*(v_old(i&
18423 & , k, jte)-v_old(i, k, jte-1))+vb*(v_oldd(i, k, jte)-v_oldd(i, &
18425 tendency(i, k, jte) = tendency(i, k, jte) - rdy*vb*(v_old(i, k, &
18426 & jte)-v_old(i, k, jte-1))
18430 ! pick up the rest of the horizontal radiation boundary conditions.
18431 ! (these are the computations that don't require 'cb'.
18432 ! first, set to index ranges
18434 IF (jte .GT. jde) THEN
18441 IF (config_flags%open_ys) THEN
18442 IF (jds + 1 .LT. jts) THEN
18449 IF (config_flags%open_ye) THEN
18450 IF (jte .GT. jde - 1) THEN
18457 ! compute x (u) conditions for v, w, or scalar
18458 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
18460 ! ADT eqn 45, 1st term on RHS
18461 mrdx = msfvy(its, j)*rdx
18462 IF (jmax .GT. j) THEN
18467 IF (jmin .LT. j - 1) THEN
18473 uwd = 0.5*(rud(its, k, jp)+rud(its, k, jm))
18474 uw = 0.5*(ru(its, k, jp)+ru(its, k, jm))
18475 IF (uw .GT. 0.) THEN
18482 dupd = rud(its+1, k, jp) - rud(its, k, jp)
18483 dup = ru(its+1, k, jp) - ru(its, k, jp)
18484 dumd = rud(its+1, k, jm) - rud(its, k, jm)
18485 dum = ru(its+1, k, jm) - ru(its, k, jm)
18486 tendencyd(its, k, j) = tendencyd(its, k, j) - mrdx*(ubd*(v_old(&
18487 & its+1, k, j)-v_old(its, k, j))+ub*(v_oldd(its+1, k, j)-v_oldd(&
18488 & its, k, j))+0.5*(vd(its, k, j)*(dup+dum)+v(its, k, j)*(dupd+&
18490 tendency(its, k, j) = tendency(its, k, j) - mrdx*(ub*(v_old(its+&
18491 & 1, k, j)-v_old(its, k, j))+0.5*v(its, k, j)*(dup+dum))
18495 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
18497 ! ADT eqn 45, 1st term on RHS
18498 mrdx = msfvy(ite-1, j)*rdx
18499 IF (jmax .GT. j) THEN
18504 IF (jmin .LT. j - 1) THEN
18510 uwd = 0.5*(rud(ite, k, jp)+rud(ite, k, jm))
18511 uw = 0.5*(ru(ite, k, jp)+ru(ite, k, jm))
18512 IF (uw .LT. 0.) THEN
18519 dupd = rud(ite, k, jp) - rud(ite-1, k, jp)
18520 dup = ru(ite, k, jp) - ru(ite-1, k, jp)
18521 dumd = rud(ite, k, jm) - rud(ite-1, k, jm)
18522 dum = ru(ite, k, jm) - ru(ite-1, k, jm)
18523 ! tendency(ite-1,k,j)=tendency(ite-1,k,j)-mrdx*( &
18524 ! ub*(v_old(ite-1,k,j)-v_old(ite-2,k,j)) &
18525 ! +0.5*v(ite-1,k,j)* &
18526 ! ( ru(ite,k,jp)-ru(ite-1,k,jp) &
18527 ! +ru(ite,k,jm)-ru(ite-1,k,jm)) )
18528 tendencyd(ite-1, k, j) = tendencyd(ite-1, k, j) - mrdx*(ubd*(&
18529 & v_old(ite-1, k, j)-v_old(ite-2, k, j))+ub*(v_oldd(ite-1, k, j)&
18530 & -v_oldd(ite-2, k, j))+0.5*(vd(ite-1, k, j)*(dup+dum)+v(ite-1, &
18531 & k, j)*(dupd+dumd)))
18532 tendency(ite-1, k, j) = tendency(ite-1, k, j) - mrdx*(ub*(v_old(&
18533 & ite-1, k, j)-v_old(ite-2, k, j))+0.5*v(ite-1, k, j)*(dup+dum))
18537 !-------------------- vertical advection
18538 ! ADT eqn 45 has 3rd term on RHS = -(1/mx) partial d/dz (rho v w)
18539 ! Here we have: - partial d/dz (v*rom) = - partial d/dz (v rho w / my)
18540 ! We therefore need to make a correction for advect_v
18541 ! since 'my' (map scale factor in y direction) isn't a function of z,
18542 ! we can do this using *(my/mx) (see eqn. 45 for example)
18544 IF (ite .GT. ide - 1) THEN
18552 vfluxd(i, kts) = 0.0
18554 vfluxd(i, kte) = 0.0
18557 ! Polar boundary conditions are like open or specified
18558 ! We don't want to calculate vertical v tendencies at the N or S pole
18559 IF ((config_flags%open_ys .OR. specified) .OR. config_flags%polar) &
18561 IF (jds + 1 .LT. jts) THEN
18567 IF ((config_flags%open_ye .OR. specified) .OR. config_flags%polar) &
18569 IF (jde - 1 .GT. jte) THEN
18578 ! vert_order_test : IF (vert_order == 6) THEN
18579 ! ELSE IF (vert_order == 5) THEN
18583 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
18584 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
18585 IF (-vel*sign(1,time_step) .GE. 0.0) THEN
18586 qip2d = vd(i, k+1, j)
18587 qip2 = v(i, k+1, j)
18588 qip1d = vd(i, k, j)
18590 qid = vd(i, k-1, j)
18592 qim1d = vd(i, k-2, j)
18593 qim1 = v(i, k-2, j)
18594 qim2d = vd(i, k-3, j)
18595 qim2 = v(i, k-3, j)
18597 qip2d = vd(i, k-2, j)
18598 qip2 = v(i, k-2, j)
18599 qip1d = vd(i, k-1, j)
18600 qip1 = v(i, k-1, j)
18603 qim1d = vd(i, k+1, j)
18604 qim1 = v(i, k+1, j)
18605 qim2d = vd(i, k+2, j)
18606 qim2 = v(i, k+2, j)
18608 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
18609 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
18610 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
18611 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
18612 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
18613 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
18614 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
18615 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
18616 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
18618 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
18619 & qim1-qip1)*(qim1d-qip1d)/4.
18620 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
18621 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
18622 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
18623 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
18627 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18629 pwr1d = pw*pwx1**(pw-1)*pwx1d
18630 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18636 wi0d = -(gi0*pwr1d/pwr1**2)
18640 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18642 pwr1d = pw*pwx1**(pw-1)*pwx1d
18643 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18649 wi1d = -(gi1*pwr1d/pwr1**2)
18653 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18655 pwr1d = pw*pwx1**(pw-1)*pwx1d
18656 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18662 wi2d = -(gi2*pwr1d/pwr1**2)
18664 sumwkd = wi0d + wi1d + wi2d
18665 sumwk = wi0 + wi1 + wi2
18666 vfluxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
18667 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
18668 & +wi2*f2)*sumwkd)/sumwk**2
18669 vflux(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
18672 ! vflux(i,k) = vel*flux5( &
18673 ! v(i,k-3,j), v(i,k-2,j), v(i,k-1,j), &
18674 ! v(i,k ,j), v(i,k+1,j), v(i,k+2,j), -vel )
18677 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i, k&
18678 & , j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*&
18679 & vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
18680 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, j)&
18681 & +fzp(k)*v(i, k-1, j))
18683 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
18684 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
18685 vfluxd(i, k) = veld*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
18686 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1, &
18687 & j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0) + vel*((7.*(&
18688 & vd(i, k, j)+vd(i, k-1, j))-vd(i, k+1, j)-vd(i, k-2, j))/12.0+&
18689 & SIGN(1, time_step)*SIGN(1., -vel)*(vd(i, k+1, j)-vd(i, k-2, j)-&
18690 & 3.*(vd(i, k, j)-vd(i, k-1, j)))/12.0)
18691 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v(i&
18692 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1, j)&
18693 & -v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0)
18695 veld = 0.5*(romd(i, k, j)+romd(i, k, j-1))
18696 vel = 0.5*(rom(i, k, j)+rom(i, k, j-1))
18697 vfluxd(i, k) = veld*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v&
18698 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1, &
18699 & j)-v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0) + vel*((7.*(&
18700 & vd(i, k, j)+vd(i, k-1, j))-vd(i, k+1, j)-vd(i, k-2, j))/12.0+&
18701 & SIGN(1, time_step)*SIGN(1., -vel)*(vd(i, k+1, j)-vd(i, k-2, j)-&
18702 & 3.*(vd(i, k, j)-vd(i, k-1, j)))/12.0)
18703 vflux(i, k) = vel*((7.*(v(i, k, j)+v(i, k-1, j))-(v(i, k+1, j)+v(i&
18704 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(v(i, k+1, j)&
18705 & -v(i, k-2, j)-3.*(v(i, k, j)-v(i, k-1, j)))/12.0)
18707 vfluxd(i, k) = 0.5*((romd(i, k, j)+romd(i, k, j-1))*(fzm(k)*v(i, k&
18708 & , j)+fzp(k)*v(i, k-1, j))+(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*&
18709 & vd(i, k, j)+fzp(k)*vd(i, k-1, j)))
18710 vflux(i, k) = 0.5*(rom(i, k, j)+rom(i, k, j-1))*(fzm(k)*v(i, k, j)&
18711 & +fzp(k)*v(i, k-1, j))
18715 ! We are calculating vertical fluxes on v points,
18716 ! so we must mean msf_v_x/y variables
18717 ! ADT eqn 45, 3rd term on RHS
18718 tendencyd(i, k, j) = tendencyd(i, k, j) - msfvy(i, j)*rdzw(k)*(&
18719 & vfluxd(i, k+1)-vfluxd(i, k))/msfvx(i, j)
18720 tendency(i, k, j) = tendency(i, k, j) - msfvy(i, j)/msfvx(i, j)*&
18721 & rdzw(k)*(vflux(i, k+1)-vflux(i, k))
18725 END SUBROUTINE G_ADVECT_WENO_V
18727 ! Generated by TAPENADE (INRIA, Tropics team)
18728 ! Tapenade 3.6 (r4165) - 21 sep 2011 20:54
18730 ! Differentiation of advect_weno_w in forward (tangent) mode:
18731 ! variations of useful results: tendency
18732 ! with respect to varying inputs: rom tendency w ru rv w_old
18733 ! RW status of diff variables: rom:in tendency:in-out w:in ru:in
18735 SUBROUTINE G_ADVECT_WENO_W(w, wd, w_old, w_oldd, tendency, tendencyd, ru&
18736 & , rud, rv, rvd, rom, romd, mut, time_step, config_flags, msfux, msfuy&
18737 & , msfvx, msfvy, msftx, msfty, fzm, fzp, rdx, rdy, rdzu, ids, ide, jds&
18738 & , jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts&
18742 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
18743 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde, ims, ime, jms, &
18744 & jme, kms, kme, its, ite, jts, jte, kts, kte
18745 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: w, w_old, ru&
18747 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: wd, w_oldd, &
18749 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mut
18750 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendency
18751 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: tendencyd
18752 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
18753 & msfvy, msftx, msfty
18754 REAL, DIMENSION(kms:kme), INTENT(IN) :: fzm, fzp, rdzu
18755 REAL, INTENT(IN) :: rdx, rdy
18756 INTEGER, INTENT(IN) :: time_step
18758 INTEGER :: i, j, k, itf, jtf, ktf
18759 INTEGER :: i_start, i_end, j_start, j_end
18760 INTEGER :: i_start_f, i_end_f, j_start_f, j_end_f
18761 INTEGER :: jmin, jmax, jp, jm, imin, imax
18762 REAL :: mrdx, mrdy, ub, vb, uw, vw
18763 REAL :: ubd, vbd, uwd, vwd
18764 REAL, DIMENSION(its:ite, kts:kte) :: vflux
18765 REAL, DIMENSION(its:ite, kts:kte) :: vfluxd
18767 REAL :: ue, vs, vn, wb, wt
18768 REAL, PARAMETER :: f30=7./12., f31=1./12.
18769 REAL, PARAMETER :: f50=37./60., f51=2./15., f52=1./60.
18771 REAL :: qim2, qim1, qi, qip1, qip2
18772 REAL :: qim2d, qim1d, qid, qip1d, qip2d
18773 DOUBLE PRECISION :: beta0, beta1, beta2, f0, f1, f2, wi0, wi1, wi2, &
18775 DOUBLE PRECISION :: beta0d, beta1d, beta2d, f0d, f1d, f2d, wi0d, wi1d&
18777 DOUBLE PRECISION, PARAMETER :: gi0=1.d0/10.d0, gi1=6.d0/10.d0, gi2=&
18778 & 3.d0/10.d0, eps=1.0d-18
18779 INTEGER, PARAMETER :: pw=2
18780 INTEGER :: horz_order, vert_order
18781 REAL, DIMENSION(its:ite + 1, kts:kte) :: fqx
18782 REAL, DIMENSION(its:ite+1, kts:kte) :: fqxd
18783 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqy
18784 REAL, DIMENSION(its:ite, kts:kte, 2) :: fqyd
18785 LOGICAL :: degrade_xs, degrade_ys
18786 LOGICAL :: degrade_xe, degrade_ye
18787 INTEGER :: jp1, jp0, jtmp
18788 ! definition of flux operators, 3rd, 4th, 5th or 6th order
18789 REAL :: flux3, flux4, flux5, flux6
18790 REAL :: q_im3, q_im2, q_im1, q_i, q_ip1, q_ip2, ua, vel
18792 LOGICAL :: specified
18793 DOUBLE PRECISION :: pwx1
18794 DOUBLE PRECISION :: pwx1d
18795 DOUBLE PRECISION :: pwr1
18796 DOUBLE PRECISION :: pwr1d
18804 specified = .false.
18805 IF (config_flags%specified .OR. config_flags%nested) specified = &
18807 IF (kte .GT. kde - 1) THEN
18812 horz_order = config_flags%h_sca_adv_order
18813 vert_order = config_flags%v_sca_adv_order
18814 ! here is the choice of flux operators
18815 ! begin with horizontal flux divergence
18816 ! horizontal_order_test : IF( horz_order == 6 ) THEN
18817 ! ELSE IF (horz_order == 5 ) THEN
18818 ! determine boundary mods for flux operators
18819 ! We degrade the flux operators from 3rd/4th order
18820 ! to second order one gridpoint in from the boundaries for
18821 ! all boundary conditions except periodic and symmetry - these
18822 ! conditions have boundary zone data fill for correct application
18823 ! of the higher order flux stencils
18824 degrade_xs = .true.
18825 degrade_xe = .true.
18826 degrade_ys = .true.
18827 degrade_ye = .true.
18828 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xs) .OR. its &
18829 & .GT. ids + 3) degrade_xs = .false.
18830 IF ((config_flags%periodic_x .OR. config_flags%symmetric_xe) .OR. ite &
18831 & .LT. ide - 3) degrade_xe = .false.
18832 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ys) .OR. jts &
18833 & .GT. jds + 3) degrade_ys = .false.
18834 IF ((config_flags%periodic_y .OR. config_flags%symmetric_ye) .OR. jte &
18835 & .LT. jde - 4) degrade_ye = .false.
18836 !--------------- y - advection first
18838 IF (ite .GT. ide - 1) THEN
18844 IF (jte .GT. jde - 1) THEN
18849 ! higher order flux has a 5 or 7 point stencil, so compute
18850 ! bounds so we can switch to second order flux close to the boundary
18851 j_start_f = j_start
18852 j_end_f = j_end + 1
18853 IF (degrade_ys) THEN
18854 IF (jts .LT. jds + 1) THEN
18859 j_start_f = jds + 3
18861 IF (degrade_ye) THEN
18862 IF (jte .GT. jde - 2) THEN
18869 IF (config_flags%polar) THEN
18870 IF (jte .GT. jde - 1) THEN
18876 ! compute fluxes, 5th or 6th order
18880 j_loop_y_flux_5:DO j=j_start,j_end+1
18881 IF (j .GE. j_start_f .AND. j .LE. j_end_f) THEN
18884 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
18885 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
18886 IF (vel*sign(1,time_step) .GE. 0.0) THEN
18887 qip2d = wd(i, k, j+1)
18888 qip2 = w(i, k, j+1)
18889 qip1d = wd(i, k, j)
18891 qid = wd(i, k, j-1)
18893 qim1d = wd(i, k, j-2)
18894 qim1 = w(i, k, j-2)
18895 qim2d = wd(i, k, j-3)
18896 qim2 = w(i, k, j-3)
18898 qip2d = wd(i, k, j-2)
18899 qip2 = w(i, k, j-2)
18900 qip1d = wd(i, k, j-1)
18901 qip1 = w(i, k, j-1)
18904 qim1d = wd(i, k, j+1)
18905 qim1 = w(i, k, j+1)
18906 qim2d = wd(i, k, j+2)
18907 qim2 = w(i, k, j+2)
18909 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
18910 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
18911 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
18912 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
18913 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
18914 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
18915 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*&
18916 & (qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
18917 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*&
18919 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*&
18920 & (qim1-qip1)*(qim1d-qip1d)/4.
18921 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
18922 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*&
18923 & (qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
18924 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*&
18928 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18930 pwr1d = pw*pwx1**(pw-1)*pwx1d
18931 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18937 wi0d = -(gi0*pwr1d/pwr1**2)
18941 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18943 pwr1d = pw*pwx1**(pw-1)*pwx1d
18944 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18950 wi1d = -(gi1*pwr1d/pwr1**2)
18954 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
18956 pwr1d = pw*pwx1**(pw-1)*pwx1d
18957 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
18963 wi2d = -(gi2*pwr1d/pwr1**2)
18965 sumwkd = wi0d + wi1d + wi2d
18966 sumwk = wi0 + wi1 + wi2
18967 fqyd(i, k, jp1) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+&
18968 & wi0*f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+&
18969 & wi1*f1+wi2*f2)*sumwkd)/sumwk**2
18970 fqy(i, k, jp1) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
18973 ! fqy( i, k, jp1 ) = vel*flux5( &
18974 ! w(i,k,j-3), w(i,k,j-2), w(i,k,j-1), &
18975 ! w(i,k,j ), w(i,k,j+1), w(i,k,j+2), vel )
18978 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
18979 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
18980 IF (vel*sign(1,time_step) .GE. 0.0) THEN
18981 qip2d = wd(i, k, j+1)
18982 qip2 = w(i, k, j+1)
18983 qip1d = wd(i, k, j)
18985 qid = wd(i, k, j-1)
18987 qim1d = wd(i, k, j-2)
18988 qim1 = w(i, k, j-2)
18989 qim2d = wd(i, k, j-3)
18990 qim2 = w(i, k, j-3)
18992 qip2d = wd(i, k, j-2)
18993 qip2 = w(i, k, j-2)
18994 qip1d = wd(i, k, j-1)
18995 qip1 = w(i, k, j-1)
18998 qim1d = wd(i, k, j+1)
18999 qim1 = w(i, k, j+1)
19000 qim2d = wd(i, k, j+2)
19001 qim2 = w(i, k, j+2)
19003 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
19004 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
19005 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
19006 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
19007 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
19008 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
19009 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
19010 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
19011 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
19013 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
19014 & qim1-qip1)*(qim1d-qip1d)/4.
19015 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
19016 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
19017 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
19018 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
19022 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19024 pwr1d = pw*pwx1**(pw-1)*pwx1d
19025 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19031 wi0d = -(gi0*pwr1d/pwr1**2)
19035 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19037 pwr1d = pw*pwx1**(pw-1)*pwx1d
19038 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19044 wi1d = -(gi1*pwr1d/pwr1**2)
19048 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19050 pwr1d = pw*pwx1**(pw-1)*pwx1d
19051 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19057 wi2d = -(gi2*pwr1d/pwr1**2)
19059 sumwkd = wi0d + wi1d + wi2d
19060 sumwk = wi0 + wi1 + wi2
19061 fqyd(i, k, jp1) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0&
19062 & *f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*&
19063 & f1+wi2*f2)*sumwkd)/sumwk**2
19064 fqy(i, k, jp1) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
19066 ELSE IF (j .EQ. jds + 1) THEN
19067 ! fqy( i, k, jp1 ) = vel*flux5( &
19068 ! w(i,k,j-3), w(i,k,j-2), w(i,k,j-1), &
19069 ! w(i,k,j ), w(i,k,j+1), w(i,k,j+2), vel )
19070 ! 2nd order flux next to south boundary
19073 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-1&
19074 & , j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k)*&
19075 & rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
19076 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j))&
19077 & *(w(i, k, j)+w(i, k, j-1))
19082 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
19083 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(i&
19084 & , k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1)))
19085 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(i&
19086 & , k-2, j))*(w(i, k, j)+w(i, k, j-1))
19088 ELSE IF (j .EQ. jds + 2) THEN
19089 ! third of 4th order flux 2 in from south boundary
19092 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
19093 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
19094 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
19095 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
19096 & (w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/&
19097 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-&
19098 & wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, &
19099 & k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
19100 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
19101 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(&
19102 & i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
19107 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
19108 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
19109 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
19110 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
19111 & , k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0) + &
19112 & vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-wd(i, k, j-&
19113 & 2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, k, j+1)-wd(i&
19114 & , k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
19115 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j+1&
19116 & )+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i, k&
19117 & , j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
19119 ELSE IF (j .EQ. jde - 1) THEN
19120 ! 2nd order flux next to north boundary
19123 fqyd(i, k, jp1) = 0.5*((fzm(k)*rvd(i, k, j)+fzp(k)*rvd(i, k-1&
19124 & , j))*(w(i, k, j)+w(i, k, j-1))+(fzm(k)*rv(i, k, j)+fzp(k)*&
19125 & rv(i, k-1, j))*(wd(i, k, j)+wd(i, k, j-1)))
19126 fqy(i, k, jp1) = 0.5*(fzm(k)*rv(i, k, j)+fzp(k)*rv(i, k-1, j))&
19127 & *(w(i, k, j)+w(i, k, j-1))
19132 fqyd(i, k, jp1) = 0.5*(((2.-fzm(k-1))*rvd(i, k-1, j)-fzp(k-1)*&
19133 & rvd(i, k-2, j))*(w(i, k, j)+w(i, k, j-1))+((2.-fzm(k-1))*rv(i&
19134 & , k-1, j)-fzp(k-1)*rv(i, k-2, j))*(wd(i, k, j)+wd(i, k, j-1)))
19135 fqy(i, k, jp1) = 0.5*((2.-fzm(k-1))*rv(i, k-1, j)-fzp(k-1)*rv(i&
19136 & , k-2, j))*(w(i, k, j)+w(i, k, j-1))
19138 ELSE IF (j .EQ. jde - 2) THEN
19139 ! 3rd or 4th order flux 2 in from north boundary
19142 veld = fzm(k)*rvd(i, k, j) + fzp(k)*rvd(i, k-1, j)
19143 vel = fzm(k)*rv(i, k, j) + fzp(k)*rv(i, k-1, j)
19144 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k&
19145 & , j+1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*&
19146 & (w(i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/&
19147 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-&
19148 & wd(i, k, j-2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, &
19149 & k, j+1)-wd(i, k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
19150 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
19151 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(&
19152 & i, k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
19157 veld = (2.-fzm(k-1))*rvd(i, k-1, j) - fzp(k-1)*rvd(i, k-2, j)
19158 vel = (2.-fzm(k-1))*rv(i, k-1, j) - fzp(k-1)*rv(i, k-2, j)
19159 fqyd(i, k, jp1) = veld*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j&
19160 & +1)+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
19161 & , k, j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0) + &
19162 & vel*((7.*(wd(i, k, j)+wd(i, k, j-1))-wd(i, k, j+1)-wd(i, k, j-&
19163 & 2))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i, k, j+1)-wd(i&
19164 & , k, j-2)-3.*(wd(i, k, j)-wd(i, k, j-1)))/12.0)
19165 fqy(i, k, jp1) = vel*((7.*(w(i, k, j)+w(i, k, j-1))-(w(i, k, j+1&
19166 & )+w(i, k, j-2)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i, k&
19167 & , j+1)-w(i, k, j-2)-3.*(w(i, k, j)-w(i, k, j-1)))/12.0)
19170 ! y flux-divergence into tendency
19171 ! Comments for polar boundary conditions
19172 ! Same process as for advect_u - tendencies run from jds to jde-1
19173 ! (latitudes are as for u grid, longitudes are displaced)
19174 ! Therefore: flow is only from one side for points next to poles
19175 IF (config_flags%polar .AND. j .EQ. jds + 1) THEN
19178 ! see ADT eqn 46 dividing by my, 2nd term RHS
19179 mrdy = msftx(i, j-1)*rdy
19180 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*fqyd(i, k, &
19182 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*fqy(i, k, jp1&
19186 ELSE IF (config_flags%polar .AND. j .EQ. jde) THEN
19189 ! see ADT eqn 46 dividing by my, 2nd term RHS
19190 mrdy = msftx(i, j-1)*rdy
19191 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) + mrdy*fqyd(i, k, &
19193 tendency(i, k, j-1) = tendency(i, k, j-1) + mrdy*fqy(i, k, jp0&
19197 ELSE IF (j .GT. j_start) THEN
19201 ! see ADT eqn 46 dividing by my, 2nd term RHS
19202 mrdy = msftx(i, j-1)*rdy
19203 tendencyd(i, k, j-1) = tendencyd(i, k, j-1) - mrdy*(fqyd(i, k&
19204 & , jp1)-fqyd(i, k, jp0))
19205 tendency(i, k, j-1) = tendency(i, k, j-1) - mrdy*(fqy(i, k, &
19206 & jp1)-fqy(i, k, jp0))
19213 END DO j_loop_y_flux_5
19214 ! next, x - flux divergence
19216 IF (ite .GT. ide - 1) THEN
19222 IF (jte .GT. jde - 1) THEN
19227 ! higher order flux has a 5 or 7 point stencil, so compute
19228 ! bounds so we can switch to second order flux close to the boundary
19229 i_start_f = i_start
19230 i_end_f = i_end + 1
19231 IF (degrade_xs) THEN
19232 IF (ids + 1 .LT. its) THEN
19237 IF (i_start + 2 .GT. ids + 3) THEN
19238 i_start_f = ids + 3
19240 i_start_f = i_start + 2
19243 IF (degrade_xe) THEN
19244 IF (ide - 2 .GT. ite) THEN
19256 ! 5th or 6th order flux
19258 DO i=i_start_f,i_end_f
19259 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
19260 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
19261 IF (vel*sign(1,time_step) .GE. 0.0) THEN
19262 qip2d = wd(i+1, k, j)
19263 qip2 = w(i+1, k, j)
19264 qip1d = wd(i, k, j)
19266 qid = wd(i-1, k, j)
19268 qim1d = wd(i-2, k, j)
19269 qim1 = w(i-2, k, j)
19270 qim2d = wd(i-3, k, j)
19271 qim2 = w(i-3, k, j)
19273 qip2d = wd(i-2, k, j)
19274 qip2 = w(i-2, k, j)
19275 qip1d = wd(i-1, k, j)
19276 qip1 = w(i-1, k, j)
19279 qim1d = wd(i+1, k, j)
19280 qim1 = w(i+1, k, j)
19281 qim2d = wd(i+2, k, j)
19282 qim2 = w(i+2, k, j)
19284 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
19285 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
19286 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
19287 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
19288 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
19289 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
19290 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
19291 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
19292 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
19294 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
19295 & qim1-qip1)*(qim1d-qip1d)/4.
19296 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
19297 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
19298 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
19299 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
19303 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19305 pwr1d = pw*pwx1**(pw-1)*pwx1d
19306 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19312 wi0d = -(gi0*pwr1d/pwr1**2)
19316 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19318 pwr1d = pw*pwx1**(pw-1)*pwx1d
19319 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19325 wi1d = -(gi1*pwr1d/pwr1**2)
19329 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19331 pwr1d = pw*pwx1**(pw-1)*pwx1d
19332 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19338 wi2d = -(gi2*pwr1d/pwr1**2)
19340 sumwkd = wi0d + wi1d + wi2d
19341 sumwk = wi0 + wi1 + wi2
19342 fqxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*f0d+&
19343 & wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1+wi2&
19344 & *f2)*sumwkd)/sumwk**2
19345 fqx(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
19348 ! fqx( i,k ) = vel*flux5( w(i-3,k,j), w(i-2,k,j), &
19349 ! w(i-1,k,j), w(i ,k,j), &
19350 ! w(i+1,k,j), w(i+2,k,j), &
19353 DO i=i_start_f,i_end_f
19354 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
19355 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
19356 IF (vel*sign(1,time_step) .GE. 0.0) THEN
19357 qip2d = wd(i+1, k, j)
19358 qip2 = w(i+1, k, j)
19359 qip1d = wd(i, k, j)
19361 qid = wd(i-1, k, j)
19363 qim1d = wd(i-2, k, j)
19364 qim1 = w(i-2, k, j)
19365 qim2d = wd(i-3, k, j)
19366 qim2 = w(i-3, k, j)
19368 qip2d = wd(i-2, k, j)
19369 qip2 = w(i-2, k, j)
19370 qip1d = wd(i-1, k, j)
19371 qip1 = w(i-1, k, j)
19374 qim1d = wd(i+1, k, j)
19375 qim1 = w(i+1, k, j)
19376 qim2d = wd(i+2, k, j)
19377 qim2 = w(i+2, k, j)
19379 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
19380 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
19381 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
19382 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
19383 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
19384 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
19385 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
19386 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
19387 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi)&
19389 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
19390 & qim1-qip1)*(qim1d-qip1d)/4.
19391 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
19392 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
19393 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
19394 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi)&
19398 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) THEN
19399 pwr1d = pw*pwx1**(pw-1)*pwx1d
19400 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19406 wi0d = -(gi0*pwr1d/pwr1**2)
19410 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) THEN
19411 pwr1d = pw*pwx1**(pw-1)*pwx1d
19412 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19418 wi1d = -(gi1*pwr1d/pwr1**2)
19422 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) THEN
19423 pwr1d = pw*pwx1**(pw-1)*pwx1d
19424 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19430 wi2d = -(gi2*pwr1d/pwr1**2)
19432 sumwkd = wi0d + wi1d + wi2d
19433 sumwk = wi0 + wi1 + wi2
19434 fqxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*f0d+&
19435 & wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1+wi2*&
19436 & f2)*sumwkd)/sumwk**2
19437 fqx(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
19439 ! fqx( i,k ) = vel*flux5( w(i-3,k,j), w(i-2,k,j), &
19440 ! w(i-1,k,j), w(i ,k,j), &
19441 ! w(i+1,k,j), w(i+2,k,j), &
19443 ! lower order fluxes close to boundaries (if not periodic or symmetric)
19444 IF (degrade_xs) THEN
19445 DO i=i_start,i_start_f-1
19446 IF (i .EQ. ids + 1) THEN
19449 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, j)&
19450 & )*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)*ru(&
19451 & i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
19452 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*(w&
19453 & (i, k, j)+w(i-1, k, j))
19456 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud(i&
19457 & , k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i, k-&
19458 & 1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, j)))
19459 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, k-&
19460 & 2, j))*(w(i, k, j)+w(i-1, k, j))
19462 IF (i .EQ. ids + 2) THEN
19465 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
19466 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
19467 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
19468 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w&
19469 & (i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/&
19470 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)&
19471 & -wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(&
19472 & i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/&
19474 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
19475 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
19476 & +1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
19479 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
19480 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
19481 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
19482 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1&
19483 & , k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0) + &
19484 & vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)-wd(i-2, k&
19485 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i+1, k, j)-&
19486 & wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/12.0)
19487 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w&
19488 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1, &
19489 & k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
19493 IF (degrade_xe) THEN
19494 DO i=i_end_f+1,i_end+1
19495 IF (i .EQ. ide - 1) THEN
19496 ! second order flux next to the boundary
19498 fqxd(i, k) = 0.5*((fzm(k)*rud(i, k, j)+fzp(k)*rud(i, k-1, j)&
19499 & )*(w(i, k, j)+w(i-1, k, j))+(fzm(k)*ru(i, k, j)+fzp(k)*ru(&
19500 & i, k-1, j))*(wd(i, k, j)+wd(i-1, k, j)))
19501 fqx(i, k) = 0.5*(fzm(k)*ru(i, k, j)+fzp(k)*ru(i, k-1, j))*(w&
19502 & (i, k, j)+w(i-1, k, j))
19505 fqxd(i, k) = 0.5*(((2.-fzm(k-1))*rud(i, k-1, j)-fzp(k-1)*rud(i&
19506 & , k-2, j))*(w(i, k, j)+w(i-1, k, j))+((2.-fzm(k-1))*ru(i, k-&
19507 & 1, j)-fzp(k-1)*ru(i, k-2, j))*(wd(i, k, j)+wd(i-1, k, j)))
19508 fqx(i, k) = 0.5*((2.-fzm(k-1))*ru(i, k-1, j)-fzp(k-1)*ru(i, k-&
19509 & 2, j))*(w(i, k, j)+w(i-1, k, j))
19511 IF (i .EQ. ide - 2) THEN
19512 ! third order flux one in from the boundary
19514 veld = fzm(k)*rud(i, k, j) + fzp(k)*rud(i, k-1, j)
19515 vel = fzm(k)*ru(i, k, j) + fzp(k)*ru(i, k-1, j)
19516 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, &
19517 & j)+w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w&
19518 & (i+1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/&
19519 & 12.0) + vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)&
19520 & -wd(i-2, k, j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(&
19521 & i+1, k, j)-wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/&
19523 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
19524 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i&
19525 & +1, k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
19528 veld = (2.-fzm(k-1))*rud(i, k-1, j) - fzp(k-1)*rud(i, k-2, j)
19529 vel = (2.-fzm(k-1))*ru(i, k-1, j) - fzp(k-1)*ru(i, k-2, j)
19530 fqxd(i, k) = veld*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)&
19531 & +w(i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1&
19532 & , k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0) + &
19533 & vel*((7.*(wd(i, k, j)+wd(i-1, k, j))-wd(i+1, k, j)-wd(i-2, k&
19534 & , j))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(wd(i+1, k, j)-&
19535 & wd(i-2, k, j)-3.*(wd(i, k, j)-wd(i-1, k, j)))/12.0)
19536 fqx(i, k) = vel*((7.*(w(i, k, j)+w(i-1, k, j))-(w(i+1, k, j)+w&
19537 & (i-2, k, j)))/12.0+SIGN(1, time_step)*SIGN(1., vel)*(w(i+1, &
19538 & k, j)-w(i-2, k, j)-3.*(w(i, k, j)-w(i-1, k, j)))/12.0)
19542 ! x flux-divergence into tendency
19545 ! see ADT eqn 46 dividing by my, 1st term RHS
19546 mrdx = msftx(i, j)*rdx
19547 tendencyd(i, k, j) = tendencyd(i, k, j) - mrdx*(fqxd(i+1, k)-&
19549 tendency(i, k, j) = tendency(i, k, j) - mrdx*(fqx(i+1, k)-fqx(i&
19554 ! pick up the the horizontal radiation boundary conditions.
19555 ! (these are the computations that don't require 'cb'.
19556 ! first, set to index ranges
19558 IF (ite .GT. ide - 1) THEN
19564 IF (jte .GT. jde - 1) THEN
19569 IF (config_flags%open_xs .AND. its .EQ. ids) THEN
19572 uwd = 0.5*(fzm(k)*(rud(its, k, j)+rud(its+1, k, j))+fzp(k)*(rud(&
19573 & its, k-1, j)+rud(its+1, k-1, j)))
19574 uw = 0.5*(fzm(k)*(ru(its, k, j)+ru(its+1, k, j))+fzp(k)*(ru(its&
19575 & , k-1, j)+ru(its+1, k-1, j)))
19576 IF (uw .GT. 0.) THEN
19583 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(w_old(&
19584 & its+1, k, j)-w_old(its, k, j))+ub*(w_oldd(its+1, k, j)-w_oldd(&
19585 & its, k, j))+wd(its, k, j)*(fzm(k)*(ru(its+1, k, j)-ru(its, k, &
19586 & j))+fzp(k)*(ru(its+1, k-1, j)-ru(its, k-1, j)))+w(its, k, j)*(&
19587 & fzm(k)*(rud(its+1, k, j)-rud(its, k, j))+fzp(k)*(rud(its+1, k-&
19588 & 1, j)-rud(its, k-1, j))))
19589 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(w_old(its+1&
19590 & , k, j)-w_old(its, k, j))+w(its, k, j)*(fzm(k)*(ru(its+1, k, j&
19591 & )-ru(its, k, j))+fzp(k)*(ru(its+1, k-1, j)-ru(its, k-1, j))))
19596 uwd = 0.5*((2.-fzm(k-1))*(rud(its, k-1, j)+rud(its+1, k-1, j))-fzp&
19597 & (k-1)*(rud(its, k-2, j)+rud(its+1, k-2, j)))
19598 uw = 0.5*((2.-fzm(k-1))*(ru(its, k-1, j)+ru(its+1, k-1, j))-fzp(k-&
19599 & 1)*(ru(its, k-2, j)+ru(its+1, k-2, j)))
19600 IF (uw .GT. 0.) THEN
19607 tendencyd(its, k, j) = tendencyd(its, k, j) - rdx*(ubd*(w_old(its+&
19608 & 1, k, j)-w_old(its, k, j))+ub*(w_oldd(its+1, k, j)-w_oldd(its, k&
19609 & , j))+wd(its, k, j)*((2.-fzm(k-1))*(ru(its+1, k-1, j)-ru(its, k-&
19610 & 1, j))-fzp(k-1)*(ru(its+1, k-2, j)-ru(its, k-2, j)))+w(its, k, j&
19611 & )*((2.-fzm(k-1))*(rud(its+1, k-1, j)-rud(its, k-1, j))-fzp(k-1)*&
19612 & (rud(its+1, k-2, j)-rud(its, k-2, j))))
19613 tendency(its, k, j) = tendency(its, k, j) - rdx*(ub*(w_old(its+1, &
19614 & k, j)-w_old(its, k, j))+w(its, k, j)*((2.-fzm(k-1))*(ru(its+1, k&
19615 & -1, j)-ru(its, k-1, j))-fzp(k-1)*(ru(its+1, k-2, j)-ru(its, k-2&
19619 IF (config_flags%open_xe .AND. ite .EQ. ide) THEN
19622 uwd = 0.5*(fzm(k)*(rud(ite-1, k, j)+rud(ite, k, j))+fzp(k)*(rud(&
19623 & ite-1, k-1, j)+rud(ite, k-1, j)))
19624 uw = 0.5*(fzm(k)*(ru(ite-1, k, j)+ru(ite, k, j))+fzp(k)*(ru(ite-&
19625 & 1, k-1, j)+ru(ite, k-1, j)))
19626 IF (uw .LT. 0.) THEN
19633 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(&
19634 & w_old(i_end, k, j)-w_old(i_end-1, k, j))+ub*(w_oldd(i_end, k, &
19635 & j)-w_oldd(i_end-1, k, j))+wd(i_end, k, j)*(fzm(k)*(ru(ite, k, &
19636 & j)-ru(ite-1, k, j))+fzp(k)*(ru(ite, k-1, j)-ru(ite-1, k-1, j))&
19637 & )+w(i_end, k, j)*(fzm(k)*(rud(ite, k, j)-rud(ite-1, k, j))+fzp&
19638 & (k)*(rud(ite, k-1, j)-rud(ite-1, k-1, j))))
19639 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(w_old(&
19640 & i_end, k, j)-w_old(i_end-1, k, j))+w(i_end, k, j)*(fzm(k)*(ru(&
19641 & ite, k, j)-ru(ite-1, k, j))+fzp(k)*(ru(ite, k-1, j)-ru(ite-1, &
19647 uwd = 0.5*((2.-fzm(k-1))*(rud(ite-1, k-1, j)+rud(ite, k-1, j))-fzp&
19648 & (k-1)*(rud(ite-1, k-2, j)+rud(ite, k-2, j)))
19649 uw = 0.5*((2.-fzm(k-1))*(ru(ite-1, k-1, j)+ru(ite, k-1, j))-fzp(k-&
19650 & 1)*(ru(ite-1, k-2, j)+ru(ite, k-2, j)))
19651 IF (uw .LT. 0.) THEN
19658 tendencyd(i_end, k, j) = tendencyd(i_end, k, j) - rdx*(ubd*(w_old(&
19659 & i_end, k, j)-w_old(i_end-1, k, j))+ub*(w_oldd(i_end, k, j)-&
19660 & w_oldd(i_end-1, k, j))+wd(i_end, k, j)*((2.-fzm(k-1))*(ru(ite, k&
19661 & -1, j)-ru(ite-1, k-1, j))-fzp(k-1)*(ru(ite, k-2, j)-ru(ite-1, k-&
19662 & 2, j)))+w(i_end, k, j)*((2.-fzm(k-1))*(rud(ite, k-1, j)-rud(ite-&
19663 & 1, k-1, j))-fzp(k-1)*(rud(ite, k-2, j)-rud(ite-1, k-2, j))))
19664 tendency(i_end, k, j) = tendency(i_end, k, j) - rdx*(ub*(w_old(&
19665 & i_end, k, j)-w_old(i_end-1, k, j))+w(i_end, k, j)*((2.-fzm(k-1))&
19666 & *(ru(ite, k-1, j)-ru(ite-1, k-1, j))-fzp(k-1)*(ru(ite, k-2, j)-&
19667 & ru(ite-1, k-2, j))))
19670 IF (config_flags%open_ys .AND. jts .EQ. jds) THEN
19673 vwd = 0.5*(fzm(k)*(rvd(i, k, jts)+rvd(i, k, jts+1))+fzp(k)*(rvd(&
19674 & i, k-1, jts)+rvd(i, k-1, jts+1)))
19675 vw = 0.5*(fzm(k)*(rv(i, k, jts)+rv(i, k, jts+1))+fzp(k)*(rv(i, k&
19676 & -1, jts)+rv(i, k-1, jts+1)))
19677 IF (vw .GT. 0.) THEN
19684 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(w_old(i&
19685 & , k, jts+1)-w_old(i, k, jts))+vb*(w_oldd(i, k, jts+1)-w_oldd(i&
19686 & , k, jts))+wd(i, k, jts)*(fzm(k)*(rv(i, k, jts+1)-rv(i, k, jts&
19687 & ))+fzp(k)*(rv(i, k-1, jts+1)-rv(i, k-1, jts)))+w(i, k, jts)*(&
19688 & fzm(k)*(rvd(i, k, jts+1)-rvd(i, k, jts))+fzp(k)*(rvd(i, k-1, &
19689 & jts+1)-rvd(i, k-1, jts))))
19690 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(w_old(i, k&
19691 & , jts+1)-w_old(i, k, jts))+w(i, k, jts)*(fzm(k)*(rv(i, k, jts+&
19692 & 1)-rv(i, k, jts))+fzp(k)*(rv(i, k-1, jts+1)-rv(i, k-1, jts))))
19697 vwd = 0.5*((2.-fzm(k-1))*(rvd(i, k-1, jts)+rvd(i, k-1, jts+1))-fzp&
19698 & (k-1)*(rvd(i, k-2, jts)+rvd(i, k-2, jts+1)))
19699 vw = 0.5*((2.-fzm(k-1))*(rv(i, k-1, jts)+rv(i, k-1, jts+1))-fzp(k-&
19700 & 1)*(rv(i, k-2, jts)+rv(i, k-2, jts+1)))
19701 IF (vw .GT. 0.) THEN
19708 tendencyd(i, k, jts) = tendencyd(i, k, jts) - rdy*(vbd*(w_old(i, k&
19709 & , jts+1)-w_old(i, k, jts))+vb*(w_oldd(i, k, jts+1)-w_oldd(i, k, &
19710 & jts))+wd(i, k, jts)*((2.-fzm(k-1))*(rv(i, k-1, jts+1)-rv(i, k-1&
19711 & , jts))-fzp(k-1)*(rv(i, k-2, jts+1)-rv(i, k-2, jts)))+w(i, k, &
19712 & jts)*((2.-fzm(k-1))*(rvd(i, k-1, jts+1)-rvd(i, k-1, jts))-fzp(k-&
19713 & 1)*(rvd(i, k-2, jts+1)-rvd(i, k-2, jts))))
19714 tendency(i, k, jts) = tendency(i, k, jts) - rdy*(vb*(w_old(i, k, &
19715 & jts+1)-w_old(i, k, jts))+w(i, k, jts)*((2.-fzm(k-1))*(rv(i, k-1&
19716 & , jts+1)-rv(i, k-1, jts))-fzp(k-1)*(rv(i, k-2, jts+1)-rv(i, k-2&
19720 IF (config_flags%open_ye .AND. jte .EQ. jde) THEN
19723 vwd = 0.5*(fzm(k)*(rvd(i, k, jte-1)+rvd(i, k, jte))+fzp(k)*(rvd(&
19724 & i, k-1, jte-1)+rvd(i, k-1, jte)))
19725 vw = 0.5*(fzm(k)*(rv(i, k, jte-1)+rv(i, k, jte))+fzp(k)*(rv(i, k&
19726 & -1, jte-1)+rv(i, k-1, jte)))
19727 IF (vw .LT. 0.) THEN
19734 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(&
19735 & w_old(i, k, j_end)-w_old(i, k, j_end-1))+vb*(w_oldd(i, k, &
19736 & j_end)-w_oldd(i, k, j_end-1))+wd(i, k, j_end)*(fzm(k)*(rv(i, k&
19737 & , jte)-rv(i, k, jte-1))+fzp(k)*(rv(i, k-1, jte)-rv(i, k-1, jte&
19738 & -1)))+w(i, k, j_end)*(fzm(k)*(rvd(i, k, jte)-rvd(i, k, jte-1))&
19739 & +fzp(k)*(rvd(i, k-1, jte)-rvd(i, k-1, jte-1))))
19740 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(w_old(i&
19741 & , k, j_end)-w_old(i, k, j_end-1))+w(i, k, j_end)*(fzm(k)*(rv(i&
19742 & , k, jte)-rv(i, k, jte-1))+fzp(k)*(rv(i, k-1, jte)-rv(i, k-1, &
19748 vwd = 0.5*((2.-fzm(k-1))*(rvd(i, k-1, jte-1)+rvd(i, k-1, jte))-fzp&
19749 & (k-1)*(rvd(i, k-2, jte-1)+rvd(i, k-2, jte)))
19750 vw = 0.5*((2.-fzm(k-1))*(rv(i, k-1, jte-1)+rv(i, k-1, jte))-fzp(k-&
19751 & 1)*(rv(i, k-2, jte-1)+rv(i, k-2, jte)))
19752 IF (vw .LT. 0.) THEN
19759 tendencyd(i, k, j_end) = tendencyd(i, k, j_end) - rdy*(vbd*(w_old(&
19760 & i, k, j_end)-w_old(i, k, j_end-1))+vb*(w_oldd(i, k, j_end)-&
19761 & w_oldd(i, k, j_end-1))+wd(i, k, j_end)*((2.-fzm(k-1))*(rv(i, k-1&
19762 & , jte)-rv(i, k-1, jte-1))-fzp(k-1)*(rv(i, k-2, jte)-rv(i, k-2, &
19763 & jte-1)))+w(i, k, j_end)*((2.-fzm(k-1))*(rvd(i, k-1, jte)-rvd(i, &
19764 & k-1, jte-1))-fzp(k-1)*(rvd(i, k-2, jte)-rvd(i, k-2, jte-1))))
19765 tendency(i, k, j_end) = tendency(i, k, j_end) - rdy*(vb*(w_old(i, &
19766 & k, j_end)-w_old(i, k, j_end-1))+w(i, k, j_end)*((2.-fzm(k-1))*(&
19767 & rv(i, k-1, jte)-rv(i, k-1, jte-1))-fzp(k-1)*(rv(i, k-2, jte)-rv(&
19768 & i, k-2, jte-1))))
19771 !-------------------- vertical advection
19772 ! ADT eqn 46 has 3rd term on RHS (dividing through by my) = - partial d/dz (w rho w /my)
19773 ! Here we have: - partial d/dz (w*rom) = - partial d/dz (w rho w / my)
19774 ! Therefore we don't need to make a correction for advect_w
19776 IF (ite .GT. ide - 1) THEN
19782 IF (jte .GT. jde - 1) THEN
19788 vfluxd(i, kts) = 0.0
19790 vfluxd(i, kte) = 0.0
19794 ! vert_order_test : IF (vert_order == 6) THEN
19795 ! ELSE IF (vert_order == 5) THEN
19799 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
19800 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
19801 IF (-vel*sign(1,time_step) .GE. 0.0) THEN
19802 qip2d = wd(i, k+1, j)
19803 qip2 = w(i, k+1, j)
19804 qip1d = wd(i, k, j)
19806 qid = wd(i, k-1, j)
19808 qim1d = wd(i, k-2, j)
19809 qim1 = w(i, k-2, j)
19810 qim2d = wd(i, k-3, j)
19811 qim2 = w(i, k-3, j)
19813 qip2d = wd(i, k-2, j)
19814 qip2 = w(i, k-2, j)
19815 qip1d = wd(i, k-1, j)
19816 qip1 = w(i, k-1, j)
19819 qim1d = wd(i, k+1, j)
19820 qim1 = w(i, k+1, j)
19821 qim2d = wd(i, k+2, j)
19822 qim2 = w(i, k+2, j)
19824 f0d = qim2d/3. - 7.*qim1d/6. + 11.*qid/6.
19825 f0 = 1./3.*qim2 - 7./6.*qim1 + 11./6.*qi
19826 f1d = 5.*qid/6. - qim1d/6. + qip1d/3.
19827 f1 = -(1./6.*qim1) + 5./6.*qi + 1./3.*qip1
19828 f2d = qid/3. + 5.*qip1d/6. - qip2d/6.
19829 f2 = 1./3.*qi + 5./6.*qip1 - 1./6.*qip2
19830 beta0d = 13.*2*(qim2-2.*qim1+qi)*(qim2d-2.*qim1d+qid)/12. + 2*(&
19831 & qim2-4.*qim1+3.*qi)*(qim2d-4.*qim1d+3.*qid)/4.
19832 beta0 = 13./12.*(qim2-2.*qim1+qi)**2 + 1./4.*(qim2-4.*qim1+3.*qi&
19834 beta1d = 13.*2*(qim1-2.*qi+qip1)*(qim1d-2.*qid+qip1d)/12. + 2*(&
19835 & qim1-qip1)*(qim1d-qip1d)/4.
19836 beta1 = 13./12.*(qim1-2.*qi+qip1)**2 + 1./4.*(qim1-qip1)**2
19837 beta2d = 13.*2*(qi-2.*qip1+qip2)*(qid-2.*qip1d+qip2d)/12. + 2*(&
19838 & qip2-4.*qip1+3.*qi)*(qip2d-4.*qip1d+3.*qid)/4.
19839 beta2 = 13./12.*(qi-2.*qip1+qip2)**2 + 1./4.*(qip2-4.*qip1+3.*qi&
19843 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19845 pwr1d = pw*pwx1**(pw-1)*pwx1d
19846 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19852 wi0d = -(gi0*pwr1d/pwr1**2)
19856 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19858 pwr1d = pw*pwx1**(pw-1)*pwx1d
19859 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19865 wi1d = -(gi1*pwr1d/pwr1**2)
19869 IF (pwx1 .GT. 0.0 .OR. (pwx1 .LT. 0.0 .AND. pw .EQ. INT(pw))) &
19871 pwr1d = pw*pwx1**(pw-1)*pwx1d
19872 ELSE IF (pwx1 .EQ. 0.0 .AND. pw .EQ. 1.0) THEN
19878 wi2d = -(gi2*pwr1d/pwr1**2)
19880 sumwkd = wi0d + wi1d + wi2d
19881 sumwk = wi0 + wi1 + wi2
19882 vfluxd(i, k) = ((veld*(wi0*f0+wi1*f1+wi2*f2)+vel*(wi0d*f0+wi0*&
19883 & f0d+wi1d*f1+wi1*f1d+wi2d*f2+wi2*f2d))*sumwk-vel*(wi0*f0+wi1*f1&
19884 & +wi2*f2)*sumwkd)/sumwk**2
19885 vflux(i, k) = vel*(wi0*f0+wi1*f1+wi2*f2)/sumwk
19888 ! vflux(i,k) = vel*flux5( &
19889 ! w(i,k-3,j), w(i,k-2,j), w(i,k-1,j), &
19890 ! w(i,k ,j), w(i,k+1,j), w(i,k+2,j), -vel )
19893 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)+w&
19894 & (i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i, k-&
19896 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i, &
19899 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
19900 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
19901 vfluxd(i, k) = veld*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
19902 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1, &
19903 & j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0) + vel*((7.*(&
19904 & wd(i, k, j)+wd(i, k-1, j))-wd(i, k+1, j)-wd(i, k-2, j))/12.0+&
19905 & SIGN(1, time_step)*SIGN(1., -vel)*(wd(i, k+1, j)-wd(i, k-2, j)-&
19906 & 3.*(wd(i, k, j)-wd(i, k-1, j)))/12.0)
19907 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w(i&
19908 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1, j)&
19909 & -w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0)
19911 veld = 0.5*(romd(i, k, j)+romd(i, k-1, j))
19912 vel = 0.5*(rom(i, k, j)+rom(i, k-1, j))
19913 vfluxd(i, k) = veld*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w&
19914 & (i, k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1, &
19915 & j)-w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0) + vel*((7.*(&
19916 & wd(i, k, j)+wd(i, k-1, j))-wd(i, k+1, j)-wd(i, k-2, j))/12.0+&
19917 & SIGN(1, time_step)*SIGN(1., -vel)*(wd(i, k+1, j)-wd(i, k-2, j)-&
19918 & 3.*(wd(i, k, j)-wd(i, k-1, j)))/12.0)
19919 vflux(i, k) = vel*((7.*(w(i, k, j)+w(i, k-1, j))-(w(i, k+1, j)+w(i&
19920 & , k-2, j)))/12.0+SIGN(1, time_step)*SIGN(1., -vel)*(w(i, k+1, j)&
19921 & -w(i, k-2, j)-3.*(w(i, k, j)-w(i, k-1, j)))/12.0)
19923 vfluxd(i, k) = 0.25*((romd(i, k, j)+romd(i, k-1, j))*(w(i, k, j)+w&
19924 & (i, k-1, j))+(rom(i, k, j)+rom(i, k-1, j))*(wd(i, k, j)+wd(i, k-&
19926 vflux(i, k) = 0.25*(rom(i, k, j)+rom(i, k-1, j))*(w(i, k, j)+w(i, &
19931 tendencyd(i, k, j) = tendencyd(i, k, j) - rdzu(k)*(vfluxd(i, k+1&
19933 tendency(i, k, j) = tendency(i, k, j) - rdzu(k)*(vflux(i, k+1)-&
19937 ! pick up flux contribution for w at the lid, wcs. 13 march 2004
19940 tendencyd(i, k, j) = tendencyd(i, k, j) + 2.*rdzu(k-1)*vfluxd(i, k&
19942 tendency(i, k, j) = tendency(i, k, j) + 2.*rdzu(k-1)*vflux(i, k)
19945 END SUBROUTINE G_ADVECT_WENO_W
19947 END MODULE g_module_advect_em