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