[1682] | 1 | !> @file diffusivities.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[1036] | 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[2101] | 17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[2001] | 22 | ! |
---|
[2032] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: diffusivities.f90 2101 2017-01-05 16:42:31Z kanani $ |
---|
| 27 | ! |
---|
[2032] | 28 | ! 2031 2016-10-21 15:11:58Z knoop |
---|
| 29 | ! renamed variable rho to rho_ocean |
---|
| 30 | ! |
---|
[2001] | 31 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 32 | ! Forced header and separation lines into 80 columns |
---|
| 33 | ! |
---|
[1712] | 34 | ! 1711 2015-11-05 07:38:04Z raasch |
---|
| 35 | ! bugfix: loop moved into IF block to avoid usage of l without being defined |
---|
| 36 | ! |
---|
[1683] | 37 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 38 | ! Code annotations made doxygen readable |
---|
| 39 | ! |
---|
[1375] | 40 | ! 1374 2014-04-25 12:55:07Z raasch |
---|
| 41 | ! rif removed from acc-present-list |
---|
| 42 | ! |
---|
[1354] | 43 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 44 | ! REAL constants provided with KIND-attribute |
---|
| 45 | ! |
---|
[1341] | 46 | ! 1340 2014-03-25 19:45:13Z kanani |
---|
| 47 | ! REAL constants defined as wp-kind |
---|
| 48 | ! |
---|
[1323] | 49 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 50 | ! REAL constants defined as wp-kind |
---|
| 51 | ! |
---|
[1321] | 52 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 53 | ! ONLY-attribute added to USE-statements, |
---|
| 54 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 55 | ! kinds are defined in new module kinds, |
---|
| 56 | ! revision history before 2012 removed, |
---|
| 57 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 58 | ! all variable declaration statements |
---|
[1017] | 59 | ! |
---|
[1182] | 60 | ! 1179 2013-06-14 05:57:58Z raasch |
---|
| 61 | ! use_reference renamed use_single_reference_value |
---|
| 62 | ! |
---|
[1037] | 63 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 64 | ! code put under GPL (PALM 3.9) |
---|
| 65 | ! |
---|
[1017] | 66 | ! 1015 2012-09-27 09:23:24Z raasch |
---|
| 67 | ! OpenACC statements added + code changes required for GPU optimization, |
---|
| 68 | ! adjustment of mixing length to the Prandtl mixing length at first grid point |
---|
| 69 | ! above ground removed |
---|
| 70 | ! |
---|
[1] | 71 | ! Revision 1.1 1997/09/19 07:41:10 raasch |
---|
| 72 | ! Initial revision |
---|
| 73 | ! |
---|
| 74 | ! |
---|
| 75 | ! Description: |
---|
| 76 | ! ------------ |
---|
[1682] | 77 | !> Computation of the turbulent diffusion coefficients for momentum and heat |
---|
| 78 | !> according to Prandtl-Kolmogorov |
---|
[1] | 79 | !------------------------------------------------------------------------------! |
---|
[1682] | 80 | SUBROUTINE diffusivities( var, var_reference ) |
---|
| 81 | |
---|
[1] | 82 | |
---|
[1320] | 83 | USE arrays_3d, & |
---|
| 84 | ONLY: dd2zu, e, kh, km, l_grid, l_wall |
---|
| 85 | |
---|
| 86 | USE control_parameters, & |
---|
| 87 | ONLY: atmos_ocean_sign, e_min, g, outflow_l, outflow_n, outflow_r, & |
---|
| 88 | outflow_s, use_single_reference_value, wall_adjustment |
---|
| 89 | |
---|
| 90 | USE indices, & |
---|
| 91 | ONLY: nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb_s_inner, nzb, nzt |
---|
| 92 | USE kinds |
---|
| 93 | |
---|
[1] | 94 | USE pegrid |
---|
[1320] | 95 | |
---|
| 96 | USE statistics, & |
---|
| 97 | ONLY : rmask, statistic_regions, sums_l_l |
---|
[1] | 98 | |
---|
| 99 | IMPLICIT NONE |
---|
| 100 | |
---|
[1682] | 101 | INTEGER(iwp) :: i !< |
---|
| 102 | INTEGER(iwp) :: j !< |
---|
| 103 | INTEGER(iwp) :: k !< |
---|
| 104 | INTEGER(iwp) :: omp_get_thread_num !< |
---|
| 105 | INTEGER(iwp) :: sr !< |
---|
| 106 | INTEGER(iwp) :: tn !< |
---|
[1] | 107 | |
---|
[1682] | 108 | REAL(wp) :: dvar_dz !< |
---|
| 109 | REAL(wp) :: l !< |
---|
| 110 | REAL(wp) :: ll !< |
---|
| 111 | REAL(wp) :: l_stable !< |
---|
| 112 | REAL(wp) :: sqrt_e !< |
---|
| 113 | REAL(wp) :: var_reference !< |
---|
[1] | 114 | |
---|
[1682] | 115 | REAL(wp) :: var(nzb:nzt+1,nysg:nyng,nxlg:nxrg) !< |
---|
[97] | 116 | |
---|
[1] | 117 | |
---|
| 118 | ! |
---|
| 119 | !-- Default thread number in case of one thread |
---|
| 120 | tn = 0 |
---|
| 121 | |
---|
| 122 | ! |
---|
| 123 | !-- Initialization for calculation of the mixing length profile |
---|
[1340] | 124 | sums_l_l = 0.0_wp |
---|
[1] | 125 | |
---|
| 126 | ! |
---|
| 127 | !-- Compute the turbulent diffusion coefficient for momentum |
---|
[1015] | 128 | !$OMP PARALLEL PRIVATE (dvar_dz,i,j,k,l,ll,l_stable,sqrt_e,sr,tn) |
---|
[1] | 129 | !$ tn = omp_get_thread_num() |
---|
| 130 | |
---|
[1015] | 131 | ! |
---|
| 132 | !-- Data declerations for accelerators |
---|
[1374] | 133 | !$acc data present( dd2zu, e, km, kh, l_grid, l_wall, nzb_s_inner, var ) |
---|
[1015] | 134 | !$acc kernels |
---|
| 135 | |
---|
| 136 | ! |
---|
| 137 | !-- Introduce an optional minimum tke |
---|
[1340] | 138 | IF ( e_min > 0.0_wp ) THEN |
---|
[1015] | 139 | !$OMP DO |
---|
| 140 | !$acc loop |
---|
| 141 | DO i = nxlg, nxrg |
---|
| 142 | DO j = nysg, nyng |
---|
| 143 | !$acc loop vector( 32 ) |
---|
| 144 | DO k = 1, nzt |
---|
| 145 | IF ( k > nzb_s_inner(j,i) ) THEN |
---|
| 146 | e(k,j,i) = MAX( e(k,j,i), e_min ) |
---|
| 147 | ENDIF |
---|
| 148 | ENDDO |
---|
| 149 | ENDDO |
---|
| 150 | ENDDO |
---|
| 151 | ENDIF |
---|
| 152 | |
---|
[1] | 153 | !$OMP DO |
---|
[1015] | 154 | !$acc loop |
---|
[667] | 155 | DO i = nxlg, nxrg |
---|
| 156 | DO j = nysg, nyng |
---|
[1015] | 157 | !$acc loop vector( 32 ) |
---|
| 158 | DO k = 1, nzt |
---|
[1] | 159 | |
---|
[1015] | 160 | IF ( k > nzb_s_inner(j,i) ) THEN |
---|
[1] | 161 | |
---|
[1015] | 162 | sqrt_e = SQRT( e(k,j,i) ) |
---|
[1] | 163 | ! |
---|
[1015] | 164 | !-- Determine the mixing length |
---|
[2031] | 165 | dvar_dz = atmos_ocean_sign * & ! inverse effect of pt/rho_ocean gradient |
---|
[1015] | 166 | ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k) |
---|
[1340] | 167 | IF ( dvar_dz > 0.0_wp ) THEN |
---|
[1179] | 168 | IF ( use_single_reference_value ) THEN |
---|
[1322] | 169 | l_stable = 0.76_wp * sqrt_e / & |
---|
[1340] | 170 | SQRT( g / var_reference * dvar_dz ) + 1E-5_wp |
---|
[1015] | 171 | ELSE |
---|
[1322] | 172 | l_stable = 0.76_wp * sqrt_e / & |
---|
[1340] | 173 | SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5_wp |
---|
[1015] | 174 | ENDIF |
---|
| 175 | ELSE |
---|
| 176 | l_stable = l_grid(k) |
---|
| 177 | ENDIF |
---|
[1] | 178 | ! |
---|
[1015] | 179 | !-- Adjustment of the mixing length |
---|
| 180 | IF ( wall_adjustment ) THEN |
---|
| 181 | l = MIN( l_wall(k,j,i), l_grid(k), l_stable ) |
---|
| 182 | ll = MIN( l_wall(k,j,i), l_grid(k) ) |
---|
[57] | 183 | ELSE |
---|
[1015] | 184 | l = MIN( l_grid(k), l_stable ) |
---|
| 185 | ll = l_grid(k) |
---|
[57] | 186 | ENDIF |
---|
[1015] | 187 | |
---|
| 188 | ! |
---|
| 189 | !-- Compute diffusion coefficients for momentum and heat |
---|
[1322] | 190 | km(k,j,i) = 0.1_wp * l * sqrt_e |
---|
| 191 | kh(k,j,i) = ( 1.0_wp + 2.0_wp * l / ll ) * km(k,j,i) |
---|
[1015] | 192 | |
---|
| 193 | #if ! defined( __openacc ) |
---|
[1] | 194 | ! |
---|
[1711] | 195 | !++ Statistics still have to be realized for accelerators |
---|
| 196 | !-- Summation for averaged profile (cf. flow_statistics) |
---|
| 197 | DO sr = 0, statistic_regions |
---|
| 198 | sums_l_l(k,sr,tn) = sums_l_l(k,sr,tn) + l * rmask(j,i,sr) |
---|
| 199 | ENDDO |
---|
[1015] | 200 | #endif |
---|
[1711] | 201 | ENDIF |
---|
[1] | 202 | |
---|
| 203 | ENDDO |
---|
| 204 | ENDDO |
---|
| 205 | ENDDO |
---|
| 206 | |
---|
[1015] | 207 | #if ! defined( __openacc ) |
---|
| 208 | ! |
---|
| 209 | !++ Statistics still have to be realized for accelerators |
---|
[1] | 210 | sums_l_l(nzt+1,:,tn) = sums_l_l(nzt,:,tn) ! quasi boundary-condition for |
---|
[667] | 211 | ! data output |
---|
[1015] | 212 | #endif |
---|
[1] | 213 | !$OMP END PARALLEL |
---|
| 214 | |
---|
| 215 | ! |
---|
| 216 | !-- Set vertical boundary values (Neumann conditions both at bottom and top). |
---|
| 217 | !-- Horizontal boundary conditions at vertical walls are not set because |
---|
| 218 | !-- so far vertical walls require usage of a Prandtl-layer where the boundary |
---|
| 219 | !-- values of the diffusivities are not needed |
---|
| 220 | !$OMP PARALLEL DO |
---|
[1015] | 221 | !$acc loop |
---|
[667] | 222 | DO i = nxlg, nxrg |
---|
| 223 | DO j = nysg, nyng |
---|
[1] | 224 | km(nzb_s_inner(j,i),j,i) = km(nzb_s_inner(j,i)+1,j,i) |
---|
| 225 | km(nzt+1,j,i) = km(nzt,j,i) |
---|
| 226 | kh(nzb_s_inner(j,i),j,i) = kh(nzb_s_inner(j,i)+1,j,i) |
---|
| 227 | kh(nzt+1,j,i) = kh(nzt,j,i) |
---|
| 228 | ENDDO |
---|
| 229 | ENDDO |
---|
| 230 | |
---|
| 231 | ! |
---|
| 232 | !-- Set Neumann boundary conditions at the outflow boundaries in case of |
---|
| 233 | !-- non-cyclic lateral boundaries |
---|
| 234 | IF ( outflow_l ) THEN |
---|
| 235 | km(:,:,nxl-1) = km(:,:,nxl) |
---|
| 236 | kh(:,:,nxl-1) = kh(:,:,nxl) |
---|
| 237 | ENDIF |
---|
| 238 | IF ( outflow_r ) THEN |
---|
| 239 | km(:,:,nxr+1) = km(:,:,nxr) |
---|
| 240 | kh(:,:,nxr+1) = kh(:,:,nxr) |
---|
| 241 | ENDIF |
---|
| 242 | IF ( outflow_s ) THEN |
---|
| 243 | km(:,nys-1,:) = km(:,nys,:) |
---|
| 244 | kh(:,nys-1,:) = kh(:,nys,:) |
---|
| 245 | ENDIF |
---|
| 246 | IF ( outflow_n ) THEN |
---|
| 247 | km(:,nyn+1,:) = km(:,nyn,:) |
---|
| 248 | kh(:,nyn+1,:) = kh(:,nyn,:) |
---|
| 249 | ENDIF |
---|
| 250 | |
---|
[1015] | 251 | !$acc end kernels |
---|
| 252 | !$acc end data |
---|
[1] | 253 | |
---|
| 254 | END SUBROUTINE diffusivities |
---|