source: palm/trunk/SOURCE/diffusivities.f90 @ 1697

Last change on this file since 1697 was 1683, checked in by knoop, 9 years ago

last commit documented

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