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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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