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

Last change on this file since 1939 was 1818, checked in by maronga, 9 years ago

last commit documented / copyright update

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