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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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