MODULE diffusion_w_mod !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2014 Leibniz Universitaet Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: diffusion_w.f90 1321 2014-03-20 09:40:40Z raasch $ ! ! 1320 2014-03-20 08:40:49Z raasch ! ONLY-attribute added to USE-statements, ! kind-parameters added to all INTEGER and REAL declaration statements, ! kinds are defined in new module kinds, ! revision history before 2012 removed, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1257 2013-11-08 15:18:40Z raasch ! openacc loop and loop vector clauses removed, declare create moved after ! the FORTRAN declaration statement ! ! 1128 2013-04-12 06:19:32Z raasch ! loop index bounds in accelerator version replaced by i_left, i_right, j_south, ! j_north ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! accelerator version (*_acc) added ! ! 1001 2012-09-13 14:08:46Z raasch ! arrays comunicated by module instead of parameter list ! ! 978 2012-08-09 08:28:32Z fricke ! outflow damping layer removed ! kmxm_x/_z and kmxp_x/_z change to kmxm and kmxp ! kmym_y/_z and kmyp_y/_z change to kmym and kmyp ! ! Revision 1.1 1997/09/12 06:24:11 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion term of the w-component !------------------------------------------------------------------------------! USE wall_fluxes_mod, & ONLY : wall_fluxes, wall_fluxes_acc PRIVATE PUBLIC diffusion_w, diffusion_w_acc INTERFACE diffusion_w MODULE PROCEDURE diffusion_w MODULE PROCEDURE diffusion_w_ij END INTERFACE diffusion_w INTERFACE diffusion_w_acc MODULE PROCEDURE diffusion_w_acc END INTERFACE diffusion_w_acc CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE diffusion_w USE arrays_3d, & ONLY : ddzu, ddzw, km, tend, u, v, w USE control_parameters, & ONLY : topography USE grid_variables, & ONLY : ddx, ddy, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y USE indices, & ONLY : nxl, nxr, nyn, nys, nzb, nzb_w_inner, nzb_w_outer, nzt USE kinds IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: REAL(wp) :: kmxm !: REAL(wp) :: kmxp !: REAL(wp) :: kmym !: REAL(wp) :: kmyp !: REAL(wp), DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: wsus !: REAL(wp), DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: wsvs !: ! !-- First calculate horizontal momentum flux w'u' and/or w'v' at vertical !-- walls, if neccessary IF ( topography /= 'flat' ) THEN CALL wall_fluxes( wsus, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, nzb_w_inner, & nzb_w_outer, wall_w_x ) CALL wall_fluxes( wsvs, 0.0_wp, 0.0_wp, 1.0_wp, 0.0_wp, nzb_w_inner, & nzb_w_outer, wall_w_y ) ENDIF DO i = nxl, nxr DO j = nys, nyn DO k = nzb_w_outer(j,i)+1, nzt-1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & & + ( kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & & - kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & - kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & ) * ddx & & + ( kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & & - kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & & - kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & & ) * ddy & & + 2.0 * ( & & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & & ) * ddzu(k+1) ENDDO ! !-- Wall functions at all vertical walls, where necessary IF ( wall_w_x(j,i) /= 0.0 .OR. wall_w_y(j,i) /= 0.0 ) THEN DO k = nzb_w_inner(j,i)+1, nzb_w_outer(j,i) ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & + ( fwxp(j,i) * ( & kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & ) & - fwxm(j,i) * ( & kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & + kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & ) & + wall_w_x(j,i) * wsus(k,j,i) & ) * ddx & + ( fwyp(j,i) * ( & kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & ) & - fwym(j,i) * ( & kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & + kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & ) & + wall_w_y(j,i) * wsvs(k,j,i) & ) * ddy & + 2.0 * ( & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & ) * ddzu(k+1) ENDDO ENDIF ENDDO ENDDO END SUBROUTINE diffusion_w !------------------------------------------------------------------------------! ! Call for all grid points - accelerator version !------------------------------------------------------------------------------! SUBROUTINE diffusion_w_acc USE arrays_3d, & ONLY : ddzu, ddzw, km, tend, u, v, w USE control_parameters, & ONLY : topography USE grid_variables, & ONLY : ddx, ddy, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y USE indices, & ONLY : i_left, i_right, j_north, j_south, nxl, nxr, nyn, nys, nzb, & nzb_w_inner, nzb_w_outer, nzt USE kinds IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: REAL(wp) :: kmxm !: REAL(wp) :: kmxp !: REAL(wp) :: kmym !: REAL(wp) :: kmyp !: REAL(wp), DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: wsus !: REAL(wp), DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: wsvs !: !$acc declare create ( wsus, wsvs ) ! !-- First calculate horizontal momentum flux w'u' and/or w'v' at vertical !-- walls, if neccessary IF ( topography /= 'flat' ) THEN CALL wall_fluxes_acc( wsus, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, & nzb_w_inner, nzb_w_outer, wall_w_x ) CALL wall_fluxes_acc( wsvs, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, & nzb_w_inner, nzb_w_outer, wall_w_y ) ENDIF !$acc kernels present ( u, v, w, km, tend, vsws, vswst ) & !$acc present ( ddzu, ddzw, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y ) & !$acc present ( nzb_w_inner, nzb_w_outer ) DO i = i_left, i_right DO j = j_south, j_north DO k = 1, nzt IF ( k > nzb_w_outer(j,i) ) THEN ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & & + ( kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & & - kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & - kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & ) * ddx & & + ( kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & & - kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & & - kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & & ) * ddy & & + 2.0 * ( & & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & & ) * ddzu(k+1) ENDIF ENDDO ! !-- Wall functions at all vertical walls, where necessary DO k = 1,nzt IF ( k > nzb_w_inner(j,i) .AND. k <= nzb_w_outer(j,i) .AND. & wall_w_x(j,i) /= 0.0 .AND. wall_w_y(j,i) /= 0.0 ) THEN ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * & ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * & ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * & ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & + ( fwxp(j,i) * ( & kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & ) & - fwxm(j,i) * ( & kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & + kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & ) & + wall_w_x(j,i) * wsus(k,j,i) & ) * ddx & + ( fwyp(j,i) * ( & kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & ) & - fwym(j,i) * ( & kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & + kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & ) & + wall_w_y(j,i) * wsvs(k,j,i) & ) * ddy & + 2.0 * ( & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & ) * ddzu(k+1) ENDIF ENDDO ENDDO ENDDO !$acc end kernels END SUBROUTINE diffusion_w_acc !------------------------------------------------------------------------------! ! Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE diffusion_w_ij( i, j ) USE arrays_3d, & ONLY : ddzu, ddzw, km, tend, u, v, w USE control_parameters, & ONLY : topography USE grid_variables, & ONLY : ddx, ddy, fwxm, fwxp, fwym, fwyp, wall_w_x, wall_w_y USE indices, & ONLY : nxl, nxr, nyn, nys, nzb, nzb_w_inner, nzb_w_outer, nzt USE kinds IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: REAL(wp) :: kmxm !: REAL(wp) :: kmxp !: REAL(wp) :: kmym !: REAL(wp) :: kmyp !: REAL(wp), DIMENSION(nzb:nzt+1) :: wsus REAL(wp), DIMENSION(nzb:nzt+1) :: wsvs DO k = nzb_w_outer(j,i)+1, nzt-1 ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & & + ( kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & & - kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & & - kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & & ) * ddx & & + ( kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & & - kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & & - kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & & ) * ddy & & + 2.0 * ( & & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & & ) * ddzu(k+1) ENDDO ! !-- Wall functions at all vertical walls, where necessary IF ( wall_w_x(j,i) /= 0.0 .OR. wall_w_y(j,i) /= 0.0 ) THEN ! !-- Calculate the horizontal momentum fluxes w'u' and/or w'v' IF ( wall_w_x(j,i) /= 0.0 ) THEN CALL wall_fluxes( i, j, nzb_w_inner(j,i)+1, nzb_w_outer(j,i), & wsus, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp ) ELSE wsus = 0.0 ENDIF IF ( wall_w_y(j,i) /= 0.0 ) THEN CALL wall_fluxes( i, j, nzb_w_inner(j,i)+1, nzb_w_outer(j,i), & wsvs, 0.0_wp, 0.0_wp, 1.0_wp, 0.0_wp ) ELSE wsvs = 0.0 ENDIF DO k = nzb_w_inner(j,i)+1, nzb_w_outer(j,i) ! !-- Interpolate eddy diffusivities on staggered gridpoints kmxp = 0.25 * ( km(k,j,i)+km(k,j,i+1)+km(k+1,j,i)+km(k+1,j,i+1) ) kmxm = 0.25 * ( km(k,j,i)+km(k,j,i-1)+km(k+1,j,i)+km(k+1,j,i-1) ) kmyp = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j+1,i)+km(k+1,j+1,i) ) kmym = 0.25 * ( km(k,j,i)+km(k+1,j,i)+km(k,j-1,i)+km(k+1,j-1,i) ) tend(k,j,i) = tend(k,j,i) & + ( fwxp(j,i) * ( & kmxp * ( w(k,j,i+1) - w(k,j,i) ) * ddx & + kmxp * ( u(k+1,j,i+1) - u(k,j,i+1) ) * ddzu(k+1) & ) & - fwxm(j,i) * ( & kmxm * ( w(k,j,i) - w(k,j,i-1) ) * ddx & + kmxm * ( u(k+1,j,i) - u(k,j,i) ) * ddzu(k+1) & ) & + wall_w_x(j,i) * wsus(k) & ) * ddx & + ( fwyp(j,i) * ( & kmyp * ( w(k,j+1,i) - w(k,j,i) ) * ddy & + kmyp * ( v(k+1,j+1,i) - v(k,j+1,i) ) * ddzu(k+1) & ) & - fwym(j,i) * ( & kmym * ( w(k,j,i) - w(k,j-1,i) ) * ddy & + kmym * ( v(k+1,j,i) - v(k,j,i) ) * ddzu(k+1) & ) & + wall_w_y(j,i) * wsvs(k) & ) * ddy & + 2.0 * ( & km(k+1,j,i) * ( w(k+1,j,i) - w(k,j,i) ) * ddzw(k+1) & - km(k,j,i) * ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) & ) * ddzu(k+1) ENDDO ENDIF END SUBROUTINE diffusion_w_ij END MODULE diffusion_w_mod