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