[2696] | 1 | !> @file pmc_handle_communicator_mod.f90 |
---|
[4649] | 2 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1762] | 4 | ! |
---|
[4649] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General |
---|
| 6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
| 7 | ! (at your option) any later version. |
---|
[1762] | 8 | ! |
---|
[4649] | 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
| 10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 11 | ! Public License for more details. |
---|
[1762] | 12 | ! |
---|
[4649] | 13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
| 14 | ! <http://www.gnu.org/licenses/>. |
---|
[1762] | 15 | ! |
---|
[4828] | 16 | ! Copyright 1997-2021 Leibniz Universitaet Hannover |
---|
[4649] | 17 | !--------------------------------------------------------------------------------------------------! |
---|
[1762] | 18 | ! |
---|
[4649] | 19 | ! |
---|
[1762] | 20 | ! Current revisions: |
---|
[4649] | 21 | ! ----------------- |
---|
[4629] | 22 | ! |
---|
| 23 | ! |
---|
[1792] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: pmc_handle_communicator_mod.f90 4843 2021-01-15 15:22:11Z raasch $ |
---|
[4843] | 27 | ! local namelist parameter added to switch off the module although the respective module namelist |
---|
| 28 | ! appears in the namelist file |
---|
| 29 | ! |
---|
| 30 | ! 4828 2021-01-05 11:21:41Z Giersch |
---|
[4771] | 31 | ! Canopy-restricted anterpolation introduced. New namelist parameter anterpolation_starting_height |
---|
| 32 | ! introduced for controlling canopy-restricted anterpolation. |
---|
| 33 | ! |
---|
| 34 | ! 4650 2020-08-25 14:35:50Z raasch |
---|
[4650] | 35 | ! bugfix for r4649 |
---|
| 36 | ! |
---|
| 37 | ! 4649 2020-08-25 12:11:17Z raasch |
---|
[4649] | 38 | ! File re-formatted to follow the PALM coding standard |
---|
| 39 | ! |
---|
| 40 | ! |
---|
| 41 | ! 4629 2020-07-29 09:37:56Z raasch |
---|
| 42 | ! Support for MPI Fortran77 interface (mpif.h) removed |
---|
| 43 | ! |
---|
[4629] | 44 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 45 | ! Corrected "Former revisions" section |
---|
[4649] | 46 | ! |
---|
[4182] | 47 | ! 3888 2019-04-12 09:18:10Z hellstea |
---|
[3888] | 48 | ! Missing MPI_BCAST of anterpolation_buffer_width added. |
---|
[4649] | 49 | ! |
---|
[3888] | 50 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
[4649] | 51 | ! Changes related to global restructuring of location messages and introduction of additional debug |
---|
| 52 | ! messages |
---|
| 53 | ! |
---|
[3885] | 54 | ! 3819 2019-03-27 11:01:36Z hellstea |
---|
[4649] | 55 | ! Adjustable anterpolation buffer introduced on all nest boundaries, it is controlled by the new |
---|
| 56 | ! nesting_parameters parameter anterpolation_buffer_width. |
---|
| 57 | ! |
---|
[3819] | 58 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[2932] | 59 | ! nestpar renamed to nesting_parameters |
---|
[4649] | 60 | ! |
---|
[4182] | 61 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 62 | ! Initial revision by K. Ketelsen |
---|
[1792] | 63 | ! |
---|
[1762] | 64 | ! Description: |
---|
| 65 | ! ------------ |
---|
[1764] | 66 | ! Handle MPI communicator in PALM model coupler |
---|
[4649] | 67 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 68 | MODULE PMC_handle_communicator |
---|
[1764] | 69 | #if defined( __parallel ) |
---|
| 70 | USE kinds |
---|
[1762] | 71 | |
---|
[1764] | 72 | USE MPI |
---|
[1762] | 73 | |
---|
[4649] | 74 | USE pmc_general, & |
---|
| 75 | ONLY: pmc_max_models, & |
---|
| 76 | pmc_status_error, & |
---|
| 77 | pmc_status_ok |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | USE control_parameters, & |
---|
[1933] | 81 | ONLY: message_string |
---|
[1762] | 82 | |
---|
[1900] | 83 | IMPLICIT NONE |
---|
[1762] | 84 | |
---|
[4650] | 85 | ! |
---|
| 86 | !-- ATTENTION: Do not change the order of variable declarations in the following TYPE definition, |
---|
| 87 | !-- because the order must follow the order in which the layout data is given in the NAMELIST file. |
---|
[1900] | 88 | TYPE pmc_layout |
---|
[1762] | 89 | |
---|
[4649] | 90 | CHARACTER(LEN=32) :: name !< |
---|
[1762] | 91 | |
---|
[4649] | 92 | INTEGER :: id !< |
---|
[4650] | 93 | INTEGER :: parent_id !< |
---|
[4649] | 94 | INTEGER :: npe_total !< |
---|
[1762] | 95 | |
---|
[1900] | 96 | REAL(wp) :: lower_left_x !< |
---|
| 97 | REAL(wp) :: lower_left_y !< |
---|
[1762] | 98 | |
---|
[1900] | 99 | END TYPE pmc_layout |
---|
[1764] | 100 | |
---|
[4649] | 101 | PUBLIC pmc_status_ok, pmc_status_error !< |
---|
[1764] | 102 | |
---|
[2599] | 103 | INTEGER, PARAMETER, PUBLIC :: pmc_error_npes = 1 !< illegal number of processes |
---|
[2932] | 104 | INTEGER, PARAMETER, PUBLIC :: pmc_namelist_error = 2 !< error(s) in nesting_parameters namelist |
---|
[1900] | 105 | INTEGER, PARAMETER, PUBLIC :: pmc_no_namelist_found = 3 !< no couple layout namelist found |
---|
[1764] | 106 | |
---|
[2801] | 107 | INTEGER :: m_my_cpl_id !< coupler id of this model |
---|
[4649] | 108 | INTEGER :: m_ncpl !< number of couplers given in nesting_parameters namelist |
---|
[1900] | 109 | INTEGER :: m_parent_id !< coupler id of parent of this model |
---|
[4649] | 110 | INTEGER :: m_world_comm !< global nesting communicator |
---|
[1762] | 111 | |
---|
[2801] | 112 | TYPE(pmc_layout), PUBLIC, DIMENSION(pmc_max_models) :: m_couplers !< information of all couplers |
---|
[1762] | 113 | |
---|
[1900] | 114 | INTEGER, PUBLIC :: m_model_comm !< communicator of this model |
---|
[4649] | 115 | INTEGER, PUBLIC :: m_model_npes !< |
---|
| 116 | INTEGER, PUBLIC :: m_model_rank !< |
---|
[1933] | 117 | INTEGER, PUBLIC :: m_to_parent_comm !< communicator to the parent |
---|
[1900] | 118 | INTEGER, PUBLIC :: m_world_rank !< |
---|
[4649] | 119 | INTEGER :: m_parent_remote_size !< number of processes in the parent model |
---|
[1900] | 120 | INTEGER :: m_world_npes !< |
---|
[2599] | 121 | INTEGER :: peer_comm !< peer_communicator for inter communicators |
---|
[1791] | 122 | |
---|
[4649] | 123 | INTEGER, DIMENSION(pmc_max_models), PUBLIC :: m_to_child_comm !< communicator to the child(ren) |
---|
| 124 | INTEGER, DIMENSION(:), POINTER, PUBLIC :: pmc_parent_for_child !< |
---|
[1762] | 125 | |
---|
| 126 | |
---|
[4649] | 127 | INTERFACE pmc_get_model_info |
---|
| 128 | MODULE PROCEDURE pmc_get_model_info |
---|
| 129 | END INTERFACE pmc_get_model_info |
---|
| 130 | |
---|
[1900] | 131 | INTERFACE pmc_is_rootmodel |
---|
| 132 | MODULE PROCEDURE pmc_is_rootmodel |
---|
| 133 | END INTERFACE pmc_is_rootmodel |
---|
[1762] | 134 | |
---|
[4649] | 135 | PUBLIC pmc_get_model_info, pmc_init_model, pmc_is_rootmodel !< |
---|
[1762] | 136 | |
---|
| 137 | |
---|
[4649] | 138 | |
---|
[1764] | 139 | CONTAINS |
---|
[1762] | 140 | |
---|
[4649] | 141 | |
---|
| 142 | !--------------------------------------------------------------------------------------------------! |
---|
| 143 | ! Description: |
---|
| 144 | ! ------------ |
---|
| 145 | !> @Todo: Missing subroutine description. |
---|
| 146 | !--------------------------------------------------------------------------------------------------! |
---|
| 147 | SUBROUTINE pmc_init_model( comm, nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 148 | anterpolation_buffer_width, anterpolation_starting_height, pmc_status ) |
---|
[1762] | 149 | |
---|
[4649] | 150 | USE control_parameters, & |
---|
[1900] | 151 | ONLY: message_string |
---|
[1764] | 152 | |
---|
[4649] | 153 | USE pegrid, & |
---|
[1900] | 154 | ONLY: myid |
---|
[1764] | 155 | |
---|
| 156 | IMPLICIT NONE |
---|
| 157 | |
---|
[4649] | 158 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_datatransfer_mode !< |
---|
[2696] | 159 | CHARACTER(LEN=8), INTENT(INOUT) :: nesting_mode !< |
---|
[1764] | 160 | |
---|
[4649] | 161 | INTEGER, INTENT(INOUT) :: anterpolation_buffer_width !< Boundary buffer width for anterpolation |
---|
| 162 | INTEGER, INTENT(INOUT) :: comm !< |
---|
| 163 | INTEGER, INTENT(INOUT) :: pmc_status !< |
---|
[1764] | 164 | |
---|
[4771] | 165 | REAL(wp), INTENT(INOUT) :: anterpolation_starting_height !< steering parameter for canopy restricted anterpolation |
---|
| 166 | |
---|
[1933] | 167 | INTEGER :: childcount !< |
---|
[1900] | 168 | INTEGER :: i !< |
---|
| 169 | INTEGER :: ierr !< |
---|
| 170 | INTEGER :: istat !< |
---|
| 171 | INTEGER :: m_my_cpl_rank !< |
---|
| 172 | INTEGER :: tag !< |
---|
[1764] | 173 | |
---|
[4649] | 174 | INTEGER, DIMENSION(pmc_max_models) :: activeparent !< I am active parent for this child ID |
---|
| 175 | INTEGER, DIMENSION(pmc_max_models+1) :: start_pe !< |
---|
[1762] | 176 | |
---|
[1900] | 177 | pmc_status = pmc_status_ok |
---|
| 178 | comm = -1 |
---|
| 179 | m_world_comm = MPI_COMM_WORLD |
---|
| 180 | m_my_cpl_id = -1 |
---|
[1933] | 181 | childcount = 0 |
---|
| 182 | activeparent = -1 |
---|
[1900] | 183 | start_pe(:) = 0 |
---|
| 184 | |
---|
| 185 | CALL MPI_COMM_RANK( MPI_COMM_WORLD, m_world_rank, istat ) |
---|
| 186 | CALL MPI_COMM_SIZE( MPI_COMM_WORLD, m_world_npes, istat ) |
---|
[1764] | 187 | ! |
---|
[2599] | 188 | !-- Only process 0 of root model reads |
---|
[1900] | 189 | IF ( m_world_rank == 0 ) THEN |
---|
[1762] | 190 | |
---|
[4649] | 191 | CALL read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 192 | anterpolation_buffer_width, anterpolation_starting_height, & |
---|
| 193 | pmc_status ) |
---|
[1762] | 194 | |
---|
[4649] | 195 | IF ( pmc_status /= pmc_no_namelist_found .AND. & |
---|
| 196 | pmc_status /= pmc_namelist_error ) & |
---|
[1900] | 197 | THEN |
---|
[1764] | 198 | ! |
---|
[2801] | 199 | !-- Calculate start PE of every model |
---|
[1900] | 200 | start_pe(1) = 0 |
---|
| 201 | DO i = 2, m_ncpl+1 |
---|
| 202 | start_pe(i) = start_pe(i-1) + m_couplers(i-1)%npe_total |
---|
| 203 | ENDDO |
---|
[1762] | 204 | |
---|
[1764] | 205 | ! |
---|
[4649] | 206 | !-- The sum of numbers of processes requested by all the domains must be equal to the total |
---|
| 207 | !-- number of processes of the run |
---|
[1900] | 208 | IF ( start_pe(m_ncpl+1) /= m_world_npes ) THEN |
---|
[4649] | 209 | WRITE( message_string, '(2A,I6,2A,I6,A)' ) & |
---|
| 210 | 'nesting-setup requires different number of ', & |
---|
| 211 | 'MPI procs (', start_pe(m_ncpl+1), ') than ', & |
---|
| 212 | 'provided (', m_world_npes,')' |
---|
[1900] | 213 | CALL message( 'pmc_init_model', 'PA0229', 3, 2, 0, 6, 0 ) |
---|
| 214 | ENDIF |
---|
[1762] | 215 | |
---|
[1900] | 216 | ENDIF |
---|
[1762] | 217 | |
---|
[1900] | 218 | ENDIF |
---|
[1764] | 219 | ! |
---|
[4649] | 220 | !-- Broadcast the read status. This synchronises all other processes with process 0 of the root |
---|
| 221 | !-- model. Without synchronisation, they would not behave in the correct way (e.g. they would not |
---|
| 222 | !-- return in case of a missing NAMELIST). |
---|
[1900] | 223 | CALL MPI_BCAST( pmc_status, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1762] | 224 | |
---|
[1900] | 225 | IF ( pmc_status == pmc_no_namelist_found ) THEN |
---|
[1764] | 226 | ! |
---|
[1900] | 227 | !-- Not a nested run; return the MPI_WORLD communicator |
---|
| 228 | comm = MPI_COMM_WORLD |
---|
| 229 | RETURN |
---|
[1762] | 230 | |
---|
[1900] | 231 | ELSEIF ( pmc_status == pmc_namelist_error ) THEN |
---|
[1764] | 232 | ! |
---|
[4649] | 233 | !-- Only the root model gives the error message. Others are aborted by the message-routine with |
---|
| 234 | !-- MPI_ABORT. Must be done this way since myid and comm2d have not yet been assigned at this |
---|
| 235 | !-- point. |
---|
[1900] | 236 | IF ( m_world_rank == 0 ) THEN |
---|
[2932] | 237 | message_string = 'errors in \$nesting_parameters' |
---|
[1900] | 238 | CALL message( 'pmc_init_model', 'PA0223', 3, 2, 0, 6, 0 ) |
---|
| 239 | ENDIF |
---|
[1762] | 240 | |
---|
[1900] | 241 | ENDIF |
---|
[1762] | 242 | |
---|
[2599] | 243 | CALL MPI_BCAST( m_ncpl, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
| 244 | CALL MPI_BCAST( start_pe, m_ncpl+1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1764] | 245 | ! |
---|
[1900] | 246 | !-- Broadcast coupling layout |
---|
| 247 | DO i = 1, m_ncpl |
---|
[4649] | 248 | CALL MPI_BCAST( m_couplers(i)%name, LEN( m_couplers(i)%name ), & |
---|
[1900] | 249 | MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
[4649] | 250 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, & |
---|
[1900] | 251 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 252 | CALL MPI_BCAST( m_couplers(i)%Parent_id, 1, MPI_INTEGER, 0, & |
---|
[1900] | 253 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 254 | CALL MPI_BCAST( m_couplers(i)%npe_total, 1, MPI_INTEGER, 0, & |
---|
[1900] | 255 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 256 | CALL MPI_BCAST( m_couplers(i)%lower_left_x, 1, MPI_REAL, 0, & |
---|
[1900] | 257 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 258 | CALL MPI_BCAST( m_couplers(i)%lower_left_y, 1, MPI_REAL, 0, & |
---|
[1900] | 259 | MPI_COMM_WORLD, istat ) |
---|
| 260 | ENDDO |
---|
[4649] | 261 | CALL MPI_BCAST( nesting_mode, LEN( nesting_mode ), MPI_CHARACTER, 0, MPI_COMM_WORLD, istat ) |
---|
| 262 | CALL MPI_BCAST( nesting_datatransfer_mode, LEN(nesting_datatransfer_mode), MPI_CHARACTER, 0, & |
---|
[1900] | 263 | MPI_COMM_WORLD, istat ) |
---|
[4649] | 264 | CALL MPI_BCAST( anterpolation_buffer_width, 1, MPI_INT, 0, MPI_COMM_WORLD, istat ) |
---|
[4771] | 265 | CALL MPI_BCAST( anterpolation_starting_height, 1, MPI_REAL, 0, MPI_COMM_WORLD, istat ) |
---|
[1764] | 266 | ! |
---|
[1900] | 267 | !-- Assign global MPI processes to individual models by setting the couple id |
---|
| 268 | DO i = 1, m_ncpl |
---|
[4649] | 269 | IF ( m_world_rank >= start_pe(i) .AND. m_world_rank < start_pe(i+1) ) THEN |
---|
[1900] | 270 | m_my_cpl_id = i |
---|
| 271 | EXIT |
---|
| 272 | ENDIF |
---|
| 273 | ENDDO |
---|
| 274 | m_my_cpl_rank = m_world_rank - start_pe(i) |
---|
[1764] | 275 | ! |
---|
[4649] | 276 | !-- MPI_COMM_WORLD is the communicator for ALL models (MPI-1 approach). The communictors for the |
---|
| 277 | !-- individual models as created by MPI_COMM_SPLIT. The color of the model is represented by the |
---|
| 278 | !-- coupler id |
---|
| 279 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, m_my_cpl_id, m_my_cpl_rank, comm, istat ) |
---|
[1764] | 280 | ! |
---|
[2599] | 281 | !-- Get size and rank of the model running on this process |
---|
[1900] | 282 | CALL MPI_COMM_RANK( comm, m_model_rank, istat ) |
---|
| 283 | CALL MPI_COMM_SIZE( comm, m_model_npes, istat ) |
---|
[1764] | 284 | ! |
---|
[2599] | 285 | !-- Broadcast (from process 0) the parent id and id of every model |
---|
[1900] | 286 | DO i = 1, m_ncpl |
---|
[4649] | 287 | CALL MPI_BCAST( m_couplers(i)%parent_id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
| 288 | CALL MPI_BCAST( m_couplers(i)%id, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, istat ) |
---|
[1900] | 289 | ENDDO |
---|
[1764] | 290 | ! |
---|
[1900] | 291 | !-- Save the current model communicator for pmc internal use |
---|
| 292 | m_model_comm = comm |
---|
[1762] | 293 | |
---|
[1764] | 294 | ! |
---|
[2599] | 295 | !-- Create intercommunicator between the parent and children. |
---|
[4649] | 296 | !-- MPI_INTERCOMM_CREATE creates an intercommunicator between 2 groups of different colors. The |
---|
| 297 | !-- grouping was done above with MPI_COMM_SPLIT. A duplicate of MPI_COMM_WORLD is created and used |
---|
| 298 | !-- as peer communicator (peer_comm) for MPI_INTERCOMM_CREATE. |
---|
| 299 | CALL MPI_COMM_DUP( MPI_COMM_WORLD, peer_comm, ierr ) |
---|
[1900] | 300 | DO i = 2, m_ncpl |
---|
| 301 | IF ( m_couplers(i)%parent_id == m_my_cpl_id ) THEN |
---|
[1764] | 302 | ! |
---|
[4649] | 303 | !-- Identify all children models of the current model and create inter-communicators to |
---|
| 304 | !-- connect between the current model and its children models. |
---|
[1900] | 305 | tag = 500 + i |
---|
[4649] | 306 | CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm, start_pe(i), tag, m_to_child_comm(i), & |
---|
| 307 | istat ) |
---|
[1933] | 308 | childcount = childcount + 1 |
---|
| 309 | activeparent(i) = 1 |
---|
[1900] | 310 | ELSEIF ( i == m_my_cpl_id) THEN |
---|
[1764] | 311 | ! |
---|
[4649] | 312 | !-- Create an inter-communicator to connect between the current model and its parent model. |
---|
[1900] | 313 | tag = 500 + i |
---|
[4649] | 314 | CALL MPI_INTERCOMM_CREATE( comm, 0, peer_comm, start_pe(m_couplers(i)%parent_id), tag, & |
---|
| 315 | m_to_parent_comm, istat ) |
---|
[1900] | 316 | ENDIF |
---|
| 317 | ENDDO |
---|
[1764] | 318 | ! |
---|
[4649] | 319 | !-- If I am a parent, count the number of children I have. Although this loop is symmetric on all |
---|
| 320 | !-- processes, the "activeparent" flag is true (==1) on the respective individual process only. |
---|
[1933] | 321 | ALLOCATE( pmc_parent_for_child(childcount+1) ) |
---|
[1762] | 322 | |
---|
[1933] | 323 | childcount = 0 |
---|
[1900] | 324 | DO i = 2, m_ncpl |
---|
[1933] | 325 | IF ( activeparent(i) == 1 ) THEN |
---|
| 326 | childcount = childcount + 1 |
---|
| 327 | pmc_parent_for_child(childcount) = i |
---|
[1900] | 328 | ENDIF |
---|
| 329 | ENDDO |
---|
[1764] | 330 | ! |
---|
[1933] | 331 | !-- Get the size of the parent model |
---|
[1900] | 332 | IF ( m_my_cpl_id > 1 ) THEN |
---|
[4649] | 333 | CALL MPI_COMM_REMOTE_SIZE( m_to_parent_comm, m_parent_remote_size, istat ) |
---|
[1900] | 334 | ELSE |
---|
[1764] | 335 | ! |
---|
[1933] | 336 | !-- The root model does not have a parent |
---|
| 337 | m_parent_remote_size = -1 |
---|
[1900] | 338 | ENDIF |
---|
[1764] | 339 | ! |
---|
[4649] | 340 | !-- Set myid to non-zero value except for the root domain. This is a setting for the message routine |
---|
| 341 | !-- which is called at the end of pmci_init. That routine outputs messages for myid = 0, only. |
---|
| 342 | !-- However, myid has not been assigened so far, so that all processes of the root model would |
---|
| 343 | !-- output a message. To avoid this, set myid to some other value except for process 0 of the root |
---|
| 344 | !-- domain. |
---|
[1900] | 345 | IF ( m_world_rank /= 0 ) myid = 1 |
---|
[1762] | 346 | |
---|
[1900] | 347 | END SUBROUTINE PMC_init_model |
---|
[1762] | 348 | |
---|
| 349 | |
---|
[4649] | 350 | !--------------------------------------------------------------------------------------------------! |
---|
| 351 | ! Description: |
---|
| 352 | ! ------------ |
---|
| 353 | !> @Todo: Missing subroutine description. |
---|
| 354 | !--------------------------------------------------------------------------------------------------! |
---|
| 355 | SUBROUTINE pmc_get_model_info( comm_world_nesting, cpl_id, cpl_name, cpl_parent_id, lower_left_x, & |
---|
| 356 | lower_left_y, ncpl, npe_total, request_for_cpl_id ) |
---|
[1764] | 357 | ! |
---|
[1791] | 358 | !-- Provide module private variables of the pmc for PALM |
---|
[1762] | 359 | |
---|
[1900] | 360 | USE kinds |
---|
[1762] | 361 | |
---|
[1900] | 362 | IMPLICIT NONE |
---|
[1762] | 363 | |
---|
[1933] | 364 | CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: cpl_name !< |
---|
[1762] | 365 | |
---|
[1933] | 366 | INTEGER, INTENT(IN), OPTIONAL :: request_for_cpl_id !< |
---|
[1762] | 367 | |
---|
[1900] | 368 | INTEGER, INTENT(OUT), OPTIONAL :: comm_world_nesting !< |
---|
| 369 | INTEGER, INTENT(OUT), OPTIONAL :: cpl_id !< |
---|
| 370 | INTEGER, INTENT(OUT), OPTIONAL :: cpl_parent_id !< |
---|
| 371 | INTEGER, INTENT(OUT), OPTIONAL :: ncpl !< |
---|
| 372 | INTEGER, INTENT(OUT), OPTIONAL :: npe_total !< |
---|
[1762] | 373 | |
---|
[2599] | 374 | INTEGER :: requested_cpl_id !< |
---|
[1764] | 375 | |
---|
[2599] | 376 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_x !< |
---|
| 377 | REAL(wp), INTENT(OUT), OPTIONAL :: lower_left_y !< |
---|
[1764] | 378 | |
---|
[1791] | 379 | ! |
---|
[1900] | 380 | !-- Set the requested coupler id |
---|
| 381 | IF ( PRESENT( request_for_cpl_id ) ) THEN |
---|
| 382 | requested_cpl_id = request_for_cpl_id |
---|
[1791] | 383 | ! |
---|
[1900] | 384 | !-- Check for allowed range of values |
---|
| 385 | IF ( requested_cpl_id < 1 .OR. requested_cpl_id > m_ncpl ) RETURN |
---|
| 386 | ELSE |
---|
| 387 | requested_cpl_id = m_my_cpl_id |
---|
| 388 | ENDIF |
---|
[1791] | 389 | ! |
---|
[1900] | 390 | !-- Return the requested information |
---|
| 391 | IF ( PRESENT( comm_world_nesting ) ) THEN |
---|
| 392 | comm_world_nesting = m_world_comm |
---|
| 393 | ENDIF |
---|
| 394 | IF ( PRESENT( cpl_id ) ) THEN |
---|
| 395 | cpl_id = requested_cpl_id |
---|
| 396 | ENDIF |
---|
| 397 | IF ( PRESENT( cpl_parent_id ) ) THEN |
---|
| 398 | cpl_parent_id = m_couplers(requested_cpl_id)%parent_id |
---|
| 399 | ENDIF |
---|
| 400 | IF ( PRESENT( cpl_name ) ) THEN |
---|
| 401 | cpl_name = m_couplers(requested_cpl_id)%name |
---|
| 402 | ENDIF |
---|
| 403 | IF ( PRESENT( ncpl ) ) THEN |
---|
| 404 | ncpl = m_ncpl |
---|
| 405 | ENDIF |
---|
| 406 | IF ( PRESENT( npe_total ) ) THEN |
---|
| 407 | npe_total = m_couplers(requested_cpl_id)%npe_total |
---|
| 408 | ENDIF |
---|
| 409 | IF ( PRESENT( lower_left_x ) ) THEN |
---|
| 410 | lower_left_x = m_couplers(requested_cpl_id)%lower_left_x |
---|
| 411 | ENDIF |
---|
| 412 | IF ( PRESENT( lower_left_y ) ) THEN |
---|
| 413 | lower_left_y = m_couplers(requested_cpl_id)%lower_left_y |
---|
| 414 | ENDIF |
---|
[1791] | 415 | |
---|
[1900] | 416 | END SUBROUTINE pmc_get_model_info |
---|
[1791] | 417 | |
---|
| 418 | |
---|
| 419 | |
---|
[1900] | 420 | LOGICAL function pmc_is_rootmodel( ) |
---|
[1764] | 421 | |
---|
[1900] | 422 | IMPLICIT NONE |
---|
[1764] | 423 | |
---|
[1900] | 424 | pmc_is_rootmodel = ( m_my_cpl_id == 1 ) |
---|
[1764] | 425 | |
---|
[1900] | 426 | END FUNCTION pmc_is_rootmodel |
---|
[1764] | 427 | |
---|
| 428 | |
---|
| 429 | |
---|
[4649] | 430 | !--------------------------------------------------------------------------------------------------! |
---|
| 431 | ! Description: |
---|
| 432 | ! ------------ |
---|
| 433 | !> @Todo: Missing subroutine description. |
---|
| 434 | !--------------------------------------------------------------------------------------------------! |
---|
| 435 | SUBROUTINE read_coupling_layout( nesting_datatransfer_mode, nesting_mode, & |
---|
[4771] | 436 | anterpolation_buffer_width, anterpolation_starting_height, & |
---|
| 437 | pmc_status ) |
---|
[1762] | 438 | |
---|
[1764] | 439 | IMPLICIT NONE |
---|
[1762] | 440 | |
---|
[4649] | 441 | CHARACTER(LEN=7), INTENT(INOUT) :: nesting_datatransfer_mode !< |
---|
| 442 | CHARACTER(LEN=8), INTENT(INOUT) :: nesting_mode !< |
---|
[1764] | 443 | |
---|
[4649] | 444 | INTEGER, INTENT(INOUT) :: anterpolation_buffer_width !< Boundary buffer width for anterpolation |
---|
| 445 | INTEGER(iwp), INTENT(INOUT) :: pmc_status !< |
---|
[1764] | 446 | |
---|
[4771] | 447 | REAL(wp), INTENT(INOUT) :: anterpolation_starting_height !< steering parameter for canopy restricted anterpolation |
---|
| 448 | |
---|
[4649] | 449 | INTEGER(iwp) :: bad_llcorner !< |
---|
| 450 | INTEGER(iwp) :: i !< |
---|
[4843] | 451 | INTEGER(iwp) :: io_status !< |
---|
[4649] | 452 | |
---|
[4843] | 453 | LOGICAL :: switch_off_module = .FALSE. !< local namelist parameter to switch off the module |
---|
| 454 | !< although the respective module namelist appears in |
---|
| 455 | !< the namelist file |
---|
| 456 | |
---|
[4649] | 457 | TYPE(pmc_layout), DIMENSION(pmc_max_models) :: domain_layouts !< |
---|
| 458 | |
---|
[4843] | 459 | NAMELIST /nesting_parameters/ anterpolation_buffer_width, & |
---|
| 460 | anterpolation_starting_height, & |
---|
| 461 | domain_layouts, & |
---|
[4649] | 462 | nesting_datatransfer_mode, & |
---|
| 463 | nesting_mode, & |
---|
[4843] | 464 | switch_off_module |
---|
[4649] | 465 | |
---|
[4843] | 466 | |
---|
[1764] | 467 | ! |
---|
| 468 | !-- Initialize some coupling variables |
---|
[1900] | 469 | domain_layouts(1:pmc_max_models)%id = -1 |
---|
[1791] | 470 | m_ncpl = 0 |
---|
[1762] | 471 | |
---|
[4843] | 472 | pmc_status = pmc_no_namelist_found |
---|
[1764] | 473 | ! |
---|
| 474 | !-- Open the NAMELIST-file and read the nesting layout |
---|
| 475 | CALL check_open( 11 ) |
---|
[4843] | 476 | READ ( 11, nesting_parameters, IOSTAT = io_status ) |
---|
[2279] | 477 | ! |
---|
[4649] | 478 | !-- Set filepointer to the beginning of the file. Otherwise process 0 will later be unable to read |
---|
| 479 | !-- the inipar-NAMELIST |
---|
[2279] | 480 | REWIND ( 11 ) |
---|
[1764] | 481 | |
---|
[4843] | 482 | IF ( io_status == 0 ) THEN |
---|
[1764] | 483 | ! |
---|
[4843] | 484 | !-- nesting_parameters namelist was found and read correctly. Enable the nesting by setting |
---|
| 485 | !-- the palm model coupler status respectively. |
---|
| 486 | IF ( .NOT. switch_off_module ) THEN |
---|
| 487 | pmc_status = pmc_status_ok |
---|
| 488 | ELSE |
---|
| 489 | RETURN |
---|
| 490 | ENDIF |
---|
| 491 | ELSEIF ( io_status < 0 ) THEN |
---|
| 492 | ! |
---|
[2932] | 493 | !-- No nesting_parameters-NAMELIST found |
---|
[1762] | 494 | RETURN |
---|
[4843] | 495 | ELSEIF ( io_status > 0 ) THEN |
---|
[1764] | 496 | ! |
---|
[2932] | 497 | !-- Errors in reading nesting_parameters-NAMELIST |
---|
[1764] | 498 | pmc_status = pmc_namelist_error |
---|
| 499 | RETURN |
---|
| 500 | ENDIF |
---|
[4843] | 501 | |
---|
[1764] | 502 | ! |
---|
| 503 | !-- Output location message |
---|
[3885] | 504 | CALL location_message( 'initialize communicators for nesting', 'start' ) |
---|
[1764] | 505 | ! |
---|
[2599] | 506 | !-- Assign the layout to the corresponding internally used variable m_couplers |
---|
[1764] | 507 | m_couplers = domain_layouts |
---|
| 508 | ! |
---|
[2932] | 509 | !-- Get the number of nested models given in the nesting_parameters-NAMELIST |
---|
[1900] | 510 | DO i = 1, pmc_max_models |
---|
[1764] | 511 | ! |
---|
[1791] | 512 | !-- When id=-1 is found for the first time, the list of domains is finished |
---|
[2599] | 513 | IF ( m_couplers(i)%id == -1 .OR. i == pmc_max_models ) THEN |
---|
[1791] | 514 | IF ( m_couplers(i)%id == -1 ) THEN |
---|
| 515 | m_ncpl = i - 1 |
---|
| 516 | EXIT |
---|
| 517 | ELSE |
---|
[1900] | 518 | m_ncpl = pmc_max_models |
---|
[1791] | 519 | ENDIF |
---|
[1764] | 520 | ENDIF |
---|
| 521 | ENDDO |
---|
[1933] | 522 | ! |
---|
[4649] | 523 | !-- Make sure that all domains have equal lower left corner in case of vertical nesting |
---|
[1933] | 524 | IF ( nesting_mode == 'vertical' ) THEN |
---|
| 525 | bad_llcorner = 0 |
---|
| 526 | DO i = 1, m_ncpl |
---|
[4649] | 527 | IF ( domain_layouts(i)%lower_left_x /= 0.0_wp .OR. & |
---|
[1933] | 528 | domain_layouts(i)%lower_left_y /= 0.0_wp ) THEN |
---|
| 529 | bad_llcorner = bad_llcorner + 1 |
---|
| 530 | domain_layouts(i)%lower_left_x = 0.0_wp |
---|
| 531 | domain_layouts(i)%lower_left_y = 0.0_wp |
---|
| 532 | ENDIF |
---|
| 533 | ENDDO |
---|
| 534 | IF ( bad_llcorner /= 0) THEN |
---|
[4649] | 535 | WRITE( message_string, *) 'at least one dimension of lower ', & |
---|
| 536 | 'left corner of one domain is not 0. ', & |
---|
| 537 | 'All lower left corners were set to (0, 0)' |
---|
[1933] | 538 | CALL message( 'read_coupling_layout', 'PA0427', 0, 0, 0, 6, 0 ) |
---|
| 539 | ENDIF |
---|
| 540 | ENDIF |
---|
| 541 | |
---|
[3885] | 542 | CALL location_message( 'initialize communicators for nesting', 'finished' ) |
---|
| 543 | |
---|
[1764] | 544 | END SUBROUTINE read_coupling_layout |
---|
| 545 | |
---|
| 546 | #endif |
---|
| 547 | END MODULE pmc_handle_communicator |
---|