!> @file diffusivities.f90 !------------------------------------------------------------------------------! ! 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-2017 Leibniz Universitaet Hannover !------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: diffusivities.f90 2365 2017-08-21 14:59:59Z knoop $ ! Vertical grid nesting implemented (SadiqHuq) ! ! 2233 2017-05-30 18:08:54Z suehring ! ! 2232 2017-05-30 17:47:52Z suehring ! Adjustments to new topography and surface concept ! ! 2118 2017-01-17 16:38:49Z raasch ! OpenACC directives removed ! ! 2031 2016-10-21 15:11:58Z knoop ! renamed variable rho to rho_ocean ! ! 2000 2016-08-20 18:09:15Z knoop ! Forced header and separation lines into 80 columns ! ! 1711 2015-11-05 07:38:04Z raasch ! bugfix: loop moved into IF block to avoid usage of l without being defined ! ! 1682 2015-10-07 23:56:08Z knoop ! Code annotations made doxygen readable ! ! 1374 2014-04-25 12:55:07Z raasch ! rif removed from acc-present-list ! ! 1353 2014-04-08 15:21:23Z heinze ! REAL constants provided with KIND-attribute ! ! 1340 2014-03-25 19:45:13Z kanani ! REAL constants defined as wp-kind ! ! 1322 2014-03-20 16:38:49Z raasch ! REAL constants defined as wp-kind ! ! 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 ! ! 1179 2013-06-14 05:57:58Z raasch ! use_reference renamed use_single_reference_value ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! OpenACC statements added + code changes required for GPU optimization, ! adjustment of mixing length to the Prandtl mixing length at first grid point ! above ground removed ! ! Revision 1.1 1997/09/19 07:41:10 raasch ! Initial revision ! ! ! Description: ! ------------ !> Computation of the turbulent diffusion coefficients for momentum and heat !> according to Prandtl-Kolmogorov !------------------------------------------------------------------------------! SUBROUTINE diffusivities( var, var_reference ) USE arrays_3d, & ONLY: dd2zu, e, kh, km, l_grid, l_wall USE control_parameters, & ONLY: atmos_ocean_sign, e_min, g, outflow_l, outflow_n, outflow_r, & outflow_s, use_single_reference_value, wall_adjustment, & wall_adjustment_factor USE indices, & ONLY: nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt, & wall_flags_0 USE kinds USE pegrid USE statistics, & ONLY : rmask, statistic_regions, sums_l_l USE surface_mod, & ONLY : bc_h USE vertical_nesting_mod, & ONLY: vnest_boundary_conds_khkm, vnest_init IMPLICIT NONE INTEGER(iwp) :: i !< INTEGER(iwp) :: j !< INTEGER(iwp) :: k !< INTEGER(iwp) :: m !< INTEGER(iwp) :: omp_get_thread_num !< INTEGER(iwp) :: sr !< INTEGER(iwp) :: tn !< REAL(wp) :: dvar_dz !< REAL(wp) :: flag !< REAL(wp) :: l !< REAL(wp) :: ll !< REAL(wp) :: l_stable !< REAL(wp) :: sqrt_e !< REAL(wp) :: var_reference !< REAL(wp) :: var(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< ! !-- Default thread number in case of one thread tn = 0 ! !-- Initialization for calculation of the mixing length profile sums_l_l = 0.0_wp ! !-- Compute the turbulent diffusion coefficient for momentum !$OMP PARALLEL PRIVATE (dvar_dz,i,j,k,l,ll,l_stable,sqrt_e,sr,tn,flag) !$ tn = omp_get_thread_num() ! !-- Introduce an optional minimum tke IF ( e_min > 0.0_wp ) THEN !$OMP DO DO i = nxlg, nxrg DO j = nysg, nyng DO k = nzb+1, nzt e(k,j,i) = MAX( e(k,j,i), e_min ) * & MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) ) ENDDO ENDDO ENDDO ENDIF !$OMP DO DO i = nxlg, nxrg DO j = nysg, nyng DO k = nzb+1, nzt flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) ) sqrt_e = SQRT( e(k,j,i) ) ! !-- Determine the mixing length dvar_dz = atmos_ocean_sign * & ! inverse effect of pt/rho_ocean gradient ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) IF ( dvar_dz > 0.0_wp ) THEN IF ( use_single_reference_value ) THEN l_stable = 0.76_wp * sqrt_e / & SQRT( g / var_reference * dvar_dz ) + 1E-5_wp ELSE l_stable = 0.76_wp * sqrt_e / & SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp ENDIF ELSE l_stable = l_grid(k) ENDIF ! !-- Adjustment of the mixing length IF ( wall_adjustment ) THEN l = MIN( wall_adjustment_factor * l_wall(k,j,i), l_grid(k), & l_stable ) ll = MIN( wall_adjustment_factor * l_wall(k,j,i), l_grid(k) ) ELSE l = MIN( l_grid(k), l_stable ) ll = l_grid(k) ENDIF ! !-- Compute diffusion coefficients for momentum and heat km(k,j,i) = 0.1_wp * l * sqrt_e * flag kh(k,j,i) = ( 1.0_wp + 2.0_wp * l / ll ) * km(k,j,i) * flag ! !-- Summation for averaged profile (cf. flow_statistics) DO sr = 0, statistic_regions sums_l_l(k,sr,tn) = sums_l_l(k,sr,tn) + l * rmask(j,i,sr) & * flag ENDDO ENDDO ENDDO ENDDO sums_l_l(nzt+1,:,tn) = sums_l_l(nzt,:,tn) ! quasi boundary-condition for ! data output !$OMP END PARALLEL ! !-- Set vertical boundary values (Neumann conditions both at upward- and !-- downward facing walls. To set wall-boundary values, the surface data type !-- is applied. !-- Horizontal boundary conditions at vertical walls are not set because !-- so far vertical surfaces require usage of a Prandtl-layer where the boundary !-- values of the diffusivities are not needed. !-- Upward-facing !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, bc_h(0)%ns i = bc_h(0)%i(m) j = bc_h(0)%j(m) k = bc_h(0)%k(m) km(k-1,j,i) = km(k,j,i) kh(k-1,j,i) = kh(k,j,i) ENDDO ! !-- Downward facing surfaces !$OMP PARALLEL DO PRIVATE( i, j, k ) DO m = 1, bc_h(1)%ns i = bc_h(1)%i(m) j = bc_h(1)%j(m) k = bc_h(1)%k(m) km(k+1,j,i) = km(k,j,i) kh(k+1,j,i) = kh(k,j,i) ENDDO ! !-- Model top !$OMP PARALLEL DO DO i = nxlg, nxrg DO j = nysg, nyng km(nzt+1,j,i) = km(nzt,j,i) kh(nzt+1,j,i) = kh(nzt,j,i) ENDDO ENDDO ! !-- Set Neumann boundary conditions at the outflow boundaries in case of !-- non-cyclic lateral boundaries IF ( outflow_l ) THEN km(:,:,nxl-1) = km(:,:,nxl) kh(:,:,nxl-1) = kh(:,:,nxl) ENDIF IF ( outflow_r ) THEN km(:,:,nxr+1) = km(:,:,nxr) kh(:,:,nxr+1) = kh(:,:,nxr) ENDIF IF ( outflow_s ) THEN km(:,nys-1,:) = km(:,nys,:) kh(:,nys-1,:) = kh(:,nys,:) ENDIF IF ( outflow_n ) THEN km(:,nyn+1,:) = km(:,nyn,:) kh(:,nyn+1,:) = kh(:,nyn,:) ENDIF ! !-- Vertical nesting: set fine grid eddy viscosity top boundary condition IF ( vnest_init ) CALL vnest_boundary_conds_khkm END SUBROUTINE diffusivities