1 | SUBROUTINE init_grid |
---|
2 | |
---|
3 | !------------------------------------------------------------------------------! |
---|
4 | ! Current revisions: |
---|
5 | ! ----------------- |
---|
6 | ! Output of messages replaced by message handling routine. |
---|
7 | ! new topography case 'single_street_canyon' |
---|
8 | ! |
---|
9 | ! Former revisions: |
---|
10 | ! ----------------- |
---|
11 | ! $Id: init_grid.f90 254 2009-03-05 15:33:42Z weinreis $ |
---|
12 | ! |
---|
13 | ! 217 2008-12-09 18:00:48Z letzel |
---|
14 | ! +topography_grid_convention |
---|
15 | ! |
---|
16 | ! 134 2007-11-21 07:28:38Z letzel |
---|
17 | ! Redefine initial nzb_local as the actual total size of topography (later the |
---|
18 | ! extent of topography in nzb_local is reduced by 1dx at the E topography walls |
---|
19 | ! and by 1dy at the N topography walls to form the basis for nzb_s_inner); |
---|
20 | ! for consistency redefine 'single_building' case. |
---|
21 | ! Calculation of wall flag arrays |
---|
22 | ! |
---|
23 | ! 94 2007-06-01 15:25:22Z raasch |
---|
24 | ! Grid definition for ocean version |
---|
25 | ! |
---|
26 | ! 75 2007-03-22 09:54:05Z raasch |
---|
27 | ! storage of topography height arrays zu_s_inner and zw_s_inner, |
---|
28 | ! 2nd+3rd argument removed from exchange horiz |
---|
29 | ! |
---|
30 | ! 19 2007-02-23 04:53:48Z raasch |
---|
31 | ! Setting of nzt_diff |
---|
32 | ! |
---|
33 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
34 | ! |
---|
35 | ! Revision 1.17 2006/08/22 14:00:05 raasch |
---|
36 | ! +dz_max to limit vertical stretching, |
---|
37 | ! bugfix in index array initialization for line- or point-like topography |
---|
38 | ! structures |
---|
39 | ! |
---|
40 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
41 | ! Initial revision (Testversion) |
---|
42 | ! |
---|
43 | ! |
---|
44 | ! Description: |
---|
45 | ! ------------ |
---|
46 | ! Creating grid depending constants |
---|
47 | !------------------------------------------------------------------------------! |
---|
48 | |
---|
49 | USE arrays_3d |
---|
50 | USE control_parameters |
---|
51 | USE grid_variables |
---|
52 | USE indices |
---|
53 | USE pegrid |
---|
54 | |
---|
55 | IMPLICIT NONE |
---|
56 | |
---|
57 | INTEGER :: bh, blx, bly, bxl, bxr, byn, bys, ch, cwx, cwy, cxl, cxr, cyn, & |
---|
58 | cys, gls, i, inc, i_center, j, j_center, k, l, nxl_l, nxr_l, & |
---|
59 | nyn_l, nys_l, nzb_si, nzt_l, vi |
---|
60 | |
---|
61 | INTEGER, DIMENSION(:), ALLOCATABLE :: vertical_influence |
---|
62 | |
---|
63 | INTEGER, DIMENSION(:,:), ALLOCATABLE :: corner_nl, corner_nr, corner_sl, & |
---|
64 | corner_sr, wall_l, wall_n, wall_r,& |
---|
65 | wall_s, nzb_local, nzb_tmp |
---|
66 | |
---|
67 | REAL :: dx_l, dy_l, dz_stretched |
---|
68 | |
---|
69 | REAL, DIMENSION(0:ny,0:nx) :: topo_height |
---|
70 | |
---|
71 | REAL, DIMENSION(:,:,:), ALLOCATABLE :: distance |
---|
72 | |
---|
73 | ! |
---|
74 | !-- Allocate grid arrays |
---|
75 | ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & |
---|
76 | dzw(1:nzt+1), l_grid(1:nzt), zu(0:nzt+1), zw(0:nzt+1) ) |
---|
77 | |
---|
78 | ! |
---|
79 | !-- Compute height of u-levels from constant grid length and dz stretch factors |
---|
80 | IF ( dz == -1.0 ) THEN |
---|
81 | message_string = 'missing dz' |
---|
82 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
83 | ELSEIF ( dz <= 0.0 ) THEN |
---|
84 | WRITE( message_string, * ) 'dz=',dz,' <= 0.0' |
---|
85 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
86 | ENDIF |
---|
87 | |
---|
88 | ! |
---|
89 | !-- Define the vertical grid levels |
---|
90 | IF ( .NOT. ocean ) THEN |
---|
91 | ! |
---|
92 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
93 | !-- Since the w-level lies on the surface, the first u-level (staggered!) |
---|
94 | !-- lies below the surface (used for "mirror" boundary condition). |
---|
95 | !-- The first u-level above the surface corresponds to the top of the |
---|
96 | !-- Prandtl-layer. |
---|
97 | zu(0) = - dz * 0.5 |
---|
98 | zu(1) = dz * 0.5 |
---|
99 | |
---|
100 | dz_stretch_level_index = nzt+1 |
---|
101 | dz_stretched = dz |
---|
102 | DO k = 2, nzt+1 |
---|
103 | IF ( dz_stretch_level <= zu(k-1) .AND. dz_stretched < dz_max ) THEN |
---|
104 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
105 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
106 | IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1 |
---|
107 | ENDIF |
---|
108 | zu(k) = zu(k-1) + dz_stretched |
---|
109 | ENDDO |
---|
110 | |
---|
111 | ! |
---|
112 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
113 | !-- corresponding u-levels. The top w-level is extrapolated linearly. |
---|
114 | zw(0) = 0.0 |
---|
115 | DO k = 1, nzt |
---|
116 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5 |
---|
117 | ENDDO |
---|
118 | zw(nzt+1) = zw(nzt) + 2.0 * ( zu(nzt+1) - zw(nzt) ) |
---|
119 | |
---|
120 | ELSE |
---|
121 | ! |
---|
122 | !-- Grid for ocean with solid surface at z=0 (k=0, w-grid). The free water |
---|
123 | !-- surface is at k=nzt (w-grid). |
---|
124 | !-- Since the w-level lies always on the surface, the first/last u-level |
---|
125 | !-- (staggered!) lies below the bottom surface / above the free surface. |
---|
126 | !-- It is used for "mirror" boundary condition. |
---|
127 | !-- The first u-level above the bottom surface corresponds to the top of the |
---|
128 | !-- Prandtl-layer. |
---|
129 | zu(nzt+1) = dz * 0.5 |
---|
130 | zu(nzt) = - dz * 0.5 |
---|
131 | |
---|
132 | dz_stretch_level_index = 0 |
---|
133 | dz_stretched = dz |
---|
134 | DO k = nzt-1, 0, -1 |
---|
135 | IF ( dz_stretch_level <= ABS( zu(k+1) ) .AND. & |
---|
136 | dz_stretched < dz_max ) THEN |
---|
137 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
138 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
139 | IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1 |
---|
140 | ENDIF |
---|
141 | zu(k) = zu(k+1) - dz_stretched |
---|
142 | ENDDO |
---|
143 | |
---|
144 | ! |
---|
145 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
146 | !-- corresponding u-levels. |
---|
147 | !-- The top w-level (nzt+1) is not used but set for consistency, since |
---|
148 | !-- w and all scalar variables are defined up tp nzt+1. |
---|
149 | zw(nzt+1) = dz |
---|
150 | zw(nzt) = 0.0 |
---|
151 | DO k = 0, nzt |
---|
152 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5 |
---|
153 | ENDDO |
---|
154 | |
---|
155 | ENDIF |
---|
156 | |
---|
157 | ! |
---|
158 | !-- Compute grid lengths. |
---|
159 | DO k = 1, nzt+1 |
---|
160 | dzu(k) = zu(k) - zu(k-1) |
---|
161 | ddzu(k) = 1.0 / dzu(k) |
---|
162 | dzw(k) = zw(k) - zw(k-1) |
---|
163 | ddzw(k) = 1.0 / dzw(k) |
---|
164 | ENDDO |
---|
165 | |
---|
166 | DO k = 1, nzt |
---|
167 | dd2zu(k) = 1.0 / ( dzu(k) + dzu(k+1) ) |
---|
168 | ENDDO |
---|
169 | |
---|
170 | ! |
---|
171 | !-- In case of multigrid method, compute grid lengths and grid factors for the |
---|
172 | !-- grid levels |
---|
173 | IF ( psolver == 'multigrid' ) THEN |
---|
174 | |
---|
175 | ALLOCATE( ddx2_mg(maximum_grid_level), ddy2_mg(maximum_grid_level), & |
---|
176 | dzu_mg(nzb+1:nzt+1,maximum_grid_level), & |
---|
177 | dzw_mg(nzb+1:nzt+1,maximum_grid_level), & |
---|
178 | f1_mg(nzb+1:nzt,maximum_grid_level), & |
---|
179 | f2_mg(nzb+1:nzt,maximum_grid_level), & |
---|
180 | f3_mg(nzb+1:nzt,maximum_grid_level) ) |
---|
181 | |
---|
182 | dzu_mg(:,maximum_grid_level) = dzu |
---|
183 | dzw_mg(:,maximum_grid_level) = dzw |
---|
184 | nzt_l = nzt |
---|
185 | DO l = maximum_grid_level-1, 1, -1 |
---|
186 | dzu_mg(nzb+1,l) = 2.0 * dzu_mg(nzb+1,l+1) |
---|
187 | dzw_mg(nzb+1,l) = 2.0 * dzw_mg(nzb+1,l+1) |
---|
188 | nzt_l = nzt_l / 2 |
---|
189 | DO k = 2, nzt_l+1 |
---|
190 | dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1) |
---|
191 | dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1) |
---|
192 | ENDDO |
---|
193 | ENDDO |
---|
194 | |
---|
195 | nzt_l = nzt |
---|
196 | dx_l = dx |
---|
197 | dy_l = dy |
---|
198 | DO l = maximum_grid_level, 1, -1 |
---|
199 | ddx2_mg(l) = 1.0 / dx_l**2 |
---|
200 | ddy2_mg(l) = 1.0 / dy_l**2 |
---|
201 | DO k = nzb+1, nzt_l |
---|
202 | f2_mg(k,l) = 1.0 / ( dzu_mg(k+1,l) * dzw_mg(k,l) ) |
---|
203 | f3_mg(k,l) = 1.0 / ( dzu_mg(k,l) * dzw_mg(k,l) ) |
---|
204 | f1_mg(k,l) = 2.0 * ( ddx2_mg(l) + ddy2_mg(l) ) + & |
---|
205 | f2_mg(k,l) + f3_mg(k,l) |
---|
206 | ENDDO |
---|
207 | nzt_l = nzt_l / 2 |
---|
208 | dx_l = dx_l * 2.0 |
---|
209 | dy_l = dy_l * 2.0 |
---|
210 | ENDDO |
---|
211 | |
---|
212 | ENDIF |
---|
213 | |
---|
214 | ! |
---|
215 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
216 | ddx = 1.0 / dx |
---|
217 | ddy = 1.0 / dy |
---|
218 | dx2 = dx * dx |
---|
219 | dy2 = dy * dy |
---|
220 | ddx2 = 1.0 / dx2 |
---|
221 | ddy2 = 1.0 / dy2 |
---|
222 | |
---|
223 | ! |
---|
224 | !-- Compute the grid-dependent mixing length. |
---|
225 | DO k = 1, nzt |
---|
226 | l_grid(k) = ( dx * dy * dzw(k) )**0.33333333333333 |
---|
227 | ENDDO |
---|
228 | |
---|
229 | ! |
---|
230 | !-- Allocate outer and inner index arrays for topography and set |
---|
231 | !-- defaults. |
---|
232 | !-- nzb_local has to contain additional layers of ghost points for calculating |
---|
233 | !-- the flag arrays needed for the multigrid method |
---|
234 | gls = 2**( maximum_grid_level ) |
---|
235 | ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr), & |
---|
236 | corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr), & |
---|
237 | nzb_local(-gls:ny+gls,-gls:nx+gls), nzb_tmp(-1:ny+1,-1:nx+1), & |
---|
238 | wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr), & |
---|
239 | wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) ) |
---|
240 | ALLOCATE( fwxm(nys-1:nyn+1,nxl-1:nxr+1), fwxp(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
241 | fwym(nys-1:nyn+1,nxl-1:nxr+1), fwyp(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
242 | fxm(nys-1:nyn+1,nxl-1:nxr+1), fxp(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
243 | fym(nys-1:nyn+1,nxl-1:nxr+1), fyp(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
244 | nzb_s_inner(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
245 | nzb_s_outer(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
246 | nzb_u_inner(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
247 | nzb_u_outer(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
248 | nzb_v_inner(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
249 | nzb_v_outer(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
250 | nzb_w_inner(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
251 | nzb_w_outer(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
252 | nzb_diff_s_inner(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
253 | nzb_diff_s_outer(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
254 | nzb_diff_u(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
255 | nzb_diff_v(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
256 | nzb_2d(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
257 | wall_e_x(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
258 | wall_e_y(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
259 | wall_u(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
260 | wall_v(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
261 | wall_w_x(nys-1:nyn+1,nxl-1:nxr+1), & |
---|
262 | wall_w_y(nys-1:nyn+1,nxl-1:nxr+1) ) |
---|
263 | |
---|
264 | ALLOCATE( l_wall(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) |
---|
265 | |
---|
266 | nzb_s_inner = nzb; nzb_s_outer = nzb |
---|
267 | nzb_u_inner = nzb; nzb_u_outer = nzb |
---|
268 | nzb_v_inner = nzb; nzb_v_outer = nzb |
---|
269 | nzb_w_inner = nzb; nzb_w_outer = nzb |
---|
270 | |
---|
271 | ! |
---|
272 | !-- Define vertical gridpoint from (or to) which on the usual finite difference |
---|
273 | !-- form (which does not use surface fluxes) is applied |
---|
274 | IF ( prandtl_layer .OR. use_surface_fluxes ) THEN |
---|
275 | nzb_diff = nzb + 2 |
---|
276 | ELSE |
---|
277 | nzb_diff = nzb + 1 |
---|
278 | ENDIF |
---|
279 | IF ( use_top_fluxes ) THEN |
---|
280 | nzt_diff = nzt - 1 |
---|
281 | ELSE |
---|
282 | nzt_diff = nzt |
---|
283 | ENDIF |
---|
284 | |
---|
285 | nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff |
---|
286 | nzb_diff_u = nzb_diff; nzb_diff_v = nzb_diff |
---|
287 | |
---|
288 | wall_e_x = 0.0; wall_e_y = 0.0; wall_u = 0.0; wall_v = 0.0 |
---|
289 | wall_w_x = 0.0; wall_w_y = 0.0 |
---|
290 | fwxp = 1.0; fwxm = 1.0; fwyp = 1.0; fwym = 1.0 |
---|
291 | fxp = 1.0; fxm = 1.0; fyp = 1.0; fym = 1.0 |
---|
292 | |
---|
293 | ! |
---|
294 | !-- Initialize near-wall mixing length l_wall only in the vertical direction |
---|
295 | !-- for the moment, |
---|
296 | !-- multiplication with wall_adjustment_factor near the end of this routine |
---|
297 | l_wall(nzb,:,:) = l_grid(1) |
---|
298 | DO k = nzb+1, nzt |
---|
299 | l_wall(k,:,:) = l_grid(k) |
---|
300 | ENDDO |
---|
301 | l_wall(nzt+1,:,:) = l_grid(nzt) |
---|
302 | |
---|
303 | ALLOCATE ( vertical_influence(nzb:nzt) ) |
---|
304 | DO k = 1, nzt |
---|
305 | vertical_influence(k) = MIN ( INT( l_grid(k) / & |
---|
306 | ( wall_adjustment_factor * dzw(k) ) + 0.5 ), nzt - k ) |
---|
307 | ENDDO |
---|
308 | |
---|
309 | DO k = 1, MAXVAL( nzb_s_inner ) |
---|
310 | IF ( l_grid(k) > 1.5 * dx * wall_adjustment_factor .OR. & |
---|
311 | l_grid(k) > 1.5 * dy * wall_adjustment_factor ) THEN |
---|
312 | WRITE( message_string, * ) 'grid anisotropy exceeds ', & |
---|
313 | 'threshold given by only local', & |
---|
314 | ' &horizontal reduction of near_wall ', & |
---|
315 | 'mixing length l_wall', & |
---|
316 | ' &starting from height level k = ', k, '.' |
---|
317 | CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 ) |
---|
318 | EXIT |
---|
319 | ENDIF |
---|
320 | ENDDO |
---|
321 | vertical_influence(0) = vertical_influence(1) |
---|
322 | |
---|
323 | DO i = nxl-1, nxr+1 |
---|
324 | DO j = nys-1, nyn+1 |
---|
325 | DO k = nzb_s_inner(j,i) + 1, & |
---|
326 | nzb_s_inner(j,i) + vertical_influence(nzb_s_inner(j,i)) |
---|
327 | l_wall(k,j,i) = zu(k) - zw(nzb_s_inner(j,i)) |
---|
328 | ENDDO |
---|
329 | ENDDO |
---|
330 | ENDDO |
---|
331 | |
---|
332 | ! |
---|
333 | !-- Set outer and inner index arrays for non-flat topography. |
---|
334 | !-- Here consistency checks concerning domain size and periodicity are |
---|
335 | !-- necessary. |
---|
336 | !-- Within this SELECT CASE structure only nzb_local is initialized |
---|
337 | !-- individually depending on the chosen topography type, all other index |
---|
338 | !-- arrays are initialized further below. |
---|
339 | SELECT CASE ( TRIM( topography ) ) |
---|
340 | |
---|
341 | CASE ( 'flat' ) |
---|
342 | ! |
---|
343 | !-- No actions necessary |
---|
344 | |
---|
345 | CASE ( 'single_building' ) |
---|
346 | ! |
---|
347 | !-- Single rectangular building, by default centered in the middle of the |
---|
348 | !-- total domain |
---|
349 | blx = NINT( building_length_x / dx ) |
---|
350 | bly = NINT( building_length_y / dy ) |
---|
351 | bh = NINT( building_height / dz ) |
---|
352 | |
---|
353 | IF ( building_wall_left == 9999999.9 ) THEN |
---|
354 | building_wall_left = ( nx + 1 - blx ) / 2 * dx |
---|
355 | ENDIF |
---|
356 | bxl = NINT( building_wall_left / dx ) |
---|
357 | bxr = bxl + blx |
---|
358 | |
---|
359 | IF ( building_wall_south == 9999999.9 ) THEN |
---|
360 | building_wall_south = ( ny + 1 - bly ) / 2 * dy |
---|
361 | ENDIF |
---|
362 | bys = NINT( building_wall_south / dy ) |
---|
363 | byn = bys + bly |
---|
364 | |
---|
365 | ! |
---|
366 | !-- Building size has to meet some requirements |
---|
367 | IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & |
---|
368 | ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN |
---|
369 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
370 | '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & |
---|
371 | 'byn=', byn, 'nx=', nx, 'ny=', ny |
---|
372 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
373 | ENDIF |
---|
374 | |
---|
375 | ! |
---|
376 | !-- Define the building. |
---|
377 | nzb_local = 0 |
---|
378 | nzb_local(bys:byn,bxl:bxr) = bh |
---|
379 | |
---|
380 | CASE ( 'single_street_canyon' ) |
---|
381 | ! |
---|
382 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
383 | !-- The canyon is centered in the other direction by default. |
---|
384 | IF ( canyon_width_x /= 9999999.9 ) THEN |
---|
385 | ! |
---|
386 | !-- Street canyon in y direction |
---|
387 | cwx = NINT( canyon_width_x / dx ) |
---|
388 | IF ( canyon_wall_left == 9999999.9 ) THEN |
---|
389 | canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx |
---|
390 | ENDIF |
---|
391 | cxl = NINT( canyon_wall_left / dx ) |
---|
392 | cxr = cxl + cwx |
---|
393 | |
---|
394 | ELSEIF ( canyon_width_y /= 9999999.9 ) THEN |
---|
395 | ! |
---|
396 | !-- Street canyon in x direction |
---|
397 | cwy = NINT( canyon_width_y / dy ) |
---|
398 | IF ( canyon_wall_south == 9999999.9 ) THEN |
---|
399 | canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy |
---|
400 | ENDIF |
---|
401 | cys = NINT( canyon_wall_south / dy ) |
---|
402 | cyn = cys + cwy |
---|
403 | |
---|
404 | ELSE |
---|
405 | |
---|
406 | message_string = 'no street canyon width given' |
---|
407 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
408 | |
---|
409 | ENDIF |
---|
410 | |
---|
411 | ch = NINT( canyon_height / dz ) |
---|
412 | dp_level_ind_b = ch |
---|
413 | ! |
---|
414 | !-- Street canyon size has to meet some requirements |
---|
415 | IF ( canyon_width_x /= 9999999.9 ) THEN |
---|
416 | IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & |
---|
417 | ( ch < 3 ) ) THEN |
---|
418 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
419 | '&cxl=', cxl, 'cxr=', cxr, & |
---|
420 | 'cwx=', cwx, & |
---|
421 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
422 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
423 | ENDIF |
---|
424 | ELSEIF ( canyon_width_y /= 9999999.9 ) THEN |
---|
425 | IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & |
---|
426 | ( ch < 3 ) ) THEN |
---|
427 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
428 | '&cys=', cys, 'cyn=', cyn, & |
---|
429 | 'cwy=', cwy, & |
---|
430 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
431 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
432 | ENDIF |
---|
433 | ENDIF |
---|
434 | IF ( canyon_width_x /= 9999999.9 .AND. canyon_width_y /= 9999999.9 ) & |
---|
435 | THEN |
---|
436 | message_string = 'inconsistent canyon parameters:' // & |
---|
437 | '&street canyon can only be oriented' // & |
---|
438 | '&either in x- or in y-direction' |
---|
439 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
440 | ENDIF |
---|
441 | |
---|
442 | nzb_local = ch |
---|
443 | IF ( canyon_width_x /= 9999999.9 ) THEN |
---|
444 | nzb_local(:,cxl+1:cxr-1) = 0 |
---|
445 | ELSEIF ( canyon_width_y /= 9999999.9 ) THEN |
---|
446 | nzb_local(cys+1:cyn-1,:) = 0 |
---|
447 | ENDIF |
---|
448 | |
---|
449 | CASE ( 'read_from_file' ) |
---|
450 | ! |
---|
451 | !-- Arbitrary irregular topography data in PALM format (exactly matching |
---|
452 | !-- the grid size and total domain size) |
---|
453 | OPEN( 90, FILE='TOPOGRAPHY_DATA', STATUS='OLD', FORM='FORMATTED', & |
---|
454 | ERR=10 ) |
---|
455 | DO j = ny, 0, -1 |
---|
456 | READ( 90, *, ERR=11, END=11 ) ( topo_height(j,i), i = 0, nx ) |
---|
457 | ENDDO |
---|
458 | ! |
---|
459 | !-- Calculate the index height of the topography |
---|
460 | DO i = 0, nx |
---|
461 | DO j = 0, ny |
---|
462 | nzb_local(j,i) = NINT( topo_height(j,i) / dz ) |
---|
463 | ENDDO |
---|
464 | ENDDO |
---|
465 | ! |
---|
466 | !-- Add cyclic boundaries (additional layers are for calculating flag |
---|
467 | !-- arrays needed for the multigrid sover) |
---|
468 | nzb_local(-gls:-1,0:nx) = nzb_local(ny-gls+1:ny,0:nx) |
---|
469 | nzb_local(ny+1:ny+gls,0:nx) = nzb_local(0:gls-1,0:nx) |
---|
470 | nzb_local(:,-gls:-1) = nzb_local(:,nx-gls+1:nx) |
---|
471 | nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) |
---|
472 | |
---|
473 | GOTO 12 |
---|
474 | |
---|
475 | 10 message_string = 'file TOPOGRAPHY_DATA does not exist' |
---|
476 | CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 ) |
---|
477 | |
---|
478 | 11 message_string = 'errors in file TOPOGRAPHY_DATA' |
---|
479 | CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 ) |
---|
480 | |
---|
481 | 12 CLOSE( 90 ) |
---|
482 | |
---|
483 | CASE DEFAULT |
---|
484 | ! |
---|
485 | !-- The DEFAULT case is reached either if the parameter topography |
---|
486 | !-- contains a wrong character string or if the user has defined a special |
---|
487 | !-- case in the user interface. There, the subroutine user_init_grid |
---|
488 | !-- checks which of these two conditions applies. |
---|
489 | CALL user_init_grid( gls, nzb_local ) |
---|
490 | |
---|
491 | END SELECT |
---|
492 | |
---|
493 | ! |
---|
494 | !-- Test output of nzb_local -1:ny+1,-1:nx+1 |
---|
495 | ! WRITE (9,*) '*** nzb_local ***' |
---|
496 | ! DO j = ny+1, -1, -1 |
---|
497 | ! WRITE (9,'(194(1X,I2))') ( nzb_local(j,i), i = -1, nx+1 ) |
---|
498 | ! ENDDO |
---|
499 | |
---|
500 | ! |
---|
501 | !-- Consistency checks and index array initialization are only required for |
---|
502 | !-- non-flat topography, also the initialization of topography height arrays |
---|
503 | !-- zu_s_inner and zw_w_inner |
---|
504 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
505 | |
---|
506 | ! |
---|
507 | !-- Consistency checks |
---|
508 | IF ( MINVAL( nzb_local ) < 0 .OR. MAXVAL( nzb_local ) > nz + 1 ) THEN |
---|
509 | WRITE( message_string, * ) 'nzb_local values are outside the', & |
---|
510 | 'model domain', & |
---|
511 | '&MINVAL( nzb_local ) = ', MINVAL(nzb_local), & |
---|
512 | '&MAXVAL( nzb_local ) = ', MAXVAL(nzb_local) |
---|
513 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
514 | ENDIF |
---|
515 | |
---|
516 | IF ( bc_lr == 'cyclic' ) THEN |
---|
517 | IF ( ANY( nzb_local(:,-1) /= nzb_local(:,nx) ) .OR. & |
---|
518 | ANY( nzb_local(:,0) /= nzb_local(:,nx+1) ) ) THEN |
---|
519 | message_string = 'nzb_local does not fulfill cyclic' // & |
---|
520 | ' boundary condition in x-direction' |
---|
521 | CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 ) |
---|
522 | ENDIF |
---|
523 | ENDIF |
---|
524 | IF ( bc_ns == 'cyclic' ) THEN |
---|
525 | IF ( ANY( nzb_local(-1,:) /= nzb_local(ny,:) ) .OR. & |
---|
526 | ANY( nzb_local(0,:) /= nzb_local(ny+1,:) ) ) THEN |
---|
527 | message_string = 'nzb_local does not fulfill cyclic' // & |
---|
528 | ' boundary condition in y-direction' |
---|
529 | CALL message( 'init_grid', 'PA0212', 1, 2, 0, 6, 0 ) |
---|
530 | ENDIF |
---|
531 | ENDIF |
---|
532 | |
---|
533 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
534 | ! |
---|
535 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
536 | !-- describes the actual total size of topography which is defined at the |
---|
537 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
538 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
539 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
540 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
541 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
542 | !-- to form the basis for nzb_s_inner. |
---|
543 | DO j = -gls, ny + gls |
---|
544 | DO i = -gls, nx |
---|
545 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) ) |
---|
546 | ENDDO |
---|
547 | ENDDO |
---|
548 | !-- apply cyclic boundary conditions in x-direction |
---|
549 | !(ist das erforderlich? Ursache von Seung Bus Fehler?) |
---|
550 | nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) |
---|
551 | DO i = -gls, nx + gls |
---|
552 | DO j = -gls, ny |
---|
553 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) ) |
---|
554 | ENDDO |
---|
555 | ENDDO |
---|
556 | !-- apply cyclic boundary conditions in y-direction |
---|
557 | !(ist das erforderlich? Ursache von Seung Bus Fehler?) |
---|
558 | nzb_local(ny+1:ny+gls,:) = nzb_local(0:gls-1,:) |
---|
559 | ENDIF |
---|
560 | |
---|
561 | ! |
---|
562 | !-- Initialize index arrays nzb_s_inner and nzb_w_inner |
---|
563 | nzb_s_inner = nzb_local(nys-1:nyn+1,nxl-1:nxr+1) |
---|
564 | nzb_w_inner = nzb_local(nys-1:nyn+1,nxl-1:nxr+1) |
---|
565 | |
---|
566 | ! |
---|
567 | !-- Initialize remaining index arrays: |
---|
568 | !-- first pre-initialize them with nzb_s_inner... |
---|
569 | nzb_u_inner = nzb_s_inner |
---|
570 | nzb_u_outer = nzb_s_inner |
---|
571 | nzb_v_inner = nzb_s_inner |
---|
572 | nzb_v_outer = nzb_s_inner |
---|
573 | nzb_w_outer = nzb_s_inner |
---|
574 | nzb_s_outer = nzb_s_inner |
---|
575 | |
---|
576 | ! |
---|
577 | !-- ...then extend pre-initialized arrays in their according directions |
---|
578 | !-- based on nzb_local using nzb_tmp as a temporary global index array |
---|
579 | |
---|
580 | ! |
---|
581 | !-- nzb_s_outer: |
---|
582 | !-- extend nzb_local east-/westwards first, then north-/southwards |
---|
583 | nzb_tmp = nzb_local(-1:ny+1,-1:nx+1) |
---|
584 | DO j = -1, ny + 1 |
---|
585 | DO i = 0, nx |
---|
586 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & |
---|
587 | nzb_local(j,i+1) ) |
---|
588 | ENDDO |
---|
589 | ENDDO |
---|
590 | DO i = nxl, nxr |
---|
591 | DO j = nys, nyn |
---|
592 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
593 | nzb_tmp(j+1,i) ) |
---|
594 | ENDDO |
---|
595 | ! |
---|
596 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
597 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
598 | IF ( nys == 0 ) THEN |
---|
599 | j = -1 |
---|
600 | nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
601 | ENDIF |
---|
602 | IF ( nys == ny ) THEN |
---|
603 | j = ny + 1 |
---|
604 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
605 | ENDIF |
---|
606 | ENDDO |
---|
607 | ! |
---|
608 | !-- nzb_w_outer: |
---|
609 | !-- identical to nzb_s_outer |
---|
610 | nzb_w_outer = nzb_s_outer |
---|
611 | |
---|
612 | ! |
---|
613 | !-- nzb_u_inner: |
---|
614 | !-- extend nzb_local rightwards only |
---|
615 | nzb_tmp = nzb_local(-1:ny+1,-1:nx+1) |
---|
616 | DO j = -1, ny + 1 |
---|
617 | DO i = 0, nx + 1 |
---|
618 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) |
---|
619 | ENDDO |
---|
620 | ENDDO |
---|
621 | nzb_u_inner = nzb_tmp(nys-1:nyn+1,nxl-1:nxr+1) |
---|
622 | |
---|
623 | ! |
---|
624 | !-- nzb_u_outer: |
---|
625 | !-- extend current nzb_tmp (nzb_u_inner) north-/southwards |
---|
626 | DO i = nxl, nxr |
---|
627 | DO j = nys, nyn |
---|
628 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
629 | nzb_tmp(j+1,i) ) |
---|
630 | ENDDO |
---|
631 | ! |
---|
632 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
633 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
634 | IF ( nys == 0 ) THEN |
---|
635 | j = -1 |
---|
636 | nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
637 | ENDIF |
---|
638 | IF ( nys == ny ) THEN |
---|
639 | j = ny + 1 |
---|
640 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
641 | ENDIF |
---|
642 | ENDDO |
---|
643 | |
---|
644 | ! |
---|
645 | !-- nzb_v_inner: |
---|
646 | !-- extend nzb_local northwards only |
---|
647 | nzb_tmp = nzb_local(-1:ny+1,-1:nx+1) |
---|
648 | DO i = -1, nx + 1 |
---|
649 | DO j = 0, ny + 1 |
---|
650 | nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) |
---|
651 | ENDDO |
---|
652 | ENDDO |
---|
653 | nzb_v_inner = nzb_tmp(nys-1:nyn+1,nxl-1:nxr+1) |
---|
654 | |
---|
655 | ! |
---|
656 | !-- nzb_v_outer: |
---|
657 | !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards |
---|
658 | DO j = nys, nyn |
---|
659 | DO i = nxl, nxr |
---|
660 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & |
---|
661 | nzb_tmp(j,i+1) ) |
---|
662 | ENDDO |
---|
663 | ! |
---|
664 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
665 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
666 | IF ( nxl == 0 ) THEN |
---|
667 | i = -1 |
---|
668 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) |
---|
669 | ENDIF |
---|
670 | IF ( nxr == nx ) THEN |
---|
671 | i = nx + 1 |
---|
672 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) |
---|
673 | ENDIF |
---|
674 | ENDDO |
---|
675 | |
---|
676 | ! |
---|
677 | !-- Exchange of lateral boundary values (parallel computers) and cyclic |
---|
678 | !-- boundary conditions, if applicable. |
---|
679 | !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local |
---|
680 | !-- they do not require exchange and are not included here. |
---|
681 | CALL exchange_horiz_2d_int( nzb_u_inner ) |
---|
682 | CALL exchange_horiz_2d_int( nzb_u_outer ) |
---|
683 | CALL exchange_horiz_2d_int( nzb_v_inner ) |
---|
684 | CALL exchange_horiz_2d_int( nzb_v_outer ) |
---|
685 | CALL exchange_horiz_2d_int( nzb_w_outer ) |
---|
686 | CALL exchange_horiz_2d_int( nzb_s_outer ) |
---|
687 | |
---|
688 | ! |
---|
689 | !-- Allocate and set the arrays containing the topography height |
---|
690 | IF ( myid == 0 ) THEN |
---|
691 | |
---|
692 | ALLOCATE( zu_s_inner(0:nx+1,0:ny+1), zw_w_inner(0:nx+1,0:ny+1) ) |
---|
693 | |
---|
694 | DO i = 0, nx + 1 |
---|
695 | DO j = 0, ny + 1 |
---|
696 | zu_s_inner(i,j) = zu(nzb_local(j,i)) |
---|
697 | zw_w_inner(i,j) = zw(nzb_local(j,i)) |
---|
698 | ENDDO |
---|
699 | ENDDO |
---|
700 | |
---|
701 | ENDIF |
---|
702 | |
---|
703 | ENDIF |
---|
704 | |
---|
705 | ! |
---|
706 | !-- Preliminary: to be removed after completion of the topography code! |
---|
707 | !-- Set the former default k index arrays nzb_2d |
---|
708 | nzb_2d = nzb |
---|
709 | |
---|
710 | ! |
---|
711 | !-- Set the individual index arrays which define the k index from which on |
---|
712 | !-- the usual finite difference form (which does not use surface fluxes) is |
---|
713 | !-- applied |
---|
714 | IF ( prandtl_layer .OR. use_surface_fluxes ) THEN |
---|
715 | nzb_diff_u = nzb_u_inner + 2 |
---|
716 | nzb_diff_v = nzb_v_inner + 2 |
---|
717 | nzb_diff_s_inner = nzb_s_inner + 2 |
---|
718 | nzb_diff_s_outer = nzb_s_outer + 2 |
---|
719 | ELSE |
---|
720 | nzb_diff_u = nzb_u_inner + 1 |
---|
721 | nzb_diff_v = nzb_v_inner + 1 |
---|
722 | nzb_diff_s_inner = nzb_s_inner + 1 |
---|
723 | nzb_diff_s_outer = nzb_s_outer + 1 |
---|
724 | ENDIF |
---|
725 | |
---|
726 | ! |
---|
727 | !-- Calculation of wall switches and factors required by diffusion_u/v.f90 and |
---|
728 | !-- for limitation of near-wall mixing length l_wall further below |
---|
729 | corner_nl = 0 |
---|
730 | corner_nr = 0 |
---|
731 | corner_sl = 0 |
---|
732 | corner_sr = 0 |
---|
733 | wall_l = 0 |
---|
734 | wall_n = 0 |
---|
735 | wall_r = 0 |
---|
736 | wall_s = 0 |
---|
737 | |
---|
738 | DO i = nxl, nxr |
---|
739 | DO j = nys, nyn |
---|
740 | ! |
---|
741 | !-- u-component |
---|
742 | IF ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) THEN |
---|
743 | wall_u(j,i) = 1.0 ! north wall (location of adjacent fluid) |
---|
744 | fym(j,i) = 0.0 |
---|
745 | fyp(j,i) = 1.0 |
---|
746 | ELSEIF ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) THEN |
---|
747 | wall_u(j,i) = 1.0 ! south wall (location of adjacent fluid) |
---|
748 | fym(j,i) = 1.0 |
---|
749 | fyp(j,i) = 0.0 |
---|
750 | ENDIF |
---|
751 | ! |
---|
752 | !-- v-component |
---|
753 | IF ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) ) THEN |
---|
754 | wall_v(j,i) = 1.0 ! rigth wall (location of adjacent fluid) |
---|
755 | fxm(j,i) = 0.0 |
---|
756 | fxp(j,i) = 1.0 |
---|
757 | ELSEIF ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) ) THEN |
---|
758 | wall_v(j,i) = 1.0 ! left wall (location of adjacent fluid) |
---|
759 | fxm(j,i) = 1.0 |
---|
760 | fxp(j,i) = 0.0 |
---|
761 | ENDIF |
---|
762 | ! |
---|
763 | !-- w-component, also used for scalars, separate arrays for shear |
---|
764 | !-- production of tke |
---|
765 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) ) THEN |
---|
766 | wall_e_y(j,i) = 1.0 ! north wall (location of adjacent fluid) |
---|
767 | wall_w_y(j,i) = 1.0 |
---|
768 | fwym(j,i) = 0.0 |
---|
769 | fwyp(j,i) = 1.0 |
---|
770 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) ) THEN |
---|
771 | wall_e_y(j,i) = -1.0 ! south wall (location of adjacent fluid) |
---|
772 | wall_w_y(j,i) = 1.0 |
---|
773 | fwym(j,i) = 1.0 |
---|
774 | fwyp(j,i) = 0.0 |
---|
775 | ENDIF |
---|
776 | IF ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) ) THEN |
---|
777 | wall_e_x(j,i) = 1.0 ! right wall (location of adjacent fluid) |
---|
778 | wall_w_x(j,i) = 1.0 |
---|
779 | fwxm(j,i) = 0.0 |
---|
780 | fwxp(j,i) = 1.0 |
---|
781 | ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) ) THEN |
---|
782 | wall_e_x(j,i) = -1.0 ! left wall (location of adjacent fluid) |
---|
783 | wall_w_x(j,i) = 1.0 |
---|
784 | fwxm(j,i) = 1.0 |
---|
785 | fwxp(j,i) = 0.0 |
---|
786 | ENDIF |
---|
787 | ! |
---|
788 | !-- Wall and corner locations inside buildings for limitation of |
---|
789 | !-- near-wall mixing length l_wall |
---|
790 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j+1,i) ) THEN |
---|
791 | |
---|
792 | wall_n(j,i) = nzb_s_inner(j+1,i) + 1 ! North wall |
---|
793 | |
---|
794 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
795 | corner_nl(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northleft corner |
---|
796 | nzb_s_inner(j,i-1) ) + 1 |
---|
797 | ENDIF |
---|
798 | |
---|
799 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
800 | corner_nr(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northright corner |
---|
801 | nzb_s_inner(j,i+1) ) + 1 |
---|
802 | ENDIF |
---|
803 | |
---|
804 | ENDIF |
---|
805 | |
---|
806 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j-1,i) ) THEN |
---|
807 | |
---|
808 | wall_s(j,i) = nzb_s_inner(j-1,i) + 1 ! South wall |
---|
809 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
810 | corner_sl(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southleft corner |
---|
811 | nzb_s_inner(j,i-1) ) + 1 |
---|
812 | ENDIF |
---|
813 | |
---|
814 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
815 | corner_sr(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southright corner |
---|
816 | nzb_s_inner(j,i+1) ) + 1 |
---|
817 | ENDIF |
---|
818 | |
---|
819 | ENDIF |
---|
820 | |
---|
821 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN |
---|
822 | wall_l(j,i) = nzb_s_inner(j,i-1) + 1 ! Left wall |
---|
823 | ENDIF |
---|
824 | |
---|
825 | IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN |
---|
826 | wall_r(j,i) = nzb_s_inner(j,i+1) + 1 ! Right wall |
---|
827 | ENDIF |
---|
828 | |
---|
829 | ENDDO |
---|
830 | ENDDO |
---|
831 | |
---|
832 | ! |
---|
833 | !-- Calculate wall flag arrays for the multigrid method |
---|
834 | IF ( psolver == 'multigrid' ) THEN |
---|
835 | ! |
---|
836 | !-- Gridpoint increment of the current level |
---|
837 | inc = 1 |
---|
838 | |
---|
839 | DO l = maximum_grid_level, 1 , -1 |
---|
840 | |
---|
841 | nxl_l = nxl_mg(l) |
---|
842 | nxr_l = nxr_mg(l) |
---|
843 | nys_l = nys_mg(l) |
---|
844 | nyn_l = nyn_mg(l) |
---|
845 | nzt_l = nzt_mg(l) |
---|
846 | |
---|
847 | ! |
---|
848 | !-- Assign the flag level to be calculated |
---|
849 | SELECT CASE ( l ) |
---|
850 | CASE ( 1 ) |
---|
851 | flags => wall_flags_1 |
---|
852 | CASE ( 2 ) |
---|
853 | flags => wall_flags_2 |
---|
854 | CASE ( 3 ) |
---|
855 | flags => wall_flags_3 |
---|
856 | CASE ( 4 ) |
---|
857 | flags => wall_flags_4 |
---|
858 | CASE ( 5 ) |
---|
859 | flags => wall_flags_5 |
---|
860 | CASE ( 6 ) |
---|
861 | flags => wall_flags_6 |
---|
862 | CASE ( 7 ) |
---|
863 | flags => wall_flags_7 |
---|
864 | CASE ( 8 ) |
---|
865 | flags => wall_flags_8 |
---|
866 | CASE ( 9 ) |
---|
867 | flags => wall_flags_9 |
---|
868 | CASE ( 10 ) |
---|
869 | flags => wall_flags_10 |
---|
870 | END SELECT |
---|
871 | |
---|
872 | ! |
---|
873 | !-- Depending on the grid level, set the respective bits in case of |
---|
874 | !-- neighbouring walls |
---|
875 | !-- Bit 0: wall to the bottom |
---|
876 | !-- Bit 1: wall to the top (not realized in remaining PALM code so far) |
---|
877 | !-- Bit 2: wall to the south |
---|
878 | !-- Bit 3: wall to the north |
---|
879 | !-- Bit 4: wall to the left |
---|
880 | !-- Bit 5: wall to the right |
---|
881 | !-- Bit 6: inside building |
---|
882 | |
---|
883 | flags = 0 |
---|
884 | |
---|
885 | DO i = nxl_l-1, nxr_l+1 |
---|
886 | DO j = nys_l-1, nyn_l+1 |
---|
887 | DO k = nzb, nzt_l+1 |
---|
888 | |
---|
889 | ! |
---|
890 | !-- Inside/outside building (inside building does not need |
---|
891 | !-- further tests for walls) |
---|
892 | IF ( k*inc <= nzb_local(j*inc,i*inc) ) THEN |
---|
893 | |
---|
894 | flags(k,j,i) = IBSET( flags(k,j,i), 6 ) |
---|
895 | |
---|
896 | ELSE |
---|
897 | ! |
---|
898 | !-- Bottom wall |
---|
899 | IF ( (k-1)*inc <= nzb_local(j*inc,i*inc) ) THEN |
---|
900 | flags(k,j,i) = IBSET( flags(k,j,i), 0 ) |
---|
901 | ENDIF |
---|
902 | ! |
---|
903 | !-- South wall |
---|
904 | IF ( k*inc <= nzb_local((j-1)*inc,i*inc) ) THEN |
---|
905 | flags(k,j,i) = IBSET( flags(k,j,i), 2 ) |
---|
906 | ENDIF |
---|
907 | ! |
---|
908 | !-- North wall |
---|
909 | IF ( k*inc <= nzb_local((j+1)*inc,i*inc) ) THEN |
---|
910 | flags(k,j,i) = IBSET( flags(k,j,i), 3 ) |
---|
911 | ENDIF |
---|
912 | ! |
---|
913 | !-- Left wall |
---|
914 | IF ( k*inc <= nzb_local(j*inc,(i-1)*inc) ) THEN |
---|
915 | flags(k,j,i) = IBSET( flags(k,j,i), 4 ) |
---|
916 | ENDIF |
---|
917 | ! |
---|
918 | !-- Right wall |
---|
919 | IF ( k*inc <= nzb_local(j*inc,(i+1)*inc) ) THEN |
---|
920 | flags(k,j,i) = IBSET( flags(k,j,i), 5 ) |
---|
921 | ENDIF |
---|
922 | |
---|
923 | ENDIF |
---|
924 | |
---|
925 | ENDDO |
---|
926 | ENDDO |
---|
927 | ENDDO |
---|
928 | |
---|
929 | ! |
---|
930 | !-- Test output of flag arrays |
---|
931 | ! i = nxl_l |
---|
932 | ! WRITE (9,*) ' ' |
---|
933 | ! WRITE (9,*) '*** mg level ', l, ' ***', mg_switch_to_pe0_level |
---|
934 | ! WRITE (9,*) ' inc=', inc, ' i =', nxl_l |
---|
935 | ! WRITE (9,*) ' nxl_l',nxl_l,' nxr_l=',nxr_l,' nys_l=',nys_l,' nyn_l=',nyn_l |
---|
936 | ! DO k = nzt_l+1, nzb, -1 |
---|
937 | ! WRITE (9,'(194(1X,I2))') ( flags(k,j,i), j = nys_l-1, nyn_l+1 ) |
---|
938 | ! ENDDO |
---|
939 | |
---|
940 | inc = inc * 2 |
---|
941 | |
---|
942 | ENDDO |
---|
943 | |
---|
944 | ENDIF |
---|
945 | |
---|
946 | ! |
---|
947 | !-- In case of topography: limit near-wall mixing length l_wall further: |
---|
948 | !-- Go through all points of the subdomain one by one and look for the closest |
---|
949 | !-- surface |
---|
950 | IF ( TRIM(topography) /= 'flat' ) THEN |
---|
951 | DO i = nxl, nxr |
---|
952 | DO j = nys, nyn |
---|
953 | |
---|
954 | nzb_si = nzb_s_inner(j,i) |
---|
955 | vi = vertical_influence(nzb_si) |
---|
956 | |
---|
957 | IF ( wall_n(j,i) > 0 ) THEN |
---|
958 | ! |
---|
959 | !-- North wall (y distance) |
---|
960 | DO k = wall_n(j,i), nzb_si |
---|
961 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), 0.5 * dy ) |
---|
962 | ENDDO |
---|
963 | ! |
---|
964 | !-- Above North wall (yz distance) |
---|
965 | DO k = nzb_si + 1, nzb_si + vi |
---|
966 | l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), & |
---|
967 | SQRT( 0.25 * dy**2 + & |
---|
968 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
969 | ENDDO |
---|
970 | ! |
---|
971 | !-- Northleft corner (xy distance) |
---|
972 | IF ( corner_nl(j,i) > 0 ) THEN |
---|
973 | DO k = corner_nl(j,i), nzb_si |
---|
974 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
975 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
976 | ENDDO |
---|
977 | ! |
---|
978 | !-- Above Northleft corner (xyz distance) |
---|
979 | DO k = nzb_si + 1, nzb_si + vi |
---|
980 | l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & |
---|
981 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
982 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
983 | ENDDO |
---|
984 | ENDIF |
---|
985 | ! |
---|
986 | !-- Northright corner (xy distance) |
---|
987 | IF ( corner_nr(j,i) > 0 ) THEN |
---|
988 | DO k = corner_nr(j,i), nzb_si |
---|
989 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
990 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
991 | ENDDO |
---|
992 | ! |
---|
993 | !-- Above northright corner (xyz distance) |
---|
994 | DO k = nzb_si + 1, nzb_si + vi |
---|
995 | l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & |
---|
996 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
997 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
998 | ENDDO |
---|
999 | ENDIF |
---|
1000 | ENDIF |
---|
1001 | |
---|
1002 | IF ( wall_s(j,i) > 0 ) THEN |
---|
1003 | ! |
---|
1004 | !-- South wall (y distance) |
---|
1005 | DO k = wall_s(j,i), nzb_si |
---|
1006 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), 0.5 * dy ) |
---|
1007 | ENDDO |
---|
1008 | ! |
---|
1009 | !-- Above south wall (yz distance) |
---|
1010 | DO k = nzb_si + 1, & |
---|
1011 | nzb_si + vi |
---|
1012 | l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), & |
---|
1013 | SQRT( 0.25 * dy**2 + & |
---|
1014 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1015 | ENDDO |
---|
1016 | ! |
---|
1017 | !-- Southleft corner (xy distance) |
---|
1018 | IF ( corner_sl(j,i) > 0 ) THEN |
---|
1019 | DO k = corner_sl(j,i), nzb_si |
---|
1020 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1021 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1022 | ENDDO |
---|
1023 | ! |
---|
1024 | !-- Above southleft corner (xyz distance) |
---|
1025 | DO k = nzb_si + 1, nzb_si + vi |
---|
1026 | l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & |
---|
1027 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1028 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1029 | ENDDO |
---|
1030 | ENDIF |
---|
1031 | ! |
---|
1032 | !-- Southright corner (xy distance) |
---|
1033 | IF ( corner_sr(j,i) > 0 ) THEN |
---|
1034 | DO k = corner_sr(j,i), nzb_si |
---|
1035 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1036 | 0.5 * SQRT( dx**2 + dy**2 ) ) |
---|
1037 | ENDDO |
---|
1038 | ! |
---|
1039 | !-- Above southright corner (xyz distance) |
---|
1040 | DO k = nzb_si + 1, nzb_si + vi |
---|
1041 | l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & |
---|
1042 | SQRT( 0.25 * (dx**2 + dy**2) + & |
---|
1043 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1044 | ENDDO |
---|
1045 | ENDIF |
---|
1046 | |
---|
1047 | ENDIF |
---|
1048 | |
---|
1049 | IF ( wall_l(j,i) > 0 ) THEN |
---|
1050 | ! |
---|
1051 | !-- Left wall (x distance) |
---|
1052 | DO k = wall_l(j,i), nzb_si |
---|
1053 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), 0.5 * dx ) |
---|
1054 | ENDDO |
---|
1055 | ! |
---|
1056 | !-- Above left wall (xz distance) |
---|
1057 | DO k = nzb_si + 1, nzb_si + vi |
---|
1058 | l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), & |
---|
1059 | SQRT( 0.25 * dx**2 + & |
---|
1060 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1061 | ENDDO |
---|
1062 | ENDIF |
---|
1063 | |
---|
1064 | IF ( wall_r(j,i) > 0 ) THEN |
---|
1065 | ! |
---|
1066 | !-- Right wall (x distance) |
---|
1067 | DO k = wall_r(j,i), nzb_si |
---|
1068 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), 0.5 * dx ) |
---|
1069 | ENDDO |
---|
1070 | ! |
---|
1071 | !-- Above right wall (xz distance) |
---|
1072 | DO k = nzb_si + 1, nzb_si + vi |
---|
1073 | l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), & |
---|
1074 | SQRT( 0.25 * dx**2 + & |
---|
1075 | ( zu(k) - zw(nzb_si) )**2 ) ) |
---|
1076 | ENDDO |
---|
1077 | |
---|
1078 | ENDIF |
---|
1079 | |
---|
1080 | ENDDO |
---|
1081 | ENDDO |
---|
1082 | |
---|
1083 | ENDIF |
---|
1084 | |
---|
1085 | ! |
---|
1086 | !-- Multiplication with wall_adjustment_factor |
---|
1087 | l_wall = wall_adjustment_factor * l_wall |
---|
1088 | |
---|
1089 | ! |
---|
1090 | !-- Need to set lateral boundary conditions for l_wall |
---|
1091 | CALL exchange_horiz( l_wall ) |
---|
1092 | |
---|
1093 | DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, & |
---|
1094 | nzb_tmp, vertical_influence, wall_l, wall_n, wall_r, wall_s ) |
---|
1095 | |
---|
1096 | |
---|
1097 | END SUBROUTINE init_grid |
---|