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