1 | SUBROUTINE init_grid |
---|
2 | |
---|
3 | !--------------------------------------------------------------------------------! |
---|
4 | ! This file is part of PALM. |
---|
5 | ! |
---|
6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | ! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover |
---|
18 | !--------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: init_grid.f90 1323 2014-03-20 17:09:54Z suehring $ |
---|
27 | ! |
---|
28 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
29 | ! REAL constants defined as wp-kind |
---|
30 | ! |
---|
31 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
32 | ! ONLY-attribute added to USE-statements, |
---|
33 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
34 | ! kinds are defined in new module kinds, |
---|
35 | ! revision history before 2012 removed, |
---|
36 | ! comment fields (!:) to be used for variable explanations added to |
---|
37 | ! all variable declaration statements |
---|
38 | ! |
---|
39 | ! 1221 2013-09-10 08:59:13Z raasch |
---|
40 | ! wall_flags_00 introduced to hold bits 32-63, |
---|
41 | ! additional 3D-flag arrays for replacing the 2D-index array nzb_s_inner in |
---|
42 | ! loops optimized for openACC (pres + flow_statistics) |
---|
43 | ! |
---|
44 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
45 | ! unused variables removed |
---|
46 | ! |
---|
47 | ! 1069 2012-11-28 16:18:43Z maronga |
---|
48 | ! bugfix: added coupling_char to TOPOGRAPHY_DATA to allow topography in the ocean |
---|
49 | ! model in case of coupled runs |
---|
50 | ! |
---|
51 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
52 | ! code put under GPL (PALM 3.9) |
---|
53 | ! |
---|
54 | ! 1015 2012-09-27 09:23:24Z raasch |
---|
55 | ! lower index for calculating wall_flags_0 set to nzb_w_inner instead of |
---|
56 | ! nzb_w_inner+1 |
---|
57 | ! |
---|
58 | ! 996 2012-09-07 10:41:47Z raasch |
---|
59 | ! little reformatting |
---|
60 | ! |
---|
61 | ! 978 2012-08-09 08:28:32Z fricke |
---|
62 | ! Bugfix: nzb_max is set to nzt at non-cyclic lateral boundaries |
---|
63 | ! Bugfix: Set wall_flags_0 for inflow boundary |
---|
64 | ! |
---|
65 | ! 927 2012-06-06 19:15:04Z raasch |
---|
66 | ! Wall flags are not set for multigrid method in case of masking method |
---|
67 | ! |
---|
68 | ! 864 2012-03-27 15:10:33Z gryschka |
---|
69 | ! In case of ocean and Dirichlet bottom bc for u and v dzu_mg and ddzu_pres |
---|
70 | ! were not correctly defined for k=1. |
---|
71 | ! |
---|
72 | ! 861 2012-03-26 14:18:34Z suehring |
---|
73 | ! Set wall_flags_0. The array is needed for degradation in ws-scheme near walls, |
---|
74 | ! inflow and outflow boundaries as well as near the bottom and the top of the |
---|
75 | ! model domain.! |
---|
76 | ! Initialization of nzb_s_inner and nzb_w_inner. |
---|
77 | ! gls has to be at least nbgp to do not exceed the array bounds of nzb_local |
---|
78 | ! while setting wall_flags_0 |
---|
79 | ! |
---|
80 | ! 843 2012-02-29 15:16:21Z gryschka |
---|
81 | ! In case of ocean and dirichlet bc for u and v at the bottom |
---|
82 | ! the first u-level ist defined at same height as the first w-level |
---|
83 | ! |
---|
84 | ! 818 2012-02-08 16:11:23Z maronga |
---|
85 | ! Bugfix: topo_height is only required if topography is used. It is thus now |
---|
86 | ! allocated in the topography branch |
---|
87 | ! |
---|
88 | ! 809 2012-01-30 13:32:58Z maronga |
---|
89 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
90 | ! |
---|
91 | ! 807 2012-01-25 11:53:51Z maronga |
---|
92 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
93 | ! |
---|
94 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
95 | ! Initial revision (Testversion) |
---|
96 | ! |
---|
97 | ! |
---|
98 | ! Description: |
---|
99 | ! ------------ |
---|
100 | ! Creating grid depending constants |
---|
101 | !------------------------------------------------------------------------------! |
---|
102 | |
---|
103 | USE arrays_3d, & |
---|
104 | ONLY: dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzu_mg, dzw, dzw_mg, f1_mg, & |
---|
105 | f2_mg, f3_mg, l_grid, l_wall, zu, zw |
---|
106 | |
---|
107 | USE control_parameters, & |
---|
108 | ONLY: bc_lr, bc_ns, building_height, building_length_x, & |
---|
109 | building_length_y, building_wall_left, building_wall_south, & |
---|
110 | canyon_height, canyon_wall_left, canyon_wall_south, & |
---|
111 | canyon_width_x, canyon_width_y, coupling_char, dp_level_ind_b, & |
---|
112 | dz, dz_max, dz_stretch_factor, dz_stretch_level, & |
---|
113 | dz_stretch_level_index, ibc_uv_b, io_blocks, io_group, & |
---|
114 | inflow_l, inflow_n, inflow_r, inflow_s, masking_method, & |
---|
115 | maximum_grid_level, message_string, momentum_advec, ocean, & |
---|
116 | outflow_l, outflow_n, outflow_r, outflow_s, prandtl_layer, & |
---|
117 | psolver, scalar_advec, topography, topography_grid_convention, & |
---|
118 | use_surface_fluxes, use_top_fluxes, wall_adjustment_factor |
---|
119 | |
---|
120 | USE grid_variables, & |
---|
121 | ONLY: ddx, ddx2, ddx2_mg, ddy, ddy2, ddy2_mg, dx, dx2, dy, dy2, fwxm, & |
---|
122 | fwxp, fwym, fwyp, fxm, fxp, fym, fyp, wall_e_x, wall_e_y, & |
---|
123 | wall_u, wall_v, wall_w_x, wall_w_y, zu_s_inner, zw_w_inner |
---|
124 | |
---|
125 | USE indices, & |
---|
126 | ONLY: flags, nbgp, nx, nxl, nxlg, nxlu, nxl_mg, nxr, nxrg, nxr_mg, & |
---|
127 | ny, nyn, nyng, nyn_mg, nys, nysv, nys_mg, nysg, nz, nzb, & |
---|
128 | nzb_2d, nzb_diff, nzb_diff_s_inner, nzb_diff_s_outer, & |
---|
129 | nzb_diff_u, nzb_diff_v, nzb_max, nzb_s_inner, nzb_s_outer, & |
---|
130 | nzb_u_inner, nzb_u_outer, nzb_v_inner, nzb_v_outer, & |
---|
131 | nzb_w_inner, nzb_w_outer, nzt, nzt_diff, nzt_mg, rflags_invers, & |
---|
132 | rflags_s_inner, wall_flags_0, wall_flags_00, wall_flags_1, & |
---|
133 | wall_flags_10, wall_flags_2, wall_flags_3, wall_flags_4, & |
---|
134 | wall_flags_5, wall_flags_6, wall_flags_7, wall_flags_8, & |
---|
135 | wall_flags_9 |
---|
136 | |
---|
137 | USE kinds |
---|
138 | |
---|
139 | USE pegrid |
---|
140 | |
---|
141 | IMPLICIT NONE |
---|
142 | |
---|
143 | INTEGER(iwp) :: bh !: |
---|
144 | INTEGER(iwp) :: blx !: |
---|
145 | INTEGER(iwp) :: bly !: |
---|
146 | INTEGER(iwp) :: bxl !: |
---|
147 | INTEGER(iwp) :: bxr !: |
---|
148 | INTEGER(iwp) :: byn !: |
---|
149 | INTEGER(iwp) :: bys !: |
---|
150 | INTEGER(iwp) :: ch !: |
---|
151 | INTEGER(iwp) :: cwx !: |
---|
152 | INTEGER(iwp) :: cwy !: |
---|
153 | INTEGER(iwp) :: cxl !: |
---|
154 | INTEGER(iwp) :: cxr !: |
---|
155 | INTEGER(iwp) :: cyn !: |
---|
156 | INTEGER(iwp) :: cys !: |
---|
157 | INTEGER(iwp) :: gls !: |
---|
158 | INTEGER(iwp) :: i !: |
---|
159 | INTEGER(iwp) :: ii !: |
---|
160 | INTEGER(iwp) :: inc !: |
---|
161 | INTEGER(iwp) :: j !: |
---|
162 | INTEGER(iwp) :: k !: |
---|
163 | INTEGER(iwp) :: l !: |
---|
164 | INTEGER(iwp) :: nxl_l !: |
---|
165 | INTEGER(iwp) :: nxr_l !: |
---|
166 | INTEGER(iwp) :: nyn_l !: |
---|
167 | INTEGER(iwp) :: nys_l !: |
---|
168 | INTEGER(iwp) :: nzb_si !: |
---|
169 | INTEGER(iwp) :: nzt_l !: |
---|
170 | INTEGER(iwp) :: vi !: |
---|
171 | |
---|
172 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: vertical_influence !: |
---|
173 | |
---|
174 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_nl !: |
---|
175 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_nr !: |
---|
176 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_sl !: |
---|
177 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: corner_sr !: |
---|
178 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_l !: |
---|
179 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_n !: |
---|
180 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_r !: |
---|
181 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: wall_s !: |
---|
182 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !: |
---|
183 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_tmp !: |
---|
184 | |
---|
185 | LOGICAL :: flag_set = .FALSE. !: |
---|
186 | |
---|
187 | REAL(wp) :: dx_l !: |
---|
188 | REAL(wp) :: dy_l !: |
---|
189 | REAL(wp) :: dz_stretched !: |
---|
190 | |
---|
191 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: topo_height !: |
---|
192 | |
---|
193 | |
---|
194 | ! |
---|
195 | !-- Calculation of horizontal array bounds including ghost layers |
---|
196 | nxlg = nxl - nbgp |
---|
197 | nxrg = nxr + nbgp |
---|
198 | nysg = nys - nbgp |
---|
199 | nyng = nyn + nbgp |
---|
200 | |
---|
201 | ! |
---|
202 | !-- Allocate grid arrays |
---|
203 | ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & |
---|
204 | dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) ) |
---|
205 | |
---|
206 | ! |
---|
207 | !-- Compute height of u-levels from constant grid length and dz stretch factors |
---|
208 | IF ( dz == -1.0 ) THEN |
---|
209 | message_string = 'missing dz' |
---|
210 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
211 | ELSEIF ( dz <= 0.0 ) THEN |
---|
212 | WRITE( message_string, * ) 'dz=',dz,' <= 0.0' |
---|
213 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
214 | ENDIF |
---|
215 | |
---|
216 | ! |
---|
217 | !-- Define the vertical grid levels |
---|
218 | IF ( .NOT. ocean ) THEN |
---|
219 | ! |
---|
220 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
221 | !-- The second u-level (k=1) corresponds to the top of the |
---|
222 | !-- Prandtl-layer. |
---|
223 | |
---|
224 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN |
---|
225 | zu(0) = 0.0 |
---|
226 | ! zu(0) = - dz * 0.5 |
---|
227 | ELSE |
---|
228 | zu(0) = - dz * 0.5 |
---|
229 | ENDIF |
---|
230 | zu(1) = dz * 0.5 |
---|
231 | |
---|
232 | dz_stretch_level_index = nzt+1 |
---|
233 | dz_stretched = dz |
---|
234 | DO k = 2, nzt+1 |
---|
235 | IF ( dz_stretch_level <= zu(k-1) .AND. dz_stretched < dz_max ) THEN |
---|
236 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
237 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
238 | IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1 |
---|
239 | ENDIF |
---|
240 | zu(k) = zu(k-1) + dz_stretched |
---|
241 | ENDDO |
---|
242 | |
---|
243 | ! |
---|
244 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
245 | !-- corresponding u-levels. In case of dirichlet bc for u and v at the |
---|
246 | !-- ground the first u- and w-level (k=0) are defined at same height (z=0). |
---|
247 | !-- The top w-level is extrapolated linearly. |
---|
248 | zw(0) = 0.0 |
---|
249 | DO k = 1, nzt |
---|
250 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5 |
---|
251 | ENDDO |
---|
252 | zw(nzt+1) = zw(nzt) + 2.0 * ( zu(nzt+1) - zw(nzt) ) |
---|
253 | |
---|
254 | ELSE |
---|
255 | ! |
---|
256 | !-- Grid for ocean with free water surface is at k=nzt (w-grid). |
---|
257 | !-- In case of neumann bc at the ground the first first u-level (k=0) lies |
---|
258 | !-- below the first w-level (k=0). In case of dirichlet bc the first u- and |
---|
259 | !-- w-level are defined at same height, but staggered from the second level. |
---|
260 | !-- The second u-level (k=1) corresponds to the top of the Prandtl-layer. |
---|
261 | zu(nzt+1) = dz * 0.5 |
---|
262 | zu(nzt) = - dz * 0.5 |
---|
263 | |
---|
264 | dz_stretch_level_index = 0 |
---|
265 | dz_stretched = dz |
---|
266 | DO k = nzt-1, 0, -1 |
---|
267 | IF ( dz_stretch_level <= ABS( zu(k+1) ) .AND. & |
---|
268 | dz_stretched < dz_max ) THEN |
---|
269 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
270 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
271 | IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1 |
---|
272 | ENDIF |
---|
273 | zu(k) = zu(k+1) - dz_stretched |
---|
274 | ENDDO |
---|
275 | |
---|
276 | ! |
---|
277 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
278 | !-- corresponding u-levels, except in case of dirichlet bc for u and v |
---|
279 | !-- at the ground. In this case the first u- and w-level are defined at |
---|
280 | !-- same height. The top w-level (nzt+1) is not used but set for |
---|
281 | !-- consistency, since w and all scalar variables are defined up tp nzt+1. |
---|
282 | zw(nzt+1) = dz |
---|
283 | zw(nzt) = 0.0 |
---|
284 | DO k = 0, nzt |
---|
285 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5 |
---|
286 | ENDDO |
---|
287 | |
---|
288 | ! |
---|
289 | !-- In case of dirichlet bc for u and v the first u- and w-level are defined |
---|
290 | !-- at same height. |
---|
291 | IF ( ibc_uv_b == 0 ) THEN |
---|
292 | zu(0) = zw(0) |
---|
293 | ENDIF |
---|
294 | |
---|
295 | ENDIF |
---|
296 | |
---|
297 | ! |
---|
298 | !-- Compute grid lengths. |
---|
299 | DO k = 1, nzt+1 |
---|
300 | dzu(k) = zu(k) - zu(k-1) |
---|
301 | ddzu(k) = 1.0 / dzu(k) |
---|
302 | dzw(k) = zw(k) - zw(k-1) |
---|
303 | ddzw(k) = 1.0 / dzw(k) |
---|
304 | ENDDO |
---|
305 | |
---|
306 | DO k = 1, nzt |
---|
307 | dd2zu(k) = 1.0 / ( dzu(k) + dzu(k+1) ) |
---|
308 | ENDDO |
---|
309 | |
---|
310 | ! |
---|
311 | !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid |
---|
312 | !-- everywhere. For the actual grid, the grid spacing at the lowest level |
---|
313 | !-- is only dz/2, but should be dz. Therefore, an additional array |
---|
314 | !-- containing with appropriate grid information is created for these |
---|
315 | !-- solvers. |
---|
316 | IF ( psolver /= 'multigrid' ) THEN |
---|
317 | ALLOCATE( ddzu_pres(1:nzt+1) ) |
---|
318 | ddzu_pres = ddzu |
---|
319 | ddzu_pres(1) = ddzu_pres(2) ! change for lowest level |
---|
320 | ENDIF |
---|
321 | |
---|
322 | ! |
---|
323 | !-- In case of multigrid method, compute grid lengths and grid factors for the |
---|
324 | !-- grid levels |
---|
325 | IF ( psolver == 'multigrid' ) THEN |
---|
326 | |
---|
327 | ALLOCATE( ddx2_mg(maximum_grid_level), ddy2_mg(maximum_grid_level), & |
---|
328 | dzu_mg(nzb+1:nzt+1,maximum_grid_level), & |
---|
329 | dzw_mg(nzb+1:nzt+1,maximum_grid_level), & |
---|
330 | f1_mg(nzb+1:nzt,maximum_grid_level), & |
---|
331 | f2_mg(nzb+1:nzt,maximum_grid_level), & |
---|
332 | f3_mg(nzb+1:nzt,maximum_grid_level) ) |
---|
333 | |
---|
334 | dzu_mg(:,maximum_grid_level) = dzu |
---|
335 | ! |
---|
336 | !-- Next line to ensure an equally spaced grid. |
---|
337 | dzu_mg(1,maximum_grid_level) = dzu(2) |
---|
338 | |
---|
339 | dzw_mg(:,maximum_grid_level) = dzw |
---|
340 | nzt_l = nzt |
---|
341 | DO l = maximum_grid_level-1, 1, -1 |
---|
342 | dzu_mg(nzb+1,l) = 2.0 * dzu_mg(nzb+1,l+1) |
---|
343 | dzw_mg(nzb+1,l) = 2.0 * dzw_mg(nzb+1,l+1) |
---|
344 | nzt_l = nzt_l / 2 |
---|
345 | DO k = 2, nzt_l+1 |
---|
346 | dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1) |
---|
347 | dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1) |
---|
348 | ENDDO |
---|
349 | ENDDO |
---|
350 | |
---|
351 | nzt_l = nzt |
---|
352 | dx_l = dx |
---|
353 | dy_l = dy |
---|
354 | DO l = maximum_grid_level, 1, -1 |
---|
355 | ddx2_mg(l) = 1.0 / dx_l**2 |
---|
356 | ddy2_mg(l) = 1.0 / dy_l**2 |
---|
357 | DO k = nzb+1, nzt_l |
---|
358 | f2_mg(k,l) = 1.0 / ( dzu_mg(k+1,l) * dzw_mg(k,l) ) |
---|
359 | f3_mg(k,l) = 1.0 / ( dzu_mg(k,l) * dzw_mg(k,l) ) |
---|
360 | f1_mg(k,l) = 2.0 * ( ddx2_mg(l) + ddy2_mg(l) ) + & |
---|
361 | f2_mg(k,l) + f3_mg(k,l) |
---|
362 | ENDDO |
---|
363 | nzt_l = nzt_l / 2 |
---|
364 | dx_l = dx_l * 2.0 |
---|
365 | dy_l = dy_l * 2.0 |
---|
366 | ENDDO |
---|
367 | |
---|
368 | ENDIF |
---|
369 | |
---|
370 | ! |
---|
371 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
372 | ddx = 1.0 / dx |
---|
373 | ddy = 1.0 / dy |
---|
374 | dx2 = dx * dx |
---|
375 | dy2 = dy * dy |
---|
376 | ddx2 = 1.0 / dx2 |
---|
377 | ddy2 = 1.0 / dy2 |
---|
378 | |
---|
379 | ! |
---|
380 | !-- Compute the grid-dependent mixing length. |
---|
381 | DO k = 1, nzt |
---|
382 | l_grid(k) = ( dx * dy * dzw(k) )**0.33333333333333_wp |
---|
383 | ENDDO |
---|
384 | |
---|
385 | ! |
---|
386 | !-- Allocate outer and inner index arrays for topography and set |
---|
387 | !-- defaults. |
---|
388 | !-- nzb_local has to contain additional layers of ghost points for calculating |
---|
389 | !-- the flag arrays needed for the multigrid method |
---|
390 | gls = 2**( maximum_grid_level ) |
---|
391 | IF ( gls < nbgp ) gls = nbgp |
---|
392 | |
---|
393 | ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr), & |
---|
394 | corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr), & |
---|
395 | nzb_local(-gls:ny+gls,-gls:nx+gls), & |
---|
396 | nzb_tmp(-nbgp:ny+nbgp,-nbgp:nx+nbgp), & |
---|
397 | wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr), & |
---|
398 | wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) ) |
---|
399 | ALLOCATE( fwxm(nysg:nyng,nxlg:nxrg), fwxp(nysg:nyng,nxlg:nxrg), & |
---|
400 | fwym(nysg:nyng,nxlg:nxrg), fwyp(nysg:nyng,nxlg:nxrg), & |
---|
401 | fxm(nysg:nyng,nxlg:nxrg), fxp(nysg:nyng,nxlg:nxrg), & |
---|
402 | fym(nysg:nyng,nxlg:nxrg), fyp(nysg:nyng,nxlg:nxrg), & |
---|
403 | nzb_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
404 | nzb_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
405 | nzb_u_inner(nysg:nyng,nxlg:nxrg), & |
---|
406 | nzb_u_outer(nysg:nyng,nxlg:nxrg), & |
---|
407 | nzb_v_inner(nysg:nyng,nxlg:nxrg), & |
---|
408 | nzb_v_outer(nysg:nyng,nxlg:nxrg), & |
---|
409 | nzb_w_inner(nysg:nyng,nxlg:nxrg), & |
---|
410 | nzb_w_outer(nysg:nyng,nxlg:nxrg), & |
---|
411 | nzb_diff_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
412 | nzb_diff_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
413 | nzb_diff_u(nysg:nyng,nxlg:nxrg), & |
---|
414 | nzb_diff_v(nysg:nyng,nxlg:nxrg), & |
---|
415 | nzb_2d(nysg:nyng,nxlg:nxrg), & |
---|
416 | rflags_s_inner(nzb:nzt+2,nysg:nyng,nxlg:nxrg), & |
---|
417 | rflags_invers(nysg:nyng,nxlg:nxrg,nzb:nzt+2), & |
---|
418 | wall_e_x(nysg:nyng,nxlg:nxrg), & |
---|
419 | wall_e_y(nysg:nyng,nxlg:nxrg), & |
---|
420 | wall_u(nysg:nyng,nxlg:nxrg), & |
---|
421 | wall_v(nysg:nyng,nxlg:nxrg), & |
---|
422 | wall_w_x(nysg:nyng,nxlg:nxrg), & |
---|
423 | wall_w_y(nysg:nyng,nxlg:nxrg) ) |
---|
424 | |
---|
425 | |
---|
426 | |
---|
427 | ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
428 | |
---|
429 | |
---|
430 | nzb_s_inner = nzb; nzb_s_outer = nzb |
---|
431 | nzb_u_inner = nzb; nzb_u_outer = nzb |
---|
432 | nzb_v_inner = nzb; nzb_v_outer = nzb |
---|
433 | nzb_w_inner = nzb; nzb_w_outer = nzb |
---|
434 | |
---|
435 | rflags_s_inner = 1.0 |
---|
436 | rflags_invers = 1.0 |
---|
437 | |
---|
438 | ! |
---|
439 | !-- Define vertical gridpoint from (or to) which on the usual finite difference |
---|
440 | !-- form (which does not use surface fluxes) is applied |
---|
441 | IF ( prandtl_layer .OR. use_surface_fluxes ) THEN |
---|
442 | nzb_diff = nzb + 2 |
---|
443 | ELSE |
---|
444 | nzb_diff = nzb + 1 |
---|
445 | ENDIF |
---|
446 | IF ( use_top_fluxes ) THEN |
---|
447 | nzt_diff = nzt - 1 |
---|
448 | ELSE |
---|
449 | nzt_diff = nzt |
---|
450 | ENDIF |
---|
451 | |
---|
452 | nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff |
---|
453 | nzb_diff_u = nzb_diff; nzb_diff_v = nzb_diff |
---|
454 | |
---|
455 | wall_e_x = 0.0; wall_e_y = 0.0; wall_u = 0.0; wall_v = 0.0 |
---|
456 | wall_w_x = 0.0; wall_w_y = 0.0 |
---|
457 | fwxp = 1.0; fwxm = 1.0; fwyp = 1.0; fwym = 1.0 |
---|
458 | fxp = 1.0; fxm = 1.0; fyp = 1.0; fym = 1.0 |
---|
459 | |
---|
460 | ! |
---|
461 | !-- Initialize near-wall mixing length l_wall only in the vertical direction |
---|
462 | !-- for the moment, |
---|
463 | !-- multiplication with wall_adjustment_factor near the end of this routine |
---|
464 | l_wall(nzb,:,:) = l_grid(1) |
---|
465 | DO k = nzb+1, nzt |
---|
466 | l_wall(k,:,:) = l_grid(k) |
---|
467 | ENDDO |
---|
468 | l_wall(nzt+1,:,:) = l_grid(nzt) |
---|
469 | |
---|
470 | ALLOCATE ( vertical_influence(nzb:nzt) ) |
---|
471 | DO k = 1, nzt |
---|
472 | vertical_influence(k) = MIN ( INT( l_grid(k) / & |
---|
473 | ( wall_adjustment_factor * dzw(k) ) + 0.5 ), nzt - k ) |
---|
474 | ENDDO |
---|
475 | |
---|
476 | DO k = 1, MAXVAL( nzb_s_inner ) |
---|
477 | IF ( l_grid(k) > 1.5 * dx * wall_adjustment_factor .OR. & |
---|
478 | l_grid(k) > 1.5 * dy * wall_adjustment_factor ) THEN |
---|
479 | WRITE( message_string, * ) 'grid anisotropy exceeds ', & |
---|
480 | 'threshold given by only local', & |
---|
481 | ' &horizontal reduction of near_wall ', & |
---|
482 | 'mixing length l_wall', & |
---|
483 | ' &starting from height level k = ', k, '.' |
---|
484 | CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 ) |
---|
485 | EXIT |
---|
486 | ENDIF |
---|
487 | ENDDO |
---|
488 | vertical_influence(0) = vertical_influence(1) |
---|
489 | |
---|
490 | DO i = nxlg, nxrg |
---|
491 | DO j = nysg, nyng |
---|
492 | DO k = nzb_s_inner(j,i) + 1, & |
---|
493 | nzb_s_inner(j,i) + vertical_influence(nzb_s_inner(j,i)) |
---|
494 | l_wall(k,j,i) = zu(k) - zw(nzb_s_inner(j,i)) |
---|
495 | ENDDO |
---|
496 | ENDDO |
---|
497 | ENDDO |
---|
498 | |
---|
499 | ! |
---|
500 | !-- Set outer and inner index arrays for non-flat topography. |
---|
501 | !-- Here consistency checks concerning domain size and periodicity are |
---|
502 | !-- necessary. |
---|
503 | !-- Within this SELECT CASE structure only nzb_local is initialized |
---|
504 | !-- individually depending on the chosen topography type, all other index |
---|
505 | !-- arrays are initialized further below. |
---|
506 | SELECT CASE ( TRIM( topography ) ) |
---|
507 | |
---|
508 | CASE ( 'flat' ) |
---|
509 | ! |
---|
510 | !-- nzb_local is required for the multigrid solver |
---|
511 | nzb_local = 0 |
---|
512 | |
---|
513 | CASE ( 'single_building' ) |
---|
514 | ! |
---|
515 | !-- Single rectangular building, by default centered in the middle of the |
---|
516 | !-- total domain |
---|
517 | blx = NINT( building_length_x / dx ) |
---|
518 | bly = NINT( building_length_y / dy ) |
---|
519 | bh = NINT( building_height / dz ) |
---|
520 | |
---|
521 | IF ( building_wall_left == 9999999.9_wp ) THEN |
---|
522 | building_wall_left = ( nx + 1 - blx ) / 2 * dx |
---|
523 | ENDIF |
---|
524 | bxl = NINT( building_wall_left / dx ) |
---|
525 | bxr = bxl + blx |
---|
526 | |
---|
527 | IF ( building_wall_south == 9999999.9_wp ) THEN |
---|
528 | building_wall_south = ( ny + 1 - bly ) / 2 * dy |
---|
529 | ENDIF |
---|
530 | bys = NINT( building_wall_south / dy ) |
---|
531 | byn = bys + bly |
---|
532 | |
---|
533 | ! |
---|
534 | !-- Building size has to meet some requirements |
---|
535 | IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & |
---|
536 | ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN |
---|
537 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
538 | '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & |
---|
539 | 'byn=', byn, 'nx=', nx, 'ny=', ny |
---|
540 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
541 | ENDIF |
---|
542 | |
---|
543 | ! |
---|
544 | !-- Define the building. |
---|
545 | nzb_local = 0 |
---|
546 | nzb_local(bys:byn,bxl:bxr) = bh |
---|
547 | |
---|
548 | CASE ( 'single_street_canyon' ) |
---|
549 | ! |
---|
550 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
551 | !-- The canyon is centered in the other direction by default. |
---|
552 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
553 | ! |
---|
554 | !-- Street canyon in y direction |
---|
555 | cwx = NINT( canyon_width_x / dx ) |
---|
556 | IF ( canyon_wall_left == 9999999.9_wp ) THEN |
---|
557 | canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx |
---|
558 | ENDIF |
---|
559 | cxl = NINT( canyon_wall_left / dx ) |
---|
560 | cxr = cxl + cwx |
---|
561 | |
---|
562 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
563 | ! |
---|
564 | !-- Street canyon in x direction |
---|
565 | cwy = NINT( canyon_width_y / dy ) |
---|
566 | IF ( canyon_wall_south == 9999999.9_wp ) THEN |
---|
567 | canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy |
---|
568 | ENDIF |
---|
569 | cys = NINT( canyon_wall_south / dy ) |
---|
570 | cyn = cys + cwy |
---|
571 | |
---|
572 | ELSE |
---|
573 | |
---|
574 | message_string = 'no street canyon width given' |
---|
575 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
576 | |
---|
577 | ENDIF |
---|
578 | |
---|
579 | ch = NINT( canyon_height / dz ) |
---|
580 | dp_level_ind_b = ch |
---|
581 | ! |
---|
582 | !-- Street canyon size has to meet some requirements |
---|
583 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
584 | IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & |
---|
585 | ( ch < 3 ) ) THEN |
---|
586 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
587 | '&cxl=', cxl, 'cxr=', cxr, & |
---|
588 | 'cwx=', cwx, & |
---|
589 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
590 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
591 | ENDIF |
---|
592 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
593 | IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & |
---|
594 | ( ch < 3 ) ) THEN |
---|
595 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
596 | '&cys=', cys, 'cyn=', cyn, & |
---|
597 | 'cwy=', cwy, & |
---|
598 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
599 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
600 | ENDIF |
---|
601 | ENDIF |
---|
602 | IF ( canyon_width_x /= 9999999.9_wp .AND. canyon_width_y /= 9999999.9_wp ) & |
---|
603 | THEN |
---|
604 | message_string = 'inconsistent canyon parameters:' // & |
---|
605 | '&street canyon can only be oriented' // & |
---|
606 | '&either in x- or in y-direction' |
---|
607 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
608 | ENDIF |
---|
609 | |
---|
610 | nzb_local = ch |
---|
611 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
612 | nzb_local(:,cxl+1:cxr-1) = 0 |
---|
613 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
614 | nzb_local(cys+1:cyn-1,:) = 0 |
---|
615 | ENDIF |
---|
616 | |
---|
617 | CASE ( 'read_from_file' ) |
---|
618 | |
---|
619 | ALLOCATE ( topo_height(0:ny,0:nx) ) |
---|
620 | |
---|
621 | DO ii = 0, io_blocks-1 |
---|
622 | IF ( ii == io_group ) THEN |
---|
623 | |
---|
624 | ! |
---|
625 | !-- Arbitrary irregular topography data in PALM format (exactly |
---|
626 | !-- matching the grid size and total domain size) |
---|
627 | OPEN( 90, FILE='TOPOGRAPHY_DATA'//coupling_char, STATUS='OLD', & |
---|
628 | FORM='FORMATTED', ERR=10 ) |
---|
629 | DO j = ny, 0, -1 |
---|
630 | READ( 90, *, ERR=11, END=11 ) ( topo_height(j,i), i = 0,nx ) |
---|
631 | ENDDO |
---|
632 | |
---|
633 | GOTO 12 |
---|
634 | |
---|
635 | 10 message_string = 'file TOPOGRAPHY'//coupling_char//' does not exist' |
---|
636 | CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 ) |
---|
637 | |
---|
638 | 11 message_string = 'errors in file TOPOGRAPHY_DATA'//coupling_char |
---|
639 | CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 ) |
---|
640 | |
---|
641 | 12 CLOSE( 90 ) |
---|
642 | |
---|
643 | ENDIF |
---|
644 | #if defined( __parallel ) && ! defined ( __check ) |
---|
645 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
646 | #endif |
---|
647 | ENDDO |
---|
648 | |
---|
649 | ! |
---|
650 | !-- Calculate the index height of the topography |
---|
651 | DO i = 0, nx |
---|
652 | DO j = 0, ny |
---|
653 | nzb_local(j,i) = NINT( topo_height(j,i) / dz ) |
---|
654 | ENDDO |
---|
655 | ENDDO |
---|
656 | |
---|
657 | DEALLOCATE ( topo_height ) |
---|
658 | ! |
---|
659 | !-- Add cyclic boundaries (additional layers are for calculating |
---|
660 | !-- flag arrays needed for the multigrid sover) |
---|
661 | nzb_local(-gls:-1,0:nx) = nzb_local(ny-gls+1:ny,0:nx) |
---|
662 | nzb_local(ny+1:ny+gls,0:nx) = nzb_local(0:gls-1,0:nx) |
---|
663 | nzb_local(:,-gls:-1) = nzb_local(:,nx-gls+1:nx) |
---|
664 | nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) |
---|
665 | |
---|
666 | CASE DEFAULT |
---|
667 | ! |
---|
668 | !-- The DEFAULT case is reached either if the parameter topography |
---|
669 | !-- contains a wrong character string or if the user has defined a special |
---|
670 | !-- case in the user interface. There, the subroutine user_init_grid |
---|
671 | !-- checks which of these two conditions applies. |
---|
672 | CALL user_init_grid( gls, nzb_local ) |
---|
673 | |
---|
674 | END SELECT |
---|
675 | ! |
---|
676 | !-- Determine the maximum level of topography. Furthermore it is used for |
---|
677 | !-- steering the degradation of order of the applied advection scheme. |
---|
678 | !-- In case of non-cyclic lateral boundaries, the order of the advection |
---|
679 | !-- scheme have to be reduced up to nzt (required at the lateral boundaries). |
---|
680 | nzb_max = MAXVAL( nzb_local ) |
---|
681 | IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR. & |
---|
682 | inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s ) THEN |
---|
683 | nzb_max = nzt |
---|
684 | ENDIF |
---|
685 | |
---|
686 | ! |
---|
687 | !-- Consistency checks and index array initialization are only required for |
---|
688 | !-- non-flat topography, also the initialization of topography height arrays |
---|
689 | !-- zu_s_inner and zw_w_inner |
---|
690 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
691 | |
---|
692 | ! |
---|
693 | !-- Consistency checks |
---|
694 | IF ( MINVAL( nzb_local ) < 0 .OR. MAXVAL( nzb_local ) > nz + 1 ) THEN |
---|
695 | WRITE( message_string, * ) 'nzb_local values are outside the', & |
---|
696 | 'model domain', & |
---|
697 | '&MINVAL( nzb_local ) = ', MINVAL(nzb_local), & |
---|
698 | '&MAXVAL( nzb_local ) = ', MAXVAL(nzb_local) |
---|
699 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
700 | ENDIF |
---|
701 | |
---|
702 | IF ( bc_lr == 'cyclic' ) THEN |
---|
703 | IF ( ANY( nzb_local(:,-1) /= nzb_local(:,nx) ) .OR. & |
---|
704 | ANY( nzb_local(:,0) /= nzb_local(:,nx+1) ) ) THEN |
---|
705 | message_string = 'nzb_local does not fulfill cyclic' // & |
---|
706 | ' boundary condition in x-direction' |
---|
707 | CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 ) |
---|
708 | ENDIF |
---|
709 | ENDIF |
---|
710 | IF ( bc_ns == 'cyclic' ) THEN |
---|
711 | IF ( ANY( nzb_local(-1,:) /= nzb_local(ny,:) ) .OR. & |
---|
712 | ANY( nzb_local(0,:) /= nzb_local(ny+1,:) ) ) THEN |
---|
713 | message_string = 'nzb_local does not fulfill cyclic' // & |
---|
714 | ' boundary condition in y-direction' |
---|
715 | CALL message( 'init_grid', 'PA0212', 1, 2, 0, 6, 0 ) |
---|
716 | ENDIF |
---|
717 | ENDIF |
---|
718 | |
---|
719 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
720 | ! |
---|
721 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
722 | !-- describes the actual total size of topography which is defined at the |
---|
723 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
724 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
725 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
726 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
727 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
728 | !-- to form the basis for nzb_s_inner. |
---|
729 | DO j = -gls, ny + gls |
---|
730 | DO i = -gls, nx |
---|
731 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) ) |
---|
732 | ENDDO |
---|
733 | ENDDO |
---|
734 | !-- apply cyclic boundary conditions in x-direction |
---|
735 | !(ist das erforderlich? Ursache von Seung Bus Fehler?) |
---|
736 | nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) |
---|
737 | DO i = -gls, nx + gls |
---|
738 | DO j = -gls, ny |
---|
739 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) ) |
---|
740 | ENDDO |
---|
741 | ENDDO |
---|
742 | !-- apply cyclic boundary conditions in y-direction |
---|
743 | !(ist das erforderlich? Ursache von Seung Bus Fehler?) |
---|
744 | nzb_local(ny+1:ny+gls,:) = nzb_local(0:gls-1,:) |
---|
745 | ENDIF |
---|
746 | |
---|
747 | ! |
---|
748 | !-- Initialize index arrays nzb_s_inner and nzb_w_inner |
---|
749 | nzb_s_inner = nzb_local(nysg:nyng,nxlg:nxrg) |
---|
750 | nzb_w_inner = nzb_local(nysg:nyng,nxlg:nxrg) |
---|
751 | |
---|
752 | ! |
---|
753 | !-- Initialize remaining index arrays: |
---|
754 | !-- first pre-initialize them with nzb_s_inner... |
---|
755 | nzb_u_inner = nzb_s_inner |
---|
756 | nzb_u_outer = nzb_s_inner |
---|
757 | nzb_v_inner = nzb_s_inner |
---|
758 | nzb_v_outer = nzb_s_inner |
---|
759 | nzb_w_outer = nzb_s_inner |
---|
760 | nzb_s_outer = nzb_s_inner |
---|
761 | |
---|
762 | ! |
---|
763 | !-- ...then extend pre-initialized arrays in their according directions |
---|
764 | !-- based on nzb_local using nzb_tmp as a temporary global index array |
---|
765 | |
---|
766 | ! |
---|
767 | !-- nzb_s_outer: |
---|
768 | !-- extend nzb_local east-/westwards first, then north-/southwards |
---|
769 | nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) |
---|
770 | DO j = -1, ny + 1 |
---|
771 | DO i = 0, nx |
---|
772 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & |
---|
773 | nzb_local(j,i+1) ) |
---|
774 | ENDDO |
---|
775 | ENDDO |
---|
776 | DO i = nxl, nxr |
---|
777 | DO j = nys, nyn |
---|
778 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
779 | nzb_tmp(j+1,i) ) |
---|
780 | ENDDO |
---|
781 | ! |
---|
782 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
783 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
784 | IF ( nys == 0 ) THEN |
---|
785 | j = -1 |
---|
786 | nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
787 | ENDIF |
---|
788 | IF ( nys == ny ) THEN |
---|
789 | j = ny + 1 |
---|
790 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
791 | ENDIF |
---|
792 | ENDDO |
---|
793 | ! |
---|
794 | !-- nzb_w_outer: |
---|
795 | !-- identical to nzb_s_outer |
---|
796 | nzb_w_outer = nzb_s_outer |
---|
797 | |
---|
798 | ! |
---|
799 | !-- nzb_u_inner: |
---|
800 | !-- extend nzb_local rightwards only |
---|
801 | nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) |
---|
802 | DO j = -1, ny + 1 |
---|
803 | DO i = 0, nx + 1 |
---|
804 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) |
---|
805 | ENDDO |
---|
806 | ENDDO |
---|
807 | nzb_u_inner = nzb_tmp(nysg:nyng,nxlg:nxrg) |
---|
808 | |
---|
809 | ! |
---|
810 | !-- nzb_u_outer: |
---|
811 | !-- extend current nzb_tmp (nzb_u_inner) north-/southwards |
---|
812 | DO i = nxl, nxr |
---|
813 | DO j = nys, nyn |
---|
814 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
815 | nzb_tmp(j+1,i) ) |
---|
816 | ENDDO |
---|
817 | ! |
---|
818 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
819 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
820 | IF ( nys == 0 ) THEN |
---|
821 | j = -1 |
---|
822 | nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
823 | ENDIF |
---|
824 | IF ( nys == ny ) THEN |
---|
825 | j = ny + 1 |
---|
826 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
827 | ENDIF |
---|
828 | ENDDO |
---|
829 | |
---|
830 | ! |
---|
831 | !-- nzb_v_inner: |
---|
832 | !-- extend nzb_local northwards only |
---|
833 | nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) |
---|
834 | DO i = -1, nx + 1 |
---|
835 | DO j = 0, ny + 1 |
---|
836 | nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) |
---|
837 | ENDDO |
---|
838 | ENDDO |
---|
839 | nzb_v_inner = nzb_tmp(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) |
---|
840 | |
---|
841 | ! |
---|
842 | !-- nzb_v_outer: |
---|
843 | !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards |
---|
844 | DO j = nys, nyn |
---|
845 | DO i = nxl, nxr |
---|
846 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & |
---|
847 | nzb_tmp(j,i+1) ) |
---|
848 | ENDDO |
---|
849 | ! |
---|
850 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
851 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
852 | IF ( nxl == 0 ) THEN |
---|
853 | i = -1 |
---|
854 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) |
---|
855 | ENDIF |
---|
856 | IF ( nxr == nx ) THEN |
---|
857 | i = nx + 1 |
---|
858 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) |
---|
859 | ENDIF |
---|
860 | ENDDO |
---|
861 | #if ! defined ( __check ) |
---|
862 | ! |
---|
863 | !-- Exchange of lateral boundary values (parallel computers) and cyclic |
---|
864 | !-- boundary conditions, if applicable. |
---|
865 | !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local |
---|
866 | !-- they do not require exchange and are not included here. |
---|
867 | CALL exchange_horiz_2d_int( nzb_u_inner ) |
---|
868 | CALL exchange_horiz_2d_int( nzb_u_outer ) |
---|
869 | CALL exchange_horiz_2d_int( nzb_v_inner ) |
---|
870 | CALL exchange_horiz_2d_int( nzb_v_outer ) |
---|
871 | CALL exchange_horiz_2d_int( nzb_w_outer ) |
---|
872 | CALL exchange_horiz_2d_int( nzb_s_outer ) |
---|
873 | |
---|
874 | ! |
---|
875 | !-- Allocate and set the arrays containing the topography height |
---|
876 | IF ( myid == 0 ) THEN |
---|
877 | |
---|
878 | ALLOCATE( zu_s_inner(0:nx+1,0:ny+1), zw_w_inner(0:nx+1,0:ny+1) ) |
---|
879 | |
---|
880 | DO i = 0, nx + 1 |
---|
881 | DO j = 0, ny + 1 |
---|
882 | zu_s_inner(i,j) = zu(nzb_local(j,i)) |
---|
883 | zw_w_inner(i,j) = zw(nzb_local(j,i)) |
---|
884 | ENDDO |
---|
885 | ENDDO |
---|
886 | |
---|
887 | ENDIF |
---|
888 | ! |
---|
889 | !-- Set flag arrays to be used for masking of grid points |
---|
890 | DO i = nxlg, nxrg |
---|
891 | DO j = nysg, nyng |
---|
892 | DO k = nzb, nzt+1 |
---|
893 | IF ( k <= nzb_s_inner(j,i) ) rflags_s_inner(k,j,i) = 0.0 |
---|
894 | IF ( k <= nzb_s_inner(j,i) ) rflags_invers(j,i,k) = 0.0 |
---|
895 | ENDDO |
---|
896 | ENDDO |
---|
897 | ENDDO |
---|
898 | #endif |
---|
899 | ENDIF |
---|
900 | |
---|
901 | #if ! defined ( __check ) |
---|
902 | ! |
---|
903 | !-- Preliminary: to be removed after completion of the topography code! |
---|
904 | !-- Set the former default k index arrays nzb_2d |
---|
905 | nzb_2d = nzb |
---|
906 | |
---|
907 | ! |
---|
908 | !-- Set the individual index arrays which define the k index from which on |
---|
909 | !-- the usual finite difference form (which does not use surface fluxes) is |
---|
910 | !-- applied |
---|
911 | IF ( prandtl_layer .OR. use_surface_fluxes ) THEN |
---|
912 | nzb_diff_u = nzb_u_inner + 2 |
---|
913 | nzb_diff_v = nzb_v_inner + 2 |
---|
914 | nzb_diff_s_inner = nzb_s_inner + 2 |
---|
915 | nzb_diff_s_outer = nzb_s_outer + 2 |
---|
916 | ELSE |
---|
917 | nzb_diff_u = nzb_u_inner + 1 |
---|
918 | nzb_diff_v = nzb_v_inner + 1 |
---|
919 | nzb_diff_s_inner = nzb_s_inner + 1 |
---|
920 | nzb_diff_s_outer = nzb_s_outer + 1 |
---|
921 | ENDIF |
---|
922 | |
---|
923 | ! |
---|
924 | !-- Calculation of wall switches and factors required by diffusion_u/v.f90 and |
---|
925 | !-- for limitation of near-wall mixing length l_wall further below |
---|
926 | corner_nl = 0 |
---|
927 | corner_nr = 0 |
---|
928 | corner_sl = 0 |
---|
929 | corner_sr = 0 |
---|
930 | wall_l = 0 |
---|
931 | wall_n = 0 |
---|
932 | wall_r = 0 |
---|
933 | wall_s = 0 |
---|
934 | |
---|
935 | DO i = nxl, nxr |
---|
936 | DO j = nys, nyn |
---|
937 | ! |
---|
938 | !-- u-component |
---|
939 | IF ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) THEN |
---|
940 | wall_u(j,i) = 1.0 ! north wall (location of adjacent fluid) |
---|
941 | fym(j,i) = 0.0 |
---|
942 | fyp(j,i) = 1.0 |
---|
943 | ELSEIF ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) THEN |
---|
944 | wall_u(j,i) = 1.0 ! south wall (location of adjacent fluid) |
---|
945 | fym(j,i) = 1.0 |
---|
946 | fyp(j,i) = 0.0 |
---|
947 | ENDIF |
---|
948 | ! |
---|
949 | !-- v-component |
---|
950 | IF ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) ) THEN |
---|
951 | wall_v(j,i) = 1.0 ! rigth wall (location of adjacent fluid) |
---|
952 | fxm(j,i) = 0.0 |
---|
953 | fxp(j,i) = 1.0 |
---|
954 | ELSEIF ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) ) THEN |
---|
955 | wall_v(j,i) = 1.0 ! left wall (location of adjacent fluid) |
---|
956 | fxm(j,i) = 1.0 |
---|
957 | fxp(j,i) = 0.0 |
---|
958 | ENDIF |
---|
959 | ! |
---|
960 | !-- w-component, also used for scalars, separate arrays for shear |
---|
961 | !-- production of tke |
---|
962 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) ) THEN |
---|
963 | wall_e_y(j,i) = 1.0 ! north wall (location of adjacent fluid) |
---|
964 | wall_w_y(j,i) = 1.0 |
---|
965 | fwym(j,i) = 0.0 |
---|
966 | fwyp(j,i) = 1.0 |
---|
967 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) ) THEN |
---|
968 | wall_e_y(j,i) = -1.0 ! south wall (location of adjacent fluid) |
---|
969 | wall_w_y(j,i) = 1.0 |
---|
970 | fwym(j,i) = 1.0 |
---|
971 | fwyp(j,i) = 0.0 |
---|
972 | ENDIF |
---|
973 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) ) THEN |
---|
974 | wall_e_x(j,i) = 1.0 ! right wall (location of adjacent fluid) |
---|
975 | wall_w_x(j,i) = 1.0 |
---|
976 | fwxm(j,i) = 0.0 |
---|
977 | fwxp(j,i) = 1.0 |
---|
978 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) ) THEN |
---|
979 | wall_e_x(j,i) = -1.0 ! left wall (location of adjacent fluid) |
---|
980 | wall_w_x(j,i) = 1.0 |
---|
981 | fwxm(j,i) = 1.0 |
---|
982 | fwxp(j,i) = 0.0 |
---|
983 | ENDIF |
---|
984 | ! |
---|
985 | !-- Wall and corner locations inside buildings for limitation of |
---|
986 | !-- near-wall mixing length l_wall |
---|
987 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j+1,i) ) THEN |
---|
988 | |
---|
989 | wall_n(j,i) = nzb_s_inner(j+1,i) + 1 ! North wall |
---|
990 | |
---|
991 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
992 | corner_nl(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northleft corner |
---|
993 | nzb_s_inner(j,i-1) ) + 1 |
---|
994 | ENDIF |
---|
995 | |
---|
996 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
997 | corner_nr(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northright corner |
---|
998 | nzb_s_inner(j,i+1) ) + 1 |
---|
999 | ENDIF |
---|
1000 | |
---|
1001 | ENDIF |
---|
1002 | |
---|
1003 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j-1,i) ) THEN |
---|
1004 | |
---|
1005 | wall_s(j,i) = nzb_s_inner(j-1,i) + 1 ! South wall |
---|
1006 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
1007 | corner_sl(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southleft corner |
---|
1008 | nzb_s_inner(j,i-1) ) + 1 |
---|
1009 | ENDIF |
---|
1010 | |
---|
1011 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
1012 | corner_sr(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southright corner |
---|
1013 | nzb_s_inner(j,i+1) ) + 1 |
---|
1014 | ENDIF |
---|
1015 | |
---|
1016 | ENDIF |
---|
1017 | |
---|
1018 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
1019 | wall_l(j,i) = nzb_s_inner(j,i-1) + 1 ! Left wall |
---|
1020 | ENDIF |
---|
1021 | |
---|
1022 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
1023 | wall_r(j,i) = nzb_s_inner(j,i+1) + 1 ! Right wall |
---|
1024 | ENDIF |
---|
1025 | |
---|
1026 | ENDDO |
---|
1027 | ENDDO |
---|
1028 | |
---|
1029 | ! |
---|
1030 | !-- Calculate wall flag arrays for the multigrid method |
---|
1031 | IF ( psolver == 'multigrid' ) THEN |
---|
1032 | ! |
---|
1033 | !-- Gridpoint increment of the current level |
---|
1034 | inc = 1 |
---|
1035 | |
---|
1036 | DO l = maximum_grid_level, 1 , -1 |
---|
1037 | |
---|
1038 | nxl_l = nxl_mg(l) |
---|
1039 | nxr_l = nxr_mg(l) |
---|
1040 | nys_l = nys_mg(l) |
---|
1041 | nyn_l = nyn_mg(l) |
---|
1042 | nzt_l = nzt_mg(l) |
---|
1043 | |
---|
1044 | ! |
---|
1045 | !-- Assign the flag level to be calculated |
---|
1046 | SELECT CASE ( l ) |
---|
1047 | CASE ( 1 ) |
---|
1048 | flags => wall_flags_1 |
---|
1049 | CASE ( 2 ) |
---|
1050 | flags => wall_flags_2 |
---|
1051 | CASE ( 3 ) |
---|
1052 | flags => wall_flags_3 |
---|
1053 | CASE ( 4 ) |
---|
1054 | flags => wall_flags_4 |
---|
1055 | CASE ( 5 ) |
---|
1056 | flags => wall_flags_5 |
---|
1057 | CASE ( 6 ) |
---|
1058 | flags => wall_flags_6 |
---|
1059 | CASE ( 7 ) |
---|
1060 | flags => wall_flags_7 |
---|
1061 | CASE ( 8 ) |
---|
1062 | flags => wall_flags_8 |
---|
1063 | CASE ( 9 ) |
---|
1064 | flags => wall_flags_9 |
---|
1065 | CASE ( 10 ) |
---|
1066 | flags => wall_flags_10 |
---|
1067 | END SELECT |
---|
1068 | |
---|
1069 | ! |
---|
1070 | !-- Depending on the grid level, set the respective bits in case of |
---|
1071 | !-- neighbouring walls |
---|
1072 | !-- Bit 0: wall to the bottom |
---|
1073 | !-- Bit 1: wall to the top (not realized in remaining PALM code so far) |
---|
1074 | !-- Bit 2: wall to the south |
---|
1075 | !-- Bit 3: wall to the north |
---|
1076 | !-- Bit 4: wall to the left |
---|
1077 | !-- Bit 5: wall to the right |
---|
1078 | !-- Bit 6: inside building |
---|
1079 | |
---|
1080 | flags = 0 |
---|
1081 | |
---|
1082 | ! |
---|
1083 | !-- In case of masking method, flags are not set and multigrid method |
---|
1084 | !-- works like FFT-solver |
---|
1085 | IF ( .NOT. masking_method ) THEN |
---|
1086 | |
---|
1087 | DO i = nxl_l-1, nxr_l+1 |
---|
1088 | DO j = nys_l-1, nyn_l+1 |
---|
1089 | DO k = nzb, nzt_l+1 |
---|
1090 | |
---|
1091 | ! |
---|
1092 | !-- Inside/outside building (inside building does not need |
---|
1093 | !-- further tests for walls) |
---|
1094 | IF ( k*inc <= nzb_local(j*inc,i*inc) ) THEN |
---|
1095 | |
---|
1096 | flags(k,j,i) = IBSET( flags(k,j,i), 6 ) |
---|
1097 | |
---|
1098 | ELSE |
---|
1099 | ! |
---|
1100 | !-- Bottom wall |
---|
1101 | IF ( (k-1)*inc <= nzb_local(j*inc,i*inc) ) THEN |
---|
1102 | flags(k,j,i) = IBSET( flags(k,j,i), 0 ) |
---|
1103 | ENDIF |
---|
1104 | ! |
---|
1105 | !-- South wall |
---|
1106 | IF ( k*inc <= nzb_local((j-1)*inc,i*inc) ) THEN |
---|
1107 | flags(k,j,i) = IBSET( flags(k,j,i), 2 ) |
---|
1108 | ENDIF |
---|
1109 | ! |
---|
1110 | !-- North wall |
---|
1111 | IF ( k*inc <= nzb_local((j+1)*inc,i*inc) ) THEN |
---|
1112 | flags(k,j,i) = IBSET( flags(k,j,i), 3 ) |
---|
1113 | ENDIF |
---|
1114 | ! |
---|
1115 | !-- Left wall |
---|
1116 | IF ( k*inc <= nzb_local(j*inc,(i-1)*inc) ) THEN |
---|
1117 | flags(k,j,i) = IBSET( flags(k,j,i), 4 ) |
---|
1118 | ENDIF |
---|
1119 | ! |
---|
1120 | !-- Right wall |
---|
1121 | IF ( k*inc <= nzb_local(j*inc,(i+1)*inc) ) THEN |
---|
1122 | flags(k,j,i) = IBSET( flags(k,j,i), 5 ) |
---|
1123 | ENDIF |
---|
1124 | |
---|
1125 | ENDIF |
---|
1126 | |
---|
1127 | ENDDO |
---|
1128 | ENDDO |
---|
1129 | ENDDO |
---|
1130 | |
---|
1131 | ENDIF |
---|
1132 | |
---|
1133 | ! |
---|
1134 | !-- Test output of flag arrays |
---|
1135 | ! i = nxl_l |
---|
1136 | ! WRITE (9,*) ' ' |
---|
1137 | ! WRITE (9,*) '*** mg level ', l, ' ***', mg_switch_to_pe0_level |
---|
1138 | ! WRITE (9,*) ' inc=', inc, ' i =', nxl_l |
---|
1139 | ! WRITE (9,*) ' nxl_l',nxl_l,' nxr_l=',nxr_l,' nys_l=',nys_l,' nyn_l=',nyn_l |
---|
1140 | ! DO k = nzt_l+1, nzb, -1 |
---|
1141 | ! WRITE (9,'(194(1X,I2))') ( flags(k,j,i), j = nys_l-1, nyn_l+1 ) |
---|
1142 | ! ENDDO |
---|
1143 | |
---|
1144 | inc = inc * 2 |
---|
1145 | |
---|
1146 | ENDDO |
---|
1147 | |
---|
1148 | ENDIF |
---|
1149 | ! |
---|
1150 | !-- Allocate flags needed for masking walls. |
---|
1151 | ALLOCATE( wall_flags_0(nzb:nzt,nys:nyn,nxl:nxr), & |
---|
1152 | wall_flags_00(nzb:nzt,nys:nyn,nxl:nxr) ) |
---|
1153 | wall_flags_0 = 0 |
---|
1154 | wall_flags_00 = 0 |
---|
1155 | |
---|
1156 | IF ( scalar_advec == 'ws-scheme' ) THEN |
---|
1157 | ! |
---|
1158 | !-- Set flags to steer the degradation of the advection scheme in advec_ws |
---|
1159 | !-- near topography, inflow- and outflow boundaries as well as bottom and |
---|
1160 | !-- top of model domain. wall_flags_0 remains zero for all non-prognostic |
---|
1161 | !-- grid points. |
---|
1162 | DO i = nxl, nxr |
---|
1163 | DO j = nys, nyn |
---|
1164 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
1165 | ! |
---|
1166 | !-- scalar - x-direction |
---|
1167 | !-- WS1 (0), WS3 (1), WS5 (2) |
---|
1168 | IF ( k <= nzb_s_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& |
---|
1169 | .AND. i == nxl ) .OR. ( ( inflow_r .OR. outflow_r ) & |
---|
1170 | .AND. i == nxr ) ) THEN |
---|
1171 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 ) |
---|
1172 | ELSEIF ( k <= nzb_s_inner(j,i+2) .OR. k <= nzb_s_inner(j,i-1) & |
---|
1173 | .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & |
---|
1174 | .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & |
---|
1175 | ) THEN |
---|
1176 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 ) |
---|
1177 | ELSE |
---|
1178 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 2 ) |
---|
1179 | ENDIF |
---|
1180 | ! |
---|
1181 | !-- scalar - y-direction |
---|
1182 | !-- WS1 (3), WS3 (4), WS5 (5) |
---|
1183 | IF ( k <= nzb_s_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& |
---|
1184 | .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & |
---|
1185 | .AND. j == nyn ) ) THEN |
---|
1186 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 3 ) |
---|
1187 | !-- WS3 |
---|
1188 | ELSEIF ( k <= nzb_s_inner(j+2,i) .OR. k <= nzb_s_inner(j-1,i) & |
---|
1189 | .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & |
---|
1190 | .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & |
---|
1191 | ) THEN |
---|
1192 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 4 ) |
---|
1193 | !-- WS5 |
---|
1194 | ELSE |
---|
1195 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 5 ) |
---|
1196 | ENDIF |
---|
1197 | ! |
---|
1198 | !-- scalar - z-direction |
---|
1199 | !-- WS1 (6), WS3 (7), WS5 (8) |
---|
1200 | flag_set = .FALSE. |
---|
1201 | IF ( k == nzb_s_inner(j,i) + 1 .OR. k == nzt ) THEN |
---|
1202 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 6 ) |
---|
1203 | flag_set = .TRUE. |
---|
1204 | ELSEIF ( k == nzb_s_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN |
---|
1205 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 7 ) |
---|
1206 | flag_set = .TRUE. |
---|
1207 | ELSEIF ( k > nzb_s_inner(j,i) .AND. .NOT. flag_set ) THEN |
---|
1208 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) |
---|
1209 | ENDIF |
---|
1210 | ENDDO |
---|
1211 | ENDDO |
---|
1212 | ENDDO |
---|
1213 | ENDIF |
---|
1214 | |
---|
1215 | IF ( momentum_advec == 'ws-scheme' ) THEN |
---|
1216 | ! |
---|
1217 | !-- Set wall_flags_0 to steer the degradation of the advection scheme in advec_ws |
---|
1218 | !-- near topography, inflow- and outflow boundaries as well as bottom and |
---|
1219 | !-- top of model domain. wall_flags_0 remains zero for all non-prognostic |
---|
1220 | !-- grid points. |
---|
1221 | DO i = nxl, nxr |
---|
1222 | DO j = nys, nyn |
---|
1223 | DO k = nzb_u_inner(j,i)+1, nzt |
---|
1224 | ! |
---|
1225 | !-- u component - x-direction |
---|
1226 | !-- WS1 (9), WS3 (10), WS5 (11) |
---|
1227 | IF ( k <= nzb_u_inner(j,i+1) & |
---|
1228 | .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & |
---|
1229 | .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr ) & |
---|
1230 | ) THEN |
---|
1231 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 9 ) |
---|
1232 | ELSEIF ( k <= nzb_u_inner(j,i+2) .OR. k <= nzb_u_inner(j,i-1) & |
---|
1233 | .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 )& |
---|
1234 | .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu+1)& |
---|
1235 | ) THEN |
---|
1236 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 10 ) |
---|
1237 | ELSE |
---|
1238 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 11 ) |
---|
1239 | ENDIF |
---|
1240 | |
---|
1241 | ! |
---|
1242 | !-- u component - y-direction |
---|
1243 | !-- WS1 (12), WS3 (13), WS5 (14) |
---|
1244 | IF ( k <= nzb_u_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& |
---|
1245 | .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & |
---|
1246 | .AND. j == nyn ) ) THEN |
---|
1247 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 ) |
---|
1248 | ELSEIF ( k <= nzb_u_inner(j+2,i) .OR. k <= nzb_u_inner(j-1,i) & |
---|
1249 | .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & |
---|
1250 | .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & |
---|
1251 | ) THEN |
---|
1252 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 13 ) |
---|
1253 | ELSE |
---|
1254 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 14 ) |
---|
1255 | ENDIF |
---|
1256 | ! |
---|
1257 | !-- u component - z-direction |
---|
1258 | !-- WS1 (15), WS3 (16), WS5 (17) |
---|
1259 | flag_set = .FALSE. |
---|
1260 | IF ( k == nzb_u_inner(j,i) + 1 .OR. k == nzt ) THEN |
---|
1261 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 15 ) |
---|
1262 | flag_set = .TRUE. |
---|
1263 | ELSEIF ( k == nzb_u_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN |
---|
1264 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 16 ) |
---|
1265 | flag_set = .TRUE. |
---|
1266 | ELSEIF ( k > nzb_u_inner(j,i) .AND. .NOT. flag_set ) THEN |
---|
1267 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 17 ) |
---|
1268 | ENDIF |
---|
1269 | |
---|
1270 | ENDDO |
---|
1271 | ENDDO |
---|
1272 | ENDDO |
---|
1273 | |
---|
1274 | DO i = nxl, nxr |
---|
1275 | DO j = nys, nyn |
---|
1276 | DO k = nzb_v_inner(j,i)+1, nzt |
---|
1277 | ! |
---|
1278 | !-- v component - x-direction |
---|
1279 | !-- WS1 (18), WS3 (19), WS5 (20) |
---|
1280 | IF ( k <= nzb_v_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& |
---|
1281 | .AND. i == nxl ) .OR. (( inflow_r .OR. outflow_r ) & |
---|
1282 | .AND. i == nxr ) ) THEN |
---|
1283 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 ) |
---|
1284 | !-- WS3 |
---|
1285 | ELSEIF ( k <= nzb_v_inner(j,i+2) .OR. k <= nzb_v_inner(j,i-1) & |
---|
1286 | .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & |
---|
1287 | .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & |
---|
1288 | ) THEN |
---|
1289 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 19 ) |
---|
1290 | ELSE |
---|
1291 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 20 ) |
---|
1292 | ENDIF |
---|
1293 | ! |
---|
1294 | !-- v component - y-direction |
---|
1295 | !-- WS1 (21), WS3 (22), WS5 (23) |
---|
1296 | IF ( k <= nzb_v_inner(j+1,i) & |
---|
1297 | .OR. ( ( inflow_s .OR. outflow_s ) .AND. i == nysv ) & |
---|
1298 | .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn ) & |
---|
1299 | ) THEN |
---|
1300 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 ) |
---|
1301 | ELSEIF ( k <= nzb_v_inner(j+2,i) .OR. k <= nzb_v_inner(j-1,i) & |
---|
1302 | .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv+1 )& |
---|
1303 | .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 )& |
---|
1304 | ) THEN |
---|
1305 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 22 ) |
---|
1306 | ELSE |
---|
1307 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) |
---|
1308 | ENDIF |
---|
1309 | ! |
---|
1310 | !-- v component - z-direction |
---|
1311 | !-- WS1 (24), WS3 (25), WS5 (26) |
---|
1312 | flag_set = .FALSE. |
---|
1313 | IF ( k == nzb_v_inner(j,i) + 1 .OR. k == nzt ) THEN |
---|
1314 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 24 ) |
---|
1315 | flag_set = .TRUE. |
---|
1316 | ELSEIF ( k == nzb_v_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN |
---|
1317 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 25 ) |
---|
1318 | flag_set = .TRUE. |
---|
1319 | ELSEIF ( k > nzb_v_inner(j,i) .AND. .NOT. flag_set ) THEN |
---|
1320 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 26 ) |
---|
1321 | ENDIF |
---|
1322 | |
---|
1323 | ENDDO |
---|
1324 | ENDDO |
---|
1325 | ENDDO |
---|
1326 | DO i = nxl, nxr |
---|
1327 | DO j = nys, nyn |
---|
1328 | DO k = nzb_w_inner(j,i), nzt |
---|
1329 | ! |
---|
1330 | !-- w component - x-direction |
---|
1331 | !-- WS1 (27), WS3 (28), WS5 (29) |
---|
1332 | IF ( k <= nzb_w_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& |
---|
1333 | .AND. i == nxl ) .OR. ( ( inflow_r .OR. outflow_r ) & |
---|
1334 | .AND. i == nxr ) ) THEN |
---|
1335 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 ) |
---|
1336 | ELSEIF ( k <= nzb_w_inner(j,i+2) .OR. k <= nzb_w_inner(j,i-1) & |
---|
1337 | .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & |
---|
1338 | .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & |
---|
1339 | ) THEN |
---|
1340 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 28 ) |
---|
1341 | ELSE |
---|
1342 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i),29 ) |
---|
1343 | ENDIF |
---|
1344 | ! |
---|
1345 | !-- w component - y-direction |
---|
1346 | !-- WS1 (30), WS3 (31), WS5 (32) |
---|
1347 | IF ( k <= nzb_w_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& |
---|
1348 | .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & |
---|
1349 | .AND. j == nyn ) ) THEN |
---|
1350 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) |
---|
1351 | ELSEIF ( k <= nzb_w_inner(j+2,i) .OR. k <= nzb_w_inner(j-1,i) & |
---|
1352 | .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & |
---|
1353 | .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & |
---|
1354 | ) THEN |
---|
1355 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 31 ) |
---|
1356 | ELSE |
---|
1357 | wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 0 ) |
---|
1358 | ENDIF |
---|
1359 | ! |
---|
1360 | !-- w component - z-direction |
---|
1361 | !-- WS1 (33), WS3 (34), WS5 (35) |
---|
1362 | flag_set = .FALSE. |
---|
1363 | IF ( k == nzb_w_inner(j,i) .OR. k == nzb_w_inner(j,i) + 1 & |
---|
1364 | .OR. k == nzt ) THEN |
---|
1365 | ! |
---|
1366 | !-- Please note, at k == nzb_w_inner(j,i) a flag is explictely |
---|
1367 | !-- set, although this is not a prognostic level. However, |
---|
1368 | !-- contrary to the advection of u,v and s this is necessary |
---|
1369 | !-- because flux_t(nzb_w_inner(j,i)) is used for the tendency |
---|
1370 | !-- at k == nzb_w_inner(j,i)+1. |
---|
1371 | wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 1 ) |
---|
1372 | flag_set = .TRUE. |
---|
1373 | ELSEIF ( k == nzb_w_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN |
---|
1374 | wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 2 ) |
---|
1375 | flag_set = .TRUE. |
---|
1376 | ELSEIF ( k > nzb_w_inner(j,i) .AND. .NOT. flag_set ) THEN |
---|
1377 | wall_flags_00(k,j,i) = IBSET( wall_flags_00(k,j,i), 3 ) |
---|
1378 | ENDIF |
---|
1379 | |
---|
1380 | ENDDO |
---|
1381 | ENDDO |
---|
1382 | ENDDO |
---|
1383 | |
---|
1384 | ENDIF |
---|
1385 | |
---|
1386 | ! |
---|
1387 | !-- In case of topography: limit near-wall mixing length l_wall further: |
---|
1388 | !-- Go through all points of the subdomain one by one and look for the closest |
---|
1389 | !-- surface |
---|
1390 | IF ( TRIM(topography) /= 'flat' ) THEN |
---|
1391 | DO i = nxl, nxr |
---|
1392 | DO j = nys, nyn |
---|
1393 | |
---|
1394 | nzb_si = nzb_s_inner(j,i) |
---|
1395 | vi = vertical_influence(nzb_si) |
---|
1396 | |
---|
1397 | IF ( wall_n(j,i) > 0 ) THEN |
---|
1398 | ! |
---|
1399 | !-- North wall (y distance) |
---|
1400 | DO k = wall_n(j,i), nzb_si |
---|
1401 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), 0.5 * dy ) |
---|
1402 | ENDDO |
---|
1403 | ! |
---|
1404 | !-- Above North wall (yz distance) |
---|
1405 | DO k = nzb_si + 1, nzb_si + vi |
---|
1406 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), & |
---|
1407 | SQRT( 0.25 * dy**2 + & |
---|
1408 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1409 | ENDDO |
---|
1410 | ! |
---|
1411 | !-- Northleft corner (xy distance) |
---|
1412 | IF ( corner_nl(j,i) > 0 ) THEN |
---|
1413 | DO k = corner_nl(j,i), nzb_si |
---|
1414 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
1415 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1416 | ENDDO |
---|
1417 | ! |
---|
1418 | !-- Above Northleft corner (xyz distance) |
---|
1419 | DO k = nzb_si + 1, nzb_si + vi |
---|
1420 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
1421 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1422 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1423 | ENDDO |
---|
1424 | ENDIF |
---|
1425 | ! |
---|
1426 | !-- Northright corner (xy distance) |
---|
1427 | IF ( corner_nr(j,i) > 0 ) THEN |
---|
1428 | DO k = corner_nr(j,i), nzb_si |
---|
1429 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
1430 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1431 | ENDDO |
---|
1432 | ! |
---|
1433 | !-- Above northright corner (xyz distance) |
---|
1434 | DO k = nzb_si + 1, nzb_si + vi |
---|
1435 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
1436 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1437 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1438 | ENDDO |
---|
1439 | ENDIF |
---|
1440 | ENDIF |
---|
1441 | |
---|
1442 | IF ( wall_s(j,i) > 0 ) THEN |
---|
1443 | ! |
---|
1444 | !-- South wall (y distance) |
---|
1445 | DO k = wall_s(j,i), nzb_si |
---|
1446 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), 0.5 * dy ) |
---|
1447 | ENDDO |
---|
1448 | ! |
---|
1449 | !-- Above south wall (yz distance) |
---|
1450 | DO k = nzb_si + 1, & |
---|
1451 | nzb_si + vi |
---|
1452 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), & |
---|
1453 | SQRT( 0.25 * dy**2 + & |
---|
1454 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1455 | ENDDO |
---|
1456 | ! |
---|
1457 | !-- Southleft corner (xy distance) |
---|
1458 | IF ( corner_sl(j,i) > 0 ) THEN |
---|
1459 | DO k = corner_sl(j,i), nzb_si |
---|
1460 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1461 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1462 | ENDDO |
---|
1463 | ! |
---|
1464 | !-- Above southleft corner (xyz distance) |
---|
1465 | DO k = nzb_si + 1, nzb_si + vi |
---|
1466 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1467 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1468 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1469 | ENDDO |
---|
1470 | ENDIF |
---|
1471 | ! |
---|
1472 | !-- Southright corner (xy distance) |
---|
1473 | IF ( corner_sr(j,i) > 0 ) THEN |
---|
1474 | DO k = corner_sr(j,i), nzb_si |
---|
1475 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1476 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1477 | ENDDO |
---|
1478 | ! |
---|
1479 | !-- Above southright corner (xyz distance) |
---|
1480 | DO k = nzb_si + 1, nzb_si + vi |
---|
1481 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1482 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1483 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1484 | ENDDO |
---|
1485 | ENDIF |
---|
1486 | |
---|
1487 | ENDIF |
---|
1488 | |
---|
1489 | IF ( wall_l(j,i) > 0 ) THEN |
---|
1490 | ! |
---|
1491 | !-- Left wall (x distance) |
---|
1492 | DO k = wall_l(j,i), nzb_si |
---|
1493 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), 0.5 * dx ) |
---|
1494 | ENDDO |
---|
1495 | ! |
---|
1496 | !-- Above left wall (xz distance) |
---|
1497 | DO k = nzb_si + 1, nzb_si + vi |
---|
1498 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), & |
---|
1499 | SQRT( 0.25 * dx**2 + & |
---|
1500 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1501 | ENDDO |
---|
1502 | ENDIF |
---|
1503 | |
---|
1504 | IF ( wall_r(j,i) > 0 ) THEN |
---|
1505 | ! |
---|
1506 | !-- Right wall (x distance) |
---|
1507 | DO k = wall_r(j,i), nzb_si |
---|
1508 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), 0.5 * dx ) |
---|
1509 | ENDDO |
---|
1510 | ! |
---|
1511 | !-- Above right wall (xz distance) |
---|
1512 | DO k = nzb_si + 1, nzb_si + vi |
---|
1513 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), & |
---|
1514 | SQRT( 0.25 * dx**2 + & |
---|
1515 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1516 | ENDDO |
---|
1517 | |
---|
1518 | ENDIF |
---|
1519 | |
---|
1520 | ENDDO |
---|
1521 | ENDDO |
---|
1522 | |
---|
1523 | ENDIF |
---|
1524 | |
---|
1525 | ! |
---|
1526 | !-- Multiplication with wall_adjustment_factor |
---|
1527 | l_wall = wall_adjustment_factor * l_wall |
---|
1528 | |
---|
1529 | ! |
---|
1530 | !-- Set lateral boundary conditions for l_wall |
---|
1531 | CALL exchange_horiz( l_wall, nbgp ) |
---|
1532 | |
---|
1533 | DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, & |
---|
1534 | nzb_tmp, vertical_influence, wall_l, wall_n, wall_r, wall_s ) |
---|
1535 | |
---|
1536 | #endif |
---|
1537 | |
---|
1538 | END SUBROUTINE init_grid |
---|