source: palm/trunk/SOURCE/init_grid.f90 @ 557

Last change on this file since 557 was 557, checked in by weinreis, 14 years ago

bugfix message string in set_mask_locations

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