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