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