Index: palm/trunk/SOURCE/advec_ws.f90
===================================================================
--- palm/trunk/SOURCE/advec_ws.f90	(revision 2329)
+++ palm/trunk/SOURCE/advec_ws.f90	(revision 2696)
@@ -1,5 +1,5 @@
 !> @file advec_ws.f90
 !------------------------------------------------------------------------------!
-! This file is part of PALM.
+! This file is part of the PALM model system.
 !
 ! PALM is free software: you can redistribute it and/or modify it under the
@@ -25,4 +25,9 @@
 ! -----------------
 ! $Id$ 
+! Implement advection for TKE-dissipation in case of RANS-TKE-e closure (TG)
+! Allocate advc_flags_1/2 within ws_init_flags instead of init_grid
+! Change argument list for exchange_horiz_2d_int (MS)
+! 
+! 2329 2017-08-03 14:24:56Z knoop
 ! Bugfix concerning density in divergence correction close to buildings
 ! 
@@ -247,14 +252,15 @@
 
        USE arrays_3d,                                                          &
-           ONLY:  diss_l_e, diss_l_nc, diss_l_nr, diss_l_pt, diss_l_q,         &
-                  diss_l_qc, diss_l_qr, diss_l_s, diss_l_sa, diss_l_u,         &
-                  diss_l_v, diss_l_w, flux_l_e, flux_l_nc, flux_l_nr,          & 
-                  flux_l_pt, flux_l_q, flux_l_qc, flux_l_qr, flux_l_s,         &
-                  flux_l_sa, flux_l_u, flux_l_v, flux_l_w, diss_s_e,           &
-                  diss_s_nc,  diss_s_nr, diss_s_pt, diss_s_q, diss_s_qc,       &
-                  diss_s_qr, diss_s_s, diss_s_sa, diss_s_u, diss_s_v,          &
-                  diss_s_w, flux_s_e, flux_s_nc, flux_s_nr, flux_s_pt,         &
-                  flux_s_q, flux_s_qc, flux_s_qr, flux_s_s, flux_s_sa,         &
-                  flux_s_u, flux_s_v, flux_s_w
+           ONLY:  diss_l_diss, diss_l_e, diss_l_nc, diss_l_nr, diss_l_pt,      &
+                  diss_l_q, diss_l_qc, diss_l_qr, diss_l_s, diss_l_sa,         &
+                  diss_l_u, diss_l_v, diss_l_w, flux_l_diss, flux_l_e,         & 
+                  flux_l_nc, flux_l_nr, flux_l_pt, flux_l_q, flux_l_qc,        &
+                  flux_l_qr, flux_l_s, flux_l_sa, flux_l_u, flux_l_v,          &
+                  flux_l_w, diss_s_diss, diss_s_e, diss_s_nc,  diss_s_nr,      &
+                  diss_s_pt, diss_s_q, diss_s_qc, diss_s_qr, diss_s_s,         &
+                  diss_s_sa, diss_s_u, diss_s_v,  diss_s_w, flux_s_diss,       &
+                  flux_s_e, flux_s_nc, flux_s_nr, flux_s_pt, flux_s_q,         &
+                  flux_s_qc, flux_s_qr, flux_s_s, flux_s_sa, flux_s_u,         &
+                  flux_s_v, flux_s_w
 
        USE constants,                                                          &
@@ -265,5 +271,5 @@
            ONLY:  cloud_physics, humidity, loop_optimization,                  &
                   passive_scalar, microphysics_morrison, microphysics_seifert, &
-                  ocean, ws_scheme_mom, ws_scheme_sca
+                  ocean, rans_tke_e, ws_scheme_mom, ws_scheme_sca
 
        USE indices,                                                            &
@@ -378,4 +384,11 @@
                        diss_l_pt(nzb+1:nzt,nys:nyn,0:threads_per_task-1),      &
                        diss_l_e(nzb+1:nzt,nys:nyn,0:threads_per_task-1) )
+
+             IF ( rans_tke_e )  THEN
+                ALLOCATE( flux_s_diss(nzb+1:nzt,0:threads_per_task-1),         &
+                          diss_s_diss(nzb+1:nzt,0:threads_per_task-1) )
+                ALLOCATE( flux_l_diss(nzb+1:nzt,nys:nyn,0:threads_per_task-1), &
+                          diss_l_diss(nzb+1:nzt,nys:nyn,0:threads_per_task-1) )
+             ENDIF
 
              IF ( humidity )  THEN
@@ -437,11 +450,12 @@
 
        USE control_parameters,                                                 &
