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

Last change on this file since 1375 was 1375, checked in by raasch, 8 years ago

last commit documented

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