source: palm/trunk/SOURCE/init_pegrid.f90 @ 3241

Last change on this file since 3241 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

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