-           ONLY:  inflow_l, inflow_n, inflow_r, inflow_s, momentum_advec,      &
+           ONLY:  force_bound_l, force_bound_n, force_bound_r, force_bound_s,  &
+                  inflow_l, inflow_n, inflow_r, inflow_s, momentum_advec,      &
                   nest_bound_l, nest_bound_n, nest_bound_r, nest_bound_s,      &
                   outflow_l, outflow_n, outflow_r, outflow_s, scalar_advec
 
        USE indices,                                                            &
-           ONLY:  advc_flags_1, advc_flags_2, nbgp, nxl, nxlu, nxr, nyn, nys,  &
-                  nysv, nzb, nzt, wall_flags_0
+           ONLY:  advc_flags_1, advc_flags_2, nbgp, nxl, nxlg, nxlu, nxr, nxrg,&
+                  nyn, nyng, nys, nysg, nysv, nzb, nzt, wall_flags_0
 
        USE kinds
@@ -458,5 +472,8 @@
        LOGICAL      ::  flag_set !< steering variable for advection flags
    
-
+       ALLOCATE( advc_flags_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                  &
+                 advc_flags_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
+       advc_flags_1 = 0
+       advc_flags_2 = 0
        IF ( scalar_advec == 'ws-scheme' )  THEN
 !
@@ -474,7 +491,9 @@
                     .OR.  .NOT. BTEST(wall_flags_0(k,j,i+2),0)                 &   
                     .OR.  .NOT. BTEST(wall_flags_0(k,j,i-1),0) )               &
-                      .OR.  ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                      .OR.  ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                             .AND.  i == nxl   )                                &
-                      .OR.  ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                      .OR.  ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                             .AND.  i == nxr   ) )                              &
                    THEN
@@ -491,8 +510,10 @@
                             )                                                  &
                                                     .OR.                       &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr-1 )    .OR.                       &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
-                              .AND. i == nxlu  ) )                             &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
+                              .AND. i == nxlu  ) )                             & ! why not nxl+1
                    THEN
                       advc_flags_1(k,j,i) = IBSET( advc_flags_1(k,j,i), 1 )
@@ -511,7 +532,9 @@
                     .OR.  .NOT. BTEST(wall_flags_0(k,j+2,i),0)                 &   
                     .OR.  .NOT. BTEST(wall_flags_0(k,j-1,i),0))                &
-                      .OR.  ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                      .OR.  ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                             .AND.  j == nys   )                                &
-                      .OR.  ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                      .OR.  ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                             .AND.  j == nyn   ) )                              &
                    THEN
@@ -530,7 +553,9 @@
                             )                                                  &
                                                     .OR.                       &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
-                              .AND. j == nysv  )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
+                              .AND. j == nysv  )    .OR.                       & ! why not nys+1
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn-1 ) )                             &          
                    THEN
@@ -620,7 +645,9 @@
 !--                WS1 (9), WS3 (10), WS5 (11)
                    IF ( .NOT. BTEST(wall_flags_0(k,j,i+1),1)  .OR.             &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i <= nxlu  )    .OR.                       &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr   ) )                             &
                    THEN
@@ -630,7 +657,9 @@
                               .NOT. BTEST(wall_flags_0(k,j,i-1),1) )           &
                                                         .OR.                   &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr-1 )    .OR.                       &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i == nxlu+1) )                             &
                    THEN
@@ -652,7 +681,9 @@
 !--                WS1 (12), WS3 (13), WS5 (14)
                    IF ( .NOT. BTEST(wall_flags_0(k,j+1,i),1)   .OR.            &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j == nys   )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn   ) )                             &
                    THEN
@@ -662,7 +693,9 @@
                               .NOT. BTEST(wall_flags_0(k,j-1,i),1) )           &
                                                         .OR.                   &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j == nysv  )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn-1 ) )                             &
                    THEN
@@ -746,7 +779,9 @@
 !--                WS1 (18), WS3 (19), WS5 (20)
                    IF ( .NOT. BTEST(wall_flags_0(k,j,i+1),2)  .OR.             &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i == nxl   )    .OR.                       &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr   ) )                             &
                   THEN
@@ -758,7 +793,9 @@
                               .NOT. BTEST(wall_flags_0(k,j,i-1),2)             &
                                                     .OR.                       &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr-1 )    .OR.                       &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i == nxlu  ) )                             &
                    THEN
