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

Last change on this file since 755 was 755, checked in by witha, 13 years ago

adapted for lcflow (ForWind? cluster in Oldenburg)

  • Property svn:keywords set to Id
File size: 40.7 KB
Line 
1 SUBROUTINE init_pegrid
2
3!------------------------------------------------------------------------------!
4! Current revisions:
5! -----------------
6!
7! 2d-decomposition is default for lcflow (ForWind cluster in Oldenburg)
8!
9! ATTENTION: nnz_x undefined problem still has to be solved!!!!!!!!
10! TEST OUTPUT (TO BE REMOVED) logging mpi2 ierr values
11!
12! Former revisions:
13! -----------------
14! $Id: init_pegrid.f90 755 2011-08-29 09:55:16Z witha $
15!
16! 722 2011-04-11 06:21:09Z raasch
17! Bugfix: bc_lr/ns_cyc/dirrad/raddir replaced by bc_lr/ns, because variables
18!         are not yet set here; grid_level set to 0
19!
20! 709 2011-03-30 09:31:40Z raasch
21! formatting adjustments
22!
23! 707 2011-03-29 11:39:40Z raasch
24! bc_lr/ns replaced by bc_lr/ns_cyc/dirrad/raddir
25!
26! 667 2010-12-23 12:06:00Z suehring/gryschka
27! Moved determination of target_id's from init_coupling
28! Determination of parameters needed for coupling (coupling_topology, ngp_a,
29! ngp_o) with different grid/processor-topology in ocean and atmosphere
30! Adaption of ngp_xy, ngp_y to a dynamic number of ghost points.
31! The maximum_grid_level changed from 1 to 0. 0 is the normal grid, 1 to
32! maximum_grid_level the grids for multigrid, in which 0 and 1 are normal grids.
33! This distinction is due to reasons of data exchange and performance for the
34! normal grid and grids in poismg.
35! The definition of MPI-Vectors adapted to a dynamic numer of ghost points.
36! New MPI-Vectors for data exchange between left and right boundaries added.
37! This is due to reasons of performance (10% faster).
38!
39! 646 2010-12-15 13:03:52Z raasch
40! lctit is now using a 2d decomposition by default
41!
42! 622 2010-12-10 08:08:13Z raasch
43! optional barriers included in order to speed up collective operations
44!
45! 438 2010-02-01 04:32:43Z raasch
46! 2d-decomposition is default for Cray-XT machines
47!
48! 274 2009-03-26 15:11:21Z heinze
49! Output of messages replaced by message handling routine.
50!
51! 206 2008-10-13 14:59:11Z raasch
52! Implementation of a MPI-1 coupling: added __parallel within the __mpi2 part
53! 2d-decomposition is default on SGI-ICE systems
54!
55! 197 2008-09-16 15:29:03Z raasch
56! multigrid levels are limited by subdomains if mg_switch_to_pe0_level = -1,
57! nz is used instead nnz for calculating mg-levels
58! Collect on PE0 horizontal index bounds from all other PEs,
59! broadcast the id of the inflow PE (using the respective communicator)
60!
61! 114 2007-10-10 00:03:15Z raasch
62! Allocation of wall flag arrays for multigrid solver
63!
64! 108 2007-08-24 15:10:38Z letzel
65! Intercommunicator (comm_inter) and derived data type (type_xy) for
66! coupled model runs created, assign coupling_mode_remote,
67! indices nxlu and nysv are calculated (needed for non-cyclic boundary
68! conditions)
69!
70! 82 2007-04-16 15:40:52Z raasch
71! Cpp-directive lcmuk changed to intel_openmp_bug, setting of host on lcmuk by
72! cpp-directive removed
73!
74! 75 2007-03-22 09:54:05Z raasch
75! uxrp, vynp eliminated,
76! dirichlet/neumann changed to dirichlet/radiation, etc.,
77! poisfft_init is only called if fft-solver is switched on
78!
79! RCS Log replace by Id keyword, revision history cleaned up
80!
81! Revision 1.28  2006/04/26 13:23:32  raasch
82! lcmuk does not understand the !$ comment so a cpp-directive is required
83!
84! Revision 1.1  1997/07/24 11:15:09  raasch
85! Initial revision
86!
87!
88! Description:
89! ------------
90! Determination of the virtual processor topology (if not prescribed by the
91! user)and computation of the grid point number and array bounds of the local
92! domains.
93!------------------------------------------------------------------------------!
94
95    USE control_parameters
96    USE fft_xy
97    USE grid_variables
98    USE indices
99    USE pegrid
100    USE poisfft_mod
101    USE poisfft_hybrid_mod
102    USE statistics
103    USE transpose_indices
104
105
106
107    IMPLICIT NONE
108
109    INTEGER ::  gathered_size, i, id_inflow_l, id_recycling_l, ind(5), j, k, &
110                maximum_grid_level_l, mg_switch_to_pe0_level_l, mg_levels_x, &
111                mg_levels_y, mg_levels_z, nnx_y, nnx_z, nny_x, nny_z, nnz_x, &
112                nnz_y, numproc_sqr, nx_total, nxl_l, nxr_l, nyn_l, nys_l,    &
113                nzb_l, nzt_l, omp_get_num_threads, subdomain_size
114
115    INTEGER, DIMENSION(:), ALLOCATABLE ::  ind_all, nxlf, nxrf, nynf, nysf
116
117    INTEGER, DIMENSION(2) :: pdims_remote
118
119    LOGICAL ::  found
120
121!
122!-- Get the number of OpenMP threads
123    !$OMP PARALLEL
124#if defined( __intel_openmp_bug )
125    threads_per_task = omp_get_num_threads()
126#else
127!$  threads_per_task = omp_get_num_threads()
128#endif
129    !$OMP END PARALLEL
130
131
132#if defined( __parallel )
133
134!
135!-- Determine the processor topology or check it, if prescribed by the user
136    IF ( npex == -1  .AND.  npey == -1 )  THEN
137
138!
139!--    Automatic determination of the topology
140!--    The default on SMP- and cluster-hosts is a 1d-decomposition along x
141       IF ( host(1:3) == 'ibm'  .OR.  host(1:3) == 'nec'      .OR. &
142            ( host(1:2) == 'lc'  .AND.  host(3:5) /= 'sgi'  .AND.  &
143              host(3:4) /= 'xt'  .AND.  host(3:5) /= 'tit'  .AND.  &
144              host(3:6) /= 'flow' )  .OR.  host(1:3) == 'dec' )  THEN
145
146          pdims(1) = numprocs
147          pdims(2) = 1
148
149       ELSE
150
151          numproc_sqr = SQRT( REAL( numprocs ) )
152          pdims(1)    = MAX( numproc_sqr , 1 )
153          DO  WHILE ( MOD( numprocs , pdims(1) ) /= 0 )
154             pdims(1) = pdims(1) - 1
155          ENDDO
156          pdims(2) = numprocs / pdims(1)
157
158       ENDIF
159
160    ELSEIF ( npex /= -1  .AND.  npey /= -1 )  THEN
161
162!
163!--    Prescribed by user. Number of processors on the prescribed topology
164!--    must be equal to the number of PEs available to the job
165       IF ( ( npex * npey ) /= numprocs )  THEN
166          WRITE( message_string, * ) 'number of PEs of the prescribed ',      & 
167                 'topology (', npex*npey,') does not match & the number of ', & 
168                 'PEs available to the job (', numprocs, ')'
169          CALL message( 'init_pegrid', 'PA0221', 1, 2, 0, 6, 0 )
170       ENDIF
171       pdims(1) = npex
172       pdims(2) = npey
173
174    ELSE
175!
176!--    If the processor topology is prescribed by the user, the number of
177!--    PEs must be given in both directions
178       message_string = 'if the processor topology is prescribed by the, ' //  &
179                   ' user& both values of "npex" and "npey" must be given ' // &
180                   'in the &NAMELIST-parameter file'
181       CALL message( 'init_pegrid', 'PA0222', 1, 2, 0, 6, 0 )
182
183    ENDIF
184
185!
186!-- The hybrid solver can only be used in case of a 1d-decomposition along x
187    IF ( pdims(2) /= 1  .AND.  psolver == 'poisfft_hybrid' )  THEN
188       message_string = 'psolver = "poisfft_hybrid" can only be' // &
189                        '& used in case of a 1d-decomposition along x'
190       CALL message( 'init_pegrid', 'PA0223', 1, 2, 0, 6, 0 )
191    ENDIF
192
193!
194!-- For communication speedup, set barriers in front of collective
195!-- communications by default on SGI-type systems
196    IF ( host(3:5) == 'sgi' )  collective_wait = .TRUE.
197
198!
199!-- If necessary, set horizontal boundary conditions to non-cyclic
200    IF ( bc_lr /= 'cyclic' )  cyclic(1) = .FALSE.
201    IF ( bc_ns /= 'cyclic' )  cyclic(2) = .FALSE.
202
203!
204!-- Create the virtual processor grid
205    CALL MPI_CART_CREATE( comm_palm, ndim, pdims, cyclic, reorder, &
206                          comm2d, ierr )
207    CALL MPI_COMM_RANK( comm2d, myid, ierr )
208    WRITE (myid_char,'(''_'',I4.4)')  myid
209
210    CALL MPI_CART_COORDS( comm2d, myid, ndim, pcoord, ierr )
211    CALL MPI_CART_SHIFT( comm2d, 0, 1, pleft, pright, ierr )
212    CALL MPI_CART_SHIFT( comm2d, 1, 1, psouth, pnorth, ierr )
213
214!
215!-- Determine sub-topologies for transpositions
216!-- Transposition from z to x:
217    remain_dims(1) = .TRUE.
218    remain_dims(2) = .FALSE.
219    CALL MPI_CART_SUB( comm2d, remain_dims, comm1dx, ierr )
220    CALL MPI_COMM_RANK( comm1dx, myidx, ierr )
221!
222!-- Transposition from x to y
223    remain_dims(1) = .FALSE.
224    remain_dims(2) = .TRUE.
225    CALL MPI_CART_SUB( comm2d, remain_dims, comm1dy, ierr )
226    CALL MPI_COMM_RANK( comm1dy, myidy, ierr )
227
228
229!
230!-- Find a grid (used for array d) which will match the transposition demands
231    IF ( grid_matching == 'strict' )  THEN
232
233       nxa = nx;  nya = ny;  nza = nz
234
235    ELSE
236
237       found = .FALSE.
238   xn: DO  nxa = nx, 2*nx
239!
240!--       Meet conditions for nx
241          IF ( MOD( nxa+1, pdims(1) ) /= 0 .OR. &
242               MOD( nxa+1, pdims(2) ) /= 0 )  CYCLE xn
243
244      yn: DO  nya = ny, 2*ny
245!
246!--          Meet conditions for ny
247             IF ( MOD( nya+1, pdims(2) ) /= 0 .OR. &
248                  MOD( nya+1, pdims(1) ) /= 0 )  CYCLE yn
249
250
251         zn: DO  nza = nz, 2*nz
252!
253!--             Meet conditions for nz
254                IF ( ( MOD( nza, pdims(1) ) /= 0  .AND.  pdims(1) /= 1  .AND. &
255                       pdims(2) /= 1 )  .OR.                                  &
256                     ( MOD( nza, pdims(2) ) /= 0  .AND.  dt_dosp /= 9999999.9 &
257                     ) )  THEN
258                   CYCLE zn
259                ELSE
260                   found = .TRUE.
261                   EXIT xn
262                ENDIF
263
264             ENDDO zn
265
266          ENDDO yn
267
268       ENDDO xn
269
270       IF ( .NOT. found )  THEN
271          message_string = 'no matching grid for transpositions found'
272          CALL message( 'init_pegrid', 'PA0224', 1, 2, 0, 6, 0 )
273       ENDIF
274
275    ENDIF
276
277!
278!-- Calculate array bounds in x-direction for every PE.
279!-- The last PE along x may get less grid points than the others
280    ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1), &
281              nysf(0:pdims(2)-1), nnx_pe(0:pdims(1)-1), nny_pe(0:pdims(2)-1) )
282
283    IF ( MOD( nxa+1 , pdims(1) ) /= 0 )  THEN
284       WRITE( message_string, * ) 'x-direction: gridpoint number (',nx+1,') ',&
285                               'is not an& integral divisor of the number ',  &
286                               'processors (', pdims(1),')'
287       CALL message( 'init_pegrid', 'PA0225', 1, 2, 0, 6, 0 )
288    ELSE
289       nnx  = ( nxa + 1 ) / pdims(1)
290       IF ( nnx*pdims(1) - ( nx + 1) > nnx )  THEN
291          WRITE( message_string, * ) 'x-direction: nx does not match the',    & 
292                       'requirements given by the number of PEs &used',       &
293                       '& please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
294                                   - ( nx + 1 ) ) ), ' instead of nx =', nx
295          CALL message( 'init_pegrid', 'PA0226', 1, 2, 0, 6, 0 )
296       ENDIF
297    ENDIF   
298
299!
300!-- Left and right array bounds, number of gridpoints
301    DO  i = 0, pdims(1)-1
302       nxlf(i)   = i * nnx
303       nxrf(i)   = ( i + 1 ) * nnx - 1
304       nnx_pe(i) = MIN( nx, nxrf(i) ) - nxlf(i) + 1
305    ENDDO
306
307!
308!-- Calculate array bounds in y-direction for every PE.
309    IF ( MOD( nya+1 , pdims(2) ) /= 0 )  THEN
310       WRITE( message_string, * ) 'y-direction: gridpoint number (',ny+1,') ', &
311                           'is not an& integral divisor of the number of',     &
312                           'processors (', pdims(2),')'
313       CALL message( 'init_pegrid', 'PA0227', 1, 2, 0, 6, 0 )
314    ELSE
315       nny  = ( nya + 1 ) / pdims(2)
316       IF ( nny*pdims(2) - ( ny + 1) > nny )  THEN
317          WRITE( message_string, * ) 'y-direction: ny does not match the',    &
318                       'requirements given by the number of PEs &used ',      &
319                       '& please use ny = ', ny - ( pdims(2) - ( nnx*pdims(2) &
320                                     - ( ny + 1 ) ) ), ' instead of ny =', ny
321          CALL message( 'init_pegrid', 'PA0228', 1, 2, 0, 6, 0 )
322       ENDIF
323    ENDIF   
324
325!
326!-- South and north array bounds
327    DO  j = 0, pdims(2)-1
328       nysf(j)   = j * nny
329       nynf(j)   = ( j + 1 ) * nny - 1
330       nny_pe(j) = MIN( ny, nynf(j) ) - nysf(j) + 1
331    ENDDO
332
333!
334!-- Local array bounds of the respective PEs
335    nxl  = nxlf(pcoord(1))
336    nxra = nxrf(pcoord(1))
337    nxr  = MIN( nx, nxra )
338    nys  = nysf(pcoord(2))
339    nyna = nynf(pcoord(2))
340    nyn  = MIN( ny, nyna )
341    nzb  = 0
342    nzta = nza
343    nzt  = MIN( nz, nzta )
344    nnz  = nza
345
346!
347!-- Set switches to define if the PE is situated at the border of the virtual
348!-- processor grid
349    IF ( nxl == 0 )   left_border_pe  = .TRUE.
350    IF ( nxr == nx )  right_border_pe = .TRUE.
351    IF ( nys == 0 )   south_border_pe = .TRUE.
352    IF ( nyn == ny )  north_border_pe = .TRUE.
353
354!
355!-- Calculate array bounds and gridpoint numbers for the transposed arrays
356!-- (needed in the pressure solver)
357!-- For the transposed arrays, cyclic boundaries as well as top and bottom
358!-- boundaries are omitted, because they are obstructive to the transposition
359
360!
361!-- 1. transposition  z --> x
362!-- This transposition is not neccessary in case of a 1d-decomposition along x,
363!-- except that the uptream-spline method is switched on
364    IF ( pdims(2) /= 1  .OR.  momentum_advec == 'ups-scheme'  .OR. &
365         scalar_advec == 'ups-scheme' )  THEN
366
367       IF ( pdims(2) == 1  .AND. ( momentum_advec == 'ups-scheme'  .OR. &
368            scalar_advec == 'ups-scheme' ) )  THEN
369          message_string = '1d-decomposition along x ' // &
370                           'chosen but nz restrictions may occur' // &
371                           '& since ups-scheme is activated'
372          CALL message( 'init_pegrid', 'PA0229', 0, 1, 0, 6, 0 )
373       ENDIF
374       nys_x  = nys
375       nyn_xa = nyna
376       nyn_x  = nyn
377       nny_x  = nny
378       IF ( MOD( nza , pdims(1) ) /= 0 )  THEN
379          WRITE( message_string, * ) 'transposition z --> x:',                &
380                       '&nz=',nz,' is not an integral divisior of pdims(1)=', &
381                                                                   pdims(1)
382          CALL message( 'init_pegrid', 'PA0230', 1, 2, 0, 6, 0 )
383       ENDIF
384       nnz_x  = nza / pdims(1)
385       nzb_x  = 1 + myidx * nnz_x
386       nzt_xa = ( myidx + 1 ) * nnz_x
387       nzt_x  = MIN( nzt, nzt_xa )
388
389       sendrecvcount_zx = nnx * nny * nnz_x
390
391    ELSE
392!
393!---   Setting of dummy values because otherwise variables are undefined in
394!---   the next step  x --> y
395!---   WARNING: This case has still to be clarified!!!!!!!!!!!!
396       nnz_x  = 1
397       nzb_x  = 1
398       nzt_xa = 1
399       nzt_x  = 1
400       nny_x  = nny
401
402    ENDIF
403
404!
405!-- 2. transposition  x --> y
406    nnz_y  = nnz_x
407    nzb_y  = nzb_x
408    nzt_ya = nzt_xa
409    nzt_y  = nzt_x
410    IF ( MOD( nxa+1 , pdims(2) ) /= 0 )  THEN
411       WRITE( message_string, * ) 'transposition x --> y:',                &
412                         '&nx+1=',nx+1,' is not an integral divisor of ',&
413                         'pdims(2)=',pdims(2)
414       CALL message( 'init_pegrid', 'PA0231', 1, 2, 0, 6, 0 )
415    ENDIF
416    nnx_y = (nxa+1) / pdims(2)
417    nxl_y = myidy * nnx_y
418    nxr_ya = ( myidy + 1 ) * nnx_y - 1
419    nxr_y  = MIN( nx, nxr_ya )
420
421    sendrecvcount_xy = nnx_y * nny_x * nnz_y
422
423!
424!-- 3. transposition  y --> z  (ELSE:  x --> y  in case of 1D-decomposition
425!-- along x)
426    IF ( pdims(2) /= 1  .OR.  momentum_advec == 'ups-scheme'  .OR. &
427         scalar_advec == 'ups-scheme' )  THEN
428!
429!--    y --> z
430!--    This transposition is not neccessary in case of a 1d-decomposition
431!--    along x, except that the uptream-spline method is switched on
432       nnx_z  = nnx_y
433       nxl_z  = nxl_y
434       nxr_za = nxr_ya
435       nxr_z  = nxr_y
436       IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
437          WRITE( message_string, * ) 'transposition y --> z:',            &
438                            '& ny+1=',ny+1,' is not an integral divisor of ',&
439                            'pdims(1)=',pdims(1)
440          CALL message( 'init_pegrid', 'PA0232', 1, 2, 0, 6, 0 )
441       ENDIF
442       nny_z  = (nya+1) / pdims(1)
443       nys_z  = myidx * nny_z
444       nyn_za = ( myidx + 1 ) * nny_z - 1
445       nyn_z  = MIN( ny, nyn_za )
446
447       sendrecvcount_yz = nnx_y * nny_z * nnz_y
448
449    ELSE
450!
451!--    x --> y. This condition must be fulfilled for a 1D-decomposition along x
452       IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
453          WRITE( message_string, * ) 'transposition x --> y:',               &
454                            '& ny+1=',ny+1,' is not an integral divisor of ',&
455                            'pdims(1)=',pdims(1)
456          CALL message( 'init_pegrid', 'PA0233', 1, 2, 0, 6, 0 )
457       ENDIF
458
459    ENDIF
460
461!
462!-- Indices for direct transpositions z --> y (used for calculating spectra)
463    IF ( dt_dosp /= 9999999.9 )  THEN
464       IF ( MOD( nza, pdims(2) ) /= 0 )  THEN
465          WRITE( message_string, * ) 'direct transposition z --> y (needed ', &
466                    'for spectra):& nz=',nz,' is not an integral divisor of ',&
467                    'pdims(2)=',pdims(2)
468          CALL message( 'init_pegrid', 'PA0234', 1, 2, 0, 6, 0 )
469       ELSE
470          nxl_yd  = nxl
471          nxr_yda = nxra
472          nxr_yd  = nxr
473          nzb_yd  = 1 + myidy * ( nza / pdims(2) )
474          nzt_yda = ( myidy + 1 ) * ( nza / pdims(2) )
475          nzt_yd  = MIN( nzt, nzt_yda )
476
477          sendrecvcount_zyd = nnx * nny * ( nza / pdims(2) )
478       ENDIF
479    ENDIF
480
481!
482!-- Indices for direct transpositions y --> x (they are only possible in case
483!-- of a 1d-decomposition along x)
484    IF ( pdims(2) == 1 )  THEN
485       nny_x  = nny / pdims(1)
486       nys_x  = myid * nny_x
487       nyn_xa = ( myid + 1 ) * nny_x - 1
488       nyn_x  = MIN( ny, nyn_xa )
489       nzb_x  = 1
490       nzt_xa = nza
491       nzt_x  = nz
492       sendrecvcount_xy = nnx * nny_x * nza
493    ENDIF
494
495!
496!-- Indices for direct transpositions x --> y (they are only possible in case
497!-- of a 1d-decomposition along y)
498    IF ( pdims(1) == 1 )  THEN
499       nnx_y  = nnx / pdims(2)
500       nxl_y  = myid * nnx_y
501       nxr_ya = ( myid + 1 ) * nnx_y - 1
502       nxr_y  = MIN( nx, nxr_ya )
503       nzb_y  = 1
504       nzt_ya = nza
505       nzt_y  = nz
506       sendrecvcount_xy = nnx_y * nny * nza
507    ENDIF
508
509!
510!-- Arrays for storing the array bounds are needed any more
511    DEALLOCATE( nxlf , nxrf , nynf , nysf )
512
513!
514!-- Collect index bounds from other PEs (to be written to restart file later)
515    ALLOCATE( hor_index_bounds(4,0:numprocs-1) )
516
517    IF ( myid == 0 )  THEN
518
519       hor_index_bounds(1,0) = nxl
520       hor_index_bounds(2,0) = nxr
521       hor_index_bounds(3,0) = nys
522       hor_index_bounds(4,0) = nyn
523
524!
525!--    Receive data from all other PEs
526       DO  i = 1, numprocs-1
527          CALL MPI_RECV( ibuf, 4, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, &
528                         ierr )
529          hor_index_bounds(:,i) = ibuf(1:4)
530       ENDDO
531
532    ELSE
533!
534!--    Send index bounds to PE0
535       ibuf(1) = nxl
536       ibuf(2) = nxr
537       ibuf(3) = nys
538       ibuf(4) = nyn
539       CALL MPI_SEND( ibuf, 4, MPI_INTEGER, 0, myid, comm2d, ierr )
540
541    ENDIF
542
543#if defined( __print )
544!
545!-- Control output
546    IF ( myid == 0 )  THEN
547       PRINT*, '*** processor topology ***'
548       PRINT*, ' '
549       PRINT*, 'myid   pcoord    left right  south north  idx idy   nxl: nxr',&
550               &'   nys: nyn'
551       PRINT*, '------------------------------------------------------------',&
552               &'-----------'
553       WRITE (*,1000)  0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, &
554                       myidx, myidy, nxl, nxr, nys, nyn
5551000   FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3, &
556               2(2X,I4,':',I4))
557
558!
559!--    Receive data from the other PEs
560       DO  i = 1,numprocs-1
561          CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, &
562                         ierr )
563          WRITE (*,1000)  i, ( ibuf(j) , j = 1,12 )
564       ENDDO
565    ELSE
566
567!
568!--    Send data to PE0
569       ibuf(1) = pcoord(1); ibuf(2) = pcoord(2); ibuf(3) = pleft
570       ibuf(4) = pright; ibuf(5) = psouth; ibuf(6) = pnorth; ibuf(7) = myidx
571       ibuf(8) = myidy; ibuf(9) = nxl; ibuf(10) = nxr; ibuf(11) = nys
572       ibuf(12) = nyn
573       CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr )       
574    ENDIF
575#endif
576
577#if defined( __parallel )
578#if defined( __mpi2 )
579!
580!-- In case of coupled runs, get the port name on PE0 of the atmosphere model
581!-- and pass it to PE0 of the ocean model
582    IF ( myid == 0 )  THEN
583
584       IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
585
586          CALL MPI_OPEN_PORT( MPI_INFO_NULL, port_name, ierr )
587
588          CALL MPI_PUBLISH_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, &
589                                 ierr )
590
591!
592!--       Write a flag file for the ocean model and the other atmosphere
593!--       processes.
594!--       There seems to be a bug in MPICH2 which causes hanging processes
595!--       in case that execution of LOOKUP_NAME is continued too early
596!--       (i.e. before the port has been created)
597          OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
598          WRITE ( 90, '(''TRUE'')' )
599          CLOSE ( 90 )
600
601       ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
602
603!
604!--       Continue only if the atmosphere model has created the port.
605!--       There seems to be a bug in MPICH2 which causes hanging processes
606!--       in case that execution of LOOKUP_NAME is continued too early
607!--       (i.e. before the port has been created)
608          INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found )
609          DO WHILE ( .NOT. found )
610             INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found )
611          ENDDO
612
613          CALL MPI_LOOKUP_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, ierr )
614
615       ENDIF
616
617    ENDIF
618
619!
620!-- In case of coupled runs, establish the connection between the atmosphere
621!-- and the ocean model and define the intercommunicator (comm_inter)
622    CALL MPI_BARRIER( comm2d, ierr )
623    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
624
625       CALL MPI_COMM_ACCEPT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
626                             comm_inter, ierr )
627       coupling_mode_remote = 'ocean_to_atmosphere'
628
629    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
630
631       CALL MPI_COMM_CONNECT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
632                              comm_inter, ierr )
633       coupling_mode_remote = 'atmosphere_to_ocean'
634
635    ENDIF
636#endif
637
638!
639!-- Determine the number of ghost point layers
640    IF ( scalar_advec == 'ws-scheme' .OR. momentum_advec == 'ws-scheme' )  THEN
641       nbgp = 3
642    ELSE
643       nbgp = 1
644    ENDIF 
645
646!
647!-- Create a new MPI derived datatype for the exchange of surface (xy) data,
648!-- which is needed for coupled atmosphere-ocean runs.
649!-- First, calculate number of grid points of an xy-plane.
650    ngp_xy  = ( nxr - nxl + 1 + 2 * nbgp ) * ( nyn - nys + 1 + 2 * nbgp )
651    CALL MPI_TYPE_VECTOR( ngp_xy, 1, nzt-nzb+2, MPI_REAL, type_xy, ierr )
652    CALL MPI_TYPE_COMMIT( type_xy, ierr )
653
654    IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
655   
656!
657!--    Pass the number of grid points of the atmosphere model to
658!--    the ocean model and vice versa
659       IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
660
661          nx_a = nx
662          ny_a = ny
663
664          IF ( myid == 0 )  THEN
665
666             CALL MPI_SEND( nx_a, 1, MPI_INTEGER, numprocs, 1, comm_inter,  &
667                            ierr )
668             CALL MPI_SEND( ny_a, 1, MPI_INTEGER, numprocs, 2, comm_inter,  &
669                            ierr )
670             CALL MPI_SEND( pdims, 2, MPI_INTEGER, numprocs, 3, comm_inter, &
671                            ierr )
672             CALL MPI_RECV( nx_o, 1, MPI_INTEGER, numprocs, 4, comm_inter,  &
673                            status, ierr )
674             CALL MPI_RECV( ny_o, 1, MPI_INTEGER, numprocs, 5, comm_inter,  &
675                            status, ierr )
676             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, numprocs, 6,      &
677                            comm_inter, status, ierr )
678          ENDIF
679
680          CALL MPI_BCAST( nx_o, 1, MPI_INTEGER, 0, comm2d, ierr )
681          CALL MPI_BCAST( ny_o, 1, MPI_INTEGER, 0, comm2d, ierr ) 
682          CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr )
683       
684       ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
685
686          nx_o = nx
687          ny_o = ny 
688
689          IF ( myid == 0 ) THEN
690
691             CALL MPI_RECV( nx_a, 1, MPI_INTEGER, 0, 1, comm_inter, status, &
692                            ierr )
693             CALL MPI_RECV( ny_a, 1, MPI_INTEGER, 0, 2, comm_inter, status, &
694                            ierr )
695             CALL MPI_RECV( pdims_remote, 2, MPI_INTEGER, 0, 3, comm_inter, &
696                            status, ierr )
697             CALL MPI_SEND( nx_o, 1, MPI_INTEGER, 0, 4, comm_inter, ierr )
698             CALL MPI_SEND( ny_o, 1, MPI_INTEGER, 0, 5, comm_inter, ierr )
699             CALL MPI_SEND( pdims, 2, MPI_INTEGER, 0, 6, comm_inter, ierr )
700          ENDIF
701
702          CALL MPI_BCAST( nx_a, 1, MPI_INTEGER, 0, comm2d, ierr)
703          CALL MPI_BCAST( ny_a, 1, MPI_INTEGER, 0, comm2d, ierr) 
704          CALL MPI_BCAST( pdims_remote, 2, MPI_INTEGER, 0, comm2d, ierr) 
705
706       ENDIF
707 
708       ngp_a = ( nx_a+1 + 2 * nbgp ) * ( ny_a+1 + 2 * nbgp )
709       ngp_o = ( nx_o+1 + 2 * nbgp ) * ( ny_o+1 + 2 * nbgp )
710
711!
712!--    Determine if the horizontal grid and the number of PEs in ocean and
713!--    atmosphere is same or not
714       IF ( nx_o == nx_a  .AND.  ny_o == ny_a  .AND.  &
715            pdims(1) == pdims_remote(1) .AND. pdims(2) == pdims_remote(2) ) &
716       THEN
717          coupling_topology = 0
718       ELSE
719          coupling_topology = 1
720       ENDIF 
721
722!
723!--    Determine the target PEs for the exchange between ocean and
724!--    atmosphere (comm2d)
725       IF ( coupling_topology == 0 )  THEN
726!
727!--       In case of identical topologies, every atmosphere PE has exactly one
728!--       ocean PE counterpart and vice versa
729          IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN
730             target_id = myid + numprocs
731          ELSE
732             target_id = myid 
733          ENDIF
734
735       ELSE
736!
737!--       In case of nonequivalent topology in ocean and atmosphere only for
738!--       PE0 in ocean and PE0 in atmosphere a target_id is needed, since
739!--       data echxchange between ocean and atmosphere will be done only
740!--       between these PEs.   
741          IF ( myid == 0 )  THEN
742
743             IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
744                target_id = numprocs 
745             ELSE
746                target_id = 0
747             ENDIF
748
749          ENDIF
750
751       ENDIF
752
753    ENDIF
754
755
756#endif
757
758#else
759
760!
761!-- Array bounds when running on a single PE (respectively a non-parallel
762!-- machine)
763    nxl  = 0
764    nxr  = nx
765    nxra = nx
766    nnx  = nxr - nxl + 1
767    nys  = 0
768    nyn  = ny
769    nyna = ny
770    nny  = nyn - nys + 1
771    nzb  = 0
772    nzt  = nz
773    nzta = nz
774    nnz  = nz
775
776    ALLOCATE( hor_index_bounds(4,0:0) )
777    hor_index_bounds(1,0) = nxl
778    hor_index_bounds(2,0) = nxr
779    hor_index_bounds(3,0) = nys
780    hor_index_bounds(4,0) = nyn
781
782!
783!-- Array bounds for the pressure solver (in the parallel code, these bounds
784!-- are the ones for the transposed arrays)
785    nys_x  = nys
786    nyn_x  = nyn
787    nyn_xa = nyn
788    nzb_x  = nzb + 1
789    nzt_x  = nzt
790    nzt_xa = nzt
791
792    nxl_y  = nxl
793    nxr_y  = nxr
794    nxr_ya = nxr
795    nzb_y  = nzb + 1
796    nzt_y  = nzt
797    nzt_ya = nzt
798
799    nxl_z  = nxl
800    nxr_z  = nxr
801    nxr_za = nxr
802    nys_z  = nys
803    nyn_z  = nyn
804    nyn_za = nyn
805
806#endif
807
808!
809!-- Calculate number of grid levels necessary for the multigrid poisson solver
810!-- as well as the gridpoint indices on each level
811    IF ( psolver == 'multigrid' )  THEN
812
813!
814!--    First calculate number of possible grid levels for the subdomains
815       mg_levels_x = 1
816       mg_levels_y = 1
817       mg_levels_z = 1
818
819       i = nnx
820       DO WHILE ( MOD( i, 2 ) == 0  .AND.  i /= 2 )
821          i = i / 2
822          mg_levels_x = mg_levels_x + 1
823       ENDDO
824
825       j = nny
826       DO WHILE ( MOD( j, 2 ) == 0  .AND.  j /= 2 )
827          j = j / 2
828          mg_levels_y = mg_levels_y + 1
829       ENDDO
830
831       k = nz    ! do not use nnz because it might be > nz due to transposition
832                 ! requirements
833       DO WHILE ( MOD( k, 2 ) == 0  .AND.  k /= 2 )
834          k = k / 2
835          mg_levels_z = mg_levels_z + 1
836       ENDDO
837
838       maximum_grid_level = MIN( mg_levels_x, mg_levels_y, mg_levels_z )
839
840!
841!--    Find out, if the total domain allows more levels. These additional
842!--    levels are identically processed on all PEs.
843       IF ( numprocs > 1  .AND.  mg_switch_to_pe0_level /= -1 )  THEN
844
845          IF ( mg_levels_z > MIN( mg_levels_x, mg_levels_y ) )  THEN
846
847             mg_switch_to_pe0_level_l = maximum_grid_level
848
849             mg_levels_x = 1
850             mg_levels_y = 1
851
852             i = nx+1
853             DO WHILE ( MOD( i, 2 ) == 0  .AND.  i /= 2 )
854                i = i / 2
855                mg_levels_x = mg_levels_x + 1
856             ENDDO
857
858             j = ny+1
859             DO WHILE ( MOD( j, 2 ) == 0  .AND.  j /= 2 )
860                j = j / 2
861                mg_levels_y = mg_levels_y + 1
862             ENDDO
863
864             maximum_grid_level_l = MIN( mg_levels_x, mg_levels_y, mg_levels_z )
865
866             IF ( maximum_grid_level_l > mg_switch_to_pe0_level_l )  THEN
867                mg_switch_to_pe0_level_l = maximum_grid_level_l - &
868                                           mg_switch_to_pe0_level_l + 1
869             ELSE
870                mg_switch_to_pe0_level_l = 0
871             ENDIF
872
873          ELSE
874
875             mg_switch_to_pe0_level_l = 0
876             maximum_grid_level_l = maximum_grid_level
877
878          ENDIF
879
880!
881!--       Use switch level calculated above only if it is not pre-defined
882!--       by user
883          IF ( mg_switch_to_pe0_level == 0 )  THEN
884
885             IF ( mg_switch_to_pe0_level_l /= 0 )  THEN
886                mg_switch_to_pe0_level = mg_switch_to_pe0_level_l
887                maximum_grid_level     = maximum_grid_level_l
888             ENDIF
889
890          ELSE
891!
892!--          Check pre-defined value and reset to default, if neccessary
893             IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l  .OR.  &
894                  mg_switch_to_pe0_level >= maximum_grid_level_l )  THEN
895                message_string = 'mg_switch_to_pe0_level ' // &
896                                 'out of range and reset to default (=0)'
897                CALL message( 'init_pegrid', 'PA0235', 0, 1, 0, 6, 0 )
898                mg_switch_to_pe0_level = 0
899             ELSE
900!
901!--             Use the largest number of possible levels anyway and recalculate
902!--             the switch level to this largest number of possible values
903                maximum_grid_level = maximum_grid_level_l
904
905             ENDIF
906
907          ENDIF
908
909       ENDIF
910
911       ALLOCATE( grid_level_count(maximum_grid_level),                   &
912                 nxl_mg(maximum_grid_level), nxr_mg(maximum_grid_level), &
913                 nyn_mg(maximum_grid_level), nys_mg(maximum_grid_level), &
914                 nzt_mg(maximum_grid_level) )
915
916       grid_level_count = 0
917       nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzt_l = nzt
918
919       DO  i = maximum_grid_level, 1 , -1
920
921          IF ( i == mg_switch_to_pe0_level )  THEN
922#if defined( __parallel )
923!
924!--          Save the grid size of the subdomain at the switch level, because
925!--          it is needed in poismg.
926             ind(1) = nxl_l; ind(2) = nxr_l
927             ind(3) = nys_l; ind(4) = nyn_l
928             ind(5) = nzt_l
929             ALLOCATE( ind_all(5*numprocs), mg_loc_ind(5,0:numprocs-1) )
930             CALL MPI_ALLGATHER( ind, 5, MPI_INTEGER, ind_all, 5, &
931                                 MPI_INTEGER, comm2d, ierr )
932             DO  j = 0, numprocs-1
933                DO  k = 1, 5
934                   mg_loc_ind(k,j) = ind_all(k+j*5)
935                ENDDO
936             ENDDO
937             DEALLOCATE( ind_all )
938!
939!--          Calculate the grid size of the total domain
940             nxr_l = ( nxr_l-nxl_l+1 ) * pdims(1) - 1
941             nxl_l = 0
942             nyn_l = ( nyn_l-nys_l+1 ) * pdims(2) - 1
943             nys_l = 0
944!
945!--          The size of this gathered array must not be larger than the
946!--          array tend, which is used in the multigrid scheme as a temporary
947!--          array
948             subdomain_size = ( nxr - nxl + 3 )     * ( nyn - nys + 3 )     * &
949                              ( nzt - nzb + 2 )
950             gathered_size  = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) * &
951                              ( nzt_l - nzb + 2 )
952
953             IF ( gathered_size > subdomain_size )  THEN
954                message_string = 'not enough memory for storing ' // &
955                                 'gathered multigrid data on PE0'
956                CALL message( 'init_pegrid', 'PA0236', 1, 2, 0, 6, 0 )
957             ENDIF
958#else
959             message_string = 'multigrid gather/scatter impossible ' // &
960                          'in non parallel mode'
961             CALL message( 'init_pegrid', 'PA0237', 1, 2, 0, 6, 0 )
962#endif
963          ENDIF
964
965          nxl_mg(i) = nxl_l
966          nxr_mg(i) = nxr_l
967          nys_mg(i) = nys_l
968          nyn_mg(i) = nyn_l
969          nzt_mg(i) = nzt_l
970
971          nxl_l = nxl_l / 2 
972          nxr_l = nxr_l / 2
973          nys_l = nys_l / 2 
974          nyn_l = nyn_l / 2 
975          nzt_l = nzt_l / 2 
976       ENDDO
977
978    ELSE
979
980       maximum_grid_level = 0
981
982    ENDIF
983
984!
985!-- Default level 0 tells exchange_horiz that all ghost planes have to be
986!-- exchanged. grid_level is adjusted in poismg, where only one ghost plane
987!-- is required.
988    grid_level = 0
989
990#if defined( __parallel )
991!
992!-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays)
993    ngp_y  = nyn - nys + 1 + 2 * nbgp
994
995!
996!-- Define new MPI derived datatypes for the exchange of ghost points in
997!-- x- and y-direction for 2D-arrays (line)
998    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_REAL, type_x, &
999                          ierr )
1000    CALL MPI_TYPE_COMMIT( type_x, ierr )
1001    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp, ngp_y, MPI_INTEGER, &
1002                          type_x_int, ierr )
1003    CALL MPI_TYPE_COMMIT( type_x_int, ierr )
1004
1005    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_REAL, type_y, ierr )
1006    CALL MPI_TYPE_COMMIT( type_y, ierr )
1007    CALL MPI_TYPE_VECTOR( nbgp, ngp_y, ngp_y, MPI_INTEGER, type_y_int, ierr )
1008    CALL MPI_TYPE_COMMIT( type_y_int, ierr )
1009
1010
1011!
1012!-- Calculate gridpoint numbers for the exchange of ghost points along x
1013!-- (yz-plane for 3D-arrays) and define MPI derived data type(s) for the
1014!-- exchange of ghost points in y-direction (xz-plane).
1015!-- Do these calculations for the model grid and (if necessary) also
1016!-- for the coarser grid levels used in the multigrid method
1017    ALLOCATE ( ngp_yz(0:maximum_grid_level), type_xz(0:maximum_grid_level),&
1018               type_yz(0:maximum_grid_level) )
1019
1020    nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt
1021
1022!
1023!-- Discern between the model grid, which needs nbgp ghost points and
1024!-- grid levels for the multigrid scheme. In the latter case only one
1025!-- ghost point is necessary.
1026!-- First definition of MPI-datatypes for exchange of ghost layers on normal
1027!-- grid. The following loop is needed for data exchange in poismg.f90.
1028!
1029!-- Determine number of grid points of yz-layer for exchange
1030    ngp_yz(0) = (nzt - nzb + 2) * (nyn - nys + 1 + 2 * nbgp)
1031
1032!
1033!-- Define an MPI-datatype for the exchange of left/right boundaries.
1034!-- Although data are contiguous in physical memory (which does not
1035!-- necessarily require an MPI-derived datatype), the data exchange between
1036!-- left and right PE's using the MPI-derived type is 10% faster than without.
1037    CALL MPI_TYPE_VECTOR( nxr-nxl+1+2*nbgp, nbgp*(nzt-nzb+2), ngp_yz(0), &
1038                          MPI_REAL, type_xz(0), ierr )
1039    CALL MPI_TYPE_COMMIT( type_xz(0), ierr )
1040
1041    CALL MPI_TYPE_VECTOR( nbgp, ngp_yz(0), ngp_yz(0), MPI_REAL, type_yz(0), &
1042                          ierr ) 
1043    CALL MPI_TYPE_COMMIT( type_yz(0), ierr )
1044
1045!
1046!-- Definition of MPI-datatypes for multigrid method (coarser level grids)
1047    IF ( psolver == 'multigrid' )  THEN
1048!   
1049!--    Definition of MPI-datatyoe as above, but only 1 ghost level is used
1050       DO  i = maximum_grid_level, 1 , -1
1051
1052          ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
1053
1054          CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i), &
1055                                MPI_REAL, type_xz(i), ierr )
1056          CALL MPI_TYPE_COMMIT( type_xz(i), ierr )
1057
1058          CALL MPI_TYPE_VECTOR( 1, ngp_yz(i), ngp_yz(i), MPI_REAL, type_yz(i), &
1059                                ierr )
1060          CALL MPI_TYPE_COMMIT( type_yz(i), ierr )
1061
1062          nxl_l = nxl_l / 2
1063          nxr_l = nxr_l / 2
1064          nys_l = nys_l / 2
1065          nyn_l = nyn_l / 2
1066          nzt_l = nzt_l / 2
1067
1068       ENDDO
1069
1070    ENDIF
1071#endif
1072
1073#if defined( __parallel )
1074!
1075!-- Setting of flags for inflow/outflow conditions in case of non-cyclic
1076!-- horizontal boundary conditions.
1077    IF ( pleft == MPI_PROC_NULL )  THEN
1078       IF ( bc_lr == 'dirichlet/radiation' )  THEN
1079          inflow_l  = .TRUE.
1080       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
1081          outflow_l = .TRUE.
1082       ENDIF
1083    ENDIF
1084
1085    IF ( pright == MPI_PROC_NULL )  THEN
1086       IF ( bc_lr == 'dirichlet/radiation' )  THEN
1087          outflow_r = .TRUE.
1088       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
1089          inflow_r  = .TRUE.
1090       ENDIF
1091    ENDIF
1092
1093    IF ( psouth == MPI_PROC_NULL )  THEN
1094       IF ( bc_ns == 'dirichlet/radiation' )  THEN
1095          outflow_s = .TRUE.
1096       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
1097          inflow_s  = .TRUE.
1098       ENDIF
1099    ENDIF
1100
1101    IF ( pnorth == MPI_PROC_NULL )  THEN
1102       IF ( bc_ns == 'dirichlet/radiation' )  THEN
1103          inflow_n  = .TRUE.
1104       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
1105          outflow_n = .TRUE.
1106       ENDIF
1107    ENDIF
1108
1109!
1110!-- Broadcast the id of the inflow PE
1111    IF ( inflow_l )  THEN
1112       id_inflow_l = myidx
1113    ELSE
1114       id_inflow_l = 0
1115    ENDIF
1116    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1117    CALL MPI_ALLREDUCE( id_inflow_l, id_inflow, 1, MPI_INTEGER, MPI_SUM, &
1118                        comm1dx, ierr )
1119
1120!
1121!-- Broadcast the id of the recycling plane
1122!-- WARNING: needs to be adjusted in case of inflows other than from left side!
1123    IF ( ( recycling_width / dx ) >= nxl  .AND. &
1124         ( recycling_width / dx ) <= nxr )  THEN
1125       id_recycling_l = myidx
1126    ELSE
1127       id_recycling_l = 0
1128    ENDIF
1129    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1130    CALL MPI_ALLREDUCE( id_recycling_l, id_recycling, 1, MPI_INTEGER, MPI_SUM, &
1131                        comm1dx, ierr )
1132
1133#else
1134    IF ( bc_lr == 'dirichlet/radiation' )  THEN
1135       inflow_l  = .TRUE.
1136       outflow_r = .TRUE.
1137    ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
1138       outflow_l = .TRUE.
1139       inflow_r  = .TRUE.
1140    ENDIF
1141
1142    IF ( bc_ns == 'dirichlet/radiation' )  THEN
1143       inflow_n  = .TRUE.
1144       outflow_s = .TRUE.
1145    ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
1146       outflow_n = .TRUE.
1147       inflow_s  = .TRUE.
1148    ENDIF
1149#endif
1150!
1151!-- At the outflow, u or v, respectively, have to be calculated for one more
1152!-- grid point.
1153    IF ( outflow_l )  THEN
1154       nxlu = nxl + 1
1155    ELSE
1156       nxlu = nxl
1157    ENDIF
1158    IF ( outflow_s )  THEN
1159       nysv = nys + 1
1160    ELSE
1161       nysv = nys
1162    ENDIF
1163
1164    IF ( psolver == 'poisfft_hybrid' )  THEN
1165       CALL poisfft_hybrid_ini
1166    ELSEIF ( psolver == 'poisfft' )  THEN
1167       CALL poisfft_init
1168    ENDIF
1169
1170!
1171!-- Allocate wall flag arrays used in the multigrid solver
1172    IF ( psolver == 'multigrid' )  THEN
1173
1174       DO  i = maximum_grid_level, 1, -1
1175
1176           SELECT CASE ( i )
1177
1178              CASE ( 1 )
1179                 ALLOCATE( wall_flags_1(nzb:nzt_mg(i)+1,         &
1180                                        nys_mg(i)-1:nyn_mg(i)+1, &
1181                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1182
1183              CASE ( 2 )
1184                 ALLOCATE( wall_flags_2(nzb:nzt_mg(i)+1,         &
1185                                        nys_mg(i)-1:nyn_mg(i)+1, &
1186                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1187
1188              CASE ( 3 )
1189                 ALLOCATE( wall_flags_3(nzb:nzt_mg(i)+1,         &
1190                                        nys_mg(i)-1:nyn_mg(i)+1, &
1191                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1192
1193              CASE ( 4 )
1194                 ALLOCATE( wall_flags_4(nzb:nzt_mg(i)+1,         &
1195                                        nys_mg(i)-1:nyn_mg(i)+1, &
1196                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1197
1198              CASE ( 5 )
1199                 ALLOCATE( wall_flags_5(nzb:nzt_mg(i)+1,         &
1200                                        nys_mg(i)-1:nyn_mg(i)+1, &
1201                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1202
1203              CASE ( 6 )
1204                 ALLOCATE( wall_flags_6(nzb:nzt_mg(i)+1,         &
1205                                        nys_mg(i)-1:nyn_mg(i)+1, &
1206                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1207
1208              CASE ( 7 )
1209                 ALLOCATE( wall_flags_7(nzb:nzt_mg(i)+1,         &
1210                                        nys_mg(i)-1:nyn_mg(i)+1, &
1211                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1212
1213              CASE ( 8 )
1214                 ALLOCATE( wall_flags_8(nzb:nzt_mg(i)+1,         &
1215                                        nys_mg(i)-1:nyn_mg(i)+1, &
1216                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1217
1218              CASE ( 9 )
1219                 ALLOCATE( wall_flags_9(nzb:nzt_mg(i)+1,         &
1220                                        nys_mg(i)-1:nyn_mg(i)+1, &
1221                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1222
1223              CASE ( 10 )
1224                 ALLOCATE( wall_flags_10(nzb:nzt_mg(i)+1,        &
1225                                        nys_mg(i)-1:nyn_mg(i)+1, &
1226                                        nxl_mg(i)-1:nxr_mg(i)+1) )
1227
1228              CASE DEFAULT
1229                 message_string = 'more than 10 multigrid levels'
1230                 CALL message( 'init_pegrid', 'PA0238', 1, 2, 0, 6, 0 )
1231
1232          END SELECT
1233
1234       ENDDO
1235
1236    ENDIF
1237
1238 END SUBROUTINE init_pegrid
Note: See TracBrowser for help on using the repository browser.