MODULE diffusion_e_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-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! Former revisions: ! ----------------- ! $Id: diffusion_e.f90 1066 2012-11-22 17:52:43Z suehring $ ! ! 1065 2012-11-22 17:42:36Z hoffmann ! Enabled the claculation of diss in case of turbulence = .TRUE. (parameterized ! effects of turbulence on autoconversion and accretion in two-moments cloud ! physics scheme). ! ! 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, ! adjustment of mixing length to the Prandtl mixing length at first grid point ! above ground removed ! ! 1010 2012-09-20 07:59:54Z raasch ! cpp switch __nopointer added for pointer free version ! ! 1001 2012-09-13 14:08:46Z raasch ! most arrays comunicated by module instead of parameter list ! ! 825 2012-02-19 03:03:44Z raasch ! wang_collision_kernel renamed wang_kernel ! ! 790 2011-11-29 03:11:20Z raasch ! diss is also calculated in case that the Wang kernel is used ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng ! ! 97 2007-06-21 08:23:15Z raasch ! Adjustment of mixing length calculation for the ocean version. zw added to ! argument list. ! This is also a bugfix, because the height above the topography is now ! used instead of the height above level k=0. ! theta renamed var, dpt_dz renamed dvar_dz, +new argument var_reference ! use_pt_reference renamed use_reference ! ! 65 2007-03-13 12:11:43Z raasch ! Reference temperature pt_reference can be used in buoyancy term ! ! 20 2007-02-26 00:12:32Z raasch ! Bugfix: ddzw dimensioned 1:nzt"+1" ! Calculation extended for gridpoint nzt ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.18 2006/08/04 14:29:43 raasch ! dissipation is stored in extra array diss if needed later on for calculating ! the sgs particle velocities ! ! Revision 1.1 1997/09/19 07:40:24 raasch ! Initial revision ! ! ! Description: ! ------------ ! Diffusion- and dissipation terms for the TKE !------------------------------------------------------------------------------! PRIVATE PUBLIC diffusion_e, diffusion_e_acc INTERFACE diffusion_e MODULE PROCEDURE diffusion_e MODULE PROCEDURE diffusion_e_ij END INTERFACE diffusion_e INTERFACE diffusion_e_acc MODULE PROCEDURE diffusion_e_acc END INTERFACE diffusion_e_acc CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE diffusion_e( var, var_reference ) USE arrays_3d USE control_parameters USE grid_variables USE indices USE particle_attributes IMPLICIT NONE INTEGER :: i, j, k REAL :: dvar_dz, l_stable, var_reference #if defined( __nopointer ) REAL, DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var #else REAL, DIMENSION(:,:,:), POINTER :: var #endif REAL, DIMENSION(nzb+1:nzt,nys:nyn) :: dissipation, l, ll ! !-- This if clause must be outside the k-loop because otherwise !-- runtime errors occur with -C hopt on NEC IF ( use_reference ) THEN DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt ! !-- Calculate the mixing length (for dissipation) dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var_reference * dvar_dz ) + 1E-5 ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k), l_stable ) ll(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k) ) ELSE l(k,j) = MIN( l_grid(k), l_stable ) ll(k,j) = l_grid(k) ENDIF ENDDO ENDDO ! !-- Calculate the tendency terms DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt dissipation(k,j) = ( 0.19 + 0.74 * l(k,j) / ll(k,j) ) * & e(k,j,i) * SQRT( e(k,j,i) ) / l(k,j) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k,j) ENDDO ENDDO ! !-- Store dissipation if needed for calculating the sgs particle !-- velocities IF ( use_sgs_for_particles .OR. wang_kernel .OR. & turbulence ) THEN DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k,j) ENDDO ENDDO ENDIF ENDDO ELSE DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt ! !-- Calculate the mixing length (for dissipation) dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5 ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k), l_stable ) ll(k,j) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k) ) ELSE l(k,j) = MIN( l_grid(k), l_stable ) ll(k,j) = l_grid(k) ENDIF ENDDO ENDDO ! !-- Calculate the tendency terms DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt dissipation(k,j) = ( 0.19 + 0.74 * l(k,j) / ll(k,j) ) * & e(k,j,i) * SQRT( e(k,j,i) ) / l(k,j) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k,j) ENDDO ENDDO ! !-- Store dissipation if needed for calculating the sgs particle !-- velocities IF ( use_sgs_for_particles .OR. wang_kernel .OR. & turbulence ) THEN DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k,j) ENDDO ENDDO ENDIF ENDDO ENDIF ! !-- Boundary condition for dissipation IF ( use_sgs_for_particles .OR. wang_kernel .OR. turbulence ) THEN DO i = nxl, nxr DO j = nys, nyn diss(nzb_s_inner(j,i),j,i) = diss(nzb_s_inner(j,i)+1,j,i) ENDDO ENDDO ENDIF END SUBROUTINE diffusion_e !------------------------------------------------------------------------------! ! Call for all grid points - accelerator version !------------------------------------------------------------------------------! SUBROUTINE diffusion_e_acc( var, var_reference ) USE arrays_3d USE control_parameters USE grid_variables USE indices USE particle_attributes IMPLICIT NONE INTEGER :: i, j, k REAL :: dissipation, dvar_dz, l, ll, l_stable, var_reference #if defined( __nopointer ) REAL, DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var #else REAL, DIMENSION(:,:,:), POINTER :: var #endif ! !-- This if clause must be outside the k-loop because otherwise !-- runtime errors occur with -C hopt on NEC IF ( use_reference ) THEN STOP '+++ use_reference in diffusion_e not implemented' ! DO i = nxl, nxr ! DO j = nys, nyn ! DO k = nzb_s_inner(j,i)+1, nzt ! !-- Calculate the mixing length (for dissipation) ! dvar_dz = atmos_ocean_sign * & ! ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) ! IF ( dvar_dz > 0.0 ) THEN ! l_stable = 0.76 * SQRT( e(k,j,i) ) / & ! SQRT( g / var_reference * dvar_dz ) + 1E-5 ! ELSE ! l_stable = l_grid(k) ! ENDIF ! !-- Adjustment of the mixing length ! IF ( wall_adjustment ) THEN ! l(k,j) = MIN( wall_adjustment_factor * & ! ( zu(k) - zw(nzb_s_inner(j,i)) ), & ! l_grid(k), l_stable ) ! ll(k,j) = MIN( wall_adjustment_factor * & ! ( zu(k) - zw(nzb_s_inner(j,i)) ), & ! l_grid(k) ) ! ELSE ! l(k,j) = MIN( l_grid(k), l_stable ) ! ll(k,j) = l_grid(k) ! ENDIF ! ! ENDDO ! ENDDO ! ! !-- Calculate the tendency terms ! DO j = nys, nyn ! DO k = nzb_s_inner(j,i)+1, nzt ! ! dissipation(k,j) = ( 0.19 + 0.74 * l(k,j) / ll(k,j) ) * & ! e(k,j,i) * SQRT( e(k,j,i) ) / l(k,j) ! ! tend(k,j,i) = tend(k,j,i) & ! + ( & ! ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & ! - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ! ) * ddx2 & ! + ( & ! ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & ! - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ! ) * ddy2 & ! + ( & ! ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & ! - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ! ) * ddzw(k) & ! - dissipation(k,j) ! ! ENDDO ! ENDDO ! ! !-- Store dissipation if needed for calculating the sgs particle !-- velocities ! IF ( use_sgs_for_particles .OR. wang_kernel ) THEN ! DO j = nys, nyn ! DO k = nzb_s_inner(j,i)+1, nzt ! diss(k,j,i) = dissipation(k,j) ! ENDDO ! ENDDO ! ENDIF ! ! ENDDO ! ELSE !$acc kernels present( ddzu, ddzw, dd2zu, diss, e, km, l_grid ) & !$acc present( nzb_s_inner, rif, tend, var, zu, zw ) !$acc loop DO i = nxl, nxr DO j = nys, nyn !$acc loop vector( 32 ) DO k = 1, nzt IF ( k > nzb_s_inner(j,i) ) THEN ! !-- Calculate the mixing length (for dissipation) dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5 ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k), l_stable ) ll = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), & l_grid(k) ) ELSE l = MIN( l_grid(k), l_stable ) ll = l_grid(k) ENDIF ! !-- Calculate the tendency terms dissipation = ( 0.19 + 0.74 * l / ll ) * & e(k,j,i) * SQRT( e(k,j,i) ) / l tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation ! !-- Store dissipation if needed for calculating the sgs !-- particle velocities IF ( use_sgs_for_particles .OR. wang_kernel .OR. & turbulence ) THEN diss(k,j,i) = dissipation ENDIF ENDIF ENDDO ENDDO ENDDO !$acc end kernels ENDIF ! !-- Boundary condition for dissipation IF ( use_sgs_for_particles .OR. wang_kernel .OR. turbulence ) THEN !$acc kernels present( diss, nzb_s_inner ) !$acc loop DO i = nxl, nxr !$acc loop vector( 32 ) DO j = nys, nyn diss(nzb_s_inner(j,i),j,i) = diss(nzb_s_inner(j,i)+1,j,i) ENDDO ENDDO !$acc end kernels ENDIF END SUBROUTINE diffusion_e_acc !------------------------------------------------------------------------------! ! Call for grid point i,j !------------------------------------------------------------------------------! SUBROUTINE diffusion_e_ij( i, j, var, var_reference ) USE arrays_3d USE control_parameters USE grid_variables USE indices USE particle_attributes IMPLICIT NONE INTEGER :: i, j, k REAL :: dvar_dz, l_stable, var_reference #if defined( __nopointer ) REAL, DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var #else REAL, DIMENSION(:,:,:), POINTER :: var #endif REAL, DIMENSION(nzb+1:nzt) :: dissipation, l, ll ! !-- Calculate the mixing length (for dissipation) DO k = nzb_s_inner(j,i)+1, nzt dvar_dz = atmos_ocean_sign * & ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0 ) THEN IF ( use_reference ) THEN l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var_reference * dvar_dz ) + 1E-5 ELSE l_stable = 0.76 * SQRT( e(k,j,i) ) / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5 ENDIF ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l(k) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), l_grid(k), & l_stable ) ll(k) = MIN( wall_adjustment_factor * & ( zu(k) - zw(nzb_s_inner(j,i)) ), l_grid(k) ) ELSE l(k) = MIN( l_grid(k), l_stable ) ll(k) = l_grid(k) ENDIF ! !-- Calculate the tendency term dissipation(k) = ( 0.19 + 0.74 * l(k) / ll(k) ) * e(k,j,i) * & SQRT( e(k,j,i) ) / l(k) tend(k,j,i) = tend(k,j,i) & + ( & ( km(k,j,i)+km(k,j,i+1) ) * ( e(k,j,i+1)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j,i-1) ) * ( e(k,j,i)-e(k,j,i-1) ) & ) * ddx2 & + ( & ( km(k,j,i)+km(k,j+1,i) ) * ( e(k,j+1,i)-e(k,j,i) ) & - ( km(k,j,i)+km(k,j-1,i) ) * ( e(k,j,i)-e(k,j-1,i) ) & ) * ddy2 & + ( & ( km(k,j,i)+km(k+1,j,i) ) * ( e(k+1,j,i)-e(k,j,i) ) * ddzu(k+1) & - ( km(k,j,i)+km(k-1,j,i) ) * ( e(k,j,i)-e(k-1,j,i) ) * ddzu(k) & ) * ddzw(k) & - dissipation(k) ENDDO ! !-- Store dissipation if needed for calculating the sgs particle velocities IF ( use_sgs_for_particles .OR. wang_kernel .OR. turbulence ) THEN DO k = nzb_s_inner(j,i)+1, nzt diss(k,j,i) = dissipation(k) ENDDO ! !-- Boundary condition for dissipation diss(nzb_s_inner(j,i),j,i) = diss(nzb_s_inner(j,i)+1,j,i) ENDIF END SUBROUTINE diffusion_e_ij END MODULE diffusion_e_mod