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

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

last commit documented

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