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

Last change on this file since 1036 was 1036, checked in by raasch, 12 years ago

code has been put under the GNU General Public License (v3)

  • Property svn:keywords set to Id
File size: 6.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-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: diffusivities.f90 1036 2012-10-22 13:43:42Z raasch $
27!
28! 1015 2012-09-27 09:23:24Z raasch
29! OpenACC statements added + code changes required for GPU optimization,
30! adjustment of mixing length to the Prandtl mixing length at first grid point
31! above ground removed
32!
33! 667 2010-12-23 12:06:00Z suehring/gryschka
34! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng
35!
36! 137 2007-11-28 08:50:10Z letzel
37! Bugfix for summation of sums_l_l for flow_statistics
38! Vertical scalar profiles now based on nzb_s_inner and ngp_2dh_s_inner.
39!
40! 97 2007-06-21 08:23:15Z raasch
41! Adjustment of mixing length calculation for the ocean version.
42! This is also a bugfix, because the height above the topography is now
43! used instead of the height above level k=0.
44! theta renamed var, dpt_dz renamed dvar_dz, +new argument var_reference
45! use_pt_reference renamed use_reference
46!
47! 57 2007-03-09 12:05:41Z raasch
48! Reference temperature pt_reference can be used in buoyancy term
49!
50! RCS Log replace by Id keyword, revision history cleaned up
51!
52! Revision 1.24  2006/04/26 12:16:26  raasch
53! OpenMP optimization (+sums_l_l_t), sqrt_e must be private
54!
55! Revision 1.1  1997/09/19 07:41:10  raasch
56! Initial revision
57!
58!
59! Description:
60! ------------
61! Computation of the turbulent diffusion coefficients for momentum and heat
62! according to Prandtl-Kolmogorov
63!------------------------------------------------------------------------------!
64
65    USE arrays_3d
66    USE control_parameters
67    USE grid_variables
68    USE indices
69    USE pegrid
70    USE statistics
71
72    IMPLICIT NONE
73
74    INTEGER ::  i, j, k, omp_get_thread_num, sr, tn
75
76    REAL    ::  dvar_dz, l, ll, l_stable, sqrt_e, var_reference
77
78    REAL    ::  var(nzb:nzt+1,nysg:nyng,nxlg:nxrg)
79
80
81!
82!-- Default thread number in case of one thread
83    tn = 0
84
85!
86!-- Initialization for calculation of the mixing length profile
87    sums_l_l = 0.0
88
89!
90!-- Compute the turbulent diffusion coefficient for momentum
91    !$OMP PARALLEL PRIVATE (dvar_dz,i,j,k,l,ll,l_stable,sqrt_e,sr,tn)
92!$  tn = omp_get_thread_num()
93
94!
95!-- Data declerations for accelerators
96    !$acc data present( dd2zu, e, km, kh, l_grid, l_wall, nzb_s_inner, rif, var )
97    !$acc kernels
98
99!
100!-- Introduce an optional minimum tke
101    IF ( e_min > 0.0 )  THEN
102       !$OMP DO
103       !$acc loop
104       DO  i = nxlg, nxrg
105          DO  j = nysg, nyng
106             !$acc loop vector( 32 )
107             DO  k = 1, nzt
108                IF ( k > nzb_s_inner(j,i) )  THEN
109                   e(k,j,i) = MAX( e(k,j,i), e_min )
110                ENDIF
111             ENDDO
112          ENDDO
113       ENDDO
114    ENDIF
115
116    !$OMP DO
117    !$acc loop
118    DO  i = nxlg, nxrg
119       DO  j = nysg, nyng
120          !$acc loop vector( 32 )
121          DO  k = 1, nzt
122
123             IF ( k > nzb_s_inner(j,i) )  THEN
124
125                sqrt_e = SQRT( e(k,j,i) )
126!
127!--             Determine the mixing length
128                dvar_dz = atmos_ocean_sign * &  ! inverse effect of pt/rho gradient
129                          ( var(k+1,j,i) - var(k-1,j,i) ) * dd2zu(k)
130                IF ( dvar_dz > 0.0 ) THEN
131                   IF ( use_reference )  THEN
132                      l_stable = 0.76 * sqrt_e / &
133                                 SQRT( g / var_reference * dvar_dz ) + 1E-5
134                   ELSE
135                      l_stable = 0.76 * sqrt_e / &
136                                 SQRT( g / var(k,j,i) * dvar_dz ) + 1E-5
137                   ENDIF
138                ELSE
139                   l_stable = l_grid(k)
140                ENDIF
141!
142!--             Adjustment of the mixing length
143                IF ( wall_adjustment )  THEN
144                   l  = MIN( l_wall(k,j,i), l_grid(k), l_stable )
145                   ll = MIN( l_wall(k,j,i), l_grid(k) )
146                ELSE
147                   l  = MIN( l_grid(k), l_stable )
148                   ll = l_grid(k)
149                ENDIF
150
151      !
152      !--       Compute diffusion coefficients for momentum and heat
153                km(k,j,i) = 0.1 * l * sqrt_e
154                kh(k,j,i) = ( 1.0 + 2.0 * l / ll ) * km(k,j,i)
155
156             ENDIF
157
158#if ! defined( __openacc )
159!
160!++          Statistics still have to be realized for accelerators
161!--          Summation for averaged profile (cf. flow_statistics)
162             DO  sr = 0, statistic_regions
163                sums_l_l(k,sr,tn) = sums_l_l(k,sr,tn) + l * rmask(j,i,sr)
164             ENDDO
165#endif
166
167          ENDDO
168       ENDDO
169    ENDDO
170
171#if ! defined( __openacc )
172!
173!++ Statistics still have to be realized for accelerators
174    sums_l_l(nzt+1,:,tn) = sums_l_l(nzt,:,tn)   ! quasi boundary-condition for
175                                                  ! data output
176#endif
177    !$OMP END PARALLEL
178
179!
180!-- Set vertical boundary values (Neumann conditions both at bottom and top).
181!-- Horizontal boundary conditions at vertical walls are not set because
182!-- so far vertical walls require usage of a Prandtl-layer where the boundary
183!-- values of the diffusivities are not needed
184    !$OMP PARALLEL DO
185    !$acc loop
186    DO  i = nxlg, nxrg
187       DO  j = nysg, nyng
188          km(nzb_s_inner(j,i),j,i) = km(nzb_s_inner(j,i)+1,j,i)
189          km(nzt+1,j,i)            = km(nzt,j,i)
190          kh(nzb_s_inner(j,i),j,i) = kh(nzb_s_inner(j,i)+1,j,i)
191          kh(nzt+1,j,i)            = kh(nzt,j,i)
192       ENDDO
193    ENDDO
194
195!
196!-- Set Neumann boundary conditions at the outflow boundaries in case of
197!-- non-cyclic lateral boundaries
198    IF ( outflow_l )  THEN
199       km(:,:,nxl-1) = km(:,:,nxl)
200       kh(:,:,nxl-1) = kh(:,:,nxl)
201    ENDIF
202    IF ( outflow_r )  THEN
203       km(:,:,nxr+1) = km(:,:,nxr)
204       kh(:,:,nxr+1) = kh(:,:,nxr)
205    ENDIF
206    IF ( outflow_s )  THEN
207       km(:,nys-1,:) = km(:,nys,:)
208       kh(:,nys-1,:) = kh(:,nys,:)
209    ENDIF
210    IF ( outflow_n )  THEN
211       km(:,nyn+1,:) = km(:,nyn,:)
212       kh(:,nyn+1,:) = kh(:,nyn,:)
213    ENDIF
214
215    !$acc end kernels
216    !$acc end data
217
218 END SUBROUTINE diffusivities
Note: See TracBrowser for help on using the repository browser.