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