MODULE diffusion_w_mod !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: diffusion_w.f90 1017 2012-09-27 11:28:50Z letzel $ ! ! 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 ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! ! 366 2009-08-25 08:06:27Z raasch ! bc_lr/bc_ns replaced by bc_lr_cyc/bc_ns_cyc ! ! 75 2007-03-22 09:54:05Z raasch ! Wall functions now include diabatic conditions, call of routine wall_fluxes, ! z0 removed from argument list ! ! 20 2007-02-26 00:12:32Z raasch ! Bugfix: ddzw dimensioned 1:nzt"+1" ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.12 2006/02/23 10:38:03 raasch ! nzb_2d replaced by nzb_w_outer, wall functions added for all vertical walls, ! +z0 in argument list ! WARNING: loops containing the MAX function are still not properly vectorized! ! ! Revision 1.1 1997/09/12 06:24:11 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion term of the w-component !------------------------------------------------------------------------------! USE wall_fluxes_mod 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 USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmxm, kmxp, kmym, kmyp REAL, DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: 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( wsus, 0.0, 0.0, 0.0, 1.0, nzb_w_inner, & nzb_w_outer, wall_w_x ) CALL wall_fluxes( wsvs, 0.0, 0.0, 1.0, 0.0, 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 USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmxm, kmxp, kmym, kmyp !$acc declare create ( wsus, wsvs ) REAL, DIMENSION(nzb:nzt+1,nys:nyn,nxl:nxr) :: 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, 0.0, 0.0, 1.0, nzb_w_inner, & nzb_w_outer, wall_w_x ) CALL wall_fluxes_acc( wsvs, 0.0, 0.0, 1.0, 0.0, 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 ) !$acc loop DO i = nxl, nxr DO j = nys, nyn !$acc loop vector( 32 ) 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 !$acc loop vector( 32 ) 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 USE control_parameters USE grid_variables USE indices IMPLICIT NONE INTEGER :: i, j, k REAL :: kmxm, kmxp, kmym, kmyp REAL, DIMENSION(nzb:nzt+1) :: wsus, 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, 0.0, 0.0, 1.0 ) 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, 0.0, 1.0, 0.0 ) 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