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