[1682] | 1 | !> @file init_grid.f90 |
---|
[4648] | 2 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[4648] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General |
---|
| 6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
| 7 | ! (at your option) any later version. |
---|
[1036] | 8 | ! |
---|
[4648] | 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
| 10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 11 | ! Public License for more details. |
---|
[1036] | 12 | ! |
---|
[4648] | 13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
| 14 | ! <http://www.gnu.org/licenses/>. |
---|
[1036] | 15 | ! |
---|
[4360] | 16 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[4648] | 17 | !--------------------------------------------------------------------------------------------------! |
---|
[1036] | 18 | ! |
---|
[254] | 19 | ! Current revisions: |
---|
[1] | 20 | ! ----------------- |
---|
[4601] | 21 | ! |
---|
| 22 | ! |
---|
[2233] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: init_grid.f90 4653 2020-08-27 08:54:43Z pavelkrc $ |
---|
[4648] | 26 | ! file re-formatted to follow the PALM coding standard |
---|
| 27 | ! |
---|
| 28 | ! 4630 2020-07-30 14:54:34Z suehring |
---|
[4630] | 29 | ! In case of ASCII topography input flag grid points as terrain and building. |
---|
| 30 | ! |
---|
| 31 | ! 4601 2020-07-14 12:06:09Z suehring |
---|
[4601] | 32 | ! Minor formatting adjustments |
---|
[4648] | 33 | ! |
---|
[4601] | 34 | ! 4564 2020-06-12 14:03:36Z raasch |
---|
[4564] | 35 | ! Vertical nesting method of Huq et al. (2019) removed |
---|
[4648] | 36 | ! |
---|
[4564] | 37 | ! 4543 2020-05-20 14:12:22Z gronemeier |
---|
[4543] | 38 | ! Remove non-required check for canyon height |
---|
[4648] | 39 | ! |
---|
[4543] | 40 | ! 4507 2020-04-22 18:21:45Z gronemeier |
---|
[4507] | 41 | ! update origin_z with shifting height of orography (oro_min) |
---|
[4648] | 42 | ! |
---|
[4507] | 43 | ! 4457 2020-03-11 14:20:43Z raasch |
---|
[4457] | 44 | ! use statement for exchange horiz added, |
---|
| 45 | ! bugfix for call of exchange horiz 2d |
---|
[4648] | 46 | ! |
---|
[4457] | 47 | ! 4444 2020-03-05 15:59:50Z raasch |
---|
[4444] | 48 | ! bugfix: cpp-directives for serial mode added |
---|
[4648] | 49 | ! |
---|
[4444] | 50 | ! 4414 2020-02-19 20:16:04Z suehring |
---|
[4414] | 51 | ! - Remove deprecated topography arrays nzb_s_inner, nzb_u_inner, etc. |
---|
[4648] | 52 | ! - Move initialization of boundary conditions and multigrid into an extra module interface. |
---|
| 53 | ! |
---|
[4414] | 54 | ! 4386 2020-01-27 15:07:30Z Giersch |
---|
[4648] | 55 | ! Allocation statements, comments, naming of variables revised and _wp added to real type values |
---|
| 56 | ! |
---|
[4386] | 57 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4356] | 58 | ! Revise error messages for generic tunnel setup. |
---|
[4648] | 59 | ! |
---|
[4356] | 60 | ! 4346 2019-12-18 11:55:56Z motisi |
---|
[4648] | 61 | ! Introduction of wall_flags_total_0, which currently sets bits based on static topography |
---|
| 62 | ! information used in wall_flags_static_0 |
---|
| 63 | ! |
---|
[4346] | 64 | ! 4340 2019-12-16 08:17:03Z Giersch |
---|
[4340] | 65 | ! Topography closed channel flow with symmetric boundaries implemented |
---|
[4648] | 66 | ! |
---|
[4340] | 67 | ! 4329 2019-12-10 15:46:36Z motisi |
---|
[4329] | 68 | ! Renamed wall_flags_0 to wall_flags_static_0 |
---|
[4648] | 69 | ! |
---|
[4329] | 70 | ! 4328 2019-12-09 18:53:04Z suehring |
---|
[4328] | 71 | ! Minor change in nzb_max computation. Commentation added. |
---|
[4648] | 72 | ! |
---|
[4328] | 73 | ! 4314 2019-11-29 10:29:20Z suehring |
---|
[4648] | 74 | ! Set additional topography flag 4 to mark topography grid points emerged from the filtering process. |
---|
| 75 | ! |
---|
[4314] | 76 | ! 4294 2019-11-13 18:34:16Z suehring |
---|
[4648] | 77 | ! Bugfix, always set bit 5 and 6 of wall_flags, indicating terrain- and building surfaces in all |
---|
| 78 | ! cases, in order to enable terrain-following output also when no land- or urban-surface model is |
---|
| 79 | ! applied. |
---|
| 80 | ! |
---|
[4294] | 81 | ! 4265 2019-10-15 16:16:24Z suehring |
---|
[4648] | 82 | ! Bugfix for last commit, exchange oro_max variable only when it is allocated (not necessarily the |
---|
| 83 | ! case when topography is input from ASCII file). |
---|
| 84 | ! |
---|
[4265] | 85 | ! 4245 2019-09-30 08:40:37Z pavelkrc |
---|
[4245] | 86 | ! Store oro_max (building z-offset) in 2D for building surfaces |
---|
[4648] | 87 | ! |
---|
[4245] | 88 | ! 4189 2019-08-26 16:19:38Z suehring |
---|
[4189] | 89 | ! - Add check for proper setting of namelist parameter topography |
---|
| 90 | ! - Set flag to indicate land surfaces in case no topography is provided |
---|
[4648] | 91 | ! |
---|
[4189] | 92 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
[4182] | 93 | ! Corrected "Former revisions" section |
---|
[4648] | 94 | ! |
---|
[4182] | 95 | ! 4168 2019-08-16 13:50:17Z suehring |
---|
[4648] | 96 | ! Pre-calculate topography top index and store it on an array (replaces former functions |
---|
| 97 | ! get_topography_top_index) |
---|
| 98 | ! |
---|
[4168] | 99 | ! 4159 2019-08-15 13:31:35Z suehring |
---|
[4648] | 100 | ! Revision of topography processing. This was not consistent between 2D and 3D buildings. |
---|
| 101 | ! |
---|
[4159] | 102 | ! 4144 2019-08-06 09:11:47Z raasch |
---|
[4144] | 103 | ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc. |
---|
[4648] | 104 | ! |
---|
[4144] | 105 | ! 4115 2019-07-24 12:50:49Z suehring |
---|
[4648] | 106 | ! Bugfix in setting near-surface flag 24, inidicating wall-bounded grid points |
---|
| 107 | ! |
---|
[4115] | 108 | ! 4110 2019-07-22 17:05:21Z suehring |
---|
[4110] | 109 | ! - Separate initialization of advection flags for momentum and scalars. |
---|
| 110 | ! - Change subroutine interface for ws_init_flags_scalar to pass boundary flags |
---|
[4648] | 111 | ! |
---|
[4110] | 112 | ! 4109 2019-07-22 17:00:34Z suehring |
---|
[3927] | 113 | ! Fix bad commit |
---|
[4648] | 114 | ! |
---|
[3927] | 115 | ! 3926 2019-04-23 12:56:42Z suehring |
---|
[4648] | 116 | ! Minor bugfix in building mapping when all building IDs in the model domain are missing |
---|
| 117 | ! |
---|
[3925] | 118 | ! 3857 2019-04-03 13:00:16Z knoop |
---|
[4648] | 119 | ! In projection of non-building 3D objects onto numerical grid remove dependency on building_type |
---|
| 120 | ! |
---|
[3855] | 121 | ! 3763 2019-02-25 17:33:49Z suehring |
---|
[4648] | 122 | ! Replace work-around for ghost point exchange of 1-byte arrays with specific routine as already |
---|
| 123 | ! done in other routines |
---|
| 124 | ! |
---|
[3763] | 125 | ! 3761 2019-02-25 15:31:42Z raasch |
---|
[3761] | 126 | ! unused variables removed |
---|
[4648] | 127 | ! |
---|
[3761] | 128 | ! 3661 2019-01-08 18:22:50Z suehring |
---|
[4648] | 129 | ! Remove setting of nzb_max to nzt at non-cyclic boundary PEs, instead, order degradation of |
---|
| 130 | ! advection scheme is handeled directly in advec_ws |
---|
| 131 | ! |
---|
[3661] | 132 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3538] | 133 | ! Comment added |
---|
[2716] | 134 | ! |
---|
[4182] | 135 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
| 136 | ! Initial revision (Testversion) |
---|
| 137 | ! |
---|
| 138 | ! |
---|
[1] | 139 | ! Description: |
---|
[4648] | 140 | ! -------------------------------------------------------------------------------------------------! |
---|
[1682] | 141 | !> Creating grid depending constants |
---|
[2696] | 142 | !> @todo: Rearrange topo flag list |
---|
[4648] | 143 | !> @todo: reference 3D buildings on top of orography is not tested and may need further improvement |
---|
| 144 | !> for steep slopes |
---|
| 145 | !> @todo: Use more advanced setting of building type at filled holes |
---|
| 146 | !--------------------------------------------------------------------------------------------------! |
---|
[1682] | 147 | SUBROUTINE init_grid |
---|
[1] | 148 | |
---|
[4648] | 149 | USE arrays_3d, & |
---|
[3857] | 150 | ONLY: dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzw, x, xu, y, yv, zu, zw |
---|
[4414] | 151 | |
---|
[4648] | 152 | USE control_parameters, & |
---|
| 153 | ONLY: constant_flux_layer, dz, dz_max, dz_stretch_factor, & |
---|
| 154 | dz_stretch_factor_array, dz_stretch_level, dz_stretch_level_end, & |
---|
| 155 | dz_stretch_level_end_index, dz_stretch_level_start_index, & |
---|
| 156 | dz_stretch_level_start, ibc_uv_b, message_string, & |
---|
| 157 | number_stretch_level_end, & |
---|
| 158 | number_stretch_level_start, & |
---|
| 159 | ocean_mode, & |
---|
| 160 | psolver, & |
---|
| 161 | symmetry_flag, & |
---|
| 162 | topography, & |
---|
[4414] | 163 | use_surface_fluxes |
---|
| 164 | |
---|
[4648] | 165 | USE grid_variables, & |
---|
[2232] | 166 | ONLY: ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, zu_s_inner, zw_w_inner |
---|
[4414] | 167 | |
---|
[4648] | 168 | USE indices, & |
---|
| 169 | ONLY: nbgp, & |
---|
| 170 | nx, & |
---|
| 171 | nxl, & |
---|
| 172 | nxlg, & |
---|
| 173 | nxr, & |
---|
| 174 | nxrg, & |
---|
| 175 | ny, & |
---|
| 176 | nyn, & |
---|
| 177 | nyng, & |
---|
| 178 | nys, & |
---|
| 179 | nysg, & |
---|
| 180 | nz, & |
---|
| 181 | nzb, & |
---|
| 182 | nzb_diff, & |
---|
| 183 | nzb_max, & |
---|
| 184 | nzt, & |
---|
| 185 | topo_top_ind, & |
---|
[4414] | 186 | topo_min_level |
---|
| 187 | |
---|
[1320] | 188 | USE kinds |
---|
[2696] | 189 | |
---|
[1] | 190 | USE pegrid |
---|
| 191 | |
---|
| 192 | IMPLICIT NONE |
---|
| 193 | |
---|
[4648] | 194 | INTEGER(iwp) :: i !< index variable along x |
---|
[3182] | 195 | INTEGER(iwp) :: j !< index variable along y |
---|
| 196 | INTEGER(iwp) :: k !< index variable along z |
---|
| 197 | INTEGER(iwp) :: k_top !< topography top index on local PE |
---|
| 198 | INTEGER(iwp) :: n !< loop variable for stretching |
---|
[4648] | 199 | INTEGER(iwp) :: number_dz !< number of user-specified dz values |
---|
[3182] | 200 | INTEGER(iwp) :: nzb_local_max !< vertical grid index of maximum topography height |
---|
| 201 | INTEGER(iwp) :: nzb_local_min !< vertical grid index of minimum topography height |
---|
[1] | 202 | |
---|
[2696] | 203 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: topo !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
[2232] | 204 | |
---|
[3065] | 205 | REAL(wp) :: dz_level_end !< distance between calculated height level for u/v-grid and user-specified end level for stretching |
---|
[1886] | 206 | REAL(wp) :: dz_stretched !< stretched vertical grid spacing |
---|
[861] | 207 | |
---|
[4648] | 208 | REAL(wp), DIMENSION(:), ALLOCATABLE :: min_dz_stretch_level_end !< Array that contains all minimum heights where the stretching |
---|
| 209 | !< can end |
---|
[1] | 210 | |
---|
[4648] | 211 | |
---|
[1] | 212 | ! |
---|
[709] | 213 | !-- Calculation of horizontal array bounds including ghost layers |
---|
[667] | 214 | nxlg = nxl - nbgp |
---|
| 215 | nxrg = nxr + nbgp |
---|
| 216 | nysg = nys - nbgp |
---|
| 217 | nyng = nyn + nbgp |
---|
[709] | 218 | |
---|
[667] | 219 | ! |
---|
[1] | 220 | !-- Allocate grid arrays |
---|
[4386] | 221 | ALLOCATE( x(0:nx) ) |
---|
| 222 | ALLOCATE( xu(0:nx) ) |
---|
[4648] | 223 | |
---|
[3857] | 224 | DO i = 0, nx |
---|
| 225 | xu(i) = i * dx |
---|
| 226 | x(i) = i * dx + 0.5_wp * dx |
---|
| 227 | ENDDO |
---|
| 228 | |
---|
[4386] | 229 | ALLOCATE( y(0:ny) ) |
---|
| 230 | ALLOCATE( yv(0:ny) ) |
---|
[4648] | 231 | |
---|
[3857] | 232 | DO j = 0, ny |
---|
| 233 | yv(j) = j * dy |
---|
| 234 | y(j) = j * dy + 0.5_wp * dy |
---|
| 235 | ENDDO |
---|
| 236 | |
---|
[4386] | 237 | ALLOCATE( ddzu(1:nzt+1) ) |
---|
| 238 | ALLOCATE( ddzw(1:nzt+1) ) |
---|
| 239 | ALLOCATE( dd2zu(1:nzt) ) |
---|
| 240 | ALLOCATE( dzu(1:nzt+1) ) |
---|
| 241 | ALLOCATE( dzw(1:nzt+1) ) |
---|
| 242 | ALLOCATE( zu(nzb:nzt+1) ) |
---|
| 243 | ALLOCATE( zw(nzb:nzt+1) ) |
---|
[1] | 244 | |
---|
| 245 | ! |
---|
[4648] | 246 | !-- For constructing an appropriate grid, the vertical grid spacing dz has to be specified with a |
---|
| 247 | !-- non-negative value in the parameter file. |
---|
[3065] | 248 | IF ( dz(1) == -1.0_wp ) THEN |
---|
[254] | 249 | message_string = 'missing dz' |
---|
[4648] | 250 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
[3065] | 251 | ELSEIF ( dz(1) <= 0.0_wp ) THEN |
---|
| 252 | WRITE( message_string, * ) 'dz=',dz(1),' <= 0.0' |
---|
[254] | 253 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
[1] | 254 | ENDIF |
---|
[94] | 255 | |
---|
[1] | 256 | ! |
---|
[4648] | 257 | !-- Initialize dz_stretch_level_start with the value of dz_stretch_level if it was set by the user. |
---|
[3065] | 258 | IF ( dz_stretch_level /= -9999999.9_wp ) THEN |
---|
| 259 | dz_stretch_level_start(1) = dz_stretch_level |
---|
| 260 | ENDIF |
---|
[4648] | 261 | |
---|
[3065] | 262 | ! |
---|
[4648] | 263 | !-- Determine number of dz values and stretching levels specified by the user to allow right |
---|
| 264 | !-- controlling of the stretching mechanism and to perform error checks. The additional requirement |
---|
| 265 | !-- that dz /= dz_max for counting number of user-specified dz values is necessary. Otherwise |
---|
| 266 | !-- restarts would abort if the old stretching mechanism with dz_stretch_level is used (Attention: |
---|
| 267 | !-- The user is not allowed to specify a dz value equal to the default of dz_max = 999.0). |
---|
| 268 | number_dz = COUNT( dz /= -1.0_wp .AND. dz /= dz_max) |
---|
| 269 | number_stretch_level_start = COUNT( dz_stretch_level_start /= -9999999.9_wp ) |
---|
| 270 | number_stretch_level_end = COUNT( dz_stretch_level_end /= 9999999.9_wp ) |
---|
[3065] | 271 | |
---|
| 272 | ! |
---|
[4648] | 273 | !-- The number of specified end levels +1 has to be the same as the number |
---|
[3065] | 274 | !-- of specified dz values |
---|
| 275 | IF ( number_dz /= number_stretch_level_end + 1 ) THEN |
---|
[4648] | 276 | WRITE( message_string, * ) 'The number of values for dz = ', number_dz, & |
---|
| 277 | 'has to be the same as& ', 'the number of values for ', & |
---|
| 278 | 'dz_stretch_level_end + 1 = ', number_stretch_level_end+1 |
---|
[4601] | 279 | CALL message( 'init_grid', 'PA0156', 1, 2, 0, 6, 0 ) |
---|
[3065] | 280 | ENDIF |
---|
[4648] | 281 | |
---|
[3065] | 282 | ! |
---|
[4648] | 283 | !-- The number of specified start levels has to be the same or one less than the number of specified |
---|
| 284 | !-- dz values |
---|
| 285 | IF ( number_dz /= number_stretch_level_start + 1 .AND. & |
---|
| 286 | number_dz /= number_stretch_level_start ) THEN |
---|
| 287 | WRITE( message_string, * ) 'The number of values for dz = ', number_dz, & |
---|
| 288 | 'has to be the same as or one ', & |
---|
| 289 | 'more than& the number of values for ', & |
---|
| 290 | 'dz_stretch_level_start = ', number_stretch_level_start |
---|
[4601] | 291 | CALL message( 'init_grid', 'PA0211', 1, 2, 0, 6, 0 ) |
---|
[3065] | 292 | ENDIF |
---|
[4648] | 293 | |
---|
| 294 | !-- The number of specified start levels has to be the same or one more than the number of specified |
---|
| 295 | !-- end levels |
---|
| 296 | IF ( number_stretch_level_start /= number_stretch_level_end + 1 .AND. & |
---|
[3065] | 297 | number_stretch_level_start /= number_stretch_level_end ) THEN |
---|
[4648] | 298 | WRITE( message_string, * ) 'The number of values for ', & |
---|
| 299 | 'dz_stretch_level_start = ', dz_stretch_level_start, & |
---|
| 300 | 'has to be the ', 'same or one more than& the number of ', & |
---|
| 301 | 'values for dz_stretch_level_end = ', number_stretch_level_end |
---|
[4601] | 302 | CALL message( 'init_grid', 'PA0216', 1, 2, 0, 6, 0 ) |
---|
[3065] | 303 | ENDIF |
---|
| 304 | |
---|
| 305 | ! |
---|
| 306 | !-- Initialize dz for the free atmosphere with the value of dz_max |
---|
[4648] | 307 | IF ( dz(number_stretch_level_start+1) == -1.0_wp .AND. number_stretch_level_start /= 0 ) THEN |
---|
[3065] | 308 | dz(number_stretch_level_start+1) = dz_max |
---|
| 309 | ENDIF |
---|
[4648] | 310 | |
---|
[3065] | 311 | ! |
---|
[4648] | 312 | !-- Initialize the stretching factor if (infinitely) stretching in the free atmosphere is desired |
---|
| 313 | !-- (dz_stretch_level_end was not specified for the free atmosphere) |
---|
| 314 | IF ( number_stretch_level_start == number_stretch_level_end + 1 ) THEN |
---|
| 315 | dz_stretch_factor_array(number_stretch_level_start) = dz_stretch_factor |
---|
[3065] | 316 | ENDIF |
---|
[4648] | 317 | |
---|
[3065] | 318 | ! |
---|
| 319 | !-- Allocation of arrays for stretching |
---|
| 320 | ALLOCATE( min_dz_stretch_level_end(number_stretch_level_start) ) |
---|
[3066] | 321 | |
---|
[3065] | 322 | ! |
---|
[4386] | 323 | !-- Define the vertical grid levels. Start with atmosphere branch |
---|
[3294] | 324 | IF ( .NOT. ocean_mode ) THEN |
---|
[4648] | 325 | |
---|
[94] | 326 | ! |
---|
[4648] | 327 | !-- The stretching region has to be large enough to allow for a smooth transition between two |
---|
| 328 | !-- different grid spacings. The number 4 is an empirical value. |
---|
[3065] | 329 | DO n = 1, number_stretch_level_start |
---|
[4648] | 330 | min_dz_stretch_level_end(n) = dz_stretch_level_start(n) + 4 * MAX( dz(n),dz(n+1) ) |
---|
[3065] | 331 | ENDDO |
---|
| 332 | |
---|
[4648] | 333 | IF ( ANY( min_dz_stretch_level_end(1:number_stretch_level_start) > & |
---|
| 334 | dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN |
---|
| 335 | message_string= 'Each dz_stretch_level_end has to be larger ' // & |
---|
| 336 | 'than its corresponding value for &' // & |
---|
| 337 | 'dz_stretch_level_start + 4*MAX(dz(n),dz(n+1)) '// & |
---|
[4601] | 338 | 'to allow for smooth grid stretching' |
---|
| 339 | CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 ) |
---|
[3065] | 340 | ENDIF |
---|
[4648] | 341 | |
---|
[3065] | 342 | ! |
---|
[4648] | 343 | !-- Stretching must not be applied within the surface layer (first two grid points). For the |
---|
| 344 | !-- default case dz_stretch_level_start is negative. Therefore the absolut value is checked here. |
---|
[4386] | 345 | IF ( ANY( ABS( dz_stretch_level_start ) <= dz(1) * 1.5_wp ) ) THEN |
---|
[4648] | 346 | WRITE( message_string, * ) 'Each dz_stretch_level_start has to be ', & |
---|
| 347 | 'larger than ', dz(1) * 1.5 |
---|
[4601] | 348 | CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 ) |
---|
[3065] | 349 | ENDIF |
---|
| 350 | |
---|
| 351 | ! |
---|
[4648] | 352 | !-- The stretching has to start and end on a grid level. Therefore user-specified values are |
---|
| 353 | !-- mapped to the next lowest level. The calculation of the first level is realized differently |
---|
| 354 | !-- just because of historical reasons (the advanced/new stretching mechanism was realized in a |
---|
| 355 | !-- way that results don't change if the old parameters dz_stretch_level, dz_stretch_factor and |
---|
| 356 | !-- dz_max are used). |
---|
| 357 | IF ( number_stretch_level_start /= 0 ) THEN |
---|
| 358 | dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) - dz(1)/2.0) / dz(1) ) & |
---|
[3065] | 359 | * dz(1) + dz(1)/2.0 |
---|
| 360 | ENDIF |
---|
[4648] | 361 | |
---|
[3065] | 362 | IF ( number_stretch_level_start > 1 ) THEN |
---|
| 363 | DO n = 2, number_stretch_level_start |
---|
[4648] | 364 | dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / dz(n) ) * dz(n) |
---|
[3065] | 365 | ENDDO |
---|
| 366 | ENDIF |
---|
[4648] | 367 | |
---|
[3065] | 368 | IF ( number_stretch_level_end /= 0 ) THEN |
---|
| 369 | DO n = 1, number_stretch_level_end |
---|
[4648] | 370 | dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / dz(n+1) ) * dz(n+1) |
---|
[3065] | 371 | ENDDO |
---|
| 372 | ENDIF |
---|
[4386] | 373 | |
---|
[3065] | 374 | ! |
---|
| 375 | !-- Determine stretching factor if necessary |
---|
[4648] | 376 | IF ( number_stretch_level_end >= 1 ) THEN |
---|
[3065] | 377 | CALL calculate_stretching_factor( number_stretch_level_end ) |
---|
| 378 | ENDIF |
---|
| 379 | |
---|
| 380 | ! |
---|
[94] | 381 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
[4648] | 382 | !-- First compute the u- and v-levels. In case of dirichlet bc for u and v the first u/v- and |
---|
| 383 | !-- w-level (k=0) are defined at same height (z=0). |
---|
| 384 | !-- The second u-level (k=1) corresponds to the top of the surface layer. In case of symmetric |
---|
| 385 | !-- boundaries (closed channel flow), the first grid point is always at z=0. |
---|
| 386 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 .OR. topography == 'closed_channel' ) THEN |
---|
[1353] | 387 | zu(0) = 0.0_wp |
---|
[667] | 388 | ELSE |
---|
[3065] | 389 | zu(0) = - dz(1) * 0.5_wp |
---|
[667] | 390 | ENDIF |
---|
[4648] | 391 | |
---|
[3065] | 392 | zu(1) = dz(1) * 0.5_wp |
---|
[4648] | 393 | |
---|
[3065] | 394 | ! |
---|
[4648] | 395 | !-- Determine u and v height levels considering the possibility of grid stretching in several |
---|
| 396 | !-- heights. |
---|
[3065] | 397 | n = 1 |
---|
| 398 | dz_stretch_level_start_index = nzt+1 |
---|
| 399 | dz_stretch_level_end_index = nzt+1 |
---|
| 400 | dz_stretched = dz(1) |
---|
[1] | 401 | |
---|
[4648] | 402 | !-- The default value of dz_stretch_level_start is negative, thus the first condition is true |
---|
| 403 | !-- even if no stretching shall be applied. Hence, the second condition is also necessary. |
---|
[4340] | 404 | DO k = 2, nzt+1-symmetry_flag |
---|
[4648] | 405 | IF ( dz_stretch_level_start(n) <= zu(k-1) .AND. & |
---|
| 406 | dz_stretch_level_start(n) /= -9999999.9_wp ) THEN |
---|
[3065] | 407 | dz_stretched = dz_stretched * dz_stretch_factor_array(n) |
---|
[4648] | 408 | |
---|
| 409 | IF ( dz(n) > dz(n+1) ) THEN |
---|
[3065] | 410 | dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz |
---|
| 411 | ELSE |
---|
| 412 | dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz |
---|
| 413 | ENDIF |
---|
[4648] | 414 | |
---|
| 415 | IF ( dz_stretch_level_start_index(n) == nzt+1 ) dz_stretch_level_start_index(n) = k-1 |
---|
| 416 | |
---|
[94] | 417 | ENDIF |
---|
[4648] | 418 | |
---|
[94] | 419 | zu(k) = zu(k-1) + dz_stretched |
---|
[4648] | 420 | |
---|
[3065] | 421 | ! |
---|
[4648] | 422 | !-- Make sure that the stretching ends exactly at dz_stretch_level_end |
---|
| 423 | dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) |
---|
| 424 | |
---|
| 425 | IF ( dz_level_end < dz(n+1)/3.0 ) THEN |
---|
[3065] | 426 | zu(k) = dz_stretch_level_end(n) |
---|
| 427 | dz_stretched = dz(n+1) |
---|
| 428 | dz_stretch_level_end_index(n) = k |
---|
[4648] | 429 | n = n + 1 |
---|
[3065] | 430 | ENDIF |
---|
[94] | 431 | ENDDO |
---|
[4648] | 432 | |
---|
[4340] | 433 | ! |
---|
[4648] | 434 | !-- If a closed channel flow is simulated, make sure that grid structure is the same for both |
---|
| 435 | !-- bottom and top boundary. (Hint: Using a different dz at the bottom and at the top makes no |
---|
| 436 | !-- sense due to symmetric boundaries where dz should be equal. Therefore, different dz at the |
---|
| 437 | !-- bottom and top causes an abort (see check_parameters).) |
---|
| 438 | IF ( topography == 'closed_channel' ) THEN |
---|
[4340] | 439 | zu(nzt+1) = zu(nzt) + dz(1) * 0.5_wp |
---|
| 440 | ENDIF |
---|
[1] | 441 | |
---|
| 442 | ! |
---|
[4648] | 443 | !-- Compute the w-levels. They are always staggered half-way between the corresponding u-levels. |
---|
| 444 | !-- In case of dirichlet bc for u and v at the ground the first u- and w-level (k=0) are defined |
---|
| 445 | !-- at same height (z=0). |
---|
| 446 | !-- Per default, the top w-level is extrapolated linearly. In case of a closed channel flow, |
---|
| 447 | !-- zu(nzt+1) and zw(nzt) must be set explicitely. |
---|
| 448 | !-- (Hint: Using a different dz at the bottom and at the top makes no sense due to symmetric |
---|
| 449 | !-- boundaries where dz should be equal. Therefore, different dz at the bottom and top causes an |
---|
| 450 | !-- abort (see check_parameters).) |
---|
[1353] | 451 | zw(0) = 0.0_wp |
---|
[4340] | 452 | DO k = 1, nzt-symmetry_flag |
---|
[1353] | 453 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
[94] | 454 | ENDDO |
---|
[4648] | 455 | IF ( topography == 'closed_channel' ) THEN |
---|
[4340] | 456 | zw(nzt) = zw(nzt-1) + dz(1) |
---|
| 457 | zw(nzt+1) = zw(nzt) + dz(1) |
---|
| 458 | ELSE |
---|
| 459 | zw(nzt+1) = zw(nzt) + 2.0_wp * ( zu(nzt+1) - zw(nzt) ) |
---|
| 460 | ENDIF |
---|
[1] | 461 | |
---|
[4386] | 462 | ELSE !ocean branch |
---|
[3065] | 463 | |
---|
[1] | 464 | ! |
---|
[4648] | 465 | !-- The stretching region has to be large enough to allow for a smooth transition between two |
---|
| 466 | !-- different grid spacings. The number 4 is an empirical value |
---|
[3065] | 467 | DO n = 1, number_stretch_level_start |
---|
[4648] | 468 | min_dz_stretch_level_end(n) = dz_stretch_level_start(n) - 4 * MAX( dz(n),dz(n+1) ) |
---|
[3065] | 469 | ENDDO |
---|
[4648] | 470 | |
---|
| 471 | IF ( ANY( min_dz_stretch_level_end (1:number_stretch_level_start) < & |
---|
| 472 | dz_stretch_level_end(1:number_stretch_level_start) ) ) THEN |
---|
| 473 | message_string= 'Each dz_stretch_level_end has to be less ' // & |
---|
| 474 | 'than its corresponding value for &' // & |
---|
| 475 | 'dz_stretch_level_start - 4*MAX(dz(n),dz(n+1)) '// & |
---|
[3065] | 476 | 'to allow for smooth grid stretching' |
---|
| 477 | CALL message( 'init_grid', 'PA0224', 1, 2, 0, 6, 0 ) |
---|
| 478 | ENDIF |
---|
[4648] | 479 | |
---|
[3065] | 480 | ! |
---|
[4648] | 481 | !-- Stretching must not be applied close to the surface (last two grid points). For the default |
---|
| 482 | !-- case dz_stretch_level_start is negative. |
---|
| 483 | IF ( ANY( dz_stretch_level_start >= - dz(1) * 1.5_wp ) ) THEN |
---|
| 484 | WRITE( message_string, * ) 'Each dz_stretch_level_start has to be ', & |
---|
| 485 | 'less than ', -dz(1) * 1.5 |
---|
[3065] | 486 | CALL message( 'init_grid', 'PA0226', 1, 2, 0, 6, 0 ) |
---|
| 487 | ENDIF |
---|
| 488 | |
---|
| 489 | ! |
---|
[4648] | 490 | !-- The stretching has to start and end on a grid level. Therefore user-specified values are |
---|
| 491 | !-- mapped to the next highest level. The calculation of the first level is realized differently |
---|
| 492 | !-- just because of historical reasons (the advanced/new stretching mechanism was realized in a |
---|
| 493 | !-- way that results don't change if the old parameters dz_stretch_level, dz_stretch_factor and |
---|
| 494 | !-- dz_max are used) |
---|
| 495 | IF ( number_stretch_level_start /= 0 ) THEN |
---|
| 496 | dz_stretch_level_start(1) = INT( (dz_stretch_level_start(1) + dz(1)/2.0) / dz(1) ) & |
---|
[3065] | 497 | * dz(1) - dz(1)/2.0 |
---|
| 498 | ENDIF |
---|
[4648] | 499 | |
---|
| 500 | IF ( number_stretch_level_start > 1 ) THEN |
---|
[3065] | 501 | DO n = 2, number_stretch_level_start |
---|
[4648] | 502 | dz_stretch_level_start(n) = INT( dz_stretch_level_start(n) / dz(n) ) * dz(n) |
---|
[3065] | 503 | ENDDO |
---|
| 504 | ENDIF |
---|
[4648] | 505 | |
---|
| 506 | IF ( number_stretch_level_end /= 0 ) THEN |
---|
[3065] | 507 | DO n = 1, number_stretch_level_end |
---|
[4648] | 508 | dz_stretch_level_end(n) = INT( dz_stretch_level_end(n) / dz(n+1) ) * dz(n+1) |
---|
[3065] | 509 | ENDDO |
---|
| 510 | ENDIF |
---|
[4648] | 511 | |
---|
[3065] | 512 | ! |
---|
| 513 | !-- Determine stretching factor if necessary |
---|
[4648] | 514 | IF ( number_stretch_level_end >= 1 ) THEN |
---|
[3065] | 515 | CALL calculate_stretching_factor( number_stretch_level_end ) |
---|
| 516 | ENDIF |
---|
| 517 | |
---|
| 518 | ! |
---|
[843] | 519 | !-- Grid for ocean with free water surface is at k=nzt (w-grid). |
---|
[4648] | 520 | !-- In case of neumann bc at the ground the first first u-level (k=0) lies below the first |
---|
| 521 | !-- w-level (k=0). In case of dirichlet bc the first u- and w-level are defined at same height, |
---|
| 522 | !-- but staggered from the second level. |
---|
[4386] | 523 | !-- The second u-level (k=1) corresponds to the top of the surface layer. |
---|
[3065] | 524 | !-- z values are negative starting from z=0 (surface) |
---|
| 525 | zu(nzt+1) = dz(1) * 0.5_wp |
---|
| 526 | zu(nzt) = - dz(1) * 0.5_wp |
---|
[94] | 527 | |
---|
[3065] | 528 | ! |
---|
[4648] | 529 | !-- Determine u and v height levels considering the possibility of grid stretching in several |
---|
| 530 | !-- heights. |
---|
[3065] | 531 | n = 1 |
---|
| 532 | dz_stretch_level_start_index = 0 |
---|
| 533 | dz_stretch_level_end_index = 0 |
---|
| 534 | dz_stretched = dz(1) |
---|
| 535 | |
---|
[94] | 536 | DO k = nzt-1, 0, -1 |
---|
[4648] | 537 | |
---|
| 538 | IF ( dz_stretch_level_start(n) >= zu(k+1) ) THEN |
---|
[3065] | 539 | dz_stretched = dz_stretched * dz_stretch_factor_array(n) |
---|
| 540 | |
---|
[4648] | 541 | IF ( dz(n) > dz(n+1) ) THEN |
---|
[3065] | 542 | dz_stretched = MAX( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (higher) dz |
---|
| 543 | ELSE |
---|
| 544 | dz_stretched = MIN( dz_stretched, dz(n+1) ) !Restrict dz_stretched to the user-specified (lower) dz |
---|
| 545 | ENDIF |
---|
[4648] | 546 | |
---|
| 547 | IF ( dz_stretch_level_start_index(n) == 0 ) dz_stretch_level_start_index(n) = k+1 |
---|
| 548 | |
---|
[3065] | 549 | ENDIF |
---|
[4648] | 550 | |
---|
[3065] | 551 | zu(k) = zu(k+1) - dz_stretched |
---|
[4648] | 552 | |
---|
[1418] | 553 | ! |
---|
[4648] | 554 | !-- Make sure that the stretching ends exactly at dz_stretch_level_end |
---|
| 555 | dz_level_end = ABS( zu(k) - dz_stretch_level_end(n) ) |
---|
| 556 | |
---|
| 557 | IF ( dz_level_end < dz(n+1)/3.0 ) THEN |
---|
[3065] | 558 | zu(k) = dz_stretch_level_end(n) |
---|
| 559 | dz_stretched = dz(n+1) |
---|
| 560 | dz_stretch_level_end_index(n) = k |
---|
[4648] | 561 | n = n + 1 |
---|
[94] | 562 | ENDIF |
---|
| 563 | ENDDO |
---|
[4648] | 564 | |
---|
[94] | 565 | ! |
---|
[4648] | 566 | !-- Compute the w-levels. They are always staggered half-way between the corresponding u-levels, |
---|
| 567 | !-- except in case of dirichlet bc for u and v at the ground. In this case the first u- and |
---|
| 568 | !-- w-level are defined at same height. The top w-level (nzt+1) is not used but set for |
---|
[843] | 569 | !-- consistency, since w and all scalar variables are defined up tp nzt+1. |
---|
[3065] | 570 | zw(nzt+1) = dz(1) |
---|
[1353] | 571 | zw(nzt) = 0.0_wp |
---|
[94] | 572 | DO k = 0, nzt |
---|
[1353] | 573 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
[94] | 574 | ENDDO |
---|
| 575 | |
---|
[843] | 576 | ! |
---|
[4648] | 577 | !-- In case of dirichlet bc for u and v the first u- and w-level are defined at same height. |
---|
[843] | 578 | IF ( ibc_uv_b == 0 ) THEN |
---|
| 579 | zu(0) = zw(0) |
---|
| 580 | ENDIF |
---|
| 581 | |
---|
[4386] | 582 | ENDIF !End of defining the vertical grid levels |
---|
[94] | 583 | |
---|
| 584 | ! |
---|
[1] | 585 | !-- Compute grid lengths. |
---|
| 586 | DO k = 1, nzt+1 |
---|
| 587 | dzu(k) = zu(k) - zu(k-1) |
---|
[1353] | 588 | ddzu(k) = 1.0_wp / dzu(k) |
---|
[1] | 589 | dzw(k) = zw(k) - zw(k-1) |
---|
[1353] | 590 | ddzw(k) = 1.0_wp / dzw(k) |
---|
[1] | 591 | ENDDO |
---|
| 592 | |
---|
| 593 | DO k = 1, nzt |
---|
[1353] | 594 | dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) ) |
---|
[1] | 595 | ENDDO |
---|
[4648] | 596 | |
---|
| 597 | ! |
---|
| 598 | !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid everywhere. For the |
---|
| 599 | !-- actual grid, the grid spacing at the lowest level is only dz/2, but should be dz. Therefore, an |
---|
| 600 | !-- additional array containing with appropriate grid information is created for these solvers. |
---|
[1575] | 601 | IF ( psolver(1:9) /= 'multigrid' ) THEN |
---|
[667] | 602 | ALLOCATE( ddzu_pres(1:nzt+1) ) |
---|
| 603 | ddzu_pres = ddzu |
---|
[864] | 604 | ddzu_pres(1) = ddzu_pres(2) ! change for lowest level |
---|
[1] | 605 | ENDIF |
---|
| 606 | |
---|
| 607 | ! |
---|
| 608 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
[1353] | 609 | ddx = 1.0_wp / dx |
---|
| 610 | ddy = 1.0_wp / dy |
---|
[1] | 611 | dx2 = dx * dx |
---|
| 612 | dy2 = dy * dy |
---|
[1353] | 613 | ddx2 = 1.0_wp / dx2 |
---|
| 614 | ddy2 = 1.0_wp / dy2 |
---|
[1] | 615 | |
---|
| 616 | ! |
---|
[2696] | 617 | !-- Allocate 3D array to set topography |
---|
| 618 | ALLOCATE( topo(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 619 | topo = 0 |
---|
| 620 | ! |
---|
[4648] | 621 | !-- Initialize topography by generic topography or read topography from file. |
---|
[2696] | 622 | CALL init_topo( topo ) |
---|
| 623 | ! |
---|
[4648] | 624 | !-- Set flags to mask topography on the grid. |
---|
[4414] | 625 | CALL set_topo_flags( topo ) |
---|
[2696] | 626 | |
---|
| 627 | ! |
---|
[4648] | 628 | !-- Determine the maximum level of topography. It is used for steering the degradation of order of |
---|
| 629 | !-- the applied advection scheme, as well in the lpm. |
---|
[2696] | 630 | k_top = 0 |
---|
| 631 | DO i = nxl, nxr |
---|
| 632 | DO j = nys, nyn |
---|
| 633 | DO k = nzb, nzt + 1 |
---|
[4109] | 634 | k_top = MAX( k_top, MERGE( k, 0, .NOT. BTEST( topo(k,j,i), 0 ) ) ) |
---|
[2696] | 635 | ENDDO |
---|
| 636 | ENDDO |
---|
[1] | 637 | ENDDO |
---|
[2696] | 638 | #if defined( __parallel ) |
---|
[4648] | 639 | CALL MPI_ALLREDUCE( k_top, nzb_max, 1, MPI_INTEGER, MPI_MAX, comm2d, ierr ) |
---|
[2696] | 640 | #else |
---|
[4328] | 641 | nzb_max = k_top |
---|
[2696] | 642 | #endif |
---|
[1] | 643 | ! |
---|
[4328] | 644 | !-- Increment nzb_max by 1 in order to allow for proper diverengence correction. |
---|
| 645 | !-- Further, in case topography extents up to the model top, limit to nzt. |
---|
[4648] | 646 | nzb_max = MIN( nzb_max+1, nzt ) |
---|
[4328] | 647 | ! |
---|
[4648] | 648 | !-- Determine minimum index of topography. Usually, this will be nzb. In case there is elevated |
---|
| 649 | !-- topography, however, the lowest topography will be higher. |
---|
| 650 | !-- This index is e.g. used to calculate mean first-grid point atmosphere temperature, surface |
---|
| 651 | !-- pressure and density, etc. . |
---|
[2968] | 652 | topo_min_level = 0 |
---|
| 653 | #if defined( __parallel ) |
---|
[4648] | 654 | CALL MPI_ALLREDUCE( MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), topo_min_level, 1, MPI_INTEGER, & |
---|
| 655 | MPI_MIN, comm2d, ierr ) |
---|
[2968] | 656 | #else |
---|
[4168] | 657 | topo_min_level = MINVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ) |
---|
[2968] | 658 | #endif |
---|
[3182] | 659 | |
---|
[2696] | 660 | ! |
---|
[4648] | 661 | !-- Check topography for consistency with model domain. Therefore, use maximum and minium |
---|
| 662 | !-- topography-top indices. Note, minimum topography top index is already calculated. |
---|
[2696] | 663 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
| 664 | #if defined( __parallel ) |
---|
[4648] | 665 | CALL MPI_ALLREDUCE( MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ), nzb_local_max, 1, & |
---|
| 666 | MPI_INTEGER, MPI_MAX, comm2d, ierr ) |
---|
[2696] | 667 | #else |
---|
[4168] | 668 | nzb_local_max = MAXVAL( topo_top_ind(nys:nyn,nxl:nxr,0) ) |
---|
[2696] | 669 | #endif |
---|
[2968] | 670 | nzb_local_min = topo_min_level |
---|
[2696] | 671 | ! |
---|
| 672 | !-- Consistency checks |
---|
| 673 | IF ( nzb_local_min < 0 .OR. nzb_local_max > nz + 1 ) THEN |
---|
[4648] | 674 | WRITE( message_string, * ) 'nzb_local values are outside the model domain', & |
---|
| 675 | '&MINVAL( nzb_local ) = ', nzb_local_min, & |
---|
| 676 | '&MAXVAL( nzb_local ) = ', nzb_local_max |
---|
[2696] | 677 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
| 678 | ENDIF |
---|
| 679 | ENDIF |
---|
[1] | 680 | ! |
---|
[4648] | 681 | !-- Define vertical gridpoint from (or to) which on the usual finite difference form (which does not |
---|
| 682 | !-- use surface fluxes) is applied. |
---|
[1691] | 683 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[1] | 684 | nzb_diff = nzb + 2 |
---|
| 685 | ELSE |
---|
| 686 | nzb_diff = nzb + 1 |
---|
| 687 | ENDIF |
---|
| 688 | |
---|
[4414] | 689 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
[2696] | 690 | ! |
---|
[4648] | 691 | !-- Allocate and set the arrays containing the topography height (for output reasons only). |
---|
[4414] | 692 | IF ( nxr == nx .AND. nyn /= ny ) THEN |
---|
[4648] | 693 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn), zw_w_inner(nxl:nxr+1,nys:nyn) ) |
---|
[4414] | 694 | ELSEIF ( nxr /= nx .AND. nyn == ny ) THEN |
---|
[4648] | 695 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn+1), zw_w_inner(nxl:nxr,nys:nyn+1) ) |
---|
[4414] | 696 | ELSEIF ( nxr == nx .AND. nyn == ny ) THEN |
---|
[4648] | 697 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn+1), zw_w_inner(nxl:nxr+1,nys:nyn+1) ) |
---|
[4414] | 698 | ELSE |
---|
[4648] | 699 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn), zw_w_inner(nxl:nxr,nys:nyn) ) |
---|
[2696] | 700 | ENDIF |
---|
[1] | 701 | |
---|
[4414] | 702 | zu_s_inner = 0.0_wp |
---|
| 703 | zw_w_inner = 0.0_wp |
---|
[1] | 704 | ! |
---|
[4648] | 705 | !-- Determine local topography height on scalar and w-grid. Note, setting lateral boundary values |
---|
| 706 | !-- is not necessary, realized via wall_flags_static_0 array. Further, please note that loop |
---|
| 707 | !-- bounds are different from nxl to nxr and nys to nyn on south and right model boundary, hence, |
---|
[4414] | 708 | !-- use intrinsic lbound and ubound functions to infer array bounds. |
---|
| 709 | DO i = LBOUND(zu_s_inner, 1), UBOUND(zu_s_inner, 1) |
---|
| 710 | DO j = LBOUND(zu_s_inner, 2), UBOUND(zu_s_inner, 2) |
---|
[2696] | 711 | ! |
---|
[4648] | 712 | !-- Topography height on scalar grid. Therefore, determine index of upward-facing surface |
---|
| 713 | !-- element on scalar grid. |
---|
[4414] | 714 | zu_s_inner(i,j) = zu(topo_top_ind(j,i,0)) |
---|
[2696] | 715 | ! |
---|
[4648] | 716 | !-- Topography height on w grid. Therefore, determine index of upward-facing surface |
---|
| 717 | !-- element on w grid. |
---|
[4414] | 718 | zw_w_inner(i,j) = zw(topo_top_ind(j,i,3)) |
---|
| 719 | ENDDO |
---|
[2696] | 720 | ENDDO |
---|
| 721 | ENDIF |
---|
[4444] | 722 | |
---|
[2696] | 723 | END SUBROUTINE init_grid |
---|
| 724 | |
---|
[3065] | 725 | |
---|
[2696] | 726 | ! Description: |
---|
[4648] | 727 | ! -------------------------------------------------------------------------------------------------! |
---|
| 728 | !> Calculation of the stretching factor through an iterative method. Ideas were taken from the paper |
---|
| 729 | !> "Regional stretched grid generation and its application to the NCAR RegCM (1999)". Normally, no |
---|
| 730 | !> analytic solution exists because the system of equations has two variables (r,l) but four |
---|
| 731 | !> requirements (l=integer, r=[0,88;1,2], Eq(6), Eq(5) starting from index j=1) which results into |
---|
| 732 | !> an overdetermined system. |
---|
| 733 | !--------------------------------------------------------------------------------------------------! |
---|
[3065] | 734 | SUBROUTINE calculate_stretching_factor( number_end ) |
---|
[4648] | 735 | |
---|
| 736 | USE control_parameters, & |
---|
| 737 | ONLY: dz, dz_stretch_factor_array, dz_stretch_level_end, dz_stretch_level_start, & |
---|
| 738 | message_string |
---|
| 739 | |
---|
[3065] | 740 | USE kinds |
---|
[4648] | 741 | |
---|
[3065] | 742 | IMPLICIT NONE |
---|
[4648] | 743 | |
---|
| 744 | REAL(wp), PARAMETER :: stretch_factor_interval = 1.0E-06_wp !< interval for sampling possible stretching factors |
---|
| 745 | REAL(wp), PARAMETER :: stretch_factor_lower_limit = 0.88_wp !< lowest possible stretching factor |
---|
| 746 | REAL(wp), PARAMETER :: stretch_factor_upper_limit = 1.12_wp !< highest possible stretching factor |
---|
| 747 | |
---|
| 748 | INTEGER(iwp) :: iterations !< number of iterations until stretch_factor_lower/upper_limit is reached |
---|
| 749 | INTEGER(iwp) :: l_rounded !< after l_rounded grid levels dz(n) is strechted to dz(n+1) with stretch_factor_2 |
---|
[3065] | 750 | INTEGER(iwp) :: n !< loop variable for stretching |
---|
[4648] | 751 | |
---|
[3065] | 752 | INTEGER(iwp), INTENT(IN) :: number_end !< number of user-specified end levels for stretching |
---|
[4648] | 753 | |
---|
[3065] | 754 | REAL(wp) :: delta_l !< absolute difference between l and l_rounded |
---|
| 755 | REAL(wp) :: delta_stretch_factor !< absolute difference between stretch_factor_1 and stretch_factor_2 |
---|
[4648] | 756 | REAL(wp) :: delta_total_new !< sum of delta_l and delta_stretch_factor for the next iteration (should be as small as |
---|
| 757 | !< possible) |
---|
| 758 | REAL(wp) :: delta_total_old !< sum of delta_l and delta_stretch_factor for the last iteration |
---|
[3065] | 759 | REAL(wp) :: distance !< distance between dz_stretch_level_start and dz_stretch_level_end (stretching region) |
---|
[4648] | 760 | REAL(wp) :: l !< value that fulfil Eq. (5) in the paper mentioned above together with stretch_factor_1 |
---|
| 761 | !< exactly |
---|
[3065] | 762 | REAL(wp) :: numerator !< numerator of the quotient |
---|
| 763 | REAL(wp) :: stretch_factor_1 !< stretching factor that fulfil Eq. (5) togehter with l exactly |
---|
| 764 | REAL(wp) :: stretch_factor_2 !< stretching factor that fulfil Eq. (6) togehter with l_rounded exactly |
---|
[4648] | 765 | |
---|
| 766 | REAL(wp) :: dz_stretch_factor_array_2(9) = 1.08_wp !< Array that contains all stretch_factor_2 that belongs to |
---|
| 767 | !< stretch_factor_1 |
---|
| 768 | |
---|
| 769 | |
---|
[3068] | 770 | l = 0 |
---|
| 771 | DO n = 1, number_end |
---|
[4648] | 772 | |
---|
[3068] | 773 | iterations = 1 |
---|
[4648] | 774 | stretch_factor_1 = 1.0_wp |
---|
[4386] | 775 | stretch_factor_2 = 1.0_wp |
---|
| 776 | delta_total_old = 1.0_wp |
---|
[4648] | 777 | |
---|
[4386] | 778 | ! |
---|
| 779 | !-- First branch for stretching from rough to fine |
---|
[4648] | 780 | IF ( dz(n) > dz(n+1) ) THEN |
---|
| 781 | DO WHILE ( stretch_factor_1 >= stretch_factor_lower_limit ) |
---|
| 782 | |
---|
[4386] | 783 | stretch_factor_1 = 1.0_wp - iterations * stretch_factor_interval |
---|
[4648] | 784 | distance = ABS( dz_stretch_level_end(n) - dz_stretch_level_start(n) ) |
---|
| 785 | numerator = distance * stretch_factor_1 / dz(n) + stretch_factor_1 - distance / dz(n) |
---|
| 786 | |
---|
| 787 | IF ( numerator > 0.0_wp ) THEN |
---|
[4386] | 788 | l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0_wp |
---|
[3068] | 789 | l_rounded = NINT( l ) |
---|
| 790 | delta_l = ABS( l_rounded - l ) / l |
---|
| 791 | ENDIF |
---|
[4648] | 792 | |
---|
[3068] | 793 | stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) ) |
---|
[4648] | 794 | |
---|
| 795 | delta_stretch_factor = ABS( stretch_factor_1 - stretch_factor_2 ) / stretch_factor_2 |
---|
| 796 | |
---|
[3068] | 797 | delta_total_new = delta_l + delta_stretch_factor |
---|
[3065] | 798 | |
---|
| 799 | ! |
---|
[4648] | 800 | !-- stretch_factor_1 is taken to guarantee that the stretching procedure ends as close as |
---|
| 801 | !-- possible to dz_stretch_level_end. |
---|
| 802 | !-- stretch_factor_2 would guarantee that the stretched dz(n) is equal to dz(n+1) after |
---|
| 803 | !-- l_rounded grid levels. |
---|
| 804 | IF (delta_total_new < delta_total_old) THEN |
---|
[3068] | 805 | dz_stretch_factor_array(n) = stretch_factor_1 |
---|
| 806 | dz_stretch_factor_array_2(n) = stretch_factor_2 |
---|
| 807 | delta_total_old = delta_total_new |
---|
| 808 | ENDIF |
---|
[4648] | 809 | |
---|
[3068] | 810 | iterations = iterations + 1 |
---|
[4648] | 811 | |
---|
[3068] | 812 | ENDDO |
---|
[4386] | 813 | |
---|
| 814 | ! |
---|
| 815 | !-- Second branch for stretching from fine to rough |
---|
[4648] | 816 | ELSEIF ( dz(n) < dz(n+1) ) THEN |
---|
[3068] | 817 | DO WHILE ( stretch_factor_1 <= stretch_factor_upper_limit ) |
---|
[4648] | 818 | |
---|
[4386] | 819 | stretch_factor_1 = 1.0_wp + iterations * stretch_factor_interval |
---|
[4648] | 820 | distance = ABS( dz_stretch_level_end(n) - dz_stretch_level_start(n) ) |
---|
| 821 | numerator = distance * stretch_factor_1 / dz(n) + stretch_factor_1 - distance / dz(n) |
---|
| 822 | |
---|
[4386] | 823 | l = LOG( numerator ) / LOG( stretch_factor_1 ) - 1.0_wp |
---|
[3068] | 824 | l_rounded = NINT( l ) |
---|
| 825 | delta_l = ABS( l_rounded - l ) / l |
---|
[4648] | 826 | |
---|
[3068] | 827 | stretch_factor_2 = EXP( LOG( dz(n+1)/dz(n) ) / (l_rounded) ) |
---|
[3065] | 828 | |
---|
[4648] | 829 | delta_stretch_factor = ABS( stretch_factor_1 - stretch_factor_2 ) / stretch_factor_2 |
---|
| 830 | |
---|
[3068] | 831 | delta_total_new = delta_l + delta_stretch_factor |
---|
[4648] | 832 | |
---|
[3065] | 833 | ! |
---|
[4648] | 834 | !-- stretch_factor_1 is taken to guarantee that the stretching procedure ends as close as |
---|
| 835 | !-- possible to dz_stretch_level_end. |
---|
| 836 | !-- stretch_factor_2 would guarantee that the stretched dz(n) is equal to dz(n+1) after |
---|
| 837 | !-- l_rounded grid levels. |
---|
| 838 | IF (delta_total_new < delta_total_old) THEN |
---|
[3068] | 839 | dz_stretch_factor_array(n) = stretch_factor_1 |
---|
| 840 | dz_stretch_factor_array_2(n) = stretch_factor_2 |
---|
| 841 | delta_total_old = delta_total_new |
---|
| 842 | ENDIF |
---|
[4648] | 843 | |
---|
[3068] | 844 | iterations = iterations + 1 |
---|
| 845 | ENDDO |
---|
[4648] | 846 | |
---|
[3068] | 847 | ELSE |
---|
| 848 | message_string= 'Two adjacent values of dz must be different' |
---|
| 849 | CALL message( 'init_grid', 'PA0228', 1, 2, 0, 6, 0 ) |
---|
[4648] | 850 | |
---|
[3068] | 851 | ENDIF |
---|
| 852 | |
---|
| 853 | ! |
---|
[4648] | 854 | !-- Check if also the second stretching factor fits into the allowed interval. If not, print a |
---|
| 855 | !-- warning for the user. |
---|
| 856 | IF ( dz_stretch_factor_array_2(n) < stretch_factor_lower_limit .OR. & |
---|
| 857 | dz_stretch_factor_array_2(n) > stretch_factor_upper_limit ) THEN |
---|
| 858 | WRITE( message_string, * ) 'stretch_factor_2 = ', dz_stretch_factor_array_2(n), & |
---|
| 859 | ' which is', ' responsible for exactly reaching& dz =', & |
---|
| 860 | dz(n+1), 'after a specific amount of', & |
---|
| 861 | ' grid levels& exceeds the upper', & |
---|
| 862 | ' limit =', stretch_factor_upper_limit, & |
---|
| 863 | ' &or lower limit = ', stretch_factor_lower_limit |
---|
[3068] | 864 | CALL message( 'init_grid', 'PA0499', 0, 1, 0, 6, 0 ) |
---|
[4648] | 865 | |
---|
[3068] | 866 | ENDIF |
---|
| 867 | ENDDO |
---|
[4648] | 868 | |
---|
[3065] | 869 | END SUBROUTINE calculate_stretching_factor |
---|
[4648] | 870 | |
---|
| 871 | |
---|
[3065] | 872 | ! Description: |
---|
[4648] | 873 | ! -------------------------------------------------------------------------------------------------! |
---|
| 874 | !> Set temporary topography flags and reference buildings on top of underlying orography. |
---|
| 875 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 876 | SUBROUTINE process_topography( topo_3d ) |
---|
| 877 | |
---|
[4648] | 878 | USE arrays_3d, & |
---|
[2747] | 879 | ONLY: zu, zw |
---|
[2696] | 880 | |
---|
[4648] | 881 | USE control_parameters, & |
---|
[4507] | 882 | ONLY: bc_lr_cyc, bc_ns_cyc, ocean_mode |
---|
[2696] | 883 | |
---|
[4648] | 884 | USE exchange_horiz_mod, & |
---|
| 885 | ONLY: exchange_horiz_2d, exchange_horiz_int |
---|
[4457] | 886 | |
---|
[4648] | 887 | USE indices, & |
---|
| 888 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt |
---|
[2696] | 889 | |
---|
[4648] | 890 | USE netcdf_data_input_mod, & |
---|
| 891 | ONLY: buildings_f, building_id_f, building_type_f, & |
---|
| 892 | init_model, & |
---|
| 893 | input_pids_static, & |
---|
[2696] | 894 | terrain_height_f |
---|
| 895 | |
---|
| 896 | USE kinds |
---|
| 897 | |
---|
| 898 | USE pegrid |
---|
| 899 | |
---|
| 900 | IMPLICIT NONE |
---|
| 901 | |
---|
[2867] | 902 | INTEGER(iwp) :: i !< running index along x-direction |
---|
| 903 | INTEGER(iwp) :: j !< running index along y-direction |
---|
| 904 | INTEGER(iwp) :: k !< running index along z-direction with respect to numeric grid |
---|
| 905 | INTEGER(iwp) :: k2 !< running index along z-direction with respect to netcdf grid |
---|
| 906 | INTEGER(iwp) :: nr !< index variable indication maximum terrain height for respective building ID |
---|
| 907 | INTEGER(iwp) :: num_build !< counter for number of buildings |
---|
| 908 | INTEGER(iwp) :: topo_top_index !< orography top index, used to map 3D buildings onto terrain |
---|
[2696] | 909 | |
---|
[4444] | 910 | #if defined( __parallel ) |
---|
[2696] | 911 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: displace_dum !< displacements of start addresses, used for MPI_ALLGATHERV |
---|
[4444] | 912 | #endif |
---|
[2696] | 913 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids !< building IDs on entire model domain |
---|
[4648] | 914 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_final !< building IDs on entire model domain, multiple occurences are |
---|
| 915 | !< sorted out |
---|
[2696] | 916 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_final_tmp !< temporary array used for resizing |
---|
| 917 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_l !< building IDs on local subdomain |
---|
| 918 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: build_ids_l_tmp !< temporary array used to resize array of building IDs |
---|
| 919 | |
---|
| 920 | INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_buildings !< number of buildings with different ID on entire model domain |
---|
| 921 | INTEGER(iwp), DIMENSION(0:numprocs-1) :: num_buildings_l !< number of buildings with different ID on local subdomain |
---|
| 922 | |
---|
[4648] | 923 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo_3d !< input array for 3D topography and dummy array for setting |
---|
| 924 | !< "outer"-flags |
---|
[2696] | 925 | |
---|
[4648] | 926 | REAL(wp) :: ocean_offset !< offset to consider inverse vertical coordinate at topography |
---|
| 927 | !< definition |
---|
| 928 | REAL(wp) :: oro_min = 0.0_wp !< minimum terrain height in entire model domain, used to reference |
---|
| 929 | !< terrain to zero |
---|
[2696] | 930 | REAL(wp), DIMENSION(:), ALLOCATABLE :: oro_max !< maximum terrain height occupied by an building with certain id |
---|
[4648] | 931 | REAL(wp), DIMENSION(:), ALLOCATABLE :: oro_max_l !< maximum terrain height occupied by an building with certain id, |
---|
| 932 | !< on local subdomain |
---|
[2696] | 933 | |
---|
| 934 | ! |
---|
[4648] | 935 | !-- Reference lowest terrain height to zero. This ensures that first, non-required gird levels |
---|
| 936 | !-- (those which lie entirely below the minimum orography) are avoided, and second, that also |
---|
| 937 | !-- negative orography can be used within the input file. |
---|
| 938 | !-- Please note, in case of a nested run, the global minimum from all parent and childs needs to be |
---|
| 939 | !-- removed to avoid steep edges at the child-domain boundaries. |
---|
[3103] | 940 | IF ( input_pids_static ) THEN |
---|
[4648] | 941 | |
---|
| 942 | #if defined( __parallel ) |
---|
| 943 | CALL MPI_ALLREDUCE( MINVAL( terrain_height_f%var ), oro_min, 1, MPI_REAL, MPI_MIN, & |
---|
| 944 | MPI_COMM_WORLD, ierr ) |
---|
[3200] | 945 | #else |
---|
| 946 | oro_min = MINVAL( terrain_height_f%var ) |
---|
| 947 | #endif |
---|
[3103] | 948 | terrain_height_f%var = terrain_height_f%var - oro_min |
---|
[4507] | 949 | ! |
---|
| 950 | !-- Update reference height used within output files |
---|
| 951 | init_model%origin_z = init_model%origin_z + oro_min |
---|
| 952 | |
---|
[4648] | 953 | ENDIF |
---|
| 954 | |
---|
[3103] | 955 | ! |
---|
[4648] | 956 | !-- In the following, buildings and orography are further preprocessed before they are mapped on the |
---|
| 957 | !-- LES grid. |
---|
| 958 | !-- Buildings are mapped on top of the orography by maintaining the roof shape of the building. This |
---|
| 959 | !-- can be achieved by referencing building on top of the maximum terrain height within the area |
---|
| 960 | !-- occupied by the respective building. As buildings and terrain height are defined PE-wise, |
---|
| 961 | !-- parallelization of this referencing is required (a building can be distributed between different |
---|
| 962 | !-- PEs). |
---|
| 963 | !-- In a first step, determine the number of buildings with different building id on each PE. In a |
---|
| 964 | !-- next step, all building ids are gathered into one array which is present to all PEs. For each |
---|
| 965 | !-- building ID, the maximum terrain height occupied by the respective building is computed and |
---|
| 966 | !-- distributed to each PE. |
---|
| 967 | !-- Finally, for each building id and its respective reference orography, builidings are mapped on |
---|
| 968 | !-- top. |
---|
| 969 | !-- |
---|
| 970 | !-- First, pre-set topography flags, bit 1 indicates orography, bit 2 buildings classify the |
---|
| 971 | !-- respective surfaces. |
---|
[2696] | 972 | topo_3d = IBSET( topo_3d, 0 ) |
---|
| 973 | topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 ) |
---|
| 974 | ! |
---|
[4648] | 975 | !-- In order to map topography on PALM grid also in case of ocean simulations, pre-calculate an |
---|
| 976 | !-- offset value. |
---|
[3294] | 977 | ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode ) |
---|
[3051] | 978 | ! |
---|
[4648] | 979 | !-- Reference buildings on top of orography. This is not necessary if topography is read from ASCII |
---|
| 980 | !-- file as no distinction between buildings and terrain height can be made. Moreover, this is also |
---|
| 981 | !-- not necessary if urban-surface and land-surface model are used at the same time. |
---|
[2897] | 982 | IF ( input_pids_static ) THEN |
---|
| 983 | |
---|
[4648] | 984 | IF ( buildings_f%from_file ) THEN |
---|
[2897] | 985 | num_buildings_l = 0 |
---|
| 986 | num_buildings = 0 |
---|
[2696] | 987 | ! |
---|
[4648] | 988 | !-- Allocate at least one element for building ids and give it an inital negative value that |
---|
| 989 | !-- will be overwritten later. This, however, is necessary in case there all IDs in the model |
---|
| 990 | !-- domain are fill values. |
---|
[2897] | 991 | ALLOCATE( build_ids_l(1) ) |
---|
[4648] | 992 | build_ids_l = -1 |
---|
[2897] | 993 | DO i = nxl, nxr |
---|
| 994 | DO j = nys, nyn |
---|
| 995 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
| 996 | IF ( num_buildings_l(myid) > 0 ) THEN |
---|
[4648] | 997 | IF ( ANY( building_id_f%var(j,i) == build_ids_l ) ) THEN |
---|
[2897] | 998 | CYCLE |
---|
| 999 | ELSE |
---|
| 1000 | num_buildings_l(myid) = num_buildings_l(myid) + 1 |
---|
[2696] | 1001 | ! |
---|
| 1002 | !-- Resize array with different local building ids |
---|
| 1003 | ALLOCATE( build_ids_l_tmp(1:SIZE(build_ids_l)) ) |
---|
| 1004 | build_ids_l_tmp = build_ids_l |
---|
| 1005 | DEALLOCATE( build_ids_l ) |
---|
| 1006 | ALLOCATE( build_ids_l(1:num_buildings_l(myid)) ) |
---|
[4648] | 1007 | build_ids_l(1:num_buildings_l(myid)-1) = & |
---|
| 1008 | build_ids_l_tmp(1:num_buildings_l(myid)-1) |
---|
[2696] | 1009 | build_ids_l(num_buildings_l(myid)) = building_id_f%var(j,i) |
---|
| 1010 | DEALLOCATE( build_ids_l_tmp ) |
---|
| 1011 | ENDIF |
---|
| 1012 | ! |
---|
[4648] | 1013 | !-- First occuring building id on PE |
---|
| 1014 | ELSE |
---|
[2897] | 1015 | num_buildings_l(myid) = num_buildings_l(myid) + 1 |
---|
| 1016 | build_ids_l(1) = building_id_f%var(j,i) |
---|
| 1017 | ENDIF |
---|
[2696] | 1018 | ENDIF |
---|
[2897] | 1019 | ENDDO |
---|
[2696] | 1020 | ENDDO |
---|
| 1021 | ! |
---|
[4648] | 1022 | !-- Determine number of different building ids for the entire domain |
---|
| 1023 | #if defined( __parallel ) |
---|
| 1024 | CALL MPI_ALLREDUCE( num_buildings_l, num_buildings, numprocs, MPI_INTEGER, MPI_SUM, & |
---|
| 1025 | comm2d, ierr ) |
---|
[2696] | 1026 | #else |
---|
[2897] | 1027 | num_buildings = num_buildings_l |
---|
[2696] | 1028 | #endif |
---|
| 1029 | ! |
---|
[4648] | 1030 | !-- Gather all buildings ids on each PEs. |
---|
| 1031 | !-- First, allocate array encompassing all building ids in model domain. |
---|
[2897] | 1032 | ALLOCATE( build_ids(1:SUM(num_buildings)) ) |
---|
[4648] | 1033 | #if defined( __parallel ) |
---|
[2696] | 1034 | ! |
---|
[4648] | 1035 | !-- Allocate array for displacements. |
---|
| 1036 | !-- As each PE may has a different number of buildings, so that the block sizes send by each |
---|
| 1037 | !-- PE may not be equal. Hence, information about the respective displacement is required, |
---|
| 1038 | !-- indicating the respective adress where each MPI-task writes into the receive buffer array. |
---|
[2897] | 1039 | ALLOCATE( displace_dum(0:numprocs-1) ) |
---|
| 1040 | displace_dum(0) = 0 |
---|
| 1041 | DO i = 1, numprocs-1 |
---|
| 1042 | displace_dum(i) = displace_dum(i-1) + num_buildings(i-1) |
---|
| 1043 | ENDDO |
---|
[2696] | 1044 | |
---|
[4648] | 1045 | CALL MPI_ALLGATHERV( build_ids_l(1:num_buildings_l(myid)), num_buildings(myid), & |
---|
| 1046 | MPI_INTEGER, build_ids, num_buildings, displace_dum, MPI_INTEGER, & |
---|
| 1047 | comm2d, ierr ) |
---|
[2696] | 1048 | |
---|
[2897] | 1049 | DEALLOCATE( displace_dum ) |
---|
[2696] | 1050 | |
---|
| 1051 | #else |
---|
[2897] | 1052 | build_ids = build_ids_l |
---|
[2696] | 1053 | #endif |
---|
| 1054 | |
---|
| 1055 | ! |
---|
[4648] | 1056 | !-- Note, in parallel mode building ids can occure mutliple times, as each PE has send its own |
---|
| 1057 | !-- ids. Therefore, sort out building ids which appear more than one time. |
---|
[2897] | 1058 | num_build = 0 |
---|
| 1059 | DO nr = 1, SIZE(build_ids) |
---|
[2696] | 1060 | |
---|
[2897] | 1061 | IF ( ALLOCATED(build_ids_final) ) THEN |
---|
[4144] | 1062 | IF ( ANY( build_ids(nr) == build_ids_final ) ) THEN |
---|
[2897] | 1063 | CYCLE |
---|
| 1064 | ELSE |
---|
| 1065 | num_build = num_build + 1 |
---|
| 1066 | ! |
---|
| 1067 | !-- Resize |
---|
| 1068 | ALLOCATE( build_ids_final_tmp(1:num_build) ) |
---|
| 1069 | build_ids_final_tmp(1:num_build-1) = build_ids_final(1:num_build-1) |
---|
| 1070 | DEALLOCATE( build_ids_final ) |
---|
| 1071 | ALLOCATE( build_ids_final(1:num_build) ) |
---|
| 1072 | build_ids_final(1:num_build-1) = build_ids_final_tmp(1:num_build-1) |
---|
| 1073 | build_ids_final(num_build) = build_ids(nr) |
---|
| 1074 | DEALLOCATE( build_ids_final_tmp ) |
---|
[4648] | 1075 | ENDIF |
---|
[2696] | 1076 | ELSE |
---|
| 1077 | num_build = num_build + 1 |
---|
| 1078 | ALLOCATE( build_ids_final(1:num_build) ) |
---|
| 1079 | build_ids_final(num_build) = build_ids(nr) |
---|
[2897] | 1080 | ENDIF |
---|
| 1081 | ENDDO |
---|
[2696] | 1082 | |
---|
| 1083 | ! |
---|
[4648] | 1084 | !-- Determine maximumum terrain height occupied by the respective building and temporalily |
---|
| 1085 | !-- store on oro_max. |
---|
[2897] | 1086 | ALLOCATE( oro_max_l(1:SIZE(build_ids_final)) ) |
---|
| 1087 | ALLOCATE( oro_max(1:SIZE(build_ids_final)) ) |
---|
| 1088 | oro_max_l = 0.0_wp |
---|
[2696] | 1089 | |
---|
[2897] | 1090 | DO nr = 1, SIZE(build_ids_final) |
---|
[4648] | 1091 | oro_max_l(nr) = MAXVAL( MERGE( terrain_height_f%var(nys:nyn,nxl:nxr), & |
---|
| 1092 | 0.0_wp, & |
---|
| 1093 | building_id_f%var(nys:nyn,nxl:nxr) == & |
---|
| 1094 | build_ids_final(nr) ) ) |
---|
[2897] | 1095 | ENDDO |
---|
[4648] | 1096 | |
---|
| 1097 | #if defined( __parallel ) |
---|
| 1098 | IF ( SIZE(build_ids_final) >= 1 ) THEN |
---|
| 1099 | CALL MPI_ALLREDUCE( oro_max_l, oro_max, SIZE( oro_max ), MPI_REAL, MPI_MAX, comm2d, & |
---|
| 1100 | ierr ) |
---|
[2897] | 1101 | ENDIF |
---|
[2696] | 1102 | #else |
---|
[2897] | 1103 | oro_max = oro_max_l |
---|
[2696] | 1104 | #endif |
---|
[3051] | 1105 | ! |
---|
[4648] | 1106 | !-- Finally, determine discrete grid height of maximum orography occupied by a building. Use |
---|
| 1107 | !-- all-or-nothing approach, i.e. if terrain exceeds the scalar level the grid box is fully |
---|
| 1108 | !-- terrain and the maximum terrain is set to the zw level. |
---|
| 1109 | !-- terrain or |
---|
[3051] | 1110 | oro_max_l = 0.0 |
---|
| 1111 | DO nr = 1, SIZE(build_ids_final) |
---|
| 1112 | DO k = nzb, nzt |
---|
[4648] | 1113 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) oro_max_l(nr) = zw(k) - ocean_offset |
---|
[3051] | 1114 | ENDDO |
---|
[3142] | 1115 | oro_max(nr) = oro_max_l(nr) |
---|
[3051] | 1116 | ENDDO |
---|
[2897] | 1117 | ENDIF |
---|
[2696] | 1118 | ! |
---|
[4245] | 1119 | !-- Allocate array for storing terrain height under buildings |
---|
| 1120 | IF ( buildings_f%from_file ) THEN |
---|
| 1121 | ALLOCATE( buildings_f%oro_max(nysg:nyng,nxlg:nxrg) ) |
---|
| 1122 | buildings_f%oro_max = buildings_f%fill1 |
---|
| 1123 | END IF |
---|
| 1124 | ! |
---|
[4648] | 1125 | !-- Map orography as well as buildings onto grid. |
---|
[2696] | 1126 | DO i = nxl, nxr |
---|
| 1127 | DO j = nys, nyn |
---|
[2867] | 1128 | topo_top_index = 0 |
---|
[3142] | 1129 | ! |
---|
| 1130 | !-- Obtain index in global building_id array |
---|
| 1131 | IF ( buildings_f%from_file ) THEN |
---|
| 1132 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
| 1133 | ! |
---|
[4648] | 1134 | !-- Determine index where maximum terrain height occupied by the respective building |
---|
| 1135 | !-- height is stored. |
---|
| 1136 | nr = MINLOC( ABS( build_ids_final - building_id_f%var(j,i) ), DIM=1 ) |
---|
[4245] | 1137 | ! |
---|
| 1138 | !-- Save grid-indexed oro_max |
---|
| 1139 | buildings_f%oro_max(j,i) = oro_max(nr) |
---|
[3142] | 1140 | ENDIF |
---|
| 1141 | ENDIF |
---|
[2696] | 1142 | DO k = nzb, nzt |
---|
| 1143 | ! |
---|
[4648] | 1144 | !-- In a first step, if grid point is below or equal the given terrain height, grid |
---|
| 1145 | !-- point is flagged to be of type natural. |
---|
| 1146 | !-- Please note, in case there is also a building which is lower than the vertical grid |
---|
| 1147 | !-- spacing, initialization of surface attributes will not be correct as given surface |
---|
| 1148 | !-- information will not be in accordance to the classified grid points. |
---|
[4159] | 1149 | !-- Hence, in this case, also a building flag. |
---|
[2747] | 1150 | IF ( zu(k) - ocean_offset <= terrain_height_f%var(j,i) ) THEN |
---|
[4189] | 1151 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
| 1152 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
| 1153 | topo_top_index = k ! topo_top_index + 1 |
---|
[2696] | 1154 | ENDIF |
---|
| 1155 | ! |
---|
[4648] | 1156 | !-- Set building grid points. Here, only consider 2D buildings. |
---|
| 1157 | !-- 3D buildings require separate treatment. |
---|
[2897] | 1158 | IF ( buildings_f%from_file .AND. buildings_f%lod == 1 ) THEN |
---|
[4159] | 1159 | ! |
---|
[4648] | 1160 | !-- Fill-up the terrain to the level of maximum orography within the building-covered |
---|
| 1161 | !-- area. |
---|
[4159] | 1162 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
| 1163 | ! |
---|
[4648] | 1164 | !-- Note, oro_max is always on zw level |
---|
[4159] | 1165 | IF ( zu(k) - ocean_offset < oro_max(nr) ) THEN |
---|
[2696] | 1166 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
[4159] | 1167 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
[4648] | 1168 | ELSEIF ( zu(k) - ocean_offset <= oro_max(nr) + buildings_f%var_2d(j,i) ) THEN |
---|
[4159] | 1169 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
[2696] | 1170 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
| 1171 | ENDIF |
---|
| 1172 | ENDIF |
---|
| 1173 | ENDIF |
---|
| 1174 | ENDDO |
---|
| 1175 | ! |
---|
[4648] | 1176 | !-- Special treatment for non grid-resolved buildings. This case, the uppermost terrain |
---|
| 1177 | !-- grid point is flagged as building as well, even though no building exists at all. |
---|
| 1178 | !-- However, the surface element will be identified as urban-surface and the input data |
---|
| 1179 | !-- provided by the drivers is consistent to the surface classification. Else, all non |
---|
| 1180 | !-- grid-resolved buildings would vanish and identified as terrain grid points, which, |
---|
| 1181 | !-- however, won't be consistent with the input data. |
---|
[4159] | 1182 | IF ( buildings_f%from_file .AND. buildings_f%lod == 1 ) THEN |
---|
| 1183 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
| 1184 | DO k = nzb, nzt |
---|
| 1185 | IF( zw(k) - ocean_offset == oro_max(nr) ) THEN |
---|
| 1186 | IF ( buildings_f%var_2d(j,i) <= zu(k+1) - zw(k) ) THEN |
---|
| 1187 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
| 1188 | ENDIF |
---|
| 1189 | ENDIF |
---|
| 1190 | ENDDO |
---|
| 1191 | ENDIF |
---|
| 1192 | ENDIF |
---|
| 1193 | ! |
---|
[4648] | 1194 | !-- Map 3D buildings onto terrain height. |
---|
| 1195 | !-- In case of any slopes, map building on top of maximum terrain height covered by the |
---|
| 1196 | !-- building. In other words, extend building down to the respective local terrain-surface |
---|
| 1197 | !-- height. |
---|
[2897] | 1198 | IF ( buildings_f%from_file .AND. buildings_f%lod == 2 ) THEN |
---|
[2696] | 1199 | IF ( building_id_f%var(j,i) /= building_id_f%fill ) THEN |
---|
| 1200 | ! |
---|
[4648] | 1201 | !-- Extend building down to the terrain surface, i.e. fill-up surface irregularities |
---|
| 1202 | !-- below a building. Note, oro_max is already a discrete height according to the |
---|
| 1203 | !-- all-or-nothing approach, i.e. grid box is either topography or atmosphere, |
---|
[3051] | 1204 | !-- terrain top is defined at upper bound of the grid box. |
---|
[4648] | 1205 | !-- Hence, check for zw in this case. |
---|
| 1206 | !-- Note, do this only for buildings which are surface mounted, i.e. building types |
---|
| 1207 | !-- 1-6. Below bridges, which are represented exclusively by building type 7, terrain |
---|
| 1208 | !-- shape should be maintained. |
---|
[3855] | 1209 | IF ( building_type_f%from_file ) THEN |
---|
| 1210 | IF ( building_type_f%var(j,i) /= 7 ) THEN |
---|
[4648] | 1211 | DO k = topo_top_index + 1, nzt + 1 |
---|
[4159] | 1212 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) THEN |
---|
[3855] | 1213 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
[4159] | 1214 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
[3855] | 1215 | ENDIF |
---|
[4648] | 1216 | ENDDO |
---|
| 1217 | ! |
---|
| 1218 | !-- After surface irregularities are smoothen, determine lower start index |
---|
| 1219 | !-- where building starts. |
---|
[3855] | 1220 | DO k = nzb, nzt |
---|
[4648] | 1221 | IF ( zu(k) - ocean_offset <= oro_max(nr) ) topo_top_index = k |
---|
[3855] | 1222 | ENDDO |
---|
| 1223 | ENDIF |
---|
[3115] | 1224 | ENDIF |
---|
[3051] | 1225 | ! |
---|
| 1226 | !-- Finally, map building on top. |
---|
[2867] | 1227 | k2 = 0 |
---|
| 1228 | DO k = topo_top_index, nzt + 1 |
---|
[2796] | 1229 | IF ( k2 <= buildings_f%nz-1 ) THEN |
---|
[2696] | 1230 | IF ( buildings_f%var_3d(k2,j,i) == 1 ) THEN |
---|
| 1231 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
| 1232 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
| 1233 | ENDIF |
---|
| 1234 | ENDIF |
---|
| 1235 | k2 = k2 + 1 |
---|
| 1236 | ENDDO |
---|
| 1237 | ENDIF |
---|
| 1238 | ENDIF |
---|
| 1239 | ENDDO |
---|
| 1240 | ENDDO |
---|
| 1241 | ! |
---|
[4648] | 1242 | !-- Horizontal exchange the oro_max array, which is required to for initialization of |
---|
| 1243 | !-- building-surface properties. |
---|
[4265] | 1244 | IF ( ALLOCATED( buildings_f%oro_max ) ) THEN |
---|
[4457] | 1245 | CALL exchange_horiz_2d( buildings_f%oro_max(:,:) ) |
---|
[4265] | 1246 | ENDIF |
---|
[4245] | 1247 | ! |
---|
[2696] | 1248 | !-- Deallocate temporary arrays required for processing and reading data |
---|
| 1249 | IF ( ALLOCATED( oro_max ) ) DEALLOCATE( oro_max ) |
---|
| 1250 | IF ( ALLOCATED( oro_max_l ) ) DEALLOCATE( oro_max_l ) |
---|
| 1251 | IF ( ALLOCATED( build_ids_final ) ) DEALLOCATE( build_ids_final ) |
---|
| 1252 | ! |
---|
[4648] | 1253 | !-- Topography input via ASCII format. |
---|
[2696] | 1254 | ELSE |
---|
[3294] | 1255 | ocean_offset = MERGE( zw(0), 0.0_wp, ocean_mode ) |
---|
[4159] | 1256 | ! |
---|
[4648] | 1257 | !-- Initialize topography bit 0 (indicates obstacle) everywhere to zero and clear all grid points |
---|
| 1258 | !-- at nzb, where alway a surface is defined. |
---|
| 1259 | !-- Further, set also bit 1 (indicates terrain) at nzb, which is further used for masked data |
---|
| 1260 | !-- output and further processing. Note, in the ASCII case no distinction is made between |
---|
| 1261 | !-- buildings and terrain, so that setting of bit 1 and 2 at the same time has no effect. |
---|
[2696] | 1262 | topo_3d = IBSET( topo_3d, 0 ) |
---|
| 1263 | topo_3d(nzb,:,:) = IBCLR( topo_3d(nzb,:,:), 0 ) |
---|
[4159] | 1264 | topo_3d(nzb,:,:) = IBSET( topo_3d(nzb,:,:), 1 ) |
---|
[2696] | 1265 | DO i = nxl, nxr |
---|
| 1266 | DO j = nys, nyn |
---|
| 1267 | DO k = nzb, nzt |
---|
[3538] | 1268 | ! |
---|
[4648] | 1269 | !-- Flag topography for all grid points which are below the local topography height. |
---|
| 1270 | !-- Note, each topography is flagged as building (bit 2) as well as terrain (bit 1) in |
---|
| 1271 | !-- order to employ urban-surface as well as land-surface model. |
---|
[2747] | 1272 | IF ( zu(k) - ocean_offset <= buildings_f%var_2d(j,i) ) THEN |
---|
[4189] | 1273 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
[4630] | 1274 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 1 ) |
---|
| 1275 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
[2696] | 1276 | ENDIF |
---|
| 1277 | ENDDO |
---|
| 1278 | ENDDO |
---|
| 1279 | ENDDO |
---|
| 1280 | ENDIF |
---|
| 1281 | |
---|
| 1282 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
| 1283 | |
---|
| 1284 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1285 | IF ( nys == 0 ) topo_3d(:,-1,:) = topo_3d(:,0,:) |
---|
| 1286 | IF ( nyn == ny ) topo_3d(:,ny+1,:) = topo_3d(:,ny,:) |
---|
| 1287 | ENDIF |
---|
| 1288 | |
---|
| 1289 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1290 | IF ( nxl == 0 ) topo_3d(:,:,-1) = topo_3d(:,:,0) |
---|
[4648] | 1291 | IF ( nxr == nx ) topo_3d(:,:,nx+1) = topo_3d(:,:,nx) |
---|
[2696] | 1292 | ENDIF |
---|
| 1293 | |
---|
| 1294 | END SUBROUTINE process_topography |
---|
| 1295 | |
---|
| 1296 | |
---|
| 1297 | ! Description: |
---|
[4648] | 1298 | ! -------------------------------------------------------------------------------------------------! |
---|
| 1299 | !> Filter topography, i.e. fill holes resolved by only one grid point. |
---|
| 1300 | !> Such holes are suspected to lead to velocity blow-ups as continuity equation on discrete grid |
---|
| 1301 | !> cannot be fulfilled in such case. |
---|
| 1302 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 1303 | SUBROUTINE filter_topography( topo_3d ) |
---|
| 1304 | |
---|
[4648] | 1305 | USE control_parameters, & |
---|
[2696] | 1306 | ONLY: bc_lr_cyc, bc_ns_cyc, message_string |
---|
| 1307 | |
---|
[4648] | 1308 | USE exchange_horiz_mod, & |
---|
[4457] | 1309 | ONLY: exchange_horiz_int, exchange_horiz_2d_byte, exchange_horiz_2d_int |
---|
| 1310 | |
---|
[4648] | 1311 | USE indices, & |
---|
[2696] | 1312 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt |
---|
| 1313 | |
---|
[4648] | 1314 | USE netcdf_data_input_mod, & |
---|
| 1315 | ONLY: building_id_f, building_type_f |
---|
[2696] | 1316 | |
---|
| 1317 | USE pegrid |
---|
| 1318 | |
---|
| 1319 | IMPLICIT NONE |
---|
| 1320 | |
---|
| 1321 | INTEGER(iwp) :: i !< running index along x-direction |
---|
| 1322 | INTEGER(iwp) :: j !< running index along y-direction |
---|
| 1323 | INTEGER(iwp) :: k !< running index along z-direction |
---|
[4648] | 1324 | INTEGER(iwp) :: num_hole !< number of holes (in topography) resolved by only one grid point |
---|
| 1325 | INTEGER(iwp) :: num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE |
---|
[2696] | 1326 | INTEGER(iwp) :: num_wall !< number of surrounding vertical walls for a single grid point |
---|
| 1327 | |
---|
[2955] | 1328 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: topo_tmp !< temporary 3D-topography used to fill holes |
---|
[4648] | 1329 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo_3d !< 3D-topography array merging buildings and |
---|
| 1330 | !< orography |
---|
| 1331 | |
---|
| 1332 | LOGICAL :: filled = .FALSE. !< flag indicating if holes were filled |
---|
| 1333 | |
---|
[2696] | 1334 | ! |
---|
[4648] | 1335 | !-- Before checking for holes, set lateral boundary conditions for |
---|
[2696] | 1336 | !-- topography. After hole-filling, boundary conditions must be set again. |
---|
[4648] | 1337 | !-- Several iterations are performed, in order to fill holes which might |
---|
[2696] | 1338 | !-- emerge by the filling-algorithm itself. |
---|
| 1339 | ALLOCATE( topo_tmp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 1340 | topo_tmp = 0 |
---|
| 1341 | |
---|
| 1342 | num_hole = 99999 |
---|
[4648] | 1343 | DO WHILE ( num_hole > 0 ) |
---|
[2696] | 1344 | |
---|
[4648] | 1345 | num_hole = 0 |
---|
[2696] | 1346 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2955] | 1347 | ! |
---|
[4648] | 1348 | !-- Exchange also building ID and type. Note, building_type is an one-byte variable. |
---|
| 1349 | IF ( building_id_f%from_file ) & |
---|
[2955] | 1350 | CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
[4648] | 1351 | IF ( building_type_f%from_file ) & |
---|
[3763] | 1352 | CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
[2696] | 1353 | |
---|
| 1354 | topo_tmp = topo_3d |
---|
| 1355 | ! |
---|
[4648] | 1356 | !-- In case of non-cyclic lateral boundaries, assume lateral boundary to be a solid wall. Thus, |
---|
| 1357 | !-- intermediate spaces of one grid point between boundary and some topographic structure will be |
---|
| 1358 | !-- filled. |
---|
[2696] | 1359 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1360 | IF ( nys == 0 ) topo_tmp(:,-1,:) = IBCLR( topo_tmp(:,0,:), 0 ) |
---|
| 1361 | IF ( nyn == ny ) topo_tmp(:,ny+1,:) = IBCLR( topo_tmp(:,ny,:), 0 ) |
---|
| 1362 | ENDIF |
---|
| 1363 | |
---|
| 1364 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1365 | IF ( nxl == 0 ) topo_tmp(:,:,-1) = IBCLR( topo_tmp(:,:,0), 0 ) |
---|
[4648] | 1366 | IF ( nxr == nx ) topo_tmp(:,:,nx+1) = IBCLR( topo_tmp(:,:,nx), 0 ) |
---|
[2696] | 1367 | ENDIF |
---|
| 1368 | |
---|
| 1369 | num_hole_l = 0 |
---|
| 1370 | DO i = nxl, nxr |
---|
| 1371 | DO j = nys, nyn |
---|
| 1372 | DO k = nzb+1, nzt |
---|
| 1373 | IF ( BTEST( topo_tmp(k,j,i), 0 ) ) THEN |
---|
| 1374 | num_wall = 0 |
---|
[4648] | 1375 | IF ( .NOT. BTEST( topo_tmp(k,j-1,i), 0 ) ) num_wall = num_wall + 1 |
---|
| 1376 | IF ( .NOT. BTEST( topo_tmp(k,j+1,i), 0 ) ) num_wall = num_wall + 1 |
---|
| 1377 | IF ( .NOT. BTEST( topo_tmp(k,j,i-1), 0 ) ) num_wall = num_wall + 1 |
---|
| 1378 | IF ( .NOT. BTEST( topo_tmp(k,j,i+1), 0 ) ) num_wall = num_wall + 1 |
---|
| 1379 | IF ( .NOT. BTEST( topo_tmp(k-1,j,i), 0 ) ) num_wall = num_wall + 1 |
---|
| 1380 | IF ( .NOT. BTEST( topo_tmp(k+1,j,i), 0 ) ) num_wall = num_wall + 1 |
---|
[2696] | 1381 | |
---|
| 1382 | IF ( num_wall >= 4 ) THEN |
---|
| 1383 | num_hole_l = num_hole_l + 1 |
---|
| 1384 | ! |
---|
[4648] | 1385 | !-- Clear flag 0 and set special flag ( bit 4) to indicate that new topography |
---|
| 1386 | !-- point is a result of filtering process. |
---|
[2696] | 1387 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
[4314] | 1388 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 4 ) |
---|
[2696] | 1389 | ! |
---|
[4648] | 1390 | !-- If filled grid point is occupied by a building, classify it as building grid |
---|
| 1391 | !-- point. |
---|
[2696] | 1392 | IF ( building_type_f%from_file ) THEN |
---|
[4648] | 1393 | IF ( building_type_f%var(j,i) /= building_type_f%fill .OR. & |
---|
| 1394 | building_type_f%var(j+1,i) /= building_type_f%fill .OR. & |
---|
| 1395 | building_type_f%var(j-1,i) /= building_type_f%fill .OR. & |
---|
| 1396 | building_type_f%var(j,i+1) /= building_type_f%fill .OR. & |
---|
| 1397 | building_type_f%var(j,i-1) /= building_type_f%fill ) THEN |
---|
[2696] | 1398 | ! |
---|
| 1399 | !-- Set flag indicating building surfaces |
---|
| 1400 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 2 ) |
---|
| 1401 | ! |
---|
[4648] | 1402 | !-- Set building_type and ID at this position if not already set. This is |
---|
| 1403 | !-- required for proper initialization of urban-surface energy balance |
---|
[2696] | 1404 | !-- solver. |
---|
[4648] | 1405 | IF ( building_type_f%var(j,i) == building_type_f%fill ) THEN |
---|
[2696] | 1406 | |
---|
[4648] | 1407 | IF ( building_type_f%var(j+1,i) /= building_type_f%fill ) THEN |
---|
| 1408 | building_type_f%var(j,i) = building_type_f%var(j+1,i) |
---|
| 1409 | building_id_f%var(j,i) = building_id_f%var(j+1,i) |
---|
| 1410 | ELSEIF ( building_type_f%var(j-1,i) /= building_type_f%fill ) THEN |
---|
| 1411 | building_type_f%var(j,i) = building_type_f%var(j-1,i) |
---|
| 1412 | building_id_f%var(j,i) = building_id_f%var(j-1,i) |
---|
| 1413 | ELSEIF ( building_type_f%var(j,i+1) /= building_type_f%fill ) THEN |
---|
| 1414 | building_type_f%var(j,i) = building_type_f%var(j,i+1) |
---|
| 1415 | building_id_f%var(j,i) = building_id_f%var(j,i+1) |
---|
| 1416 | ELSEIF ( building_type_f%var(j,i-1) /= building_type_f%fill ) THEN |
---|
| 1417 | building_type_f%var(j,i) = building_type_f%var(j,i-1) |
---|
| 1418 | building_id_f%var(j,i) = building_id_f%var(j,i-1) |
---|
[2696] | 1419 | ENDIF |
---|
| 1420 | ENDIF |
---|
| 1421 | ENDIF |
---|
| 1422 | ENDIF |
---|
| 1423 | ! |
---|
[4648] | 1424 | !-- If filled grid point is already classified as building everything is fine, |
---|
| 1425 | !-- else classify this grid point as natural type grid point. This case, values |
---|
| 1426 | !-- for the surface type are already set. |
---|
[2696] | 1427 | IF ( .NOT. BTEST( topo_3d(k,j,i), 2 ) ) THEN |
---|
| 1428 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 1 ) |
---|
| 1429 | ENDIF |
---|
| 1430 | ENDIF |
---|
| 1431 | ENDIF |
---|
| 1432 | ENDDO |
---|
| 1433 | ENDDO |
---|
| 1434 | ENDDO |
---|
| 1435 | ! |
---|
| 1436 | !-- Count the total number of holes, required for informative message. |
---|
| 1437 | #if defined( __parallel ) |
---|
[4648] | 1438 | CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
[2696] | 1439 | #else |
---|
| 1440 | num_hole = num_hole_l |
---|
[4648] | 1441 | #endif |
---|
[2893] | 1442 | IF ( num_hole > 0 .AND. .NOT. filled ) filled = .TRUE. |
---|
[2696] | 1443 | |
---|
[2893] | 1444 | ENDDO |
---|
[2696] | 1445 | ! |
---|
[2893] | 1446 | !-- Create an informative message if any holes were filled. |
---|
| 1447 | IF ( filled ) THEN |
---|
[4648] | 1448 | WRITE( message_string, * ) 'Topography was filtered, i.e. holes ' // & |
---|
| 1449 | 'resolved by only one grid point ' // & |
---|
[2893] | 1450 | 'were filled during initialization.' |
---|
| 1451 | CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 ) |
---|
| 1452 | ENDIF |
---|
[2696] | 1453 | |
---|
| 1454 | DEALLOCATE( topo_tmp ) |
---|
| 1455 | ! |
---|
[4648] | 1456 | !-- Finally, exchange topo_3d array again and if necessary set Neumann boundary condition in case of |
---|
| 1457 | !-- non-cyclic lateral boundaries. |
---|
[2696] | 1458 | CALL exchange_horiz_int( topo_3d, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
| 1459 | |
---|
| 1460 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1461 | IF ( nys == 0 ) topo_3d(:,-1,:) = topo_3d(:,0,:) |
---|
| 1462 | IF ( nyn == ny ) topo_3d(:,ny+1,:) = topo_3d(:,ny,:) |
---|
| 1463 | ENDIF |
---|
| 1464 | |
---|
| 1465 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1466 | IF ( nxl == 0 ) topo_3d(:,:,-1) = topo_3d(:,:,0) |
---|
[4648] | 1467 | IF ( nxr == nx ) topo_3d(:,:,nx+1) = topo_3d(:,:,nx) |
---|
[2696] | 1468 | ENDIF |
---|
[2955] | 1469 | ! |
---|
| 1470 | !-- Exchange building ID and type. Note, building_type is an one-byte variable. |
---|
[4648] | 1471 | IF ( building_id_f%from_file ) & |
---|
[2955] | 1472 | CALL exchange_horiz_2d_int( building_id_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
[4648] | 1473 | IF ( building_type_f%from_file ) & |
---|
[3763] | 1474 | CALL exchange_horiz_2d_byte( building_type_f%var, nys, nyn, nxl, nxr, nbgp ) |
---|
[2696] | 1475 | |
---|
| 1476 | END SUBROUTINE filter_topography |
---|
| 1477 | |
---|
| 1478 | |
---|
| 1479 | ! Description: |
---|
[4648] | 1480 | ! -------------------------------------------------------------------------------------------------! |
---|
| 1481 | !> Reads topography information from file or sets generic topography. Moreover, all |
---|
| 1482 | !> topography-relevant topography arrays are initialized, and grid flags are set. |
---|
| 1483 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 1484 | SUBROUTINE init_topo( topo ) |
---|
| 1485 | |
---|
[4648] | 1486 | USE arrays_3d, & |
---|
[2696] | 1487 | ONLY: zw |
---|
[4648] | 1488 | |
---|
| 1489 | USE control_parameters, & |
---|
| 1490 | ONLY: bc_lr_cyc, bc_ns_cyc, building_height, building_length_x, building_length_y, & |
---|
| 1491 | building_wall_left, building_wall_south, canyon_height, canyon_wall_left, & |
---|
| 1492 | canyon_wall_south, canyon_width_x, canyon_width_y, dp_level_ind_b, dz, & |
---|
| 1493 | message_string, topography, topography_grid_convention, tunnel_height, & |
---|
| 1494 | tunnel_length, tunnel_width_x, tunnel_width_y, tunnel_wall_depth |
---|
| 1495 | |
---|
| 1496 | USE exchange_horiz_mod, & |
---|
[4457] | 1497 | ONLY: exchange_horiz_int |
---|
| 1498 | |
---|
[4648] | 1499 | USE grid_variables, & |
---|
[2696] | 1500 | ONLY: dx, dy |
---|
[4648] | 1501 | |
---|
| 1502 | USE indices, & |
---|
| 1503 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nz, nzb, nzt |
---|
| 1504 | |
---|
[2696] | 1505 | USE kinds |
---|
| 1506 | |
---|
[4648] | 1507 | USE netcdf_data_input_mod, & |
---|
| 1508 | ONLY: buildings_f, terrain_height_f |
---|
| 1509 | |
---|
[2696] | 1510 | USE pegrid |
---|
| 1511 | |
---|
| 1512 | IMPLICIT NONE |
---|
| 1513 | |
---|
[4386] | 1514 | INTEGER(iwp) :: bh !< temporary vertical index of building height |
---|
[4648] | 1515 | INTEGER(iwp) :: ch !< temporary vertical index for canyon height |
---|
| 1516 | INTEGER(iwp) :: hv_in !< heavyside function to model inner tunnel surface |
---|
| 1517 | INTEGER(iwp) :: i !< index variable along x |
---|
[4386] | 1518 | INTEGER(iwp) :: index_left_bwall !< index for left building wall |
---|
[4648] | 1519 | INTEGER(iwp) :: index_north_bwall !< index for north building wall |
---|
[4386] | 1520 | INTEGER(iwp) :: index_right_bwall !< index for right building wall |
---|
| 1521 | INTEGER(iwp) :: index_south_bwall !< index for south building wall |
---|
| 1522 | INTEGER(iwp) :: index_left_cwall !< index for left canyon wall |
---|
[4648] | 1523 | INTEGER(iwp) :: index_north_cwall !< index for north canyon wall |
---|
[4386] | 1524 | INTEGER(iwp) :: index_right_cwall !< index for right canyon wall |
---|
| 1525 | INTEGER(iwp) :: index_south_cwall !< index for south canyon wall |
---|
| 1526 | INTEGER(iwp) :: j !< index variable along y |
---|
| 1527 | INTEGER(iwp) :: k !< index variable along z |
---|
[4648] | 1528 | INTEGER(iwp) :: ngp_bx !< grid point number of building size along x |
---|
| 1529 | INTEGER(iwp) :: ngp_by !< grid point number of building size along y |
---|
| 1530 | INTEGER(iwp) :: ngp_cx !< grid point number of canyon size along x |
---|
| 1531 | INTEGER(iwp) :: ngp_cy !< grid point number of canyon size along y |
---|
| 1532 | INTEGER(iwp) :: hv_out !< heavyside function to model outer tunnel surface |
---|
| 1533 | INTEGER(iwp) :: td !< tunnel wall depth |
---|
| 1534 | INTEGER(iwp) :: th !< height of outer tunnel wall |
---|
| 1535 | INTEGER(iwp) :: txe_in !< end position of inner tunnel wall in x |
---|
[4386] | 1536 | INTEGER(iwp) :: txe_out !< end position of outer tunnel wall in x |
---|
[4648] | 1537 | INTEGER(iwp) :: txs_in !< start position of inner tunnel wall in x |
---|
[4386] | 1538 | INTEGER(iwp) :: txs_out !< start position of outer tunnel wall in x |
---|
[4648] | 1539 | INTEGER(iwp) :: tye_in !< end position of inner tunnel wall in y |
---|
[4386] | 1540 | INTEGER(iwp) :: tye_out !< end position of outer tunnel wall in y |
---|
[4648] | 1541 | INTEGER(iwp) :: tys_in !< start position of inner tunnel wall in y |
---|
[4386] | 1542 | INTEGER(iwp) :: tys_out !< start position of outer tunnel wall in y |
---|
[2696] | 1543 | |
---|
| 1544 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !< index for topography top at cell-center |
---|
[4648] | 1545 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo !< input array for 3D topography and dummy array for setting |
---|
| 1546 | !< "outer"-flags |
---|
[2696] | 1547 | ! |
---|
[4648] | 1548 | !-- Check for correct setting of the namelist parameter topography. If topography information is |
---|
| 1549 | !-- read from file but topography = 'flat', initialization does not work properly. |
---|
| 1550 | IF ( ( buildings_f%from_file .OR. terrain_height_f%from_file ) .AND. & |
---|
[4189] | 1551 | TRIM( topography ) /= 'read_from_file' ) THEN |
---|
[4648] | 1552 | message_string = 'If topography information is provided (via ' // & |
---|
| 1553 | 'Netcdf or ASCII input) topography = ' // & |
---|
[4189] | 1554 | '"read_from_file" is required.' |
---|
[4648] | 1555 | CALL message( 'init_grid', 'PA0437', 1, 2, 0, 6, 0 ) |
---|
[4189] | 1556 | ENDIF |
---|
| 1557 | ! |
---|
[1] | 1558 | !-- Set outer and inner index arrays for non-flat topography. |
---|
[4648] | 1559 | !-- Here consistency checks concerning domain size and periodicity are necessary. |
---|
| 1560 | !-- Within this SELECT CASE structure only nzb_local is initialized individually depending on the |
---|
| 1561 | !-- chosen topography type, all other index arrays are initialized further below. |
---|
[1] | 1562 | SELECT CASE ( TRIM( topography ) ) |
---|
| 1563 | |
---|
| 1564 | CASE ( 'flat' ) |
---|
[4648] | 1565 | ! |
---|
[2232] | 1566 | !-- Initialilize 3D topography array, used later for initializing flags |
---|
[4340] | 1567 | topo(nzb+1:nzt+1,:,:) = IBSET( topo(nzb+1:nzt+1,:,:), 0 ) |
---|
[4648] | 1568 | |
---|
[4340] | 1569 | CASE ( 'closed_channel' ) |
---|
[4648] | 1570 | ! |
---|
[4340] | 1571 | !-- Initialilize 3D topography array, used later for initializing flags |
---|
[4648] | 1572 | topo(nzb+1:nzt,:,:) = IBSET( topo(nzb+1:nzt,:,:), 0 ) |
---|
[1] | 1573 | |
---|
| 1574 | CASE ( 'single_building' ) |
---|
| 1575 | ! |
---|
| 1576 | !-- Single rectangular building, by default centered in the middle of the |
---|
| 1577 | !-- total domain |
---|
[4386] | 1578 | ngp_bx = NINT( building_length_x / dx ) |
---|
| 1579 | ngp_by = NINT( building_length_y / dy ) |
---|
[2232] | 1580 | bh = MINLOC( ABS( zw - building_height ), 1 ) - 1 |
---|
[4648] | 1581 | IF ( ABS( zw(bh) - building_height ) == ABS( zw(bh+1) - building_height ) ) bh = bh + 1 |
---|
[1322] | 1582 | IF ( building_wall_left == 9999999.9_wp ) THEN |
---|
[4386] | 1583 | building_wall_left = ( nx + 1 - ngp_bx ) / 2 * dx |
---|
[1] | 1584 | ENDIF |
---|
[4386] | 1585 | index_left_bwall = NINT( building_wall_left / dx ) |
---|
| 1586 | index_right_bwall = index_left_bwall + ngp_bx |
---|
[1] | 1587 | |
---|
[1322] | 1588 | IF ( building_wall_south == 9999999.9_wp ) THEN |
---|
[4386] | 1589 | building_wall_south = ( ny + 1 - ngp_by ) / 2 * dy |
---|
[1] | 1590 | ENDIF |
---|
[4386] | 1591 | index_south_bwall = NINT( building_wall_south / dy ) |
---|
| 1592 | index_north_bwall = index_south_bwall + ngp_by |
---|
[1] | 1593 | |
---|
| 1594 | ! |
---|
| 1595 | !-- Building size has to meet some requirements |
---|
[4648] | 1596 | IF ( ( index_left_bwall < 1 ) .OR. ( index_right_bwall > nx-1 ) .OR. & |
---|
| 1597 | ( index_right_bwall < index_left_bwall+3 ) .OR. & |
---|
| 1598 | ( index_south_bwall < 1 ) .OR. ( index_north_bwall > ny-1 ) .OR. & |
---|
[4386] | 1599 | ( index_north_bwall < index_south_bwall+3 ) ) THEN |
---|
[4648] | 1600 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
| 1601 | '&index_left_bwall=', index_left_bwall, & |
---|
| 1602 | 'index_right_bwall=', index_right_bwall, & |
---|
| 1603 | 'index_south_bwall=', index_south_bwall, & |
---|
| 1604 | 'index_north_bwall=', index_north_bwall, & |
---|
[4386] | 1605 | 'nx=', nx, 'ny=', ny |
---|
[254] | 1606 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
[1] | 1607 | ENDIF |
---|
| 1608 | |
---|
[2696] | 1609 | ALLOCATE( nzb_local(nysg:nyng,nxlg:nxrg) ) |
---|
[2892] | 1610 | nzb_local = 0 |
---|
[1] | 1611 | ! |
---|
[4648] | 1612 | !-- Define the building. |
---|
| 1613 | IF ( index_left_bwall <= nxr .AND. index_right_bwall >= nxl .AND. & |
---|
| 1614 | index_south_bwall <= nyn .AND. index_north_bwall >= nys ) & |
---|
| 1615 | nzb_local(MAX(nys,index_south_bwall):MIN(nyn,index_north_bwall), & |
---|
[4386] | 1616 | MAX(nxl,index_left_bwall):MIN(nxr,index_right_bwall)) = bh |
---|
[2232] | 1617 | ! |
---|
[2696] | 1618 | !-- Set bit array on basis of nzb_local |
---|
| 1619 | DO i = nxl, nxr |
---|
| 1620 | DO j = nys, nyn |
---|
[4648] | 1621 | topo(nzb_local(j,i)+1:nzt+1,j,i) = IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
[2232] | 1622 | ENDDO |
---|
| 1623 | ENDDO |
---|
[4648] | 1624 | |
---|
[2696] | 1625 | DEALLOCATE( nzb_local ) |
---|
[2232] | 1626 | |
---|
[2696] | 1627 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2823] | 1628 | ! |
---|
[4648] | 1629 | !-- Set boundary conditions also for flags. Can be interpreted as Neumannb oundary conditions |
---|
| 1630 | !-- for topography. |
---|
[2823] | 1631 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1632 | IF ( nys == 0 ) THEN |
---|
[4648] | 1633 | DO i = 1, nbgp |
---|
[2823] | 1634 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
| 1635 | ENDDO |
---|
| 1636 | ENDIF |
---|
| 1637 | IF ( nyn == ny ) THEN |
---|
[4648] | 1638 | DO i = 1, nbgp |
---|
[2823] | 1639 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
| 1640 | ENDDO |
---|
| 1641 | ENDIF |
---|
| 1642 | ENDIF |
---|
| 1643 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1644 | IF ( nxl == 0 ) THEN |
---|
[4648] | 1645 | DO i = 1, nbgp |
---|
[2823] | 1646 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
| 1647 | ENDDO |
---|
| 1648 | ENDIF |
---|
[4648] | 1649 | IF ( nxr == nx ) THEN |
---|
| 1650 | DO i = 1, nbgp |
---|
| 1651 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
[2823] | 1652 | ENDDO |
---|
[4648] | 1653 | ENDIF |
---|
[2823] | 1654 | ENDIF |
---|
[2232] | 1655 | |
---|
[240] | 1656 | CASE ( 'single_street_canyon' ) |
---|
| 1657 | ! |
---|
| 1658 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
| 1659 | !-- The canyon is centered in the other direction by default. |
---|
[1322] | 1660 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[240] | 1661 | ! |
---|
| 1662 | !-- Street canyon in y direction |
---|
[4386] | 1663 | ngp_cx = NINT( canyon_width_x / dx ) |
---|
[1322] | 1664 | IF ( canyon_wall_left == 9999999.9_wp ) THEN |
---|
[4386] | 1665 | canyon_wall_left = ( nx + 1 - ngp_cx ) / 2 * dx |
---|
[240] | 1666 | ENDIF |
---|
[4386] | 1667 | index_left_cwall= NINT( canyon_wall_left / dx ) |
---|
| 1668 | index_right_cwall= index_left_cwall+ ngp_cx |
---|
[1322] | 1669 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[240] | 1670 | ! |
---|
| 1671 | !-- Street canyon in x direction |
---|
[4386] | 1672 | ngp_cy = NINT( canyon_width_y / dy ) |
---|
[1322] | 1673 | IF ( canyon_wall_south == 9999999.9_wp ) THEN |
---|
[4386] | 1674 | canyon_wall_south = ( ny + 1 - ngp_cy ) / 2 * dy |
---|
[240] | 1675 | ENDIF |
---|
[4386] | 1676 | index_south_cwall = NINT( canyon_wall_south / dy ) |
---|
| 1677 | index_north_cwall = index_south_cwall + ngp_cy |
---|
[4648] | 1678 | |
---|
[240] | 1679 | ELSE |
---|
[4648] | 1680 | |
---|
[254] | 1681 | message_string = 'no street canyon width given' |
---|
| 1682 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
[4648] | 1683 | |
---|
[240] | 1684 | ENDIF |
---|
| 1685 | |
---|
[2232] | 1686 | ch = MINLOC( ABS( zw - canyon_height ), 1 ) - 1 |
---|
[4648] | 1687 | IF ( ABS( zw(ch) - canyon_height ) == ABS( zw(ch+1) - canyon_height ) ) ch = ch + 1 |
---|
[240] | 1688 | dp_level_ind_b = ch |
---|
| 1689 | ! |
---|
| 1690 | !-- Street canyon size has to meet some requirements |
---|
[1322] | 1691 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[4648] | 1692 | IF ( ( index_left_cwall< 1 ) .OR. ( index_right_cwall> nx-1 ) .OR. & |
---|
[4543] | 1693 | ( ngp_cx < 3 ) ) THEN |
---|
[4648] | 1694 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
| 1695 | '&index_left_cwall=', index_left_cwall, & |
---|
| 1696 | ' index_right_cwall=', index_right_cwall, & |
---|
| 1697 | ' ngp_cx=', ngp_cx, ' ch=', ch, ' nx=', nx, ' ny=', ny |
---|
| 1698 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
[240] | 1699 | ENDIF |
---|
[1322] | 1700 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[4648] | 1701 | IF ( ( index_south_cwall < 1 ) .OR. & |
---|
| 1702 | ( index_north_cwall > ny-1 ) .OR. ( ngp_cy < 3 ) ) THEN |
---|
| 1703 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
| 1704 | '&index_south_cwall=', index_south_cwall, & |
---|
| 1705 | ' index_north_cwall=', index_north_cwall, & |
---|
| 1706 | ' ngp_cy=', ngp_cy, ' ch=', ch, ' nx=', nx, ' ny=', ny |
---|
| 1707 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
[240] | 1708 | ENDIF |
---|
| 1709 | ENDIF |
---|
[4648] | 1710 | IF ( canyon_width_x /= 9999999.9_wp .AND. canyon_width_y /= 9999999.9_wp ) THEN |
---|
| 1711 | message_string = 'inconsistent canyon parameters:' // & |
---|
| 1712 | '&street canyon can only be oriented' // & |
---|
[3045] | 1713 | ' either in x- or in y-direction' |
---|
[254] | 1714 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
[240] | 1715 | ENDIF |
---|
| 1716 | |
---|
[2696] | 1717 | ALLOCATE( nzb_local(nysg:nyng,nxlg:nxrg) ) |
---|
[240] | 1718 | nzb_local = ch |
---|
[1322] | 1719 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[4648] | 1720 | IF ( index_left_cwall<= nxr .AND. index_right_cwall>= nxl ) & |
---|
[4386] | 1721 | nzb_local(:,MAX(nxl,index_left_cwall+1):MIN(nxr,index_right_cwall-1)) = 0 |
---|
[1322] | 1722 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[4648] | 1723 | IF ( index_south_cwall <= nyn .AND. index_north_cwall >= nys ) & |
---|
[4386] | 1724 | nzb_local(MAX(nys,index_south_cwall+1):MIN(nyn,index_north_cwall-1),:) = 0 |
---|
[240] | 1725 | ENDIF |
---|
[2232] | 1726 | ! |
---|
[2696] | 1727 | !-- Set bit array on basis of nzb_local |
---|
| 1728 | DO i = nxl, nxr |
---|
| 1729 | DO j = nys, nyn |
---|
[4648] | 1730 | topo(nzb_local(j,i)+1:nzt+1,j,i) = IBSET( topo(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
[2232] | 1731 | ENDDO |
---|
| 1732 | ENDDO |
---|
[2696] | 1733 | DEALLOCATE( nzb_local ) |
---|
[1994] | 1734 | |
---|
[2696] | 1735 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2823] | 1736 | ! |
---|
[4648] | 1737 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions |
---|
| 1738 | !-- for topography. |
---|
[2823] | 1739 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1740 | IF ( nys == 0 ) THEN |
---|
[4648] | 1741 | DO i = 1, nbgp |
---|
| 1742 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
[2823] | 1743 | ENDDO |
---|
| 1744 | ENDIF |
---|
| 1745 | IF ( nyn == ny ) THEN |
---|
[4648] | 1746 | DO i = 1, nbgp |
---|
[2823] | 1747 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
| 1748 | ENDDO |
---|
| 1749 | ENDIF |
---|
| 1750 | ENDIF |
---|
| 1751 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1752 | IF ( nxl == 0 ) THEN |
---|
[4648] | 1753 | DO i = 1, nbgp |
---|
| 1754 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
[2823] | 1755 | ENDDO |
---|
| 1756 | ENDIF |
---|
[4648] | 1757 | IF ( nxr == nx ) THEN |
---|
| 1758 | DO i = 1, nbgp |
---|
| 1759 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
[2823] | 1760 | ENDDO |
---|
[4648] | 1761 | ENDIF |
---|
[2823] | 1762 | ENDIF |
---|
[2232] | 1763 | |
---|
| 1764 | CASE ( 'tunnel' ) |
---|
| 1765 | |
---|
| 1766 | ! |
---|
| 1767 | !-- Tunnel height |
---|
| 1768 | IF ( tunnel_height == 9999999.9_wp ) THEN |
---|
| 1769 | th = zw( INT( 0.2 * nz) ) |
---|
| 1770 | ELSE |
---|
| 1771 | th = tunnel_height |
---|
| 1772 | ENDIF |
---|
| 1773 | ! |
---|
| 1774 | !-- Tunnel-wall depth |
---|
[4648] | 1775 | IF ( tunnel_wall_depth == 9999999.9_wp ) THEN |
---|
[3065] | 1776 | td = MAX ( dx, dy, dz(1) ) |
---|
[2232] | 1777 | ELSE |
---|
| 1778 | td = tunnel_wall_depth |
---|
| 1779 | ENDIF |
---|
| 1780 | ! |
---|
| 1781 | !-- Check for tunnel width |
---|
[4648] | 1782 | IF ( tunnel_width_x == 9999999.9_wp .AND. tunnel_width_y == 9999999.9_wp ) THEN |
---|
[2232] | 1783 | message_string = 'No tunnel width is given. ' |
---|
[2274] | 1784 | CALL message( 'init_grid', 'PA0280', 1, 2, 0, 6, 0 ) |
---|
[2232] | 1785 | ENDIF |
---|
[4648] | 1786 | IF ( tunnel_width_x /= 9999999.9_wp .AND. tunnel_width_y /= 9999999.9_wp ) THEN |
---|
| 1787 | message_string = 'Inconsistent tunnel parameters:' // & |
---|
| 1788 | 'tunnel can only be oriented' // & |
---|
[2232] | 1789 | 'either in x- or in y-direction.' |
---|
[2274] | 1790 | CALL message( 'init_grid', 'PA0281', 1, 2, 0, 6, 0 ) |
---|
[2232] | 1791 | ENDIF |
---|
| 1792 | ! |
---|
[4356] | 1793 | !-- Check for too small tunnel width in x- and y-direction |
---|
[4648] | 1794 | IF ( tunnel_width_x /= 9999999.9_wp .AND. & |
---|
[4356] | 1795 | tunnel_width_x - 2.0_wp * td <= 2.0_wp * dx ) THEN |
---|
| 1796 | message_string = 'tunnel_width_x too small' |
---|
| 1797 | CALL message( 'init_grid', 'PA0175', 1, 2, 0, 6, 0 ) |
---|
| 1798 | ENDIF |
---|
[4648] | 1799 | IF ( tunnel_width_y /= 9999999.9_wp .AND. & |
---|
[4356] | 1800 | tunnel_width_y - 2.0_wp * td <= 2.0_wp * dy ) THEN |
---|
| 1801 | message_string = 'tunnel_width_y too small' |
---|
| 1802 | CALL message( 'init_grid', 'PA0455', 1, 2, 0, 6, 0 ) |
---|
| 1803 | ENDIF |
---|
| 1804 | ! |
---|
[4648] | 1805 | !-- Check for too large tunnel width. |
---|
[4356] | 1806 | !-- Tunnel axis along y. |
---|
[2232] | 1807 | IF ( tunnel_width_x /= 9999999.9_wp ) THEN |
---|
| 1808 | IF ( tunnel_width_x > ( nx + 1 ) * dx ) THEN |
---|
[4356] | 1809 | message_string = 'tunnel_width_x too large' |
---|
[2274] | 1810 | CALL message( 'init_grid', 'PA0282', 1, 2, 0, 6, 0 ) |
---|
[2232] | 1811 | ENDIF |
---|
| 1812 | |
---|
| 1813 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_width_x * 0.5_wp ) |
---|
| 1814 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_width_x * 0.5_wp ) |
---|
[4648] | 1815 | txs_in = INT( ( nx + 1 ) * 0.5_wp * dx - ( tunnel_width_x * 0.5_wp - td ) ) |
---|
| 1816 | txe_in = INT( ( nx + 1 ) * 0.5_wp * dx + ( tunnel_width_x * 0.5_wp - td ) ) |
---|
[2232] | 1817 | |
---|
| 1818 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_length * 0.5_wp ) |
---|
| 1819 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_length * 0.5_wp ) |
---|
| 1820 | tys_in = tys_out |
---|
| 1821 | tye_in = tye_out |
---|
| 1822 | ENDIF |
---|
| 1823 | ! |
---|
[4356] | 1824 | !-- Tunnel axis along x. |
---|
[2232] | 1825 | IF ( tunnel_width_y /= 9999999.9_wp ) THEN |
---|
| 1826 | IF ( tunnel_width_y > ( ny + 1 ) * dy ) THEN |
---|
[4356] | 1827 | message_string = 'tunnel_width_y too large' |
---|
[2274] | 1828 | CALL message( 'init_grid', 'PA0456', 1, 2, 0, 6, 0 ) |
---|
[2232] | 1829 | ENDIF |
---|
| 1830 | |
---|
| 1831 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_length * 0.5_wp ) |
---|
| 1832 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_length * 0.5_wp ) |
---|
| 1833 | txs_in = txs_out |
---|
| 1834 | txe_in = txe_out |
---|
| 1835 | |
---|
| 1836 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_width_y * 0.5_wp ) |
---|
| 1837 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_width_y * 0.5_wp ) |
---|
[4648] | 1838 | tys_in = INT( ( ny + 1 ) * 0.5_wp * dy - ( tunnel_width_y * 0.5_wp - td ) ) |
---|
| 1839 | tye_in = INT( ( ny + 1 ) * 0.5_wp * dy + ( tunnel_width_y * 0.5_wp - td ) ) |
---|
[2232] | 1840 | ENDIF |
---|
| 1841 | |
---|
[2696] | 1842 | topo = 0 |
---|
[2232] | 1843 | DO i = nxl, nxr |
---|
| 1844 | DO j = nys, nyn |
---|
| 1845 | ! |
---|
| 1846 | !-- Use heaviside function to model outer tunnel surface |
---|
[4648] | 1847 | hv_out = th * 0.5_wp * ( ( SIGN( 1.0_wp, i * dx - txs_out ) + 1.0_wp ) & |
---|
| 1848 | - ( SIGN( 1.0_wp, i * dx - txe_out ) + 1.0_wp ) ) |
---|
[2232] | 1849 | |
---|
[4648] | 1850 | hv_out = hv_out * 0.5_wp * ( ( SIGN( 1.0_wp, j * dy - tys_out ) + 1.0_wp ) & |
---|
| 1851 | - ( SIGN( 1.0_wp, j * dy - tye_out ) + 1.0_wp ) ) |
---|
| 1852 | ! |
---|
[2232] | 1853 | !-- Use heaviside function to model inner tunnel surface |
---|
[4648] | 1854 | hv_in = ( th - td ) * 0.5_wp * ( ( SIGN( 1.0_wp, i * dx - txs_in ) + 1.0_wp ) & |
---|
| 1855 | - ( SIGN( 1.0_wp, i * dx - txe_in ) + 1.0_wp ) ) |
---|
[2232] | 1856 | |
---|
[4648] | 1857 | hv_in = hv_in * 0.5_wp * ( ( SIGN( 1.0_wp, j * dy - tys_in ) + 1.0_wp ) & |
---|
| 1858 | - ( SIGN( 1.0_wp, j * dy - tye_in ) + 1.0_wp ) ) |
---|
[2232] | 1859 | ! |
---|
| 1860 | !-- Set flags at x-y-positions without any tunnel surface |
---|
| 1861 | IF ( hv_out - hv_in == 0.0_wp ) THEN |
---|
[2696] | 1862 | topo(nzb+1:nzt+1,j,i) = IBSET( topo(nzb+1:nzt+1,j,i), 0 ) |
---|
[2232] | 1863 | ! |
---|
| 1864 | !-- Set flags at x-y-positions with tunnel surfaces |
---|
| 1865 | ELSE |
---|
| 1866 | DO k = nzb + 1, nzt + 1 |
---|
| 1867 | ! |
---|
| 1868 | !-- Inner tunnel |
---|
| 1869 | IF ( hv_out - hv_in == th ) THEN |
---|
| 1870 | IF ( zw(k) <= hv_out ) THEN |
---|
[2696] | 1871 | topo(k,j,i) = IBCLR( topo(k,j,i), 0 ) |
---|
[2232] | 1872 | ELSE |
---|
[2696] | 1873 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
[2232] | 1874 | ENDIF |
---|
| 1875 | ENDIF |
---|
| 1876 | ! |
---|
| 1877 | !-- Lateral tunnel walls |
---|
| 1878 | IF ( hv_out - hv_in == td ) THEN |
---|
[4648] | 1879 | IF ( zw(k) <= hv_in ) THEN |
---|
[2696] | 1880 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
[4648] | 1881 | ELSEIF ( zw(k) > hv_in .AND. zw(k) <= hv_out ) THEN |
---|
[2696] | 1882 | topo(k,j,i) = IBCLR( topo(k,j,i), 0 ) |
---|
[4648] | 1883 | ELSEIF ( zw(k) > hv_out ) THEN |
---|
[2696] | 1884 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
[2232] | 1885 | ENDIF |
---|
| 1886 | ENDIF |
---|
| 1887 | ENDDO |
---|
| 1888 | ENDIF |
---|
| 1889 | ENDDO |
---|
| 1890 | ENDDO |
---|
| 1891 | |
---|
[2696] | 1892 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2823] | 1893 | ! |
---|
[4648] | 1894 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions |
---|
| 1895 | !-- for topography. |
---|
[2823] | 1896 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1897 | IF ( nys == 0 ) THEN |
---|
[4648] | 1898 | DO i = 1, nbgp |
---|
| 1899 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
[2823] | 1900 | ENDDO |
---|
| 1901 | ENDIF |
---|
| 1902 | IF ( nyn == ny ) THEN |
---|
[4648] | 1903 | DO i = 1, nbgp |
---|
[2823] | 1904 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
| 1905 | ENDDO |
---|
| 1906 | ENDIF |
---|
| 1907 | ENDIF |
---|
| 1908 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1909 | IF ( nxl == 0 ) THEN |
---|
[4648] | 1910 | DO i = 1, nbgp |
---|
| 1911 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
[2823] | 1912 | ENDDO |
---|
| 1913 | ENDIF |
---|
[4648] | 1914 | IF ( nxr == nx ) THEN |
---|
| 1915 | DO i = 1, nbgp |
---|
| 1916 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
[2823] | 1917 | ENDDO |
---|
[4648] | 1918 | ENDIF |
---|
[2823] | 1919 | ENDIF |
---|
[2232] | 1920 | |
---|
[1] | 1921 | CASE ( 'read_from_file' ) |
---|
| 1922 | ! |
---|
[4648] | 1923 | !-- Note, topography information have been already read. |
---|
| 1924 | !-- If required, further process topography, i.e. reference buildings on top of orography and |
---|
| 1925 | !-- set temporary 3D topography array, which is used later to set grid flags. Calling of this |
---|
| 1926 | !-- rouinte is also required in case of ASCII input, even though no distinction between |
---|
| 1927 | !-- terrain- and building height is made in this case. |
---|
[2696] | 1928 | CALL process_topography( topo ) |
---|
[1968] | 1929 | ! |
---|
[2696] | 1930 | !-- Filter holes resolved by only one grid-point |
---|
| 1931 | CALL filter_topography( topo ) |
---|
[1968] | 1932 | ! |
---|
[4648] | 1933 | !-- Exchange ghost-points, as well as add cyclic or Neumann boundary conditions. |
---|
[2696] | 1934 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2232] | 1935 | ! |
---|
[4314] | 1936 | !-- Set lateral boundary conditions for topography on all ghost layers |
---|
[1968] | 1937 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2550] | 1938 | IF ( nys == 0 ) THEN |
---|
[4648] | 1939 | DO i = 1, nbgp |
---|
[2696] | 1940 | topo(:,nys-i,:) = topo(:,nys,:) |
---|
| 1941 | ENDDO |
---|
[2550] | 1942 | ENDIF |
---|
[2696] | 1943 | IF ( nyn == ny ) THEN |
---|
[4648] | 1944 | DO i = 1, nbgp |
---|
[2696] | 1945 | topo(:,nyn+i,:) = topo(:,nyn,:) |
---|
| 1946 | ENDDO |
---|
| 1947 | ENDIF |
---|
[1942] | 1948 | ENDIF |
---|
[1910] | 1949 | |
---|
[1968] | 1950 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2550] | 1951 | IF ( nxl == 0 ) THEN |
---|
[4648] | 1952 | DO i = 1, nbgp |
---|
[2696] | 1953 | topo(:,:,nxl-i) = topo(:,:,nxl) |
---|
[2232] | 1954 | ENDDO |
---|
[2696] | 1955 | ENDIF |
---|
| 1956 | IF ( nxr == nx ) THEN |
---|
[4648] | 1957 | DO i = 1, nbgp |
---|
[2696] | 1958 | topo(:,:,nxr+i) = topo(:,:,nxr) |
---|
| 1959 | ENDDO |
---|
| 1960 | ENDIF |
---|
[2232] | 1961 | ENDIF |
---|
| 1962 | |
---|
[667] | 1963 | |
---|
[1] | 1964 | CASE DEFAULT |
---|
[4648] | 1965 | ! |
---|
| 1966 | !-- The DEFAULT case is reached either if the parameter topography contains a wrong character |
---|
| 1967 | !-- string or if the user has defined a special case in the user interface. There, the |
---|
| 1968 | !-- subroutine user_init_grid checks which of these two conditions applies. |
---|
[2696] | 1969 | CALL user_init_grid( topo ) |
---|
| 1970 | CALL filter_topography( topo ) |
---|
[1] | 1971 | |
---|
| 1972 | END SELECT |
---|
| 1973 | ! |
---|
[4648] | 1974 | !-- Consistency checks and index array initialization are only required for non-flat topography. |
---|
[1] | 1975 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
| 1976 | ! |
---|
[4648] | 1977 | !-- In case of non-flat topography, check whether the convention how to define the topography |
---|
| 1978 | !-- grid has been set correctly, or whether the default is applicable. If this is not possible, |
---|
| 1979 | !-- abort. |
---|
[2232] | 1980 | IF ( TRIM( topography_grid_convention ) == ' ' ) THEN |
---|
[4648] | 1981 | IF ( TRIM( topography ) /= 'closed_channel' .AND. & |
---|
| 1982 | TRIM( topography ) /= 'single_building' .AND. & |
---|
| 1983 | TRIM( topography ) /= 'single_street_canyon' .AND. & |
---|
| 1984 | TRIM( topography ) /= 'tunnel' .AND. & |
---|
[2232] | 1985 | TRIM( topography ) /= 'read_from_file') THEN |
---|
[4648] | 1986 | !-- The default value is not applicable here, because it is only valid for the four |
---|
| 1987 | !-- standard cases 'single_building', 'single_street_canyon', 'tunnel' and 'read_from_file' |
---|
[2232] | 1988 | !-- defined in init_grid. |
---|
[4648] | 1989 | WRITE( message_string, * ) 'The value for "topography_grid_convention" ', & |
---|
| 1990 | 'is not set. Its default value is & only valid for ', & |
---|
| 1991 | '"topography" = ''single_building'', ''tunnel'' ', & |
---|
| 1992 | '''single_street_canyon'', ''closed_channel'' & or ', & |
---|
| 1993 | '''read_from_file''.', & |
---|
| 1994 | '& Choose ''cell_edge'' or ''cell_center''.' |
---|
[2232] | 1995 | CALL message( 'init_grid', 'PA0239', 1, 2, 0, 6, 0 ) |
---|
| 1996 | ELSE |
---|
| 1997 | !-- The default value is applicable here. |
---|
| 1998 | !-- Set convention according to topography. |
---|
[4648] | 1999 | IF ( TRIM( topography ) == 'single_building' .OR. & |
---|
[2232] | 2000 | TRIM( topography ) == 'single_street_canyon' ) THEN |
---|
| 2001 | topography_grid_convention = 'cell_edge' |
---|
[4648] | 2002 | ELSEIF ( TRIM( topography ) == 'read_from_file' .OR. & |
---|
[2232] | 2003 | TRIM( topography ) == 'tunnel') THEN |
---|
| 2004 | topography_grid_convention = 'cell_center' |
---|
| 2005 | ENDIF |
---|
| 2006 | ENDIF |
---|
[4648] | 2007 | ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND. & |
---|
[2232] | 2008 | TRIM( topography_grid_convention ) /= 'cell_center' ) THEN |
---|
[4648] | 2009 | WRITE( message_string, * ) 'The value for "topography_grid_convention" is ', & |
---|
| 2010 | 'not recognized.& Choose ''cell_edge'' or ''cell_center''.' |
---|
[2232] | 2011 | CALL message( 'init_grid', 'PA0240', 1, 2, 0, 6, 0 ) |
---|
| 2012 | ENDIF |
---|
[1] | 2013 | |
---|
[2169] | 2014 | |
---|
[217] | 2015 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
[4648] | 2016 | ! |
---|
| 2017 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
| 2018 | !-- describes the actual total size of topography which is defined at the |
---|
| 2019 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
[217] | 2020 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
| 2021 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
[4648] | 2022 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
| 2023 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
| 2024 | !-- to form the basis for nzb_s_inner. |
---|
[1968] | 2025 | !-- Note, the reverse memory access (i-j instead of j-i) is absolutely |
---|
| 2026 | !-- required at this point. |
---|
| 2027 | DO j = nys+1, nyn+1 |
---|
| 2028 | DO i = nxl-1, nxr |
---|
[2232] | 2029 | DO k = nzb, nzt+1 |
---|
[4648] | 2030 | IF ( BTEST( topo(k,j,i), 0 ) .OR. BTEST( topo(k,j,i+1), 0 ) ) & |
---|
[2696] | 2031 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
[2232] | 2032 | ENDDO |
---|
| 2033 | ENDDO |
---|
[4648] | 2034 | ENDDO |
---|
[2696] | 2035 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2232] | 2036 | |
---|
| 2037 | DO i = nxl, nxr+1 |
---|
| 2038 | DO j = nys-1, nyn |
---|
| 2039 | DO k = nzb, nzt+1 |
---|
[4648] | 2040 | IF ( BTEST( topo(k,j,i), 0 ) .OR. BTEST( topo(k,j+1,i), 0 ) ) & |
---|
[2696] | 2041 | topo(k,j,i) = IBSET( topo(k,j,i), 0 ) |
---|
[2232] | 2042 | ENDDO |
---|
| 2043 | ENDDO |
---|
[4648] | 2044 | ENDDO |
---|
[2696] | 2045 | CALL exchange_horiz_int( topo, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[4648] | 2046 | |
---|
[217] | 2047 | ENDIF |
---|
[2696] | 2048 | ENDIF |
---|
[2232] | 2049 | |
---|
[1] | 2050 | |
---|
[2696] | 2051 | END SUBROUTINE init_topo |
---|
[1] | 2052 | |
---|
[2696] | 2053 | SUBROUTINE set_topo_flags(topo) |
---|
[1] | 2054 | |
---|
[4648] | 2055 | USE control_parameters, & |
---|
| 2056 | ONLY: bc_lr_cyc, bc_ns_cyc, constant_flux_layer, scalar_advec, topography, & |
---|
| 2057 | use_surface_fluxes, use_top_fluxes |
---|
[1] | 2058 | |
---|
[4648] | 2059 | USE exchange_horiz_mod, & |
---|
[4457] | 2060 | ONLY: exchange_horiz_int |
---|
| 2061 | |
---|
[4648] | 2062 | USE indices, & |
---|
| 2063 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, ny, nyn, nyng, nys, nysg, nzb, nzt, topo_top_ind, & |
---|
| 2064 | wall_flags_static_0, wall_flags_total_0 |
---|
[1] | 2065 | |
---|
[2696] | 2066 | USE kinds |
---|
[1] | 2067 | |
---|
[2696] | 2068 | IMPLICIT NONE |
---|
[1804] | 2069 | |
---|
[2696] | 2070 | INTEGER(iwp) :: i !< index variable along x |
---|
[4168] | 2071 | INTEGER(iwp) :: ibit !< integer bit position of topgraphy masking array |
---|
[2696] | 2072 | INTEGER(iwp) :: j !< index variable along y |
---|
| 2073 | INTEGER(iwp) :: k !< index variable along z |
---|
[1] | 2074 | |
---|
[4648] | 2075 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: topo !< input array for 3D topography and dummy array for setting |
---|
| 2076 | !< "outer"-flags |
---|
[2232] | 2077 | |
---|
[4329] | 2078 | ALLOCATE( wall_flags_static_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 2079 | wall_flags_static_0 = 0 |
---|
[2232] | 2080 | ! |
---|
[2696] | 2081 | !-- Set-up topography flags. First, set flags only for s, u, v and w-grid. |
---|
[4648] | 2082 | !-- Further special flags will be set in following loops. |
---|
[2232] | 2083 | DO i = nxl, nxr |
---|
| 2084 | DO j = nys, nyn |
---|
| 2085 | DO k = nzb, nzt+1 |
---|
| 2086 | ! |
---|
| 2087 | !-- scalar grid |
---|
[4648] | 2088 | IF ( BTEST( topo(k,j,i), 0 ) ) & |
---|
[4329] | 2089 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 0 ) |
---|
[2232] | 2090 | ! |
---|
[2696] | 2091 | !-- u grid |
---|
[4648] | 2092 | IF ( BTEST( topo(k,j,i), 0 ) .AND. BTEST( topo(k,j,i-1), 0 ) ) & |
---|
[4329] | 2093 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 1 ) |
---|
[2696] | 2094 | ! |
---|
[2232] | 2095 | !-- v grid |
---|
[4648] | 2096 | IF ( BTEST( topo(k,j,i), 0 ) .AND. BTEST( topo(k,j-1,i), 0 ) ) & |
---|
[4329] | 2097 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 2 ) |
---|
[2696] | 2098 | |
---|
[2232] | 2099 | ENDDO |
---|
[1] | 2100 | |
---|
[2232] | 2101 | DO k = nzb, nzt |
---|
[1] | 2102 | ! |
---|
[2232] | 2103 | !-- w grid |
---|
[4648] | 2104 | IF ( BTEST( topo(k,j,i), 0 ) .AND. BTEST( topo(k+1,j,i), 0 ) ) & |
---|
[4329] | 2105 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 3 ) |
---|
[2232] | 2106 | ENDDO |
---|
[4648] | 2107 | |
---|
| 2108 | IF ( topography /= 'closed_channel' ) THEN |
---|
[4340] | 2109 | wall_flags_static_0(nzt+1,j,i) = IBSET( wall_flags_static_0(nzt+1,j,i), 3 ) |
---|
| 2110 | ENDIF |
---|
[2232] | 2111 | |
---|
| 2112 | ENDDO |
---|
| 2113 | ENDDO |
---|
[2696] | 2114 | |
---|
[4329] | 2115 | CALL exchange_horiz_int( wall_flags_static_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[4346] | 2116 | |
---|
[1] | 2117 | ! |
---|
[4648] | 2118 | !-- Set outer array for scalars to mask near-surface grid points. Note, on basis of flag 24 futher |
---|
| 2119 | !-- flags will be derived which are used to control production of subgrid TKE production near walls. |
---|
| 2120 | |
---|
[4346] | 2121 | ALLOCATE( wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 2122 | wall_flags_total_0 = 0 |
---|
[4648] | 2123 | |
---|
[2696] | 2124 | DO i = nxl, nxr |
---|
| 2125 | DO j = nys, nyn |
---|
[2232] | 2126 | DO k = nzb, nzt+1 |
---|
[4346] | 2127 | wall_flags_total_0(k,j,i) = IOR( wall_flags_total_0(k,j,i), wall_flags_static_0(k,j,i) ) |
---|
[2232] | 2128 | ENDDO |
---|
| 2129 | ENDDO |
---|
| 2130 | ENDDO |
---|
[4648] | 2131 | |
---|
[4346] | 2132 | CALL exchange_horiz_int( wall_flags_total_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[4648] | 2133 | |
---|
[4346] | 2134 | DO i = nxl, nxr |
---|
| 2135 | DO j = nys, nyn |
---|
| 2136 | DO k = nzb, nzt+1 |
---|
[4648] | 2137 | IF ( BTEST( wall_flags_total_0(k,j-1,i), 0 ) .AND. & |
---|
| 2138 | BTEST( wall_flags_total_0(k,j+1,i), 0 ) .AND. & |
---|
| 2139 | BTEST( wall_flags_total_0(k,j,i-1), 0 ) .AND. & |
---|
| 2140 | BTEST( wall_flags_total_0(k,j,i+1), 0 ) .AND. & |
---|
| 2141 | BTEST( wall_flags_total_0(k,j-1,i-1), 0 ) .AND. & |
---|
| 2142 | BTEST( wall_flags_total_0(k,j+1,i-1), 0 ) .AND. & |
---|
| 2143 | BTEST( wall_flags_total_0(k,j-1,i+1), 0 ) .AND. & |
---|
| 2144 | BTEST( wall_flags_total_0(k,j+1,i+1), 0 ) ) & |
---|
[4346] | 2145 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 24 ) |
---|
| 2146 | ENDDO |
---|
| 2147 | ENDDO |
---|
| 2148 | ENDDO |
---|
[1] | 2149 | ! |
---|
[2232] | 2150 | !-- Set further special flags |
---|
| 2151 | DO i = nxl, nxr |
---|
| 2152 | DO j = nys, nyn |
---|
| 2153 | DO k = nzb, nzt+1 |
---|
[1] | 2154 | ! |
---|
[2232] | 2155 | !-- scalar grid, former nzb_diff_s_inner. |
---|
[4648] | 2156 | !-- Note, use this flag also to mask topography in diffusion_u and diffusion_v along the |
---|
| 2157 | !-- vertical direction. In case of use_surface_fluxes, fluxes are calculated via MOST, |
---|
| 2158 | !-- else, simple gradient approach is applied. Please note, in case of u- and v-diffuison, |
---|
| 2159 | !-- a small error is made at edges (on the east side for u, at the north side for v), since |
---|
| 2160 | !-- topography on scalar grid point is used instead of topography on u/v-grid. As number of |
---|
| 2161 | !-- topography grid points on uv-grid is different than s-grid, different number of surface |
---|
| 2162 | !-- elements would be required. In order to avoid this, treat edges (u(k,j,i+1)) simply by |
---|
| 2163 | !-- a gradient approach, i.e. these points are not masked within diffusion_u. Tests had |
---|
| 2164 | !-- shown that the effect on the flow is negligible. |
---|
[2232] | 2165 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[4648] | 2166 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) ) & |
---|
[4346] | 2167 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 8 ) |
---|
[2232] | 2168 | ELSE |
---|
[4346] | 2169 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 8 ) |
---|
[2232] | 2170 | ENDIF |
---|
[1] | 2171 | |
---|
[2232] | 2172 | ENDDO |
---|
| 2173 | ! |
---|
[4648] | 2174 | !-- Special flag to control vertical diffusion at model top - former nzt_diff |
---|
[4346] | 2175 | wall_flags_total_0(:,j,i) = IBSET( wall_flags_total_0(:,j,i), 9 ) |
---|
[2232] | 2176 | IF ( use_top_fluxes ) & |
---|
[4346] | 2177 | wall_flags_total_0(nzt+1,j,i) = IBCLR( wall_flags_total_0(nzt+1,j,i), 9 ) |
---|
[1] | 2178 | |
---|
[2696] | 2179 | |
---|
[2232] | 2180 | DO k = nzb+1, nzt |
---|
| 2181 | ! |
---|
[4648] | 2182 | !-- Special flag on u grid, former nzb_u_inner + 1, required for disturb_field and |
---|
| 2183 | !-- initialization. Do not disturb directly at topography, as well as initialize u with |
---|
| 2184 | !-- zero one grid point outside of topography. |
---|
| 2185 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 1 ) .AND. & |
---|
| 2186 | BTEST( wall_flags_total_0(k,j,i), 1 ) .AND. & |
---|
| 2187 | BTEST( wall_flags_total_0(k+1,j,i), 1 ) ) & |
---|
[4346] | 2188 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 20 ) |
---|
[2232] | 2189 | ! |
---|
[4648] | 2190 | !-- Special flag on v grid, former nzb_v_inner + 1, required for disturb_field and |
---|
| 2191 | !-- initialization. Do not disturb directly at topography, as well as initialize v with |
---|
| 2192 | !-- zero one grid point outside of topography. |
---|
| 2193 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 2 ) .AND. & |
---|
| 2194 | BTEST( wall_flags_total_0(k,j,i), 2 ) .AND. & |
---|
| 2195 | BTEST( wall_flags_total_0(k+1,j,i), 2 ) ) & |
---|
[4346] | 2196 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 21 ) |
---|
[2232] | 2197 | ! |
---|
[4648] | 2198 | !-- Special flag on scalar grid, former nzb_s_inner+1. Used for lpm_sgs_tke |
---|
| 2199 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) .AND. & |
---|
| 2200 | BTEST( wall_flags_total_0(k-1,j,i), 0 ) .AND. & |
---|
| 2201 | BTEST( wall_flags_total_0(k+1,j,i), 0 ) ) & |
---|
[4346] | 2202 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 25 ) |
---|
[2232] | 2203 | ! |
---|
[4648] | 2204 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in in production_e |
---|
[2232] | 2205 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[4648] | 2206 | IF ( BTEST( wall_flags_total_0(k,j,i), 24 ) .AND. & |
---|
| 2207 | BTEST( wall_flags_total_0(k-1,j,i), 24 ) .AND. & |
---|
| 2208 | BTEST( wall_flags_total_0(k+1,j,i), 0 ) ) & |
---|
[4346] | 2209 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 ) |
---|
[2232] | 2210 | ELSE |
---|
[4648] | 2211 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) ) & |
---|
[4346] | 2212 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 29 ) |
---|
[1] | 2213 | ENDIF |
---|
[2232] | 2214 | ! |
---|
[4648] | 2215 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in |
---|
[2232] | 2216 | !-- in production_e |
---|
| 2217 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[4648] | 2218 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) .AND. & |
---|
| 2219 | BTEST( wall_flags_total_0(k-1,j,i), 0 ) .AND. & |
---|
| 2220 | BTEST( wall_flags_total_0(k+1,j,i), 0 ) ) & |
---|
[4346] | 2221 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 30 ) |
---|
[2232] | 2222 | ELSE |
---|
[4648] | 2223 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) ) & |
---|
[4346] | 2224 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 30 ) |
---|
[2232] | 2225 | ENDIF |
---|
| 2226 | ENDDO |
---|
| 2227 | ! |
---|
| 2228 | !-- Flags indicating downward facing walls |
---|
[4340] | 2229 | DO k = nzb+1, nzt+1 |
---|
[2232] | 2230 | ! |
---|
| 2231 | !-- Scalar grid |
---|
[4648] | 2232 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 0 ) .AND. & |
---|
| 2233 | .NOT. BTEST( wall_flags_total_0(k,j,i), 0 ) ) & |
---|
| 2234 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 13 ) |
---|
[2232] | 2235 | ! |
---|
| 2236 | !-- Downward facing wall on u grid |
---|
[4648] | 2237 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 1 ) .AND. & |
---|
| 2238 | .NOT. BTEST( wall_flags_total_0(k,j,i), 1 ) ) & |
---|
[4346] | 2239 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 15 ) |
---|
[2232] | 2240 | ! |
---|
| 2241 | !-- Downward facing wall on v grid |
---|
[4648] | 2242 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 2 ) .AND. & |
---|
| 2243 | .NOT. BTEST( wall_flags_total_0(k,j,i), 2 ) ) & |
---|
[4346] | 2244 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 17 ) |
---|
[2232] | 2245 | ! |
---|
| 2246 | !-- Downward facing wall on w grid |
---|
[4648] | 2247 | IF ( BTEST( wall_flags_total_0(k-1,j,i), 3 ) .AND. & |
---|
| 2248 | .NOT. BTEST( wall_flags_total_0(k,j,i), 3 ) ) & |
---|
[4346] | 2249 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 19 ) |
---|
[2232] | 2250 | ENDDO |
---|
| 2251 | ! |
---|
| 2252 | !-- Flags indicating upward facing walls |
---|
| 2253 | DO k = nzb, nzt |
---|
| 2254 | ! |
---|
| 2255 | !-- Upward facing wall on scalar grid |
---|
[4648] | 2256 | IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 0 ) .AND. & |
---|
| 2257 | BTEST( wall_flags_total_0(k+1,j,i), 0 ) ) & |
---|
[4346] | 2258 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 12 ) |
---|
[2232] | 2259 | ! |
---|
| 2260 | !-- Upward facing wall on u grid |
---|
[4648] | 2261 | IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 1 ) .AND. & |
---|
| 2262 | BTEST( wall_flags_total_0(k+1,j,i), 1 ) ) & |
---|
[4346] | 2263 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 14 ) |
---|
[1] | 2264 | |
---|
[4648] | 2265 | ! |
---|
[2232] | 2266 | !-- Upward facing wall on v grid |
---|
[4648] | 2267 | IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 2 ) .AND. & |
---|
| 2268 | BTEST( wall_flags_total_0(k+1,j,i), 2 ) ) & |
---|
[4346] | 2269 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 16 ) |
---|
[4648] | 2270 | |
---|
[2232] | 2271 | ! |
---|
| 2272 | !-- Upward facing wall on w grid |
---|
[4648] | 2273 | IF ( .NOT. BTEST( wall_flags_total_0(k,j,i), 3 ) .AND. & |
---|
| 2274 | BTEST( wall_flags_total_0(k+1,j,i), 3 ) ) & |
---|
[4346] | 2275 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 18 ) |
---|
[2232] | 2276 | ! |
---|
| 2277 | !-- Special flag on scalar grid, former nzb_s_inner |
---|
[4648] | 2278 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) .OR. & |
---|
| 2279 | BTEST( wall_flags_total_0(k,j,i), 12 ) .OR. & |
---|
| 2280 | BTEST( wall_flags_total_0(k,j,i), 13 ) ) & |
---|
[4346] | 2281 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 22 ) |
---|
[2232] | 2282 | ! |
---|
[4648] | 2283 | !-- Special flag on scalar grid, nzb_diff_s_inner - 1, required for |
---|
[2232] | 2284 | !-- flow_statistics |
---|
| 2285 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[4648] | 2286 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) .AND. & |
---|
| 2287 | BTEST( wall_flags_total_0(k+1,j,i), 0 ) ) & |
---|
[4346] | 2288 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 23 ) |
---|
[2232] | 2289 | ELSE |
---|
[4648] | 2290 | IF ( BTEST( wall_flags_total_0(k,j,i), 22 ) ) & |
---|
[4346] | 2291 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 23 ) |
---|
[1] | 2292 | ENDIF |
---|
| 2293 | |
---|
[4648] | 2294 | |
---|
[2232] | 2295 | ENDDO |
---|
[4346] | 2296 | wall_flags_total_0(nzt+1,j,i) = IBSET( wall_flags_total_0(nzt+1,j,i), 22 ) |
---|
| 2297 | wall_flags_total_0(nzt+1,j,i) = IBSET( wall_flags_total_0(nzt+1,j,i), 23 ) |
---|
[4109] | 2298 | ! |
---|
[4648] | 2299 | !-- Set flags indicating that topography is close by in horizontal direction, i.e. flags that |
---|
| 2300 | !-- infold the topography. These will be used to set advection flags for passive scalars, |
---|
| 2301 | !-- where due to large gradients near buildings stationary numerical oscillations can produce |
---|
| 2302 | !-- unrealistically high concentrations. This is only necessary if WS-scheme is applied for |
---|
| 2303 | !-- scalar advection. Note, these flags will be only used for passive scalars such as chemical |
---|
| 2304 | !-- species or aerosols. |
---|
[4109] | 2305 | IF ( scalar_advec == 'ws-scheme' ) THEN |
---|
| 2306 | DO k = nzb, nzt |
---|
[4648] | 2307 | IF ( BTEST( wall_flags_total_0(k,j,i), 0 ) .AND. ( & |
---|
| 2308 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-1), 0 ) ) .OR. & |
---|
| 2309 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-2), 0 ) ) .OR. & |
---|
| 2310 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i-3), 0 ) ) .OR. & |
---|
| 2311 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+1), 0 ) ) .OR. & |
---|
| 2312 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+2), 0 ) ) .OR. & |
---|
| 2313 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3:j+3,i+3), 0 ) ) .OR. & |
---|
| 2314 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-1,i-3:i+3), 0 ) ) .OR. & |
---|
| 2315 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-2,i-3:i+3), 0 ) ) .OR. & |
---|
| 2316 | ANY( .NOT. BTEST( wall_flags_total_0(k,j-3,i-3:i+3), 0 ) ) .OR. & |
---|
| 2317 | ANY( .NOT. BTEST( wall_flags_total_0(k,j+1,i-3:i+3), 0 ) ) .OR. & |
---|
| 2318 | ANY( .NOT. BTEST( wall_flags_total_0(k,j+2,i-3:i+3), 0 ) ) .OR. & |
---|
| 2319 | ANY( .NOT. BTEST( wall_flags_total_0(k,j+3,i-3:i+3), 0 ) ) & |
---|
| 2320 | ) & |
---|
| 2321 | ) & |
---|
[4346] | 2322 | wall_flags_total_0(k,j,i) = IBSET( wall_flags_total_0(k,j,i), 31 ) |
---|
[4109] | 2323 | ENDDO |
---|
| 2324 | ENDIF |
---|
[2232] | 2325 | ENDDO |
---|
| 2326 | ENDDO |
---|
| 2327 | ! |
---|
[2696] | 2328 | !-- Finally, set identification flags indicating natural terrain or buildings. |
---|
[4648] | 2329 | !-- Natural terrain grid points. Information on the type of the surface is stored in bit 1 of |
---|
| 2330 | !-- 3D Integer array topo. However, this bit is only set when topography is read from file. In order |
---|
| 2331 | !-- to run the land-surface model also without topography information, set bit 1 explicitely in this |
---|
| 2332 | !-- case. |
---|
| 2333 | !-- |
---|
[4294] | 2334 | !-- Natural terrain grid points |
---|
| 2335 | !-- If no topography is initialized, the land-surface is at k = nzb. |
---|
| 2336 | IF ( TRIM( topography ) /= 'read_from_file' ) THEN |
---|
[4329] | 2337 | wall_flags_static_0(nzb,:,:) = IBSET( wall_flags_static_0(nzb,:,:), 5 ) |
---|
[4294] | 2338 | ELSE |
---|
| 2339 | DO i = nxl, nxr |
---|
| 2340 | DO j = nys, nyn |
---|
| 2341 | DO k = nzb, nzt+1 |
---|
[4648] | 2342 | ! |
---|
[4294] | 2343 | !-- Natural terrain grid point |
---|
[4648] | 2344 | IF ( BTEST( topo(k,j,i), 1 ) ) & |
---|
[4329] | 2345 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 5 ) |
---|
[2696] | 2346 | ENDDO |
---|
| 2347 | ENDDO |
---|
[4294] | 2348 | ENDDO |
---|
[2696] | 2349 | ENDIF |
---|
| 2350 | ! |
---|
| 2351 | !-- Building grid points. |
---|
[4294] | 2352 | DO i = nxl, nxr |
---|
| 2353 | DO j = nys, nyn |
---|
| 2354 | DO k = nzb, nzt+1 |
---|
[4648] | 2355 | IF ( BTEST( topo(k,j,i), 2 ) ) & |
---|
[4329] | 2356 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 6 ) |
---|
[2696] | 2357 | ENDDO |
---|
| 2358 | ENDDO |
---|
[4294] | 2359 | ENDDO |
---|
[2696] | 2360 | ! |
---|
[4314] | 2361 | !-- Set flag 4, indicating new topography grid points due to filtering. |
---|
| 2362 | DO i = nxl, nxr |
---|
| 2363 | DO j = nys, nyn |
---|
| 2364 | DO k = nzb, nzt+1 |
---|
[4648] | 2365 | IF ( BTEST( topo(k,j,i), 4 ) ) & |
---|
[4329] | 2366 | wall_flags_static_0(k,j,i) = IBSET( wall_flags_static_0(k,j,i), 4 ) |
---|
[4314] | 2367 | ENDDO |
---|
| 2368 | ENDDO |
---|
| 2369 | ENDDO |
---|
[4648] | 2370 | |
---|
[4346] | 2371 | CALL exchange_horiz_int( wall_flags_static_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[4648] | 2372 | |
---|
[4346] | 2373 | DO i = nxl, nxr |
---|
| 2374 | DO j = nys, nyn |
---|
| 2375 | DO k = nzb, nzt+1 |
---|
| 2376 | wall_flags_total_0(k,j,i) = IOR( wall_flags_total_0(k,j,i), wall_flags_static_0(k,j,i) ) |
---|
| 2377 | ENDDO |
---|
| 2378 | ENDDO |
---|
| 2379 | ENDDO |
---|
[4314] | 2380 | ! |
---|
[2232] | 2381 | !-- Exchange ghost points for wall flags |
---|
[4346] | 2382 | CALL exchange_horiz_int( wall_flags_total_0, nys, nyn, nxl, nxr, nzt, nbgp ) |
---|
[2232] | 2383 | ! |
---|
[4648] | 2384 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann boundary conditions for |
---|
| 2385 | !-- topography. |
---|
[2232] | 2386 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2696] | 2387 | IF ( nys == 0 ) THEN |
---|
[4648] | 2388 | DO i = 1, nbgp |
---|
[4346] | 2389 | wall_flags_total_0(:,nys-i,:) = wall_flags_total_0(:,nys,:) |
---|
[2696] | 2390 | ENDDO |
---|
| 2391 | ENDIF |
---|
| 2392 | IF ( nyn == ny ) THEN |
---|
[4648] | 2393 | DO i = 1, nbgp |
---|
[4346] | 2394 | wall_flags_total_0(:,nyn+i,:) = wall_flags_total_0(:,nyn,:) |
---|
[2696] | 2395 | ENDDO |
---|
| 2396 | ENDIF |
---|
[2232] | 2397 | ENDIF |
---|
| 2398 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2696] | 2399 | IF ( nxl == 0 ) THEN |
---|
[4648] | 2400 | DO i = 1, nbgp |
---|
[4346] | 2401 | wall_flags_total_0(:,:,nxl-i) = wall_flags_total_0(:,:,nxl) |
---|
[2696] | 2402 | ENDDO |
---|
[2232] | 2403 | ENDIF |
---|
[4648] | 2404 | IF ( nxr == nx ) THEN |
---|
| 2405 | DO i = 1, nbgp |
---|
| 2406 | wall_flags_total_0(:,:,nxr+i) = wall_flags_total_0(:,:,nxr) |
---|
[2232] | 2407 | ENDDO |
---|
[4648] | 2408 | ENDIF |
---|
[2232] | 2409 | ENDIF |
---|
[4168] | 2410 | ! |
---|
[4648] | 2411 | !-- Pre-calculate topography top indices (former get_topography_top_index |
---|
[4168] | 2412 | !-- function) |
---|
[4653] | 2413 | ALLOCATE( topo_top_ind(nysg:nyng,nxlg:nxrg,0:5) ) |
---|
[4168] | 2414 | ! |
---|
| 2415 | !-- Uppermost topography index on scalar grid |
---|
| 2416 | ibit = 12 |
---|
[4648] | 2417 | topo_top_ind(:,:,0) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) & |
---|
| 2418 | - 1 |
---|
[4168] | 2419 | ! |
---|
[4648] | 2420 | !-- Uppermost topography index on u grid |
---|
[4168] | 2421 | ibit = 14 |
---|
[4648] | 2422 | topo_top_ind(:,:,1) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) & |
---|
| 2423 | - 1 |
---|
[4168] | 2424 | ! |
---|
[4648] | 2425 | !-- Uppermost topography index on v grid |
---|
[4168] | 2426 | ibit = 16 |
---|
[4648] | 2427 | topo_top_ind(:,:,2) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) & |
---|
| 2428 | - 1 |
---|
[4168] | 2429 | ! |
---|
| 2430 | !-- Uppermost topography index on w grid |
---|
| 2431 | ibit = 18 |
---|
[4648] | 2432 | topo_top_ind(:,:,3) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) & |
---|
| 2433 | - 1 |
---|
[4168] | 2434 | ! |
---|
| 2435 | !-- Uppermost topography index on scalar outer grid |
---|
| 2436 | ibit = 24 |
---|
[4648] | 2437 | topo_top_ind(:,:,4) = MAXLOC( MERGE( 1, 0, BTEST( wall_flags_total_0(:,:,:), ibit ) ), DIM=1 ) & |
---|
| 2438 | - 1 |
---|
[4653] | 2439 | ! |
---|
| 2440 | !-- Uppermost topography index including full-3D geometry |
---|
| 2441 | ibit = 12 |
---|
| 2442 | DO k = nzb, nzt+1 |
---|
| 2443 | WHERE( BTEST( wall_flags_total_0(k,:,:), ibit ) ) topo_top_ind(:,:,5) = k |
---|
| 2444 | ENDDO |
---|
[4414] | 2445 | |
---|
[2696] | 2446 | END SUBROUTINE set_topo_flags |
---|