[1682] | 1 | !> @file exchange_horiz_2d.f90 |
---|
[1036] | 2 | !--------------------------------------------------------------------------------! |
---|
| 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
| 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 8 | ! |
---|
| 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | ! |
---|
| 13 | ! You should have received a copy of the GNU General Public License along with |
---|
| 14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | ! |
---|
[1818] | 16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1036] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
[484] | 19 | ! Current revisions: |
---|
[1] | 20 | ! ----------------- |
---|
[1683] | 21 | ! |
---|
[1969] | 22 | ! |
---|
[1321] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: exchange_horiz_2d.f90 1969 2016-07-18 12:03:12Z gronemeier $ |
---|
| 26 | ! |
---|
[1969] | 27 | ! 1968 2016-07-18 12:01:49Z suehring |
---|
| 28 | ! 2D-INTEGER exchange adopted for different multigrid level |
---|
| 29 | ! |
---|
[1933] | 30 | ! 1818 2016-04-06 15:53:27Z maronga |
---|
| 31 | ! Initial version of purely vertical nesting introduced. |
---|
| 32 | ! |
---|
[1805] | 33 | ! 1804 2016-04-05 16:30:18Z maronga |
---|
| 34 | ! Removed code for parameter file check (__check) |
---|
| 35 | ! |
---|
[1763] | 36 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 37 | ! Introduction of nested domain feature |
---|
| 38 | ! |
---|
[1683] | 39 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 40 | ! Code annotations made doxygen readable |
---|
| 41 | ! |
---|
[1349] | 42 | ! 1348 2014-03-27 18:01:03Z raasch |
---|
| 43 | ! bugfix: bc_lr_cyc and bc_ns_cyc added to ONLY-list |
---|
| 44 | ! |
---|
[1321] | 45 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 46 | ! ONLY-attribute added to USE-statements, |
---|
| 47 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 48 | ! kinds are defined in new module kinds, |
---|
| 49 | ! revision history before 2012 removed, |
---|
| 50 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 51 | ! all variable declaration statements |
---|
[1] | 52 | ! |
---|
[1093] | 53 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 54 | ! unused variables removed |
---|
| 55 | ! |
---|
[1037] | 56 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 57 | ! code put under GPL (PALM 3.9) |
---|
| 58 | ! |
---|
[842] | 59 | ! 841 2012-02-28 12:29:49Z maronga |
---|
| 60 | ! Excluded routine from compilation of namelist_file_check |
---|
| 61 | ! |
---|
[1] | 62 | ! Revision 1.1 1998/01/23 09:58:21 raasch |
---|
| 63 | ! Initial revision |
---|
| 64 | ! |
---|
| 65 | ! |
---|
| 66 | ! Description: |
---|
| 67 | ! ------------ |
---|
[1682] | 68 | !> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic |
---|
| 69 | !> boundary conditions, respectively, for 2D-arrays. |
---|
[1] | 70 | !------------------------------------------------------------------------------! |
---|
[1682] | 71 | SUBROUTINE exchange_horiz_2d( ar ) |
---|
| 72 | |
---|
[1] | 73 | |
---|
[1320] | 74 | USE control_parameters, & |
---|
[1348] | 75 | ONLY : bc_lr_cyc, bc_ns_cyc, inflow_l, inflow_n, inflow_r, inflow_s, & |
---|
[1762] | 76 | nest_bound_l, nest_bound_n, nest_bound_r, nest_bound_s, & |
---|
[1348] | 77 | outflow_l, outflow_n, outflow_r, outflow_s |
---|
[1320] | 78 | |
---|
| 79 | USE cpulog, & |
---|
| 80 | ONLY : cpu_log, log_point_s |
---|
| 81 | |
---|
| 82 | USE indices, & |
---|
| 83 | ONLY : nbgp, nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg |
---|
| 84 | |
---|
| 85 | USE kinds |
---|
| 86 | |
---|
[1] | 87 | USE pegrid |
---|
| 88 | |
---|
[1933] | 89 | USE pmc_interface, & |
---|
| 90 | ONLY : nesting_mode |
---|
| 91 | |
---|
| 92 | |
---|
[1] | 93 | IMPLICIT NONE |
---|
| 94 | |
---|
[841] | 95 | |
---|
[1682] | 96 | INTEGER(iwp) :: i !< |
---|
[1320] | 97 | |
---|
[1682] | 98 | REAL(wp) :: ar(nysg:nyng,nxlg:nxrg) !< |
---|
[1320] | 99 | |
---|
[1] | 100 | |
---|
| 101 | CALL cpu_log( log_point_s(13), 'exchange_horiz_2d', 'start' ) |
---|
| 102 | |
---|
| 103 | #if defined( __parallel ) |
---|
| 104 | |
---|
| 105 | ! |
---|
| 106 | !-- Exchange of lateral boundary values for parallel computers |
---|
| 107 | IF ( pdims(1) == 1 ) THEN |
---|
| 108 | |
---|
| 109 | ! |
---|
| 110 | !-- One-dimensional decomposition along y, boundary values can be exchanged |
---|
| 111 | !-- within the PE memory |
---|
[702] | 112 | ar(:,nxlg:nxl-1) = ar(:,nxr-nbgp+1:nxr) |
---|
| 113 | ar(:,nxr+1:nxrg) = ar(:,nxl:nxl+nbgp-1) |
---|
[1] | 114 | |
---|
| 115 | ELSE |
---|
| 116 | ! |
---|
| 117 | !-- Send left boundary, receive right one |
---|
[667] | 118 | |
---|
[702] | 119 | CALL MPI_SENDRECV( ar(nysg,nxl), 1, type_y, pleft, 0, & |
---|
| 120 | ar(nysg,nxr+1), 1, type_y, pright, 0, & |
---|
[1] | 121 | comm2d, status, ierr ) |
---|
| 122 | ! |
---|
| 123 | !-- Send right boundary, receive left one |
---|
[702] | 124 | CALL MPI_SENDRECV( ar(nysg,nxr+1-nbgp), 1, type_y, pright, 1, & |
---|
| 125 | ar(nysg,nxlg), 1, type_y, pleft, 1, & |
---|
[1] | 126 | comm2d, status, ierr ) |
---|
[702] | 127 | |
---|
| 128 | |
---|
[1] | 129 | ENDIF |
---|
| 130 | |
---|
| 131 | IF ( pdims(2) == 1 ) THEN |
---|
| 132 | ! |
---|
| 133 | !-- One-dimensional decomposition along x, boundary values can be exchanged |
---|
| 134 | !-- within the PE memory |
---|
[702] | 135 | ar(nysg:nys-1,:) = ar(nyn-nbgp+1:nyn,:) |
---|
| 136 | ar(nyn+1:nyng,:) = ar(nys:nys+nbgp-1,:) |
---|
[1] | 137 | |
---|
| 138 | ELSE |
---|
| 139 | ! |
---|
| 140 | !-- Send front boundary, receive rear one |
---|
[667] | 141 | |
---|
[702] | 142 | CALL MPI_SENDRECV( ar(nys,nxlg), 1, type_x, psouth, 0, & |
---|
| 143 | ar(nyn+1,nxlg), 1, type_x, pnorth, 0, & |
---|
[1] | 144 | comm2d, status, ierr ) |
---|
| 145 | ! |
---|
| 146 | !-- Send rear boundary, receive front one |
---|
[702] | 147 | CALL MPI_SENDRECV( ar(nyn+1-nbgp,nxlg), 1, type_x, pnorth, 1, & |
---|
| 148 | ar(nysg,nxlg), 1, type_x, psouth, 1, & |
---|
[1] | 149 | comm2d, status, ierr ) |
---|
[667] | 150 | |
---|
[1] | 151 | ENDIF |
---|
| 152 | |
---|
| 153 | #else |
---|
| 154 | |
---|
| 155 | ! |
---|
| 156 | !-- Lateral boundary conditions in the non-parallel case |
---|
[707] | 157 | IF ( bc_lr_cyc ) THEN |
---|
[702] | 158 | ar(:,nxlg:nxl-1) = ar(:,nxr-nbgp+1:nxr) |
---|
| 159 | ar(:,nxr+1:nxrg) = ar(:,nxl:nxl+nbgp-1) |
---|
[1] | 160 | ENDIF |
---|
| 161 | |
---|
[707] | 162 | IF ( bc_ns_cyc ) THEN |
---|
[702] | 163 | ar(nysg:nys-1,:) = ar(nyn-nbgp+1:nyn,:) |
---|
| 164 | ar(nyn+1:nyng,:) = ar(nys:nys+nbgp-1,:) |
---|
[1] | 165 | ENDIF |
---|
| 166 | |
---|
[667] | 167 | |
---|
[1] | 168 | #endif |
---|
| 169 | |
---|
[73] | 170 | ! |
---|
[1762] | 171 | !-- Neumann-conditions at inflow/outflow/nested boundaries |
---|
[1933] | 172 | IF ( nesting_mode /= 'vertical' ) THEN |
---|
| 173 | IF ( inflow_l .OR. outflow_l .OR. nest_bound_l ) THEN |
---|
| 174 | DO i = nbgp, 1, -1 |
---|
| 175 | ar(:,nxl-i) = ar(:,nxl) |
---|
| 176 | ENDDO |
---|
| 177 | ENDIF |
---|
| 178 | IF ( inflow_r .OR. outflow_r .OR. nest_bound_r ) THEN |
---|
| 179 | DO i = 1, nbgp |
---|
| 180 | ar(:,nxr+i) = ar(:,nxr) |
---|
| 181 | ENDDO |
---|
| 182 | ENDIF |
---|
| 183 | IF ( inflow_s .OR. outflow_s .OR. nest_bound_s ) THEN |
---|
| 184 | DO i = nbgp, 1, -1 |
---|
| 185 | ar(nys-i,:) = ar(nys,:) |
---|
| 186 | ENDDO |
---|
| 187 | ENDIF |
---|
| 188 | IF ( inflow_n .OR. outflow_n .OR. nest_bound_n ) THEN |
---|
| 189 | DO i = 1, nbgp |
---|
| 190 | ar(nyn+i,:) = ar(nyn,:) |
---|
| 191 | ENDDO |
---|
| 192 | ENDIF |
---|
[1762] | 193 | ENDIF |
---|
| 194 | |
---|
[1] | 195 | CALL cpu_log( log_point_s(13), 'exchange_horiz_2d', 'stop' ) |
---|
| 196 | |
---|
| 197 | END SUBROUTINE exchange_horiz_2d |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | !------------------------------------------------------------------------------! |
---|
| 202 | ! Description: |
---|
| 203 | ! ------------ |
---|
[1682] | 204 | !> Exchange of lateral (ghost) boundaries (parallel computers) and cyclic |
---|
| 205 | !> boundary conditions, respectively, for 2D integer arrays. |
---|
[1] | 206 | !------------------------------------------------------------------------------! |
---|
[1682] | 207 | |
---|
[1968] | 208 | SUBROUTINE exchange_horiz_2d_int( ar, nys_l, nyn_l, nxl_l, nxr_l, nbgp_local ) |
---|
[1] | 209 | |
---|
[1682] | 210 | |
---|
[1320] | 211 | USE control_parameters, & |
---|
[1968] | 212 | ONLY: bc_lr_cyc, bc_ns_cyc, grid_level, nest_bound_l, nest_bound_n, & |
---|
| 213 | nest_bound_r, nest_bound_s |
---|
[1320] | 214 | |
---|
| 215 | USE cpulog, & |
---|
| 216 | ONLY: cpu_log, log_point_s |
---|
[1968] | 217 | |
---|
[1320] | 218 | USE kinds |
---|
| 219 | |
---|
[1] | 220 | USE pegrid |
---|
| 221 | |
---|
| 222 | IMPLICIT NONE |
---|
| 223 | |
---|
[1968] | 224 | INTEGER(iwp) :: i !< dummy index to zero-gradient conditions at in/outflow boundaries |
---|
| 225 | INTEGER(iwp) :: nxl_l !< local index bound at current grid level, left side |
---|
| 226 | INTEGER(iwp) :: nxr_l !< local index bound at current grid level, right side |
---|
| 227 | INTEGER(iwp) :: nyn_l !< local index bound at current grid level, north side |
---|
| 228 | INTEGER(iwp) :: nys_l !< local index bound at current grid level, south side |
---|
| 229 | INTEGER(iwp) :: nbgp_local !< number of ghost layers to be exchanged |
---|
[1] | 230 | |
---|
[1968] | 231 | INTEGER(iwp), DIMENSION(nys_l-nbgp_local:nyn_l+nbgp_local, & |
---|
| 232 | nxl_l-nbgp_local:nxr_l+nbgp_local) :: ar !< treated array |
---|
| 233 | |
---|
[1] | 234 | CALL cpu_log( log_point_s(13), 'exchange_horiz_2d', 'start' ) |
---|
| 235 | |
---|
| 236 | #if defined( __parallel ) |
---|
| 237 | |
---|
| 238 | ! |
---|
| 239 | !-- Exchange of lateral boundary values for parallel computers |
---|
| 240 | IF ( pdims(1) == 1 ) THEN |
---|
| 241 | |
---|
| 242 | ! |
---|
| 243 | !-- One-dimensional decomposition along y, boundary values can be exchanged |
---|
| 244 | !-- within the PE memory |
---|
[1968] | 245 | ar(:,nxl_l-nbgp_local:nxl_l-1) = ar(:,nxr_l-nbgp_local+1:nxr_l) |
---|
| 246 | ar(:,nxr_l+1:nxr_l+nbgp_local) = ar(:,nxl_l:nxl_l+nbgp_local-1) |
---|
[1] | 247 | |
---|
| 248 | ELSE |
---|
| 249 | ! |
---|
| 250 | !-- Send left boundary, receive right one |
---|
[1968] | 251 | CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxl_l), 1, & |
---|
| 252 | type_y_int(grid_level), pleft, 0, & |
---|
| 253 | ar(nys_l-nbgp_local,nxr_l+1), 1, & |
---|
| 254 | type_y_int(grid_level), pright, 0, & |
---|
[1] | 255 | comm2d, status, ierr ) |
---|
| 256 | ! |
---|
| 257 | !-- Send right boundary, receive left one |
---|
[1968] | 258 | CALL MPI_SENDRECV( ar(nys_l-nbgp_local,nxr_l+1-nbgp_local), 1, & |
---|
| 259 | type_y_int(grid_level), pright, 1, & |
---|
| 260 | ar(nys_l-nbgp_local,nxl_l-nbgp_local), 1, & |
---|
| 261 | type_y_int(grid_level), pleft, 1, & |
---|
| 262 | comm2d, status, ierr ) |
---|
[667] | 263 | |
---|
[1] | 264 | ENDIF |
---|
| 265 | |
---|
| 266 | IF ( pdims(2) == 1 ) THEN |
---|
| 267 | ! |
---|
| 268 | !-- One-dimensional decomposition along x, boundary values can be exchanged |
---|
| 269 | !-- within the PE memory |
---|
[1968] | 270 | ar(nys_l-nbgp_local:nys_l-1,:) = ar(nyn_l+1-nbgp_local:nyn_l,:) |
---|
| 271 | ar(nyn_l+1:nyn_l+nbgp_local,:) = ar(nys_l:nys_l-1+nbgp_local,:) |
---|
[1] | 272 | |
---|
[667] | 273 | |
---|
[1] | 274 | ELSE |
---|
| 275 | ! |
---|
| 276 | !-- Send front boundary, receive rear one |
---|
[1968] | 277 | CALL MPI_SENDRECV( ar(nys_l,nxl_l-nbgp_local), 1, & |
---|
| 278 | type_x_int(grid_level), psouth, 0, & |
---|
| 279 | ar(nyn_l+1,nxl_l-nbgp_local), 1, & |
---|
| 280 | type_x_int(grid_level), pnorth, 0, & |
---|
[702] | 281 | comm2d, status, ierr ) |
---|
[667] | 282 | |
---|
[1] | 283 | ! |
---|
| 284 | !-- Send rear boundary, receive front one |
---|
[1968] | 285 | CALL MPI_SENDRECV( ar(nyn_l+1-nbgp_local,nxl_l-nbgp_local), 1, & |
---|
| 286 | type_x_int(grid_level), pnorth, 1, & |
---|
| 287 | ar(nys_l-nbgp_local,nxl_l-nbgp_local), 1, & |
---|
| 288 | type_x_int(grid_level), psouth, 1, & |
---|
[1] | 289 | comm2d, status, ierr ) |
---|
[667] | 290 | |
---|
[1] | 291 | ENDIF |
---|
| 292 | |
---|
| 293 | #else |
---|
| 294 | |
---|
| 295 | ! |
---|
| 296 | !-- Lateral boundary conditions in the non-parallel case |
---|
[707] | 297 | IF ( bc_lr_cyc ) THEN |
---|
[1968] | 298 | ar(:,nxl_l-nbgp_local:nxl_l-1) = ar(:,nxr_l-nbgp_local+1:nxr_l) |
---|
| 299 | ar(:,nxr_l+1:nxr_l+nbgp_local) = ar(:,nxl_l:nxl_l+nbgp_local-1) |
---|
[1] | 300 | ENDIF |
---|
| 301 | |
---|
[707] | 302 | IF ( bc_ns_cyc ) THEN |
---|
[1968] | 303 | ar(nys_l-nbgp_local:nys_l-1,:) = ar(nyn_l+1-nbgp_local:nyn_l,:) |
---|
| 304 | ar(nyn_l+1:nyn_l+nbgp_local,:) = ar(nys_l:nys_l-1+nbgp_local,:) |
---|
[1] | 305 | ENDIF |
---|
| 306 | |
---|
| 307 | #endif |
---|
[1762] | 308 | ! |
---|
| 309 | !-- Neumann-conditions at inflow/outflow/nested boundaries |
---|
| 310 | IF ( nest_bound_l ) THEN |
---|
[1968] | 311 | DO i = nbgp_local, 1, -1 |
---|
| 312 | ar(:,nxl_l-i) = ar(:,nxl_l) |
---|
[1762] | 313 | ENDDO |
---|
| 314 | ENDIF |
---|
| 315 | IF ( nest_bound_r ) THEN |
---|
[1968] | 316 | DO i = 1, nbgp_local |
---|
| 317 | ar(:,nxr_l+i) = ar(:,nxr_l) |
---|
[1762] | 318 | ENDDO |
---|
| 319 | ENDIF |
---|
| 320 | IF ( nest_bound_s ) THEN |
---|
[1968] | 321 | DO i = nbgp_local, 1, -1 |
---|
| 322 | ar(nys_l-i,:) = ar(nys_l,:) |
---|
[1762] | 323 | ENDDO |
---|
| 324 | ENDIF |
---|
| 325 | IF ( nest_bound_n ) THEN |
---|
[1968] | 326 | DO i = 1, nbgp_local |
---|
| 327 | ar(nyn_l+i,:) = ar(nyn_l,:) |
---|
[1762] | 328 | ENDDO |
---|
| 329 | ENDIF |
---|
| 330 | |
---|
[1] | 331 | CALL cpu_log( log_point_s(13), 'exchange_horiz_2d', 'stop' ) |
---|
| 332 | |
---|
| 333 | END SUBROUTINE exchange_horiz_2d_int |
---|