2 ! ======================================================================================
3 ! This file was generated by the version 5.3.5 of DFT on 06/19/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 ! ======================================================================================
8 ! Ning Pan, 2010-07-10: Change Diff_ to g_
9 ! Ning Pan, 2010-07-11: Change the order of arguments
11 MODULE g_module_small_step_em
14 USE module_model_constants
18 SUBROUTINE g_advance_all (u, g_u, ru_tend, g_ru_tend, v, g_v, rv_tend, g_rv_tend, &
19 w, g_w, rw_tend, g_rw_tend, t, g_t, t_tend, g_t_tend, &
20 mu, g_mu, mu_tend, g_mu_tend, ph, g_ph, ph_tend, g_ph_tend, &
21 muu, g_muu, muv, g_muv, mut, g_mut, &
22 msfuy, msfvx, msfty, &
24 config_flags, spec_zone, &
25 ids, ide, jds, jde, kds, kde, &
26 ims, ime, jms, jme, kms, kme, &
27 ips, ipe, jps, jpe, kps, kpe, &
28 its, ite, jts, jte, kts, kte )
30 IMPLICIT NONE ! religion first
32 TYPE(grid_config_rec_type), INTENT(IN ) :: config_flags
34 INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde
35 INTEGER, INTENT(IN ) :: ims,ime, jms,jme, kms,kme
36 INTEGER, INTENT(IN ) :: ips,ipe, jps,jpe, kps,kpe
37 INTEGER, INTENT(IN ) :: its,ite, jts,jte, kts,kte
38 INTEGER, INTENT(IN ) :: spec_zone
40 REAL, DIMENSION( ims:ime , kms:kme, jms:jme ), &
47 REAL, DIMENSION( ims:ime , kms:kme, jms:jme ), &
55 REAL, DIMENSION( ims:ime , kms:kme, jms:jme ), &
62 REAL, DIMENSION( ims:ime , kms:kme, jms:jme ), &
70 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(INOUT) :: g_mu
71 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(INOUT) :: mu
72 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(IN ) :: g_mu_tend
73 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(IN ) :: mu_tend
75 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(IN ) :: g_muu, &
78 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(IN ) :: muu, &
82 REAL, DIMENSION( ims:ime , jms:jme ), INTENT(IN ) :: msfuy, &
86 REAL, INTENT(IN ) :: dts
89 INTEGER :: i,j,k, i_start, i_end, j_start, j_end, k_start, k_end
90 INTEGER :: i_endu, j_endv, k_endw
92 INTEGER :: i_start_u_tend, i_end_u_tend, j_start_v_tend, j_end_v_tend
96 ! advance_all advances the explicit perturbation horizontal momentum
97 ! equations (u,v) by adding in the large-timestep tendency along with
98 ! the small timestep pressure gradient tendency.
102 ! now, the real work.
103 ! set the loop bounds taking into account boundary conditions.
105 IF( config_flags%nested .or. config_flags%specified ) THEN
106 i_start = max( its,ids+spec_zone )
107 i_end = min( ite,ide-spec_zone-1 )
108 j_start = max( jts,jds+spec_zone )
109 j_end = min( jte,jde-spec_zone-1 )
111 k_end = min( kte, kde-1 )
113 i_endu = min( ite,ide-spec_zone )
114 j_endv = min( jte,jde-spec_zone )
117 IF( config_flags%periodic_x) THEN
119 i_end = min(ite,ide-1)
124 i_end = min(ite,ide-1)
126 j_end = min(jte,jde-1)
135 i_start_u_tend = i_start
136 i_end_u_tend = i_endu
137 j_start_v_tend = j_start
138 j_end_v_tend = j_endv
140 IF ( config_flags%symmetric_xs .and. (its == ids) ) &
141 i_start_u_tend = i_start_u_tend+1
142 IF ( config_flags%symmetric_xe .and. (ite == ide) ) &
143 i_end_u_tend = i_end_u_tend-1
144 IF ( config_flags%symmetric_ys .and. (jts == jds) ) &
145 j_start_v_tend = j_start_v_tend+1
146 IF ( config_flags%symmetric_ye .and. (jte == jde) ) &
147 j_end_v_tend = j_end_v_tend-1
149 u_outer_j_loop: DO j = j_start, j_end
150 DO k = k_start, k_end
151 DO i = i_start_u_tend, i_end_u_tend
152 g_u(i,k,j) = g_u(i,k,j) &
153 + dts*msfuy(i,j)*( g_ru_tend(i,k,j)/muu(i,j) - &
154 ru_tend(i,k,j)*g_muu(i,j)/(muu(i,j)*muu(i,j)) )
155 u(i,k,j) = u(i,k,j) + dts*ru_tend(i,k,j)*msfuy(i,j)/muu(i,j)
160 v_outer_j_loop: DO j = j_start_v_tend, j_end_v_tend
161 DO k = k_start, k_end
162 DO i = i_start, i_end
163 g_v(i,k,j) = g_v(i,k,j) &
164 + dts*msfvx(i,j)*( g_rv_tend(i,k,j)/muv(i,j) - &
165 rv_tend(i,k,j)*g_muv(i,j)/(muv(i,j)*muv(i,j)) )
166 v(i,k,j) = v(i,k,j) + dts*rv_tend(i,k,j)*msfvx(i,j)/muv(i,j)
172 i_end = min(ite,ide-1)
174 j_end = min(jte,jde-1)
177 IF ( .NOT. config_flags%periodic_x )THEN
178 IF ( config_flags%specified .or. config_flags%nested ) then
179 i_start = max(its,ids+1)
180 i_end = min(ite,ide-2)
183 IF ( config_flags%specified .or. config_flags%nested ) then
184 j_start = max(jts,jds+1)
185 j_end = min(jte,jde-2)
188 DO j = j_start, j_end
190 g_mu(i,j) = g_mu(i,j)+dts*g_mu_tend(i,j)
191 mu(i,j) = mu(i,j)+dts*mu_tend(i,j)
198 g_t(i,k,j) = g_t(i,k,j) &
199 + dts*msfty(i,j)*( g_t_tend(i,k,j)/mut(i,j) - &
200 t_tend(i,k,j)*g_mut(i,j)/(mut(i,j)*mut(i,j)) )
201 t(i,k,j) = t(i,k,j) + msfty(i,j)*dts*t_tend(i,k,j)/mut(i,j)
207 i_end = min(ite,ide-1)
209 j_end = min(jte,jde-1)
212 IF ( .NOT. config_flags%periodic_x )THEN
213 IF ( config_flags%specified .or. config_flags%nested ) then
214 i_start = max(its,ids+1)
215 i_end = min(ite,ide-2)
218 IF ( config_flags%specified .or. config_flags%nested ) then
219 j_start = max(jts,jds+1)
220 j_end = min(jte,jde-2)
223 IF ( config_flags%non_hydrostatic ) THEN
224 j_loop_w: DO j = j_start, j_end
227 g_w(i,k,j) = g_w(i,k,j) &
228 + dts*msfty(i,j)*( g_rw_tend(i,k,j)/mut(i,j) - &
229 rw_tend(i,k,j)*g_mut(i,j)/(mut(i,j)*mut(i,j)) )
230 w(i,k,j)=w(i,k,j)+dts*rw_tend(i,k,j)*msfty(i,j)/mut(i,j)
232 g_ph(i,k,j) = g_ph(i,k,j) &
233 + dts*msfty(i,j)*( g_ph_tend(i,k,j)/mut(i,j) - &
234 ph_tend(i,k,j)*g_mut(i,j)/(mut(i,j)*mut(i,j)) )
235 ph(i,k,j) = ph(i,k,j)+dts*ph_tend(i,k,j)*msfty(i,j)/mut(i,j)
241 END SUBROUTINE g_advance_all
244 SUBROUTINE g_save_ph_mu ( ph_1, g_ph_1, ph_2, g_ph_2, ph_save, g_ph_save, &
245 mu_1, g_mu_1, mu_2, g_mu_2, mu_save, g_mu_save, &
247 ids,ide, jds,jde, kds,kde, &
248 ims,ime, jms,jme, kms,kme, &
249 its,ite, jts,jte, kts,kte )
251 IMPLICIT NONE ! religion first
253 ! declarations for the stuff coming in
255 INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde
256 INTEGER, INTENT(IN ) :: ims,ime, jms,jme, kms,kme
257 INTEGER, INTENT(IN ) :: its,ite, jts,jte, kts,kte
259 INTEGER, INTENT(IN ) :: rk_step
261 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: g_ph_1
262 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: ph_1
264 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT( OUT) :: g_ph_save
265 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT( OUT) :: ph_save
267 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: g_ph_2
268 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: ph_2
270 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: g_mu_1,g_mu_2
271 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mu_1,mu_2
272 REAL, DIMENSION(ims:ime, jms:jme), INTENT( OUT) :: g_mu_save
273 REAL, DIMENSION(ims:ime, jms:jme), INTENT( OUT) :: mu_save
278 INTEGER :: i_start, i_end, j_start, j_end, k_start, k_end
282 i_end = min(ite,ide-1)
284 j_end = min(jte,jde-1)
286 k_end = min(kte,kde-1)
288 ! if this is the first RK step, reset *_1 to *_2
289 ! (we are replacing the t-dt fields with the time t fields)
291 IF ((rk_step == 1) ) THEN
294 DO k=k_start, min(kde,kte)
296 g_ph_1(i,k,j) = g_ph_2(i,k,j)
297 ph_1(i,k,j) = ph_2(i,k,j)
304 g_mu_1(i,j) = g_mu_2(i,j)
305 mu_1(i,j) = mu_2(i,j)
311 ! set up the small timestep variables
314 ! DO k=k_start, min(kde,kte)
317 g_ph_save(i,k,j) = g_ph_2(i,k,j)
318 ph_save(i,k,j) = ph_2(i,k,j)
319 g_ph_2(i,k,j) = g_ph_1(i,k,j)-g_ph_2(i,k,j)
320 ph_2(i,k,j) = ph_1(i,k,j)-ph_2(i,k,j)
327 g_mu_save(i,j)=g_mu_2(i,j)
328 mu_save(i,j)=mu_2(i,j)
329 g_mu_2(i,j)=g_mu_1(i,j)-g_mu_2(i,j)
330 mu_2(i,j)=mu_1(i,j)-mu_2(i,j)
334 END SUBROUTINE g_save_ph_mu
336 !----------------------------------------------------------------------
338 SUBROUTINE g_restore_ph_mu ( ph_2, g_ph_2, ph_save, g_ph_save, &
339 mu_2, g_mu_2, mu_save, g_mu_save, &
340 ids,ide, jds,jde, kds,kde, &
341 ims,ime, jms,jme, kms,kme, &
342 its,ite, jts,jte, kts,kte )
344 IMPLICIT NONE ! religion first
346 ! declarations for the stuff coming in
348 INTEGER, INTENT(IN ) :: ids,ide, jds,jde, kds,kde
349 INTEGER, INTENT(IN ) :: ims,ime, jms,jme, kms,kme
350 INTEGER, INTENT(IN ) :: its,ite, jts,jte, kts,kte
352 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(IN ) :: g_ph_save
353 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(IN ) :: ph_save
354 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: g_ph_2
355 REAL, DIMENSION(ims:ime, kms:kme, jms:jme),INTENT(INOUT) :: ph_2
356 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: g_mu_2
357 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mu_2
358 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN ) :: g_mu_save
359 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN ) :: mu_save
364 INTEGER :: i_start, i_end, j_start, j_end
368 i_end = min(ite,ide-1)
370 j_end = min(jte,jde-1)
372 DO j = j_start, j_end
374 DO i = i_start, i_end
375 g_ph_2(i,k,j) = g_ph_2(i,k,j) + g_ph_save(i,k,j)
376 ph_2(i,k,j) = ph_2(i,k,j) + ph_save(i,k,j)
381 DO j = j_start, j_end
382 DO i = i_start, i_end
383 g_mu_2(i,j) = g_mu_2(i,j) + g_mu_save(i,j)
384 mu_2(i,j) = mu_2(i,j) + mu_save(i,j)
388 END SUBROUTINE g_restore_ph_mu
390 SUBROUTINE g_small_step_prep(u_1,g_u_1,u_2,g_u_2,v_1,g_v_1,v_2,g_v_2, &
391 w_1,g_w_1,w_2,g_w_2,t_1,g_t_1,t_2,g_t_2,ph_1,g_ph_1,ph_2,g_ph_2, &
392 mub,mu_1,g_mu_1,mu_2,g_mu_2,muu,g_muu,muus,g_muus,muv,g_muv,muvs, &
393 g_muvs,mut,g_mut,muts,g_muts,mudf,g_mudf,u_save,g_u_save,v_save, &
394 g_v_save,w_save,g_w_save,t_save,g_t_save,ph_save,g_ph_save,mu_save, &
395 g_mu_save,ww,g_ww,ww_save,g_ww_save,c2a,g_c2a,pb,p,g_p,alt,g_alt, &
396 msfux,msfuy,msfvx,msfvx_inv,msfvy,msftx,msfty,rdx,rdy,rk_step,ids,ide,jds,jde,kds, &
397 kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
400 INTEGER,INTENT(IN) :: ids,ide,jds,jde,kds,kde
401 INTEGER,INTENT(IN) :: ims,ime,jms,jme,kms,kme
402 INTEGER,INTENT(IN) :: its,ite,jts,jte,kts,kte
403 INTEGER,INTENT(IN) :: rk_step
404 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_u_1,u_1,g_v_1,v_1, &
405 g_w_1,w_1,g_t_1,t_1,g_ph_1,ph_1
406 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(OUT) :: g_u_save,u_save, &
407 g_v_save,v_save,g_w_save,w_save,g_t_save,t_save,g_ph_save,ph_save
408 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_u_2,u_2,g_v_2,v_2, &
409 g_w_2,w_2,g_t_2,t_2,g_ph_2,ph_2
410 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(OUT) :: g_c2a,c2a,g_ww_save,ww_save
411 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(IN) :: pb,g_p,p,g_alt,alt,g_ww,ww
412 REAL,DIMENSION(ims:ime,jms:jme),INTENT(INOUT) :: g_mu_1,mu_1,g_mu_2,mu_2
413 REAL,DIMENSION(ims:ime,jms:jme),INTENT(IN) :: mub,g_muu,muu,g_muv,muv,g_mut, &
414 mut,msfux,msfuy,msfvx,msfvx_inv,msfvy,msftx,msfty
415 REAL,DIMENSION(ims:ime,jms:jme),INTENT(OUT) :: g_muus,muus,g_muvs,muvs, &
416 g_muts,muts,g_mudf,mudf
417 REAL,DIMENSION(ims:ime,jms:jme),INTENT(OUT) :: g_mu_save,mu_save
418 REAL,INTENT(IN) :: rdx,rdy
420 INTEGER :: i_start,i_end,j_start,j_end,k_start,k_end
421 INTEGER :: i_endu,j_endv
425 i_end =min(ite,ide-1)
429 j_end =min(jte,jde-1)
433 k_end =min(kte,kde-1)
439 IF((rk_step == 1) ) THEN
444 g_mu_1(i,j) =g_mu_2(i,j)
447 g_ww_save(i,kde,j) =0.0
450 g_ww_save(i,1,j) =0.0
463 g_u_1(i,k,j) =g_u_2(i,k,j)
464 u_1(i,k,j) =u_2(i,k,j)
474 g_v_1(i,k,j) =g_v_2(i,k,j)
475 v_1(i,k,j) =v_2(i,k,j)
485 g_t_1(i,k,j) =g_t_2(i,k,j)
486 t_1(i,k,j) =t_2(i,k,j)
493 DO k =k_start,min(kde,kte)
496 g_w_1(i,k,j) =g_w_2(i,k,j)
497 w_1(i,k,j) =w_2(i,k,j)
499 g_ph_1(i,k,j) =g_ph_2(i,k,j)
500 ph_1(i,k,j) =ph_2(i,k,j)
509 g_muts(i,j) =g_mu_2(i,j)
510 muts(i,j) =mub(i,j) +mu_2(i,j)
516 g_muus(i,j) =g_muu(i,j)
525 g_muvs(i,j) =g_muv(i,j)
534 g_mu_save(i,j) =g_mu_2(i,j)
535 mu_save(i,j) =mu_2(i,j)
537 !g_mu_2(i,j) =g_mu_2(i,j) -g_mu_2(i,j)
538 !mu_2(i,j) =mu_2(i,j) -mu_2(i,j)
540 g_mu_2(i,j) =0.0 !REVISED BY WALLS
541 mu_2(i,j) =0.0 !REVISED BY WALLS
550 g_muts(i,j) =g_mu_1(i,j)
551 muts(i,j) =mub(i,j) +mu_1(i,j)
557 g_muus(i,j) =0.5*(g_mu_1(i,j) +g_mu_1(i-1,j))
558 muus(i,j) =0.5*(mub(i,j) +mu_1(i,j) +mub(i-1,j) +mu_1(i-1,j))
566 g_muvs(i,j) =0.5*(g_mu_1(i,j) +g_mu_1(i,j-1))
567 muvs(i,j) =0.5*(mub(i,j) +mu_1(i,j) +mub(i,j-1) +mu_1(i,j-1))
575 g_mu_save(i,j) =g_mu_2(i,j)
576 mu_save(i,j) =mu_2(i,j)
578 g_mu_2(i,j) =g_mu_1(i,j) -g_mu_2(i,j)
579 mu_2(i,j) =mu_1(i,j) -mu_2(i,j)
588 g_ww_save(i,kde,j) =0.0
591 g_ww_save(i,1,j) =0.0
601 g_c2a(i,k,j) =(cpovcv*(g_p(i,k,j))*alt(i,k,j) -g_alt(i,k,j)*cpovcv*(pb(i,k, &
602 j) +p(i,k,j)))/(alt(i,k,j)*alt(i,k,j))
603 c2a(i,k,j) =cpovcv*(pb(i,k,j) +p(i,k,j))/alt(i,k,j)
613 g_u_save(i,k,j) =g_u_2(i,k,j)
614 u_save(i,k,j) =u_2(i,k,j)
616 g_u_2(i,k,j) =(muus(i,j)*g_u_1(i,k,j) +g_muus(i,j)*u_1(i,k,j) -(muu(i,j) &
617 *g_u_2(i,k,j) +g_muu(i,j)*u_2(i,k,j)))/msfuy(i,j)
618 u_2(i,k,j) =(muus(i,j)*u_1(i,k,j) -muu(i,j)*u_2(i,k,j))/msfuy(i,j)
628 g_v_save(i,k,j) =g_v_2(i,k,j)
629 v_save(i,k,j) =v_2(i,k,j)
631 g_v_2(i,k,j) =(muvs(i,j)*g_v_1(i,k,j) +g_muvs(i,j)*v_1(i,k,j) -(muv(i,j) &
632 *g_v_2(i,k,j) +g_muv(i,j)*v_2(i,k,j)))*msfvx_inv(i,j)
633 v_2(i,k,j) =(muvs(i,j)*v_1(i,k,j) -muv(i,j)*v_2(i,k,j))*msfvx_inv(i,j)
644 g_t_save(i,k,j) =g_t_2(i,k,j)
645 t_save(i,k,j) =t_2(i,k,j)
647 g_t_2(i,k,j) =muts(i,j)*g_t_1(i,k,j) +g_muts(i,j)*t_1(i,k,j) -(mut(i,j) &
648 *g_t_2(i,k,j) +g_mut(i,j)*t_2(i,k,j))
649 t_2(i,k,j) =muts(i,j)*t_1(i,k,j) -mut(i,j)*t_2(i,k,j)
660 g_w_save(i,k,j) =g_w_2(i,k,j)
661 w_save(i,k,j) =w_2(i,k,j)
663 g_w_2(i,k,j) =(muts(i,j)*g_w_1(i,k,j) +g_muts(i,j)*w_1(i,k,j) -(mut(i,j) &
664 *g_w_2(i,k,j) +g_mut(i,j)*w_2(i,k,j)))/msfty(i,j)
665 w_2(i,k,j) =(muts(i,j)*w_1(i,k,j) -mut(i,j)*w_2(i,k,j))/msfty(i,j)
667 g_ph_save(i,k,j) =g_ph_2(i,k,j)
668 ph_save(i,k,j) =ph_2(i,k,j)
670 g_ph_2(i,k,j) =g_ph_1(i,k,j) -g_ph_2(i,k,j)
671 ph_2(i,k,j) =ph_1(i,k,j) -ph_2(i,k,j)
681 g_ww_save(i,k,j) =g_ww(i,k,j)
682 ww_save(i,k,j) =ww(i,k,j)
688 END SUBROUTINE g_small_step_prep
690 ! Generated by TAPENADE (INRIA, Tropics team)
691 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
693 ! Differentiation of small_step_finish in forward (tangent) mode:
694 ! variations of useful results: ww ph_2 u_2 mu_2 w_2 t_2 v_2
695 ! with respect to varying inputs: u_save ph_save ww w_save mu_save
696 ! muvs ph_2 u_2 h_diabatic mu_2 w_2 t_save v_save
697 ! muts t_2 mut muu v_2 muv ww1 muus
698 ! RW status of diff variables: u_save:in ph_save:in ww:in-out
699 ! w_save:in mu_save:in muvs:in ph_2:in-out u_2:in-out
700 ! h_diabatic:in mu_2:in-out w_2:in-out t_save:in
701 ! v_save:in muts:in t_2:in-out mut:in muu:in v_2:in-out
702 ! muv:in ww1:in muus:in
703 SUBROUTINE G_SMALL_STEP_FINISH(u_2, u_2d, u_1, v_2, v_2d, v_1, w_2, w_2d&
704 & , w_1, t_2, t_2d, t_1, ph_2, ph_2d, ph_1, ww, wwd, ww1, ww1d, mu_2, &
705 & mu_2d, mu_1, mut, mutd, muts, mutsd, muu, muud, muus, muusd, muv, muvd&
706 & , muvs, muvsd, u_save, u_saved, v_save, v_saved, w_save, w_saved, &
707 & t_save, t_saved, ph_save, ph_saved, mu_save, mu_saved, msfux, msfuy, &
708 & msfvx, msfvy, msftx, msfty, h_diabatic, h_diabaticd, &
709 & number_of_small_timesteps, dts, rk_step, rk_order, ids, ide, jds, jde&
710 & , kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, jte, kts, kte&
715 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde
716 INTEGER, INTENT(IN) :: ims, ime, jms, jme, kms, kme
717 INTEGER, INTENT(IN) :: its, ite, jts, jte, kts, kte
718 INTEGER, INTENT(IN) :: number_of_small_timesteps
719 INTEGER, INTENT(IN) :: rk_step, rk_order
720 REAL, INTENT(IN) :: dts
721 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: u_1, v_1, &
722 & w_1, t_1, ww1, ph_1
723 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ww1d
724 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: u_2, v_2&
725 & , w_2, t_2, ww, ph_2
726 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: u_2d, &
727 & v_2d, w_2d, t_2d, wwd, ph_2d
728 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: u_save, &
729 & v_save, w_save, t_save, ph_save, h_diabatic
730 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: u_saved, &
731 & v_saved, w_saved, t_saved, ph_saved, h_diabaticd
732 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: muus, muvs
733 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: muusd, muvsd
734 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mu_2, mu_1
735 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mu_2d
736 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mut, muts, muu, &
738 REAL, DIMENSION(ims:ime, jms:jme), INTENT(INOUT) :: mutd, mutsd, muud&
740 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
741 & msfvy, msftx, msfty
744 INTEGER :: i_start, i_end, j_start, j_end, i_endu, j_endv
748 ! small_step_finish reconstructs the full uncoupled prognostic variables
749 ! from the coupled perturbation variables used in the small timesteps.
753 IF (ite .GT. ide - 1) THEN
759 IF (jte .GT. jde - 1) THEN
766 ! addition of time level t back into variables
771 v_2d(i, k, j) = ((msfvx(i, j)*v_2d(i, k, j)+v_saved(i, k, j)*muv&
772 & (i, j)+v_save(i, k, j)*muvd(i, j))*muvs(i, j)-(msfvx(i, j)*v_2&
773 & (i, k, j)+v_save(i, k, j)*muv(i, j))*muvsd(i, j))/muvs(i, j)**&
775 v_2(i, k, j) = (msfvx(i, j)*v_2(i, k, j)+v_save(i, k, j)*muv(i, &
784 u_2d(i, k, j) = ((msfuy(i, j)*u_2d(i, k, j)+u_saved(i, k, j)*muu&
785 & (i, j)+u_save(i, k, j)*muud(i, j))*muus(i, j)-(msfuy(i, j)*u_2&
786 & (i, k, j)+u_save(i, k, j)*muu(i, j))*muusd(i, j))/muus(i, j)**&
788 u_2(i, k, j) = (msfuy(i, j)*u_2(i, k, j)+u_save(i, k, j)*muu(i, &
797 w_2d(i, k, j) = ((msfty(i, j)*w_2d(i, k, j)+w_saved(i, k, j)*mut&
798 & (i, j)+w_save(i, k, j)*mutd(i, j))*muts(i, j)-(msfty(i, j)*w_2&
799 & (i, k, j)+w_save(i, k, j)*mut(i, j))*mutsd(i, j))/muts(i, j)**&
801 w_2(i, k, j) = (msfty(i, j)*w_2(i, k, j)+w_save(i, k, j)*mut(i, &
803 ph_2d(i, k, j) = ph_2d(i, k, j) + ph_saved(i, k, j)
804 ph_2(i, k, j) = ph_2(i, k, j) + ph_save(i, k, j)
805 wwd(i, k, j) = wwd(i, k, j) + ww1d(i, k, j)
806 ww(i, k, j) = ww(i, k, j) + ww1(i, k, j)
810 IF (rk_step .LT. rk_order) THEN
814 t_2d(i, k, j) = ((t_2d(i, k, j)+t_saved(i, k, j)*mut(i, j)+&
815 & t_save(i, k, j)*mutd(i, j))*muts(i, j)-(t_2(i, k, j)+t_save(&
816 & i, k, j)*mut(i, j))*mutsd(i, j))/muts(i, j)**2
817 t_2(i, k, j) = (t_2(i, k, j)+t_save(i, k, j)*mut(i, j))/muts(i&
826 t_2d(i, k, j) = ((t_2d(i, k, j)-dts*number_of_small_timesteps*&
827 & (mutd(i, j)*h_diabatic(i, k, j)+mut(i, j)*h_diabaticd(i, k, &
828 & j))+t_saved(i, k, j)*mut(i, j)+t_save(i, k, j)*mutd(i, j))*&
829 & muts(i, j)-(t_2(i, k, j)-dts*number_of_small_timesteps*mut(i&
830 & , j)*h_diabatic(i, k, j)+t_save(i, k, j)*mut(i, j))*mutsd(i&
831 & , j))/muts(i, j)**2
832 t_2(i, k, j) = (t_2(i, k, j)-dts*number_of_small_timesteps*mut&
833 & (i, j)*h_diabatic(i, k, j)+t_save(i, k, j)*mut(i, j))/muts(i&
841 mu_2d(i, j) = mu_2d(i, j) + mu_saved(i, j)
842 mu_2(i, j) = mu_2(i, j) + mu_save(i, j)
845 END SUBROUTINE G_SMALL_STEP_FINISH
847 SUBROUTINE g_calc_p_rho(al,g_al,p,g_p,ph,g_ph,alt,g_alt,t_2,g_t_2, &
848 t_1,g_t_1,c2a,g_c2a,pm1,g_pm1,mu,g_mu,muts,g_muts,znu,t0,rdnw,dnw, &
849 smdiv,non_hydrostatic,step,ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite, &
853 INTEGER,INTENT(IN) :: ids,ide,jds,jde,kds,kde
854 INTEGER,INTENT(IN) :: ims,ime,jms,jme,kms,kme
855 INTEGER,INTENT(IN) :: its,ite,jts,jte,kts,kte
856 INTEGER,INTENT(IN) :: step
857 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(OUT) :: g_al,al,g_p,p
858 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(IN) :: g_alt,alt,g_t_2,t_2, &
860 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_ph,ph,g_pm1,pm1
861 REAL,DIMENSION(ims:ime,jms:jme),INTENT(IN) :: g_mu,mu,g_muts,muts
862 REAL,DIMENSION(kms:kme),INTENT(IN) :: dnw,rdnw,znu
863 REAL,INTENT(IN) :: t0,smdiv
864 LOGICAL,INTENT(IN) :: non_hydrostatic
866 INTEGER :: i_start,i_end,j_start,j_end,k_start,k_end
871 i_end =min(ite,ide-1)
875 j_end =min(jte,jde-1)
879 k_end =min(kte,kde-1)
881 IF(non_hydrostatic) THEN
887 g_al(i,k,j) =-1./muts(i,j)*(alt(i,k,j)*g_mu(i,j) +g_alt(i,k,j)*mu(i,j) &
888 +rdnw(k)*(g_ph(i,k+1,j) -g_ph(i,k,j))) +(-(-1.)*g_muts(i,j)/(muts(i,j) &
889 *muts(i,j)))*(alt(i,k,j)*mu(i,j) +rdnw(k)*(ph(i,k+1,j) -ph(i,k,j)))
890 al(i,k,j) =-1./muts(i,j)*(alt(i,k,j)*mu(i,j) +rdnw(k)*(ph(i,k+1,j) -ph(i,k,j)))
892 g_p(i,k,j) =c2a(i,k,j)*(((alt(i,k,j)*(g_t_2(i,k,j) -(mu(i,j)*g_t_1(i,k,j) &
893 +g_mu(i,j)*t_1(i,k,j))) +g_alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j))) &
894 *(muts(i,j)*(t0 +t_1(i,k,j))) -(muts(i,j)*(g_t_1(i,k,j)) +g_muts(i,j) &
895 *(t0 +t_1(i,k,j)))*alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j)))/((muts(i,j) &
896 *(t0 +t_1(i,k,j)))*(muts(i,j)*(t0 +t_1(i,k,j)))) -g_al(i,k,j)) +g_c2a(i,k,j) &
897 *(alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j))/(muts(i,j)*(t0 +t_1(i,k,j))) -al(i,k,j))
898 p(i,k,j) =c2a(i,k,j)*(alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j))/(muts(i,j) &
899 *(t0 +t_1(i,k,j))) -al(i,k,j))
911 g_p(i,k,j) =g_mu(i,j)*znu(k)
912 p(i,k,j) =mu(i,j)*znu(k)
914 g_al(i,k,j) =((alt(i,k,j)*(g_t_2(i,k,j) -(mu(i,j)*g_t_1(i,k,j) +g_mu(i,j) &
915 *t_1(i,k,j))) +g_alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j)))*(muts(i,j) &
916 *(t0 +t_1(i,k,j))) -(muts(i,j)*(g_t_1(i,k,j)) +g_muts(i,j)*(t0 +t_1(i,k,j))) &
917 *alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j)))/((muts(i,j)*(t0 +t_1(i,k,j))) &
918 *(muts(i,j)*(t0 +t_1(i,k,j)))) -((g_p(i,k,j)*c2a(i,k,j) -g_c2a(i,k,j)*p(i,k,j)) &
919 /(c2a(i,k,j)*c2a(i,k,j)))
920 al(i,k,j) =alt(i,k,j)*(t_2(i,k,j) -mu(i,j)*t_1(i,k,j))/(muts(i,j)*(t0 +t_1(i,k,j))) &
923 g_ph(i,k+1,j) =g_ph(i,k,j) -dnw(k)*(muts(i,j)*g_al(i,k,j) +g_muts(i,j) &
924 *al(i,k,j) +(mu(i,j)*g_alt(i,k,j) +g_mu(i,j)*alt(i,k,j)))
925 ph(i,k+1,j) =ph(i,k,j) -dnw(k)*(muts(i,j)*al(i,k,j) +mu(i,j)*alt(i,k,j))
938 g_pm1(i,k,j) =g_p(i,k,j)
954 g_p(i,k,j) =g_p(i,k,j) +smdiv*(g_p(i,k,j) -g_pm1(i,k,j))
955 p(i,k,j) =p(i,k,j) +smdiv*(p(i,k,j) -pm1(i,k,j))
965 END SUBROUTINE g_calc_p_rho
967 SUBROUTINE g_calc_coef_w(a,g_a,alpha,g_alpha,gamma,g_gamma,mut,g_mut, &
968 cqw,g_cqw,rdn,rdnw,c2a,g_c2a,dts,g,epssm,top_lid,ids,ide,jds,jde,kds,kde,ims, &
969 ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
972 INTEGER,INTENT(IN) :: ids,ide,jds,jde,kds,kde
973 INTEGER,INTENT(IN) :: ims,ime,jms,jme,kms,kme
974 INTEGER,INTENT(IN) :: its,ite,jts,jte,kts,kte
975 LOGICAL,INTENT(IN) :: top_lid
976 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(IN) :: g_c2a,c2a,g_cqw,cqw
977 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_alpha,alpha,g_gamma, &
979 REAL,DIMENSION(ims:ime,jms:jme),INTENT(IN) :: g_mut,mut
980 REAL,DIMENSION(kms:kme),INTENT(IN) :: rdn,rdnw
981 REAL,INTENT(IN) :: epssm,dts,g
982 REAL,DIMENSION(ims:ime) :: g_cof,cof
984 INTEGER :: i,j,k,i_start,i_end,j_start,j_end,k_start,k_end
985 INTEGER :: ij,ijp,ijm,lid_flag
989 i_end =min(ite,ide-1)
993 j_end =min(jte,jde-1)
1001 IF(top_lid) lid_flag =0
1006 g_cof(i) =2.0*(-.5 *dts *g *(1.+epssm)*g_mut(i,j)/(mut(i,j)*mut(i,j))) &
1007 *(.5 *dts *g *(1.+epssm)/mut(i,j))
1008 cof(i) =(.5 *dts *g *(1.+epssm)/mut(i,j))**2
1013 g_a(i,kde,j) =(-2.*cof(i)*rdnw(kde-1)**2*g_c2a(i,kde-1,j) +(-2.)*g_cof(i) &
1014 *rdnw(kde-1)**2*c2a(i,kde-1,j))*lid_flag
1015 a(i,kde,j) =-2.*cof(i)*rdnw(kde-1)**2*c2a(i,kde-1,j)*lid_flag
1025 g_a(i,k,j) =-cqw(i,k,j)*cof(i)*rdn(k)*rdnw(k-1)*g_c2a(i,k-1,j) +(-cqw(i,k,j) &
1026 *g_cof(i) -g_cqw(i,k,j)*cof(i))*rdn(k)*rdnw(k-1)*c2a(i,k-1,j)
1027 a(i,k,j) =-cqw(i,k,j)*cof(i)*rdn(k)*rdnw(k-1)*c2a(i,k-1,j)
1035 g_b =cqw(i,k,j)*cof(i)*rdn(k)*(rdnw(k)*g_c2a(i,k,j) +rdnw(k-1)*g_c2a(i,k-1, &
1036 j)) +(cqw(i,k,j)*g_cof(i) +g_cqw(i,k,j)*cof(i))*rdn(k)*(rdnw(k)*c2a(i,k,j) &
1037 +rdnw(k-1)*c2a(i,k-1,j))
1038 b =1. +cqw(i,k,j)*cof(i)*rdn(k)*(rdnw(k)*c2a(i,k,j) +rdnw(k-1)*c2a(i,k-1,j))
1040 g_c =-cqw(i,k,j)*cof(i)*rdn(k)*rdnw(k)*g_c2a(i,k,j) +(-cqw(i,k,j)*g_cof(i) &
1041 -g_cqw(i,k,j)*cof(i))*rdn(k)*rdnw(k)*c2a(i,k,j)
1042 c =-cqw(i,k,j)*cof(i)*rdn(k)*rdnw(k)*c2a(i,k,j)
1044 g_alpha(i,k,j) =-1.*(g_b -(a(i,k,j)*g_gamma(i,k-1,j) +g_a(i,k,j) &
1045 *gamma(i,k-1,j)))/((b -a(i,k,j)*gamma(i,k-1,j))*(b -a(i,k,j)*gamma(i,k-1,j)))
1046 alpha(i,k,j) =1./(b -a(i,k,j)*gamma(i,k-1,j))
1048 g_gamma(i,k,j) =c*g_alpha(i,k,j) +g_c*alpha(i,k,j)
1049 gamma(i,k,j) =c*alpha(i,k,j)
1056 g_b =2.*cof(i)*rdnw(kde-1)**2*g_c2a(i,kde-1,j) +2.*g_cof(i)*rdnw(kde-1) &
1058 b =1. +2.*cof(i)*rdnw(kde-1)**2*c2a(i,kde-1,j)
1063 g_alpha(i,kde,j) =-1.*(g_b -(a(i,kde,j)*g_gamma(i,kde-1,j) +g_a(i,kde,j) &
1064 *gamma(i,kde-1,j)))/((b -a(i,kde,j)*gamma(i,kde-1,j))*(b -a(i,kde,j)*gamma(i,kde-1,j)))
1065 alpha(i,kde,j) =1./(b -a(i,kde,j)*gamma(i,kde-1,j))
1067 g_gamma(i,kde,j) =c*g_alpha(i,kde,j) +g_c*alpha(i,kde,j)
1068 gamma(i,kde,j) =c*alpha(i,kde,j)
1073 END SUBROUTINE g_calc_coef_w
1075 ! Generated by TAPENADE (INRIA, Tropics team)
1076 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
1078 ! Differentiation of advance_uv in forward (tangent) mode:
1079 ! variations of useful results: u v
1080 ! with respect to varying inputs: p al u v ru_tend mudf cqu cqv
1081 ! php rv_tend ph alt muu muv mu
1082 ! RW status of diff variables: p:in al:in u:in-out v:in-out ru_tend:in
1083 ! mudf:in cqu:in cqv:in php:in rv_tend:in ph:in
1084 ! alt:in muu:in muv:in mu:in
1085 SUBROUTINE G_ADVANCE_UV(u, ud, ru_tend, ru_tendd, v, vd, rv_tend, &
1086 & rv_tendd, p, pd, pb, ph, phd, php, phpd, alt, altd, al, ald, mu, mud, &
1087 & muu, muud, cqu, cqud, muv, muvd, cqv, cqvd, mudf, mudfd, msfux, msfuy&
1088 & , msfvx, msfvx_inv, msfvy, rdx, rdy, dts, cf1, cf2, cf3, fnm, fnp, &
1089 & emdiv, rdnw, config_flags, spec_zone, non_hydrostatic, top_lid, ids, &
1090 & ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, &
1095 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
1096 LOGICAL, INTENT(IN) :: non_hydrostatic, top_lid
1097 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde
1098 INTEGER, INTENT(IN) :: ims, ime, jms, jme, kms, kme
1099 INTEGER, INTENT(IN) :: its, ite, jts, jte, kts, kte
1100 INTEGER, INTENT(IN) :: spec_zone
1101 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: u, v
1102 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: ud, vd
1103 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ru_tend, &
1104 & rv_tend, ph, php, p, pb, alt, al, cqu, cqv
1105 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: ru_tendd, &
1106 & rv_tendd, phd, phpd, pd, altd, ald, cqud, cqvd
1107 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: muu, muv, mu, mudf
1108 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: muud, muvd, mud, &
1110 REAL, DIMENSION(kms:kme), INTENT(IN) :: fnm, fnp, rdnw
1111 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: msfux, msfuy, msfvx, &
1113 REAL, INTENT(IN) :: rdx, rdy, dts, cf1, cf2, cf3, emdiv
1114 ! Local 3d array from the stack (note tile size)
1115 REAL, DIMENSION(its:ite, kts:kte) :: dpn, dpxy
1116 REAL, DIMENSION(its:ite, kts:kte) :: dpnd, dpxyd
1117 REAL, DIMENSION(its:ite) :: mudf_xy
1118 REAL, DIMENSION(its:ite) :: mudf_xyd
1120 INTEGER :: i, j, k, i_start, i_end, j_start, j_end, k_start, k_end
1121 INTEGER :: i_endu, j_endv, k_endw
1122 INTEGER :: i_start_up, i_end_up, j_start_up, j_end_up
1123 INTEGER :: i_start_vp, i_end_vp, j_start_vp, j_end_vp
1124 INTEGER :: i_start_u_tend, i_end_u_tend, j_start_v_tend, j_end_v_tend
1127 ! advance_uv advances the explicit perturbation horizontal momentum
1128 ! equations (u,v) by adding in the large-timestep tendency along with
1129 ! the small timestep pressure gradient tendency.
1132 ! now, the real work.
1133 ! set the loop bounds taking into account boundary conditions.
1134 IF (config_flags%nested .OR. config_flags%specified) THEN
1135 IF (its .LT. ids + spec_zone) THEN
1136 i_start = ids + spec_zone
1140 IF (ite .GT. ide - spec_zone - 1) THEN
1141 i_end = ide - spec_zone - 1
1145 IF (jts .LT. jds + spec_zone) THEN
1146 j_start = jds + spec_zone
1150 IF (jte .GT. jde - spec_zone - 1) THEN
1151 j_end = jde - spec_zone - 1
1156 IF (kte .GT. kde - 1) THEN
1161 IF (ite .GT. ide - spec_zone) THEN
1162 i_endu = ide - spec_zone
1166 IF (jte .GT. jde - spec_zone) THEN
1167 j_endv = jde - spec_zone
1172 IF (config_flags%periodic_x) THEN
1174 IF (ite .GT. ide - 1) THEN
1183 IF (ite .GT. ide - 1) THEN
1189 IF (jte .GT. jde - 1) THEN
1200 i_start_up = i_start
1202 j_start_up = j_start
1204 i_start_vp = i_start
1206 j_start_vp = j_start
1208 IF ((config_flags%open_xs .OR. config_flags%symmetric_xs) .AND. its &
1209 & .EQ. ids) i_start_up = i_start_up + 1
1210 IF ((config_flags%open_xe .OR. config_flags%symmetric_xe) .AND. ite &
1211 & .EQ. ide) i_end_up = i_end_up - 1
1212 IF (((config_flags%open_ys .OR. config_flags%symmetric_ys) .OR. &
1213 & config_flags%polar) .AND. jts .EQ. jds) j_start_vp = j_start_vp + &
1215 IF (((config_flags%open_ye .OR. config_flags%symmetric_ye) .OR. &
1216 & config_flags%polar) .AND. jte .EQ. jde) j_end_vp = j_end_vp - 1
1217 i_start_u_tend = i_start
1218 i_end_u_tend = i_endu
1219 j_start_v_tend = j_start
1220 j_end_v_tend = j_endv
1221 IF (config_flags%symmetric_xs .AND. its .EQ. ids) i_start_u_tend = &
1222 & i_start_u_tend + 1
1223 IF (config_flags%symmetric_xe .AND. ite .EQ. ide) i_end_u_tend = &
1225 IF (config_flags%symmetric_ys .AND. jts .EQ. jds) j_start_v_tend = &
1226 & j_start_v_tend + 1
1227 IF (config_flags%symmetric_ye .AND. jte .EQ. jde) j_end_v_tend = &
1234 ! start real calculations.
1236 u_outer_j_loop:DO j=j_start,j_end
1238 DO i=i_start_u_tend,i_end_u_tend
1239 ud(i, k, j) = ud(i, k, j) + dts*ru_tendd(i, k, j)
1240 u(i, k, j) = u(i, k, j) + dts*ru_tend(i, k, j)
1243 DO i=i_start_up,i_end_up
1244 mudf_xyd(i) = -(emdiv*dx*(mudfd(i, j)-mudfd(i-1, j))/msfuy(i, j))
1245 mudf_xy(i) = -(emdiv*dx*(mudf(i, j)-mudf(i-1, j))/msfuy(i, j))
1248 DO i=i_start_up,i_end_up
1249 ! Comments on map scale factors:
1250 ! x pressure gradient: ADT eqn 44, penultimate term on RHS
1251 ! = -(mx/my)*(mu/rho)*partial dp/dx
1252 ! [i.e., first rho->mu; 2nd still rho; alpha=1/rho]
1253 ! Klemp et al. splits into 2 terms:
1254 ! mu alpha partial dp/dx + partial dp/dnu * partial dphi/dx
1255 ! then into 4 terms:
1256 ! mu alpha partial dp'/dx + nu mu alpha' partial dmubar/dx +
1257 ! + mu partial dphi/dx + partial dphi'/dx * (partial dp'/dnu - mu')
1260 ! ph, alt, p, al, pb not coupled
1261 ! since we want tendency to fit ADT eqn 44 (coupled) we need to
1262 ! multiply by (mx/my):
1264 dpxyd(i, k) = msfux(i, j)*.5*rdx*(muud(i, j)*(ph(i, k+1, j)-ph(i&
1265 & -1, k+1, j)+(ph(i, k, j)-ph(i-1, k, j))+(alt(i, k, j)+alt(i-1&
1266 & , k, j))*(p(i, k, j)-p(i-1, k, j))+(al(i, k, j)+al(i-1, k, j))&
1267 & *(pb(i, k, j)-pb(i-1, k, j)))+muu(i, j)*(phd(i, k+1, j)-phd(i-&
1268 & 1, k+1, j)+phd(i, k, j)-phd(i-1, k, j)+(altd(i, k, j)+altd(i-1&
1269 & , k, j))*(p(i, k, j)-p(i-1, k, j))+(alt(i, k, j)+alt(i-1, k, j&
1270 & ))*(pd(i, k, j)-pd(i-1, k, j))+(pb(i, k, j)-pb(i-1, k, j))*(&
1271 & ald(i, k, j)+ald(i-1, k, j))))/msfuy(i, j)
1272 dpxy(i, k) = msfux(i, j)/msfuy(i, j)*.5*rdx*muu(i, j)*(ph(i, k+1&
1273 & , j)-ph(i-1, k+1, j)+(ph(i, k, j)-ph(i-1, k, j))+(alt(i, k, j)&
1274 & +alt(i-1, k, j))*(p(i, k, j)-p(i-1, k, j))+(al(i, k, j)+al(i-1&
1275 & , k, j))*(pb(i, k, j)-pb(i-1, k, j)))
1278 IF (non_hydrostatic) THEN
1279 DO i=i_start_up,i_end_up
1280 dpnd(i, 1) = .5*(cf1*(pd(i, 1, j)+pd(i-1, 1, j))+cf2*(pd(i, 2, j&
1281 & )+pd(i-1, 2, j))+cf3*(pd(i, 3, j)+pd(i-1, 3, j)))
1282 dpn(i, 1) = .5*(cf1*(p(i, 1, j)+p(i-1, 1, j))+cf2*(p(i, 2, j)+p(&
1283 & i-1, 2, j))+cf3*(p(i, 3, j)+p(i-1, 3, j)))
1288 DO i=i_start_up,i_end_up
1289 dpnd(i, kde) = .5*(cf1*(pd(i-1, kde-1, j)+pd(i, kde-1, j))+cf2&
1290 & *(pd(i-1, kde-2, j)+pd(i, kde-2, j))+cf3*(pd(i-1, kde-3, j)+&
1292 dpn(i, kde) = .5*(cf1*(p(i-1, kde-1, j)+p(i, kde-1, j))+cf2*(p&
1293 & (i-1, kde-2, j)+p(i, kde-2, j))+cf3*(p(i-1, kde-3, j)+p(i, &
1297 DO k=k_start+1,k_end
1298 DO i=i_start_up,i_end_up
1299 dpnd(i, k) = .5*(fnm(k)*(pd(i, k, j)+pd(i-1, k, j))+fnp(k)*(pd&
1300 & (i, k-1, j)+pd(i-1, k-1, j)))
1301 dpn(i, k) = .5*(fnm(k)*(p(i, k, j)+p(i-1, k, j))+fnp(k)*(p(i, &
1302 & k-1, j)+p(i-1, k-1, j)))
1305 ! Comments on map scale factors:
1307 ! php, dpn, mu not coupled
1308 ! since we want tendency to fit ADT eqn 44 (coupled) we need to
1309 ! multiply by (mx/my):
1311 DO i=i_start_up,i_end_up
1312 dpxyd(i, k) = dpxyd(i, k) + msfux(i, j)*rdx*((phpd(i, k, j)-&
1313 & phpd(i-1, k, j))*(rdnw(k)*(dpn(i, k+1)-dpn(i, k))-.5*(mu(i-1&
1314 & , j)+mu(i, j)))+(php(i, k, j)-php(i-1, k, j))*(rdnw(k)*(dpnd&
1315 & (i, k+1)-dpnd(i, k))-.5*(mud(i-1, j)+mud(i, j))))/msfuy(i, j&
1317 dpxy(i, k) = dpxy(i, k) + msfux(i, j)/msfuy(i, j)*rdx*(php(i, &
1318 & k, j)-php(i-1, k, j))*(rdnw(k)*(dpn(i, k+1)-dpn(i, k))-.5*(&
1319 & mu(i-1, j)+mu(i, j)))
1324 DO i=i_start_up,i_end_up
1325 ud(i, k, j) = ud(i, k, j) - dts*(cqud(i, k, j)*dpxy(i, k)+cqu(i&
1326 & , k, j)*dpxyd(i, k)) + mudf_xyd(i)
1327 u(i, k, j) = u(i, k, j) - dts*cqu(i, k, j)*dpxy(i, k) + mudf_xy(&
1331 END DO u_outer_j_loop
1333 v_outer_j_loop:DO j=j_start_v_tend,j_end_v_tend
1336 vd(i, k, j) = vd(i, k, j) + dts*rv_tendd(i, k, j)
1337 v(i, k, j) = v(i, k, j) + dts*rv_tend(i, k, j)
1341 mudf_xyd(i) = -(emdiv*dy*msfvx_inv(i, j)*(mudfd(i, j)-mudfd(i, j-1&
1343 mudf_xy(i) = -(emdiv*dy*(mudf(i, j)-mudf(i, j-1))*msfvx_inv(i, j))
1345 IF (j .GE. j_start_vp .AND. j .LE. j_end_vp) THEN
1348 ! Comments on map scale factors:
1349 ! y pressure gradient: ADT eqn 45, penultimate term on RHS
1350 ! = -(my/mx)*(mu/rho)*partial dp/dy
1351 ! [i.e., first rho->mu; 2nd still rho; alpha=1/rho]
1352 ! Klemp et al. splits into 2 terms:
1353 ! mu alpha partial dp/dy + partial dp/dnu * partial dphi/dy
1354 ! then into 4 terms:
1355 ! mu alpha partial dp'/dy + nu mu alpha' partial dmubar/dy +
1356 ! + mu partial dphi/dy + partial dphi'/dy * (partial dp'/dnu - mu')
1359 ! ph, alt, p, al, pb not coupled
1360 ! since we want tendency to fit ADT eqn 45 (coupled) we need to
1361 ! multiply by (my/mx):
1362 ! mudf_xy is NOT a map scale factor coupling
1363 ! it is some sort of divergence damping
1364 dpxyd(i, k) = msfvy(i, j)*.5*rdy*(muvd(i, j)*(ph(i, k+1, j)-ph&
1365 & (i, k+1, j-1)+(ph(i, k, j)-ph(i, k, j-1))+(alt(i, k, j)+alt(&
1366 & i, k, j-1))*(p(i, k, j)-p(i, k, j-1))+(al(i, k, j)+al(i, k, &
1367 & j-1))*(pb(i, k, j)-pb(i, k, j-1)))+muv(i, j)*(phd(i, k+1, j)&
1368 & -phd(i, k+1, j-1)+phd(i, k, j)-phd(i, k, j-1)+(altd(i, k, j)&
1369 & +altd(i, k, j-1))*(p(i, k, j)-p(i, k, j-1))+(alt(i, k, j)+&
1370 & alt(i, k, j-1))*(pd(i, k, j)-pd(i, k, j-1))+(pb(i, k, j)-pb(&
1371 & i, k, j-1))*(ald(i, k, j)+ald(i, k, j-1))))/msfvx(i, j)
1372 dpxy(i, k) = msfvy(i, j)/msfvx(i, j)*.5*rdy*muv(i, j)*(ph(i, k&
1373 & +1, j)-ph(i, k+1, j-1)+(ph(i, k, j)-ph(i, k, j-1))+(alt(i, k&
1374 & , j)+alt(i, k, j-1))*(p(i, k, j)-p(i, k, j-1))+(al(i, k, j)+&
1375 & al(i, k, j-1))*(pb(i, k, j)-pb(i, k, j-1)))
1378 IF (non_hydrostatic) THEN
1380 dpnd(i, 1) = .5*(cf1*(pd(i, 1, j)+pd(i, 1, j-1))+cf2*(pd(i, 2&
1381 & , j)+pd(i, 2, j-1))+cf3*(pd(i, 3, j)+pd(i, 3, j-1)))
1382 dpn(i, 1) = .5*(cf1*(p(i, 1, j)+p(i, 1, j-1))+cf2*(p(i, 2, j)+&
1383 & p(i, 2, j-1))+cf3*(p(i, 3, j)+p(i, 3, j-1)))
1389 dpnd(i, kde) = .5*(cf1*(pd(i, kde-1, j-1)+pd(i, kde-1, j))+&
1390 & cf2*(pd(i, kde-2, j-1)+pd(i, kde-2, j))+cf3*(pd(i, kde-3, &
1391 & j-1)+pd(i, kde-3, j)))
1392 dpn(i, kde) = .5*(cf1*(p(i, kde-1, j-1)+p(i, kde-1, j))+cf2*&
1393 & (p(i, kde-2, j-1)+p(i, kde-2, j))+cf3*(p(i, kde-3, j-1)+p(&
1397 DO k=k_start+1,k_end
1399 dpnd(i, k) = .5*(fnm(k)*(pd(i, k, j)+pd(i, k, j-1))+fnp(k)*(&
1400 & pd(i, k-1, j)+pd(i, k-1, j-1)))
1401 dpn(i, k) = .5*(fnm(k)*(p(i, k, j)+p(i, k, j-1))+fnp(k)*(p(i&
1402 & , k-1, j)+p(i, k-1, j-1)))
1405 ! Comments on map scale factors:
1407 ! php, dpn, mu not coupled
1408 ! since we want tendency to fit ADT eqn 45 (coupled) we need to
1409 ! multiply by (my/mx):
1412 dpxyd(i, k) = dpxyd(i, k) + msfvy(i, j)*rdy*((phpd(i, k, j)-&
1413 & phpd(i, k, j-1))*(rdnw(k)*(dpn(i, k+1)-dpn(i, k))-.5*(mu(i&
1414 & , j-1)+mu(i, j)))+(php(i, k, j)-php(i, k, j-1))*(rdnw(k)*(&
1415 & dpnd(i, k+1)-dpnd(i, k))-.5*(mud(i, j-1)+mud(i, j))))/&
1417 dpxy(i, k) = dpxy(i, k) + msfvy(i, j)/msfvx(i, j)*rdy*(php(i&
1418 & , k, j)-php(i, k, j-1))*(rdnw(k)*(dpn(i, k+1)-dpn(i, k))-&
1419 & .5*(mu(i, j-1)+mu(i, j)))
1425 vd(i, k, j) = vd(i, k, j) - dts*(cqvd(i, k, j)*dpxy(i, k)+cqv(&
1426 & i, k, j)*dpxyd(i, k)) + mudf_xyd(i)
1427 v(i, k, j) = v(i, k, j) - dts*cqv(i, k, j)*dpxy(i, k) + &
1432 END DO v_outer_j_loop
1433 ! The check for j_start_vp and j_end_vp makes sure that the edges in v
1434 ! are not updated. Let's add a polar boundary condition check here for
1435 ! safety to ensure that v at the poles never gets to be non-zero in the
1437 IF (config_flags%polar) THEN
1438 IF (jts .EQ. jds) THEN
1446 IF (jte .EQ. jde) THEN
1455 END SUBROUTINE G_ADVANCE_UV
1457 SUBROUTINE g_advance_mu_t(ww,g_ww,ww_1,g_ww_1,u,g_u,u_1,g_u_1,v, &
1458 g_v,v_1,g_v_1,mu,g_mu,mut,g_mut,muave,g_muave,muts,g_muts,muu,g_muu, &
1459 muv,g_muv,mudf,g_mudf,uam,g_uam,vam,g_vam,wwam,g_wwam,t,g_t, &
1460 t_1,g_t_1,t_ave,g_t_ave,ft,g_ft,mu_tend,g_mu_tend,rdx,rdy,dts,epssm,dnw, &
1461 fnm,fnp,rdnw,msfux,msfuy,msfvx,msfvx_inv,msfvy,msftx,msfty,step,config_flags,ids,ide, &
1462 jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1465 TYPE(grid_config_rec_type),INTENT(IN) :: config_flags
1466 INTEGER,INTENT(IN) :: ids,ide,jds,jde,kds,kde
1467 INTEGER,INTENT(IN) :: ims,ime,jms,jme,kms,kme
1468 INTEGER,INTENT(IN) :: its,ite,jts,jte,kts,kte
1469 INTEGER,INTENT(IN) :: step
1470 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(IN) :: g_u,u,g_v,v,g_u_1,u_1, &
1471 g_v_1,v_1,g_t_1,t_1,g_ft,ft
1472 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_ww,ww,g_ww_1,ww_1, &
1473 g_t,t,g_t_ave,t_ave,g_uam,uam,g_vam,vam,g_wwam,wwam
1474 REAL,DIMENSION(ims:ime,jms:jme),INTENT(IN) :: g_muu,muu,g_muv,muv,g_mut,mut, &
1475 msfux,msfuy,msfvx,msfvx_inv,msfvy,msftx,msfty,g_mu_tend,mu_tend
1476 REAL,DIMENSION(ims:ime,jms:jme),INTENT(OUT) :: g_muave,muave,g_muts,muts,g_mudf,mudf
1477 REAL,DIMENSION(ims:ime,jms:jme),INTENT(INOUT) :: g_mu,mu
1478 REAL,DIMENSION(kms:kme),INTENT(IN) :: fnm,fnp,dnw,rdnw
1479 REAL,INTENT(IN) :: rdx,rdy,dts,epssm
1480 REAL,DIMENSION(its:ite,kts:kte) :: g_wdtn,wdtn,g_dvdxi,dvdxi
1481 REAL,DIMENSION(its:ite) :: g_dmdt,dmdt
1482 INTEGER :: i,j,k,i_start,i_end,j_start,j_end,k_start,k_end
1483 INTEGER :: i_endu,j_endv
1488 i_end =min(ite,ide-1)
1492 j_end =min(jte,jde-1)
1498 IF( .NOT. config_flags%periodic_x ) THEN
1500 IF( config_flags%specified .or. config_flags%nested ) THEN
1502 i_start =max(its,ids+1)
1504 i_end =min(ite,ide-2)
1508 IF( config_flags%specified .or. config_flags%nested ) THEN
1510 j_start =max(jts,jds+1)
1512 j_end =min(jte,jde-2)
1530 g_dvdxi(i,k) =msftx(i,j) *msfty(i,j)*(rdy*((g_v(i,k,j+1) +(muv(i,j+1) &
1531 *g_v_1(i,k,j+1) +g_muv(i,j+1)*v_1(i,k,j+1))*msfvx_inv(i,j+1)) -(g_v(i,k,j) &
1532 +(muv(i,j)*g_v_1(i,k,j) +g_muv(i,j)*v_1(i,k,j))*msfvx_inv(i,j))) &
1533 +rdx*((g_u(i+1,k,j) +((muu(i+1,j)*g_u_1(i+1,k,j) +g_muu(i+1,j) &
1534 *u_1(i+1,k,j))/msfuy(i+1,j))) -(g_u(i,k,j) +((muu(i,j)*g_u_1(i,k,j) &
1535 +g_muu(i,j)*u_1(i,k,j))/msfuy(i,j)))))
1536 dvdxi(i,k) =msftx(i,j) *msfty(i,j)*(rdy*((v(i,k,j+1) +muv(i,j+1)*v_1(i,k,j+1) &
1537 *msfvx_inv(i,j+1)) -(v(i,k,j) +muv(i,j)*v_1(i,k,j)*msfvx_inv(i,j))) +rdx*((u(i+1,k,j) &
1538 +muu(i+1,j)*u_1(i+1,k,j)/msfuy(i+1,j)) -(u(i,k,j) +muu(i,j)*u_1(i,k,j)/msfuy(i,j))))
1540 g_dmdt(i) =g_dmdt(i) +dnw(k)*g_dvdxi(i,k)
1541 dmdt(i) =dmdt(i) +dnw(k)*dvdxi(i,k)
1548 g_muave(i,j) =g_mu(i,j)
1551 g_mu(i,j) =g_mu(i,j) +dts*(g_dmdt(i) +g_mu_tend(i,j))
1552 mu(i,j) =mu(i,j) +dts*(dmdt(i) +mu_tend(i,j))
1554 g_mudf(i,j) =(g_dmdt(i) +g_mu_tend(i,j))
1555 mudf(i,j) =(dmdt(i) +mu_tend(i,j))
1557 g_muts(i,j) =g_mut(i,j) +g_mu(i,j)
1558 muts(i,j) =mut(i,j) +mu(i,j)
1560 g_muave(i,j) =.5*((1.+epssm)*g_mu(i,j) +(1.-epssm)*g_muave(i,j))
1561 muave(i,j) =.5*((1.+epssm)*mu(i,j) +(1.-epssm)*muave(i,j))
1568 g_ww(i,k,j) =g_ww(i,k-1,j) -(dnw(k-1)*(g_dmdt(i) +g_dvdxi(i,k-1) &
1569 +g_mu_tend(i,j))/msfty(i,j))
1570 ww(i,k,j) =ww(i,k-1,j) -dnw(k-1)*(dmdt(i) +dvdxi(i,k-1) +mu_tend(i,j))/msfty(i,j)
1578 g_ww(i,k,j) =g_ww(i,k,j) -g_ww_1(i,k,j)
1579 ww(i,k,j) =ww(i,k,j) -ww_1(i,k,j)
1589 g_t_ave(i,k,j) =g_t(i,k,j)
1590 t_ave(i,k,j) =t(i,k,j)
1592 g_t(i,k,j) =g_t(i,k,j) +msfty(i,j) *dts*g_ft(i,k,j)
1593 t(i,k,j) =t(i,k,j) +msfty(i,j) *dts*ft(i,k,j)
1613 g_wdtn(i,k) =ww(i,k,j)*(fnm(k)*g_t_1(i,k,j) +fnp(k)*g_t_1(i,k-1,j)) &
1614 +g_ww(i,k,j)*(fnm(k)*t_1(i,k,j) +fnp(k)*t_1(i,k-1,j))
1615 wdtn(i,k) =ww(i,k,j)*(fnm(k)*t_1(i,k,j) +fnp(k)*t_1(i,k-1,j))
1623 g_t(i,k,j) =g_t(i,k,j) -dts *msfty(i,j)*(msftx(i,j)*(.5 *rdy*(v(i,k,j+1) &
1624 *(g_t_1(i,k,j+1) +g_t_1(i,k,j)) +g_v(i,k,j+1)*(t_1(i,k,j+1) +t_1(i,k,j)) &
1625 -(v(i,k,j)*(g_t_1(i,k,j) +g_t_1(i,k,j-1)) +g_v(i,k,j)*(t_1(i,k,j) &
1626 +t_1(i,k,j-1)))) +.5 *rdx*(u(i+1,k,j)*(g_t_1(i+1,k,j) +g_t_1(i,k,j)) &
1627 +g_u(i+1,k,j)*(t_1(i+1,k,j) +t_1(i,k,j)) -(u(i,k,j)*(g_t_1(i,k,j) &
1628 +g_t_1(i-1,k,j)) +g_u(i,k,j)*(t_1(i,k,j) +t_1(i-1,k,j))))) +rdnw(k) &
1629 *(g_wdtn(i,k+1) -g_wdtn(i,k)))
1630 t(i,k,j) =t(i,k,j) -dts *msfty(i,j)*(msftx(i,j)*(.5 *rdy*(v(i,k,j+1)*(t_1(i,k,j+1) &
1631 +t_1(i,k,j)) -v(i,k,j)*(t_1(i,k,j) +t_1(i,k,j-1))) +.5 *rdx*(u(i+1,k,j) &
1632 *(t_1(i+1,k,j) +t_1(i,k,j)) -u(i,k,j)*(t_1(i,k,j) +t_1(i-1,k,j)))) +rdnw(k) &
1633 *(wdtn(i,k+1) -wdtn(i,k)))
1639 END SUBROUTINE g_advance_mu_t
1641 ! Generated by TAPENADE (INRIA, Tropics team)
1642 ! Tapenade 3.5 (r3785) - 22 Mar 2011 18:35
1644 ! Differentiation of advance_w in forward (tangent) mode:
1645 ! variations of useful results: w t_2ave ph
1646 ! with respect to varying inputs: ww w_save muave gamma u alpha
1647 ! v w rw_tend ph_1 t_2ave cqw muts t_1 t_2 ph alt
1649 ! RW status of diff variables: ww:in w_save:in muave:in gamma:in
1650 ! u:in alpha:in v:in w:in-out rw_tend:in ph_1:in
1651 ! t_2ave:in-out cqw:in muts:in t_1:in t_2:in ph:in-out
1652 ! alt:in c2a:in mut:in ph_tend:in a:in
1655 SUBROUTINE G_ADVANCE_W(w, wd, rw_tend, rw_tendd, ww, wwd, w_save, &
1656 & w_saved, u, ud, v, vd, mu1, mut, mutd, muave, muaved, muts, mutsd, &
1657 & t_2ave, t_2aved, t_2, t_2d, t_1, t_1d, ph, phd, ph_1, ph_1d, phb, &
1658 & ph_tend, ph_tendd, ht, c2a, c2ad, cqw, cqwd, alt, altd, alb, a, ad, &
1659 & alpha, alphad, gamma, gammad, rdx, rdy, dts, t0, epssm, dnw, fnm, fnp&
1660 & , rdnw, rdn, cf1, cf2, cf3, msftx, msfty, config_flags, top_lid, ids, &
1661 & ide, jds, jde, kds, kde, ims, ime, jms, jme, kms, kme, its, ite, jts, &
1666 TYPE(GRID_CONFIG_REC_TYPE), INTENT(IN) :: config_flags
1667 INTEGER, INTENT(IN) :: ids, ide, jds, jde, kds, kde
1668 INTEGER, INTENT(IN) :: ims, ime, jms, jme, kms, kme
1669 INTEGER, INTENT(IN) :: its, ite, jts, jte, kts, kte
1670 LOGICAL, INTENT(IN) :: top_lid
1671 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: t_2ave, w&
1673 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(INOUT) :: t_2aved, &
1675 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rw_tend, ww&
1676 & , w_save, u, v, t_2, t_1, ph_1, phb, ph_tend, alpha, gamma, a, c2a, &
1678 REAL, DIMENSION(ims:ime, kms:kme, jms:jme), INTENT(IN) :: rw_tendd, &
1679 & wwd, w_saved, ud, vd, t_2d, t_1d, ph_1d, ph_tendd, alphad, gammad, ad&
1680 & , c2ad, cqwd, altd
1681 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mu1, mut, muave, muts&
1682 & , ht, msftx, msfty
1683 REAL, DIMENSION(ims:ime, jms:jme), INTENT(IN) :: mutd, muaved, mutsd
1684 REAL, DIMENSION(kms:kme), INTENT(IN) :: fnp, fnm, rdnw, rdn, dnw
1685 REAL, INTENT(IN) :: rdx, rdy, dts, cf1, cf2, cf3, t0, epssm
1686 ! Stack based 3d data, tile size.
1687 REAL, DIMENSION(its:ite) :: mut_inv, msft_inv
1688 REAL, DIMENSION(its:ite) :: mut_invd, msft_invd
1689 REAL, DIMENSION(its:ite, kts:kte) :: rhs, wdwn
1690 REAL, DIMENSION(its:ite, kts:kte) :: rhsd, wdwnd
1691 INTEGER :: i, j, k, i_start, i_end, j_start, j_end, k_start, k_end
1692 REAL, DIMENSION(kts:kte) :: dampwt
1693 REAL, DIMENSION(kts:kte) :: dampwtd
1694 REAL :: htop, hbot, hdepth, hk
1695 REAL :: htopd, hbotd, hkd
1703 ! advance_w advances the implicit w and geopotential equations.
1707 ! Currently set for periodic boundary conditions
1709 IF (ite .GT. ide - 1) THEN
1715 IF (jte .GT. jde - 1) THEN
1722 IF (.NOT.config_flags%periodic_x) THEN
1723 IF (config_flags%specified .OR. config_flags%nested) THEN
1724 IF (its .LT. ids + 1) THEN
1729 IF (ite .GT. ide - 2) THEN
1736 IF (config_flags%specified .OR. config_flags%nested) THEN
1737 IF (jts .LT. jds + 1) THEN
1742 IF (jte .GT. jde - 2) THEN
1749 dampmag = dts*config_flags%dampcoef
1750 hdepth = config_flags%zdamp
1751 ! calculation of phi and w equations
1752 ! Comments on map scale factors:
1754 ! partial d/dt(rho phi/my) = -mx partial d/dx(phi rho u/my)
1755 ! -mx partial d/dy(phi rho v/mx)
1756 ! - partial d/dz(phi rho w/my) + rho g w/my
1757 ! as with scalar equation, use uncoupled value (here phi) to find the
1758 ! coupled tendency (rho phi/my)
1759 ! here as usual rho -> ~'mu'
1761 ! w eqn [divided by my] is:
1762 ! partial d/dt(rho w/my) = -mx partial d/dx(w rho u/my)
1763 ! -mx partial d/dy(v rho v/mx)
1764 ! - partial d/dz(w rho w/my)
1765 ! +rho[(u*u+v*v)/a + 2 u omega cos(lat) -
1766 ! (1/rho) partial dp/dz - g + Fz]/my
1767 ! here as usual rho -> ~'mu'
1769 ! 'u,v,w' sent here must be coupled variables (= rho w/my etc.) by their usage
1778 j_loop_w:DO j=j_start,j_end
1780 mut_invd(i) = -(mutd(i, j)/mut(i, j)**2)
1781 mut_inv(i) = 1./mut(i, j)
1783 msft_inv(i) = 1./msfty(i, j)
1787 t_2aved(i, k, j) = .5*((1.+epssm)*t_2d(i, k, j)+(1.-epssm)*&
1789 t_2ave(i, k, j) = .5*((1.+epssm)*t_2(i, k, j)+(1.-epssm)*t_2ave(&
1791 t_2aved(i, k, j) = ((t_2aved(i, k, j)+t0*muaved(i, j))*muts(i, j&
1792 & )*(t0+t_1(i, k, j))-(t_2ave(i, k, j)+muave(i, j)*t0)*(mutsd(i&
1793 & , j)*(t0+t_1(i, k, j))+muts(i, j)*t_1d(i, k, j)))/(muts(i, j)*&
1794 & (t0+t_1(i, k, j)))**2
1795 t_2ave(i, k, j) = (t_2ave(i, k, j)+muave(i, j)*t0)/(muts(i, j)*(&
1797 wdwnd(i, k+1) = .5*rdnw(k)*((wwd(i, k+1, j)+wwd(i, k, j))*(ph_1(&
1798 & i, k+1, j)-ph_1(i, k, j)+phb(i, k+1, j)-phb(i, k, j))+(ww(i, k&
1799 & +1, j)+ww(i, k, j))*(ph_1d(i, k+1, j)-ph_1d(i, k, j)))
1800 wdwn(i, k+1) = .5*(ww(i, k+1, j)+ww(i, k, j))*rdnw(k)*(ph_1(i, k&
1801 & +1, j)-ph_1(i, k, j)+phb(i, k+1, j)-phb(i, k, j))
1802 rhsd(i, k+1) = dts*(ph_tendd(i, k+1, j)+.5*g*(1.-epssm)*wd(i, k+&
1804 rhs(i, k+1) = dts*(ph_tend(i, k+1, j)+.5*g*(1.-epssm)*w(i, k+1, &
1808 ! building up RHS of phi equation
1809 ! ph_tend contains terms 1 and 2; now adding 3 and 4 in stages:
1810 ! here rhs = delta t [ph_tend + ~g*w/2 - ~ww * partial d phi/dz]
1813 rhsd(i, k) = rhsd(i, k) - dts*(fnm(k)*wdwnd(i, k+1)+fnp(k)*wdwnd&
1815 rhs(i, k) = rhs(i, k) - dts*(fnm(k)*wdwn(i, k+1)+fnp(k)*wdwn(i, &
1819 ! NOTE: phi'' is not coupled with the map-scale factor (1/m),
1820 ! but it's tendency is, so must multiply by msft here
1821 ! Comments on map scale factors:
1822 ! building up RHS of phi equation
1823 ! ph_tend contains terms 1 and 2; now adding 3 and 4 in stages:
1824 ! here rhs = ph_previous + (msft/mu)*[rhs_previous - ~ww * delta t *
1826 ! = ph_previous + (msft*delta t/mu)*[ph_tend + ~g*w/2 - ~ww *
1830 rhsd(i, k) = phd(i, k, j) + msfty(i, j)*(rhsd(i, k)*mut_inv(i)+&
1831 & rhs(i, k)*mut_invd(i))
1832 rhs(i, k) = ph(i, k, j) + msfty(i, j)*rhs(i, k)*mut_inv(i)
1833 IF (top_lid .AND. k .EQ. k_end + 1) THEN
1839 ! lower boundary condition on w
1840 ! Comments on map scale factors:
1841 ! Chain rule: if Z=Z(X,Y) [true at the surface] then
1842 ! dZ/dt = dZ/dX * dX/dt + dZ/dY * dY/dt, U=dX/dt, V=dY/dt
1843 ! using capitals to denote actual values
1844 ! In mapped values, u=U, v=V, z=Z, 1/dX=mx/dx, 1/dY=my/dy
1845 ! w = dz/dt = mx u dz/dx + my v dz/dy
1846 ! [where dz/dx is just the surface height change between x
1847 ! gridpoints, and dz/dy is the change between y gridpoints]
1848 ! [cf1, cf2 and cf3 do vertical weighting of u or v values nearest
1851 wd(i, 1, j) = msfty(i, j)*.5*rdy*((ht(i, j+1)-ht(i, j))*(cf1*vd(i&
1852 & , 1, j+1)+cf2*vd(i, 2, j+1)+cf3*vd(i, 3, j+1))+(ht(i, j)-ht(i, j&
1853 & -1))*(cf1*vd(i, 1, j)+cf2*vd(i, 2, j)+cf3*vd(i, 3, j))) + msftx(&
1854 & i, j)*.5*rdx*((ht(i+1, j)-ht(i, j))*(cf1*ud(i+1, 1, j)+cf2*ud(i+&
1855 & 1, 2, j)+cf3*ud(i+1, 3, j))+(ht(i, j)-ht(i-1, j))*(cf1*ud(i, 1, &
1856 & j)+cf2*ud(i, 2, j)+cf3*ud(i, 3, j)))
1857 w(i, 1, j) = msfty(i, j)*.5*rdy*((ht(i, j+1)-ht(i, j))*(cf1*v(i, 1&
1858 & , j+1)+cf2*v(i, 2, j+1)+cf3*v(i, 3, j+1))+(ht(i, j)-ht(i, j-1))*&
1859 & (cf1*v(i, 1, j)+cf2*v(i, 2, j)+cf3*v(i, 3, j))) + msftx(i, j)*.5&
1860 & *rdx*((ht(i+1, j)-ht(i, j))*(cf1*u(i+1, 1, j)+cf2*u(i+1, 2, j)+&
1861 & cf3*u(i+1, 3, j))+(ht(i, j)-ht(i-1, j))*(cf1*u(i, 1, j)+cf2*u(i&
1862 & , 2, j)+cf3*u(i, 3, j)))
1865 ! Jammed 3 doubly nested loops over k/i into 1 for slight improvement
1866 ! in efficiency. No change in results (bit-for-bit). JM 20040514
1867 ! (left a blank line where the other two k/i-loops were)
1869 ! above surface, begin by adding delta t * previous (coupled) w tendency
1872 wd(i, k, j) = wd(i, k, j) + dts*rw_tendd(i, k, j) + msft_inv(i)*&
1873 & .5*dts*g*rdn(k)*((cqwd(i, k, j)*mut_inv(i)+cqw(i, k, j)*&
1874 & mut_invd(i))*(c2a(i, k, j)*rdnw(k)*((1.+epssm)*(rhs(i, k+1)-&
1875 & rhs(i, k))+(1.-epssm)*(ph(i, k+1, j)-ph(i, k, j)))-c2a(i, k-1&
1876 & , j)*rdnw(k-1)*((1.+epssm)*(rhs(i, k)-rhs(i, k-1))+(1.-epssm)*&
1877 & (ph(i, k, j)-ph(i, k-1, j))))+cqw(i, k, j)*mut_inv(i)*(rdnw(k)&
1878 & *(c2ad(i, k, j)*((1.+epssm)*(rhs(i, k+1)-rhs(i, k))+(1.-epssm)&
1879 & *(ph(i, k+1, j)-ph(i, k, j)))+c2a(i, k, j)*((1.+epssm)*(rhsd(i&
1880 & , k+1)-rhsd(i, k))+(1.-epssm)*(phd(i, k+1, j)-phd(i, k, j))))-&
1881 & rdnw(k-1)*(c2ad(i, k-1, j)*((1.+epssm)*(rhs(i, k)-rhs(i, k-1))&
1882 & +(1.-epssm)*(ph(i, k, j)-ph(i, k-1, j)))+c2a(i, k-1, j)*((1.+&
1883 & epssm)*(rhsd(i, k)-rhsd(i, k-1))+(1.-epssm)*(phd(i, k, j)-phd(&
1884 & i, k-1, j)))))) + dts*g*msft_inv(i)*(rdn(k)*((c2ad(i, k, j)*&
1885 & alt(i, k, j)+c2a(i, k, j)*altd(i, k, j))*t_2ave(i, k, j)+c2a(i&
1886 & , k, j)*alt(i, k, j)*t_2aved(i, k, j)-(c2ad(i, k-1, j)*alt(i, &
1887 & k-1, j)+c2a(i, k-1, j)*altd(i, k-1, j))*t_2ave(i, k-1, j)-c2a(&
1888 & i, k-1, j)*alt(i, k-1, j)*t_2aved(i, k-1, j))-muaved(i, j))
1889 w(i, k, j) = w(i, k, j) + dts*rw_tend(i, k, j) + msft_inv(i)*cqw&
1890 & (i, k, j)*(.5*dts*g*mut_inv(i)*rdn(k)*(c2a(i, k, j)*rdnw(k)*((&
1891 & 1.+epssm)*(rhs(i, k+1)-rhs(i, k))+(1.-epssm)*(ph(i, k+1, j)-ph&
1892 & (i, k, j)))-c2a(i, k-1, j)*rdnw(k-1)*((1.+epssm)*(rhs(i, k)-&
1893 & rhs(i, k-1))+(1.-epssm)*(ph(i, k, j)-ph(i, k-1, j))))) + dts*g&
1894 & *msft_inv(i)*(rdn(k)*(c2a(i, k, j)*alt(i, k, j)*t_2ave(i, k, j&
1895 & )-c2a(i, k-1, j)*alt(i, k-1, j)*t_2ave(i, k-1, j))-muave(i, j)&
1901 wd(i, k, j) = wd(i, k, j) + dts*rw_tendd(i, k, j) + msft_inv(i)*(-&
1902 & (.5*dts*g*rdnw(k-1)**2*2.*((mut_invd(i)*c2a(i, k-1, j)+mut_inv(i&
1903 & )*c2ad(i, k-1, j))*((1.+epssm)*(rhs(i, k)-rhs(i, k-1))+(1.-epssm&
1904 & )*(ph(i, k, j)-ph(i, k-1, j)))+mut_inv(i)*c2a(i, k-1, j)*((1.+&
1905 & epssm)*(rhsd(i, k)-rhsd(i, k-1))+(1.-epssm)*(phd(i, k, j)-phd(i&
1906 & , k-1, j)))))-dts*g*(2.*rdnw(k-1)*((c2ad(i, k-1, j)*alt(i, k-1, &
1907 & j)+c2a(i, k-1, j)*altd(i, k-1, j))*t_2ave(i, k-1, j)+c2a(i, k-1&
1908 & , j)*alt(i, k-1, j)*t_2aved(i, k-1, j))+muaved(i, j)))
1909 w(i, k, j) = w(i, k, j) + dts*rw_tend(i, k, j) + msft_inv(i)*(-(.5&
1910 & *dts*g*mut_inv(i)*rdnw(k-1)**2*2.*c2a(i, k-1, j)*((1.+epssm)*(&
1911 & rhs(i, k)-rhs(i, k-1))+(1.-epssm)*(ph(i, k, j)-ph(i, k-1, j))))-&
1912 & dts*g*(2.*rdnw(k-1)*c2a(i, k-1, j)*alt(i, k-1, j)*t_2ave(i, k-1&
1913 & , j)+muave(i, j)))
1921 wd(i, k, j) = (wd(i, k, j)-ad(i, k, j)*w(i, k-1, j)-a(i, k, j)*&
1922 & wd(i, k-1, j))*alpha(i, k, j) + (w(i, k, j)-a(i, k, j)*w(i, k-&
1923 & 1, j))*alphad(i, k, j)
1924 w(i, k, j) = (w(i, k, j)-a(i, k, j)*w(i, k-1, j))*alpha(i, k, j)
1929 wd(i, k, j) = wd(i, k, j) - gammad(i, k, j)*w(i, k+1, j) - gamma&
1930 & (i, k, j)*wd(i, k+1, j)
1931 w(i, k, j) = w(i, k, j) - gamma(i, k, j)*w(i, k+1, j)
1934 IF (config_flags%damp_opt .EQ. 3) THEN
1937 htopd = ph_1d(i, k_end+1, j)/g
1938 htop = (ph_1(i, k_end+1, j)+phb(i, k_end+1, j))/g
1939 hkd = ph_1d(i, k, j)/g
1940 hk = (ph_1(i, k, j)+phb(i, k, j))/g
1942 hbot = htop - hdepth
1945 IF (hk .GE. hbot) THEN
1946 arg1d = 0.5*pi*(hkd-hbotd)/hdepth
1947 arg1 = 0.5*pi*(hk-hbot)/hdepth
1948 arg2d = 0.5*pi*(hkd-hbotd)/hdepth
1949 arg2 = 0.5*pi*(hk-hbot)/hdepth
1950 dampwtd(k) = dampmag*(arg1d*COS(arg1)*SIN(arg2)+SIN(arg1)*&
1952 dampwt(k) = dampmag*SIN(arg1)*SIN(arg2)
1954 wd(i, k, j) = ((wd(i, k, j)-(dampwtd(k)*mut(i, j)+dampwt(k)*&
1955 & mutd(i, j))*w_save(i, k, j)-dampwt(k)*mut(i, j)*w_saved(i, k&
1956 & , j))*(1.+dampwt(k))-(w(i, k, j)-dampwt(k)*mut(i, j)*w_save(&
1957 & i, k, j))*dampwtd(k))/(1.+dampwt(k))**2
1958 w(i, k, j) = (w(i, k, j)-dampwt(k)*mut(i, j)*w_save(i, k, j))/&
1965 phd(i, k, j) = rhsd(i, k) + (msfty(i, j)*.5*dts*g*(1.+epssm)*wd(&
1966 & i, k, j)*muts(i, j)-msfty(i, j)*.5*dts*g*(1.+epssm)*w(i, k, j)&
1967 & *mutsd(i, j))/muts(i, j)**2
1968 ph(i, k, j) = rhs(i, k) + msfty(i, j)*.5*dts*g*(1.+epssm)*w(i, k&
1973 END SUBROUTINE G_ADVANCE_W
1975 SUBROUTINE g_sumflux(ru,g_ru,rv,g_rv,ww,g_ww,u_lin,g_u_lin,v_lin, &
1976 g_v_lin,ww_lin,g_ww_lin,muu,g_muu,muv,g_muv,ru_m,g_ru_m,rv_m,g_rv_m, &
1977 ww_m,g_ww_m,epssm,msfux,msfuy,msfvx,msfvx_inv,msfvy,iteration,number_of_small_timesteps, &
1978 ids,ide,jds,jde,kds,kde,ims,ime,jms,jme,kms,kme,its,ite,jts,jte,kts,kte)
1981 INTEGER,INTENT(IN) :: number_of_small_timesteps
1982 INTEGER,INTENT(IN) :: iteration
1983 INTEGER,INTENT(IN) :: ids,ide,jds,jde,kds,kde
1984 INTEGER,INTENT(IN) :: ims,ime,jms,jme,kms,kme
1985 INTEGER,INTENT(IN) :: its,ite,jts,jte,kts,kte
1986 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(IN) :: g_ru,ru,g_rv,rv,g_ww, &
1987 ww,g_u_lin,u_lin,g_v_lin,v_lin,g_ww_lin,ww_lin
1988 REAL,DIMENSION(ims:ime,kms:kme,jms:jme),INTENT(INOUT) :: g_ru_m,ru_m,g_rv_m, &
1990 REAL,DIMENSION(ims:ime,jms:jme),INTENT(IN) :: g_muu,muu,g_muv,muv,msfux,msfuy, &
1991 msfvx,msfvy,msfvx_inv
1992 INTEGER :: mini,minj,mink
1993 REAL,INTENT(IN) :: epssm
1996 IF(iteration == 1 ) THEN
2016 mini =min(ide-1,ite)
2018 minj =min(jde-1,jte)
2020 mink =min(kde-1,kte)
2026 g_ru_m(i,k,j) =g_ru_m(i,k,j) +g_ru(i,k,j)
2027 ru_m(i,k,j) =ru_m(i,k,j) +ru(i,k,j)
2029 g_rv_m(i,k,j) =g_rv_m(i,k,j) +g_rv(i,k,j)
2030 rv_m(i,k,j) =rv_m(i,k,j) +rv(i,k,j)
2032 g_ww_m(i,k,j) =g_ww_m(i,k,j) +g_ww(i,k,j)
2033 ww_m(i,k,j) =ww_m(i,k,j) +ww(i,k,j)
2039 IF(ite .GT. mini) THEN
2045 g_ru_m(i,k,j) =g_ru_m(i,k,j) +g_ru(i,k,j)
2046 ru_m(i,k,j) =ru_m(i,k,j) +ru(i,k,j)
2053 IF(jte .GT. minj) THEN
2059 g_rv_m(i,k,j) =g_rv_m(i,k,j) +g_rv(i,k,j)
2060 rv_m(i,k,j) =rv_m(i,k,j) +rv(i,k,j)
2067 IF( kte .GT. mink) THEN
2073 g_ww_m(i,k,j) =g_ww_m(i,k,j) +g_ww(i,k,j)
2074 ww_m(i,k,j) =ww_m(i,k,j) +ww(i,k,j)
2081 IF(iteration == number_of_small_timesteps) THEN
2087 g_ru_m(i,k,j) =g_ru_m(i,k,j)/number_of_small_timesteps +((muu(i,j) &
2088 *g_u_lin(i,k,j) +g_muu(i,j)*u_lin(i,k,j))/msfuy(i,j))
2089 ru_m(i,k,j) =ru_m(i,k,j)/number_of_small_timesteps +muu(i,j)*u_lin(i,k,j)/msfuy(i,j)
2091 g_rv_m(i,k,j) =g_rv_m(i,k,j)/number_of_small_timesteps +(muv(i,j) &
2092 *g_v_lin(i,k,j) +g_muv(i,j)*v_lin(i,k,j))*msfvx_inv(i,j)
2093 rv_m(i,k,j) =rv_m(i,k,j)/number_of_small_timesteps +muv(i,j)*v_lin(i,k,j)*msfvx_inv(i,j)
2095 g_ww_m(i,k,j) =g_ww_m(i,k,j)/number_of_small_timesteps +g_ww_lin(i,k,j)
2096 ww_m(i,k,j) =ww_m(i,k,j)/number_of_small_timesteps +ww_lin(i,k,j)
2102 IF(ite .GT. mini) THEN
2108 g_ru_m(i,k,j) =g_ru_m(i,k,j)/number_of_small_timesteps +((muu(i,j) &
2109 *g_u_lin(i,k,j) +g_muu(i,j)*u_lin(i,k,j))/msfuy(i,j))
2110 ru_m(i,k,j) =ru_m(i,k,j)/number_of_small_timesteps +muu(i,j)*u_lin(i,k,j)/msfuy(i,j)
2117 IF(jte .GT. minj) THEN
2123 g_rv_m(i,k,j) =g_rv_m(i,k,j)/number_of_small_timesteps +(muv(i,j) &
2124 *g_v_lin(i,k,j) +g_muv(i,j)*v_lin(i,k,j))*msfvx_inv(i,j)
2125 rv_m(i,k,j) =rv_m(i,k,j)/number_of_small_timesteps +muv(i,j)*v_lin(i,k,j)*msfvx_inv(i,j)
2132 IF( kte .GT. mink) THEN
2138 g_ww_m(i,k,j) =g_ww_m(i,k,j)/number_of_small_timesteps +g_ww_lin(i,k,j)
2139 ww_m(i,k,j) =ww_m(i,k,j)/number_of_small_timesteps +ww_lin(i,k,j)
2147 END SUBROUTINE g_sumflux
2149 SUBROUTINE g_init_module_small_step
2151 END SUBROUTINE g_init_module_small_step
2153 END MODULE g_module_small_step_em