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

Last change on this file since 555 was 555, checked in by raasch, 14 years ago

New:
---

Changed:


Documentation for surface_heatflux in case of prandtl_layer = .F. improved.

bugfix for wrong netcdf/3.6.3 module on lcsgi (mbuild, mrun)

Errors:


Bugfix in if statement (disturb_heatflux)

Bugfix: in 2201 statement: closing " was missing (interpret_config)

Bugfix: default setting of nzb_local for flat topography (init_grid)

Bugfix: wrong dimension used for ts_value_l (user_statistics)

disturb_heatflux, init_grid, interpret_config, user_statistics

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