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

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

Code annotations made doxygen readable

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