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

Last change on this file since 2248 was 2233, checked in by suehring, 7 years ago

last commit documented

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