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

Last change on this file since 2011 was 2001, checked in by knoop, 8 years ago

last commit documented

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