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

Last change on this file since 2583 was 2365, checked in by kanani, 7 years ago

Vertical nesting implemented (SadiqHuq?)

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