[1682] | 1 | !> @file init_pegrid.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[2718] | 17 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[254] | 20 | ! Current revisions: |
---|
[1322] | 21 | ! ------------------ |
---|
[2201] | 22 | ! |
---|
[3183] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: init_pegrid.f90 3183 2018-07-27 14:25:55Z schwenkel $ |
---|
[3183] | 27 | ! Rename variables and boundary conditions in mesoscale-offline nesting mode |
---|
| 28 | ! |
---|
| 29 | ! 3182 2018-07-27 13:36:03Z suehring |
---|
[3058] | 30 | ! bugfix: wrong error number in r3057 revised |
---|
| 31 | ! |
---|
| 32 | ! 3057 2018-06-05 09:03:41Z raasch |
---|
[3057] | 33 | ! bugfix: check that nz is even in case that optimized multigrid is used |
---|
| 34 | ! |
---|
| 35 | ! 3049 2018-05-29 13:52:36Z Giersch |
---|
[3045] | 36 | ! Error messages revised |
---|
| 37 | ! |
---|
[3049] | 38 | ! 3045 2018-05-28 07:55:41Z Giersch |
---|
| 39 | ! Error messages revised |
---|
| 40 | ! |
---|
[3045] | 41 | ! 2938 2018-03-27 15:52:42Z suehring |
---|
[2938] | 42 | ! - No checks for domain decomposition in case of turbulence generator |
---|
| 43 | ! (is done in stg module) |
---|
| 44 | ! - Introduce ids to indicate lateral processors for turbulence generator |
---|
| 45 | ! |
---|
| 46 | ! 2936 2018-03-27 14:49:27Z suehring |
---|
[2776] | 47 | ! Variable use_synthetic_turbulence_generator has been abbreviated |
---|
| 48 | ! |
---|
| 49 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
[2716] | 50 | ! Corrected "Former revisions" section |
---|
| 51 | ! |
---|
| 52 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 53 | ! Change in file header (GPL part) |
---|
[2696] | 54 | ! 3D-Integer exchange on multigrid level (MS) |
---|
| 55 | ! Forcing implemented (MS) |
---|
| 56 | ! |
---|
| 57 | ! 2600 2017-11-01 14:11:20Z raasch |
---|
[2600] | 58 | ! calculation of block-I/O quantitites removed (is now done in parin) |
---|
| 59 | ! |
---|
| 60 | ! 2516 2017-10-04 11:03:04Z suehring |
---|
[2516] | 61 | ! Remove tabs |
---|
| 62 | ! |
---|
| 63 | ! 2514 2017-10-04 09:52:37Z suehring |
---|
[2414] | 64 | ! Redundant preprocessor directives removed |
---|
| 65 | ! |
---|
| 66 | ! 2372 2017-08-25 12:37:32Z sward |
---|
[2372] | 67 | ! Shifted cyclic boundary conditions implemented |
---|
| 68 | ! |
---|
| 69 | ! 2365 2017-08-21 14:59:59Z kanani |
---|
[2365] | 70 | ! Vertical nesting implemented (SadiqHuq) |
---|
| 71 | ! |
---|
| 72 | ! 2300 2017-06-29 13:31:14Z raasch |
---|
[2300] | 73 | ! host-specific settings removed |
---|
| 74 | ! |
---|
| 75 | ! 2298 2017-06-29 09:28:18Z raasch |
---|
[2298] | 76 | ! MPI2 related parts removed |
---|
| 77 | ! |
---|
| 78 | ! 2271 2017-06-09 12:34:55Z sward |
---|
[2271] | 79 | ! Error message changed |
---|
| 80 | ! |
---|
| 81 | ! 2259 2017-06-08 09:09:11Z gronemeier |
---|
[2259] | 82 | ! Implemented synthetic turbulence generator |
---|
| 83 | ! |
---|
| 84 | ! 2238 2017-05-31 16:49:16Z suehring |
---|
[2238] | 85 | ! Remove unnecessary module load of pmc_interface |
---|
| 86 | ! |
---|
| 87 | ! 2231 2017-05-30 16:44:33Z suehring |
---|
[1321] | 88 | ! |
---|
[2201] | 89 | ! 2200 2017-04-11 11:37:51Z suehring |
---|
| 90 | ! monotonic_adjustment removed |
---|
| 91 | ! |
---|
[2198] | 92 | ! 2197 2017-03-24 02:25:00Z raasch |
---|
| 93 | ! bugfix: do not allow odd values for nz at the coarsest grid level in case of |
---|
| 94 | ! optimized multigrid solver |
---|
| 95 | ! |
---|
[2181] | 96 | ! 2180 2017-03-17 13:33:05Z hellstea |
---|
| 97 | ! Checks to ensure (2178) that pdims match the grid dimensions in the |
---|
| 98 | ! automatic determination of pdims are canceled as unnecessary |
---|
| 99 | ! |
---|
[2179] | 100 | ! 2178 2017-03-17 11:07:39Z hellstea |
---|
| 101 | ! Checks to ensure that pdims match the grid dimensions are added in the |
---|
| 102 | ! automatic determination of pdims |
---|
| 103 | ! |
---|
[2051] | 104 | ! 2050 2016-11-08 15:00:55Z gronemeier |
---|
| 105 | ! Implement turbulent outflow condition |
---|
| 106 | ! |
---|
[2001] | 107 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 108 | ! Forced header and separation lines into 80 columns |
---|
| 109 | ! |
---|
[1969] | 110 | ! 1968 2016-07-18 12:01:49Z suehring |
---|
| 111 | ! Extent MPI-datatypes for exchange of 2D-INTEGER arrays on coarser multigrid |
---|
| 112 | ! level |
---|
| 113 | ! |
---|
[1965] | 114 | ! 1964 2016-07-14 15:35:18Z hellstea |
---|
| 115 | ! Bugfix: erroneous setting of nest_bound_l/r/s/n = .TRUE. for vertical nesting mode removed. |
---|
[1968] | 116 | ! |
---|
[1933] | 117 | ! 1923 2016-05-31 16:37:07Z boeske |
---|
| 118 | ! Initial version of purely vertical nesting introduced. |
---|
| 119 | ! |
---|
[1923] | 120 | ! 1922 2016-05-31 16:36:08Z boeske |
---|
| 121 | ! Bugfix: array transposition checks restricted to cases if a fourier |
---|
| 122 | ! transform is used , removed unused variable nnx_z |
---|
| 123 | ! |
---|
[1834] | 124 | ! 1833 2016-04-07 14:23:03Z raasch |
---|
| 125 | ! spectra related variables moved to spectra_mod |
---|
| 126 | ! |
---|
[1816] | 127 | ! 1815 2016-04-06 13:49:59Z raasch |
---|
| 128 | ! cpp-directives for intel openmp bug removed |
---|
| 129 | ! |
---|
[1805] | 130 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
| 131 | ! Removed code for parameter file check (__check) |
---|
| 132 | ! |
---|
[1780] | 133 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 134 | ! changes regarding nested domain removed: virtual PE grid will be automatically |
---|
| 135 | ! calculated for nested runs too |
---|
| 136 | ! |
---|
[1765] | 137 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
| 138 | ! cpp-statements for nesting removed |
---|
| 139 | ! |
---|
[1763] | 140 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 141 | ! Introduction of nested domain feature |
---|
| 142 | ! |
---|
[1683] | 143 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 144 | ! Code annotations made doxygen readable |
---|
| 145 | ! |
---|
[1678] | 146 | ! 1677 2015-10-02 13:25:23Z boeske |
---|
| 147 | ! New MPI-data types for exchange of 3D integer arrays. |
---|
| 148 | ! |
---|
[1576] | 149 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
| 150 | ! adjustments for psolver-queries, calculation of ngp_xz added |
---|
| 151 | ! |
---|
[1566] | 152 | ! 1565 2015-03-09 20:59:31Z suehring |
---|
| 153 | ! Refine if-clause for setting nbgp. |
---|
| 154 | ! |
---|
[1558] | 155 | ! 1557 2015-03-05 16:43:04Z suehring |
---|
| 156 | ! Adjustment for monotonic limiter |
---|
| 157 | ! |
---|
[1469] | 158 | ! 1468 2014-09-24 14:06:57Z maronga |
---|
| 159 | ! Adapted for use on up to 6-digit processor cores |
---|
| 160 | ! |
---|
[1436] | 161 | ! 1435 2014-07-21 10:37:02Z keck |
---|
| 162 | ! bugfix: added missing parameter coupling_mode_remote to ONLY-attribute |
---|
| 163 | ! |
---|
[1403] | 164 | ! 1402 2014-05-09 14:25:13Z raasch |
---|
| 165 | ! location messages modified |
---|
| 166 | ! |
---|
[1385] | 167 | ! 1384 2014-05-02 14:31:06Z raasch |
---|
| 168 | ! location messages added |
---|
| 169 | ! |
---|
[1354] | 170 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 171 | ! REAL constants provided with KIND-attribute |
---|
| 172 | ! |
---|
[1323] | 173 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
| 174 | ! REAL functions provided with KIND-attribute |
---|
| 175 | ! |
---|
[1321] | 176 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 177 | ! ONLY-attribute added to USE-statements, |
---|
| 178 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 179 | ! kinds are defined in new module kinds, |
---|
| 180 | ! revision history before 2012 removed, |
---|
| 181 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 182 | ! all variable declaration statements |
---|
[760] | 183 | ! |
---|
[1305] | 184 | ! 1304 2014-03-12 10:29:42Z raasch |
---|
| 185 | ! bugfix: single core MPI runs missed some settings of transpose indices |
---|
| 186 | ! |
---|
[1213] | 187 | ! 1212 2013-08-15 08:46:27Z raasch |
---|
| 188 | ! error message for poisfft_hybrid removed |
---|
| 189 | ! |
---|
[1160] | 190 | ! 1159 2013-05-21 11:58:22Z fricke |
---|
| 191 | ! dirichlet/neumann and neumann/dirichlet removed |
---|
| 192 | ! |
---|
[1140] | 193 | ! 1139 2013-04-18 07:25:03Z raasch |
---|
| 194 | ! bugfix for calculating the id of the PE carrying the recycling plane |
---|
| 195 | ! |
---|
[1112] | 196 | ! 1111 2013-03-08 23:54:10Z raasch |
---|
| 197 | ! initialization of poisfft moved to module poisfft |
---|
| 198 | ! |
---|
[1093] | 199 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 200 | ! unused variables removed |
---|
| 201 | ! |
---|
[1057] | 202 | ! 1056 2012-11-16 15:28:04Z raasch |
---|
| 203 | ! Indices for arrays n.._mg start from zero due to definition of arrays f2 and |
---|
| 204 | ! p2 as automatic arrays in recursive subroutine next_mg_level |
---|
| 205 | ! |
---|
[1042] | 206 | ! 1041 2012-11-06 02:36:29Z raasch |
---|
| 207 | ! a 2d virtual processor topology is used by default for all machines |
---|
| 208 | ! |
---|
[1037] | 209 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 210 | ! code put under GPL (PALM 3.9) |
---|
| 211 | ! |
---|
[1004] | 212 | ! 1003 2012-09-14 14:35:53Z raasch |
---|
| 213 | ! subdomains must have identical size (grid matching = "match" removed) |
---|
| 214 | ! |
---|
[1002] | 215 | ! 1001 2012-09-13 14:08:46Z raasch |
---|
| 216 | ! all actions concerning upstream-spline-method removed |
---|
| 217 | ! |
---|
[979] | 218 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 219 | ! dirichlet/neumann and neumann/dirichlet added |
---|
| 220 | ! nxlu and nysv are also calculated for inflow boundary |
---|
| 221 | ! |
---|
[810] | 222 | ! 809 2012-01-30 13:32:58Z maronga |
---|
| 223 | ! Bugfix: replaced .AND. and .NOT. with && and ! in the preprocessor directives |
---|
| 224 | ! |
---|
[808] | 225 | ! 807 2012-01-25 11:53:51Z maronga |
---|
| 226 | ! New cpp directive "__check" implemented which is used by check_namelist_files |
---|
| 227 | ! |
---|
[1] | 228 | ! Revision 1.1 1997/07/24 11:15:09 raasch |
---|
| 229 | ! Initial revision |
---|
| 230 | ! |
---|
| 231 | ! |
---|
| 232 | ! Description: |
---|
| 233 | ! ------------ |
---|
[1682] | 234 | !> Determination of the virtual processor topology (if not prescribed by the |
---|
| 235 | !> user)and computation of the grid point number and array bounds of the local |
---|
| 236 | !> domains. |
---|
[2696] | 237 | !> @todo: remove MPI-data types for 2D exchange on coarse multigrid level (not |
---|
| 238 | !> used any more) |
---|
[1] | 239 | !------------------------------------------------------------------------------! |
---|
[1682] | 240 | SUBROUTINE init_pegrid |
---|
| 241 | |
---|
[1] | 242 | |
---|
[1320] | 243 | USE control_parameters, & |
---|
[3182] | 244 | ONLY: bc_dirichlet_l, bc_dirichlet_n, bc_dirichlet_r, bc_dirichlet_s, & |
---|
| 245 | bc_lr, bc_ns, bc_radiation_l, bc_radiation_n, bc_radiation_r, & |
---|
| 246 | bc_radiation_s, coupling_mode, coupling_mode_remote, & |
---|
| 247 | coupling_topology, gathered_size, grid_level, & |
---|
| 248 | grid_level_count, maximum_grid_level, message_string, & |
---|
| 249 | mg_switch_to_pe0_level, momentum_advec, neutral, & |
---|
| 250 | psolver, outflow_source_plane, recycling_width, scalar_advec, & |
---|
[2372] | 251 | subdomain_size, turbulent_outflow, y_shift |
---|
[1] | 252 | |
---|
[1320] | 253 | USE grid_variables, & |
---|
| 254 | ONLY: dx |
---|
| 255 | |
---|
| 256 | USE indices, & |
---|
| 257 | ONLY: mg_loc_ind, nbgp, nnx, nny, nnz, nx, nx_a, nx_o, nxl, nxl_mg, & |
---|
| 258 | nxlu, nxr, nxr_mg, ny, ny_a, ny_o, nyn, nyn_mg, nys, nys_mg, & |
---|
| 259 | nysv, nz, nzb, nzt, nzt_mg, wall_flags_1, wall_flags_2, & |
---|
| 260 | wall_flags_3, wall_flags_4, wall_flags_5, wall_flags_6, & |
---|
| 261 | wall_flags_7, wall_flags_8, wall_flags_9, wall_flags_10 |
---|
[1] | 262 | |
---|
[1320] | 263 | USE kinds |
---|
| 264 | |
---|
| 265 | USE pegrid |
---|
[2238] | 266 | |
---|
[1833] | 267 | USE spectra_mod, & |
---|
[1922] | 268 | ONLY: calculate_spectra, dt_dosp |
---|
[1833] | 269 | |
---|
[2259] | 270 | USE synthetic_turbulence_generator_mod, & |
---|
[2938] | 271 | ONLY: id_stg_left, id_stg_north, id_stg_right, id_stg_south, & |
---|
| 272 | use_syn_turb_gen |
---|
[2259] | 273 | |
---|
[1320] | 274 | USE transpose_indices, & |
---|
| 275 | ONLY: nxl_y, nxl_yd, nxl_z, nxr_y, nxr_yd, nxr_z, nyn_x, nyn_z, nys_x,& |
---|
| 276 | nys_z, nzb_x, nzb_y, nzb_yd, nzt_x, nzt_yd, nzt_y |
---|
[667] | 277 | |
---|
[2365] | 278 | USE vertical_nesting_mod, & |
---|
| 279 | ONLY: vnested, vnest_init_pegrid_domain, vnest_init_pegrid_rank |
---|
| 280 | |
---|
[1] | 281 | IMPLICIT NONE |
---|
| 282 | |
---|
[1682] | 283 | INTEGER(iwp) :: i !< |
---|
| 284 | INTEGER(iwp) :: id_inflow_l !< |
---|
[2050] | 285 | INTEGER(iwp) :: id_outflow_l !< local value of id_outflow |
---|
| 286 | INTEGER(iwp) :: id_outflow_source_l !< local value of id_outflow_source |
---|
[1682] | 287 | INTEGER(iwp) :: id_recycling_l !< |
---|
[2938] | 288 | INTEGER(iwp) :: id_stg_left_l !< left lateral boundary local core id in case of turbulence generator |
---|
| 289 | INTEGER(iwp) :: id_stg_north_l !< north lateral boundary local core id in case of turbulence generator |
---|
| 290 | INTEGER(iwp) :: id_stg_right_l !< right lateral boundary local core id in case of turbulence generator |
---|
| 291 | INTEGER(iwp) :: id_stg_south_l !< south lateral boundary local core id in case of turbulence generator |
---|
[1682] | 292 | INTEGER(iwp) :: ind(5) !< |
---|
| 293 | INTEGER(iwp) :: j !< |
---|
| 294 | INTEGER(iwp) :: k !< |
---|
| 295 | INTEGER(iwp) :: maximum_grid_level_l !< |
---|
| 296 | INTEGER(iwp) :: mg_levels_x !< |
---|
| 297 | INTEGER(iwp) :: mg_levels_y !< |
---|
| 298 | INTEGER(iwp) :: mg_levels_z !< |
---|
| 299 | INTEGER(iwp) :: mg_switch_to_pe0_level_l !< |
---|
| 300 | INTEGER(iwp) :: nnx_y !< |
---|
| 301 | INTEGER(iwp) :: nnx_z !< |
---|
| 302 | INTEGER(iwp) :: nny_x !< |
---|
| 303 | INTEGER(iwp) :: nny_z !< |
---|
| 304 | INTEGER(iwp) :: nnz_x !< |
---|
| 305 | INTEGER(iwp) :: nnz_y !< |
---|
| 306 | INTEGER(iwp) :: numproc_sqr !< |
---|
| 307 | INTEGER(iwp) :: nxl_l !< |
---|
| 308 | INTEGER(iwp) :: nxr_l !< |
---|
| 309 | INTEGER(iwp) :: nyn_l !< |
---|
| 310 | INTEGER(iwp) :: nys_l !< |
---|
| 311 | INTEGER(iwp) :: nzb_l !< |
---|
| 312 | INTEGER(iwp) :: nzt_l !< |
---|
| 313 | INTEGER(iwp) :: omp_get_num_threads !< |
---|
[1] | 314 | |
---|
[1682] | 315 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: ind_all !< |
---|
| 316 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: nxlf !< |
---|
| 317 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: nxrf !< |
---|
| 318 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: nynf !< |
---|
| 319 | INTEGER(iwp), DIMENSION(:), ALLOCATABLE :: nysf !< |
---|
[1] | 320 | |
---|
[2372] | 321 | INTEGER(iwp), DIMENSION(2) :: pdims_remote !< |
---|
| 322 | INTEGER(iwp) :: lcoord(2) !< PE coordinates of left neighbor along x and y |
---|
| 323 | INTEGER(iwp) :: rcoord(2) !< PE coordinates of right neighbor along x and y |
---|
[667] | 324 | |
---|
[1] | 325 | ! |
---|
| 326 | !-- Get the number of OpenMP threads |
---|
| 327 | !$OMP PARALLEL |
---|
| 328 | !$ threads_per_task = omp_get_num_threads() |
---|
| 329 | !$OMP END PARALLEL |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | #if defined( __parallel ) |
---|
[667] | 333 | |
---|
[1402] | 334 | CALL location_message( 'creating virtual PE grids + MPI derived data types', & |
---|
| 335 | .FALSE. ) |
---|
[1764] | 336 | |
---|
[1] | 337 | ! |
---|
[2177] | 338 | !-- Determine the processor topology or check it, if prescribed by the user |
---|
[1779] | 339 | IF ( npex == -1 .AND. npey == -1 ) THEN |
---|
[1] | 340 | |
---|
| 341 | ! |
---|
[2177] | 342 | !-- Automatic determination of the topology |
---|
[1779] | 343 | numproc_sqr = SQRT( REAL( numprocs, KIND=wp ) ) |
---|
| 344 | pdims(1) = MAX( numproc_sqr , 1 ) |
---|
[2180] | 345 | DO WHILE ( MOD( numprocs , pdims(1) ) /= 0 ) |
---|
[1779] | 346 | pdims(1) = pdims(1) - 1 |
---|
| 347 | ENDDO |
---|
[2180] | 348 | pdims(2) = numprocs / pdims(1) |
---|
[1] | 349 | |
---|
[1779] | 350 | ELSEIF ( npex /= -1 .AND. npey /= -1 ) THEN |
---|
[1] | 351 | |
---|
| 352 | ! |
---|
[1779] | 353 | !-- Prescribed by user. Number of processors on the prescribed topology |
---|
| 354 | !-- must be equal to the number of PEs available to the job |
---|
| 355 | IF ( ( npex * npey ) /= numprocs ) THEN |
---|
[3045] | 356 | WRITE( message_string, * ) 'number of PEs of the prescribed ', & |
---|
[3046] | 357 | 'topology (', npex*npey,') does not match & the number of ', & |
---|
[1779] | 358 | 'PEs available to the job (', numprocs, ')' |
---|
| 359 | CALL message( 'init_pegrid', 'PA0221', 1, 2, 0, 6, 0 ) |
---|
| 360 | ENDIF |
---|
| 361 | pdims(1) = npex |
---|
| 362 | pdims(2) = npey |
---|
[1] | 363 | |
---|
[1779] | 364 | ELSE |
---|
[1] | 365 | ! |
---|
[1779] | 366 | !-- If the processor topology is prescribed by the user, the number of |
---|
| 367 | !-- PEs must be given in both directions |
---|
[3045] | 368 | message_string = 'if the processor topology is prescribed by th' // & |
---|
[3046] | 369 | 'e user & both values of "npex" and "npey" must be given' // & |
---|
[1779] | 370 | ' in the &NAMELIST-parameter file' |
---|
| 371 | CALL message( 'init_pegrid', 'PA0222', 1, 2, 0, 6, 0 ) |
---|
[1] | 372 | |
---|
| 373 | ENDIF |
---|
| 374 | |
---|
| 375 | ! |
---|
| 376 | !-- If necessary, set horizontal boundary conditions to non-cyclic |
---|
[722] | 377 | IF ( bc_lr /= 'cyclic' ) cyclic(1) = .FALSE. |
---|
| 378 | IF ( bc_ns /= 'cyclic' ) cyclic(2) = .FALSE. |
---|
[1] | 379 | |
---|
[807] | 380 | |
---|
[1] | 381 | ! |
---|
| 382 | !-- Create the virtual processor grid |
---|
| 383 | CALL MPI_CART_CREATE( comm_palm, ndim, pdims, cyclic, reorder, & |
---|
| 384 | comm2d, ierr ) |
---|
| 385 | CALL MPI_COMM_RANK( comm2d, myid, ierr ) |
---|
[1468] | 386 | WRITE (myid_char,'(''_'',I6.6)') myid |
---|
[1] | 387 | |
---|
| 388 | CALL MPI_CART_COORDS( comm2d, myid, ndim, pcoord, ierr ) |
---|
| 389 | CALL MPI_CART_SHIFT( comm2d, 0, 1, pleft, pright, ierr ) |
---|
| 390 | CALL MPI_CART_SHIFT( comm2d, 1, 1, psouth, pnorth, ierr ) |
---|
| 391 | ! |
---|
[2372] | 392 | !-- In case of cyclic boundary conditions, a y-shift at the boundaries in |
---|
| 393 | !-- x-direction can be introduced via parameter y_shift. The shift is done |
---|
| 394 | !-- by modifying the processor grid in such a way that processors located |
---|
| 395 | !-- at the x-boundary communicate across it to processors with y-coordinate |
---|
| 396 | !-- shifted by y_shift relative to their own. This feature can not be used |
---|
| 397 | !-- in combination with an fft pressure solver. It has been implemented to |
---|
| 398 | !-- counter the effect of streak structures in case of cyclic boundary |
---|
| 399 | !-- conditions. For a description of these see Munters |
---|
| 400 | !-- (2016; dx.doi.org/10.1063/1.4941912) |
---|
| 401 | !-- |
---|
| 402 | !-- Get coordinates of left and right neighbor on PE grid |
---|
| 403 | IF ( y_shift /= 0 ) THEN |
---|
| 404 | |
---|
| 405 | IF ( bc_lr /= 'cyclic' .OR. bc_ns /= 'cyclic' ) THEN |
---|
| 406 | message_string = 'y_shift /= 0 is only allowed for cyclic ' // & |
---|
| 407 | 'boundary conditions in both directions ' |
---|
| 408 | CALL message( 'check_parameters', 'PA0467', 1, 2, 0, 6, 0 ) |
---|
| 409 | ENDIF |
---|
| 410 | IF ( TRIM( psolver ) /= 'multigrid' .AND. & |
---|
| 411 | TRIM( psolver ) /= 'multigrid_noopt') & |
---|
| 412 | THEN |
---|
| 413 | message_string = 'y_shift /= 0 requires a multigrid pressure solver ' |
---|
| 414 | CALL message( 'check_parameters', 'PA0468', 1, 2, 0, 6, 0 ) |
---|
| 415 | ENDIF |
---|
| 416 | |
---|
| 417 | CALL MPI_CART_COORDS( comm2d, pright, ndim, rcoord, ierr ) |
---|
| 418 | CALL MPI_CART_COORDS( comm2d, pleft, ndim, lcoord, ierr ) |
---|
| 419 | |
---|
| 420 | ! |
---|
| 421 | !-- If the x(y)-coordinate of the right (left) neighbor is smaller (greater) |
---|
| 422 | !-- than that of the calling process, then the calling process is located on |
---|
| 423 | !-- the right (left) boundary of the processor grid. In that case, |
---|
| 424 | !-- the y-coordinate of that neighbor is increased (decreased) by y_shift. |
---|
| 425 | !-- The rank of the process with that coordinate is then inquired and the |
---|
| 426 | !-- neighbor rank for MPI_SENDRECV, pright (pleft) is set to it. |
---|
| 427 | !-- In this way, the calling process receives a new right (left) neighbor |
---|
| 428 | !-- for all future MPI_SENDRECV calls. That neighbor has a y-coordinate |
---|
| 429 | !-- of y+(-)y_shift, where y is the original right (left) neighbor's |
---|
| 430 | !-- y-coordinate. The modulo-operation ensures that if the neighbor's |
---|
| 431 | !-- y-coordinate exceeds the grid-boundary, it will be relocated to |
---|
| 432 | !-- the opposite part of the grid cyclicly. |
---|
| 433 | IF ( rcoord(1) < pcoord(1) ) THEN |
---|
| 434 | rcoord(2) = MODULO( rcoord(2) + y_shift, pdims(2) ) |
---|
| 435 | CALL MPI_CART_RANK( comm2d, rcoord, pright, ierr ) |
---|
| 436 | ENDIF |
---|
| 437 | |
---|
| 438 | IF ( lcoord(1) > pcoord(1) ) THEN |
---|
| 439 | lcoord(2) = MODULO( lcoord(2) - y_shift, pdims(2) ) |
---|
| 440 | CALL MPI_CART_RANK( comm2d, lcoord, pleft, ierr ) |
---|
| 441 | ENDIF |
---|
| 442 | ENDIF |
---|
| 443 | ! |
---|
[2365] | 444 | !-- Vertical nesting: store four lists that identify partner ranks to exchange |
---|
| 445 | !-- data |
---|
| 446 | IF ( vnested ) CALL vnest_init_pegrid_rank |
---|
| 447 | |
---|
| 448 | ! |
---|
[1] | 449 | !-- Determine sub-topologies for transpositions |
---|
| 450 | !-- Transposition from z to x: |
---|
| 451 | remain_dims(1) = .TRUE. |
---|
| 452 | remain_dims(2) = .FALSE. |
---|
| 453 | CALL MPI_CART_SUB( comm2d, remain_dims, comm1dx, ierr ) |
---|
| 454 | CALL MPI_COMM_RANK( comm1dx, myidx, ierr ) |
---|
| 455 | ! |
---|
| 456 | !-- Transposition from x to y |
---|
| 457 | remain_dims(1) = .FALSE. |
---|
| 458 | remain_dims(2) = .TRUE. |
---|
| 459 | CALL MPI_CART_SUB( comm2d, remain_dims, comm1dy, ierr ) |
---|
| 460 | CALL MPI_COMM_RANK( comm1dy, myidy, ierr ) |
---|
| 461 | |
---|
| 462 | |
---|
| 463 | ! |
---|
[1003] | 464 | !-- Calculate array bounds along x-direction for every PE. |
---|
[3045] | 465 | ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1), & |
---|
[1003] | 466 | nysf(0:pdims(2)-1) ) |
---|
[1] | 467 | |
---|
[1003] | 468 | IF ( MOD( nx+1 , pdims(1) ) /= 0 ) THEN |
---|
[3045] | 469 | WRITE( message_string, * ) 'x-direction: gridpoint number (',nx+1,') ', & |
---|
[3046] | 470 | 'is not an& integral divisor of the number ', & |
---|
[3045] | 471 | 'of processors (', pdims(1),')' |
---|
[254] | 472 | CALL message( 'init_pegrid', 'PA0225', 1, 2, 0, 6, 0 ) |
---|
[1] | 473 | ELSE |
---|
[1003] | 474 | nnx = ( nx + 1 ) / pdims(1) |
---|
[1] | 475 | ENDIF |
---|
| 476 | |
---|
| 477 | ! |
---|
| 478 | !-- Left and right array bounds, number of gridpoints |
---|
| 479 | DO i = 0, pdims(1)-1 |
---|
| 480 | nxlf(i) = i * nnx |
---|
| 481 | nxrf(i) = ( i + 1 ) * nnx - 1 |
---|
| 482 | ENDDO |
---|
| 483 | |
---|
| 484 | ! |
---|
| 485 | !-- Calculate array bounds in y-direction for every PE. |
---|
[1003] | 486 | IF ( MOD( ny+1 , pdims(2) ) /= 0 ) THEN |
---|
[274] | 487 | WRITE( message_string, * ) 'y-direction: gridpoint number (',ny+1,') ', & |
---|
[3046] | 488 | 'is not an& integral divisor of the number of', & |
---|
[274] | 489 | 'processors (', pdims(2),')' |
---|
[254] | 490 | CALL message( 'init_pegrid', 'PA0227', 1, 2, 0, 6, 0 ) |
---|
[1] | 491 | ELSE |
---|
[1003] | 492 | nny = ( ny + 1 ) / pdims(2) |
---|
[1] | 493 | ENDIF |
---|
| 494 | |
---|
| 495 | ! |
---|
| 496 | !-- South and north array bounds |
---|
| 497 | DO j = 0, pdims(2)-1 |
---|
| 498 | nysf(j) = j * nny |
---|
| 499 | nynf(j) = ( j + 1 ) * nny - 1 |
---|
| 500 | ENDDO |
---|
| 501 | |
---|
| 502 | ! |
---|
| 503 | !-- Local array bounds of the respective PEs |
---|
[1003] | 504 | nxl = nxlf(pcoord(1)) |
---|
| 505 | nxr = nxrf(pcoord(1)) |
---|
| 506 | nys = nysf(pcoord(2)) |
---|
| 507 | nyn = nynf(pcoord(2)) |
---|
| 508 | nzb = 0 |
---|
| 509 | nzt = nz |
---|
| 510 | nnz = nz |
---|
[1] | 511 | |
---|
| 512 | ! |
---|
[707] | 513 | !-- Set switches to define if the PE is situated at the border of the virtual |
---|
| 514 | !-- processor grid |
---|
| 515 | IF ( nxl == 0 ) left_border_pe = .TRUE. |
---|
| 516 | IF ( nxr == nx ) right_border_pe = .TRUE. |
---|
| 517 | IF ( nys == 0 ) south_border_pe = .TRUE. |
---|
| 518 | IF ( nyn == ny ) north_border_pe = .TRUE. |
---|
| 519 | |
---|
| 520 | ! |
---|
[1] | 521 | !-- Calculate array bounds and gridpoint numbers for the transposed arrays |
---|
| 522 | !-- (needed in the pressure solver) |
---|
| 523 | !-- For the transposed arrays, cyclic boundaries as well as top and bottom |
---|
| 524 | !-- boundaries are omitted, because they are obstructive to the transposition |
---|
| 525 | |
---|
| 526 | ! |
---|
| 527 | !-- 1. transposition z --> x |
---|
[1001] | 528 | !-- This transposition is not neccessary in case of a 1d-decomposition along x |
---|
[2938] | 529 | IF ( psolver == 'poisfft' .OR. calculate_spectra ) THEN |
---|
[1304] | 530 | |
---|
[1922] | 531 | IF ( pdims(2) /= 1 ) THEN |
---|
| 532 | IF ( MOD( nz , pdims(1) ) /= 0 ) THEN |
---|
| 533 | WRITE( message_string, * ) 'transposition z --> x:', & |
---|
[3046] | 534 | '& nz=',nz,' is not an integral divisior of pdims(1)=', & |
---|
[274] | 535 | pdims(1) |
---|
[1922] | 536 | CALL message( 'init_pegrid', 'PA0230', 1, 2, 0, 6, 0 ) |
---|
| 537 | ENDIF |
---|
[1] | 538 | ENDIF |
---|
[1922] | 539 | |
---|
| 540 | nys_x = nys |
---|
| 541 | nyn_x = nyn |
---|
| 542 | nny_x = nny |
---|
| 543 | nnz_x = nz / pdims(1) |
---|
| 544 | nzb_x = 1 + myidx * nnz_x |
---|
| 545 | nzt_x = ( myidx + 1 ) * nnz_x |
---|
| 546 | sendrecvcount_zx = nnx * nny * nnz_x |
---|
| 547 | |
---|
[1] | 548 | ENDIF |
---|
| 549 | |
---|
[1922] | 550 | |
---|
| 551 | IF ( psolver == 'poisfft' ) THEN |
---|
[1] | 552 | ! |
---|
[1922] | 553 | !-- 2. transposition x --> y |
---|
| 554 | IF ( MOD( nx+1 , pdims(2) ) /= 0 ) THEN |
---|
| 555 | WRITE( message_string, * ) 'transposition x --> y:', & |
---|
[3046] | 556 | '& nx+1=',nx+1,' is not an integral divisor of ', & |
---|
[1922] | 557 | 'pdims(2)=',pdims(2) |
---|
| 558 | CALL message( 'init_pegrid', 'PA0231', 1, 2, 0, 6, 0 ) |
---|
| 559 | ENDIF |
---|
[1] | 560 | |
---|
[1922] | 561 | nnz_y = nnz_x |
---|
| 562 | nzb_y = nzb_x |
---|
| 563 | nzt_y = nzt_x |
---|
| 564 | nnx_y = (nx+1) / pdims(2) |
---|
| 565 | nxl_y = myidy * nnx_y |
---|
| 566 | nxr_y = ( myidy + 1 ) * nnx_y - 1 |
---|
| 567 | sendrecvcount_xy = nnx_y * nny_x * nnz_y |
---|
[1] | 568 | ! |
---|
[1922] | 569 | !-- 3. transposition y --> z |
---|
| 570 | !-- (ELSE: x --> y in case of 1D-decomposition along x) |
---|
| 571 | nxl_z = nxl_y |
---|
| 572 | nxr_z = nxr_y |
---|
| 573 | nny_z = (ny+1) / pdims(1) |
---|
| 574 | nys_z = myidx * nny_z |
---|
| 575 | nyn_z = ( myidx + 1 ) * nny_z - 1 |
---|
| 576 | sendrecvcount_yz = nnx_y * nny_z * nnz_y |
---|
[1304] | 577 | |
---|
[1922] | 578 | IF ( pdims(2) /= 1 ) THEN |
---|
[1] | 579 | ! |
---|
[1922] | 580 | !-- y --> z |
---|
| 581 | !-- This transposition is not neccessary in case of a 1d-decomposition |
---|
| 582 | !-- along x, except that the uptream-spline method is switched on |
---|
| 583 | IF ( MOD( ny+1 , pdims(1) ) /= 0 ) THEN |
---|
| 584 | WRITE( message_string, * ) 'transposition y --> z:', & |
---|
[3046] | 585 | '& ny+1=',ny+1,' is not an integral divisor of',& |
---|
[1922] | 586 | ' pdims(1)=',pdims(1) |
---|
| 587 | CALL message( 'init_pegrid', 'PA0232', 1, 2, 0, 6, 0 ) |
---|
| 588 | ENDIF |
---|
[1] | 589 | |
---|
[1922] | 590 | ELSE |
---|
[1] | 591 | ! |
---|
[1922] | 592 | !-- x --> y |
---|
| 593 | !-- This condition must be fulfilled for a 1D-decomposition along x |
---|
| 594 | IF ( MOD( ny+1 , pdims(1) ) /= 0 ) THEN |
---|
| 595 | WRITE( message_string, * ) 'transposition x --> y:', & |
---|
[3046] | 596 | '& ny+1=',ny+1,' is not an integral divisor of',& |
---|
[1922] | 597 | ' pdims(1)=',pdims(1) |
---|
| 598 | CALL message( 'init_pegrid', 'PA0233', 1, 2, 0, 6, 0 ) |
---|
| 599 | ENDIF |
---|
| 600 | |
---|
[1] | 601 | ENDIF |
---|
| 602 | |
---|
| 603 | ENDIF |
---|
| 604 | |
---|
| 605 | ! |
---|
| 606 | !-- Indices for direct transpositions z --> y (used for calculating spectra) |
---|
[1922] | 607 | IF ( calculate_spectra ) THEN |
---|
[1003] | 608 | IF ( MOD( nz, pdims(2) ) /= 0 ) THEN |
---|
[1922] | 609 | WRITE( message_string, * ) 'direct transposition z --> y (needed ', & |
---|
[3045] | 610 | 'for spectra): nz=',nz,' is not an integral divisor of ', & |
---|
[274] | 611 | 'pdims(2)=',pdims(2) |
---|
[254] | 612 | CALL message( 'init_pegrid', 'PA0234', 1, 2, 0, 6, 0 ) |
---|
[1] | 613 | ELSE |
---|
[1003] | 614 | nxl_yd = nxl |
---|
| 615 | nxr_yd = nxr |
---|
| 616 | nzb_yd = 1 + myidy * ( nz / pdims(2) ) |
---|
| 617 | nzt_yd = ( myidy + 1 ) * ( nz / pdims(2) ) |
---|
| 618 | sendrecvcount_zyd = nnx * nny * ( nz / pdims(2) ) |
---|
[1] | 619 | ENDIF |
---|
| 620 | ENDIF |
---|
| 621 | |
---|
[1922] | 622 | IF ( psolver == 'poisfft' .OR. calculate_spectra ) THEN |
---|
[1] | 623 | ! |
---|
[1922] | 624 | !-- Indices for direct transpositions y --> x |
---|
| 625 | !-- (they are only possible in case of a 1d-decomposition along x) |
---|
| 626 | IF ( pdims(2) == 1 ) THEN |
---|
| 627 | nny_x = nny / pdims(1) |
---|
| 628 | nys_x = myid * nny_x |
---|
| 629 | nyn_x = ( myid + 1 ) * nny_x - 1 |
---|
| 630 | nzb_x = 1 |
---|
| 631 | nzt_x = nz |
---|
| 632 | sendrecvcount_xy = nnx * nny_x * nz |
---|
| 633 | ENDIF |
---|
| 634 | |
---|
[1] | 635 | ENDIF |
---|
| 636 | |
---|
[1922] | 637 | IF ( psolver == 'poisfft' ) THEN |
---|
[1] | 638 | ! |
---|
[1922] | 639 | !-- Indices for direct transpositions x --> y |
---|
| 640 | !-- (they are only possible in case of a 1d-decomposition along y) |
---|
| 641 | IF ( pdims(1) == 1 ) THEN |
---|
| 642 | nnx_y = nnx / pdims(2) |
---|
| 643 | nxl_y = myid * nnx_y |
---|
| 644 | nxr_y = ( myid + 1 ) * nnx_y - 1 |
---|
| 645 | nzb_y = 1 |
---|
| 646 | nzt_y = nz |
---|
| 647 | sendrecvcount_xy = nnx_y * nny * nz |
---|
| 648 | ENDIF |
---|
| 649 | |
---|
[1] | 650 | ENDIF |
---|
| 651 | |
---|
| 652 | ! |
---|
| 653 | !-- Arrays for storing the array bounds are needed any more |
---|
| 654 | DEALLOCATE( nxlf , nxrf , nynf , nysf ) |
---|
| 655 | |
---|
[807] | 656 | |
---|
[145] | 657 | ! |
---|
| 658 | !-- Collect index bounds from other PEs (to be written to restart file later) |
---|
| 659 | ALLOCATE( hor_index_bounds(4,0:numprocs-1) ) |
---|
| 660 | |
---|
| 661 | IF ( myid == 0 ) THEN |
---|
| 662 | |
---|
| 663 | hor_index_bounds(1,0) = nxl |
---|
| 664 | hor_index_bounds(2,0) = nxr |
---|
| 665 | hor_index_bounds(3,0) = nys |
---|
| 666 | hor_index_bounds(4,0) = nyn |
---|
| 667 | |
---|
| 668 | ! |
---|
| 669 | !-- Receive data from all other PEs |
---|
| 670 | DO i = 1, numprocs-1 |
---|
| 671 | CALL MPI_RECV( ibuf, 4, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, & |
---|
| 672 | ierr ) |
---|
| 673 | hor_index_bounds(:,i) = ibuf(1:4) |
---|
| 674 | ENDDO |
---|
| 675 | |
---|
| 676 | ELSE |
---|
| 677 | ! |
---|
| 678 | !-- Send index bounds to PE0 |
---|
| 679 | ibuf(1) = nxl |
---|
| 680 | ibuf(2) = nxr |
---|
| 681 | ibuf(3) = nys |
---|
| 682 | ibuf(4) = nyn |
---|
| 683 | CALL MPI_SEND( ibuf, 4, MPI_INTEGER, 0, myid, comm2d, ierr ) |
---|
| 684 | |
---|
| 685 | ENDIF |
---|
| 686 | |
---|
[807] | 687 | |
---|
[1] | 688 | #if defined( __print ) |
---|
| 689 | ! |
---|
| 690 | !-- Control output |
---|
| 691 | IF ( myid == 0 ) THEN |
---|
| 692 | PRINT*, '*** processor topology ***' |
---|
| 693 | PRINT*, ' ' |
---|
| 694 | PRINT*, 'myid pcoord left right south north idx idy nxl: nxr',& |
---|
| 695 | &' nys: nyn' |
---|
| 696 | PRINT*, '------------------------------------------------------------',& |
---|
| 697 | &'-----------' |
---|
| 698 | WRITE (*,1000) 0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, & |
---|
| 699 | myidx, myidy, nxl, nxr, nys, nyn |
---|
| 700 | 1000 FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3, & |
---|
| 701 | 2(2X,I4,':',I4)) |
---|
| 702 | |
---|
| 703 | ! |
---|
[108] | 704 | !-- Receive data from the other PEs |
---|
[1] | 705 | DO i = 1,numprocs-1 |
---|
| 706 | CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, & |
---|
| 707 | ierr ) |
---|
| 708 | WRITE (*,1000) i, ( ibuf(j) , j = 1,12 ) |
---|
| 709 | ENDDO |
---|
| 710 | ELSE |
---|
| 711 | |
---|
| 712 | ! |
---|
| 713 | !-- Send data to PE0 |
---|
| 714 | ibuf(1) = pcoord(1); ibuf(2) = pcoord(2); ibuf(3) = pleft |
---|
| 715 | ibuf(4) = pright; ibuf(5) = psouth; ibuf(6) = pnorth; ibuf(7) = myidx |
---|
| 716 | ibuf(8) = myidy; ibuf(9) = nxl; ibuf(10) = nxr; ibuf(11) = nys |
---|
| 717 | ibuf(12) = nyn |
---|
| 718 | CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr ) |
---|
| 719 | ENDIF |
---|
| 720 | #endif |
---|
| 721 | |
---|
[667] | 722 | ! |
---|
[709] | 723 | !-- Determine the number of ghost point layers |
---|
[1565] | 724 | IF ( ( scalar_advec == 'ws-scheme' .AND. .NOT. neutral ) .OR. & |
---|
[1557] | 725 | momentum_advec == 'ws-scheme' ) THEN |
---|
[667] | 726 | nbgp = 3 |
---|
| 727 | ELSE |
---|
| 728 | nbgp = 1 |
---|
[709] | 729 | ENDIF |
---|
[667] | 730 | |
---|
[102] | 731 | ! |
---|
[709] | 732 | !-- Create a new MPI derived datatype for the exchange of surface (xy) data, |
---|
| 733 | !-- which is needed for coupled atmosphere-ocean runs. |
---|
| 734 | !-- First, calculate number of grid points of an xy-plane. |
---|
[667] | 735 | ngp_xy = ( nxr - nxl + 1 + 2 * nbgp ) * ( nyn - nys + 1 + 2 * nbgp ) |
---|
[102] | 736 | CALL MPI_TYPE_VECTOR( ngp_xy, 1, nzt-nzb+2, MPI_REAL, type_xy, ierr ) |
---|
| 737 | CALL MPI_TYPE_COMMIT( type_xy, ierr ) |
---|
[667] | 738 | |
---|
[2365] | 739 | IF ( TRIM( coupling_mode ) /= 'uncoupled' .AND. .NOT. vnested ) THEN |
---|
[667] | 740 | |
---|
| 741 | ! |
---|
| 742 | !-- Pass the number of grid points of the atmosphere model to |
---|
| 743 | !-- the ocean model and vice versa |
---|
| 744 | IF ( coupling_mode == 'atmosphere_to_ocean' ) THEN |
---|
| 745 | |
---|
| 746 | nx_a = nx |
---|
| 747 | ny_a = ny |
---|
| 748 | |
---|
[709] | 749 | IF ( myid == 0 ) THEN |
---|
| 750 | |
---|
| 751 | CALL MPI_SEND( nx_a, 1, MPI_INTEGER, numprocs, 1, comm_inter, & |
---|
| 752 | ierr ) |
---|
| 753 | CALL MPI_SEND( ny_a, 1, MPI_INTEGER, numprocs, 2, comm_inter, & |
---|
| 754 | ierr ) |
---|
| 755 | CALL MPI_SEND( pdims, 2, MPI_INTEGER, numprocs, 3, comm_inter, & |
---|
| 756 | ierr ) |
---|
| 757 | CALL MPI_RECV( nx_o, 1, MPI_INTEGER, numprocs, 4, comm_inter, & |
---|
| 758 | status, ierr ) |
---|
| 759 | CALL MPI_RECV( ny_o, 1, MPI_INTEGER, numprocs, 5, comm_inter, & |
---|
| 760 | status, ierr ) |
---|
| 761 | CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, numprocs, 6, & |
---|
[667] | 762 | comm_inter, status, ierr ) |
---|
| 763 | ENDIF |
---|
| 764 | |
---|
[709] | 765 | CALL MPI_BCAST( nx_o, 1, MPI_INTEGER, 0, comm2d, ierr ) |
---|
| 766 | CALL MPI_BCAST( ny_o, 1, MPI_INTEGER, 0, comm2d, ierr ) |
---|
| 767 | CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr ) |
---|
[667] | 768 | |
---|
| 769 | ELSEIF ( coupling_mode == 'ocean_to_atmosphere' ) THEN |
---|
| 770 | |
---|
| 771 | nx_o = nx |
---|
| 772 | ny_o = ny |
---|
| 773 | |
---|
| 774 | IF ( myid == 0 ) THEN |
---|
[709] | 775 | |
---|
| 776 | CALL MPI_RECV( nx_a, 1, MPI_INTEGER, 0, 1, comm_inter, status, & |
---|
| 777 | ierr ) |
---|
| 778 | CALL MPI_RECV( ny_a, 1, MPI_INTEGER, 0, 2, comm_inter, status, & |
---|
| 779 | ierr ) |
---|
| 780 | CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, 0, 3, comm_inter, & |
---|
| 781 | status, ierr ) |
---|
| 782 | CALL MPI_SEND( nx_o, 1, MPI_INTEGER, 0, 4, comm_inter, ierr ) |
---|
| 783 | CALL MPI_SEND( ny_o, 1, MPI_INTEGER, 0, 5, comm_inter, ierr ) |
---|
| 784 | CALL MPI_SEND( pdims, 2, MPI_INTEGER, 0, 6, comm_inter, ierr ) |
---|
[667] | 785 | ENDIF |
---|
| 786 | |
---|
| 787 | CALL MPI_BCAST( nx_a, 1, MPI_INTEGER, 0, comm2d, ierr) |
---|
| 788 | CALL MPI_BCAST( ny_a, 1, MPI_INTEGER, 0, comm2d, ierr) |
---|
| 789 | CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr) |
---|
| 790 | |
---|
| 791 | ENDIF |
---|
| 792 | |
---|
[709] | 793 | ngp_a = ( nx_a+1 + 2 * nbgp ) * ( ny_a+1 + 2 * nbgp ) |
---|
| 794 | ngp_o = ( nx_o+1 + 2 * nbgp ) * ( ny_o+1 + 2 * nbgp ) |
---|
[667] | 795 | |
---|
| 796 | ! |
---|
[709] | 797 | !-- Determine if the horizontal grid and the number of PEs in ocean and |
---|
| 798 | !-- atmosphere is same or not |
---|
| 799 | IF ( nx_o == nx_a .AND. ny_o == ny_a .AND. & |
---|
[667] | 800 | pdims(1) == pdims_remote(1) .AND. pdims(2) == pdims_remote(2) ) & |
---|
| 801 | THEN |
---|
| 802 | coupling_topology = 0 |
---|
| 803 | ELSE |
---|
| 804 | coupling_topology = 1 |
---|
| 805 | ENDIF |
---|
| 806 | |
---|
| 807 | ! |
---|
| 808 | !-- Determine the target PEs for the exchange between ocean and |
---|
| 809 | !-- atmosphere (comm2d) |
---|
[709] | 810 | IF ( coupling_topology == 0 ) THEN |
---|
| 811 | ! |
---|
| 812 | !-- In case of identical topologies, every atmosphere PE has exactly one |
---|
| 813 | !-- ocean PE counterpart and vice versa |
---|
| 814 | IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN |
---|
[667] | 815 | target_id = myid + numprocs |
---|
| 816 | ELSE |
---|
| 817 | target_id = myid |
---|
| 818 | ENDIF |
---|
| 819 | |
---|
| 820 | ELSE |
---|
| 821 | ! |
---|
| 822 | !-- In case of nonequivalent topology in ocean and atmosphere only for |
---|
| 823 | !-- PE0 in ocean and PE0 in atmosphere a target_id is needed, since |
---|
[709] | 824 | !-- data echxchange between ocean and atmosphere will be done only |
---|
| 825 | !-- between these PEs. |
---|
| 826 | IF ( myid == 0 ) THEN |
---|
| 827 | |
---|
| 828 | IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN |
---|
[667] | 829 | target_id = numprocs |
---|
| 830 | ELSE |
---|
| 831 | target_id = 0 |
---|
| 832 | ENDIF |
---|
[709] | 833 | |
---|
[667] | 834 | ENDIF |
---|
[709] | 835 | |
---|
[667] | 836 | ENDIF |
---|
| 837 | |
---|
| 838 | ENDIF |
---|
| 839 | |
---|
[2365] | 840 | ! |
---|
| 841 | !-- Store partner grid point co-ordinates as lists. |
---|
| 842 | !-- Create custom MPI vector datatypes for contiguous data transfer |
---|
| 843 | IF ( vnested ) CALL vnest_init_pegrid_domain |
---|
[667] | 844 | |
---|
[1] | 845 | #else |
---|
| 846 | |
---|
| 847 | ! |
---|
| 848 | !-- Array bounds when running on a single PE (respectively a non-parallel |
---|
| 849 | !-- machine) |
---|
[1003] | 850 | nxl = 0 |
---|
| 851 | nxr = nx |
---|
| 852 | nnx = nxr - nxl + 1 |
---|
| 853 | nys = 0 |
---|
| 854 | nyn = ny |
---|
| 855 | nny = nyn - nys + 1 |
---|
| 856 | nzb = 0 |
---|
| 857 | nzt = nz |
---|
| 858 | nnz = nz |
---|
[1] | 859 | |
---|
[145] | 860 | ALLOCATE( hor_index_bounds(4,0:0) ) |
---|
| 861 | hor_index_bounds(1,0) = nxl |
---|
| 862 | hor_index_bounds(2,0) = nxr |
---|
| 863 | hor_index_bounds(3,0) = nys |
---|
| 864 | hor_index_bounds(4,0) = nyn |
---|
| 865 | |
---|
[1] | 866 | ! |
---|
| 867 | !-- Array bounds for the pressure solver (in the parallel code, these bounds |
---|
| 868 | !-- are the ones for the transposed arrays) |
---|
[1003] | 869 | nys_x = nys |
---|
| 870 | nyn_x = nyn |
---|
| 871 | nzb_x = nzb + 1 |
---|
| 872 | nzt_x = nzt |
---|
[1] | 873 | |
---|
[1003] | 874 | nxl_y = nxl |
---|
| 875 | nxr_y = nxr |
---|
| 876 | nzb_y = nzb + 1 |
---|
| 877 | nzt_y = nzt |
---|
[1] | 878 | |
---|
[1003] | 879 | nxl_z = nxl |
---|
| 880 | nxr_z = nxr |
---|
| 881 | nys_z = nys |
---|
| 882 | nyn_z = nyn |
---|
[1] | 883 | |
---|
| 884 | #endif |
---|
| 885 | |
---|
| 886 | ! |
---|
| 887 | !-- Calculate number of grid levels necessary for the multigrid poisson solver |
---|
| 888 | !-- as well as the gridpoint indices on each level |
---|
[1575] | 889 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
[1] | 890 | |
---|
| 891 | ! |
---|
| 892 | !-- First calculate number of possible grid levels for the subdomains |
---|
| 893 | mg_levels_x = 1 |
---|
| 894 | mg_levels_y = 1 |
---|
| 895 | mg_levels_z = 1 |
---|
| 896 | |
---|
| 897 | i = nnx |
---|
| 898 | DO WHILE ( MOD( i, 2 ) == 0 .AND. i /= 2 ) |
---|
| 899 | i = i / 2 |
---|
| 900 | mg_levels_x = mg_levels_x + 1 |
---|
| 901 | ENDDO |
---|
| 902 | |
---|
| 903 | j = nny |
---|
| 904 | DO WHILE ( MOD( j, 2 ) == 0 .AND. j /= 2 ) |
---|
| 905 | j = j / 2 |
---|
| 906 | mg_levels_y = mg_levels_y + 1 |
---|
| 907 | ENDDO |
---|
| 908 | |
---|
[181] | 909 | k = nz ! do not use nnz because it might be > nz due to transposition |
---|
| 910 | ! requirements |
---|
[1] | 911 | DO WHILE ( MOD( k, 2 ) == 0 .AND. k /= 2 ) |
---|
| 912 | k = k / 2 |
---|
| 913 | mg_levels_z = mg_levels_z + 1 |
---|
| 914 | ENDDO |
---|
[2197] | 915 | ! |
---|
| 916 | !-- The optimized MG-solver does not allow odd values for nz at the coarsest |
---|
| 917 | !-- grid level |
---|
| 918 | IF ( TRIM( psolver ) /= 'multigrid_noopt' ) THEN |
---|
| 919 | IF ( MOD( k, 2 ) /= 0 ) mg_levels_z = mg_levels_z - 1 |
---|
[3057] | 920 | ! |
---|
| 921 | !-- An odd value of nz does not work. The finest level must have an even |
---|
| 922 | !-- value. |
---|
| 923 | IF ( mg_levels_z == 0 ) THEN |
---|
| 924 | message_string = 'optimized multigrid method requires nz to be even' |
---|
[3058] | 925 | CALL message( 'init_pegrid', 'PA0495', 1, 2, 0, 6, 0 ) |
---|
[3057] | 926 | ENDIF |
---|
[2197] | 927 | ENDIF |
---|
[1] | 928 | |
---|
| 929 | maximum_grid_level = MIN( mg_levels_x, mg_levels_y, mg_levels_z ) |
---|
| 930 | |
---|
| 931 | ! |
---|
| 932 | !-- Find out, if the total domain allows more levels. These additional |
---|
[709] | 933 | !-- levels are identically processed on all PEs. |
---|
[197] | 934 | IF ( numprocs > 1 .AND. mg_switch_to_pe0_level /= -1 ) THEN |
---|
[709] | 935 | |
---|
[1] | 936 | IF ( mg_levels_z > MIN( mg_levels_x, mg_levels_y ) ) THEN |
---|
[709] | 937 | |
---|
[1] | 938 | mg_switch_to_pe0_level_l = maximum_grid_level |
---|
| 939 | |
---|
| 940 | mg_levels_x = 1 |
---|
| 941 | mg_levels_y = 1 |
---|
| 942 | |
---|
| 943 | i = nx+1 |
---|
| 944 | DO WHILE ( MOD( i, 2 ) == 0 .AND. i /= 2 ) |
---|
| 945 | i = i / 2 |
---|
| 946 | mg_levels_x = mg_levels_x + 1 |
---|
| 947 | ENDDO |
---|
| 948 | |
---|
| 949 | j = ny+1 |
---|
| 950 | DO WHILE ( MOD( j, 2 ) == 0 .AND. j /= 2 ) |
---|
| 951 | j = j / 2 |
---|
| 952 | mg_levels_y = mg_levels_y + 1 |
---|
| 953 | ENDDO |
---|
| 954 | |
---|
| 955 | maximum_grid_level_l = MIN( mg_levels_x, mg_levels_y, mg_levels_z ) |
---|
| 956 | |
---|
| 957 | IF ( maximum_grid_level_l > mg_switch_to_pe0_level_l ) THEN |
---|
| 958 | mg_switch_to_pe0_level_l = maximum_grid_level_l - & |
---|
| 959 | mg_switch_to_pe0_level_l + 1 |
---|
| 960 | ELSE |
---|
| 961 | mg_switch_to_pe0_level_l = 0 |
---|
| 962 | ENDIF |
---|
[709] | 963 | |
---|
[1] | 964 | ELSE |
---|
[3057] | 965 | |
---|
[1] | 966 | mg_switch_to_pe0_level_l = 0 |
---|
| 967 | maximum_grid_level_l = maximum_grid_level |
---|
[709] | 968 | |
---|
[1] | 969 | ENDIF |
---|
| 970 | |
---|
| 971 | ! |
---|
| 972 | !-- Use switch level calculated above only if it is not pre-defined |
---|
| 973 | !-- by user |
---|
| 974 | IF ( mg_switch_to_pe0_level == 0 ) THEN |
---|
| 975 | IF ( mg_switch_to_pe0_level_l /= 0 ) THEN |
---|
| 976 | mg_switch_to_pe0_level = mg_switch_to_pe0_level_l |
---|
| 977 | maximum_grid_level = maximum_grid_level_l |
---|
| 978 | ENDIF |
---|
| 979 | |
---|
| 980 | ELSE |
---|
| 981 | ! |
---|
| 982 | !-- Check pre-defined value and reset to default, if neccessary |
---|
[3045] | 983 | IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l .OR. & |
---|
[1] | 984 | mg_switch_to_pe0_level >= maximum_grid_level_l ) THEN |
---|
[3045] | 985 | message_string = 'mg_switch_to_pe0_level ' // & |
---|
[2271] | 986 | 'out of range and reset to 0' |
---|
[254] | 987 | CALL message( 'init_pegrid', 'PA0235', 0, 1, 0, 6, 0 ) |
---|
[1] | 988 | mg_switch_to_pe0_level = 0 |
---|
| 989 | ELSE |
---|
| 990 | ! |
---|
| 991 | !-- Use the largest number of possible levels anyway and recalculate |
---|
| 992 | !-- the switch level to this largest number of possible values |
---|
| 993 | maximum_grid_level = maximum_grid_level_l |
---|
| 994 | |
---|
| 995 | ENDIF |
---|
[709] | 996 | |
---|
[1] | 997 | ENDIF |
---|
| 998 | |
---|
| 999 | ENDIF |
---|
| 1000 | |
---|
[1056] | 1001 | ALLOCATE( grid_level_count(maximum_grid_level), & |
---|
| 1002 | nxl_mg(0:maximum_grid_level), nxr_mg(0:maximum_grid_level), & |
---|
| 1003 | nyn_mg(0:maximum_grid_level), nys_mg(0:maximum_grid_level), & |
---|
| 1004 | nzt_mg(0:maximum_grid_level) ) |
---|
[1] | 1005 | |
---|
| 1006 | grid_level_count = 0 |
---|
[1056] | 1007 | ! |
---|
| 1008 | !-- Index zero required as dummy due to definition of arrays f2 and p2 in |
---|
| 1009 | !-- recursive subroutine next_mg_level |
---|
| 1010 | nxl_mg(0) = 0; nxr_mg(0) = 0; nyn_mg(0) = 0; nys_mg(0) = 0; nzt_mg(0) = 0 |
---|
[778] | 1011 | |
---|
[1] | 1012 | nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzt_l = nzt |
---|
| 1013 | |
---|
| 1014 | DO i = maximum_grid_level, 1 , -1 |
---|
| 1015 | |
---|
| 1016 | IF ( i == mg_switch_to_pe0_level ) THEN |
---|
[1804] | 1017 | #if defined( __parallel ) |
---|
[1] | 1018 | ! |
---|
| 1019 | !-- Save the grid size of the subdomain at the switch level, because |
---|
| 1020 | !-- it is needed in poismg. |
---|
| 1021 | ind(1) = nxl_l; ind(2) = nxr_l |
---|
| 1022 | ind(3) = nys_l; ind(4) = nyn_l |
---|
| 1023 | ind(5) = nzt_l |
---|
| 1024 | ALLOCATE( ind_all(5*numprocs), mg_loc_ind(5,0:numprocs-1) ) |
---|
| 1025 | CALL MPI_ALLGATHER( ind, 5, MPI_INTEGER, ind_all, 5, & |
---|
| 1026 | MPI_INTEGER, comm2d, ierr ) |
---|
| 1027 | DO j = 0, numprocs-1 |
---|
| 1028 | DO k = 1, 5 |
---|
| 1029 | mg_loc_ind(k,j) = ind_all(k+j*5) |
---|
| 1030 | ENDDO |
---|
| 1031 | ENDDO |
---|
| 1032 | DEALLOCATE( ind_all ) |
---|
| 1033 | ! |
---|
[709] | 1034 | !-- Calculate the grid size of the total domain |
---|
[1] | 1035 | nxr_l = ( nxr_l-nxl_l+1 ) * pdims(1) - 1 |
---|
| 1036 | nxl_l = 0 |
---|
| 1037 | nyn_l = ( nyn_l-nys_l+1 ) * pdims(2) - 1 |
---|
| 1038 | nys_l = 0 |
---|
| 1039 | ! |
---|
| 1040 | !-- The size of this gathered array must not be larger than the |
---|
| 1041 | !-- array tend, which is used in the multigrid scheme as a temporary |
---|
[778] | 1042 | !-- array. Therefore the subdomain size of an PE is calculated and |
---|
| 1043 | !-- the size of the gathered grid. These values are used in |
---|
| 1044 | !-- routines pres and poismg |
---|
| 1045 | subdomain_size = ( nxr - nxl + 2 * nbgp + 1 ) * & |
---|
| 1046 | ( nyn - nys + 2 * nbgp + 1 ) * ( nzt - nzb + 2 ) |
---|
[3045] | 1047 | gathered_size = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) * & |
---|
[1] | 1048 | ( nzt_l - nzb + 2 ) |
---|
| 1049 | |
---|
[1804] | 1050 | #else |
---|
[3045] | 1051 | message_string = 'multigrid gather/scatter impossible ' // & |
---|
[1] | 1052 | 'in non parallel mode' |
---|
[254] | 1053 | CALL message( 'init_pegrid', 'PA0237', 1, 2, 0, 6, 0 ) |
---|
[1] | 1054 | #endif |
---|
| 1055 | ENDIF |
---|
| 1056 | |
---|
| 1057 | nxl_mg(i) = nxl_l |
---|
| 1058 | nxr_mg(i) = nxr_l |
---|
| 1059 | nys_mg(i) = nys_l |
---|
| 1060 | nyn_mg(i) = nyn_l |
---|
| 1061 | nzt_mg(i) = nzt_l |
---|
| 1062 | |
---|
| 1063 | nxl_l = nxl_l / 2 |
---|
| 1064 | nxr_l = nxr_l / 2 |
---|
| 1065 | nys_l = nys_l / 2 |
---|
| 1066 | nyn_l = nyn_l / 2 |
---|
| 1067 | nzt_l = nzt_l / 2 |
---|
[778] | 1068 | |
---|
[1] | 1069 | ENDDO |
---|
| 1070 | |
---|
[780] | 1071 | ! |
---|
[3045] | 1072 | !-- Temporary problem: Currently calculation of maxerror in routine poismg crashes |
---|
[780] | 1073 | !-- if grid data are collected on PE0 already on the finest grid level. |
---|
| 1074 | !-- To be solved later. |
---|
| 1075 | IF ( maximum_grid_level == mg_switch_to_pe0_level ) THEN |
---|
| 1076 | message_string = 'grid coarsening on subdomain level cannot be performed' |
---|
| 1077 | CALL message( 'poismg', 'PA0236', 1, 2, 0, 6, 0 ) |
---|
| 1078 | ENDIF |
---|
| 1079 | |
---|
[1] | 1080 | ELSE |
---|
| 1081 | |
---|
[667] | 1082 | maximum_grid_level = 0 |
---|
[1] | 1083 | |
---|
| 1084 | ENDIF |
---|
| 1085 | |
---|
[722] | 1086 | ! |
---|
| 1087 | !-- Default level 0 tells exchange_horiz that all ghost planes have to be |
---|
| 1088 | !-- exchanged. grid_level is adjusted in poismg, where only one ghost plane |
---|
| 1089 | !-- is required. |
---|
| 1090 | grid_level = 0 |
---|
[1] | 1091 | |
---|
[1804] | 1092 | #if defined( __parallel ) |
---|
[1] | 1093 | ! |
---|
| 1094 | !-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays) |
---|
[667] | 1095 | ngp_y = nyn - nys + 1 + 2 * nbgp |
---|
[1] | 1096 | |
---|
| 1097 | ! |
---|
[709] | 1098 | !-- Define new MPI derived datatypes for the exchange of ghost points in |
---|
| 1099 | !-- x- and y-direction for 2D-arrays (line) |
---|
[1968] | 1100 | CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_REAL, type_x, & |
---|
[709] | 1101 | ierr ) |
---|
[1] | 1102 | CALL MPI_TYPE_COMMIT( type_x, ierr ) |
---|
| 1103 | |
---|
[667] | 1104 | CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_REAL, type_y, ierr ) |
---|
| 1105 | CALL MPI_TYPE_COMMIT( type_y, ierr ) |
---|
[1968] | 1106 | ! |
---|
| 1107 | !-- Define new MPI derived datatypes for the exchange of ghost points in |
---|
| 1108 | !-- x- and y-direction for 2D-INTEGER arrays (line) - on normal grid |
---|
| 1109 | ALLOCATE( type_x_int(0:maximum_grid_level), & |
---|
| 1110 | type_y_int(0:maximum_grid_level) ) |
---|
[667] | 1111 | |
---|
[1968] | 1112 | CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_INTEGER, & |
---|
| 1113 | type_x_int(0), ierr ) |
---|
| 1114 | CALL MPI_TYPE_COMMIT( type_x_int(0), ierr ) |
---|
[667] | 1115 | |
---|
[1968] | 1116 | CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_INTEGER, type_y_int(0), ierr ) |
---|
| 1117 | CALL MPI_TYPE_COMMIT( type_y_int(0), ierr ) |
---|
[1] | 1118 | ! |
---|
| 1119 | !-- Calculate gridpoint numbers for the exchange of ghost points along x |
---|
| 1120 | !-- (yz-plane for 3D-arrays) and define MPI derived data type(s) for the |
---|
| 1121 | !-- exchange of ghost points in y-direction (xz-plane). |
---|
| 1122 | !-- Do these calculations for the model grid and (if necessary) also |
---|
| 1123 | !-- for the coarser grid levels used in the multigrid method |
---|
[2696] | 1124 | ALLOCATE ( ngp_xz(0:maximum_grid_level), & |
---|
| 1125 | ngp_xz_int(0:maximum_grid_level), & |
---|
| 1126 | ngp_yz(0:maximum_grid_level), & |
---|
| 1127 | ngp_yz_int(0:maximum_grid_level), & |
---|
| 1128 | type_xz(0:maximum_grid_level), & |
---|
| 1129 | type_xz_int(0:maximum_grid_level), & |
---|
| 1130 | type_yz(0:maximum_grid_level), & |
---|
| 1131 | type_yz_int(0:maximum_grid_level) ) |
---|
[1] | 1132 | |
---|
| 1133 | nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt |
---|
[709] | 1134 | |
---|
[667] | 1135 | ! |
---|
| 1136 | !-- Discern between the model grid, which needs nbgp ghost points and |
---|
| 1137 | !-- grid levels for the multigrid scheme. In the latter case only one |
---|
| 1138 | !-- ghost point is necessary. |
---|
[709] | 1139 | !-- First definition of MPI-datatypes for exchange of ghost layers on normal |
---|
[667] | 1140 | !-- grid. The following loop is needed for data exchange in poismg.f90. |
---|
| 1141 | ! |
---|
| 1142 | !-- Determine number of grid points of yz-layer for exchange |
---|
| 1143 | ngp_yz(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp) |
---|
[709] | 1144 | |
---|
[667] | 1145 | ! |
---|
[709] | 1146 | !-- Define an MPI-datatype for the exchange of left/right boundaries. |
---|
| 1147 | !-- Although data are contiguous in physical memory (which does not |
---|
| 1148 | !-- necessarily require an MPI-derived datatype), the data exchange between |
---|
| 1149 | !-- left and right PE's using the MPI-derived type is 10% faster than without. |
---|
[667] | 1150 | CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz(0), & |
---|
[709] | 1151 | MPI_REAL, type_xz(0), ierr ) |
---|
[667] | 1152 | CALL MPI_TYPE_COMMIT( type_xz(0), ierr ) |
---|
[1] | 1153 | |
---|
[709] | 1154 | CALL MPI_TYPE_VECTOR( nbgp, ngp_yz(0), ngp_yz(0), MPI_REAL, type_yz(0), & |
---|
| 1155 | ierr ) |
---|
[667] | 1156 | CALL MPI_TYPE_COMMIT( type_yz(0), ierr ) |
---|
[709] | 1157 | |
---|
[667] | 1158 | ! |
---|
[2696] | 1159 | !-- Define data types for exchange of 3D Integer arrays. |
---|
| 1160 | ngp_yz_int(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp) |
---|
| 1161 | |
---|
| 1162 | CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz_int(0), & |
---|
| 1163 | MPI_INTEGER, type_xz_int(0), ierr ) |
---|
| 1164 | CALL MPI_TYPE_COMMIT( type_xz_int(0), ierr ) |
---|
| 1165 | |
---|
| 1166 | CALL MPI_TYPE_VECTOR( nbgp, ngp_yz_int(0), ngp_yz_int(0), MPI_INTEGER, & |
---|
| 1167 | type_yz_int(0), ierr ) |
---|
| 1168 | CALL MPI_TYPE_COMMIT( type_yz_int(0), ierr ) |
---|
| 1169 | |
---|
| 1170 | ! |
---|
[709] | 1171 | !-- Definition of MPI-datatypes for multigrid method (coarser level grids) |
---|
[1575] | 1172 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
[667] | 1173 | ! |
---|
[709] | 1174 | !-- Definition of MPI-datatyoe as above, but only 1 ghost level is used |
---|
| 1175 | DO i = maximum_grid_level, 1 , -1 |
---|
[1968] | 1176 | ! |
---|
[2696] | 1177 | !-- For 3D-exchange on different multigrid level, one ghost point for |
---|
| 1178 | !-- REAL arrays, two ghost points for INTEGER arrays |
---|
[1575] | 1179 | ngp_xz(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3) |
---|
[667] | 1180 | ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3) |
---|
| 1181 | |
---|
[2696] | 1182 | ngp_xz_int(i) = (nzt_l - nzb_l + 2) * (nxr_l - nxl_l + 3) |
---|
| 1183 | ngp_yz_int(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3) |
---|
| 1184 | ! |
---|
| 1185 | !-- MPI data type for REAL arrays, for xz-layers |
---|
| 1186 | CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i), & |
---|
[709] | 1187 | MPI_REAL, type_xz(i), ierr ) |
---|
[667] | 1188 | CALL MPI_TYPE_COMMIT( type_xz(i), ierr ) |
---|
[1] | 1189 | |
---|
[2696] | 1190 | ! |
---|
| 1191 | !-- MPI data type for INTEGER arrays, for xz-layers |
---|
| 1192 | CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz_int(i), & |
---|
| 1193 | MPI_INTEGER, type_xz_int(i), ierr ) |
---|
| 1194 | CALL MPI_TYPE_COMMIT( type_xz_int(i), ierr ) |
---|
| 1195 | |
---|
| 1196 | ! |
---|
| 1197 | !-- MPI data type for REAL arrays, for yz-layers |
---|
[709] | 1198 | CALL MPI_TYPE_VECTOR( 1, ngp_yz(i), ngp_yz(i), MPI_REAL, type_yz(i), & |
---|
| 1199 | ierr ) |
---|
[667] | 1200 | CALL MPI_TYPE_COMMIT( type_yz(i), ierr ) |
---|
[2696] | 1201 | ! |
---|
| 1202 | !-- MPI data type for INTEGER arrays, for yz-layers |
---|
| 1203 | CALL MPI_TYPE_VECTOR( 1, ngp_yz_int(i), ngp_yz_int(i), MPI_INTEGER, & |
---|
| 1204 | type_yz_int(i), ierr ) |
---|
| 1205 | CALL MPI_TYPE_COMMIT( type_yz_int(i), ierr ) |
---|
[667] | 1206 | |
---|
[1968] | 1207 | |
---|
| 1208 | !-- For 2D-exchange of INTEGER arrays on coarser grid level, where 2 ghost |
---|
| 1209 | !-- points need to be exchanged. |
---|
| 1210 | CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+5, 2, nyn_l-nys_l+5, MPI_INTEGER, & |
---|
| 1211 | type_x_int(i), ierr ) |
---|
| 1212 | CALL MPI_TYPE_COMMIT( type_x_int(i), ierr ) |
---|
| 1213 | |
---|
| 1214 | |
---|
| 1215 | CALL MPI_TYPE_VECTOR( 2, nyn_l-nys_l+5, nyn_l-nys_l+5, MPI_INTEGER, & |
---|
| 1216 | type_y_int(i), ierr ) |
---|
| 1217 | CALL MPI_TYPE_COMMIT( type_y_int(i), ierr ) |
---|
| 1218 | |
---|
[667] | 1219 | nxl_l = nxl_l / 2 |
---|
| 1220 | nxr_l = nxr_l / 2 |
---|
| 1221 | nys_l = nys_l / 2 |
---|
| 1222 | nyn_l = nyn_l / 2 |
---|
| 1223 | nzt_l = nzt_l / 2 |
---|
[709] | 1224 | |
---|
[667] | 1225 | ENDDO |
---|
[709] | 1226 | |
---|
| 1227 | ENDIF |
---|
[1677] | 1228 | |
---|
[1] | 1229 | #endif |
---|
| 1230 | |
---|
[1804] | 1231 | #if defined( __parallel ) |
---|
[1] | 1232 | ! |
---|
[1933] | 1233 | !-- Setting of flags for inflow/outflow/nesting conditions. |
---|
[1964] | 1234 | IF ( pleft == MPI_PROC_NULL ) THEN |
---|
[3182] | 1235 | IF ( bc_lr == 'dirichlet/radiation' .OR. bc_lr == 'nested' .OR. & |
---|
| 1236 | bc_lr == 'nesting_offline' ) THEN |
---|
| 1237 | bc_dirichlet_l = .TRUE. |
---|
[1964] | 1238 | ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN |
---|
[3182] | 1239 | bc_radiation_l = .TRUE. |
---|
[1] | 1240 | ENDIF |
---|
| 1241 | ENDIF |
---|
[1933] | 1242 | |
---|
[1964] | 1243 | IF ( pright == MPI_PROC_NULL ) THEN |
---|
| 1244 | IF ( bc_lr == 'dirichlet/radiation' ) THEN |
---|
[3182] | 1245 | bc_radiation_r = .TRUE. |
---|
| 1246 | ELSEIF ( bc_lr == 'radiation/dirichlet' .OR. bc_lr == 'nested' .OR. & |
---|
| 1247 | bc_lr == 'nesting_offline' ) THEN |
---|
| 1248 | bc_dirichlet_r = .TRUE. |
---|
[1] | 1249 | ENDIF |
---|
| 1250 | ENDIF |
---|
| 1251 | |
---|
[1964] | 1252 | IF ( psouth == MPI_PROC_NULL ) THEN |
---|
| 1253 | IF ( bc_ns == 'dirichlet/radiation' ) THEN |
---|
[3182] | 1254 | bc_radiation_s = .TRUE. |
---|
| 1255 | ELSEIF ( bc_ns == 'radiation/dirichlet' .OR. bc_ns == 'nested' .OR. & |
---|
| 1256 | bc_ns == 'nesting_offline' ) THEN |
---|
| 1257 | bc_dirichlet_s = .TRUE. |
---|
[1] | 1258 | ENDIF |
---|
| 1259 | ENDIF |
---|
| 1260 | |
---|
[1964] | 1261 | IF ( pnorth == MPI_PROC_NULL ) THEN |
---|
[3182] | 1262 | IF ( bc_ns == 'dirichlet/radiation' .OR. bc_ns == 'nested' .OR. & |
---|
| 1263 | bc_ns == 'nesting_offline' ) THEN |
---|
| 1264 | bc_dirichlet_n = .TRUE. |
---|
[1964] | 1265 | ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN |
---|
[3182] | 1266 | bc_radiation_n = .TRUE. |
---|
[1] | 1267 | ENDIF |
---|
| 1268 | ENDIF |
---|
[2938] | 1269 | ! |
---|
| 1270 | !-- In case of synthetic turbulence geneartor determine ids. |
---|
| 1271 | !-- Please note, if no forcing or nesting is applied, the generator is applied |
---|
| 1272 | !-- only at the left lateral boundary. |
---|
| 1273 | IF ( use_syn_turb_gen ) THEN |
---|
[3182] | 1274 | IF ( bc_dirichlet_l ) THEN |
---|
[2938] | 1275 | id_stg_left_l = myidx |
---|
| 1276 | ELSE |
---|
| 1277 | id_stg_left_l = 0 |
---|
| 1278 | ENDIF |
---|
[3182] | 1279 | IF ( bc_dirichlet_r ) THEN |
---|
[2938] | 1280 | id_stg_right_l = myidx |
---|
| 1281 | ELSE |
---|
| 1282 | id_stg_right_l = 0 |
---|
| 1283 | ENDIF |
---|
[3182] | 1284 | IF ( bc_dirichlet_s ) THEN |
---|
[2938] | 1285 | id_stg_south_l = myidy |
---|
| 1286 | ELSE |
---|
| 1287 | id_stg_south_l = 0 |
---|
| 1288 | ENDIF |
---|
[3182] | 1289 | IF ( bc_dirichlet_n ) THEN |
---|
[2938] | 1290 | id_stg_north_l = myidy |
---|
| 1291 | ELSE |
---|
| 1292 | id_stg_north_l = 0 |
---|
| 1293 | ENDIF |
---|
[1968] | 1294 | |
---|
[2938] | 1295 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1296 | CALL MPI_ALLREDUCE( id_stg_left_l, id_stg_left, 1, MPI_INTEGER, & |
---|
| 1297 | MPI_SUM, comm1dx, ierr ) |
---|
| 1298 | |
---|
| 1299 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1300 | CALL MPI_ALLREDUCE( id_stg_right_l, id_stg_right, 1, MPI_INTEGER, & |
---|
| 1301 | MPI_SUM, comm1dx, ierr ) |
---|
| 1302 | |
---|
| 1303 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1304 | CALL MPI_ALLREDUCE( id_stg_south_l, id_stg_south, 1, MPI_INTEGER, & |
---|
| 1305 | MPI_SUM, comm1dy, ierr ) |
---|
| 1306 | |
---|
| 1307 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1308 | CALL MPI_ALLREDUCE( id_stg_north_l, id_stg_north, 1, MPI_INTEGER, & |
---|
| 1309 | MPI_SUM, comm1dy, ierr ) |
---|
| 1310 | |
---|
| 1311 | ENDIF |
---|
| 1312 | |
---|
[151] | 1313 | ! |
---|
| 1314 | !-- Broadcast the id of the inflow PE |
---|
[3182] | 1315 | IF ( bc_dirichlet_l ) THEN |
---|
[163] | 1316 | id_inflow_l = myidx |
---|
[151] | 1317 | ELSE |
---|
| 1318 | id_inflow_l = 0 |
---|
| 1319 | ENDIF |
---|
[622] | 1320 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[151] | 1321 | CALL MPI_ALLREDUCE( id_inflow_l, id_inflow, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 1322 | comm1dx, ierr ) |
---|
| 1323 | |
---|
[163] | 1324 | ! |
---|
| 1325 | !-- Broadcast the id of the recycling plane |
---|
| 1326 | !-- WARNING: needs to be adjusted in case of inflows other than from left side! |
---|
[1139] | 1327 | IF ( NINT( recycling_width / dx ) >= nxl .AND. & |
---|
| 1328 | NINT( recycling_width / dx ) <= nxr ) THEN |
---|
[163] | 1329 | id_recycling_l = myidx |
---|
| 1330 | ELSE |
---|
| 1331 | id_recycling_l = 0 |
---|
| 1332 | ENDIF |
---|
[622] | 1333 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[163] | 1334 | CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 1335 | comm1dx, ierr ) |
---|
| 1336 | |
---|
[2050] | 1337 | ! |
---|
| 1338 | !-- Broadcast the id of the outflow PE and outflow-source plane |
---|
| 1339 | IF ( turbulent_outflow ) THEN |
---|
| 1340 | |
---|
[3182] | 1341 | IF ( bc_radiation_r ) THEN |
---|
[2050] | 1342 | id_outflow_l = myidx |
---|
| 1343 | ELSE |
---|
| 1344 | id_outflow_l = 0 |
---|
| 1345 | ENDIF |
---|
| 1346 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1347 | CALL MPI_ALLREDUCE( id_outflow_l, id_outflow, 1, MPI_INTEGER, MPI_SUM, & |
---|
| 1348 | comm1dx, ierr ) |
---|
| 1349 | |
---|
| 1350 | IF ( NINT( outflow_source_plane / dx ) >= nxl .AND. & |
---|
| 1351 | NINT( outflow_source_plane / dx ) <= nxr ) THEN |
---|
| 1352 | id_outflow_source_l = myidx |
---|
| 1353 | ELSE |
---|
| 1354 | id_outflow_source_l = 0 |
---|
| 1355 | ENDIF |
---|
| 1356 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 1357 | CALL MPI_ALLREDUCE( id_outflow_source_l, id_outflow_source, 1, & |
---|
| 1358 | MPI_INTEGER, MPI_SUM, comm1dx, ierr ) |
---|
| 1359 | |
---|
| 1360 | ENDIF |
---|
| 1361 | |
---|
[1402] | 1362 | CALL location_message( 'finished', .TRUE. ) |
---|
[1384] | 1363 | |
---|
[1804] | 1364 | #else |
---|
[1159] | 1365 | IF ( bc_lr == 'dirichlet/radiation' ) THEN |
---|
[3182] | 1366 | bc_dirichlet_l = .TRUE. |
---|
| 1367 | bc_radiation_r = .TRUE. |
---|
[1159] | 1368 | ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN |
---|
[3182] | 1369 | bc_radiation_l = .TRUE. |
---|
| 1370 | bc_dirichlet_r = .TRUE. |
---|
[1] | 1371 | ENDIF |
---|
| 1372 | |
---|
[1159] | 1373 | IF ( bc_ns == 'dirichlet/radiation' ) THEN |
---|
[3182] | 1374 | bc_dirichlet_n = .TRUE. |
---|
| 1375 | bc_radiation_s = .TRUE. |
---|
[1159] | 1376 | ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN |
---|
[3182] | 1377 | bc_radiation_n = .TRUE. |
---|
| 1378 | bc_dirichlet_s = .TRUE. |
---|
[1] | 1379 | ENDIF |
---|
| 1380 | #endif |
---|
[807] | 1381 | |
---|
[106] | 1382 | ! |
---|
[978] | 1383 | !-- At the inflow or outflow, u or v, respectively, have to be calculated for |
---|
| 1384 | !-- one more grid point. |
---|
[3182] | 1385 | IF ( bc_dirichlet_l .OR. bc_radiation_l ) THEN |
---|
[106] | 1386 | nxlu = nxl + 1 |
---|
| 1387 | ELSE |
---|
| 1388 | nxlu = nxl |
---|
| 1389 | ENDIF |
---|
[3182] | 1390 | IF ( bc_dirichlet_s .OR. bc_radiation_s ) THEN |
---|
[106] | 1391 | nysv = nys + 1 |
---|
| 1392 | ELSE |
---|
| 1393 | nysv = nys |
---|
| 1394 | ENDIF |
---|
[1] | 1395 | |
---|
[114] | 1396 | ! |
---|
| 1397 | !-- Allocate wall flag arrays used in the multigrid solver |
---|
[1575] | 1398 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
[114] | 1399 | |
---|
| 1400 | DO i = maximum_grid_level, 1, -1 |
---|
| 1401 | |
---|
| 1402 | SELECT CASE ( i ) |
---|
| 1403 | |
---|
| 1404 | CASE ( 1 ) |
---|
| 1405 | ALLOCATE( wall_flags_1(nzb:nzt_mg(i)+1, & |
---|
| 1406 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1407 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1408 | |
---|
| 1409 | CASE ( 2 ) |
---|
| 1410 | ALLOCATE( wall_flags_2(nzb:nzt_mg(i)+1, & |
---|
| 1411 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1412 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1413 | |
---|
| 1414 | CASE ( 3 ) |
---|
| 1415 | ALLOCATE( wall_flags_3(nzb:nzt_mg(i)+1, & |
---|
| 1416 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1417 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1418 | |
---|
| 1419 | CASE ( 4 ) |
---|
| 1420 | ALLOCATE( wall_flags_4(nzb:nzt_mg(i)+1, & |
---|
| 1421 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1422 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1423 | |
---|
| 1424 | CASE ( 5 ) |
---|
| 1425 | ALLOCATE( wall_flags_5(nzb:nzt_mg(i)+1, & |
---|
| 1426 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1427 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1428 | |
---|
| 1429 | CASE ( 6 ) |
---|
| 1430 | ALLOCATE( wall_flags_6(nzb:nzt_mg(i)+1, & |
---|
| 1431 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1432 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1433 | |
---|
| 1434 | CASE ( 7 ) |
---|
| 1435 | ALLOCATE( wall_flags_7(nzb:nzt_mg(i)+1, & |
---|
| 1436 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1437 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1438 | |
---|
| 1439 | CASE ( 8 ) |
---|
| 1440 | ALLOCATE( wall_flags_8(nzb:nzt_mg(i)+1, & |
---|
| 1441 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1442 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1443 | |
---|
| 1444 | CASE ( 9 ) |
---|
| 1445 | ALLOCATE( wall_flags_9(nzb:nzt_mg(i)+1, & |
---|
| 1446 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1447 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1448 | |
---|
| 1449 | CASE ( 10 ) |
---|
| 1450 | ALLOCATE( wall_flags_10(nzb:nzt_mg(i)+1, & |
---|
| 1451 | nys_mg(i)-1:nyn_mg(i)+1, & |
---|
| 1452 | nxl_mg(i)-1:nxr_mg(i)+1) ) |
---|
| 1453 | |
---|
| 1454 | CASE DEFAULT |
---|
[254] | 1455 | message_string = 'more than 10 multigrid levels' |
---|
| 1456 | CALL message( 'init_pegrid', 'PA0238', 1, 2, 0, 6, 0 ) |
---|
[114] | 1457 | |
---|
| 1458 | END SELECT |
---|
| 1459 | |
---|
| 1460 | ENDDO |
---|
| 1461 | |
---|
| 1462 | ENDIF |
---|
| 1463 | |
---|
[1] | 1464 | END SUBROUTINE init_pegrid |
---|