[1682] | 1 | !> @file init_grid.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[1036] | 3 | ! This file is part of PALM. |
---|
| 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 | ! |
---|
[2101] | 17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[254] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[2233] | 22 | ! |
---|
| 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: init_grid.f90 2274 2017-06-09 13:27:48Z schwenkel $ |
---|
[2274] | 27 | ! Changed error messages |
---|
| 28 | ! |
---|
| 29 | ! 2233 2017-05-30 18:08:54Z suehring |
---|
[2233] | 30 | ! |
---|
| 31 | ! 2232 2017-05-30 17:47:52Z suehring |
---|
[2232] | 32 | ! - Adjustments according to new topography representation |
---|
| 33 | ! - Bugfix: Move determination of nzb_max behind topography modification in |
---|
| 34 | ! cell-edge case |
---|
| 35 | ! - Get rid off global arrays required for topography output |
---|
| 36 | ! - Enable topography input via netcdf |
---|
| 37 | ! - Generic tunnel set-up added |
---|
[1969] | 38 | ! |
---|
[2201] | 39 | ! 2200 2017-04-11 11:37:51Z suehring |
---|
| 40 | ! monotonic_adjustment removed |
---|
| 41 | ! |
---|
[2170] | 42 | ! 2169 2017-03-06 18:16:35Z suehring |
---|
| 43 | ! Bugfix, move setting for topography grid convention to init_grid, else, if no |
---|
| 44 | ! value is set, the simulation may abort in case of restarts |
---|
| 45 | ! |
---|
[2129] | 46 | ! 2128 2017-01-23 15:00:03Z suehring |
---|
| 47 | ! Bugfix in setting topography from file in case of ocean simulations |
---|
| 48 | ! |
---|
[2089] | 49 | ! 2088 2016-12-19 16:30:25Z suehring |
---|
| 50 | ! Bugfix in generic topography in case of ocean simulations |
---|
| 51 | ! |
---|
[2038] | 52 | ! 2037 2016-10-26 11:15:40Z knoop |
---|
| 53 | ! Anelastic approximation implemented |
---|
| 54 | ! |
---|
[2022] | 55 | ! 2021 2016-10-07 14:08:57Z suehring |
---|
| 56 | ! Bugfix: setting Neumann boundary conditions for topography required for |
---|
| 57 | ! topography flags in multigrid_noopt solver |
---|
| 58 | ! |
---|
[2001] | 59 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 60 | ! Forced header and separation lines into 80 columns |
---|
| 61 | ! |
---|
[1995] | 62 | ! 1994 2016-08-15 09:52:21Z suehring |
---|
| 63 | ! Bugfix in definition of generic topography |
---|
| 64 | ! |
---|
[1983] | 65 | ! 1982 2016-08-01 11:04:48Z suehring |
---|
| 66 | ! Bugfix concering consistency check for topography |
---|
| 67 | ! |
---|
[1969] | 68 | ! 1968 2016-07-18 12:01:49Z suehring |
---|
[1968] | 69 | ! Changed: PE-wise reading of topography file in order to avoid global definition |
---|
| 70 | ! of arrays nzb_local and nzb_tmp. Thereby, topography definition for single |
---|
| 71 | ! buildings and street canyons has changed, as well as flag setting for |
---|
| 72 | ! multigrid scheme. |
---|
| 73 | ! |
---|
| 74 | ! Bugfix in checking l_grid anisotropy. |
---|
| 75 | ! Simplify initial computation of lwall and vertical_influence, i.e. remove |
---|
| 76 | ! nzb_s_inner as it is still zero at this point. |
---|
[1932] | 77 | ! |
---|
[1943] | 78 | ! 1942 2016-06-14 12:18:18Z suehring |
---|
| 79 | ! Topography filter implemented to fill holes resolved by only one grid point. |
---|
| 80 | ! Initialization of flags for ws-scheme moved to advec_ws. |
---|
| 81 | ! |
---|
[1932] | 82 | ! 1931 2016-06-10 12:06:59Z suehring |
---|
| 83 | ! Rename multigrid into multigrid_noopt and multigrid_fast into multigrid |
---|
| 84 | ! |
---|
[1911] | 85 | ! 1910 2016-05-26 06:49:46Z raasch |
---|
| 86 | ! Bugfix: if topography is read from file, Neumann conditions are used for the |
---|
| 87 | ! nzb_local array (instead of cyclic conditions) in case that non-cyclic |
---|
| 88 | ! boundary conditions are switched on for the run |
---|
| 89 | ! |
---|
[1903] | 90 | ! 1902 2016-05-09 11:18:56Z suehring |
---|
[1910] | 91 | ! Set topography flags for multigrid solver only (not for multigrid_fast) |
---|
[1903] | 92 | ! |
---|
[1887] | 93 | ! 1886 2016-04-21 11:20:47Z suehring |
---|
| 94 | ! Bugfix: setting advection flags near walls |
---|
| 95 | ! reformulated index values for nzb_v_inner |
---|
| 96 | ! variable discriptions added in declaration block |
---|
| 97 | ! |
---|
[1846] | 98 | ! 1845 2016-04-08 08:29:13Z raasch |
---|
| 99 | ! nzb_2d removed |
---|
| 100 | ! |
---|
[1805] | 101 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
| 102 | ! Removed code for parameter file check (__check) |
---|
| 103 | ! |
---|
[1780] | 104 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 105 | ! coupling_char is trimmed at every place it occurs, because it can have |
---|
| 106 | ! different length now |
---|
| 107 | ! |
---|
[1763] | 108 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 109 | ! Introduction of nested domain feature |
---|
| 110 | ! |
---|
[1744] | 111 | ! 1743 2016-01-13 10:23:51Z raasch |
---|
| 112 | ! Bugfix for calculation of nzb_s_outer and nzb_u_outer at north boundary of |
---|
| 113 | ! total domain |
---|
| 114 | ! |
---|
[1692] | 115 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
| 116 | ! Renamed prandtl_layer to constant_flux_layer. |
---|
| 117 | ! |
---|
[1683] | 118 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 119 | ! Code annotations made doxygen readable |
---|
| 120 | ! |
---|
[1678] | 121 | ! 1677 2015-10-02 13:25:23Z boeske |
---|
| 122 | ! Bugfix: Ghost points are included in wall_flags_0 and wall_flags_00 |
---|
| 123 | ! |
---|
[1676] | 124 | ! 1675 2015-10-02 08:28:59Z gronemeier |
---|
| 125 | ! Bugfix: Definition of topography grid levels |
---|
| 126 | ! |
---|
[1662] | 127 | ! 1660 2015-09-21 08:15:16Z gronemeier |
---|
| 128 | ! Bugfix: Definition of topography grid levels if vertical grid stretching |
---|
| 129 | ! starts below the maximum topography height. |
---|
| 130 | ! |
---|
[1581] | 131 | ! 1580 2015-04-10 13:43:49Z suehring |
---|
| 132 | ! Bugfix: setting flags for 5th order scheme near buildings |
---|
| 133 | ! |
---|
[1576] | 134 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
| 135 | ! adjustments for psolver-queries |
---|
| 136 | ! |
---|
[1558] | 137 | ! 1557 2015-03-05 16:43:04Z suehring |
---|
| 138 | ! Adjustment for monotoinic limiter |
---|
| 139 | ! |
---|
[1419] | 140 | ! 1418 2014-06-06 13:05:08Z fricke |
---|
| 141 | ! Bugfix: Change if-condition for stretched grid in the ocean, with the old |
---|
| 142 | ! condition and a negative value for dz_stretch_level the condition |
---|
| 143 | ! was always true for the whole model domain |
---|
| 144 | ! |
---|
[1410] | 145 | ! 1409 2014-05-23 12:11:32Z suehring |
---|
| 146 | ! Bugfix: set wall_flags_0 at inflow and outflow boundary also for i <= nxlu |
---|
| 147 | ! j <= nysv |
---|
| 148 | ! |
---|
[1354] | 149 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 150 | ! REAL constants provided with KIND-attribute |
---|
| 151 | ! |
---|
[1323] | 152 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 153 | ! REAL constants defined as wp-kind |
---|
| 154 | ! |
---|
[1321] | 155 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 156 | ! ONLY-attribute added to USE-statements, |
---|
| 157 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 158 | ! kinds are defined in new module kinds, |
---|
| 159 | ! revision history before 2012 removed, |
---|
| 160 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 161 | ! all variable declaration statements |
---|
[1321] | 162 | ! |
---|
[1222] | 163 | ! 1221 2013-09-10 08:59:13Z raasch |
---|
| 164 | ! wall_flags_00 introduced to hold bits 32-63, |
---|
| 165 | ! additional 3D-flag arrays for replacing the 2D-index array nzb_s_inner in |
---|
| 166 | ! loops optimized for openACC (pres + flow_statistics) |
---|
| 167 | ! |
---|
[1093] | 168 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 169 | ! unused variables removed |
---|
| 170 | ! |
---|
[1070] | 171 | ! 1069 2012-11-28 16:18:43Z maronga |
---|
[1779] | 172 | ! bugfix: added coupling_char to TOPOGRAPHY_DATA to allow topography in the |
---|
| 173 | ! ocean model in case of coupled runs |
---|
[1070] | 174 | ! |
---|
[1037] | 175 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 176 | ! code put under GPL (PALM 3.9) |
---|
| 177 | ! |
---|
[1017] | 178 | ! 1015 2012-09-27 09:23:24Z raasch |
---|
| 179 | ! lower index for calculating wall_flags_0 set to nzb_w_inner instead of |
---|
| 180 | ! nzb_w_inner+1 |
---|
| 181 | ! |
---|
[997] | 182 | ! 996 2012-09-07 10:41:47Z raasch |
---|
| 183 | ! little reformatting |
---|
| 184 | ! |
---|
[979] | 185 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 186 | ! Bugfix: nzb_max is set to nzt at non-cyclic lateral boundaries |
---|
| 187 | ! Bugfix: Set wall_flags_0 for inflow boundary |
---|
| 188 | ! |
---|
[928] | 189 | ! 927 2012-06-06 19:15:04Z raasch |
---|
| 190 | ! Wall flags are not set for multigrid method in case of masking method |
---|
| 191 | ! |
---|
[865] | 192 | ! 864 2012-03-27 15:10:33Z gryschka |
---|
[927] | 193 | ! In case of ocean and Dirichlet bottom bc for u and v dzu_mg and ddzu_pres |
---|
| 194 | ! were not correctly defined for k=1. |
---|
[865] | 195 | ! |
---|
[863] | 196 | ! 861 2012-03-26 14:18:34Z suehring |
---|
[861] | 197 | ! Set wall_flags_0. The array is needed for degradation in ws-scheme near walls, |
---|
| 198 | ! inflow and outflow boundaries as well as near the bottom and the top of the |
---|
[863] | 199 | ! model domain.! |
---|
[861] | 200 | ! Initialization of nzb_s_inner and nzb_w_inner. |
---|
| 201 | ! gls has to be at least nbgp to do not exceed the array bounds of nzb_local |
---|
| 202 | ! while setting wall_flags_0 |
---|
| 203 | ! |
---|
[844] | 204 | ! 843 2012-02-29 15:16:21Z gryschka |
---|
| 205 | ! In case of ocean and dirichlet bc for u and v at the bottom |
---|
| 206 | ! the first u-level ist defined at same height as the first w-level |
---|
| 207 | ! |
---|
[819] | 208 | ! 818 2012-02-08 16:11:23Z maronga |
---|
| 209 | ! Bugfix: topo_height is only required if topography is used. It is thus now |
---|
| 210 | ! allocated in the topography branch |
---|
| 211 | ! |
---|
[810] | 212 | ! 809 2012-01-30 13:32:58Z maronga |
---|
| 213 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
| 214 | ! |
---|
[808] | 215 | ! 807 2012-01-25 11:53:51Z maronga |
---|
| 216 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
| 217 | ! |
---|
[1] | 218 | ! Revision 1.1 1997/08/11 06:17:45 raasch |
---|
| 219 | ! Initial revision (Testversion) |
---|
| 220 | ! |
---|
| 221 | ! |
---|
| 222 | ! Description: |
---|
| 223 | ! ------------ |
---|
[1682] | 224 | !> Creating grid depending constants |
---|
[2232] | 225 | !> To Do: Setting topo flags only based on topo_3d array - flags for former |
---|
| 226 | !> nzb_outer arrays are still not set properly. |
---|
| 227 | !> To Do: Rearrange topo flag list |
---|
[1] | 228 | !------------------------------------------------------------------------------! |
---|
[1682] | 229 | SUBROUTINE init_grid |
---|
| 230 | |
---|
[1942] | 231 | USE advec_ws, & |
---|
| 232 | ONLY: ws_init_flags |
---|
[1] | 233 | |
---|
[1320] | 234 | USE arrays_3d, & |
---|
| 235 | ONLY: dd2zu, ddzu, ddzu_pres, ddzw, dzu, dzu_mg, dzw, dzw_mg, f1_mg, & |
---|
| 236 | f2_mg, f3_mg, l_grid, l_wall, zu, zw |
---|
| 237 | |
---|
[1353] | 238 | USE control_parameters, & |
---|
[1910] | 239 | ONLY: bc_lr_cyc, bc_ns_cyc, building_height, building_length_x, & |
---|
[1320] | 240 | building_length_y, building_wall_left, building_wall_south, & |
---|
| 241 | canyon_height, canyon_wall_left, canyon_wall_south, & |
---|
[1691] | 242 | canyon_width_x, canyon_width_y, constant_flux_layer, & |
---|
| 243 | coupling_char, dp_level_ind_b, dz, dz_max, dz_stretch_factor, & |
---|
[1968] | 244 | dz_stretch_level, dz_stretch_level_index, grid_level, ibc_uv_b, & |
---|
| 245 | io_blocks, io_group, inflow_l, inflow_n, inflow_r, inflow_s, & |
---|
[2232] | 246 | lod, masking_method, maximum_grid_level, message_string, & |
---|
[2021] | 247 | momentum_advec, nest_domain, nest_bound_l, nest_bound_n, & |
---|
| 248 | nest_bound_r, nest_bound_s, ocean, outflow_l, outflow_n, & |
---|
[1762] | 249 | outflow_r, outflow_s, psolver, scalar_advec, topography, & |
---|
[2232] | 250 | topography_grid_convention, tunnel_height, tunnel_length, & |
---|
| 251 | tunnel_width_x, tunnel_width_y, tunnel_wall_depth, & |
---|
| 252 | use_surface_fluxes, use_top_fluxes, wall_adjustment_factor |
---|
[2021] | 253 | |
---|
[1320] | 254 | USE grid_variables, & |
---|
[2232] | 255 | ONLY: ddx, ddx2, ddy, ddy2, dx, dx2, dy, dy2, zu_s_inner, zw_w_inner |
---|
[1320] | 256 | |
---|
| 257 | USE indices, & |
---|
[2232] | 258 | ONLY: advc_flags_1, advc_flags_2, flags, nbgp, nx, nxl, nxlg, nxl_mg, & |
---|
| 259 | nxr, nxrg, nxr_mg, ny, nyn, nyng, nyn_mg, nys, nys_mg, nysg, nz,& |
---|
| 260 | nzb, nzb_diff, nzb_diff_s_inner, nzb_diff_s_outer, & |
---|
| 261 | nzb_max, nzb_s_inner, nzb_s_outer, nzb_u_inner, & |
---|
[1845] | 262 | nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner, & |
---|
[2232] | 263 | nzb_w_outer, nzt, nzt_mg, wall_flags_0, wall_flags_1, & |
---|
[1320] | 264 | wall_flags_10, wall_flags_2, wall_flags_3, wall_flags_4, & |
---|
| 265 | wall_flags_5, wall_flags_6, wall_flags_7, wall_flags_8, & |
---|
| 266 | wall_flags_9 |
---|
| 267 | |
---|
| 268 | USE kinds |
---|
[2232] | 269 | #if defined ( __netcdf ) |
---|
| 270 | USE netcdf_interface, & |
---|
| 271 | ONLY: netcdf_close_file, netcdf_open_read_file, netcdf_get_attribute, & |
---|
| 272 | netcdf_get_variable |
---|
| 273 | #endif |
---|
[1] | 274 | USE pegrid |
---|
| 275 | |
---|
[2232] | 276 | USE surface_mod, & |
---|
| 277 | ONLY: init_bc |
---|
| 278 | |
---|
[1] | 279 | IMPLICIT NONE |
---|
| 280 | |
---|
[1968] | 281 | INTEGER(iwp) :: bh !< temporary vertical index of building height |
---|
| 282 | INTEGER(iwp) :: blx !< grid point number of building size along x |
---|
| 283 | INTEGER(iwp) :: bly !< grid point number of building size along y |
---|
| 284 | INTEGER(iwp) :: bxl !< index for left building wall |
---|
| 285 | INTEGER(iwp) :: bxr !< index for right building wall |
---|
| 286 | INTEGER(iwp) :: byn !< index for north building wall |
---|
| 287 | INTEGER(iwp) :: bys !< index for south building wall |
---|
| 288 | INTEGER(iwp) :: ch !< temporary vertical index for canyon height |
---|
| 289 | INTEGER(iwp) :: cwx !< grid point number of canyon size along x |
---|
| 290 | INTEGER(iwp) :: cwy !< grid point number of canyon size along y |
---|
| 291 | INTEGER(iwp) :: cxl !< index for left canyon wall |
---|
| 292 | INTEGER(iwp) :: cxr !< index for right canyon wall |
---|
| 293 | INTEGER(iwp) :: cyn !< index for north canyon wall |
---|
| 294 | INTEGER(iwp) :: cys !< index for south canyon wall |
---|
| 295 | INTEGER(iwp) :: i !< index variable along x |
---|
[2232] | 296 | INTEGER(iwp) :: id_topo !< NetCDF id of topograhy input file |
---|
[1968] | 297 | INTEGER(iwp) :: ii !< loop variable for reading topography file |
---|
| 298 | INTEGER(iwp) :: inc !< incremental parameter for coarsening grid level |
---|
| 299 | INTEGER(iwp) :: j !< index variable along y |
---|
| 300 | INTEGER(iwp) :: k !< index variable along z |
---|
[2232] | 301 | INTEGER(iwp) :: k_top !< topography top index on local PE |
---|
[1968] | 302 | INTEGER(iwp) :: l !< loop variable |
---|
| 303 | INTEGER(iwp) :: nxl_l !< index of left PE boundary for multigrid level |
---|
| 304 | INTEGER(iwp) :: nxr_l !< index of right PE boundary for multigrid level |
---|
| 305 | INTEGER(iwp) :: nyn_l !< index of north PE boundary for multigrid level |
---|
| 306 | INTEGER(iwp) :: nys_l !< index of south PE boundary for multigrid level |
---|
| 307 | INTEGER(iwp) :: nzb_local_max !< vertical grid index of maximum topography height |
---|
| 308 | INTEGER(iwp) :: nzb_local_min !< vertical grid index of minimum topography height |
---|
| 309 | INTEGER(iwp) :: nzt_l !< index of top PE boundary for multigrid level |
---|
| 310 | INTEGER(iwp) :: num_hole !< number of holes (in topography) resolved by only one grid point |
---|
| 311 | INTEGER(iwp) :: num_hole_l !< number of holes (in topography) resolved by only one grid point on local PE |
---|
| 312 | INTEGER(iwp) :: num_wall !< number of surrounding vertical walls for a single grid point |
---|
| 313 | INTEGER(iwp) :: skip_n_rows !< counting variable to skip rows while reading topography file |
---|
[2232] | 314 | INTEGER(iwp) :: hv_in !< heavyside function to model inner tunnel surface |
---|
| 315 | INTEGER(iwp) :: hv_out !< heavyside function to model outer tunnel surface |
---|
| 316 | INTEGER(iwp) :: txe_out !< end position of outer tunnel wall in x |
---|
| 317 | INTEGER(iwp) :: txs_out !< start position of outer tunnel wall in x |
---|
| 318 | INTEGER(iwp) :: tye_out !< end position of outer tunnel wall in y |
---|
| 319 | INTEGER(iwp) :: tys_out !< start position of outer tunnel wall in y |
---|
| 320 | INTEGER(iwp) :: txe_in !< end position of inner tunnel wall in x |
---|
| 321 | INTEGER(iwp) :: txs_in !< start position of inner tunnel wall in x |
---|
| 322 | INTEGER(iwp) :: tye_in !< end position of inner tunnel wall in y |
---|
| 323 | INTEGER(iwp) :: tys_in !< start position of inner tunnel wall in y |
---|
| 324 | INTEGER(iwp) :: td !< tunnel wall depth |
---|
| 325 | INTEGER(iwp) :: th !< height of outer tunnel wall |
---|
| 326 | |
---|
[1968] | 327 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_local !< index for topography top at cell-center |
---|
| 328 | INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE :: nzb_tmp !< dummy to calculate topography indices on u- and v-grid |
---|
[1] | 329 | |
---|
[2232] | 330 | INTEGER(iwp), DIMENSION(:,:,:), ALLOCATABLE :: topo_3d !< input array for 3D topography and dummy array for setting "outer"-flags |
---|
| 331 | |
---|
| 332 | LOGICAL :: netcdf_extend = .FALSE. !< Flag indicating wether netcdf topography input file or not |
---|
| 333 | |
---|
[1968] | 334 | REAL(wp) :: dum !< dummy variable to skip columns while reading topography file |
---|
[1886] | 335 | REAL(wp) :: dz_stretched !< stretched vertical grid spacing |
---|
[861] | 336 | |
---|
[2232] | 337 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: oro_height !< input variable for terrain height |
---|
[1968] | 338 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: topo_height !< input variable for topography height |
---|
[1] | 339 | |
---|
| 340 | ! |
---|
[709] | 341 | !-- Calculation of horizontal array bounds including ghost layers |
---|
[667] | 342 | nxlg = nxl - nbgp |
---|
| 343 | nxrg = nxr + nbgp |
---|
| 344 | nysg = nys - nbgp |
---|
| 345 | nyng = nyn + nbgp |
---|
[709] | 346 | |
---|
[667] | 347 | ! |
---|
[1] | 348 | !-- Allocate grid arrays |
---|
[1353] | 349 | ALLOCATE( ddzu(1:nzt+1), ddzw(1:nzt+1), dd2zu(1:nzt), dzu(1:nzt+1), & |
---|
[667] | 350 | dzw(1:nzt+1), l_grid(1:nzt), zu(nzb:nzt+1), zw(nzb:nzt+1) ) |
---|
[1] | 351 | |
---|
| 352 | ! |
---|
| 353 | !-- Compute height of u-levels from constant grid length and dz stretch factors |
---|
[1353] | 354 | IF ( dz == -1.0_wp ) THEN |
---|
[254] | 355 | message_string = 'missing dz' |
---|
| 356 | CALL message( 'init_grid', 'PA0200', 1, 2, 0, 6, 0 ) |
---|
[1353] | 357 | ELSEIF ( dz <= 0.0_wp ) THEN |
---|
[254] | 358 | WRITE( message_string, * ) 'dz=',dz,' <= 0.0' |
---|
| 359 | CALL message( 'init_grid', 'PA0201', 1, 2, 0, 6, 0 ) |
---|
[1] | 360 | ENDIF |
---|
[94] | 361 | |
---|
[1] | 362 | ! |
---|
[94] | 363 | !-- Define the vertical grid levels |
---|
| 364 | IF ( .NOT. ocean ) THEN |
---|
| 365 | ! |
---|
| 366 | !-- Grid for atmosphere with surface at z=0 (k=0, w-grid). |
---|
[843] | 367 | !-- The second u-level (k=1) corresponds to the top of the |
---|
[94] | 368 | !-- Prandtl-layer. |
---|
[667] | 369 | |
---|
| 370 | IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2 ) THEN |
---|
[1353] | 371 | zu(0) = 0.0_wp |
---|
| 372 | ! zu(0) = - dz * 0.5_wp |
---|
[667] | 373 | ELSE |
---|
[1353] | 374 | zu(0) = - dz * 0.5_wp |
---|
[667] | 375 | ENDIF |
---|
[1353] | 376 | zu(1) = dz * 0.5_wp |
---|
[1] | 377 | |
---|
[94] | 378 | dz_stretch_level_index = nzt+1 |
---|
| 379 | dz_stretched = dz |
---|
| 380 | DO k = 2, nzt+1 |
---|
| 381 | IF ( dz_stretch_level <= zu(k-1) .AND. dz_stretched < dz_max ) THEN |
---|
| 382 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
| 383 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
| 384 | IF ( dz_stretch_level_index == nzt+1 ) dz_stretch_level_index = k-1 |
---|
| 385 | ENDIF |
---|
| 386 | zu(k) = zu(k-1) + dz_stretched |
---|
| 387 | ENDDO |
---|
[1] | 388 | |
---|
| 389 | ! |
---|
[94] | 390 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
[843] | 391 | !-- corresponding u-levels. In case of dirichlet bc for u and v at the |
---|
| 392 | !-- ground the first u- and w-level (k=0) are defined at same height (z=0). |
---|
| 393 | !-- The top w-level is extrapolated linearly. |
---|
[1353] | 394 | zw(0) = 0.0_wp |
---|
[94] | 395 | DO k = 1, nzt |
---|
[1353] | 396 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
[94] | 397 | ENDDO |
---|
[1353] | 398 | zw(nzt+1) = zw(nzt) + 2.0_wp * ( zu(nzt+1) - zw(nzt) ) |
---|
[1] | 399 | |
---|
[94] | 400 | ELSE |
---|
[1] | 401 | ! |
---|
[843] | 402 | !-- Grid for ocean with free water surface is at k=nzt (w-grid). |
---|
| 403 | !-- In case of neumann bc at the ground the first first u-level (k=0) lies |
---|
| 404 | !-- below the first w-level (k=0). In case of dirichlet bc the first u- and |
---|
| 405 | !-- w-level are defined at same height, but staggered from the second level. |
---|
| 406 | !-- The second u-level (k=1) corresponds to the top of the Prandtl-layer. |
---|
[1353] | 407 | zu(nzt+1) = dz * 0.5_wp |
---|
| 408 | zu(nzt) = - dz * 0.5_wp |
---|
[94] | 409 | |
---|
| 410 | dz_stretch_level_index = 0 |
---|
| 411 | dz_stretched = dz |
---|
| 412 | DO k = nzt-1, 0, -1 |
---|
[1418] | 413 | ! |
---|
| 414 | !-- The default value of dz_stretch_level is positive, thus the first |
---|
| 415 | !-- condition is always true. Hence, the second condition is necessary. |
---|
| 416 | IF ( dz_stretch_level >= zu(k+1) .AND. dz_stretch_level <= 0.0 & |
---|
| 417 | .AND. dz_stretched < dz_max ) THEN |
---|
[94] | 418 | dz_stretched = dz_stretched * dz_stretch_factor |
---|
| 419 | dz_stretched = MIN( dz_stretched, dz_max ) |
---|
| 420 | IF ( dz_stretch_level_index == 0 ) dz_stretch_level_index = k+1 |
---|
| 421 | ENDIF |
---|
| 422 | zu(k) = zu(k+1) - dz_stretched |
---|
| 423 | ENDDO |
---|
| 424 | |
---|
| 425 | ! |
---|
| 426 | !-- Compute the w-levels. They are always staggered half-way between the |
---|
[843] | 427 | !-- corresponding u-levels, except in case of dirichlet bc for u and v |
---|
| 428 | !-- at the ground. In this case the first u- and w-level are defined at |
---|
| 429 | !-- same height. The top w-level (nzt+1) is not used but set for |
---|
| 430 | !-- consistency, since w and all scalar variables are defined up tp nzt+1. |
---|
[94] | 431 | zw(nzt+1) = dz |
---|
[1353] | 432 | zw(nzt) = 0.0_wp |
---|
[94] | 433 | DO k = 0, nzt |
---|
[1353] | 434 | zw(k) = ( zu(k) + zu(k+1) ) * 0.5_wp |
---|
[94] | 435 | ENDDO |
---|
| 436 | |
---|
[843] | 437 | ! |
---|
| 438 | !-- In case of dirichlet bc for u and v the first u- and w-level are defined |
---|
| 439 | !-- at same height. |
---|
| 440 | IF ( ibc_uv_b == 0 ) THEN |
---|
| 441 | zu(0) = zw(0) |
---|
| 442 | ENDIF |
---|
| 443 | |
---|
[94] | 444 | ENDIF |
---|
| 445 | |
---|
| 446 | ! |
---|
[1] | 447 | !-- Compute grid lengths. |
---|
| 448 | DO k = 1, nzt+1 |
---|
| 449 | dzu(k) = zu(k) - zu(k-1) |
---|
[1353] | 450 | ddzu(k) = 1.0_wp / dzu(k) |
---|
[1] | 451 | dzw(k) = zw(k) - zw(k-1) |
---|
[1353] | 452 | ddzw(k) = 1.0_wp / dzw(k) |
---|
[1] | 453 | ENDDO |
---|
| 454 | |
---|
| 455 | DO k = 1, nzt |
---|
[1353] | 456 | dd2zu(k) = 1.0_wp / ( dzu(k) + dzu(k+1) ) |
---|
[1] | 457 | ENDDO |
---|
[667] | 458 | |
---|
| 459 | ! |
---|
[709] | 460 | !-- The FFT- SOR-pressure solvers assume grid spacings of a staggered grid |
---|
| 461 | !-- everywhere. For the actual grid, the grid spacing at the lowest level |
---|
| 462 | !-- is only dz/2, but should be dz. Therefore, an additional array |
---|
| 463 | !-- containing with appropriate grid information is created for these |
---|
| 464 | !-- solvers. |
---|
[1575] | 465 | IF ( psolver(1:9) /= 'multigrid' ) THEN |
---|
[667] | 466 | ALLOCATE( ddzu_pres(1:nzt+1) ) |
---|
| 467 | ddzu_pres = ddzu |
---|
[864] | 468 | ddzu_pres(1) = ddzu_pres(2) ! change for lowest level |
---|
[1] | 469 | ENDIF |
---|
| 470 | |
---|
| 471 | ! |
---|
| 472 | !-- Compute the reciprocal values of the horizontal grid lengths. |
---|
[1353] | 473 | ddx = 1.0_wp / dx |
---|
| 474 | ddy = 1.0_wp / dy |
---|
[1] | 475 | dx2 = dx * dx |
---|
| 476 | dy2 = dy * dy |
---|
[1353] | 477 | ddx2 = 1.0_wp / dx2 |
---|
| 478 | ddy2 = 1.0_wp / dy2 |
---|
[1] | 479 | |
---|
| 480 | ! |
---|
| 481 | !-- Compute the grid-dependent mixing length. |
---|
| 482 | DO k = 1, nzt |
---|
[1322] | 483 | l_grid(k) = ( dx * dy * dzw(k) )**0.33333333333333_wp |
---|
[1] | 484 | ENDDO |
---|
| 485 | |
---|
| 486 | ! |
---|
| 487 | !-- Allocate outer and inner index arrays for topography and set |
---|
[2232] | 488 | !-- defaults. |
---|
| 489 | ALLOCATE( nzb_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
[667] | 490 | nzb_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
| 491 | nzb_u_inner(nysg:nyng,nxlg:nxrg), & |
---|
| 492 | nzb_u_outer(nysg:nyng,nxlg:nxrg), & |
---|
| 493 | nzb_v_inner(nysg:nyng,nxlg:nxrg), & |
---|
| 494 | nzb_v_outer(nysg:nyng,nxlg:nxrg), & |
---|
| 495 | nzb_w_inner(nysg:nyng,nxlg:nxrg), & |
---|
| 496 | nzb_w_outer(nysg:nyng,nxlg:nxrg), & |
---|
| 497 | nzb_diff_s_inner(nysg:nyng,nxlg:nxrg), & |
---|
| 498 | nzb_diff_s_outer(nysg:nyng,nxlg:nxrg), & |
---|
[1968] | 499 | nzb_local(nysg:nyng,nxlg:nxrg), & |
---|
| 500 | nzb_tmp(nysg:nyng,nxlg:nxrg), & |
---|
[2232] | 501 | wall_flags_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1] | 502 | |
---|
[2232] | 503 | ALLOCATE( topo_3d(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 504 | topo_3d = 0 |
---|
[1] | 505 | |
---|
[667] | 506 | ALLOCATE( l_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 507 | |
---|
[1] | 508 | nzb_s_inner = nzb; nzb_s_outer = nzb |
---|
| 509 | nzb_u_inner = nzb; nzb_u_outer = nzb |
---|
| 510 | nzb_v_inner = nzb; nzb_v_outer = nzb |
---|
| 511 | nzb_w_inner = nzb; nzb_w_outer = nzb |
---|
| 512 | |
---|
| 513 | ! |
---|
[19] | 514 | !-- Define vertical gridpoint from (or to) which on the usual finite difference |
---|
[1] | 515 | !-- form (which does not use surface fluxes) is applied |
---|
[1691] | 516 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[1] | 517 | nzb_diff = nzb + 2 |
---|
| 518 | ELSE |
---|
| 519 | nzb_diff = nzb + 1 |
---|
| 520 | ENDIF |
---|
| 521 | |
---|
| 522 | nzb_diff_s_inner = nzb_diff; nzb_diff_s_outer = nzb_diff |
---|
| 523 | |
---|
| 524 | ! |
---|
| 525 | !-- Initialize near-wall mixing length l_wall only in the vertical direction |
---|
| 526 | !-- for the moment, |
---|
| 527 | !-- multiplication with wall_adjustment_factor near the end of this routine |
---|
| 528 | l_wall(nzb,:,:) = l_grid(1) |
---|
| 529 | DO k = nzb+1, nzt |
---|
| 530 | l_wall(k,:,:) = l_grid(k) |
---|
| 531 | ENDDO |
---|
| 532 | l_wall(nzt+1,:,:) = l_grid(nzt) |
---|
| 533 | |
---|
| 534 | DO k = 1, nzt |
---|
[1353] | 535 | IF ( l_grid(k) > 1.5_wp * dx * wall_adjustment_factor .OR. & |
---|
| 536 | l_grid(k) > 1.5_wp * dy * wall_adjustment_factor ) THEN |
---|
[254] | 537 | WRITE( message_string, * ) 'grid anisotropy exceeds ', & |
---|
| 538 | 'threshold given by only local', & |
---|
| 539 | ' &horizontal reduction of near_wall ', & |
---|
| 540 | 'mixing length l_wall', & |
---|
| 541 | ' &starting from height level k = ', k, '.' |
---|
| 542 | CALL message( 'init_grid', 'PA0202', 0, 1, 0, 6, 0 ) |
---|
[1] | 543 | EXIT |
---|
| 544 | ENDIF |
---|
| 545 | ENDDO |
---|
| 546 | ! |
---|
| 547 | !-- Set outer and inner index arrays for non-flat topography. |
---|
| 548 | !-- Here consistency checks concerning domain size and periodicity are |
---|
| 549 | !-- necessary. |
---|
| 550 | !-- Within this SELECT CASE structure only nzb_local is initialized |
---|
| 551 | !-- individually depending on the chosen topography type, all other index |
---|
| 552 | !-- arrays are initialized further below. |
---|
| 553 | SELECT CASE ( TRIM( topography ) ) |
---|
| 554 | |
---|
| 555 | CASE ( 'flat' ) |
---|
| 556 | ! |
---|
[555] | 557 | !-- nzb_local is required for the multigrid solver |
---|
| 558 | nzb_local = 0 |
---|
[2232] | 559 | ! |
---|
| 560 | !-- Initialilize 3D topography array, used later for initializing flags |
---|
| 561 | topo_3d(nzb+1:nzt+1,:,:) = IBSET( topo_3d(nzb+1:nzt+1,:,:), 0 ) |
---|
| 562 | ! |
---|
| 563 | !-- level of detail is required for output routines |
---|
| 564 | lod = 1 |
---|
[1] | 565 | |
---|
| 566 | CASE ( 'single_building' ) |
---|
| 567 | ! |
---|
| 568 | !-- Single rectangular building, by default centered in the middle of the |
---|
| 569 | !-- total domain |
---|
| 570 | blx = NINT( building_length_x / dx ) |
---|
| 571 | bly = NINT( building_length_y / dy ) |
---|
[2232] | 572 | bh = MINLOC( ABS( zw - building_height ), 1 ) - 1 |
---|
| 573 | IF ( ABS( zw(bh) - building_height ) == & |
---|
[1675] | 574 | ABS( zw(bh+1) - building_height ) ) bh = bh + 1 |
---|
[1] | 575 | |
---|
[1322] | 576 | IF ( building_wall_left == 9999999.9_wp ) THEN |
---|
[1] | 577 | building_wall_left = ( nx + 1 - blx ) / 2 * dx |
---|
| 578 | ENDIF |
---|
| 579 | bxl = NINT( building_wall_left / dx ) |
---|
| 580 | bxr = bxl + blx |
---|
| 581 | |
---|
[1322] | 582 | IF ( building_wall_south == 9999999.9_wp ) THEN |
---|
[1] | 583 | building_wall_south = ( ny + 1 - bly ) / 2 * dy |
---|
| 584 | ENDIF |
---|
| 585 | bys = NINT( building_wall_south / dy ) |
---|
| 586 | byn = bys + bly |
---|
| 587 | |
---|
| 588 | ! |
---|
| 589 | !-- Building size has to meet some requirements |
---|
| 590 | IF ( ( bxl < 1 ) .OR. ( bxr > nx-1 ) .OR. ( bxr < bxl+3 ) .OR. & |
---|
| 591 | ( bys < 1 ) .OR. ( byn > ny-1 ) .OR. ( byn < bys+3 ) ) THEN |
---|
[274] | 592 | WRITE( message_string, * ) 'inconsistent building parameters:', & |
---|
| 593 | '& bxl=', bxl, 'bxr=', bxr, 'bys=', bys, & |
---|
| 594 | 'byn=', byn, 'nx=', nx, 'ny=', ny |
---|
[254] | 595 | CALL message( 'init_grid', 'PA0203', 1, 2, 0, 6, 0 ) |
---|
[1] | 596 | ENDIF |
---|
| 597 | |
---|
| 598 | ! |
---|
[1968] | 599 | !-- Define the building. |
---|
[1] | 600 | nzb_local = 0 |
---|
[1968] | 601 | IF ( bxl <= nxr .AND. bxr >= nxl .AND. & |
---|
| 602 | bys <= nyn .AND. byn >= nys ) & |
---|
| 603 | nzb_local(MAX(nys,bys):MIN(nyn,byn),MAX(nxl,bxl):MIN(nxr,bxr)) = bh |
---|
[1] | 604 | |
---|
[1994] | 605 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
[2232] | 606 | ! |
---|
| 607 | !-- Set bit array to mask topography |
---|
| 608 | DO i = nxlg, nxrg |
---|
| 609 | DO j = nysg, nyng |
---|
[1994] | 610 | |
---|
[2232] | 611 | topo_3d(nzb_local(j,i)+1:nzt+1,j,i) = & |
---|
| 612 | IBSET( topo_3d(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
| 613 | ENDDO |
---|
| 614 | ENDDO |
---|
| 615 | ! |
---|
| 616 | !-- level of detail is required for output routines. Here, 2D topography. |
---|
| 617 | lod = 1 |
---|
| 618 | |
---|
| 619 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
| 620 | |
---|
[240] | 621 | CASE ( 'single_street_canyon' ) |
---|
| 622 | ! |
---|
| 623 | !-- Single quasi-2D street canyon of infinite length in x or y direction. |
---|
| 624 | !-- The canyon is centered in the other direction by default. |
---|
[1322] | 625 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[240] | 626 | ! |
---|
| 627 | !-- Street canyon in y direction |
---|
| 628 | cwx = NINT( canyon_width_x / dx ) |
---|
[1322] | 629 | IF ( canyon_wall_left == 9999999.9_wp ) THEN |
---|
[240] | 630 | canyon_wall_left = ( nx + 1 - cwx ) / 2 * dx |
---|
| 631 | ENDIF |
---|
| 632 | cxl = NINT( canyon_wall_left / dx ) |
---|
| 633 | cxr = cxl + cwx |
---|
| 634 | |
---|
[1322] | 635 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[240] | 636 | ! |
---|
| 637 | !-- Street canyon in x direction |
---|
| 638 | cwy = NINT( canyon_width_y / dy ) |
---|
[1322] | 639 | IF ( canyon_wall_south == 9999999.9_wp ) THEN |
---|
[240] | 640 | canyon_wall_south = ( ny + 1 - cwy ) / 2 * dy |
---|
| 641 | ENDIF |
---|
| 642 | cys = NINT( canyon_wall_south / dy ) |
---|
| 643 | cyn = cys + cwy |
---|
| 644 | |
---|
| 645 | ELSE |
---|
[254] | 646 | |
---|
| 647 | message_string = 'no street canyon width given' |
---|
| 648 | CALL message( 'init_grid', 'PA0204', 1, 2, 0, 6, 0 ) |
---|
| 649 | |
---|
[240] | 650 | ENDIF |
---|
| 651 | |
---|
[2232] | 652 | ch = MINLOC( ABS( zw - canyon_height ), 1 ) - 1 |
---|
| 653 | IF ( ABS( zw(ch) - canyon_height ) == & |
---|
[1675] | 654 | ABS( zw(ch+1) - canyon_height ) ) ch = ch + 1 |
---|
| 655 | |
---|
[240] | 656 | dp_level_ind_b = ch |
---|
| 657 | ! |
---|
| 658 | !-- Street canyon size has to meet some requirements |
---|
[1322] | 659 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[1353] | 660 | IF ( ( cxl < 1 ) .OR. ( cxr > nx-1 ) .OR. ( cwx < 3 ) .OR. & |
---|
[240] | 661 | ( ch < 3 ) ) THEN |
---|
[1353] | 662 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
| 663 | '&cxl=', cxl, 'cxr=', cxr, & |
---|
| 664 | 'cwx=', cwx, & |
---|
[254] | 665 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
| 666 | CALL message( 'init_grid', 'PA0205', 1, 2, 0, 6, 0 ) |
---|
[240] | 667 | ENDIF |
---|
[1322] | 668 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[1353] | 669 | IF ( ( cys < 1 ) .OR. ( cyn > ny-1 ) .OR. ( cwy < 3 ) .OR. & |
---|
[240] | 670 | ( ch < 3 ) ) THEN |
---|
[1353] | 671 | WRITE( message_string, * ) 'inconsistent canyon parameters:', & |
---|
| 672 | '&cys=', cys, 'cyn=', cyn, & |
---|
| 673 | 'cwy=', cwy, & |
---|
[254] | 674 | 'ch=', ch, 'nx=', nx, 'ny=', ny |
---|
| 675 | CALL message( 'init_grid', 'PA0206', 1, 2, 0, 6, 0 ) |
---|
[240] | 676 | ENDIF |
---|
| 677 | ENDIF |
---|
[1353] | 678 | IF ( canyon_width_x /= 9999999.9_wp .AND. & |
---|
| 679 | canyon_width_y /= 9999999.9_wp ) THEN |
---|
| 680 | message_string = 'inconsistent canyon parameters:' // & |
---|
| 681 | '&street canyon can only be oriented' // & |
---|
[254] | 682 | '&either in x- or in y-direction' |
---|
| 683 | CALL message( 'init_grid', 'PA0207', 1, 2, 0, 6, 0 ) |
---|
[240] | 684 | ENDIF |
---|
| 685 | |
---|
| 686 | nzb_local = ch |
---|
[1322] | 687 | IF ( canyon_width_x /= 9999999.9_wp ) THEN |
---|
[1968] | 688 | IF ( cxl <= nxr .AND. cxr >= nxl ) & |
---|
| 689 | nzb_local(:,MAX(nxl,cxl+1):MIN(nxr,cxr-1)) = 0 |
---|
[1322] | 690 | ELSEIF ( canyon_width_y /= 9999999.9_wp ) THEN |
---|
[1968] | 691 | IF ( cys <= nyn .AND. cyn >= nys ) & |
---|
| 692 | nzb_local(MAX(nys,cys+1):MIN(nyn,cyn-1),:) = 0 |
---|
[240] | 693 | ENDIF |
---|
| 694 | |
---|
[1994] | 695 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
[2232] | 696 | ! |
---|
| 697 | !-- Set bit array to mask topography |
---|
| 698 | DO i = nxlg, nxrg |
---|
| 699 | DO j = nysg, nyng |
---|
| 700 | topo_3d(nzb_local(j,i)+1:nzt+1,j,i) = & |
---|
| 701 | IBSET( topo_3d(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
| 702 | ENDDO |
---|
| 703 | ENDDO |
---|
| 704 | ! |
---|
| 705 | !-- level of detail is required for output routines. Here, 2D topography. |
---|
| 706 | lod = 1 |
---|
[1994] | 707 | |
---|
[2232] | 708 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
| 709 | |
---|
| 710 | CASE ( 'tunnel' ) |
---|
| 711 | |
---|
| 712 | ! |
---|
| 713 | !-- Tunnel height |
---|
| 714 | IF ( tunnel_height == 9999999.9_wp ) THEN |
---|
| 715 | th = zw( INT( 0.2 * nz) ) |
---|
| 716 | ELSE |
---|
| 717 | th = tunnel_height |
---|
| 718 | ENDIF |
---|
| 719 | ! |
---|
| 720 | !-- Tunnel-wall depth |
---|
| 721 | IF ( tunnel_wall_depth == 9999999.9_wp ) THEN |
---|
| 722 | td = MAX ( dx, dy, dz ) |
---|
| 723 | ELSE |
---|
| 724 | td = tunnel_wall_depth |
---|
| 725 | ENDIF |
---|
| 726 | ! |
---|
| 727 | !-- Check for tunnel width |
---|
| 728 | IF ( tunnel_width_x == 9999999.9_wp .AND. & |
---|
| 729 | tunnel_width_y == 9999999.9_wp ) THEN |
---|
| 730 | message_string = 'No tunnel width is given. ' |
---|
[2274] | 731 | CALL message( 'init_grid', 'PA0280', 1, 2, 0, 6, 0 ) |
---|
[2232] | 732 | ENDIF |
---|
| 733 | IF ( tunnel_width_x /= 9999999.9_wp .AND. & |
---|
| 734 | tunnel_width_y /= 9999999.9_wp ) THEN |
---|
| 735 | message_string = 'Inconsistent tunnel parameters:' // & |
---|
| 736 | 'tunnel can only be oriented' // & |
---|
| 737 | 'either in x- or in y-direction.' |
---|
[2274] | 738 | CALL message( 'init_grid', 'PA0281', 1, 2, 0, 6, 0 ) |
---|
[2232] | 739 | ENDIF |
---|
| 740 | ! |
---|
| 741 | !-- Tunnel axis along y |
---|
| 742 | IF ( tunnel_width_x /= 9999999.9_wp ) THEN |
---|
| 743 | IF ( tunnel_width_x > ( nx + 1 ) * dx ) THEN |
---|
| 744 | message_string = 'Tunnel width too large' |
---|
[2274] | 745 | CALL message( 'init_grid', 'PA0282', 1, 2, 0, 6, 0 ) |
---|
[2232] | 746 | ENDIF |
---|
| 747 | |
---|
| 748 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_width_x * 0.5_wp ) |
---|
| 749 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_width_x * 0.5_wp ) |
---|
| 750 | txs_in = INT( ( nx + 1 ) * 0.5_wp * dx - & |
---|
| 751 | ( tunnel_width_x * 0.5_wp - td ) ) |
---|
| 752 | txe_in = INT( ( nx + 1 ) * 0.5_wp * dx + & |
---|
| 753 | ( tunnel_width_x * 0.5_wp - td ) ) |
---|
| 754 | |
---|
| 755 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_length * 0.5_wp ) |
---|
| 756 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_length * 0.5_wp ) |
---|
| 757 | tys_in = tys_out |
---|
| 758 | tye_in = tye_out |
---|
| 759 | ENDIF |
---|
| 760 | IF ( tunnel_width_x /= 9999999.9_wp .AND. & |
---|
| 761 | tunnel_width_x - 2.0_wp * tunnel_wall_depth <= 2.0_wp * dx ) THEN |
---|
| 762 | message_string = 'Tunnel width too small' |
---|
[2274] | 763 | CALL message( 'init_grid', 'PA0175', 1, 2, 0, 6, 0 ) |
---|
[2232] | 764 | ENDIF |
---|
| 765 | IF ( tunnel_width_y /= 9999999.9_wp .AND. & |
---|
| 766 | tunnel_width_y - 2.0_wp * tunnel_wall_depth <= 2.0_wp * dy ) THEN |
---|
| 767 | message_string = 'Tunnel width too small' |
---|
[2274] | 768 | CALL message( 'init_grid', 'PA0455', 1, 2, 0, 6, 0 ) |
---|
[2232] | 769 | ENDIF |
---|
| 770 | ! |
---|
| 771 | !-- Tunnel axis along x |
---|
| 772 | IF ( tunnel_width_y /= 9999999.9_wp ) THEN |
---|
| 773 | IF ( tunnel_width_y > ( ny + 1 ) * dy ) THEN |
---|
| 774 | message_string = 'Tunnel width too large' |
---|
[2274] | 775 | CALL message( 'init_grid', 'PA0456', 1, 2, 0, 6, 0 ) |
---|
[2232] | 776 | ENDIF |
---|
| 777 | |
---|
| 778 | txs_out = INT( ( nx + 1 ) * 0.5_wp * dx - tunnel_length * 0.5_wp ) |
---|
| 779 | txe_out = INT( ( nx + 1 ) * 0.5_wp * dx + tunnel_length * 0.5_wp ) |
---|
| 780 | txs_in = txs_out |
---|
| 781 | txe_in = txe_out |
---|
| 782 | |
---|
| 783 | tys_out = INT( ( ny + 1 ) * 0.5_wp * dy - tunnel_width_y * 0.5_wp ) |
---|
| 784 | tye_out = INT( ( ny + 1 ) * 0.5_wp * dy + tunnel_width_y * 0.5_wp ) |
---|
| 785 | tys_in = INT( ( ny + 1 ) * 0.5_wp * dy - & |
---|
| 786 | ( tunnel_width_y * 0.5_wp - td ) ) |
---|
| 787 | tye_in = INT( ( ny + 1 ) * 0.5_wp * dy + & |
---|
| 788 | ( tunnel_width_y * 0.5_wp - td ) ) |
---|
| 789 | ENDIF |
---|
| 790 | |
---|
| 791 | topo_3d = 0 |
---|
| 792 | DO i = nxl, nxr |
---|
| 793 | DO j = nys, nyn |
---|
| 794 | ! |
---|
| 795 | !-- Use heaviside function to model outer tunnel surface |
---|
| 796 | hv_out = th * 0.5_wp * & |
---|
| 797 | ( ( SIGN( 1.0_wp, i * dx - txs_out ) + 1.0_wp ) & |
---|
| 798 | - ( SIGN( 1.0_wp, i * dx - txe_out ) + 1.0_wp ) ) |
---|
| 799 | |
---|
| 800 | hv_out = hv_out * 0.5_wp * & |
---|
| 801 | ( ( SIGN( 1.0_wp, j * dy - tys_out ) + 1.0_wp ) & |
---|
| 802 | - ( SIGN( 1.0_wp, j * dy - tye_out ) + 1.0_wp ) ) |
---|
| 803 | ! |
---|
| 804 | !-- Use heaviside function to model inner tunnel surface |
---|
| 805 | hv_in = ( th - td ) * 0.5_wp * & |
---|
| 806 | ( ( SIGN( 1.0_wp, i * dx - txs_in ) + 1.0_wp ) & |
---|
| 807 | - ( SIGN( 1.0_wp, i * dx - txe_in ) + 1.0_wp ) ) |
---|
| 808 | |
---|
| 809 | hv_in = hv_in * 0.5_wp * & |
---|
| 810 | ( ( SIGN( 1.0_wp, j * dy - tys_in ) + 1.0_wp ) & |
---|
| 811 | - ( SIGN( 1.0_wp, j * dy - tye_in ) + 1.0_wp ) ) |
---|
| 812 | ! |
---|
| 813 | !-- Set flags at x-y-positions without any tunnel surface |
---|
| 814 | IF ( hv_out - hv_in == 0.0_wp ) THEN |
---|
| 815 | topo_3d(nzb+1:nzt+1,j,i) = IBSET( topo_3d(nzb+1:nzt+1,j,i), 0 ) |
---|
| 816 | ! |
---|
| 817 | !-- Set flags at x-y-positions with tunnel surfaces |
---|
| 818 | ELSE |
---|
| 819 | DO k = nzb + 1, nzt + 1 |
---|
| 820 | ! |
---|
| 821 | !-- Inner tunnel |
---|
| 822 | IF ( hv_out - hv_in == th ) THEN |
---|
| 823 | IF ( zw(k) <= hv_out ) THEN |
---|
| 824 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
| 825 | ELSE |
---|
| 826 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 0 ) |
---|
| 827 | ENDIF |
---|
| 828 | ENDIF |
---|
| 829 | ! |
---|
| 830 | !-- Lateral tunnel walls |
---|
| 831 | IF ( hv_out - hv_in == td ) THEN |
---|
| 832 | IF ( zw(k) <= hv_in ) THEN |
---|
| 833 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 0 ) |
---|
| 834 | ELSEIF ( zw(k) > hv_in .AND. zw(k) <= hv_out ) THEN |
---|
| 835 | topo_3d(k,j,i) = IBCLR( topo_3d(k,j,i), 0 ) |
---|
| 836 | ELSEIF ( zw(k) > hv_out ) THEN |
---|
| 837 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 0 ) |
---|
| 838 | ENDIF |
---|
| 839 | ENDIF |
---|
| 840 | ENDDO |
---|
| 841 | ENDIF |
---|
| 842 | ENDDO |
---|
| 843 | ENDDO |
---|
| 844 | |
---|
| 845 | nzb_local = 0 |
---|
| 846 | ! |
---|
| 847 | !-- level of detail is required for output routines. Here, 3D topography. |
---|
| 848 | lod = 2 |
---|
| 849 | |
---|
| 850 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
| 851 | |
---|
[1] | 852 | CASE ( 'read_from_file' ) |
---|
[759] | 853 | |
---|
[2232] | 854 | ALLOCATE ( oro_height(nys:nyn,nxl:nxr) ) |
---|
[1968] | 855 | ALLOCATE ( topo_height(nys:nyn,nxl:nxr) ) |
---|
[2232] | 856 | oro_height = 0.0_wp |
---|
| 857 | topo_height = 0.0_wp |
---|
[818] | 858 | |
---|
[759] | 859 | DO ii = 0, io_blocks-1 |
---|
| 860 | IF ( ii == io_group ) THEN |
---|
| 861 | |
---|
[1] | 862 | ! |
---|
[759] | 863 | !-- Arbitrary irregular topography data in PALM format (exactly |
---|
[2232] | 864 | !-- matching the grid size and total domain size). |
---|
| 865 | !-- First, check if NetCDF file for topography exist or not. |
---|
| 866 | !-- This case, read topography from NetCDF, else read it from |
---|
| 867 | !-- ASCII file. |
---|
| 868 | #if defined ( __netcdf ) |
---|
| 869 | INQUIRE( FILE='TOPOGRAPHY_DATA_NC'//TRIM( coupling_char ), & |
---|
| 870 | EXIST=netcdf_extend ) |
---|
[1968] | 871 | ! |
---|
[2232] | 872 | !-- NetCDF branch |
---|
| 873 | IF ( netcdf_extend ) THEN |
---|
[1968] | 874 | ! |
---|
[2232] | 875 | !-- Open file in read-only mode |
---|
| 876 | CALL netcdf_open_read_file( 'TOPOGRAPHY_DATA_NC', & |
---|
| 877 | id_topo, 20 ) !Error number still need to be set properly |
---|
| 878 | |
---|
| 879 | ! |
---|
| 880 | !-- Read terrain height. Reading is done PE-wise, i.e. each |
---|
| 881 | !-- processor reads its own domain. Reading is realized |
---|
| 882 | !-- via looping over x-dimension, i.e. calling |
---|
| 883 | !-- netcdf_get_variable reads topography along y for given x. |
---|
| 884 | !-- Orography is 2D. |
---|
| 885 | DO i = nxl, nxr |
---|
| 886 | CALL netcdf_get_variable( id_topo, 'orography_0', & |
---|
| 887 | i, oro_height(:,i), 20 ) !Error number still need to be set properly |
---|
| 888 | ENDDO |
---|
| 889 | ! |
---|
| 890 | !-- Read attribute lod (level of detail), required for variable |
---|
| 891 | !-- buildings_0 |
---|
| 892 | CALL netcdf_get_attribute( id_topo, "lod", lod, .FALSE., & |
---|
| 893 | 20, 'buildings_0' ) !Error number still need to be set properly |
---|
| 894 | ! |
---|
| 895 | !-- Read building height |
---|
| 896 | !-- 2D for lod = 1, 3D for lod = 2 |
---|
| 897 | IF ( lod == 1 ) THEN |
---|
| 898 | DO i = nxl, nxr |
---|
| 899 | CALL netcdf_get_variable( id_topo, 'buildings_0', & |
---|
| 900 | i, topo_height(:,i), 20 ) !Error number still need to be set properly |
---|
| 901 | ENDDO |
---|
| 902 | |
---|
| 903 | ELSEIF ( lod == 2 ) THEN |
---|
| 904 | ! |
---|
| 905 | !-- Read data PE-wise. Read yz-slices. |
---|
| 906 | DO i = nxl, nxr |
---|
| 907 | DO j = nys, nyn |
---|
| 908 | CALL netcdf_get_variable( id_topo, 'buildings_0', & |
---|
| 909 | i, j, topo_3d(:,j,i), 20 ) !Error number still need to be set properly |
---|
| 910 | ENDDO |
---|
| 911 | ENDDO |
---|
| 912 | ELSE |
---|
| 913 | message_string = 'NetCDF attribute lod ' // & |
---|
| 914 | '(level of detail) is not set properly.' |
---|
[2274] | 915 | CALL message( 'init_grid', 'PA0457', 1, 2, 0, 6, 0 ) |
---|
[2232] | 916 | ENDIF |
---|
| 917 | ! |
---|
| 918 | !-- Close topography input file |
---|
| 919 | CALL netcdf_close_file( id_topo, 20 ) |
---|
| 920 | #endif |
---|
| 921 | |
---|
| 922 | ! |
---|
| 923 | !-- ASCII branch. Please note, reading of 3D topography is not |
---|
| 924 | !-- supported in ASCII format. Further, no distinction is made |
---|
| 925 | !-- between orography and buildings |
---|
| 926 | ELSE |
---|
| 927 | |
---|
| 928 | OPEN( 90, FILE='TOPOGRAPHY_DATA'//TRIM( coupling_char ), & |
---|
| 929 | STATUS='OLD', FORM='FORMATTED', ERR=10 ) |
---|
| 930 | ! |
---|
| 931 | !-- Read topography PE-wise. Rows are read from nyn to nys, columns |
---|
| 932 | !-- are read from nxl to nxr. At first, ny-nyn rows need to be skipped. |
---|
| 933 | skip_n_rows = 0 |
---|
| 934 | DO WHILE ( skip_n_rows < ny - nyn ) |
---|
| 935 | READ( 90, * ) |
---|
| 936 | skip_n_rows = skip_n_rows + 1 |
---|
| 937 | ENDDO |
---|
| 938 | ! |
---|
| 939 | !-- Read data from nyn to nys and nxl to nxr. Therefore, skip |
---|
| 940 | !-- column until nxl-1 is reached |
---|
| 941 | DO j = nyn, nys, -1 |
---|
| 942 | READ( 90, *, ERR=11, END=11 ) & |
---|
[1968] | 943 | ( dum, i = 0, nxl-1 ), & |
---|
| 944 | ( topo_height(j,i), i = nxl, nxr ) |
---|
[2232] | 945 | ENDDO |
---|
[759] | 946 | |
---|
[2232] | 947 | GOTO 12 |
---|
[759] | 948 | |
---|
[2232] | 949 | 10 message_string = 'file TOPOGRAPHY'//TRIM( coupling_char )// & |
---|
| 950 | ' does not exist' |
---|
| 951 | CALL message( 'init_grid', 'PA0208', 1, 2, 0, 6, 0 ) |
---|
[759] | 952 | |
---|
[2232] | 953 | 11 message_string = 'errors in file TOPOGRAPHY_DATA'// & |
---|
| 954 | TRIM( coupling_char ) |
---|
| 955 | CALL message( 'init_grid', 'PA0209', 1, 2, 0, 6, 0 ) |
---|
[759] | 956 | |
---|
[2232] | 957 | 12 CLOSE( 90 ) |
---|
[759] | 958 | |
---|
[2232] | 959 | ENDIF |
---|
| 960 | |
---|
[759] | 961 | ENDIF |
---|
[1804] | 962 | #if defined( __parallel ) |
---|
[759] | 963 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 964 | #endif |
---|
[559] | 965 | ENDDO |
---|
[759] | 966 | |
---|
[1] | 967 | ! |
---|
| 968 | !-- Calculate the index height of the topography |
---|
[1968] | 969 | nzb_local = 0 |
---|
| 970 | DO i = nxl, nxr |
---|
| 971 | DO j = nys, nyn |
---|
[2128] | 972 | IF ( .NOT. ocean ) THEN |
---|
[2232] | 973 | nzb_local(j,i) = MINLOC( ABS( zw - topo_height(j,i) & |
---|
| 974 | - oro_height(j,i) ), 1 ) - 1 |
---|
| 975 | IF ( ABS( zw(nzb_local(j,i) ) - topo_height(j,i) & |
---|
| 976 | - oro_height(j,i) ) == & |
---|
| 977 | ABS( zw(nzb_local(j,i)+1) - topo_height(j,i) & |
---|
| 978 | - oro_height(j,i) ) ) & |
---|
[2128] | 979 | nzb_local(j,i) = nzb_local(j,i) + 1 |
---|
| 980 | ELSE |
---|
| 981 | nzb_local(j,i) = MINLOC( ABS( zw - zw(0) & |
---|
[2232] | 982 | - topo_height(j,i) & |
---|
| 983 | - oro_height(j,i) ), 1 ) - 1 |
---|
[2128] | 984 | IF ( ABS( zw(nzb_local(j,i) ) - zw(0) & |
---|
[2232] | 985 | - topo_height(j,i) & |
---|
| 986 | - oro_height(j,i) ) == & |
---|
[2128] | 987 | ABS( zw(nzb_local(j,i)+1) - zw(0) & |
---|
[2232] | 988 | - topo_height(j,i) & |
---|
| 989 | - oro_height(j,i) ) ) & |
---|
[2128] | 990 | nzb_local(j,i) = nzb_local(j,i) + 1 |
---|
| 991 | ENDIF |
---|
| 992 | |
---|
[1] | 993 | ENDDO |
---|
| 994 | ENDDO |
---|
[818] | 995 | |
---|
[2232] | 996 | DEALLOCATE ( oro_height ) |
---|
[818] | 997 | DEALLOCATE ( topo_height ) |
---|
[1942] | 998 | ! |
---|
| 999 | !-- Filter topography, i.e. fill holes resolved by only one grid point. |
---|
| 1000 | !-- Such holes are suspected to lead to velocity blow-ups as continuity |
---|
| 1001 | !-- equation on discrete grid cannot be fulfilled in such case. |
---|
| 1002 | !-- For now, check only for holes and fill them to the lowest height level |
---|
| 1003 | !-- of the directly adjoining grid points along x- and y- direction. |
---|
| 1004 | !-- Before checking for holes, set lateral boundary conditions for |
---|
| 1005 | !-- topography. After hole-filling, boundary conditions must be set again! |
---|
[1968] | 1006 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1007 | |
---|
| 1008 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1009 | IF ( nys == 0 ) nzb_local(-1,:) = nzb_local(0,:) |
---|
| 1010 | IF ( nyn == ny ) nzb_local(ny+1,:) = nzb_local(ny,:) |
---|
[1942] | 1011 | ENDIF |
---|
[1910] | 1012 | |
---|
[1968] | 1013 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1014 | IF ( nxl == 0 ) nzb_local(:,-1) = nzb_local(:,0) |
---|
| 1015 | IF ( nxr == nx ) nzb_local(:,nx+1) = nzb_local(:,nx) |
---|
[1942] | 1016 | ENDIF |
---|
| 1017 | |
---|
[1968] | 1018 | num_hole_l = 0 |
---|
| 1019 | DO i = nxl, nxr |
---|
| 1020 | DO j = nys, nyn |
---|
[1942] | 1021 | |
---|
| 1022 | num_wall = 0 |
---|
| 1023 | |
---|
| 1024 | IF ( nzb_local(j-1,i) > nzb_local(j,i) ) & |
---|
| 1025 | num_wall = num_wall + 1 |
---|
| 1026 | IF ( nzb_local(j+1,i) > nzb_local(j,i) ) & |
---|
| 1027 | num_wall = num_wall + 1 |
---|
| 1028 | IF ( nzb_local(j,i-1) > nzb_local(j,i) ) & |
---|
| 1029 | num_wall = num_wall + 1 |
---|
| 1030 | IF ( nzb_local(j,i+1) > nzb_local(j,i) ) & |
---|
| 1031 | num_wall = num_wall + 1 |
---|
| 1032 | |
---|
| 1033 | IF ( num_wall == 4 ) THEN |
---|
| 1034 | nzb_local(j,i) = MIN( nzb_local(j-1,i), nzb_local(j+1,i), & |
---|
| 1035 | nzb_local(j,i-1), nzb_local(j,i+1) ) |
---|
[1968] | 1036 | num_hole_l = num_hole_l + 1 |
---|
[1942] | 1037 | ENDIF |
---|
| 1038 | ENDDO |
---|
| 1039 | ENDDO |
---|
[114] | 1040 | ! |
---|
[1968] | 1041 | !-- Count the total number of holes, required for informative message. |
---|
| 1042 | #if defined( __parallel ) |
---|
| 1043 | CALL MPI_ALLREDUCE( num_hole_l, num_hole, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 1044 | comm2d, ierr ) |
---|
| 1045 | #else |
---|
| 1046 | num_hole = num_hole_l |
---|
| 1047 | #endif |
---|
| 1048 | ! |
---|
[1942] | 1049 | !-- Create an informative message if any hole was removed. |
---|
[1968] | 1050 | IF ( num_hole > 0 ) THEN |
---|
[1942] | 1051 | WRITE( message_string, * ) num_hole, 'hole(s) resolved by only '//& |
---|
| 1052 | 'one grid point were filled' |
---|
| 1053 | CALL message( 'init_grid', 'PA0430', 0, 0, 0, 6, 0 ) |
---|
| 1054 | ENDIF |
---|
[2232] | 1055 | |
---|
[1942] | 1056 | ! |
---|
[2232] | 1057 | !-- Set bit array to mask topography. Only required for lod = 1 |
---|
| 1058 | IF ( lod == 1 ) THEN |
---|
| 1059 | DO i = nxlg, nxrg |
---|
| 1060 | DO j = nysg, nyng |
---|
| 1061 | topo_3d(nzb_local(j,i)+1:nzt+1,j,i) = & |
---|
| 1062 | IBSET( topo_3d(nzb_local(j,i)+1:nzt+1,j,i), 0 ) |
---|
| 1063 | ENDDO |
---|
| 1064 | ENDDO |
---|
| 1065 | ENDIF |
---|
| 1066 | ! |
---|
[1968] | 1067 | !-- Exchange ghost-points, as well as add cyclic or Neumann boundary |
---|
| 1068 | !-- conditions. |
---|
[2232] | 1069 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
[1968] | 1070 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1071 | |
---|
| 1072 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2232] | 1073 | IF ( nys == 0 ) topo_3d(:,-1,:) = topo_3d(:,0,:) |
---|
| 1074 | IF ( nyn == ny ) topo_3d(:,ny+1,:) = topo_3d(:,ny,:) |
---|
| 1075 | |
---|
[1968] | 1076 | IF ( nys == 0 ) nzb_local(-1,:) = nzb_local(0,:) |
---|
| 1077 | IF ( nyn == ny ) nzb_local(ny+1,:) = nzb_local(ny,:) |
---|
[1910] | 1078 | ENDIF |
---|
[667] | 1079 | |
---|
[1968] | 1080 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2232] | 1081 | IF ( nxl == 0 ) topo_3d(:,:,-1) = topo_3d(:,:,0) |
---|
| 1082 | IF ( nxr == nx ) topo_3d(:,:,nx+1) = topo_3d(:,:,nx) |
---|
| 1083 | |
---|
[1968] | 1084 | IF ( nxl == 0 ) nzb_local(:,-1) = nzb_local(:,0) |
---|
| 1085 | IF ( nxr == nx ) nzb_local(:,nx+1) = nzb_local(:,nx) |
---|
[1910] | 1086 | ENDIF |
---|
| 1087 | |
---|
[2232] | 1088 | |
---|
[1] | 1089 | CASE DEFAULT |
---|
| 1090 | ! |
---|
| 1091 | !-- The DEFAULT case is reached either if the parameter topography |
---|
[217] | 1092 | !-- contains a wrong character string or if the user has defined a special |
---|
[1] | 1093 | !-- case in the user interface. There, the subroutine user_init_grid |
---|
| 1094 | !-- checks which of these two conditions applies. |
---|
[2232] | 1095 | CALL user_init_grid( topo_3d ) |
---|
[1] | 1096 | |
---|
| 1097 | END SELECT |
---|
| 1098 | ! |
---|
| 1099 | !-- Consistency checks and index array initialization are only required for |
---|
[217] | 1100 | !-- non-flat topography, also the initialization of topography height arrays |
---|
[49] | 1101 | !-- zu_s_inner and zw_w_inner |
---|
[1] | 1102 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
[1968] | 1103 | #if defined( __parallel ) |
---|
| 1104 | CALL MPI_ALLREDUCE( MAXVAL( nzb_local ), nzb_local_max, 1, MPI_INTEGER, & |
---|
| 1105 | MPI_MAX, comm2d, ierr ) |
---|
[1982] | 1106 | CALL MPI_ALLREDUCE( MINVAL( nzb_local ), nzb_local_min, 1, MPI_INTEGER, & |
---|
[1968] | 1107 | MPI_MIN, comm2d, ierr ) |
---|
| 1108 | #else |
---|
| 1109 | nzb_local_max = MAXVAL( nzb_local ) |
---|
| 1110 | nzb_local_min = MINVAL( nzb_local ) |
---|
| 1111 | #endif |
---|
[1982] | 1112 | |
---|
[1] | 1113 | ! |
---|
| 1114 | !-- Consistency checks |
---|
[1968] | 1115 | IF ( nzb_local_min < 0 .OR. nzb_local_max > nz + 1 ) THEN |
---|
[1353] | 1116 | WRITE( message_string, * ) 'nzb_local values are outside the', & |
---|
| 1117 | 'model domain', & |
---|
[1968] | 1118 | '&MINVAL( nzb_local ) = ', nzb_local_min, & |
---|
| 1119 | '&MAXVAL( nzb_local ) = ', nzb_local_max |
---|
[254] | 1120 | CALL message( 'init_grid', 'PA0210', 1, 2, 0, 6, 0 ) |
---|
[1] | 1121 | ENDIF |
---|
[2232] | 1122 | ! |
---|
| 1123 | !-- In case of non-flat topography, check whether the convention how to |
---|
| 1124 | !-- define the topography grid has been set correctly, or whether the default |
---|
| 1125 | !-- is applicable. If this is not possible, abort. |
---|
| 1126 | IF ( TRIM( topography_grid_convention ) == ' ' ) THEN |
---|
| 1127 | IF ( TRIM( topography ) /= 'single_building' .AND. & |
---|
| 1128 | TRIM( topography ) /= 'single_street_canyon' .AND. & |
---|
| 1129 | TRIM( topography ) /= 'tunnel' .AND. & |
---|
| 1130 | TRIM( topography ) /= 'read_from_file') THEN |
---|
| 1131 | !-- The default value is not applicable here, because it is only valid |
---|
| 1132 | !-- for the two standard cases 'single_building' and 'read_from_file' |
---|
| 1133 | !-- defined in init_grid. |
---|
| 1134 | WRITE( message_string, * ) & |
---|
| 1135 | 'The value for "topography_grid_convention" ', & |
---|
| 1136 | 'is not set. Its default value is & only valid for ', & |
---|
| 1137 | '"topography" = ''single_building'', ', & |
---|
| 1138 | '''single_street_canyon'' & or ''read_from_file''.', & |
---|
| 1139 | ' & Choose ''cell_edge'' or ''cell_center''.' |
---|
| 1140 | CALL message( 'init_grid', 'PA0239', 1, 2, 0, 6, 0 ) |
---|
| 1141 | ELSE |
---|
| 1142 | !-- The default value is applicable here. |
---|
| 1143 | !-- Set convention according to topography. |
---|
| 1144 | IF ( TRIM( topography ) == 'single_building' .OR. & |
---|
| 1145 | TRIM( topography ) == 'single_street_canyon' ) THEN |
---|
| 1146 | topography_grid_convention = 'cell_edge' |
---|
| 1147 | ELSEIF ( TRIM( topography ) == 'read_from_file' .OR. & |
---|
| 1148 | TRIM( topography ) == 'tunnel') THEN |
---|
| 1149 | topography_grid_convention = 'cell_center' |
---|
| 1150 | ENDIF |
---|
| 1151 | ENDIF |
---|
| 1152 | ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND. & |
---|
| 1153 | TRIM( topography_grid_convention ) /= 'cell_center' ) THEN |
---|
| 1154 | WRITE( message_string, * ) & |
---|
| 1155 | 'The value for "topography_grid_convention" is ', & |
---|
| 1156 | 'not recognized. & Choose ''cell_edge'' or ''cell_center''.' |
---|
| 1157 | CALL message( 'init_grid', 'PA0240', 1, 2, 0, 6, 0 ) |
---|
| 1158 | ENDIF |
---|
[1] | 1159 | |
---|
[2169] | 1160 | ! |
---|
| 1161 | !-- In case of non-flat topography, check whether the convention how to |
---|
| 1162 | !-- define the topography grid has been set correctly, or whether the default |
---|
| 1163 | !-- is applicable. If this is not possible, abort. |
---|
| 1164 | IF ( TRIM( topography_grid_convention ) == ' ' ) THEN |
---|
| 1165 | IF ( TRIM( topography ) /= 'single_building' .AND. & |
---|
| 1166 | TRIM( topography ) /= 'single_street_canyon' .AND. & |
---|
| 1167 | TRIM( topography ) /= 'read_from_file' ) THEN |
---|
| 1168 | !-- The default value is not applicable here, because it is only valid |
---|
| 1169 | !-- for the two standard cases 'single_building' and 'read_from_file' |
---|
| 1170 | !-- defined in init_grid. |
---|
| 1171 | WRITE( message_string, * ) & |
---|
| 1172 | 'The value for "topography_grid_convention" ', & |
---|
| 1173 | 'is not set. Its default value is & only valid for ', & |
---|
| 1174 | '"topography" = ''single_building'', ', & |
---|
| 1175 | '''single_street_canyon'' & or ''read_from_file''.', & |
---|
| 1176 | ' & Choose ''cell_edge'' or ''cell_center''.' |
---|
| 1177 | CALL message( 'init_grid', 'PA0239', 1, 2, 0, 6, 0 ) |
---|
| 1178 | ELSE |
---|
| 1179 | !-- The default value is applicable here. |
---|
| 1180 | !-- Set convention according to topography. |
---|
| 1181 | IF ( TRIM( topography ) == 'single_building' .OR. & |
---|
| 1182 | TRIM( topography ) == 'single_street_canyon' ) THEN |
---|
| 1183 | topography_grid_convention = 'cell_edge' |
---|
| 1184 | ELSEIF ( TRIM( topography ) == 'read_from_file' ) THEN |
---|
| 1185 | topography_grid_convention = 'cell_center' |
---|
| 1186 | ENDIF |
---|
| 1187 | ENDIF |
---|
| 1188 | ELSEIF ( TRIM( topography_grid_convention ) /= 'cell_edge' .AND. & |
---|
| 1189 | TRIM( topography_grid_convention ) /= 'cell_center' ) THEN |
---|
| 1190 | WRITE( message_string, * ) & |
---|
| 1191 | 'The value for "topography_grid_convention" is ', & |
---|
| 1192 | 'not recognized. & Choose ''cell_edge'' or ''cell_center''.' |
---|
| 1193 | CALL message( 'init_grid', 'PA0240', 1, 2, 0, 6, 0 ) |
---|
| 1194 | ENDIF |
---|
| 1195 | |
---|
[217] | 1196 | IF ( topography_grid_convention == 'cell_edge' ) THEN |
---|
[134] | 1197 | ! |
---|
[217] | 1198 | !-- The array nzb_local as defined using the 'cell_edge' convention |
---|
| 1199 | !-- describes the actual total size of topography which is defined at the |
---|
| 1200 | !-- cell edges where u=0 on the topography walls in x-direction and v=0 |
---|
| 1201 | !-- on the topography walls in y-direction. However, PALM uses individual |
---|
| 1202 | !-- arrays nzb_u|v|w|s_inner|outer that are based on nzb_s_inner. |
---|
| 1203 | !-- Therefore, the extent of topography in nzb_local is now reduced by |
---|
| 1204 | !-- 1dx at the E topography walls and by 1dy at the N topography walls |
---|
[1968] | 1205 | !-- to form the basis for nzb_s_inner. |
---|
| 1206 | !-- Note, the reverse memory access (i-j instead of j-i) is absolutely |
---|
| 1207 | !-- required at this point. |
---|
| 1208 | DO j = nys+1, nyn+1 |
---|
| 1209 | DO i = nxl-1, nxr |
---|
[217] | 1210 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j,i+1) ) |
---|
| 1211 | ENDDO |
---|
[134] | 1212 | ENDDO |
---|
[1968] | 1213 | ! |
---|
| 1214 | !-- Exchange ghost points |
---|
| 1215 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1216 | |
---|
| 1217 | DO i = nxl, nxr+1 |
---|
| 1218 | DO j = nys-1, nyn |
---|
[217] | 1219 | nzb_local(j,i) = MIN( nzb_local(j,i), nzb_local(j+1,i) ) |
---|
| 1220 | ENDDO |
---|
[2232] | 1221 | ENDDO |
---|
[1968] | 1222 | ! |
---|
| 1223 | !-- Exchange ghost points |
---|
| 1224 | CALL exchange_horiz_2d_int( nzb_local, nys, nyn, nxl, nxr, nbgp ) |
---|
[2232] | 1225 | ! |
---|
| 1226 | !-- Apply cell-edge convention also for 3D topo array. The former setting |
---|
| 1227 | !-- of nzb_local will be removed later. |
---|
| 1228 | DO j = nys+1, nyn+1 |
---|
| 1229 | DO i = nxl-1, nxr |
---|
| 1230 | DO k = nzb, nzt+1 |
---|
| 1231 | IF ( BTEST( topo_3d(k,j,i), 0 ) .OR. & |
---|
| 1232 | BTEST( topo_3d(k,j,i+1), 0 ) ) & |
---|
| 1233 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 0 ) |
---|
| 1234 | ENDDO |
---|
| 1235 | ENDDO |
---|
| 1236 | ENDDO |
---|
| 1237 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
| 1238 | |
---|
| 1239 | DO i = nxl, nxr+1 |
---|
| 1240 | DO j = nys-1, nyn |
---|
| 1241 | DO k = nzb, nzt+1 |
---|
| 1242 | IF ( BTEST( topo_3d(k,j,i), 0 ) .OR. & |
---|
| 1243 | BTEST( topo_3d(k,j+1,i), 0 ) ) & |
---|
| 1244 | topo_3d(k,j,i) = IBSET( topo_3d(k,j,i), 0 ) |
---|
| 1245 | ENDDO |
---|
| 1246 | ENDDO |
---|
| 1247 | ENDDO |
---|
| 1248 | CALL exchange_horiz_int( topo_3d, nbgp ) |
---|
| 1249 | |
---|
[217] | 1250 | ENDIF |
---|
[2232] | 1251 | |
---|
[1] | 1252 | ! |
---|
| 1253 | !-- Initialize index arrays nzb_s_inner and nzb_w_inner |
---|
[2232] | 1254 | |
---|
[1968] | 1255 | nzb_s_inner = nzb_local |
---|
| 1256 | nzb_w_inner = nzb_local |
---|
[1] | 1257 | |
---|
| 1258 | ! |
---|
| 1259 | !-- Initialize remaining index arrays: |
---|
| 1260 | !-- first pre-initialize them with nzb_s_inner... |
---|
| 1261 | nzb_u_inner = nzb_s_inner |
---|
| 1262 | nzb_u_outer = nzb_s_inner |
---|
| 1263 | nzb_v_inner = nzb_s_inner |
---|
| 1264 | nzb_v_outer = nzb_s_inner |
---|
| 1265 | nzb_w_outer = nzb_s_inner |
---|
| 1266 | nzb_s_outer = nzb_s_inner |
---|
| 1267 | |
---|
| 1268 | ! |
---|
| 1269 | !-- ...then extend pre-initialized arrays in their according directions |
---|
| 1270 | !-- based on nzb_local using nzb_tmp as a temporary global index array |
---|
| 1271 | |
---|
| 1272 | ! |
---|
| 1273 | !-- nzb_s_outer: |
---|
| 1274 | !-- extend nzb_local east-/westwards first, then north-/southwards |
---|
[1968] | 1275 | nzb_tmp = nzb_local |
---|
| 1276 | DO j = nys, nyn |
---|
| 1277 | DO i = nxl, nxr |
---|
[1353] | 1278 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i), & |
---|
[1] | 1279 | nzb_local(j,i+1) ) |
---|
| 1280 | ENDDO |
---|
| 1281 | ENDDO |
---|
[1968] | 1282 | |
---|
| 1283 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1284 | |
---|
[1] | 1285 | DO i = nxl, nxr |
---|
| 1286 | DO j = nys, nyn |
---|
[1353] | 1287 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
[1] | 1288 | nzb_tmp(j+1,i) ) |
---|
| 1289 | ENDDO |
---|
| 1290 | ! |
---|
| 1291 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
| 1292 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
| 1293 | IF ( nys == 0 ) THEN |
---|
| 1294 | j = -1 |
---|
| 1295 | nzb_s_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
| 1296 | ENDIF |
---|
[1743] | 1297 | IF ( nyn == ny ) THEN |
---|
[1] | 1298 | j = ny + 1 |
---|
| 1299 | nzb_s_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
| 1300 | ENDIF |
---|
| 1301 | ENDDO |
---|
| 1302 | ! |
---|
| 1303 | !-- nzb_w_outer: |
---|
| 1304 | !-- identical to nzb_s_outer |
---|
| 1305 | nzb_w_outer = nzb_s_outer |
---|
| 1306 | |
---|
| 1307 | ! |
---|
| 1308 | !-- nzb_u_inner: |
---|
| 1309 | !-- extend nzb_local rightwards only |
---|
[1968] | 1310 | nzb_tmp = nzb_local |
---|
| 1311 | DO j = nys, nyn |
---|
| 1312 | DO i = nxl, nxr |
---|
[1] | 1313 | nzb_tmp(j,i) = MAX( nzb_local(j,i-1), nzb_local(j,i) ) |
---|
| 1314 | ENDDO |
---|
| 1315 | ENDDO |
---|
[1968] | 1316 | |
---|
| 1317 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1318 | |
---|
| 1319 | nzb_u_inner = nzb_tmp |
---|
[1] | 1320 | ! |
---|
| 1321 | !-- nzb_u_outer: |
---|
| 1322 | !-- extend current nzb_tmp (nzb_u_inner) north-/southwards |
---|
| 1323 | DO i = nxl, nxr |
---|
| 1324 | DO j = nys, nyn |
---|
[1353] | 1325 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i), & |
---|
[1] | 1326 | nzb_tmp(j+1,i) ) |
---|
| 1327 | ENDDO |
---|
| 1328 | ! |
---|
| 1329 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
| 1330 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
| 1331 | IF ( nys == 0 ) THEN |
---|
| 1332 | j = -1 |
---|
| 1333 | nzb_u_outer(j,i) = MAX( nzb_tmp(j+1,i), nzb_tmp(j,i) ) |
---|
| 1334 | ENDIF |
---|
[1743] | 1335 | IF ( nyn == ny ) THEN |
---|
[1] | 1336 | j = ny + 1 |
---|
| 1337 | nzb_u_outer(j,i) = MAX( nzb_tmp(j-1,i), nzb_tmp(j,i) ) |
---|
| 1338 | ENDIF |
---|
| 1339 | ENDDO |
---|
| 1340 | |
---|
| 1341 | ! |
---|
| 1342 | !-- nzb_v_inner: |
---|
| 1343 | !-- extend nzb_local northwards only |
---|
[1968] | 1344 | nzb_tmp = nzb_local |
---|
| 1345 | DO i = nxl, nxr |
---|
| 1346 | DO j = nys, nyn |
---|
[1] | 1347 | nzb_tmp(j,i) = MAX( nzb_local(j-1,i), nzb_local(j,i) ) |
---|
| 1348 | ENDDO |
---|
| 1349 | ENDDO |
---|
[1968] | 1350 | |
---|
| 1351 | CALL exchange_horiz_2d_int( nzb_tmp, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1352 | nzb_v_inner = nzb_tmp |
---|
[1] | 1353 | |
---|
| 1354 | ! |
---|
| 1355 | !-- nzb_v_outer: |
---|
| 1356 | !-- extend current nzb_tmp (nzb_v_inner) right-/leftwards |
---|
| 1357 | DO j = nys, nyn |
---|
| 1358 | DO i = nxl, nxr |
---|
[1353] | 1359 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i), & |
---|
[1] | 1360 | nzb_tmp(j,i+1) ) |
---|
| 1361 | ENDDO |
---|
| 1362 | ! |
---|
| 1363 | !-- non-cyclic boundary conditions (overwritten by call of |
---|
| 1364 | !-- exchange_horiz_2d_int below in case of cyclic boundary conditions) |
---|
| 1365 | IF ( nxl == 0 ) THEN |
---|
| 1366 | i = -1 |
---|
| 1367 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i+1), nzb_tmp(j,i) ) |
---|
| 1368 | ENDIF |
---|
| 1369 | IF ( nxr == nx ) THEN |
---|
| 1370 | i = nx + 1 |
---|
| 1371 | nzb_v_outer(j,i) = MAX( nzb_tmp(j,i-1), nzb_tmp(j,i) ) |
---|
| 1372 | ENDIF |
---|
| 1373 | ENDDO |
---|
[1804] | 1374 | |
---|
[1] | 1375 | ! |
---|
| 1376 | !-- Exchange of lateral boundary values (parallel computers) and cyclic |
---|
| 1377 | !-- boundary conditions, if applicable. |
---|
| 1378 | !-- Since nzb_s_inner and nzb_w_inner are derived directly from nzb_local |
---|
| 1379 | !-- they do not require exchange and are not included here. |
---|
[1968] | 1380 | CALL exchange_horiz_2d_int( nzb_u_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1381 | CALL exchange_horiz_2d_int( nzb_u_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1382 | CALL exchange_horiz_2d_int( nzb_v_inner, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1383 | CALL exchange_horiz_2d_int( nzb_v_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1384 | CALL exchange_horiz_2d_int( nzb_w_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
| 1385 | CALL exchange_horiz_2d_int( nzb_s_outer, nys, nyn, nxl, nxr, nbgp ) |
---|
[1] | 1386 | |
---|
[2232] | 1387 | ENDIF |
---|
[49] | 1388 | ! |
---|
[2232] | 1389 | !-- Deallocate temporary array, as it might be reused for different |
---|
| 1390 | !-- grid-levels further below. |
---|
| 1391 | DEALLOCATE( nzb_tmp ) |
---|
| 1392 | |
---|
| 1393 | ! |
---|
| 1394 | !-- Determine the maximum level of topography. It is used for |
---|
| 1395 | !-- steering the degradation of order of the applied advection scheme. |
---|
| 1396 | !-- In case of non-cyclic lateral boundaries, the order of the advection |
---|
| 1397 | !-- scheme has to be reduced up to nzt (required at the lateral boundaries). |
---|
| 1398 | k_top = 0 |
---|
| 1399 | DO i = nxl, nxr |
---|
| 1400 | DO j = nys, nyn |
---|
| 1401 | DO k = nzb, nzt + 1 |
---|
| 1402 | k_top = MAX( k_top, MERGE( k, 0, & |
---|
| 1403 | .NOT. BTEST( topo_3d(k,j,i), 0 ) ) ) |
---|
[1968] | 1404 | ENDDO |
---|
| 1405 | ENDDO |
---|
[2232] | 1406 | ENDDO |
---|
[1968] | 1407 | #if defined( __parallel ) |
---|
[2232] | 1408 | CALL MPI_ALLREDUCE( k_top + 1, nzb_max, 1, MPI_INTEGER, & !is +1 really necessary here? |
---|
| 1409 | MPI_MAX, comm2d, ierr ) |
---|
[1968] | 1410 | #else |
---|
[2232] | 1411 | nzb_max = k_top + 1 |
---|
[1968] | 1412 | #endif |
---|
[2232] | 1413 | IF ( inflow_l .OR. outflow_l .OR. inflow_r .OR. outflow_r .OR. & |
---|
| 1414 | inflow_n .OR. outflow_n .OR. inflow_s .OR. outflow_s .OR. & |
---|
| 1415 | nest_domain ) & |
---|
| 1416 | THEN |
---|
| 1417 | nzb_max = nzt |
---|
[1] | 1418 | ENDIF |
---|
[1968] | 1419 | ! |
---|
[2232] | 1420 | !-- Finally, if topography extents up to the model top, limit nzb_max to nzt. |
---|
| 1421 | nzb_max = MIN( nzb_max, nzt ) |
---|
[1] | 1422 | |
---|
| 1423 | ! |
---|
| 1424 | !-- Set the individual index arrays which define the k index from which on |
---|
| 1425 | !-- the usual finite difference form (which does not use surface fluxes) is |
---|
| 1426 | !-- applied |
---|
[1691] | 1427 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
[1] | 1428 | nzb_diff_s_inner = nzb_s_inner + 2 |
---|
| 1429 | nzb_diff_s_outer = nzb_s_outer + 2 |
---|
| 1430 | ELSE |
---|
| 1431 | nzb_diff_s_inner = nzb_s_inner + 1 |
---|
| 1432 | nzb_diff_s_outer = nzb_s_outer + 1 |
---|
| 1433 | ENDIF |
---|
| 1434 | |
---|
| 1435 | ! |
---|
[2232] | 1436 | !-- Set-up topography flags. First, set flags only for s, u, v and w-grid. |
---|
| 1437 | !-- Further special flags will be set in following loops. |
---|
| 1438 | wall_flags_0 = 0 |
---|
| 1439 | DO j = nys, nyn |
---|
| 1440 | DO i = nxl, nxr |
---|
| 1441 | DO k = nzb, nzt+1 |
---|
| 1442 | ! |
---|
| 1443 | !-- scalar grid |
---|
| 1444 | IF ( BTEST( topo_3d(k,j,i), 0 ) ) & |
---|
| 1445 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 0 ) |
---|
| 1446 | ! |
---|
| 1447 | !-- v grid |
---|
| 1448 | IF ( BTEST( topo_3d(k,j,i), 0 ) .AND. & |
---|
| 1449 | BTEST( topo_3d(k,j-1,i), 0 ) ) & |
---|
| 1450 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 2 ) |
---|
| 1451 | ! |
---|
| 1452 | !-- To do: set outer arrays on basis of topo_3d array, adjust for downward-facing walls |
---|
| 1453 | !-- s grid outer array |
---|
| 1454 | IF ( k >= nzb_s_outer(j,i) ) & |
---|
| 1455 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 24 ) |
---|
| 1456 | ! |
---|
| 1457 | !-- s grid outer array |
---|
| 1458 | IF ( k >= nzb_u_outer(j,i) ) & |
---|
| 1459 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 26 ) |
---|
| 1460 | ! |
---|
| 1461 | !-- s grid outer array |
---|
| 1462 | IF ( k >= nzb_v_outer(j,i) ) & |
---|
| 1463 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 27 ) |
---|
| 1464 | ! |
---|
| 1465 | !-- w grid outer array |
---|
| 1466 | IF ( k >= nzb_w_outer(j,i) ) & |
---|
| 1467 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 28 ) |
---|
| 1468 | ENDDO |
---|
[1] | 1469 | |
---|
[2232] | 1470 | DO k = nzb, nzt |
---|
[1] | 1471 | ! |
---|
[2232] | 1472 | !-- w grid |
---|
| 1473 | IF ( BTEST( topo_3d(k,j,i), 0 ) .AND. & |
---|
| 1474 | BTEST( topo_3d(k+1,j,i), 0 ) ) & |
---|
| 1475 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 3 ) |
---|
| 1476 | ENDDO |
---|
| 1477 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 3 ) |
---|
| 1478 | |
---|
| 1479 | ENDDO |
---|
| 1480 | ENDDO |
---|
[1] | 1481 | ! |
---|
[2232] | 1482 | !-- u grid. Note, reverse |
---|
| 1483 | !-- memory access is required for setting flag on u-grid |
---|
| 1484 | DO j = nys, nyn |
---|
| 1485 | DO i = nxl, nxr |
---|
| 1486 | DO k = nzb, nzt+1 |
---|
| 1487 | IF ( BTEST( topo_3d(k,j,i), 0 ) .AND. & |
---|
| 1488 | BTEST( topo_3d(k,j,i-1), 0 ) ) & |
---|
| 1489 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 1 ) |
---|
| 1490 | ENDDO |
---|
| 1491 | ENDDO |
---|
| 1492 | ENDDO |
---|
[1] | 1493 | ! |
---|
[2232] | 1494 | !-- Set further special flags |
---|
| 1495 | DO i = nxl, nxr |
---|
| 1496 | DO j = nys, nyn |
---|
| 1497 | DO k = nzb, nzt+1 |
---|
[1] | 1498 | ! |
---|
[2232] | 1499 | !-- scalar grid, former nzb_diff_s_inner. |
---|
| 1500 | !-- Note, use this flag also to mask topography in diffusion_u and |
---|
| 1501 | !-- diffusion_v along the vertical direction. In case of |
---|
| 1502 | !-- use_surface_fluxes, fluxes are calculated via MOST, else, simple |
---|
| 1503 | !-- gradient approach is applied. Please note, in case of u- and v- |
---|
| 1504 | !-- diffuison, a small error is made at edges (on the east side for u, |
---|
| 1505 | !-- at the north side for v), since topography on scalar grid point |
---|
| 1506 | !-- is used instead of topography on u/v-grid. As number of topography grid |
---|
| 1507 | !-- points on uv-grid is different than s-grid, different number of |
---|
| 1508 | !-- surface elements would be required. In order to avoid this, |
---|
| 1509 | !-- treat edges (u(k,j,i+1)) simply by a gradient approach, i.e. these |
---|
| 1510 | !-- points are not masked within diffusion_u. Tests had shown that the |
---|
| 1511 | !-- effect on the flow is negligible. |
---|
| 1512 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
| 1513 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
| 1514 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) |
---|
| 1515 | ELSE |
---|
| 1516 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 8 ) |
---|
| 1517 | ENDIF |
---|
[1] | 1518 | |
---|
[2232] | 1519 | ENDDO |
---|
| 1520 | ! |
---|
| 1521 | !-- Special flag to control vertical diffusion at model top - former |
---|
| 1522 | !-- nzt_diff |
---|
| 1523 | wall_flags_0(:,j,i) = IBSET( wall_flags_0(:,j,i), 9 ) |
---|
| 1524 | IF ( use_top_fluxes ) & |
---|
| 1525 | wall_flags_0(nzt:nzt+1,j,i) = IBCLR( wall_flags_0(nzt:nzt+1,j,i), 9 ) |
---|
[1] | 1526 | |
---|
[2232] | 1527 | DO k = nzb+1, nzt |
---|
| 1528 | ! |
---|
| 1529 | !-- Special flag on u grid, former nzb_u_inner + 1, required |
---|
| 1530 | !-- for disturb_field and initialization. Do not disturb directly at |
---|
| 1531 | !-- topography, as well as initialize u with zero one grid point outside |
---|
| 1532 | !-- of topography. |
---|
| 1533 | IF ( BTEST( wall_flags_0(k-1,j,i), 1 ) .AND. & |
---|
| 1534 | BTEST( wall_flags_0(k,j,i), 1 ) .AND. & |
---|
| 1535 | BTEST( wall_flags_0(k+1,j,i), 1 ) ) & |
---|
| 1536 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 20 ) |
---|
| 1537 | ! |
---|
| 1538 | !-- Special flag on v grid, former nzb_v_inner + 1, required |
---|
| 1539 | !-- for disturb_field and initialization. Do not disturb directly at |
---|
| 1540 | !-- topography, as well as initialize v with zero one grid point outside |
---|
| 1541 | !-- of topography. |
---|
| 1542 | IF ( BTEST( wall_flags_0(k-1,j,i), 2 ) .AND. & |
---|
| 1543 | BTEST( wall_flags_0(k,j,i), 2 ) .AND. & |
---|
| 1544 | BTEST( wall_flags_0(k+1,j,i), 2 ) ) & |
---|
| 1545 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 21 ) |
---|
| 1546 | ! |
---|
| 1547 | !-- Special flag on scalar grid, former nzb_s_inner+1. Used for |
---|
| 1548 | !-- lpm_sgs_tke |
---|
| 1549 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
| 1550 | BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
| 1551 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1552 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 25 ) |
---|
| 1553 | ! |
---|
| 1554 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in |
---|
| 1555 | !-- in production_e |
---|
| 1556 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
| 1557 | IF ( BTEST( wall_flags_0(k,j,i), 24 ) .AND. & |
---|
| 1558 | BTEST( wall_flags_0(k-1,j,i), 24 ) .AND. & |
---|
| 1559 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1560 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 29 ) |
---|
| 1561 | ELSE |
---|
| 1562 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
| 1563 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 29 ) |
---|
[1] | 1564 | ENDIF |
---|
[2232] | 1565 | ! |
---|
| 1566 | !-- Special flag on scalar grid, nzb_diff_s_outer - 1, required in |
---|
| 1567 | !-- in production_e |
---|
| 1568 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
| 1569 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
| 1570 | BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
| 1571 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1572 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) |
---|
| 1573 | ELSE |
---|
| 1574 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
| 1575 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 30 ) |
---|
| 1576 | ENDIF |
---|
| 1577 | ENDDO |
---|
| 1578 | ! |
---|
| 1579 | !-- Flags indicating downward facing walls |
---|
| 1580 | DO k = nzb+1, nzt |
---|
| 1581 | ! |
---|
| 1582 | !-- Scalar grid |
---|
| 1583 | IF ( BTEST( wall_flags_0(k-1,j,i), 0 ) .AND. & |
---|
| 1584 | .NOT. BTEST( wall_flags_0(k,j,i), 0 ) ) & |
---|
| 1585 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 13 ) |
---|
| 1586 | ! |
---|
| 1587 | !-- Downward facing wall on u grid |
---|
| 1588 | IF ( BTEST( wall_flags_0(k-1,j,i), 1 ) .AND. & |
---|
| 1589 | .NOT. BTEST( wall_flags_0(k,j,i), 1 ) ) & |
---|
| 1590 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 15 ) |
---|
| 1591 | ! |
---|
| 1592 | !-- Downward facing wall on v grid |
---|
| 1593 | IF ( BTEST( wall_flags_0(k-1,j,i), 2 ) .AND. & |
---|
| 1594 | .NOT. BTEST( wall_flags_0(k,j,i), 2 ) ) & |
---|
| 1595 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 17 ) |
---|
| 1596 | ! |
---|
| 1597 | !-- Downward facing wall on w grid |
---|
| 1598 | IF ( BTEST( wall_flags_0(k-1,j,i), 3 ) .AND. & |
---|
| 1599 | .NOT. BTEST( wall_flags_0(k,j,i), 3 ) ) & |
---|
| 1600 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 19 ) |
---|
| 1601 | ENDDO |
---|
| 1602 | ! |
---|
| 1603 | !-- Flags indicating upward facing walls |
---|
| 1604 | DO k = nzb, nzt |
---|
| 1605 | ! |
---|
| 1606 | !-- Upward facing wall on scalar grid |
---|
| 1607 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
| 1608 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1609 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 12 ) |
---|
| 1610 | ! |
---|
| 1611 | !-- Upward facing wall on u grid |
---|
| 1612 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 1 ) .AND. & |
---|
| 1613 | BTEST( wall_flags_0(k+1,j,i), 1 ) ) & |
---|
| 1614 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 14 ) |
---|
[1] | 1615 | |
---|
[2232] | 1616 | ! |
---|
| 1617 | !-- Upward facing wall on v grid |
---|
| 1618 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 2 ) .AND. & |
---|
| 1619 | BTEST( wall_flags_0(k+1,j,i), 2 ) ) & |
---|
| 1620 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 16 ) |
---|
| 1621 | |
---|
| 1622 | ! |
---|
| 1623 | !-- Upward facing wall on w grid |
---|
| 1624 | IF ( .NOT. BTEST( wall_flags_0(k,j,i), 3 ) .AND. & |
---|
| 1625 | BTEST( wall_flags_0(k+1,j,i), 3 ) ) & |
---|
| 1626 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 18 ) |
---|
| 1627 | ! |
---|
| 1628 | !-- Special flag on scalar grid, former nzb_s_inner |
---|
| 1629 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .OR. & |
---|
| 1630 | BTEST( wall_flags_0(k,j,i), 12 ) .OR. & |
---|
| 1631 | BTEST( wall_flags_0(k,j,i), 13 ) ) & |
---|
| 1632 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 22 ) |
---|
| 1633 | ! |
---|
| 1634 | !-- Special flag on scalar grid, nzb_diff_s_inner - 1, required for |
---|
| 1635 | !-- flow_statistics |
---|
| 1636 | IF ( constant_flux_layer .OR. use_surface_fluxes ) THEN |
---|
| 1637 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) .AND. & |
---|
| 1638 | BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1639 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) |
---|
| 1640 | ELSE |
---|
| 1641 | IF ( BTEST( wall_flags_0(k,j,i), 22 ) ) & |
---|
| 1642 | wall_flags_0(k,j,i) = IBSET( wall_flags_0(k,j,i), 23 ) |
---|
[1] | 1643 | ENDIF |
---|
| 1644 | |
---|
| 1645 | |
---|
[2232] | 1646 | ENDDO |
---|
| 1647 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 22 ) |
---|
| 1648 | wall_flags_0(nzt+1,j,i) = IBSET( wall_flags_0(nzt+1,j,i), 23 ) |
---|
| 1649 | ENDDO |
---|
| 1650 | ENDDO |
---|
| 1651 | ! |
---|
| 1652 | !-- Exchange ghost points for wall flags |
---|
| 1653 | CALL exchange_horiz_int( wall_flags_0, nbgp ) |
---|
| 1654 | ! |
---|
| 1655 | !-- Set boundary conditions also for flags. Can be interpreted as Neumann |
---|
| 1656 | !-- boundary conditions for topography. |
---|
| 1657 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
| 1658 | IF ( nys == 0 ) wall_flags_0(:,-1,:) = wall_flags_0(:,0,:) |
---|
| 1659 | IF ( nyn == ny ) wall_flags_0(:,ny+1,:) = wall_flags_0(:,ny,:) |
---|
| 1660 | ENDIF |
---|
| 1661 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
| 1662 | IF ( nxl == 0 ) wall_flags_0(:,:,-1) = wall_flags_0(:,:,0) |
---|
| 1663 | IF ( nxr == nx ) wall_flags_0(:,:,nx+1) = wall_flags_0(:,:,nx) |
---|
| 1664 | ENDIF |
---|
[1] | 1665 | |
---|
[2232] | 1666 | ! |
---|
| 1667 | !-- Initialize boundary conditions via surface type |
---|
| 1668 | CALL init_bc |
---|
| 1669 | ! |
---|
| 1670 | !-- Allocate and set topography height arrays required for data output |
---|
| 1671 | IF ( TRIM( topography ) /= 'flat' ) THEN |
---|
| 1672 | ! |
---|
| 1673 | !-- Allocate and set the arrays containing the topography height |
---|
[1] | 1674 | |
---|
[2232] | 1675 | IF ( nxr == nx .AND. nyn /= ny ) THEN |
---|
| 1676 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn), & |
---|
| 1677 | zw_w_inner(nxl:nxr+1,nys:nyn) ) |
---|
| 1678 | ELSEIF ( nxr /= nx .AND. nyn == ny ) THEN |
---|
| 1679 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn+1), & |
---|
| 1680 | zw_w_inner(nxl:nxr,nys:nyn+1) ) |
---|
| 1681 | ELSEIF ( nxr == nx .AND. nyn == ny ) THEN |
---|
| 1682 | ALLOCATE( zu_s_inner(nxl:nxr+1,nys:nyn+1), & |
---|
| 1683 | zw_w_inner(nxl:nxr+1,nys:nyn+1) ) |
---|
| 1684 | ELSE |
---|
| 1685 | ALLOCATE( zu_s_inner(nxl:nxr,nys:nyn), & |
---|
| 1686 | zw_w_inner(nxl:nxr,nys:nyn) ) |
---|
| 1687 | ENDIF |
---|
[1] | 1688 | |
---|
[2232] | 1689 | zu_s_inner = 0.0_wp |
---|
| 1690 | zw_w_inner = 0.0_wp |
---|
| 1691 | ! |
---|
| 1692 | !-- Determine local topography height on scalar and w-grid. Note, setting |
---|
| 1693 | !-- lateral boundary values is not necessary, realized via wall_flags_0 |
---|
| 1694 | !-- array. Further, please note that loop bounds are different from |
---|
| 1695 | !-- nxl to nxr and nys to nyn on south and right model boundary, hence, |
---|
| 1696 | !-- use intrinsic lbound and ubound functions to infer array bounds. |
---|
| 1697 | DO i = lbound(zu_s_inner, 1), ubound(zu_s_inner, 1) |
---|
| 1698 | DO j = lbound(zu_s_inner, 2), ubound(zu_s_inner, 2) |
---|
| 1699 | ! |
---|
| 1700 | !-- Topography height on scalar grid. Therefore, determine index of |
---|
| 1701 | !-- upward-facing surface element on scalar grid (bit 12). |
---|
| 1702 | zu_s_inner(i,j) = zu( MAXLOC( MERGE( & |
---|
| 1703 | 1, 0, BTEST( wall_flags_0(:,j,i), 12 )& |
---|
| 1704 | ), DIM = 1 & |
---|
| 1705 | ) - 1 & |
---|
| 1706 | ) |
---|
| 1707 | ! |
---|
| 1708 | !-- Topography height on w grid. Therefore, determine index of |
---|
| 1709 | !-- upward-facing surface element on w grid (bit 18). |
---|
| 1710 | zw_w_inner(i,j) = zw( MAXLOC( MERGE( & |
---|
| 1711 | 1, 0, BTEST( wall_flags_0(:,j,i), 18 )& |
---|
| 1712 | ), DIM = 1 & |
---|
| 1713 | ) - 1 & |
---|
| 1714 | ) |
---|
| 1715 | ENDDO |
---|
| 1716 | ENDDO |
---|
[1] | 1717 | |
---|
| 1718 | |
---|
[2232] | 1719 | ENDIF |
---|
[1] | 1720 | |
---|
| 1721 | ! |
---|
[1931] | 1722 | !-- Calculate wall flag arrays for the multigrid method. |
---|
| 1723 | !-- Please note, wall flags are only applied in the not cache-optimized |
---|
| 1724 | !-- version. |
---|
| 1725 | IF ( psolver == 'multigrid_noopt' ) THEN |
---|
[1968] | 1726 | |
---|
[114] | 1727 | ! |
---|
[1968] | 1728 | !-- Gridpoint increment of the current level. |
---|
[114] | 1729 | inc = 1 |
---|
| 1730 | DO l = maximum_grid_level, 1 , -1 |
---|
[1968] | 1731 | ! |
---|
| 1732 | !-- Set grid_level as it is required for exchange_horiz_2d_int |
---|
| 1733 | grid_level = l |
---|
[114] | 1734 | |
---|
| 1735 | nxl_l = nxl_mg(l) |
---|
| 1736 | nxr_l = nxr_mg(l) |
---|
| 1737 | nys_l = nys_mg(l) |
---|
| 1738 | nyn_l = nyn_mg(l) |
---|
| 1739 | nzt_l = nzt_mg(l) |
---|
| 1740 | ! |
---|
| 1741 | !-- Assign the flag level to be calculated |
---|
| 1742 | SELECT CASE ( l ) |
---|
| 1743 | CASE ( 1 ) |
---|
| 1744 | flags => wall_flags_1 |
---|
| 1745 | CASE ( 2 ) |
---|
| 1746 | flags => wall_flags_2 |
---|
| 1747 | CASE ( 3 ) |
---|
| 1748 | flags => wall_flags_3 |
---|
| 1749 | CASE ( 4 ) |
---|
| 1750 | flags => wall_flags_4 |
---|
| 1751 | CASE ( 5 ) |
---|
| 1752 | flags => wall_flags_5 |
---|
| 1753 | CASE ( 6 ) |
---|
| 1754 | flags => wall_flags_6 |
---|
| 1755 | CASE ( 7 ) |
---|
| 1756 | flags => wall_flags_7 |
---|
| 1757 | CASE ( 8 ) |
---|
| 1758 | flags => wall_flags_8 |
---|
| 1759 | CASE ( 9 ) |
---|
| 1760 | flags => wall_flags_9 |
---|
| 1761 | CASE ( 10 ) |
---|
| 1762 | flags => wall_flags_10 |
---|
| 1763 | END SELECT |
---|
| 1764 | |
---|
| 1765 | ! |
---|
| 1766 | !-- Depending on the grid level, set the respective bits in case of |
---|
| 1767 | !-- neighbouring walls |
---|
| 1768 | !-- Bit 0: wall to the bottom |
---|
| 1769 | !-- Bit 1: wall to the top (not realized in remaining PALM code so far) |
---|
| 1770 | !-- Bit 2: wall to the south |
---|
| 1771 | !-- Bit 3: wall to the north |
---|
| 1772 | !-- Bit 4: wall to the left |
---|
| 1773 | !-- Bit 5: wall to the right |
---|
[116] | 1774 | !-- Bit 6: inside building |
---|
[114] | 1775 | |
---|
| 1776 | flags = 0 |
---|
| 1777 | |
---|
[927] | 1778 | ! |
---|
| 1779 | !-- In case of masking method, flags are not set and multigrid method |
---|
| 1780 | !-- works like FFT-solver |
---|
[1931] | 1781 | IF ( .NOT. masking_method ) THEN |
---|
[927] | 1782 | |
---|
[1968] | 1783 | ! |
---|
| 1784 | !-- Allocate temporary array for topography heights on coarser grid |
---|
| 1785 | !-- level. Please note, 2 ghoist points are required, in order to |
---|
| 1786 | !-- calculate flags() on the interior ghost point. |
---|
| 1787 | ALLOCATE( nzb_tmp(nys_l-2:nyn_l+2,nxl_l-2:nxr_l+2) ) |
---|
| 1788 | nzb_tmp = 0 |
---|
| 1789 | |
---|
| 1790 | DO i = nxl_l, nxr_l |
---|
| 1791 | DO j = nys_l, nyn_l |
---|
| 1792 | nzb_tmp(j,i) = nzb_local(j*inc,i*inc) |
---|
| 1793 | ENDDO |
---|
| 1794 | ENDDO |
---|
| 1795 | ! |
---|
| 1796 | !-- Exchange ghost points on respective multigrid level. 2 ghost points |
---|
| 1797 | !-- are required, in order to calculate flags on |
---|
| 1798 | !-- nys_l-1 / nyn_l+1 / nxl_l-1 / nxr_l+1. The alternative would be to |
---|
| 1799 | !-- exchange 3D-INTEGER array flags on the respective multigrid level. |
---|
| 1800 | CALL exchange_horiz_2d_int( nzb_tmp, nys_l, nyn_l, nxl_l, nxr_l, 2 ) |
---|
| 1801 | ! |
---|
| 1802 | !-- Set non-cyclic boundary conditions on respective multigrid level |
---|
| 1803 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[2021] | 1804 | IF ( inflow_s .OR. outflow_s .OR. nest_bound_s ) THEN |
---|
[1968] | 1805 | nzb_tmp(-2,:) = nzb_tmp(0,:) |
---|
| 1806 | nzb_tmp(-1,:) = nzb_tmp(0,:) |
---|
| 1807 | ENDIF |
---|
[2021] | 1808 | IF ( inflow_n .OR. outflow_n .OR. nest_bound_n ) THEN |
---|
| 1809 | nzb_tmp(nyn_l+2,:) = nzb_tmp(nyn_l,:) |
---|
| 1810 | nzb_tmp(nyn_l+1,:) = nzb_tmp(nyn_l,:) |
---|
[1968] | 1811 | ENDIF |
---|
| 1812 | ENDIF |
---|
| 1813 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[2021] | 1814 | IF ( inflow_l .OR. outflow_l .OR. nest_bound_l ) THEN |
---|
[1968] | 1815 | nzb_tmp(:,-2) = nzb_tmp(:,0) |
---|
| 1816 | nzb_tmp(:,-1) = nzb_tmp(:,0) |
---|
| 1817 | ENDIF |
---|
[2021] | 1818 | IF ( inflow_r .OR. outflow_r .OR. nest_bound_r ) THEN |
---|
| 1819 | nzb_tmp(:,nxr_l+1) = nzb_tmp(:,nxr_l) |
---|
| 1820 | nzb_tmp(:,nxr_l+2) = nzb_tmp(:,nxr_l) |
---|
[1968] | 1821 | ENDIF |
---|
| 1822 | ENDIF |
---|
| 1823 | |
---|
[927] | 1824 | DO i = nxl_l-1, nxr_l+1 |
---|
| 1825 | DO j = nys_l-1, nyn_l+1 |
---|
[1968] | 1826 | DO k = nzb, nzt_l+1 |
---|
[114] | 1827 | ! |
---|
[927] | 1828 | !-- Inside/outside building (inside building does not need |
---|
| 1829 | !-- further tests for walls) |
---|
[1968] | 1830 | IF ( k*inc <= nzb_tmp(j,i) ) THEN |
---|
[114] | 1831 | |
---|
[927] | 1832 | flags(k,j,i) = IBSET( flags(k,j,i), 6 ) |
---|
[114] | 1833 | |
---|
[927] | 1834 | ELSE |
---|
[114] | 1835 | ! |
---|
[927] | 1836 | !-- Bottom wall |
---|
[1968] | 1837 | IF ( (k-1)*inc <= nzb_tmp(j,i) ) THEN |
---|
[927] | 1838 | flags(k,j,i) = IBSET( flags(k,j,i), 0 ) |
---|
| 1839 | ENDIF |
---|
[114] | 1840 | ! |
---|
[927] | 1841 | !-- South wall |
---|
[1968] | 1842 | IF ( k*inc <= nzb_tmp(j-1,i) ) THEN |
---|
[927] | 1843 | flags(k,j,i) = IBSET( flags(k,j,i), 2 ) |
---|
| 1844 | ENDIF |
---|
[114] | 1845 | ! |
---|
[927] | 1846 | !-- North wall |
---|
[1968] | 1847 | IF ( k*inc <= nzb_tmp(j+1,i) ) THEN |
---|
[927] | 1848 | flags(k,j,i) = IBSET( flags(k,j,i), 3 ) |
---|
| 1849 | ENDIF |
---|
[114] | 1850 | ! |
---|
[927] | 1851 | !-- Left wall |
---|
[1968] | 1852 | IF ( k*inc <= nzb_tmp(j,i-1) ) THEN |
---|
[927] | 1853 | flags(k,j,i) = IBSET( flags(k,j,i), 4 ) |
---|
| 1854 | ENDIF |
---|
[114] | 1855 | ! |
---|
[927] | 1856 | !-- Right wall |
---|
[1968] | 1857 | IF ( k*inc <= nzb_tmp(j,i+1) ) THEN |
---|
[927] | 1858 | flags(k,j,i) = IBSET( flags(k,j,i), 5 ) |
---|
| 1859 | ENDIF |
---|
| 1860 | |
---|
[114] | 1861 | ENDIF |
---|
| 1862 | |
---|
[927] | 1863 | ENDDO |
---|
[114] | 1864 | ENDDO |
---|
| 1865 | ENDDO |
---|
| 1866 | |
---|
[1968] | 1867 | DEALLOCATE( nzb_tmp ) |
---|
| 1868 | |
---|
[927] | 1869 | ENDIF |
---|
| 1870 | |
---|
[114] | 1871 | inc = inc * 2 |
---|
| 1872 | |
---|
| 1873 | ENDDO |
---|
[1968] | 1874 | ! |
---|
| 1875 | !-- Reset grid_level to "normal" grid |
---|
| 1876 | grid_level = 0 |
---|
| 1877 | |
---|
[114] | 1878 | ENDIF |
---|
[861] | 1879 | ! |
---|
[1942] | 1880 | !-- Allocate flags needed for masking walls. Even though these flags are only |
---|
[2021] | 1881 | !-- required in the ws-scheme, the arrays need to be allocated here as they are |
---|
[1942] | 1882 | !-- used in OpenACC directives. |
---|
[2232] | 1883 | ALLOCATE( advc_flags_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 1884 | advc_flags_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 1885 | advc_flags_1 = 0 |
---|
| 1886 | advc_flags_2 = 0 |
---|
[114] | 1887 | ! |
---|
[2021] | 1888 | !-- Init flags for ws-scheme to degrade order of the numerics near walls, i.e. |
---|
| 1889 | !-- to decrease the numerical stencil appropriately. |
---|
[2200] | 1890 | IF ( momentum_advec == 'ws-scheme' .OR. scalar_advec == 'ws-scheme' & |
---|
| 1891 | ) THEN |
---|
[1942] | 1892 | CALL ws_init_flags |
---|
[861] | 1893 | ENDIF |
---|
| 1894 | |
---|
| 1895 | ! |
---|
[1] | 1896 | !-- In case of topography: limit near-wall mixing length l_wall further: |
---|
| 1897 | !-- Go through all points of the subdomain one by one and look for the closest |
---|
| 1898 | !-- surface |
---|
[2232] | 1899 | DO i = nxl, nxr |
---|
| 1900 | DO j = nys, nyn |
---|
| 1901 | DO k = nzb+1, nzt |
---|
[1] | 1902 | ! |
---|
[2232] | 1903 | !-- Check if current gridpoint belongs to the atmosphere |
---|
| 1904 | IF ( BTEST( wall_flags_0(k,j,i), 0 ) ) THEN |
---|
[1] | 1905 | ! |
---|
[2232] | 1906 | !-- Check for neighbouring grid-points. |
---|
| 1907 | !-- Vertical distance, down |
---|
| 1908 | IF ( .NOT. BTEST( wall_flags_0(k-1,j,i), 0 ) ) & |
---|
| 1909 | l_wall(k,j,i) = MIN( l_grid(k), zu(k) - zw(k-1) ) |
---|
[1] | 1910 | ! |
---|
[2232] | 1911 | !-- Vertical distance, up |
---|
| 1912 | IF ( .NOT. BTEST( wall_flags_0(k+1,j,i), 0 ) ) & |
---|
| 1913 | l_wall(k,j,i) = MIN( l_grid(k), zw(k) - zu(k) ) |
---|
[1] | 1914 | ! |
---|
[2232] | 1915 | !-- y-distance |
---|
| 1916 | IF ( .NOT. BTEST( wall_flags_0(k,j-1,i), 0 ) .OR. & |
---|
| 1917 | .NOT. BTEST( wall_flags_0(k,j+1,i), 0 ) ) & |
---|
| 1918 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), 0.5_wp * dy ) |
---|
[1] | 1919 | ! |
---|
[2232] | 1920 | !-- x-distance |
---|
| 1921 | IF ( .NOT. BTEST( wall_flags_0(k,j,i-1), 0 ) .OR. & |
---|
| 1922 | .NOT. BTEST( wall_flags_0(k,j,i+1), 0 ) ) & |
---|
| 1923 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), 0.5_wp * dx ) |
---|
[1] | 1924 | ! |
---|
[2232] | 1925 | !-- yz-distance (vertical edges, down) |
---|
| 1926 | IF ( .NOT. BTEST( wall_flags_0(k-1,j-1,i), 0 ) .OR. & |
---|
| 1927 | .NOT. BTEST( wall_flags_0(k-1,j+1,i), 0 ) ) & |
---|
| 1928 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1929 | SQRT( 0.25_wp * dy**2 + & |
---|
| 1930 | ( zu(k) - zw(k-1) )**2 ) ) |
---|
[1] | 1931 | ! |
---|
[2232] | 1932 | !-- yz-distance (vertical edges, up) |
---|
| 1933 | IF ( .NOT. BTEST( wall_flags_0(k+1,j-1,i), 0 ) .OR. & |
---|
| 1934 | .NOT. BTEST( wall_flags_0(k+1,j+1,i), 0 ) ) & |
---|
| 1935 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1936 | SQRT( 0.25_wp * dy**2 + & |
---|
| 1937 | ( zw(k) - zu(k) )**2 ) ) |
---|
[1] | 1938 | ! |
---|
[2232] | 1939 | !-- xz-distance (vertical edges, down) |
---|
| 1940 | IF ( .NOT. BTEST( wall_flags_0(k-1,j,i-1), 0 ) .OR. & |
---|
| 1941 | .NOT. BTEST( wall_flags_0(k-1,j,i+1), 0 ) ) & |
---|
| 1942 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1943 | SQRT( 0.25_wp * dx**2 + & |
---|
| 1944 | ( zu(k) - zw(k-1) )**2 ) ) |
---|
[1] | 1945 | ! |
---|
[2232] | 1946 | !-- xz-distance (vertical edges, up) |
---|
| 1947 | IF ( .NOT. BTEST( wall_flags_0(k+1,j,i-1), 0 ) .OR. & |
---|
| 1948 | .NOT. BTEST( wall_flags_0(k+1,j,i+1), 0 ) ) & |
---|
| 1949 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1950 | SQRT( 0.25_wp * dx**2 + & |
---|
| 1951 | ( zw(k) - zu(k) )**2 ) ) |
---|
[1] | 1952 | ! |
---|
[2232] | 1953 | !-- xy-distance (horizontal edges) |
---|
| 1954 | IF ( .NOT. BTEST( wall_flags_0(k,j-1,i-1), 0 ) .OR. & |
---|
| 1955 | .NOT. BTEST( wall_flags_0(k,j+1,i-1), 0 ) .OR. & |
---|
| 1956 | .NOT. BTEST( wall_flags_0(k,j-1,i+1), 0 ) .OR. & |
---|
| 1957 | .NOT. BTEST( wall_flags_0(k,j+1,i+1), 0 ) ) & |
---|
| 1958 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1959 | SQRT( 0.25_wp * ( dx**2 + dy**2 ) ) ) |
---|
[1] | 1960 | ! |
---|
[2232] | 1961 | !-- xyz distance (vertical and horizontal edges, down) |
---|
| 1962 | IF ( .NOT. BTEST( wall_flags_0(k-1,j-1,i-1), 0 ) .OR. & |
---|
| 1963 | .NOT. BTEST( wall_flags_0(k-1,j+1,i-1), 0 ) .OR. & |
---|
| 1964 | .NOT. BTEST( wall_flags_0(k-1,j-1,i+1), 0 ) .OR. & |
---|
| 1965 | .NOT. BTEST( wall_flags_0(k-1,j+1,i+1), 0 ) ) & |
---|
| 1966 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1967 | SQRT( 0.25_wp * ( dx**2 + dy**2 ) & |
---|
| 1968 | + ( zu(k) - zw(k-1) )**2 ) ) |
---|
[1] | 1969 | ! |
---|
[2232] | 1970 | !-- xyz distance (vertical and horizontal edges, up) |
---|
| 1971 | IF ( .NOT. BTEST( wall_flags_0(k+1,j-1,i-1), 0 ) .OR. & |
---|
| 1972 | .NOT. BTEST( wall_flags_0(k+1,j+1,i-1), 0 ) .OR. & |
---|
| 1973 | .NOT. BTEST( wall_flags_0(k+1,j-1,i+1), 0 ) .OR. & |
---|
| 1974 | .NOT. BTEST( wall_flags_0(k+1,j+1,i+1), 0 ) ) & |
---|
| 1975 | l_wall(k,j,i) = MIN( l_wall(k,j,i), l_grid(k), & |
---|
| 1976 | SQRT( 0.25_wp * ( dx**2 + dy**2 ) & |
---|
| 1977 | + ( zw(k) - zu(k) )**2 ) ) |
---|
| 1978 | |
---|
[1] | 1979 | ENDIF |
---|
| 1980 | ENDDO |
---|
| 1981 | ENDDO |
---|
[2232] | 1982 | ENDDO |
---|
[1] | 1983 | ! |
---|
[709] | 1984 | !-- Set lateral boundary conditions for l_wall |
---|
[2232] | 1985 | CALL exchange_horiz( l_wall, nbgp ) |
---|
[667] | 1986 | |
---|
[1] | 1987 | |
---|
| 1988 | END SUBROUTINE init_grid |
---|