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