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

Last change on this file since 2232 was 2232, checked in by suehring, 4 years ago

Adjustments according new topography and surface-modelling concept implemented

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