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