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

Last change on this file since 1344 was 1341, checked in by kanani, 11 years ago

last commit documented

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