SUBROUTINE init_grid !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! storage of topography height arrays zu_s_inner and zw_s_inner, ! 2nd+3rd argument removed from exchange horiz ! ! Former revisions: ! ----------------- ! $Id: init_grid.f90 75 2007-03-22 09:54:05Z raasch $ ! ! 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, i, i_center, j, j_center, k, & 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 REAL :: dx_l, dy_l, dz_stretched REAL, DIMENSION(0:ny,0:nx) :: topo_height REAL, DIMENSION(:,:,:), ALLOCATABLE :: distance ! !-- 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(0:nzt+1), zw(0:nzt+1) ) ! !-- Compute height of u-levels from constant grid length and dz stretch factors IF ( dz == -1.0 ) THEN IF ( myid == 0 ) PRINT*,'+++ init_grid: missing dz' CALL local_stop ELSEIF ( dz <= 0.0 ) THEN IF ( myid == 0 ) PRINT*,'+++ init_grid: dz=',dz,' <= 0.0' CALL local_stop ENDIF ! !-- Since the w-level lies on the surface, the first u-level (staggered!) lies !-- below the surface (used for "mirror" boundary condition). !-- The first u-level above the surface corresponds to the top of the !-- Prandtl-layer. zu(0) = - dz * 0.5 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 u-levels. They are always staggered half-way between the !-- corresponding w-levels. 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) ) ! !-- 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 ! !-- 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 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 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(-1:ny+1,-1:nx+1), nzb_tmp(-1:ny+1,-1:nx+1), & 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(nys-1:nyn+1,nxl-1:nxr+1), fwxp(nys-1:nyn+1,nxl-1:nxr+1), & fwym(nys-1:nyn+1,nxl-1:nxr+1), fwyp(nys-1:nyn+1,nxl-1:nxr+1), & fxm(nys-1:nyn+1,nxl-1:nxr+1), fxp(nys-1:nyn+1,nxl-1:nxr+1), & fym(nys-1:nyn+1,nxl-1:nxr+1), fyp(nys-1:nyn+1,nxl-1:nxr+1), & nzb_s_inner(nys-1:nyn+1,nxl-1:nxr+1), & nzb_s_outer(nys-1:nyn+1,nxl-1:nxr+1), & nzb_u_inner(nys-1:nyn+1,nxl-1:nxr+1), & nzb_u_outer(nys-1:nyn+1,nxl-1:nxr+1), & nzb_v_inner(nys-1:nyn+1,nxl-1:nxr+1), & nzb_v_outer(nys-1:nyn+1,nxl-1:nxr+1), & nzb_w_inner(nys-1:nyn+1,nxl-1:nxr+1), & nzb_w_outer(nys-1:nyn+1,nxl-1:nxr+1), & nzb_diff_s_inner(nys-1:nyn+1,nxl-1:nxr+1), & nzb_diff_s_outer(nys-1:nyn+1,nxl-1:nxr+1), & nzb_diff_u(nys-1:nyn+1,nxl-1:nxr+1), & nzb_diff_v(nys-1:nyn+1,nxl-1:nxr+1), & nzb_2d(nys-1:nyn+1,nxl-1:nxr+1), & wall_e_x(nys-1:nyn+1,nxl-1:nxr+1), & wall_e_y(nys-1:nyn+1,nxl-1:nxr+1), & wall_u(nys-1:nyn+1,nxl-1:nxr+1), & wall_v(nys-1:nyn+1,nxl-1:nxr+1), & wall_w_x(nys-1:nyn+1,nxl-1:nxr+1), & wall_w_y(nys-1:nyn+1,nxl-1:nxr+1) ) ALLOCATE( l_wall(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) 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 IF ( myid == 0 ) THEN PRINT*, '+++ WARNING: grid anisotropy exceeds '// & 'threshold given by only local' PRINT*, ' horizontal reduction of near_wall '// & 'mixing length l_wall' PRINT*, ' starting from height level k = ', k, '.' ENDIF EXIT ENDIF ENDDO vertical_influence(0) = vertical_influence(1) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 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' ) ! !-- No actions necessary 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 IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: inconsistent building parameters:' PRINT*, ' bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & 'byn=', byn, 'nx=', nx, 'ny=', ny ENDIF CALL local_stop ENDIF ! !-- Set the individual index arrays for all velocity components and !-- scalars, taking into account the staggered grid. The horizontal !-- wind component normal to a wall defines the position of the wall, and !-- in the respective direction the building is as long as specified in !-- building_length_?, but in the other horizontal direction (for w and s !-- in both horizontal directions) the building appears shortened by one !-- grid length due to the staggered grid. nzb_local = 0 nzb_local(bys:byn-1,bxl:bxr-1) = bh CASE ( 'read_from_file' ) ! !-- Arbitrary irregular topography data in PALM format (exactly matching !-- the grid size and total domain size) OPEN( 90, FILE='TOPOGRAPHY_DATA', 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 ! !-- 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 nzb_local(-1,0:nx) = nzb_local(ny,0:nx) nzb_local(ny+1,0:nx) = nzb_local(0,0:nx) nzb_local(:,-1) = nzb_local(:,nx) nzb_local(:,nx+1) = nzb_local(:,0) GOTO 12 10 IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: file TOPOGRAPHY_DATA does not exist' ENDIF CALL local_stop 11 IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: errors in file TOPOGRAPHY_DATA' ENDIF CALL local_stop 12 CLOSE( 90 ) CASE DEFAULT ! !-- The DEFAULT case is reached either if the parameter topography !-- contains a wrong character string or if the user has coded a special !-- case in the user interface. There, the subroutine user_init_grid !-- checks which of these two conditions applies. CALL user_init_grid( nzb_local ) END SELECT ! !-- Consistency checks and index array initialization are only required for !-- non-flat topography, also the initialization of topography heigth 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 IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: nzb_local values are outside the', & 'model domain' PRINT*, ' MINVAL( nzb_local ) = ', MINVAL(nzb_local) PRINT*, ' MAXVAL( nzb_local ) = ', MAXVAL(nzb_local) ENDIF CALL local_stop ENDIF IF ( bc_lr == 'cyclic' ) THEN IF ( ANY( nzb_local(:,-1) /= nzb_local(:,nx) ) .OR. & ANY( nzb_local(:,0) /= nzb_local(:,nx+1) ) ) THEN IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: nzb_local does not fulfill cyclic', & ' boundary condition in x-direction' ENDIF CALL local_stop 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 IF ( myid == 0 ) THEN PRINT*, '+++ init_grid: nzb_local does not fulfill cyclic', & ' boundary condition in y-direction' ENDIF CALL local_stop ENDIF ENDIF ! !-- Initialize index arrays nzb_s_inner and nzb_w_inner nzb_s_inner = nzb_local(nys-1:nyn+1,nxl-1:nxr+1) nzb_w_inner = nzb_local(nys-1:nyn+1,nxl-1:nxr+1) ! !-- 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 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 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(nys-1:nyn+1,nxl-1:nxr+1) ! !-- 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 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-1:nyn+1,nxl-1:nxr+1) ! !-- 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 ! !-- 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 ! !-- 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 ! !-- 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 ! !-- Need to set lateral boundary conditions for l_wall CALL exchange_horiz( l_wall ) DEALLOCATE( corner_nl, corner_nr, corner_sl, corner_sr, nzb_local, & nzb_tmp, vertical_influence, wall_l, wall_n, wall_r, wall_s ) END SUBROUTINE init_grid