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