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

Last change on this file since 1745 was 1712, checked in by raasch, 9 years ago

last commit documented

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