@@ -780,7 +817,9 @@
 !--                WS1 (21), WS3 (22), WS5 (23)
                    IF ( .NOT. BTEST(wall_flags_0(k,j+1,i),2) .OR.              &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j <= nysv  )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn   ) )                             &
                    THEN
@@ -790,7 +829,9 @@
                               .NOT. BTEST(wall_flags_0(k,j-1,i),2) )           &
                                                         .OR.                   &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j == nysv+1)    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn-1 ) )                             &
                    THEN
@@ -873,7 +914,9 @@
 !--                WS1 (27), WS3 (28), WS5 (29)
                    IF ( .NOT. BTEST(wall_flags_0(k,j,i+1),3) .OR.              &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i == nxl   )    .OR.                       &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr   ) )                             &
                    THEN
@@ -883,7 +926,9 @@
                               .NOT. BTEST(wall_flags_0(k,j,i-1),3) )           &
                                                         .OR.                   &
-                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r )    &
+                            ( ( inflow_r .OR. outflow_r .OR. nest_bound_r  .OR.&
+                                force_bound_r )                                &
                               .AND. i == nxr-1 )    .OR.                       &
-                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l )    &
+                            ( ( inflow_l .OR. outflow_l .OR. nest_bound_l  .OR.&
+                                force_bound_l )                                &
                               .AND. i == nxlu  ) )                             &
                    THEN
@@ -905,7 +950,9 @@
 !--                WS1 (30), WS3 (31), WS5 (32)
                    IF ( .NOT. BTEST(wall_flags_0(k,j+1,i),3) .OR.              &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j == nys   )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn   ) )                             &
                    THEN
@@ -915,7 +962,9 @@
                               .NOT. BTEST(wall_flags_0(k,j-1,i),3) )           &
                                                         .OR.                   &
-                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s )    &
+                            ( ( inflow_s .OR. outflow_s .OR. nest_bound_s  .OR.&
+                                force_bound_s )                                &
                               .AND. j == nysv  )    .OR.                       &
-                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n )    &
+                            ( ( inflow_n .OR. outflow_n .OR. nest_bound_n  .OR.&
+                                force_bound_n )                                &
                               .AND. j == nyn-1 ) )                             &
                    THEN
@@ -1003,25 +1052,29 @@
 !
 !--       Exchange ghost points for advection flags
-          CALL exchange_horiz_int( advc_flags_1, nbgp )
-          CALL exchange_horiz_int( advc_flags_2, nbgp )
+          CALL exchange_horiz_int( advc_flags_1, nys, nyn, nxl, nxr, nzt, nbgp )
+          CALL exchange_horiz_int( advc_flags_2, nys, nyn, nxl, nxr, nzt, nbgp )
 !
 !--       Set boundary flags at inflow and outflow boundary in case of 
 !--       non-cyclic boundary conditions.
-         IF ( inflow_l .OR. outflow_l .OR. nest_bound_l )  THEN
+          IF ( inflow_l      .OR.  outflow_l  .OR.                             &
+               nest_bound_l  .OR.  force_bound_l )  THEN
              advc_flags_1(:,:,nxl-1) = advc_flags_1(:,:,nxl)
              advc_flags_2(:,:,nxl-1) = advc_flags_2(:,:,nxl)
-         ENDIF
-
-         IF ( inflow_r .OR. outflow_r .OR. nest_bound_r )  THEN
+          ENDIF
+
+          IF ( inflow_r      .OR.  outflow_r  .OR.                             &
+               nest_bound_r  .OR.  force_bound_r )  THEN
             advc_flags_1(:,:,nxr+1) = advc_flags_1(:,:,nxr)
             advc_flags_2(:,:,nxr+1) = advc_flags_2(:,:,nxr)
           ENDIF
 
-          IF ( inflow_n .OR. outflow_n .OR. nest_bound_n )  THEN
+          IF ( inflow_n      .OR.  outflow_n  .OR.                             &
+               nest_bound_n  .OR.  force_bound_n )  THEN
              advc_flags_1(:,nyn+1,:) = advc_flags_1(:,nyn,:)
              advc_flags_2(:,nyn+1,:) = advc_flags_2(:,nyn,:)
           ENDIF
 
-          IF ( inflow_s .OR. outflow_s  .OR. nest_bound_s )  THEN
+          IF ( inflow_s      .OR.  outflow_s  .OR.                             &
+               nest_bound_s  .OR.  force_bound_s )  THEN
              advc_flags_1(:,nys-1,:) = advc_flags_1(:,nys,:)
              advc_flags_2(:,nys-1,:) = advc_flags_2(:,nys,:)
