SUBROUTINE init_grid !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: init_grid.f90 1093 2013-02-02 12:58:49Z witha $ ! ! 1092 2013-02-02 11:24:22Z raasch ! unused variables removed ! ! 1069 2012-11-28 16:18:43Z maronga ! bugfix: added coupling_char to TOPOGRAPHY_DATA to allow topography in the ocean ! model in case of coupled runs ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! lower index for calculating wall_flags_0 set to nzb_w_inner instead of ! nzb_w_inner+1 ! ! 996 2012-09-07 10:41:47Z raasch ! little reformatting ! ! 978 2012-08-09 08:28:32Z fricke ! Bugfix: nzb_max is set to nzt at non-cyclic lateral boundaries ! Bugfix: Set wall_flags_0 for inflow boundary ! ! 927 2012-06-06 19:15:04Z raasch ! Wall flags are not set for multigrid method in case of masking method ! ! 864 2012-03-27 15:10:33Z gryschka ! In case of ocean and Dirichlet bottom bc for u and v dzu_mg and ddzu_pres ! were not correctly defined for k=1. ! ! 861 2012-03-26 14:18:34Z suehring ! Set wall_flags_0. The array is needed for degradation in ws-scheme near walls, ! inflow and outflow boundaries as well as near the bottom and the top of the ! model domain.! ! Initialization of nzb_s_inner and nzb_w_inner. ! gls has to be at least nbgp to do not exceed the array bounds of nzb_local ! while setting wall_flags_0 ! ! 843 2012-02-29 15:16:21Z gryschka ! In case of ocean and dirichlet bc for u and v at the bottom ! the first u-level ist defined at same height as the first w-level ! ! 818 2012-02-08 16:11:23Z maronga ! Bugfix: topo_height is only required if topography is used. It is thus now ! allocated in the topography branch ! ! 809 2012-01-30 13:32:58Z maronga ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives ! ! 807 2012-01-25 11:53:51Z maronga ! New cpp directive "__check" implemented which is used by check_namelist_files ! ! 759 2011-09-15 13:58:31Z raasch ! Splitting of parallel I/O in blocks of PEs ! ! 722 2011-04-11 06:21:09Z raasch ! Bugfix: bc_lr/ns_cyc replaced by bc_lr/ns, because variables are not yet set ! here ! ! 709 2011-03-30 09:31:40Z raasch ! formatting adjustments ! ! 707 2011-03-29 11:39:40Z raasch ! bc_lr/ns replaced by bc_lr/ns_cyc ! ! 667 2010-12-23 12:06:00Z suehring/gryschka ! Definition of new array bounds nxlg, nxrg, nysg, nyng on each PE. ! Furthermore the allocation of arrays and steering of loops is done with these ! parameters. Call of exchange_horiz are modified. ! In case of dirichlet bounday condition at the bottom zu(0)=0.0 ! dzu_mg has to be set explicitly for a equally spaced grid near bottom. ! ddzu_pres added to use a equally spaced grid near bottom. ! ! 555 2010-09-07 07:32:53Z raasch ! Bugfix: default setting of nzb_local for flat topography ! ! 274 2009-03-26 15:11:21Z heinze ! Output of messages replaced by message handling routine. ! new topography case 'single_street_canyon' ! ! 217 2008-12-09 18:00:48Z letzel ! +topography_grid_convention ! ! 134 2007-11-21 07:28:38Z letzel ! Redefine initial nzb_local as the actual total size of topography (later the ! extent of topography in nzb_local is reduced by 1dx at the E topography walls ! and by 1dy at the N topography walls to form the basis for nzb_s_inner); ! for consistency redefine 'single_building' case. ! Calculation of wall flag arrays ! ! 94 2007-06-01 15:25:22Z raasch ! Grid definition for ocean version ! ! 75 2007-03-22 09:54:05Z raasch ! storage of topography height arrays zu_s_inner and zw_s_inner, ! 2nd+3rd argument removed from exchange horiz ! ! 19 2007-02-23 04:53:48Z raasch ! Setting of nzt_diff ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.17 2006/08/22 14:00:05 raasch ! +dz_max to limit vertical stretching, ! bugfix in index array initialization for line- or point-like topography ! structures ! ! Revision 1.1 1997/08/11 06:17:45 raasch ! Initial revision (Testversion) ! ! ! Description: ! ------------ ! Creating grid depending constants !------------------------------------------------------------------------------! USE arrays_3d USE control_parameters USE grid_variables USE indices USE pegrid IMPLICIT NONE INTEGER :: bh, blx, bly, bxl, bxr, byn, bys, ch, cwx, cwy, cxl, cxr, cyn, & cys, gls, i, ii, inc, j, k, l, nxl_l, nxr_l, nyn_l, nys_l, & nzb_si, nzt_l, vi INTEGER, DIMENSION(:), ALLOCATABLE :: vertical_influence INTEGER, DIMENSION(:,:), ALLOCATABLE :: corner_nl, corner_nr, corner_sl, & corner_sr, wall_l, wall_n, wall_r,& wall_s, nzb_local, nzb_tmp LOGICAL :: flag_set = .FALSE. REAL :: dx_l, dy_l, dz_stretched REAL, DIMENSION(:,:), ALLOCATABLE :: topo_height ! !-- Calculation of horizontal array bounds including ghost layers nxlg = nxl - nbgp nxrg = nxr + nbgp nysg = nys - nbgp nyng = nyn + nbgp ! !-- Allocate grid arrays ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) ) ! !-- Compute height of u-levels from constant grid length and dz stretch factors IF ( dz == -1.0 ) THEN message_string = 'missing dz' CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) ELSEIF ( dz <= 0.0 ) THEN WRITE( message_string, * ) 'dz=',dz,' <= 0.0' CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) ENDIF ! !-- Define the vertical grid levels IF ( .NOT. ocean ) THEN ! !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). !-- The second u-level (k=1) corresponds to the top of the !-- Prandtl-layer. IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN zu(0) = 0.0 ! zu(0) = - dz * 0.5 ELSE zu(0) = - dz * 0.5 ENDIF zu(1) = dz * 0.5 dz_stretch_level_index = nzt+1 dz_stretched = dz DO k = 2, nzt+1 IF ( dz_stretch_level <= zu(k-1) .AND. dz_stretched < dz_max ) THEN dz_stretched = dz_stretched * dz_stretch_factor dz_stretched = MIN( dz_stretched, dz_max ) IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1 ENDIF zu(k) = zu(k-1) + dz_stretched ENDDO ! !-- Compute the w-levels. They are always staggered half-way between the !-- corresponding u-levels. In case of dirichlet bc for u and v at the !-- ground the first u- and w-level (k=0) are defined at same height (z=0). !-- The top w-level is extrapolated linearly. zw(0) = 0.0 DO k = 1, nzt zw(k) = ( zu(k) + zu(k+1) ) * 0.5 ENDDO zw(nzt+1) = zw(nzt) + 2.0 * ( zu(nzt+1) - zw(nzt) ) ELSE ! !-- Grid for ocean with free water surface is at k=nzt (w-grid). !-- In case of neumann bc at the ground the first first u-level (k=0) lies !-- below the first w-level (k=0). In case of dirichlet bc the first u- and !-- w-level are defined at same height, but staggered from the second level. !-- The second u-level (k=1) corresponds to the top of the Prandtl-layer. zu(nzt+1) = dz * 0.5 zu(nzt) = - dz * 0.5 dz_stretch_level_index = 0 dz_stretched = dz DO k = nzt-1, 0, -1 IF ( dz_stretch_level <= ABS( zu(k+1) ) .AND. & dz_stretched < dz_max ) THEN dz_stretched = dz_stretched * dz_stretch_factor dz_stretched = MIN( dz_stretched, dz_max ) IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1 ENDIF zu(k) = zu(k+1) - dz_stretched ENDDO ! !-- Compute the w-levels. They are always staggered half-way between the !-- corresponding u-levels, except in case of dirichlet bc for u and v !-- at the ground. In this case the first u- and w-level are defined at !-- same height. The top w-level (nzt+1) is not used but set for !-- consistency, since w and all scalar variables are defined up tp nzt+1. zw(nzt+1) = dz zw(nzt) = 0.0 DO k = 0, nzt zw(k) = ( zu(k) + zu(k+1) ) * 0.5 ENDDO ! !-- In case of dirichlet bc for u and v the first u- and w-level are defined !-- at same height. IF ( ibc_uv_b == 0 ) THEN zu(0) = zw(0) ENDIF ENDIF ! !-- Compute grid lengths. DO k = 1, nzt+1 dzu(k) = zu(k) - zu(k-1) ddzu(k) = 1.0 / dzu(k) dzw(k) = zw(k) - zw(k-1) ddzw(k) = 1.0 / dzw(k) ENDDO DO k = 1, nzt dd2zu(k) = 1.0 / ( dzu(k) + dzu(k+1) ) ENDDO ! !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid !-- everywhere. For the actual grid, the grid spacing at the lowest level !-- is only dz/2, but should be dz. Therefore, an additional array !-- containing with appropriate grid information is created for these !-- solvers. IF ( psolver /= 'multigrid' ) THEN ALLOCATE( ddzu_pres(1:nzt+1) ) ddzu_pres = ddzu ddzu_pres(1) = ddzu_pres(2) ! change for lowest level ENDIF ! !-- In case of multigrid method, compute grid lengths and grid factors for the !-- grid levels IF ( psolver == 'multigrid' ) THEN ALLOCATE( ddx2_mg(maximum_grid_level), ddy2_mg(maximum_grid_level), & dzu_mg(nzb+1:nzt+1,maximum_grid_level), & dzw_mg(nzb+1:nzt+1,maximum_grid_level), & f1_mg(nzb+1:nzt,maximum_grid_level), & f2_mg(nzb+1:nzt,maximum_grid_level), & f3_mg(nzb+1:nzt,maximum_grid_level) ) dzu_mg(:,maximum_grid_level) = dzu ! !-- Next line to ensure an equally spaced grid. dzu_mg(1,maximum_grid_level) = dzu(2) dzw_mg(:,maximum_grid_level) = dzw nzt_l = nzt DO l = maximum_grid_level-1, 1, -1 dzu_mg(nzb+1,l) = 2.0 * dzu_mg(nzb+1,l+1) dzw_mg(nzb+1,l) = 2.0 * dzw_mg(nzb+1,l+1) nzt_l = nzt_l / 2 DO k = 2, nzt_l+1 dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1) dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1) ENDDO ENDDO nzt_l = nzt dx_l = dx dy_l = dy DO l = maximum_grid_level, 1, -1 ddx2_mg(l) = 1.0 / dx_l**2 ddy2_mg(l) = 1.0 / dy_l**2 DO k = nzb+1, nzt_l f2_mg(k,l) = 1.0 / ( dzu_mg(k+1,l) * dzw_mg(k,l) ) f3_mg(k,l) = 1.0 / ( dzu_mg(k,l) * dzw_mg(k,l) ) f1_mg(k,l) = 2.0 * ( ddx2_mg(l) + ddy2_mg(l) ) + & f2_mg(k,l) + f3_mg(k,l) ENDDO nzt_l = nzt_l / 2 dx_l = dx_l * 2.0 dy_l = dy_l * 2.0 ENDDO ENDIF ! !-- Compute the reciprocal values of the horizontal grid lengths. ddx = 1.0 / dx ddy = 1.0 / dy dx2 = dx * dx dy2 = dy * dy ddx2 = 1.0 / dx2 ddy2 = 1.0 / dy2 ! !-- Compute the grid-dependent mixing length. DO k = 1, nzt l_grid(k) = ( dx * dy * dzw(k) )**0.33333333333333 ENDDO ! !-- Allocate outer and inner index arrays for topography and set !-- defaults. !-- nzb_local has to contain additional layers of ghost points for calculating !-- the flag arrays needed for the multigrid method gls = 2**( maximum_grid_level ) IF ( gls < nbgp ) gls = nbgp ALLOCATE( corner_nl(nys:nyn,nxl:nxr), corner_nr(nys:nyn,nxl:nxr), & corner_sl(nys:nyn,nxl:nxr), corner_sr(nys:nyn,nxl:nxr), & nzb_local(-gls:ny+gls,-gls:nx+gls), & nzb_tmp(-nbgp:ny+nbgp,-nbgp:nx+nbgp), & wall_l(nys:nyn,nxl:nxr), wall_n(nys:nyn,nxl:nxr), & wall_r(nys:nyn,nxl:nxr), wall_s(nys:nyn,nxl:nxr) ) ALLOCATE( fwxm(nysg:nyng,nxlg:nxrg), fwxp(nysg:nyng,nxlg:nxrg), & fwym(nysg:nyng,nxlg:nxrg), fwyp(nysg:nyng,nxlg:nxrg), & fxm(nysg:nyng,nxlg:nxrg), fxp(nysg:nyng,nxlg:nxrg), & fym(nysg:nyng,nxlg:nxrg), fyp(nysg:nyng,nxlg:nxrg), & nzb_s_inner(nysg:nyng,nxlg:nxrg), & nzb_s_outer(nysg:nyng,nxlg:nxrg), & nzb_u_inner(nysg:nyng,nxlg:nxrg), & nzb_u_outer(nysg:nyng,nxlg:nxrg), & nzb_v_inner(nysg:nyng,nxlg:nxrg), & nzb_v_outer(nysg:nyng,nxlg:nxrg), & nzb_w_inner(nysg:nyng,nxlg:nxrg), & nzb_w_outer(nysg:nyng,nxlg:nxrg), & nzb_diff_s_inner(nysg:nyng,nxlg:nxrg), & nzb_diff_s_outer(nysg:nyng,nxlg:nxrg), & nzb_diff_u(nysg:nyng,nxlg:nxrg), & nzb_diff_v(nysg:nyng,nxlg:nxrg), & nzb_2d(nysg:nyng,nxlg:nxrg), & wall_e_x(nysg:nyng,nxlg:nxrg), & wall_e_y(nysg:nyng,nxlg:nxrg), & wall_u(nysg:nyng,nxlg:nxrg), & wall_v(nysg:nyng,nxlg:nxrg), & wall_w_x(nysg:nyng,nxlg:nxrg), & wall_w_y(nysg:nyng,nxlg:nxrg) ) ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) nzb_s_inner = nzb; nzb_s_outer = nzb nzb_u_inner = nzb; nzb_u_outer = nzb nzb_v_inner = nzb; nzb_v_outer = nzb nzb_w_inner = nzb; nzb_w_outer = nzb ! !-- Define vertical gridpoint from (or to) which on the usual finite difference !-- form (which does not use surface fluxes) is applied IF ( prandtl_layer .OR. use_surface_fluxes ) THEN nzb_diff = nzb + 2 ELSE nzb_diff = nzb + 1 ENDIF IF ( use_top_fluxes ) THEN nzt_diff = nzt - 1 ELSE nzt_diff = nzt ENDIF nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff nzb_diff_u = nzb_diff; nzb_diff_v = nzb_diff wall_e_x = 0.0; wall_e_y = 0.0; wall_u = 0.0; wall_v = 0.0 wall_w_x = 0.0; wall_w_y = 0.0 fwxp = 1.0; fwxm = 1.0; fwyp = 1.0; fwym = 1.0 fxp = 1.0; fxm = 1.0; fyp = 1.0; fym = 1.0 ! !-- Initialize near-wall mixing length l_wall only in the vertical direction !-- for the moment, !-- multiplication with wall_adjustment_factor near the end of this routine l_wall(nzb,:,:) = l_grid(1) DO k = nzb+1, nzt l_wall(k,:,:) = l_grid(k) ENDDO l_wall(nzt+1,:,:) = l_grid(nzt) ALLOCATE ( vertical_influence(nzb:nzt) ) DO k = 1, nzt vertical_influence(k) = MIN ( INT( l_grid(k) / & ( wall_adjustment_factor * dzw(k) ) + 0.5 ), nzt - k ) ENDDO DO k = 1, MAXVAL( nzb_s_inner ) IF ( l_grid(k) > 1.5 * dx * wall_adjustment_factor .OR. & l_grid(k) > 1.5 * dy * wall_adjustment_factor ) THEN WRITE( message_string, * ) 'grid anisotropy exceeds ', & 'threshold given by only local', & ' &horizontal reduction of near_wall ', & 'mixing length l_wall', & ' &starting from height level k = ', k, '.' CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 ) EXIT ENDIF ENDDO vertical_influence(0) = vertical_influence(1) DO i = nxlg, nxrg DO j = nysg, nyng DO k = nzb_s_inner(j,i) + 1, & nzb_s_inner(j,i) + vertical_influence(nzb_s_inner(j,i)) l_wall(k,j,i) = zu(k) - zw(nzb_s_inner(j,i)) ENDDO ENDDO ENDDO ! !-- Set outer and inner index arrays for non-flat topography. !-- Here consistency checks concerning domain size and periodicity are !-- necessary. !-- Within this SELECT CASE structure only nzb_local is initialized !-- individually depending on the chosen topography type, all other index !-- arrays are initialized further below. SELECT CASE ( TRIM( topography ) ) CASE ( 'flat' ) ! !-- nzb_local is required for the multigrid solver nzb_local = 0 CASE ( 'single_building' ) ! !-- Single rectangular building, by default centered in the middle of the !-- total domain blx = NINT( building_length_x / dx ) bly = NINT( building_length_y / dy ) bh = NINT( building_height / dz ) IF ( building_wall_left == 9999999.9 ) THEN building_wall_left = ( nx + 1 - blx ) / 2 * dx ENDIF bxl = NINT( building_wall_left / dx ) bxr = bxl + blx IF ( building_wall_south == 9999999.9 ) THEN building_wall_south = ( ny + 1 - bly ) / 2 * dy ENDIF bys = NINT( building_wall_south / dy ) byn = bys + bly ! !-- Building size has to meet some requirements IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN WRITE( message_string, * ) 'inconsistent building parameters:', & '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & 'byn=', byn, 'nx=', nx, 'ny=', ny CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) ENDIF ! !-- Define the building. nzb_local = 0 nzb_local(bys:byn,bxl:bxr) = bh CASE ( 'single_street_canyon' ) ! !-- Single quasi-2D street canyon of infinite length in x or y direction. !-- The canyon is centered in the other direction by default. IF ( canyon_width_x /= 9999999.9 ) THEN ! !-- Street canyon in y direction cwx = NINT( canyon_width_x / dx ) IF ( canyon_wall_left == 9999999.9 ) THEN canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx ENDIF cxl = NINT( canyon_wall_left / dx ) cxr = cxl + cwx ELSEIF ( canyon_width_y /= 9999999.9 ) THEN ! !-- Street canyon in x direction cwy = NINT( canyon_width_y / dy ) IF ( canyon_wall_south == 9999999.9 ) THEN canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy ENDIF cys = NINT( canyon_wall_south / dy ) cyn = cys + cwy ELSE message_string = 'no street canyon width given' CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) ENDIF ch = NINT( canyon_height / dz ) dp_level_ind_b = ch ! !-- Street canyon size has to meet some requirements IF ( canyon_width_x /= 9999999.9 ) THEN IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & ( ch < 3 ) ) THEN WRITE( message_string, * ) 'inconsistent canyon parameters:', & '&cxl=', cxl, 'cxr=', cxr, & 'cwx=', cwx, & 'ch=', ch, 'nx=', nx, 'ny=', ny CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) ENDIF ELSEIF ( canyon_width_y /= 9999999.9 ) THEN IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & ( ch < 3 ) ) THEN WRITE( message_string, * ) 'inconsistent canyon parameters:', & '&cys=', cys, 'cyn=', cyn, & 'cwy=', cwy, & 'ch=', ch, 'nx=', nx, 'ny=', ny CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) ENDIF ENDIF IF ( canyon_width_x /= 9999999.9 .AND. canyon_width_y /= 9999999.9 ) & THEN message_string = 'inconsistent canyon parameters:' // & '&street canyon can only be oriented' // & '&either in x- or in y-direction' CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) ENDIF nzb_local = ch IF ( canyon_width_x /= 9999999.9 ) THEN nzb_local(:,cxl+1:cxr-1) = 0 ELSEIF ( canyon_width_y /= 9999999.9 ) THEN nzb_local(cys+1:cyn-1,:) = 0 ENDIF CASE ( 'read_from_file' ) ALLOCATE ( topo_height(0:ny,0:nx) ) DO ii = 0, io_blocks-1 IF ( ii == io_group ) THEN ! !-- Arbitrary irregular topography data in PALM format (exactly !-- matching the grid size and total domain size) OPEN( 90, FILE='TOPOGRAPHY_DATA'//coupling_char, STATUS='OLD', & FORM='FORMATTED', ERR=10 ) DO j = ny, 0, -1 READ( 90, *, ERR=11, END=11 ) ( topo_height(j,i), i = 0,nx ) ENDDO GOTO 12 10 message_string = 'file TOPOGRAPHY'//coupling_char//' does not exist' CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 ) 11 message_string = 'errors in file TOPOGRAPHY_DATA'//coupling_char CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 ) 12 CLOSE( 90 ) ENDIF #if defined( __parallel ) && ! defined ( __check ) CALL MPI_BARRIER( comm2d, ierr ) #endif ENDDO ! !-- Calculate the index height of the topography DO i = 0, nx DO j = 0, ny nzb_local(j,i) = NINT( topo_height(j,i) / dz ) ENDDO ENDDO DEALLOCATE ( topo_height ) ! !-- Add cyclic boundaries (additional layers are for calculating !-- flag arrays needed for the multigrid sover) nzb_local(-gls:-1,0:nx) = nzb_local(ny-gls+1:ny,0:nx) nzb_local(ny+1:ny+gls,0:nx) = nzb_local(0:gls-1,0:nx) nzb_local(:,-gls:-1) = nzb_local(:,nx-gls+1:nx) nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) CASE DEFAULT ! !-- The DEFAULT case is reached either if the parameter topography !-- contains a wrong character string or if the user has defined a special !-- case in the user interface. There, the subroutine user_init_grid !-- checks which of these two conditions applies. CALL user_init_grid( gls, nzb_local ) END SELECT ! !-- Determine the maximum level of topography. Furthermore it is used for !-- steering the degradation of order of the applied advection scheme. !-- In case of non-cyclic lateral boundaries, the order of the advection !-- scheme have to be reduced up to nzt (required at the lateral boundaries). nzb_max = MAXVAL( nzb_local ) IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR. & inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s ) THEN nzb_max = nzt ENDIF ! !-- Consistency checks and index array initialization are only required for !-- non-flat topography, also the initialization of topography height arrays !-- zu_s_inner and zw_w_inner IF ( TRIM( topography ) /= 'flat' ) THEN ! !-- Consistency checks IF ( MINVAL( nzb_local ) < 0 .OR. MAXVAL( nzb_local ) > nz + 1 ) THEN WRITE( message_string, * ) 'nzb_local values are outside the', & 'model domain', & '&MINVAL( nzb_local ) = ', MINVAL(nzb_local), & '&MAXVAL( nzb_local ) = ', MAXVAL(nzb_local) CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) ENDIF IF ( bc_lr == 'cyclic' ) THEN IF ( ANY( nzb_local(:,-1) /= nzb_local(:,nx) ) .OR. & ANY( nzb_local(:,0) /= nzb_local(:,nx+1) ) ) THEN message_string = 'nzb_local does not fulfill cyclic' // & ' boundary condition in x-direction' CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 ) ENDIF ENDIF IF ( bc_ns == 'cyclic' ) THEN IF ( ANY( nzb_local(-1,:) /= nzb_local(ny,:) ) .OR. & ANY( nzb_local(0,:) /= nzb_local(ny+1,:) ) ) THEN message_string = 'nzb_local does not fulfill cyclic' // & ' boundary condition in y-direction' CALL message( 'init_grid', 'PA0212', 1, 2, 0, 6, 0 ) ENDIF ENDIF IF ( topography_grid_convention == 'cell_edge' ) THEN ! !-- The array nzb_local as defined using the 'cell_edge' convention !-- describes the actual total size of topography which is defined at the !-- cell edges where u=0 on the topography walls in x-direction and v=0 !-- on the topography walls in y-direction. However, PALM uses individual !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. !-- Therefore, the extent of topography in nzb_local is now reduced by !-- 1dx at the E topography walls and by 1dy at the N topography walls !-- to form the basis for nzb_s_inner. DO j = -gls, ny + gls DO i = -gls, nx nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) ) ENDDO ENDDO !-- apply cyclic boundary conditions in x-direction !(ist das erforderlich? Ursache von Seung Bus Fehler?) nzb_local(:,nx+1:nx+gls) = nzb_local(:,0:gls-1) DO i = -gls, nx + gls DO j = -gls, ny nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) ) ENDDO ENDDO !-- apply cyclic boundary conditions in y-direction !(ist das erforderlich? Ursache von Seung Bus Fehler?) nzb_local(ny+1:ny+gls,:) = nzb_local(0:gls-1,:) ENDIF ! !-- Initialize index arrays nzb_s_inner and nzb_w_inner nzb_s_inner = nzb_local(nysg:nyng,nxlg:nxrg) nzb_w_inner = nzb_local(nysg:nyng,nxlg:nxrg) ! !-- Initialize remaining index arrays: !-- first pre-initialize them with nzb_s_inner... nzb_u_inner = nzb_s_inner nzb_u_outer = nzb_s_inner nzb_v_inner = nzb_s_inner nzb_v_outer = nzb_s_inner nzb_w_outer = nzb_s_inner nzb_s_outer = nzb_s_inner ! !-- ...then extend pre-initialized arrays in their according directions !-- based on nzb_local using nzb_tmp as a temporary global index array ! !-- nzb_s_outer: !-- extend nzb_local east-/westwards first, then north-/southwards nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) DO j = -1, ny + 1 DO i = 0, nx nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & nzb_local(j,i+1) ) ENDDO ENDDO DO i = nxl, nxr DO j = nys, nyn nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & nzb_tmp(j+1,i) ) ENDDO ! !-- non-cyclic boundary conditions (overwritten by call of !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) IF ( nys == 0 ) THEN j = -1 nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) ENDIF IF ( nys == ny ) THEN j = ny + 1 nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) ENDIF ENDDO ! !-- nzb_w_outer: !-- identical to nzb_s_outer nzb_w_outer = nzb_s_outer ! !-- nzb_u_inner: !-- extend nzb_local rightwards only nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) DO j = -1, ny + 1 DO i = 0, nx + 1 nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) ENDDO ENDDO nzb_u_inner = nzb_tmp(nysg:nyng,nxlg:nxrg) ! !-- nzb_u_outer: !-- extend current nzb_tmp (nzb_u_inner) north-/southwards DO i = nxl, nxr DO j = nys, nyn nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & nzb_tmp(j+1,i) ) ENDDO ! !-- non-cyclic boundary conditions (overwritten by call of !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) IF ( nys == 0 ) THEN j = -1 nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) ENDIF IF ( nys == ny ) THEN j = ny + 1 nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) ENDIF ENDDO ! !-- nzb_v_inner: !-- extend nzb_local northwards only nzb_tmp = nzb_local(-nbgp:ny+nbgp,-nbgp:nx+nbgp) DO i = -1, nx + 1 DO j = 0, ny + 1 nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) ENDDO ENDDO nzb_v_inner = nzb_tmp(nys-nbgp:nyn+nbgp,nxl-nbgp:nxr+nbgp) ! !-- nzb_v_outer: !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards DO j = nys, nyn DO i = nxl, nxr nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & nzb_tmp(j,i+1) ) ENDDO ! !-- non-cyclic boundary conditions (overwritten by call of !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) IF ( nxl == 0 ) THEN i = -1 nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) ENDIF IF ( nxr == nx ) THEN i = nx + 1 nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) ENDIF ENDDO #if ! defined ( __check ) ! !-- Exchange of lateral boundary values (parallel computers) and cyclic !-- boundary conditions, if applicable. !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local !-- they do not require exchange and are not included here. CALL exchange_horiz_2d_int( nzb_u_inner ) CALL exchange_horiz_2d_int( nzb_u_outer ) CALL exchange_horiz_2d_int( nzb_v_inner ) CALL exchange_horiz_2d_int( nzb_v_outer ) CALL exchange_horiz_2d_int( nzb_w_outer ) CALL exchange_horiz_2d_int( nzb_s_outer ) ! !-- Allocate and set the arrays containing the topography height IF ( myid == 0 ) THEN ALLOCATE( zu_s_inner(0:nx+1,0:ny+1), zw_w_inner(0:nx+1,0:ny+1) ) DO i = 0, nx + 1 DO j = 0, ny + 1 zu_s_inner(i,j) = zu(nzb_local(j,i)) zw_w_inner(i,j) = zw(nzb_local(j,i)) ENDDO ENDDO ENDIF #endif ENDIF #if ! defined ( __check ) ! !-- Preliminary: to be removed after completion of the topography code! !-- Set the former default k index arrays nzb_2d nzb_2d = nzb ! !-- Set the individual index arrays which define the k index from which on !-- the usual finite difference form (which does not use surface fluxes) is !-- applied IF ( prandtl_layer .OR. use_surface_fluxes ) THEN nzb_diff_u = nzb_u_inner + 2 nzb_diff_v = nzb_v_inner + 2 nzb_diff_s_inner = nzb_s_inner + 2 nzb_diff_s_outer = nzb_s_outer + 2 ELSE nzb_diff_u = nzb_u_inner + 1 nzb_diff_v = nzb_v_inner + 1 nzb_diff_s_inner = nzb_s_inner + 1 nzb_diff_s_outer = nzb_s_outer + 1 ENDIF ! !-- Calculation of wall switches and factors required by diffusion_u/v.f90 and !-- for limitation of near-wall mixing length l_wall further below corner_nl = 0 corner_nr = 0 corner_sl = 0 corner_sr = 0 wall_l = 0 wall_n = 0 wall_r = 0 wall_s = 0 DO i = nxl, nxr DO j = nys, nyn ! !-- u-component IF ( nzb_u_outer(j,i) > nzb_u_outer(j+1,i) ) THEN wall_u(j,i) = 1.0 ! north wall (location of adjacent fluid) fym(j,i) = 0.0 fyp(j,i) = 1.0 ELSEIF ( nzb_u_outer(j,i) > nzb_u_outer(j-1,i) ) THEN wall_u(j,i) = 1.0 ! south wall (location of adjacent fluid) fym(j,i) = 1.0 fyp(j,i) = 0.0 ENDIF ! !-- v-component IF ( nzb_v_outer(j,i) > nzb_v_outer(j,i+1) ) THEN wall_v(j,i) = 1.0 ! rigth wall (location of adjacent fluid) fxm(j,i) = 0.0 fxp(j,i) = 1.0 ELSEIF ( nzb_v_outer(j,i) > nzb_v_outer(j,i-1) ) THEN wall_v(j,i) = 1.0 ! left wall (location of adjacent fluid) fxm(j,i) = 1.0 fxp(j,i) = 0.0 ENDIF ! !-- w-component, also used for scalars, separate arrays for shear !-- production of tke IF ( nzb_w_outer(j,i) > nzb_w_outer(j+1,i) ) THEN wall_e_y(j,i) = 1.0 ! north wall (location of adjacent fluid) wall_w_y(j,i) = 1.0 fwym(j,i) = 0.0 fwyp(j,i) = 1.0 ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j-1,i) ) THEN wall_e_y(j,i) = -1.0 ! south wall (location of adjacent fluid) wall_w_y(j,i) = 1.0 fwym(j,i) = 1.0 fwyp(j,i) = 0.0 ENDIF IF ( nzb_w_outer(j,i) > nzb_w_outer(j,i+1) ) THEN wall_e_x(j,i) = 1.0 ! right wall (location of adjacent fluid) wall_w_x(j,i) = 1.0 fwxm(j,i) = 0.0 fwxp(j,i) = 1.0 ELSEIF ( nzb_w_outer(j,i) > nzb_w_outer(j,i-1) ) THEN wall_e_x(j,i) = -1.0 ! left wall (location of adjacent fluid) wall_w_x(j,i) = 1.0 fwxm(j,i) = 1.0 fwxp(j,i) = 0.0 ENDIF ! !-- Wall and corner locations inside buildings for limitation of !-- near-wall mixing length l_wall IF ( nzb_s_inner(j,i) > nzb_s_inner(j+1,i) ) THEN wall_n(j,i) = nzb_s_inner(j+1,i) + 1 ! North wall IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN corner_nl(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northleft corner nzb_s_inner(j,i-1) ) + 1 ENDIF IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN corner_nr(j,i) = MAX( nzb_s_inner(j+1,i), & ! Northright corner nzb_s_inner(j,i+1) ) + 1 ENDIF ENDIF IF ( nzb_s_inner(j,i) > nzb_s_inner(j-1,i) ) THEN wall_s(j,i) = nzb_s_inner(j-1,i) + 1 ! South wall IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN corner_sl(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southleft corner nzb_s_inner(j,i-1) ) + 1 ENDIF IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN corner_sr(j,i) = MAX( nzb_s_inner(j-1,i), & ! Southright corner nzb_s_inner(j,i+1) ) + 1 ENDIF ENDIF IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i-1) ) THEN wall_l(j,i) = nzb_s_inner(j,i-1) + 1 ! Left wall ENDIF IF ( nzb_s_inner(j,i) > nzb_s_inner(j,i+1) ) THEN wall_r(j,i) = nzb_s_inner(j,i+1) + 1 ! Right wall ENDIF ENDDO ENDDO ! !-- Calculate wall flag arrays for the multigrid method IF ( psolver == 'multigrid' ) THEN ! !-- Gridpoint increment of the current level inc = 1 DO l = maximum_grid_level, 1 , -1 nxl_l = nxl_mg(l) nxr_l = nxr_mg(l) nys_l = nys_mg(l) nyn_l = nyn_mg(l) nzt_l = nzt_mg(l) ! !-- Assign the flag level to be calculated SELECT CASE ( l ) CASE ( 1 ) flags => wall_flags_1 CASE ( 2 ) flags => wall_flags_2 CASE ( 3 ) flags => wall_flags_3 CASE ( 4 ) flags => wall_flags_4 CASE ( 5 ) flags => wall_flags_5 CASE ( 6 ) flags => wall_flags_6 CASE ( 7 ) flags => wall_flags_7 CASE ( 8 ) flags => wall_flags_8 CASE ( 9 ) flags => wall_flags_9 CASE ( 10 ) flags => wall_flags_10 END SELECT ! !-- Depending on the grid level, set the respective bits in case of !-- neighbouring walls !-- Bit 0: wall to the bottom !-- Bit 1: wall to the top (not realized in remaining PALM code so far) !-- Bit 2: wall to the south !-- Bit 3: wall to the north !-- Bit 4: wall to the left !-- Bit 5: wall to the right !-- Bit 6: inside building flags = 0 ! !-- In case of masking method, flags are not set and multigrid method !-- works like FFT-solver IF ( .NOT. masking_method ) THEN DO i = nxl_l-1, nxr_l+1 DO j = nys_l-1, nyn_l+1 DO k = nzb, nzt_l+1 ! !-- Inside/outside building (inside building does not need !-- further tests for walls) IF ( k*inc <= nzb_local(j*inc,i*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 6 ) ELSE ! !-- Bottom wall IF ( (k-1)*inc <= nzb_local(j*inc,i*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 0 ) ENDIF ! !-- South wall IF ( k*inc <= nzb_local((j-1)*inc,i*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 2 ) ENDIF ! !-- North wall IF ( k*inc <= nzb_local((j+1)*inc,i*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 3 ) ENDIF ! !-- Left wall IF ( k*inc <= nzb_local(j*inc,(i-1)*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 4 ) ENDIF ! !-- Right wall IF ( k*inc <= nzb_local(j*inc,(i+1)*inc) ) THEN flags(k,j,i) = IBSET( flags(k,j,i), 5 ) ENDIF ENDIF ENDDO ENDDO ENDDO ENDIF ! !-- Test output of flag arrays ! i = nxl_l ! WRITE (9,*) ' ' ! WRITE (9,*) '*** mg level ', l, ' ***', mg_switch_to_pe0_level ! WRITE (9,*) ' inc=', inc, ' i =', nxl_l ! WRITE (9,*) ' nxl_l',nxl_l,' nxr_l=',nxr_l,' nys_l=',nys_l,' nyn_l=',nyn_l ! DO k = nzt_l+1, nzb, -1 ! WRITE (9,'(194(1X,I2))') ( flags(k,j,i), j = nys_l-1, nyn_l+1 ) ! ENDDO inc = inc * 2 ENDDO ENDIF ! !-- Allocate flags needed for masking walls. ALLOCATE( wall_flags_0(nzb:nzt,nys:nyn,nxl:nxr) ) wall_flags_0 = 0 IF ( scalar_advec == 'ws-scheme' ) THEN ! !-- Set flags to steer the degradation of the advection scheme in advec_ws !-- near topography, inflow- and outflow boundaries as well as bottom and !-- top of model domain. wall_flags_0 remains zero for all non-prognostic !-- grid points. DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt ! !-- scalar - x-direction !-- WS1 (0), WS3 (1), WS5 (2) IF ( k <= nzb_s_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& .AND. i == nxl ) .OR. ( ( inflow_r .OR. outflow_r ) & .AND. i == nxr ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 ) ELSEIF ( k <= nzb_s_inner(j,i+2) .OR. k <= nzb_s_inner(j,i-1) & .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 2 ) ENDIF ! !-- scalar - y-direction !-- WS1 (3), WS3 (4), WS5 (5) IF ( k <= nzb_s_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & .AND. j == nyn ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 3 ) !-- WS3 ELSEIF ( k <= nzb_s_inner(j+2,i) .OR. k <= nzb_s_inner(j-1,i) & .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 4 ) !-- WS5 ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 5 ) ENDIF ! !-- scalar - z-direction !-- WS1 (6), WS3 (7), WS5 (8) flag_set = .FALSE. IF ( k == nzb_s_inner(j,i) + 1 .OR. k == nzt ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 6 ) flag_set = .TRUE. ELSEIF ( k == nzb_s_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 7 ) flag_set = .TRUE. ELSEIF ( k > nzb_s_inner(j,i) .AND. .NOT. flag_set ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) ENDIF ENDDO ENDDO ENDDO ENDIF IF ( momentum_advec == 'ws-scheme' ) THEN ! !-- Set wall_flags_0 to steer the degradation of the advection scheme in advec_ws !-- near topography, inflow- and outflow boundaries as well as bottom and !-- top of model domain. wall_flags_0 remains zero for all non-prognostic !-- grid points. DO i = nxl, nxr DO j = nys, nyn DO k = nzb_u_inner(j,i)+1, nzt ! !-- u component - x-direction !-- WS1 (9), WS3 (10), WS5 (11) IF ( k <= nzb_u_inner(j,i+1) & .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 9 ) ELSEIF ( k <= nzb_u_inner(j,i+2) .OR. k <= nzb_u_inner(j,i-1) & .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 )& .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu+1)& ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 10 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 11 ) ENDIF ! !-- u component - y-direction !-- WS1 (12), WS3 (13), WS5 (14) IF ( k <= nzb_u_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & .AND. j == nyn ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 ) ELSEIF ( k <= nzb_u_inner(j+2,i) .OR. k <= nzb_u_inner(j-1,i) & .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 13 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 14 ) ENDIF ! !-- u component - z-direction !-- WS1 (15), WS3 (16), WS5 (17) flag_set = .FALSE. IF ( k == nzb_u_inner(j,i) + 1 .OR. k == nzt ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 15 ) flag_set = .TRUE. ELSEIF ( k == nzb_u_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 16 ) flag_set = .TRUE. ELSEIF ( k > nzb_u_inner(j,i) .AND. .NOT. flag_set ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 17 ) ENDIF ENDDO ENDDO ENDDO DO i = nxl, nxr DO j = nys, nyn DO k = nzb_v_inner(j,i)+1, nzt ! !-- v component - x-direction !-- WS1 (18), WS3 (19), WS5 (20) IF ( k <= nzb_v_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& .AND. i == nxl ) .OR. (( inflow_r .OR. outflow_r ) & .AND. i == nxr ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 ) !-- WS3 ELSEIF ( k <= nzb_v_inner(j,i+2) .OR. k <= nzb_v_inner(j,i-1) & .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 19 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 20 ) ENDIF ! !-- v component - y-direction !-- WS1 (21), WS3 (22), WS5 (23) IF ( k <= nzb_v_inner(j+1,i) & .OR. ( ( inflow_s .OR. outflow_s ) .AND. i == nysv ) & .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 ) ELSEIF ( k <= nzb_v_inner(j+2,i) .OR. k <= nzb_v_inner(j-1,i) & .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv+1 )& .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 )& ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 22 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) ENDIF ! !-- v component - z-direction !-- WS1 (24), WS3 (25), WS5 (26) flag_set = .FALSE. IF ( k == nzb_v_inner(j,i) + 1 .OR. k == nzt ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 24 ) flag_set = .TRUE. ELSEIF ( k == nzb_v_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 25 ) flag_set = .TRUE. ELSEIF ( k > nzb_v_inner(j,i) .AND. .NOT. flag_set ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 26 ) ENDIF ENDDO ENDDO ENDDO DO i = nxl, nxr DO j = nys, nyn DO k = nzb_w_inner(j,i), nzt ! !-- w component - x-direction !-- WS1 (27), WS3 (28), WS5 (29) IF ( k <= nzb_w_inner(j,i+1) .OR. ( ( inflow_l .OR. outflow_l )& .AND. i == nxl ) .OR. ( ( inflow_r .OR. outflow_r ) & .AND. i == nxr ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 ) ELSEIF ( k <= nzb_w_inner(j,i+2) .OR. k <= nzb_w_inner(j,i-1) & .OR. ( ( inflow_r .OR. outflow_r ) .AND. i == nxr-1 ) & .OR. ( ( inflow_l .OR. outflow_l ) .AND. i == nxlu ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 28 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i),29 ) ENDIF ! !-- w component - y-direction !-- WS1 (30), WS3 (31), WS5 (32) IF ( k <= nzb_w_inner(j+1,i) .OR. ( ( inflow_s .OR. outflow_s )& .AND. j == nys ) .OR. ( ( inflow_n .OR. outflow_n ) & .AND. j == nyn ) ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) ELSEIF ( k <= nzb_w_inner(j+2,i) .OR. k <= nzb_w_inner(j-1,i) & .OR. ( ( inflow_s .OR. outflow_s ) .AND. j == nysv ) & .OR. ( ( inflow_n .OR. outflow_n ) .AND. j == nyn-1 ) & ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 31 ) ELSE wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 32 ) ENDIF ! !-- w component - z-direction !-- WS1 (33), WS3 (34), WS5 (35) flag_set = .FALSE. IF ( k == nzb_w_inner(j,i) .OR. k == nzb_w_inner(j,i) + 1 & .OR. k == nzt ) THEN ! !-- Please note, at k == nzb_w_inner(j,i) a flag is explictely !-- set, although this is not a prognostic level. However, !-- contrary to the advection of u,v and s this is necessary !-- because flux_t(nzb_w_inner(j,i)) is used for the tendency !-- at k == nzb_w_inner(j,i)+1. wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 33 ) flag_set = .TRUE. ELSEIF ( k == nzb_w_inner(j,i) + 2 .OR. k == nzt - 1 ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 34 ) flag_set = .TRUE. ELSEIF ( k > nzb_w_inner(j,i) .AND. .NOT. flag_set ) THEN wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 35 ) ENDIF ENDDO ENDDO ENDDO ENDIF ! !-- In case of topography: limit near-wall mixing length l_wall further: !-- Go through all points of the subdomain one by one and look for the closest !-- surface IF ( TRIM(topography) /= 'flat' ) THEN DO i = nxl, nxr DO j = nys, nyn nzb_si = nzb_s_inner(j,i) vi = vertical_influence(nzb_si) IF ( wall_n(j,i) > 0 ) THEN ! !-- North wall (y distance) DO k = wall_n(j,i), nzb_si l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), 0.5 * dy ) ENDDO ! !-- Above North wall (yz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j+1,i) = MIN( l_wall(k,j+1,i), & SQRT( 0.25 * dy**2 + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ! !-- Northleft corner (xy distance) IF ( corner_nl(j,i) > 0 ) THEN DO k = corner_nl(j,i), nzb_si l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & 0.5 * SQRT( dx**2 + dy**2 ) ) ENDDO ! !-- Above Northleft corner (xyz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j+1,i-1) = MIN( l_wall(k,j+1,i-1), & SQRT( 0.25 * (dx**2 + dy**2) + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF ! !-- Northright corner (xy distance) IF ( corner_nr(j,i) > 0 ) THEN DO k = corner_nr(j,i), nzb_si l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & 0.5 * SQRT( dx**2 + dy**2 ) ) ENDDO ! !-- Above northright corner (xyz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j+1,i+1) = MIN( l_wall(k,j+1,i+1), & SQRT( 0.25 * (dx**2 + dy**2) + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF ENDIF IF ( wall_s(j,i) > 0 ) THEN ! !-- South wall (y distance) DO k = wall_s(j,i), nzb_si l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), 0.5 * dy ) ENDDO ! !-- Above south wall (yz distance) DO k = nzb_si + 1, & nzb_si + vi l_wall(k,j-1,i) = MIN( l_wall(k,j-1,i), & SQRT( 0.25 * dy**2 + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ! !-- Southleft corner (xy distance) IF ( corner_sl(j,i) > 0 ) THEN DO k = corner_sl(j,i), nzb_si l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & 0.5 * SQRT( dx**2 + dy**2 ) ) ENDDO ! !-- Above southleft corner (xyz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j-1,i-1) = MIN( l_wall(k,j-1,i-1), & SQRT( 0.25 * (dx**2 + dy**2) + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF ! !-- Southright corner (xy distance) IF ( corner_sr(j,i) > 0 ) THEN DO k = corner_sr(j,i), nzb_si l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & 0.5 * SQRT( dx**2 + dy**2 ) ) ENDDO ! !-- Above southright corner (xyz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j-1,i+1) = MIN( l_wall(k,j-1,i+1), & SQRT( 0.25 * (dx**2 + dy**2) + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF ENDIF IF ( wall_l(j,i) > 0 ) THEN ! !-- Left wall (x distance) DO k = wall_l(j,i), nzb_si l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), 0.5 * dx ) ENDDO ! !-- Above left wall (xz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j,i-1) = MIN( l_wall(k,j,i-1), & SQRT( 0.25 * dx**2 + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF IF ( wall_r(j,i) > 0 ) THEN ! !-- Right wall (x distance) DO k = wall_r(j,i), nzb_si l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), 0.5 * dx ) ENDDO ! !-- Above right wall (xz distance) DO k = nzb_si + 1, nzb_si + vi l_wall(k,j,i+1) = MIN( l_wall(k,j,i+1), & SQRT( 0.25 * dx**2 + & ( zu(k) - zw(nzb_si) )**2 ) ) ENDDO ENDIF ENDDO ENDDO ENDIF ! !-- Multiplication with wall_adjustment_factor l_wall = wall_adjustment_factor * l_wall ! !-- Set lateral boundary conditions for l_wall CALL exchange_horiz( l_wall, nbgp ) DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, & nzb_tmp, vertical_influence, wall_l, wall_n, wall_r, wall_s ) #endif END SUBROUTINE init_grid