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