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

Last change on this file since 2037 was 2037, checked in by knoop, 7 years ago

Anelastic approximation implemented

  • Property svn:keywords set to Id
File size: 60.7 KB
Line 
1!> @file init_grid.f90
2!------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2016 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! Anelastic approximation implemented
23!
24! Former revisions:
25! -----------------
26! $Id: init_grid.f90 2037 2016-10-26 11:15:40Z knoop $
27!
28! 2021 2016-10-07 14:08:57Z suehring
29! Bugfix: setting Neumann boundary conditions for topography required for
30! topography flags in multigrid_noopt solver
31!
32! 2000 2016-08-20 18:09:15Z knoop
33! Forced header and separation lines into 80 columns
34!
35! 1994 2016-08-15 09:52:21Z suehring
36! Bugfix in definition of generic topography
37!
38! 1982 2016-08-01 11:04:48Z suehring
39! Bugfix concering consistency check for topography
40!
41! 1968 2016-07-18 12:01:49Z suehring
42! Changed: PE-wise reading of topography file in order to avoid global definition
43! of arrays nzb_local and nzb_tmp. Thereby, topography definition for single
44! buildings and street canyons has changed, as well as flag setting for
45! multigrid scheme.
46!
47! Bugfix in checking l_grid anisotropy.
48! Simplify initial computation of lwall and vertical_influence, i.e. remove
49! nzb_s_inner as it is still zero at this point.
50!
51! 1942 2016-06-14 12:18:18Z suehring
52! Topography filter implemented to fill holes resolved by only one grid point.
53! Initialization of flags for ws-scheme moved to advec_ws. 
54!
55! 1931 2016-06-10 12:06:59Z suehring
56! Rename multigrid into multigrid_noopt and multigrid_fast into multigrid
57!
58! 1910 2016-05-26 06:49:46Z raasch
59! Bugfix: if topography is read from file, Neumann conditions are used for the
60! nzb_local array (instead of cyclic conditions) in case that non-cyclic
61! boundary conditions are switched on for the run
62!
63! 1902 2016-05-09 11:18:56Z suehring
64! Set topography flags for multigrid solver only (not for multigrid_fast)
65!
66! 1886 2016-04-21 11:20:47Z suehring
67! Bugfix: setting advection flags near walls
68! reformulated index values for nzb_v_inner
69! variable discriptions added in declaration block
70!
71! 1845 2016-04-08 08:29:13Z raasch
72! nzb_2d removed
73!
74! 1804 2016-04-05 16:30:18Z maronga
75! Removed code for parameter file check (__check)
76!
77! 1779 2016-03-03 08:01:28Z raasch
78! coupling_char is trimmed at every place it occurs, because it can have
79! different length now
80!
81! 1762 2016-02-25 12:31:13Z hellstea
82! Introduction of nested domain feature
83!
84! 1743 2016-01-13 10:23:51Z raasch
85! Bugfix for calculation of nzb_s_outer and nzb_u_outer at north boundary of
86! total domain
87!
88! 1691 2015-10-26 16:17:44Z maronga
89! Renamed prandtl_layer to constant_flux_layer.
90!
91! 1682 2015-10-07 23:56:08Z knoop
92! Code annotations made doxygen readable
93!
94! 1677 2015-10-02 13:25:23Z boeske
95! Bugfix: Ghost points are included in wall_flags_0 and wall_flags_00
96!
97! 1675 2015-10-02 08:28:59Z gronemeier
98! Bugfix: Definition of topography grid levels
99!
100! 1660 2015-09-21 08:15:16Z gronemeier
101! Bugfix: Definition of topography grid levels if vertical grid stretching
102!         starts below the maximum topography height.
103!
104! 1580 2015-04-10 13:43:49Z suehring
105! Bugfix: setting flags for 5th order scheme near buildings
106!
107! 1575 2015-03-27 09:56:27Z raasch
108! adjustments for psolver-queries
109!
110! 1557 2015-03-05 16:43:04Z suehring
111! Adjustment for monotoinic limiter
112!
113! 1418 2014-06-06 13:05:08Z fricke
114! Bugfix: Change if-condition for stretched grid in the ocean, with the old
115!          condition and a negative value for dz_stretch_level the condition
116!          was always true for the whole model domain
117!
118! 1409 2014-05-23 12:11:32Z suehring
119! Bugfix: set wall_flags_0 at inflow and outflow boundary also for i <= nxlu
120! j <= nysv
121!
122! 1353 2014-04-08 15:21:23Z heinze
123! REAL constants provided with KIND-attribute
124!
125! 1322 2014-03-20 16:38:49Z raasch
126! REAL constants defined as wp-kind
127!
128! 1320 2014-03-20 08:40:49Z raasch
129! ONLY-attribute added to USE-statements,
130! kind-parameters added to all INTEGER and REAL declaration statements,
131! kinds are defined in new module kinds,
132! revision history before 2012 removed,
133! comment fields (!:) to be used for variable explanations added to
134! all variable declaration statements
135!
136! 1221 2013-09-10 08:59:13Z raasch
137! wall_flags_00 introduced to hold bits 32-63,
138! additional 3D-flag arrays for replacing the 2D-index array nzb_s_inner in
139! loops optimized for openACC (pres + flow_statistics)
140!
141! 1092 2013-02-02 11:24:22Z raasch
142! unused variables removed
143!
144! 1069 2012-11-28 16:18:43Z maronga
145! bugfix: added coupling_char to TOPOGRAPHY_DATA to allow topography in the
146!         ocean model in case of coupled runs
147!
148! 1036 2012-10-22 13:43:42Z raasch
149! code put under GPL (PALM 3.9)
150!
151! 1015 2012-09-27 09:23:24Z raasch
152! lower index for calculating wall_flags_0 set to nzb_w_inner instead of
153! nzb_w_inner+1
154!
155! 996 2012-09-07 10:41:47Z raasch
156! little reformatting
157!
158! 978 2012-08-09 08:28:32Z fricke
159! Bugfix: nzb_max is set to nzt at non-cyclic lateral boundaries
160! Bugfix: Set wall_flags_0 for inflow boundary
161!
162! 927 2012-06-06 19:15:04Z raasch
163! Wall flags are not set for multigrid method in case of masking method
164!
165! 864 2012-03-27 15:10:33Z gryschka
166! In case of ocean and Dirichlet bottom bc for u and v dzu_mg and ddzu_pres
167! were not correctly defined for k=1.
168!
169! 861 2012-03-26 14:18:34Z suehring
170! Set wall_flags_0. The array is needed for degradation in ws-scheme near walls,
171! inflow and outflow boundaries as well as near the bottom and the top of the
172! model domain.!
173! Initialization of nzb_s_inner and nzb_w_inner.
174! gls has to be at least nbgp to do not exceed the array bounds of nzb_local
175! while setting wall_flags_0
176!
177! 843 2012-02-29 15:16:21Z gryschka
178! In case of ocean and dirichlet bc for u and v at the bottom
179! the first u-level ist defined at same height as the first w-level
180!
181! 818 2012-02-08 16:11:23Z maronga
182! Bugfix: topo_height is only required if topography is used. It is thus now
183! allocated in the topography branch
184!
185! 809 2012-01-30 13:32:58Z maronga
186! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives
187!
188! 807 2012-01-25 11:53:51Z maronga
189! New cpp directive "__check" implemented which is used by check_namelist_files
190!
191! Revision 1.1  1997/08/11 06:17:45  raasch
192! Initial revision (Testversion)
193!
194!
195! Description:
196! ------------
197!> Creating grid depending constants
198!------------------------------------------------------------------------------!
199 SUBROUTINE init_grid
200 
201    USE advec_ws,                                                              &
202        ONLY:  ws_init_flags
203
204    USE arrays_3d,                                                             &
205        ONLY:  dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzu_mg, dzw, dzw_mg, f1_mg,  &
206               f2_mg, f3_mg, l_grid, l_wall, zu, zw
207       
208    USE control_parameters,                                                    &
209        ONLY:  bc_lr_cyc, bc_ns_cyc, building_height, building_length_x,       &
210               building_length_y, building_wall_left, building_wall_south,     &
211               canyon_height, canyon_wall_left, canyon_wall_south,             &
212               canyon_width_x, canyon_width_y, constant_flux_layer,            &
213               coupling_char, dp_level_ind_b, dz, dz_max, dz_stretch_factor,   &
214               dz_stretch_level, dz_stretch_level_index, grid_level, ibc_uv_b, &
215               io_blocks, io_group, inflow_l, inflow_n, inflow_r, inflow_s,    &
216               masking_method, maximum_grid_level, message_string,             &
217               momentum_advec, nest_domain, nest_bound_l, nest_bound_n,        &
218               nest_bound_r, nest_bound_s, ocean, outflow_l, outflow_n,        &
219               outflow_r, outflow_s, psolver, scalar_advec, topography,        &
220               topography_grid_convention, use_surface_fluxes, use_top_fluxes, &
221               wall_adjustment_factor
222         
223    USE grid_variables,                                                        &
224        ONLY:  ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, fwxm,                   &
225               fwxp, fwym, fwyp, fxm, fxp, fym, fyp, wall_e_x, wall_e_y,       &
226               wall_u, wall_v, wall_w_x, wall_w_y, zu_s_inner, zw_w_inner
227       
228    USE indices,                                                               &
229        ONLY:  flags, nbgp, nx, nxl, nxlg, nxl_mg, nxr, nxrg, nxr_mg,          &
230               ny, nyn, nyng, nyn_mg, nys, nys_mg, nysg, nz, nzb,              &
231               nzb_diff, nzb_diff_s_inner, nzb_diff_s_outer, nzb_diff_u,       &
232               nzb_diff_v, nzb_max, nzb_s_inner, nzb_s_outer, nzb_u_inner,     &
233               nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner,             &
234               nzb_w_outer, nzt, nzt_diff, nzt_mg, rflags_invers,              &
235               rflags_s_inner, wall_flags_0, wall_flags_00, wall_flags_1,      &
236               wall_flags_10, wall_flags_2, wall_flags_3,  wall_flags_4,       &
237               wall_flags_5, wall_flags_6, wall_flags_7, wall_flags_8,         &
238               wall_flags_9
239   
240    USE kinds
241   
242    USE pegrid
243
244    IMPLICIT NONE
245
246    INTEGER(iwp) ::  bh            !< temporary vertical index of building height
247    INTEGER(iwp) ::  blx           !< grid point number of building size along x
248    INTEGER(iwp) ::  bly           !< grid point number of building size along y
249    INTEGER(iwp) ::  bxl           !< index for left building wall
250    INTEGER(iwp) ::  bxr           !< index for right building wall
251    INTEGER(iwp) ::  byn           !< index for north building wall
252    INTEGER(iwp) ::  bys           !< index for south building wall
253    INTEGER(iwp) ::  ch            !< temporary vertical index for canyon height
254    INTEGER(iwp) ::  cwx           !< grid point number of canyon size along x
255    INTEGER(iwp) ::  cwy           !< grid point number of canyon size along y
256    INTEGER(iwp) ::  cxl           !< index for left canyon wall
257    INTEGER(iwp) ::  cxr           !< index for right canyon wall
258    INTEGER(iwp) ::  cyn           !< index for north canyon wall
259    INTEGER(iwp) ::  cys           !< index for south canyon wall
260    INTEGER(iwp) ::  i             !< index variable along x
261    INTEGER(iwp) ::  ii            !< loop variable for reading topography file
262    INTEGER(iwp) ::  inc           !< incremental parameter for coarsening grid level
263    INTEGER(iwp) ::  j             !< index variable along y
264    INTEGER(iwp) ::  k             !< index variable along z
265    INTEGER(iwp) ::  l             !< loop variable
266    INTEGER(iwp) ::  nxl_l         !< index of left PE boundary for multigrid level
267    INTEGER(iwp) ::  nxr_l         !< index of right PE boundary for multigrid level
268    INTEGER(iwp) ::  nyn_l         !< index of north PE boundary for multigrid level
269    INTEGER(iwp) ::  nys_l         !< index of south PE boundary for multigrid level
270    INTEGER(iwp) ::  nzb_local_max !< vertical grid index of maximum topography height
271    INTEGER(iwp) ::  nzb_local_min !< vertical grid index of minimum topography height
272    INTEGER(iwp) ::  nzb_si        !< dummy index for local nzb_s_inner
273    INTEGER(iwp) ::  nzt_l         !< index of top PE boundary for multigrid level
274    INTEGER(iwp) ::  num_hole      !< number of holes (in topography) resolved by only one grid point
275    INTEGER(iwp) ::  num_hole_l    !< number of holes (in topography) resolved by only one grid point on local PE     
276    INTEGER(iwp) ::  num_wall      !< number of surrounding vertical walls for a single grid point
277    INTEGER(iwp) ::  skip_n_rows   !< counting variable to skip rows while reading topography file   
278    INTEGER(iwp) ::  vi            !< dummy for vertical influence
279
280    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::                               &
281                     vertical_influence  !< number of vertical grid points above obstacle where adjustment of near-wall mixing length is required
282                                         
283    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nl      !< index of north-left corner location to limit near-wall mixing length
284    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_nr      !< north-right
285    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sl      !< south-left
286    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  corner_sr      !< south-right
287    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_local      !< index for topography top at cell-center
288    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  nzb_tmp        !< dummy to calculate topography indices on u- and v-grid
289    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_l         !< distance to adjacent left-facing wall
290    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_n         !< north-facing
291    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_r         !< right-facing
292    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  wall_s         !< right-facing
293
294    REAL(wp) ::  dum           !< dummy variable to skip columns while reading topography file   
295    REAL(wp) ::  dz_stretched  !< stretched vertical grid spacing
296
297    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  topo_height   !< input variable for topography height
298    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  zu_s_inner_l  !< dummy array on global scale to write topography output array
299    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  zw_w_inner_l  !< dummy array on global scale to write topography output array
300
301   
302!
303!-- Calculation of horizontal array bounds including ghost layers
304    nxlg = nxl - nbgp
305    nxrg = nxr + nbgp
306    nysg = nys - nbgp
307    nyng = nyn + nbgp
308
309!
310!-- Allocate grid arrays
311    ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1),        &
312              dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) )
313
314!
315!-- Compute height of u-levels from constant grid length and dz stretch factors
316    IF ( dz == -1.0_wp )  THEN
317       message_string = 'missing dz'
318       CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) 
319    ELSEIF ( dz <= 0.0_wp )  THEN
320       WRITE( message_string, * ) 'dz=',dz,' <= 0.0'
321       CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 )
322    ENDIF
323
324!
325!-- Define the vertical grid levels
326    IF ( .NOT. ocean )  THEN
327!
328!--    Grid for atmosphere with surface at z=0 (k=0, w-grid).
329!--    The second u-level (k=1) corresponds to the top of the
330!--    Prandtl-layer.
331
332       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN
333          zu(0) = 0.0_wp
334      !    zu(0) = - dz * 0.5_wp
335       ELSE
336          zu(0) = - dz * 0.5_wp
337       ENDIF
338       zu(1) =   dz * 0.5_wp
339
340       dz_stretch_level_index = nzt+1
341       dz_stretched = dz
342       DO  k = 2, nzt+1
343          IF ( dz_stretch_level <= zu(k-1)  .AND.  dz_stretched < dz_max )  THEN
344             dz_stretched = dz_stretched * dz_stretch_factor
345             dz_stretched = MIN( dz_stretched, dz_max )
346             IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1
347          ENDIF
348          zu(k) = zu(k-1) + dz_stretched
349       ENDDO
350
351!
352!--    Compute the w-levels. They are always staggered half-way between the
353!--    corresponding u-levels. In case of dirichlet bc for u and v at the
354!--    ground the first u- and w-level (k=0) are defined at same height (z=0).
355!--    The top w-level is extrapolated linearly.
356       zw(0) = 0.0_wp
357       DO  k = 1, nzt
358          zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp
359       ENDDO
360       zw(nzt+1) = zw(nzt) + 2.0_wp * ( zu(nzt+1) - zw(nzt) )
361
362    ELSE
363!
364!--    Grid for ocean with free water surface is at k=nzt (w-grid).
365!--    In case of neumann bc at the ground the first first u-level (k=0) lies
366!--    below the first w-level (k=0). In case of dirichlet bc the first u- and
367!--    w-level are defined at same height, but staggered from the second level.
368!--    The second u-level (k=1) corresponds to the top of the Prandtl-layer.
369       zu(nzt+1) =   dz * 0.5_wp
370       zu(nzt)   = - dz * 0.5_wp
371
372       dz_stretch_level_index = 0
373       dz_stretched = dz
374       DO  k = nzt-1, 0, -1
375!
376!--       The default value of dz_stretch_level is positive, thus the first
377!--       condition is always true. Hence, the second condition is necessary.
378          IF ( dz_stretch_level >= zu(k+1)  .AND.  dz_stretch_level <= 0.0  &
379               .AND.  dz_stretched < dz_max )  THEN
380             dz_stretched = dz_stretched * dz_stretch_factor
381             dz_stretched = MIN( dz_stretched, dz_max )
382             IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1
383          ENDIF
384          zu(k) = zu(k+1) - dz_stretched
385       ENDDO
386
387!
388!--    Compute the w-levels. They are always staggered half-way between the
389!--    corresponding u-levels, except in case of dirichlet bc for u and v
390!--    at the ground. In this case the first u- and w-level are defined at
391!--    same height. The top w-level (nzt+1) is not used but set for
392!--    consistency, since w and all scalar variables are defined up tp nzt+1.
393       zw(nzt+1) = dz
394       zw(nzt)   = 0.0_wp
395       DO  k = 0, nzt
396          zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp
397       ENDDO
398
399!
400!--    In case of dirichlet bc for u and v the first u- and w-level are defined
401!--    at same height.
402       IF ( ibc_uv_b == 0 ) THEN
403          zu(0) = zw(0)
404       ENDIF
405
406    ENDIF
407
408!
409!-- Compute grid lengths.
410    DO  k = 1, nzt+1
411       dzu(k)  = zu(k) - zu(k-1)
412       ddzu(k) = 1.0_wp / dzu(k)
413       dzw(k)  = zw(k) - zw(k-1)
414       ddzw(k) = 1.0_wp / dzw(k)
415    ENDDO
416
417    DO  k = 1, nzt
418       dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) )
419    ENDDO
420   
421!   
422!-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid
423!-- everywhere. For the actual grid, the grid spacing at the lowest level
424!-- is only dz/2, but should be dz. Therefore, an additional array
425!-- containing with appropriate grid information is created for these
426!-- solvers.
427    IF ( psolver(1:9) /= 'multigrid' )  THEN
428       ALLOCATE( ddzu_pres(1:nzt+1) )
429       ddzu_pres = ddzu
430       ddzu_pres(1) = ddzu_pres(2)  ! change for lowest level
431    ENDIF
432
433!
434!-- Compute the reciprocal values of the horizontal grid lengths.
435    ddx = 1.0_wp / dx
436    ddy = 1.0_wp / dy
437    dx2 = dx * dx
438    dy2 = dy * dy
439    ddx2 = 1.0_wp / dx2
440    ddy2 = 1.0_wp / dy2
441
442!
443!-- Compute the grid-dependent mixing length.
444    DO  k = 1, nzt
445       l_grid(k)  = ( dx * dy * dzw(k) )**0.33333333333333_wp
446    ENDDO
447
448!
449!-- Allocate outer and inner index arrays for topography and set
450!-- defaults.
451
452    ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr),       &
453              corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr),       &
454              wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr),             &
455              wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) )                     
456     
457    ALLOCATE( fwxm(nysg:nyng,nxlg:nxrg), fwxp(nysg:nyng,nxlg:nxrg),         &
458              fwym(nysg:nyng,nxlg:nxrg), fwyp(nysg:nyng,nxlg:nxrg),         &
459              fxm(nysg:nyng,nxlg:nxrg), fxp(nysg:nyng,nxlg:nxrg),           &
460              fym(nysg:nyng,nxlg:nxrg), fyp(nysg:nyng,nxlg:nxrg),           &
461              nzb_s_inner(nysg:nyng,nxlg:nxrg),                             &
462              nzb_s_outer(nysg:nyng,nxlg:nxrg),                             &
463              nzb_u_inner(nysg:nyng,nxlg:nxrg),                             &
464              nzb_u_outer(nysg:nyng,nxlg:nxrg),                             &
465              nzb_v_inner(nysg:nyng,nxlg:nxrg),                             &
466              nzb_v_outer(nysg:nyng,nxlg:nxrg),                             &
467              nzb_w_inner(nysg:nyng,nxlg:nxrg),                             &
468              nzb_w_outer(nysg:nyng,nxlg:nxrg),                             &
469              nzb_diff_s_inner(nysg:nyng,nxlg:nxrg),                        &
470              nzb_diff_s_outer(nysg:nyng,nxlg:nxrg),                        &
471              nzb_diff_u(nysg:nyng,nxlg:nxrg),                              &
472              nzb_diff_v(nysg:nyng,nxlg:nxrg),                              &
473              nzb_local(nysg:nyng,nxlg:nxrg),                               &
474              nzb_tmp(nysg:nyng,nxlg:nxrg),                                 &
475              rflags_s_inner(nzb:nzt+2,nysg:nyng,nxlg:nxrg),                &
476              rflags_invers(nysg:nyng,nxlg:nxrg,nzb:nzt+2),                 &
477              wall_e_x(nysg:nyng,nxlg:nxrg),                                &
478              wall_e_y(nysg:nyng,nxlg:nxrg),                                &
479              wall_u(nysg:nyng,nxlg:nxrg),                                  &
480              wall_v(nysg:nyng,nxlg:nxrg),                                  &
481              wall_w_x(nysg:nyng,nxlg:nxrg),                                &
482              wall_w_y(nysg:nyng,nxlg:nxrg) )
483
484
485
486    ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
487
488
489    nzb_s_inner = nzb;  nzb_s_outer = nzb
490    nzb_u_inner = nzb;  nzb_u_outer = nzb
491    nzb_v_inner = nzb;  nzb_v_outer = nzb
492    nzb_w_inner = nzb;  nzb_w_outer = nzb
493
494    rflags_s_inner = 1.0_wp
495    rflags_invers  = 1.0_wp
496
497!
498!-- Define vertical gridpoint from (or to) which on the usual finite difference
499!-- form (which does not use surface fluxes) is applied
500    IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
501       nzb_diff = nzb + 2
502    ELSE
503       nzb_diff = nzb + 1
504    ENDIF
505    IF ( use_top_fluxes )  THEN
506       nzt_diff = nzt - 1
507    ELSE
508       nzt_diff = nzt
509    ENDIF
510
511    nzb_diff_s_inner = nzb_diff;  nzb_diff_s_outer = nzb_diff
512    nzb_diff_u = nzb_diff;  nzb_diff_v = nzb_diff
513
514    wall_e_x = 0.0_wp;  wall_e_y = 0.0_wp;  wall_u = 0.0_wp;  wall_v = 0.0_wp
515    wall_w_x = 0.0_wp;  wall_w_y = 0.0_wp
516    fwxp = 1.0_wp;  fwxm = 1.0_wp;  fwyp = 1.0_wp;  fwym = 1.0_wp
517    fxp  = 1.0_wp;  fxm  = 1.0_wp;  fyp  = 1.0_wp;  fym  = 1.0_wp
518
519!
520!-- Initialize near-wall mixing length l_wall only in the vertical direction
521!-- for the moment,
522!-- multiplication with wall_adjustment_factor near the end of this routine
523    l_wall(nzb,:,:)   = l_grid(1)
524    DO  k = nzb+1, nzt
525       l_wall(k,:,:)  = l_grid(k)
526    ENDDO
527    l_wall(nzt+1,:,:) = l_grid(nzt)
528
529    ALLOCATE ( vertical_influence(nzb:nzt) )
530    DO  k = 1, nzt
531       vertical_influence(k) = MIN ( INT( l_grid(k) / &
532                     ( wall_adjustment_factor * dzw(k) ) + 0.5_wp ), nzt - k )
533    ENDDO
534
535    DO  k = 1, nzt
536       IF ( l_grid(k) > 1.5_wp * dx * wall_adjustment_factor .OR.  &
537            l_grid(k) > 1.5_wp * dy * wall_adjustment_factor )  THEN
538          WRITE( message_string, * ) 'grid anisotropy exceeds ', &
539                                     'threshold given by only local', &
540                                     ' &horizontal reduction of near_wall ', &
541                                     'mixing length l_wall', &
542                                     ' &starting from height level k = ', k, '.'
543          CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 )
544          EXIT
545       ENDIF
546    ENDDO
547    vertical_influence(0) = vertical_influence(1)
548
549    DO  k = nzb + 1, nzb + vertical_influence(nzb)
550       l_wall(k,:,:) = zu(k) - zw(nzb)
551    ENDDO
552
553!
554!-- Set outer and inner index arrays for non-flat topography.
555!-- Here consistency checks concerning domain size and periodicity are
556!-- necessary.
557!-- Within this SELECT CASE structure only nzb_local is initialized
558!-- individually depending on the chosen topography type, all other index
559!-- arrays are initialized further below.
560    SELECT CASE ( TRIM( topography ) )
561
562       CASE ( 'flat' )
563!
564!--       nzb_local is required for the multigrid solver
565          nzb_local = 0
566
567       CASE ( 'single_building' )
568!
569!--       Single rectangular building, by default centered in the middle of the
570!--       total domain
571          blx = NINT( building_length_x / dx )
572          bly = NINT( building_length_y / dy )
573          bh  = MINLOC( ABS( zw - building_height ), 1 ) - 1
574          IF ( ABS( zw(bh  ) - building_height ) == &
575               ABS( zw(bh+1) - building_height )    )  bh = bh + 1
576
577          IF ( building_wall_left == 9999999.9_wp )  THEN
578             building_wall_left = ( nx + 1 - blx ) / 2 * dx
579          ENDIF
580          bxl = NINT( building_wall_left / dx )
581          bxr = bxl + blx
582
583          IF ( building_wall_south == 9999999.9_wp )  THEN
584             building_wall_south = ( ny + 1 - bly ) / 2 * dy
585          ENDIF
586          bys = NINT( building_wall_south / dy )
587          byn = bys + bly
588
589!
590!--       Building size has to meet some requirements
591          IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR.  &
592               ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) )  THEN
593             WRITE( message_string, * ) 'inconsistent building parameters:',   &
594                                      '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, &
595                                      'byn=', byn, 'nx=', nx, 'ny=', ny
596             CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 )
597          ENDIF
598
599!
600!--       Define the building.
601          nzb_local = 0
602          IF ( bxl <= nxr  .AND.  bxr >= nxl  .AND.                            &
603               bys <= nyn  .AND.  byn >= nys )                                 &       
604             nzb_local(MAX(nys,bys):MIN(nyn,byn),MAX(nxl,bxl):MIN(nxr,bxr)) = bh
605
606          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
607
608       CASE ( 'single_street_canyon' )
609!
610!--       Single quasi-2D street canyon of infinite length in x or y direction.
611!--       The canyon is centered in the other direction by default.
612          IF ( canyon_width_x /= 9999999.9_wp )  THEN
613!
614!--          Street canyon in y direction
615             cwx = NINT( canyon_width_x / dx )
616             IF ( canyon_wall_left == 9999999.9_wp )  THEN
617                canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx
618             ENDIF
619             cxl = NINT( canyon_wall_left / dx )
620             cxr = cxl + cwx
621
622          ELSEIF ( canyon_width_y /= 9999999.9_wp )  THEN
623!
624!--          Street canyon in x direction
625             cwy = NINT( canyon_width_y / dy )
626             IF ( canyon_wall_south == 9999999.9_wp )  THEN
627                canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy
628             ENDIF
629             cys = NINT( canyon_wall_south / dy )
630             cyn = cys + cwy
631
632          ELSE
633             
634             message_string = 'no street canyon width given'
635             CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 )
636 
637          ENDIF
638
639          ch  = MINLOC( ABS( zw - canyon_height ), 1 ) - 1
640          IF ( ABS( zw(ch  ) - canyon_height ) == &
641               ABS( zw(ch+1) - canyon_height )    )  ch = ch + 1
642
643          dp_level_ind_b = ch
644!
645!--       Street canyon size has to meet some requirements
646          IF ( canyon_width_x /= 9999999.9_wp )  THEN
647             IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR.        &
648               ( ch < 3 ) )  THEN
649                WRITE( message_string, * ) 'inconsistent canyon parameters:',  &
650                                           '&cxl=', cxl, 'cxr=', cxr,          &
651                                           'cwx=', cwx,                        &
652                                           'ch=', ch, 'nx=', nx, 'ny=', ny
653                CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) 
654             ENDIF
655          ELSEIF ( canyon_width_y /= 9999999.9_wp )  THEN
656             IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR.        &
657               ( ch < 3 ) )  THEN
658                WRITE( message_string, * ) 'inconsistent canyon parameters:',  &
659                                           '&cys=', cys, 'cyn=', cyn,          &
660                                           'cwy=', cwy,                        &
661                                           'ch=', ch, 'nx=', nx, 'ny=', ny
662                CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) 
663             ENDIF
664          ENDIF
665          IF ( canyon_width_x /= 9999999.9_wp .AND.                            &                 
666               canyon_width_y /= 9999999.9_wp )  THEN
667             message_string = 'inconsistent canyon parameters:' //             &   
668                              '&street canyon can only be oriented' //         &
669                              '&either in x- or in y-direction'
670             CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 )
671          ENDIF
672
673          nzb_local = ch
674          IF ( canyon_width_x /= 9999999.9_wp )  THEN
675             IF ( cxl <= nxr  .AND.  cxr >= nxl )                              &
676                nzb_local(:,MAX(nxl,cxl+1):MIN(nxr,cxr-1)) = 0
677          ELSEIF ( canyon_width_y /= 9999999.9_wp )  THEN
678             IF ( cys <= nyn  .AND.  cyn >= nys )                              &         
679                nzb_local(MAX(nys,cys+1):MIN(nyn,cyn-1),:) = 0
680          ENDIF
681
682          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
683
684       CASE ( 'read_from_file' )
685
686          ALLOCATE ( topo_height(nys:nyn,nxl:nxr) )
687
688          DO  ii = 0, io_blocks-1
689             IF ( ii == io_group )  THEN
690
691!
692!--             Arbitrary irregular topography data in PALM format (exactly
693!--             matching the grid size and total domain size)
694                OPEN( 90, FILE='TOPOGRAPHY_DATA'//TRIM( coupling_char ),       &
695                          STATUS='OLD', FORM='FORMATTED', ERR=10 )
696!
697!--             Read topography PE-wise. Rows are read from nyn to nys, columns
698!--             are read from nxl to nxr. At first, ny-nyn rows need to be skipped.
699                skip_n_rows = 0
700                DO WHILE ( skip_n_rows < ny - nyn )
701                   READ( 90, * ) 
702                   skip_n_rows = skip_n_rows + 1
703                ENDDO
704!
705!--             Read data from nyn to nys and nxl to nxr. Therefore, skip
706!--             column until nxl-1 is reached
707                DO  j = nyn, nys, -1
708                   READ( 90, *, ERR=11, END=11 )                               &
709                                              ( dum, i = 0, nxl-1 ),           &
710                                              ( topo_height(j,i), i = nxl, nxr )
711                ENDDO
712
713                GOTO 12
714         
715 10             message_string = 'file TOPOGRAPHY'//TRIM( coupling_char )//    &
716                                 ' does not exist'
717                CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 )
718
719 11             message_string = 'errors in file TOPOGRAPHY_DATA'//            &
720                                 TRIM( coupling_char )
721                CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 )
722
723 12             CLOSE( 90 )
724
725             ENDIF
726#if defined( __parallel )
727             CALL MPI_BARRIER( comm2d, ierr )
728#endif
729          ENDDO
730
731!
732!--       Calculate the index height of the topography
733          nzb_local = 0
734          DO  i = nxl, nxr
735             DO  j = nys, nyn
736                nzb_local(j,i) = MINLOC( ABS( zw - topo_height(j,i) ), 1 ) - 1
737                IF ( ABS( zw(nzb_local(j,i)  ) - topo_height(j,i) ) == &
738                     ABS( zw(nzb_local(j,i)+1) - topo_height(j,i) )    )  &
739                   nzb_local(j,i) = nzb_local(j,i) + 1
740             ENDDO
741          ENDDO
742
743          DEALLOCATE ( topo_height )
744!
745!--       Filter topography, i.e. fill holes resolved by only one grid point. 
746!--       Such holes are suspected to lead to velocity blow-ups as continuity
747!--       equation on discrete grid cannot be fulfilled in such case.
748!--       For now, check only for holes and fill them to the lowest height level
749!--       of the directly adjoining grid points along x- and y- direction.
750!--       Before checking for holes, set lateral boundary conditions for
751!--       topography. After hole-filling, boundary conditions must be set again!
752          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
753         
754          IF ( .NOT. bc_ns_cyc )  THEN
755             IF ( nys == 0  )  nzb_local(-1,:)   = nzb_local(0,:)
756             IF ( nyn == ny )  nzb_local(ny+1,:) = nzb_local(ny,:)
757          ENDIF
758
759          IF ( .NOT. bc_lr_cyc )  THEN
760             IF ( nxl == 0  )  nzb_local(:,-1)   = nzb_local(:,0)
761             IF ( nxr == nx )  nzb_local(:,nx+1) = nzb_local(:,nx)         
762          ENDIF
763
764          num_hole_l = 0
765          DO i = nxl, nxr
766             DO j = nys, nyn
767
768                num_wall = 0
769
770                IF ( nzb_local(j-1,i) > nzb_local(j,i) )                       &
771                   num_wall = num_wall + 1
772                IF ( nzb_local(j+1,i) > nzb_local(j,i) )                       &
773                   num_wall = num_wall + 1
774                IF ( nzb_local(j,i-1) > nzb_local(j,i) )                       &
775                   num_wall = num_wall + 1
776                IF ( nzb_local(j,i+1) > nzb_local(j,i) )                       &
777                   num_wall = num_wall + 1
778
779                IF ( num_wall == 4 )  THEN
780                   nzb_local(j,i) = MIN( nzb_local(j-1,i), nzb_local(j+1,i),   &
781                                         nzb_local(j,i-1), nzb_local(j,i+1) )
782                   num_hole_l     = num_hole_l + 1
783                ENDIF
784             ENDDO
785          ENDDO
786!
787!--       Count the total number of holes, required for informative message.
788#if defined( __parallel )
789          CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM,   &
790                              comm2d, ierr )
791#else
792          num_hole = num_hole_l
793#endif   
794!
795!--       Create an informative message if any hole was removed.
796          IF ( num_hole > 0 )  THEN
797             WRITE( message_string, * ) num_hole, 'hole(s) resolved by only '//&
798                                                  'one grid point were filled'
799             CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 )
800          ENDIF
801!
802!--       Exchange ghost-points, as well as add cyclic or Neumann boundary
803!--       conditions.
804          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
805         
806          IF ( .NOT. bc_ns_cyc )  THEN
807             IF ( nys == 0  )  nzb_local(-1,:)   = nzb_local(0,:)
808             IF ( nyn == ny )  nzb_local(ny+1,:) = nzb_local(ny,:)
809          ENDIF
810
811          IF ( .NOT. bc_lr_cyc )  THEN
812             IF ( nxl == 0  )  nzb_local(:,-1)   = nzb_local(:,0)
813             IF ( nxr == nx )  nzb_local(:,nx+1) = nzb_local(:,nx)         
814          ENDIF
815
816       CASE DEFAULT
817!
818!--       The DEFAULT case is reached either if the parameter topography
819!--       contains a wrong character string or if the user has defined a special
820!--       case in the user interface. There, the subroutine user_init_grid
821!--       checks which of these two conditions applies.
822          CALL user_init_grid( nzb_local )
823
824    END SELECT
825!
826!-- Determine the maximum level of topography. Furthermore it is used for
827!-- steering the degradation of order of the applied advection scheme.
828!-- In case of non-cyclic lateral boundaries, the order of the advection
829!-- scheme has to be reduced up to nzt (required at the lateral boundaries).
830#if defined( __parallel )
831    CALL MPI_ALLREDUCE( MAXVAL( nzb_local ) + 1, nzb_max, 1, MPI_INTEGER,      &
832                        MPI_MAX, comm2d, ierr )
833#else
834    nzb_max = MAXVAL( nzb_local ) + 1
835#endif
836    IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR.             &
837         inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s .OR.             &
838         nest_domain )                                                         &
839    THEN
840       nzb_max = nzt
841    ENDIF
842
843!
844!-- Consistency checks and index array initialization are only required for
845!-- non-flat topography, also the initialization of topography height arrays
846!-- zu_s_inner and zw_w_inner
847    IF ( TRIM( topography ) /= 'flat' )  THEN
848#if defined( __parallel )
849       CALL MPI_ALLREDUCE( MAXVAL( nzb_local ), nzb_local_max, 1, MPI_INTEGER, &
850                           MPI_MAX, comm2d, ierr )
851       CALL MPI_ALLREDUCE( MINVAL( nzb_local ), nzb_local_min, 1, MPI_INTEGER, &
852                           MPI_MIN, comm2d, ierr )                           
853#else
854       nzb_local_max = MAXVAL( nzb_local )
855       nzb_local_min = MINVAL( nzb_local )
856#endif
857
858!
859!--    Consistency checks
860       IF ( nzb_local_min < 0  .OR.  nzb_local_max  > nz + 1 )  THEN
861          WRITE( message_string, * ) 'nzb_local values are outside the',       &
862                                'model domain',                                &
863                                '&MINVAL( nzb_local ) = ', nzb_local_min,      &
864                                '&MAXVAL( nzb_local ) = ', nzb_local_max
865          CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 )
866       ENDIF
867
868       IF ( topography_grid_convention == 'cell_edge' )  THEN
869!
870!--       The array nzb_local as defined using the 'cell_edge' convention
871!--       describes the actual total size of topography which is defined at the
872!--       cell edges where u=0 on the topography walls in x-direction and v=0
873!--       on the topography walls in y-direction. However, PALM uses individual
874!--       arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner.
875!--       Therefore, the extent of topography in nzb_local is now reduced by
876!--       1dx at the E topography walls and by 1dy at the N topography walls
877!--       to form the basis for nzb_s_inner.
878!--       Note, the reverse memory access (i-j instead of j-i) is absolutely
879!--       required at this point.
880          DO  j = nys+1, nyn+1
881             DO  i = nxl-1, nxr
882                nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) )
883             ENDDO
884          ENDDO
885!
886!--       Exchange ghost points
887          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
888
889          DO  i = nxl, nxr+1
890             DO  j = nys-1, nyn
891                nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) )
892             ENDDO
893          ENDDO
894!
895!--       Exchange ghost points         
896          CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp )
897       ENDIF
898!
899!--    Initialize index arrays nzb_s_inner and nzb_w_inner
900       nzb_s_inner = nzb_local
901       nzb_w_inner = nzb_local
902
903!
904!--    Initialize remaining index arrays:
905!--    first pre-initialize them with nzb_s_inner...
906       nzb_u_inner = nzb_s_inner
907       nzb_u_outer = nzb_s_inner
908       nzb_v_inner = nzb_s_inner
909       nzb_v_outer = nzb_s_inner
910       nzb_w_outer = nzb_s_inner
911       nzb_s_outer = nzb_s_inner
912
913!
914!--    ...then extend pre-initialized arrays in their according directions
915!--    based on nzb_local using nzb_tmp as a temporary global index array
916
917!
918!--    nzb_s_outer:
919!--    extend nzb_local east-/westwards first, then north-/southwards
920       nzb_tmp = nzb_local
921       DO  j = nys, nyn
922          DO  i = nxl, nxr
923             nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i),             &
924                                 nzb_local(j,i+1) )
925          ENDDO
926       ENDDO
927       
928       CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp )
929       
930       DO  i = nxl, nxr
931          DO  j = nys, nyn
932             nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i),             &
933                                     nzb_tmp(j+1,i) )
934          ENDDO
935!
936!--       non-cyclic boundary conditions (overwritten by call of
937!--       exchange_horiz_2d_int below in case of cyclic boundary conditions)
938          IF ( nys == 0 )  THEN
939             j = -1
940             nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) )
941          ENDIF
942          IF ( nyn == ny )  THEN
943             j = ny + 1
944             nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) )
945          ENDIF
946       ENDDO
947!
948!--    nzb_w_outer:
949!--    identical to nzb_s_outer
950       nzb_w_outer = nzb_s_outer
951
952!
953!--    nzb_u_inner:
954!--    extend nzb_local rightwards only
955       nzb_tmp = nzb_local
956       DO  j = nys, nyn
957          DO  i = nxl, nxr
958             nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) )
959          ENDDO
960       ENDDO
961       
962       CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp )
963       
964       nzb_u_inner = nzb_tmp
965!
966!--    nzb_u_outer:
967!--    extend current nzb_tmp (nzb_u_inner) north-/southwards
968       DO  i = nxl, nxr
969          DO  j = nys, nyn
970             nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i),             &
971                                     nzb_tmp(j+1,i) )
972          ENDDO
973!
974!--       non-cyclic boundary conditions (overwritten by call of
975!--       exchange_horiz_2d_int below in case of cyclic boundary conditions)
976          IF ( nys == 0 )  THEN
977             j = -1
978             nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) )
979          ENDIF
980          IF ( nyn == ny )  THEN
981             j = ny + 1
982             nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) )
983          ENDIF
984       ENDDO
985
986!
987!--    nzb_v_inner:
988!--    extend nzb_local northwards only
989       nzb_tmp = nzb_local
990       DO  i = nxl, nxr
991          DO  j = nys, nyn
992             nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) )
993          ENDDO
994       ENDDO
995       
996       CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp )     
997       nzb_v_inner = nzb_tmp
998
999!
1000!--    nzb_v_outer:
1001!--    extend current nzb_tmp (nzb_v_inner) right-/leftwards
1002       DO  j = nys, nyn
1003          DO  i = nxl, nxr
1004             nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i),             &
1005                                     nzb_tmp(j,i+1) )
1006          ENDDO
1007!
1008!--       non-cyclic boundary conditions (overwritten by call of
1009!--       exchange_horiz_2d_int below in case of cyclic boundary conditions)
1010          IF ( nxl == 0 )  THEN
1011             i = -1
1012             nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) )
1013          ENDIF
1014          IF ( nxr == nx )  THEN
1015             i = nx + 1
1016             nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) )
1017          ENDIF
1018       ENDDO
1019
1020!
1021!--    Exchange of lateral boundary values (parallel computers) and cyclic
1022!--    boundary conditions, if applicable.
1023!--    Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local
1024!--    they do not require exchange and are not included here.
1025       CALL exchange_horiz_2d_int( nzb_u_inner, nys, nyn, nxl, nxr, nbgp )
1026       CALL exchange_horiz_2d_int( nzb_u_outer, nys, nyn, nxl, nxr, nbgp )
1027       CALL exchange_horiz_2d_int( nzb_v_inner, nys, nyn, nxl, nxr, nbgp )
1028       CALL exchange_horiz_2d_int( nzb_v_outer, nys, nyn, nxl, nxr, nbgp )
1029       CALL exchange_horiz_2d_int( nzb_w_outer, nys, nyn, nxl, nxr, nbgp )
1030       CALL exchange_horiz_2d_int( nzb_s_outer, nys, nyn, nxl, nxr, nbgp )
1031
1032!
1033!--    Allocate and set the arrays containing the topography height
1034       ALLOCATE( zu_s_inner(0:nx+1,0:ny+1), zw_w_inner(0:nx+1,0:ny+1),         &
1035                 zu_s_inner_l(0:nx+1,0:ny+1), zw_w_inner_l(0:nx+1,0:ny+1) )
1036                 
1037       zu_s_inner   = 0.0_wp
1038       zw_w_inner   = 0.0_wp
1039       zu_s_inner_l = 0.0_wp
1040       zw_w_inner_l = 0.0_wp
1041       
1042       DO  i = nxl, nxr
1043          DO  j = nys, nyn
1044             zu_s_inner_l(i,j) = zu(nzb_local(j,i))
1045             zw_w_inner_l(i,j) = zw(nzb_local(j,i))
1046          ENDDO
1047       ENDDO
1048       
1049#if defined( __parallel )
1050       CALL MPI_REDUCE( zu_s_inner_l, zu_s_inner, (nx+2)*(ny+2),         &
1051                           MPI_REAL, MPI_SUM, 0, comm2d, ierr )       
1052       CALL MPI_REDUCE( zw_w_inner_l, zw_w_inner, (nx+2)*(ny+2),         &
1053                           MPI_REAL, MPI_SUM, 0, comm2d, ierr ) 
1054#else
1055       zu_s_inner = zu_s_inner_l
1056       zw_w_inner = zw_w_inner_l
1057#endif
1058
1059      DEALLOCATE( zu_s_inner_l, zw_w_inner_l )
1060      IF ( myid /= 0 )  DEALLOCATE( zu_s_inner, zw_w_inner )
1061!
1062!--   Set south and left ghost points, required for netcdf output
1063      IF ( myid == 0 )  THEN
1064         IF( bc_lr_cyc )  THEN
1065            zu_s_inner(nx+1,:) = zu_s_inner(0,:)
1066            zw_w_inner(nx+1,:) = zw_w_inner(0,:)
1067         ELSE
1068            zu_s_inner(nx+1,:) = zu_s_inner(nx,:)
1069            zw_w_inner(nx+1,:) = zw_w_inner(nx,:)
1070         ENDIF
1071         IF( bc_ns_cyc )  THEN
1072            zu_s_inner(:,ny+1) = zu_s_inner(:,0)
1073            zw_w_inner(:,ny+1) = zw_w_inner(:,0)
1074         ELSE
1075            zu_s_inner(:,ny+1) = zu_s_inner(:,ny)
1076            zw_w_inner(:,ny+1) = zw_w_inner(:,ny)
1077         ENDIF
1078      ENDIF
1079!
1080!--    Set flag arrays to be used for masking of grid points
1081       DO  i = nxlg, nxrg
1082          DO  j = nysg, nyng
1083             DO  k = nzb, nzt+1
1084                IF ( k <= nzb_s_inner(j,i) )  rflags_s_inner(k,j,i) = 0.0_wp
1085                IF ( k <= nzb_s_inner(j,i) )  rflags_invers(j,i,k)  = 0.0_wp
1086             ENDDO
1087          ENDDO
1088       ENDDO
1089
1090    ENDIF
1091!
1092!-- Deallocate temporary array, as it might be reused for different
1093!-- grid-levels further below.
1094    DEALLOCATE( nzb_tmp )
1095
1096!
1097!-- Set the individual index arrays which define the k index from which on
1098!-- the usual finite difference form (which does not use surface fluxes) is
1099!-- applied
1100    IF ( constant_flux_layer  .OR.  use_surface_fluxes )  THEN
1101       nzb_diff_u         = nzb_u_inner + 2
1102       nzb_diff_v         = nzb_v_inner + 2
1103       nzb_diff_s_inner   = nzb_s_inner + 2
1104       nzb_diff_s_outer   = nzb_s_outer + 2
1105    ELSE
1106       nzb_diff_u         = nzb_u_inner + 1
1107       nzb_diff_v         = nzb_v_inner + 1
1108       nzb_diff_s_inner   = nzb_s_inner + 1
1109       nzb_diff_s_outer   = nzb_s_outer + 1
1110    ENDIF
1111
1112!
1113!-- Calculation of wall switches and factors required by diffusion_u/v.f90 and
1114!-- for limitation of near-wall mixing length l_wall further below
1115    corner_nl = 0
1116    corner_nr = 0
1117    corner_sl = 0
1118    corner_sr = 0
1119    wall_l    = 0
1120    wall_n    = 0
1121    wall_r    = 0
1122    wall_s    = 0
1123
1124    DO  i = nxl, nxr
1125       DO  j = nys, nyn
1126!
1127!--       u-component
1128          IF ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) )  THEN
1129             wall_u(j,i) = 1.0_wp   ! north wall (location of adjacent fluid)
1130             fym(j,i)    = 0.0_wp
1131             fyp(j,i)    = 1.0_wp
1132          ELSEIF ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) )  THEN
1133             wall_u(j,i) = 1.0_wp   ! south wall (location of adjacent fluid)
1134             fym(j,i)    = 1.0_wp
1135             fyp(j,i)    = 0.0_wp
1136          ENDIF
1137!
1138!--       v-component
1139          IF ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) )  THEN
1140             wall_v(j,i) = 1.0_wp   ! rigth wall (location of adjacent fluid)
1141             fxm(j,i)    = 0.0_wp
1142             fxp(j,i)    = 1.0_wp
1143          ELSEIF ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) )  THEN
1144             wall_v(j,i) = 1.0_wp   ! left wall (location of adjacent fluid)
1145             fxm(j,i)    = 1.0_wp
1146             fxp(j,i)    = 0.0_wp
1147          ENDIF
1148!
1149!--       w-component, also used for scalars, separate arrays for shear
1150!--       production of tke
1151          IF ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) )  THEN
1152             wall_e_y(j,i) =  1.0_wp   ! north wall (location of adjacent fluid)
1153             wall_w_y(j,i) =  1.0_wp
1154             fwym(j,i)     =  0.0_wp
1155             fwyp(j,i)     =  1.0_wp
1156          ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) )  THEN
1157             wall_e_y(j,i) = -1.0_wp   ! south wall (location of adjacent fluid)
1158             wall_w_y(j,i) =  1.0_wp
1159             fwym(j,i)     =  1.0_wp
1160             fwyp(j,i)     =  0.0_wp
1161          ENDIF
1162          IF ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) )  THEN
1163             wall_e_x(j,i) =  1.0_wp   ! right wall (location of adjacent fluid)
1164             wall_w_x(j,i) =  1.0_wp
1165             fwxm(j,i)     =  0.0_wp
1166             fwxp(j,i)     =  1.0_wp
1167          ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) )  THEN
1168             wall_e_x(j,i) = -1.0_wp   ! left wall (location of adjacent fluid)
1169             wall_w_x(j,i) =  1.0_wp
1170             fwxm(j,i)     =  1.0_wp
1171             fwxp(j,i)     =  0.0_wp
1172          ENDIF
1173!
1174!--       Wall and corner locations inside buildings for limitation of
1175!--       near-wall mixing length l_wall
1176          IF ( nzb_s_inner(j,i) > nzb_s_inner(j+1,i) )  THEN
1177
1178             wall_n(j,i) = nzb_s_inner(j+1,i) + 1            ! North wall
1179
1180             IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) )  THEN
1181                corner_nl(j,i) = MAX( nzb_s_inner(j+1,i),  & ! Northleft corner
1182                                      nzb_s_inner(j,i-1) ) + 1
1183             ENDIF
1184
1185             IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) )  THEN
1186                corner_nr(j,i) = MAX( nzb_s_inner(j+1,i),  & ! Northright corner
1187                                      nzb_s_inner(j,i+1) ) + 1
1188             ENDIF
1189
1190          ENDIF
1191
1192          IF ( nzb_s_inner(j,i) > nzb_s_inner(j-1,i) )  THEN
1193
1194             wall_s(j,i) = nzb_s_inner(j-1,i) + 1            ! South wall
1195             IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) )  THEN
1196                corner_sl(j,i) = MAX( nzb_s_inner(j-1,i),  & ! Southleft corner
1197                                      nzb_s_inner(j,i-1) ) + 1
1198             ENDIF
1199
1200             IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) )  THEN
1201                corner_sr(j,i) = MAX( nzb_s_inner(j-1,i),  & ! Southright corner
1202                                      nzb_s_inner(j,i+1) ) + 1
1203             ENDIF
1204
1205          ENDIF
1206
1207          IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) )  THEN
1208             wall_l(j,i) = nzb_s_inner(j,i-1) + 1            ! Left wall
1209          ENDIF
1210
1211          IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) )  THEN
1212             wall_r(j,i) = nzb_s_inner(j,i+1) + 1            ! Right wall
1213          ENDIF
1214
1215       ENDDO
1216    ENDDO
1217!
1218!-- Calculate wall flag arrays for the multigrid method.
1219!-- Please note, wall flags are only applied in the not cache-optimized
1220!-- version.
1221    IF ( psolver == 'multigrid_noopt' )  THEN
1222
1223!
1224!--    Gridpoint increment of the current level.
1225       inc = 1
1226       DO  l = maximum_grid_level, 1 , -1
1227!
1228!--       Set grid_level as it is required for exchange_horiz_2d_int
1229          grid_level = l
1230
1231          nxl_l = nxl_mg(l)
1232          nxr_l = nxr_mg(l)
1233          nys_l = nys_mg(l)
1234          nyn_l = nyn_mg(l)
1235          nzt_l = nzt_mg(l)
1236!
1237!--       Assign the flag level to be calculated
1238          SELECT CASE ( l )
1239             CASE ( 1 )
1240                flags => wall_flags_1
1241             CASE ( 2 )
1242                flags => wall_flags_2
1243             CASE ( 3 )
1244                flags => wall_flags_3
1245             CASE ( 4 )
1246                flags => wall_flags_4
1247             CASE ( 5 )
1248                flags => wall_flags_5
1249             CASE ( 6 )
1250                flags => wall_flags_6
1251             CASE ( 7 )
1252                flags => wall_flags_7
1253             CASE ( 8 )
1254                flags => wall_flags_8
1255             CASE ( 9 )
1256                flags => wall_flags_9
1257             CASE ( 10 )
1258                flags => wall_flags_10
1259          END SELECT
1260
1261!
1262!--       Depending on the grid level, set the respective bits in case of
1263!--       neighbouring walls
1264!--       Bit 0:  wall to the bottom
1265!--       Bit 1:  wall to the top (not realized in remaining PALM code so far)
1266!--       Bit 2:  wall to the south
1267!--       Bit 3:  wall to the north
1268!--       Bit 4:  wall to the left
1269!--       Bit 5:  wall to the right
1270!--       Bit 6:  inside building
1271
1272          flags = 0
1273
1274!
1275!--       In case of masking method, flags are not set and multigrid method
1276!--       works like FFT-solver
1277          IF ( .NOT. masking_method )  THEN
1278
1279!
1280!--          Allocate temporary array for topography heights on coarser grid
1281!--          level. Please note, 2 ghoist points are required, in order to
1282!--          calculate flags() on the interior ghost point.
1283             ALLOCATE( nzb_tmp(nys_l-2:nyn_l+2,nxl_l-2:nxr_l+2) )
1284             nzb_tmp = 0
1285             
1286             DO  i = nxl_l, nxr_l
1287                DO  j = nys_l, nyn_l
1288                   nzb_tmp(j,i) = nzb_local(j*inc,i*inc)
1289                ENDDO
1290             ENDDO
1291!
1292!--          Exchange ghost points on respective multigrid level. 2 ghost points
1293!--          are required, in order to calculate flags on
1294!--          nys_l-1 / nyn_l+1 / nxl_l-1 / nxr_l+1. The alternative would be to
1295!--          exchange 3D-INTEGER array flags on the respective multigrid level.
1296             CALL exchange_horiz_2d_int( nzb_tmp, nys_l, nyn_l, nxl_l, nxr_l, 2 )
1297!
1298!--          Set non-cyclic boundary conditions on respective multigrid level
1299             IF ( .NOT. bc_ns_cyc )  THEN
1300                IF ( inflow_s .OR. outflow_s .OR. nest_bound_s  )  THEN
1301                   nzb_tmp(-2,:) = nzb_tmp(0,:)
1302                   nzb_tmp(-1,:) = nzb_tmp(0,:)
1303                ENDIF
1304                IF ( inflow_n .OR. outflow_n .OR. nest_bound_n )  THEN
1305                   nzb_tmp(nyn_l+2,:) = nzb_tmp(nyn_l,:)
1306                   nzb_tmp(nyn_l+1,:) = nzb_tmp(nyn_l,:)
1307                ENDIF
1308             ENDIF
1309             IF ( .NOT. bc_lr_cyc )  THEN
1310                IF ( inflow_l .OR. outflow_l .OR. nest_bound_l  )  THEN
1311                   nzb_tmp(:,-2) = nzb_tmp(:,0)
1312                   nzb_tmp(:,-1) = nzb_tmp(:,0)
1313                ENDIF
1314                IF ( inflow_r .OR. outflow_r .OR. nest_bound_r )  THEN
1315                   nzb_tmp(:,nxr_l+1) = nzb_tmp(:,nxr_l)   
1316                   nzb_tmp(:,nxr_l+2) = nzb_tmp(:,nxr_l)     
1317                ENDIF       
1318             ENDIF
1319                       
1320             DO  i = nxl_l-1, nxr_l+1
1321                DO  j = nys_l-1, nyn_l+1
1322                   DO  k = nzb, nzt_l+1     
1323!
1324!--                   Inside/outside building (inside building does not need
1325!--                   further tests for walls)
1326                      IF ( k*inc <= nzb_tmp(j,i) )  THEN
1327
1328                         flags(k,j,i) = IBSET( flags(k,j,i), 6 )
1329
1330                      ELSE
1331!
1332!--                      Bottom wall
1333                         IF ( (k-1)*inc <= nzb_tmp(j,i) )  THEN
1334                            flags(k,j,i) = IBSET( flags(k,j,i), 0 )
1335                         ENDIF
1336!
1337!--                      South wall
1338                         IF ( k*inc <= nzb_tmp(j-1,i) )  THEN
1339                            flags(k,j,i) = IBSET( flags(k,j,i), 2 )
1340                         ENDIF
1341!
1342!--                      North wall
1343                         IF ( k*inc <= nzb_tmp(j+1,i) )  THEN
1344                            flags(k,j,i) = IBSET( flags(k,j,i), 3 )
1345                         ENDIF
1346!
1347!--                      Left wall
1348                         IF ( k*inc <= nzb_tmp(j,i-1) )  THEN
1349                            flags(k,j,i) = IBSET( flags(k,j,i), 4 )
1350                         ENDIF
1351!
1352!--                      Right wall
1353                         IF ( k*inc <= nzb_tmp(j,i+1) )  THEN
1354                            flags(k,j,i) = IBSET( flags(k,j,i), 5 )
1355                         ENDIF
1356
1357                      ENDIF
1358                           
1359                   ENDDO
1360                ENDDO
1361             ENDDO
1362
1363             DEALLOCATE( nzb_tmp )
1364
1365          ENDIF
1366
1367          inc = inc * 2
1368
1369       ENDDO
1370!
1371!--    Reset grid_level to "normal" grid
1372       grid_level = 0
1373       
1374    ENDIF
1375!
1376!-- Allocate flags needed for masking walls. Even though these flags are only
1377!-- required in the ws-scheme, the arrays need to be allocated here as they are
1378!-- used in OpenACC directives.
1379    ALLOCATE( wall_flags_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                     &
1380              wall_flags_00(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
1381    wall_flags_0  = 0
1382    wall_flags_00 = 0
1383!
1384!-- Init flags for ws-scheme to degrade order of the numerics near walls, i.e.
1385!-- to decrease the numerical stencil appropriately.
1386    IF ( momentum_advec == 'ws-scheme'  .OR.  scalar_advec == 'ws-scheme'  .OR.&
1387         scalar_advec   == 'ws-scheme-mono' )  THEN
1388       CALL ws_init_flags
1389    ENDIF
1390
1391!
1392!-- In case of topography: limit near-wall mixing length l_wall further:
1393!-- Go through all points of the subdomain one by one and look for the closest
1394!-- surface
1395    IF ( TRIM(topography) /= 'flat' )  THEN
1396       DO  i = nxl, nxr
1397          DO  j = nys, nyn
1398
1399             nzb_si = nzb_s_inner(j,i)
1400             vi     = vertical_influence(nzb_si)
1401
1402             IF ( wall_n(j,i) > 0 )  THEN
1403!
1404!--             North wall (y distance)
1405                DO  k = wall_n(j,i), nzb_si
1406                   l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), 0.5_wp * dy )
1407                ENDDO
1408!
1409!--             Above North wall (yz distance)
1410                DO  k = nzb_si + 1, nzb_si + vi
1411                   l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i),                     &
1412                                          SQRT( 0.25_wp * dy**2 +              &
1413                                          ( zu(k) - zw(nzb_si) )**2 ) )
1414                ENDDO
1415!
1416!--             Northleft corner (xy distance)
1417                IF ( corner_nl(j,i) > 0 )  THEN
1418                   DO  k = corner_nl(j,i), nzb_si
1419                      l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), &
1420                                               0.5_wp * SQRT( dx**2 + dy**2 ) )
1421                   ENDDO
1422!
1423!--                Above Northleft corner (xyz distance)
1424                   DO  k = nzb_si + 1, nzb_si + vi
1425                      l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1),              &
1426                                            SQRT( 0.25_wp * (dx**2 + dy**2) +  &
1427                                            ( zu(k) - zw(nzb_si) )**2 ) )
1428                   ENDDO
1429                ENDIF
1430!
1431!--             Northright corner (xy distance)
1432                IF ( corner_nr(j,i) > 0 )  THEN
1433                   DO  k = corner_nr(j,i), nzb_si
1434                       l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1),             &
1435                                                0.5_wp * SQRT( dx**2 + dy**2 ) )
1436                   ENDDO
1437!
1438!--                Above northright corner (xyz distance)
1439                   DO  k = nzb_si + 1, nzb_si + vi
1440                      l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1),              &
1441                                            SQRT( 0.25_wp * (dx**2 + dy**2) +  &
1442                                            ( zu(k) - zw(nzb_si) )**2 ) )
1443                   ENDDO
1444                ENDIF
1445             ENDIF
1446
1447             IF ( wall_s(j,i) > 0 )  THEN
1448!
1449!--             South wall (y distance)
1450                DO  k = wall_s(j,i), nzb_si
1451                   l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), 0.5_wp * dy )
1452                ENDDO
1453!
1454!--             Above south wall (yz distance)
1455                DO  k = nzb_si + 1, nzb_si + vi
1456                   l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i),                     &
1457                                          SQRT( 0.25_wp * dy**2 +              &
1458                                          ( zu(k) - zw(nzb_si) )**2 ) )
1459                ENDDO
1460!
1461!--             Southleft corner (xy distance)
1462                IF ( corner_sl(j,i) > 0 )  THEN
1463                   DO  k = corner_sl(j,i), nzb_si
1464                      l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1),              &
1465                                               0.5_wp * SQRT( dx**2 + dy**2 ) )
1466                   ENDDO
1467!
1468!--                Above southleft corner (xyz distance)
1469                   DO  k = nzb_si + 1, nzb_si + vi
1470                      l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1),              &
1471                                            SQRT( 0.25_wp * (dx**2 + dy**2) +  &
1472                                            ( zu(k) - zw(nzb_si) )**2 ) )
1473                   ENDDO
1474                ENDIF
1475!
1476!--             Southright corner (xy distance)
1477                IF ( corner_sr(j,i) > 0 )  THEN
1478                   DO  k = corner_sr(j,i), nzb_si
1479                      l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1),              &
1480                                               0.5_wp * SQRT( dx**2 + dy**2 ) )
1481                   ENDDO
1482!
1483!--                Above southright corner (xyz distance)
1484                   DO  k = nzb_si + 1, nzb_si + vi
1485                      l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1),              &
1486                                            SQRT( 0.25_wp * (dx**2 + dy**2) +  &
1487                                            ( zu(k) - zw(nzb_si) )**2 ) )
1488                   ENDDO
1489                ENDIF
1490
1491             ENDIF
1492
1493             IF ( wall_l(j,i) > 0 )  THEN
1494!
1495!--             Left wall (x distance)
1496                DO  k = wall_l(j,i), nzb_si
1497                   l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), 0.5_wp * dx )
1498                ENDDO
1499!
1500!--             Above left wall (xz distance)
1501                DO  k = nzb_si + 1, nzb_si + vi
1502                   l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1),                     &
1503                                       SQRT( 0.25_wp * dx**2 +                 &
1504                                       ( zu(k) - zw(nzb_si) )**2 ) )
1505                ENDDO
1506             ENDIF
1507
1508             IF ( wall_r(j,i) > 0 )  THEN
1509!
1510!--             Right wall (x distance)
1511                DO  k = wall_r(j,i), nzb_si
1512                   l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), 0.5_wp * dx )
1513                ENDDO
1514!
1515!--             Above right wall (xz distance)
1516                DO  k = nzb_si + 1, nzb_si + vi
1517                   l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1),                     &
1518                                          SQRT( 0.25_wp * dx**2 +              &
1519                                          ( zu(k) - zw(nzb_si) )**2 ) )
1520                ENDDO
1521
1522             ENDIF
1523
1524          ENDDO
1525       ENDDO
1526
1527    ENDIF
1528
1529!
1530!-- Multiplication with wall_adjustment_factor
1531    l_wall = wall_adjustment_factor * l_wall
1532
1533!
1534!-- Set lateral boundary conditions for l_wall
1535    CALL exchange_horiz( l_wall, nbgp )
1536
1537    DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, &
1538                vertical_influence, wall_l, wall_n, wall_r, wall_s )
1539
1540
1541 END SUBROUTINE init_grid
Note: See TracBrowser for help on using the repository browser.