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