Index: palm/trunk/SOURCE/diffusion_u.f90
===================================================================
--- palm/trunk/SOURCE/diffusion_u.f90	(revision 1002)
+++ palm/trunk/SOURCE/diffusion_u.f90	(revision 1015)
@@ -4,5 +4,5 @@
 ! Current revisions:
 ! -----------------
-!
+! accelerator version (*_acc) added
 !
 ! Former revisions:
@@ -58,5 +58,5 @@
 
     PRIVATE
-    PUBLIC diffusion_u
+    PUBLIC diffusion_u, diffusion_u_acc
 
     INTERFACE diffusion_u
@@ -64,4 +64,8 @@
        MODULE PROCEDURE diffusion_u_ij
     END INTERFACE diffusion_u
+
+    INTERFACE diffusion_u_acc
+       MODULE PROCEDURE diffusion_u_acc
+    END INTERFACE diffusion_u_acc
 
  CONTAINS
@@ -220,4 +224,188 @@
 
 !------------------------------------------------------------------------------!
+! Call for all grid points - accelerator version
+!------------------------------------------------------------------------------!
+    SUBROUTINE diffusion_u_acc
+
+       USE arrays_3d
+       USE control_parameters
+       USE grid_variables
+       USE indices
+
+       IMPLICIT NONE
+
+       INTEGER ::  i, j, k
+       REAL    ::  kmym, kmyp, kmzm, kmzp
+
+       !$acc declare create ( usvs )
+       REAL, DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) ::  usvs
+
+!
+!--    First calculate horizontal momentum flux u'v' at vertical walls,
+!--    if neccessary
+       IF ( topography /= 'flat' )  THEN
+          CALL wall_fluxes_acc( usvs, 1.0, 0.0, 0.0, 0.0, nzb_u_inner, &
+                                nzb_u_outer, wall_u )
+       ENDIF
+
+       !$acc kernels present ( u, v, w, km, tend, usws, uswst )   &
+       !$acc         present ( ddzu, ddzw, fym, fyp, wall_u )           &
+       !$acc         present ( nzb_u_inner, nzb_u_outer, nzb_diff_u )
+       !$acc loop
+       DO  i = nxlu, nxr
+          DO  j = nys, nyn
+!
+!--          Compute horizontal diffusion
+             !$acc loop vector(32)
+             DO  k = 1, nzt
+                IF ( k > nzb_u_outer(j,i) )  THEN
+!
+!--                Interpolate eddy diffusivities on staggered gridpoints
+                   kmyp = 0.25 * &
+                          ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) )
+                   kmym = 0.25 * &
+                          ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) )
+
+                   tend(k,j,i) = tend(k,j,i)                                   &
+                         & + 2.0 * (                                           &
+                         &           km(k,j,i)   * ( u(k,j,i+1) - u(k,j,i)   ) &
+                         &         - km(k,j,i-1) * ( u(k,j,i)   - u(k,j,i-1) ) &
+                         &         ) * ddx2                                    &
+                         & + ( kmyp * ( u(k,j+1,i) - u(k,j,i)     ) * ddy      &
+                         &   + kmyp * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx      &
+                         &   - kmym * ( u(k,j,i) - u(k,j-1,i) ) * ddy          &
+                         &   - kmym * ( v(k,j,i) - v(k,j,i-1) ) * ddx          &
+                         &   ) * ddy
+                ENDIF
+             ENDDO
+
+!
+!--          Wall functions at the north and south walls, respectively
+             !$acc loop vector(32)
+             DO  k = 1, nzt
+                IF( k > nzb_u_inner(j,i)  .AND.  k <= nzb_u_outer(j,i)  .AND. &
+                    wall_u(j,i) /= 0.0 )  THEN
+
+                   kmyp = 0.25 * &
+                          ( km(k,j,i)+km(k,j+1,i)+km(k,j,i-1)+km(k,j+1,i-1) )
+                   kmym = 0.25 * &
+                          ( km(k,j,i)+km(k,j-1,i)+km(k,j,i-1)+km(k,j-1,i-1) )
+
+                   tend(k,j,i) = tend(k,j,i)                                   &
+                                 + 2.0 * (                                     &
+                                       km(k,j,i)   * ( u(k,j,i+1) - u(k,j,i) ) &
+                                     - km(k,j,i-1) * ( u(k,j,i) - u(k,j,i-1) ) &
+                                         ) * ddx2                              &
+                                 + (   fyp(j,i) * (                            &
+                                  kmyp * ( u(k,j+1,i) - u(k,j,i)     ) * ddy   &
+                                + kmyp * ( v(k,j+1,i) - v(k,j+1,i-1) ) * ddx   &
+                                                  )                            &
+                                     - fym(j,i) * (                            &
+                                  kmym * ( u(k,j,i) - u(k,j-1,i) ) * ddy       &
+                                + kmym * ( v(k,j,i) - v(k,j,i-1) ) * ddx       &
+                                                  )                            &
+                                     + wall_u(j,i) * usvs(k,j,i)               &
+                                   ) * ddy
+                ENDIF
+             ENDDO
+
+!
+!--          Compute vertical diffusion. In case of simulating a Prandtl layer,
+!--          index k starts at nzb_u_inner+2.
+             !$acc loop vector(32)
+             DO  k = 1, nzt_diff
+                IF ( k >= nzb_diff_u(j,i) )  THEN
+!
+!--                Interpolate eddy diffusivities on staggered gridpoints
+                   kmzp = 0.25 * &
+                          ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) )
+                   kmzm = 0.25 * &
+                          ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) )
+
+                   tend(k,j,i) = tend(k,j,i)                                   &
+                         & + ( kmzp * ( ( u(k+1,j,i) - u(k,j,i)   ) * ddzu(k+1)&
+                         &            + ( w(k,j,i)   - w(k,j,i-1) ) * ddx      &
+                         &            )                                        &
+                         &   - kmzm * ( ( u(k,j,i)   - u(k-1,j,i)   ) * ddzu(k)&
+                         &            + ( w(k-1,j,i) - w(k-1,j,i-1) ) * ddx    &
+                         &            )                                        &
+                         &   ) * ddzw(k)
+                ENDIF
+             ENDDO
+
+          ENDDO
+       ENDDO
+
+!
+!--    Vertical diffusion at the first grid point above the surface,
+!--    if the momentum flux at the bottom is given by the Prandtl law or
+!--    if it is prescribed by the user.
+!--    Difference quotient of the momentum flux is not formed over half
+!--    of the grid spacing (2.0*ddzw(k)) any more, since the comparison
+!--    with other (LES) modell showed that the values of the momentum
+!--    flux becomes too large in this case.
+!--    The term containing w(k-1,..) (see above equation) is removed here
+!--    because the vertical velocity is assumed to be zero at the surface.
+       IF ( use_surface_fluxes )  THEN
+
+          !$acc loop
+          DO  i = nxlu, nxr
+             !$acc loop vector(32)
+             DO  j = nys, nyn
+          
+                k = nzb_u_inner(j,i)+1
+!
+!--             Interpolate eddy diffusivities on staggered gridpoints
+                kmzp = 0.25 * &
+                      ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) )
+                kmzm = 0.25 * &
+                      ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) )
+
+                tend(k,j,i) = tend(k,j,i)                                    &
+                      & + ( kmzp * ( w(k,j,i)   - w(k,j,i-1)   ) * ddx       &
+                      &   ) * ddzw(k)                                        &
+                      & + ( kmzp * ( u(k+1,j,i) - u(k,j,i)     ) * ddzu(k+1) &
+                      &   + usws(j,i)                                        &
+                      &   ) * ddzw(k)
+             ENDDO
+          ENDDO
+
+       ENDIF
+
+!
+!--    Vertical diffusion at the first gridpoint below the top boundary,
+!--    if the momentum flux at the top is prescribed by the user
+       IF ( use_top_fluxes  .AND.  constant_top_momentumflux )  THEN
+
+          k = nzt
+
+          !$acc loop
+          DO  i = nxlu, nxr
+             !$acc loop vector(32)
+             DO  j = nys, nyn
+
+!
+!--             Interpolate eddy diffusivities on staggered gridpoints
+                kmzp = 0.25 * &
+                       ( km(k,j,i)+km(k+1,j,i)+km(k,j,i-1)+km(k+1,j,i-1) )
+                kmzm = 0.25 * &
+                       ( km(k,j,i)+km(k-1,j,i)+km(k,j,i-1)+km(k-1,j,i-1) )
+
+                tend(k,j,i) = tend(k,j,i)                                    &
+                      & - ( kmzm * ( w(k-1,j,i) - w(k-1,j,i-1) ) * ddx       &
+                      &   ) * ddzw(k)                                        &
+                      & + ( -uswst(j,i)                                      &
+                      &   - kmzm * ( u(k,j,i)   - u(k-1,j,i)   ) * ddzu(k)   &
+                      &   ) * ddzw(k)
+             ENDDO
+          ENDDO
+
+       ENDIF
+       !$acc end kernels
+
+    END SUBROUTINE diffusion_u_acc
+
+
+!------------------------------------------------------------------------------!
 ! Call for grid point i,j
 !------------------------------------------------------------------------------!
