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

Last change on this file since 110 was 110, checked in by raasch, 16 years ago

New:
---
Allows runs for a coupled atmosphere-ocean LES,
coupling frequency is controlled by new d3par-parameter dt_coupling,
the coupling mode (atmosphere_to_ocean or ocean_to_atmosphere) for the
respective processes is read from environment variable coupling_mode,
which is set by the mpiexec-command,
communication between the two models is done using the intercommunicator
comm_inter,
local files opened by the ocean model get the additional suffic "_O".
Assume saturation at k=nzb_s_inner(j,i) for atmosphere coupled to ocean.

A momentum flux can be set as top boundary condition using the new
inipar parameter top_momentumflux_u|v.

Non-cyclic boundary conditions can be used along all horizontal directions.

Quantities w*p* and w"e can be output as vertical profiles.

Initial profiles are reset to constant profiles in case that initializing_actions /= 'set_constant_profiles'. (init_rankine)

Optionally calculate km and kh from initial TKE e_init.

Changed:


Remaining variables iran changed to iran_part (advec_particles, init_particles).

In case that the presure solver is not called for every Runge-Kutta substep
(call_psolver_at_all_substeps = .F.), it is called after the first substep
instead of the last. In that case, random perturbations are also added to the
velocity field after the first substep.

Initialization of km,kh = 0.00001 for ocean = .T. (for ocean = .F. it remains 0.01).

Allow data_output_pr= q, wq, w"q", w*q* for humidity = .T. (instead of cloud_physics = .T.).

Errors:


Bugs from code parts for non-cyclic boundary conditions are removed: loops for
u and v are starting from index nxlu, nysv, respectively. The radiation boundary
condition is used for every Runge-Kutta substep. Velocity phase speeds for
the radiation boundary conditions are calculated for the first Runge-Kutta
substep only and reused for the further substeps. New arrays c_u, c_v, and c_w
are defined for this purpose. Several index errors are removed from the
radiation boundary condition code parts. Upper bounds for calculating
u_0 and v_0 (in production_e) are nxr+1 and nyn+1 because otherwise these
values are not available in case of non-cyclic boundary conditions.

+dots_num_palm in module user, +module netcdf_control in user_init (both in user_interface)

Bugfix: wrong sign removed from the buoyancy production term in the case use_reference = .T. (production_e)

Bugfix: Error message concerning output of particle concentration (pc) modified (check_parameters).

Bugfix: Rayleigh damping for ocean fixed.

  • Property svn:keywords set to Id
File size: 28.3 KB
Line 
1 SUBROUTINE init_pegrid
2
3!------------------------------------------------------------------------------!
4! Actual revisions:
5! -----------------
6! TEST OUTPUT (TO BE REMOVED) logging mpi2 ierr values
7!
8! Former revisions:
9! -----------------
10! $Id: init_pegrid.f90 110 2007-10-05 05:13:14Z raasch $
11!
12! 108 2007-08-24 15:10:38Z letzel
13! Intercommunicator (comm_inter) and derived data type (type_xy) for
14! coupled model runs created, assign coupling_mode_remote,
15! indices nxlu and nysv are calculated (needed for non-cyclic boundary
16! conditions)
17!
18! 82 2007-04-16 15:40:52Z raasch
19! Cpp-directive lcmuk changed to intel_openmp_bug, setting of host on lcmuk by
20! cpp-directive removed
21!
22! 75 2007-03-22 09:54:05Z raasch
23! uxrp, vynp eliminated,
24! dirichlet/neumann changed to dirichlet/radiation, etc.,
25! poisfft_init is only called if fft-solver is switched on
26!
27! RCS Log replace by Id keyword, revision history cleaned up
28!
29! Revision 1.28  2006/04/26 13:23:32  raasch
30! lcmuk does not understand the !$ comment so a cpp-directive is required
31!
32! Revision 1.1  1997/07/24 11:15:09  raasch
33! Initial revision
34!
35!
36! Description:
37! ------------
38! Determination of the virtual processor topology (if not prescribed by the
39! user)and computation of the grid point number and array bounds of the local
40! domains.
41!------------------------------------------------------------------------------!
42
43    USE control_parameters
44    USE fft_xy
45    USE indices
46    USE pegrid
47    USE poisfft_mod
48    USE poisfft_hybrid_mod
49    USE statistics
50    USE transpose_indices
51
52
53    IMPLICIT NONE
54
55    INTEGER ::  gathered_size, i, ind(5), j, k, maximum_grid_level_l,     &
56                mg_switch_to_pe0_level_l, mg_levels_x, mg_levels_y,       &
57                mg_levels_z, nnx_y, nnx_z, nny_x, nny_z, nnz_x, nnz_y,    &
58                numproc_sqr, nx_total, nxl_l, nxr_l, nyn_l, nys_l, nzb_l, &
59                nzt_l, omp_get_num_threads, subdomain_size
60
61    INTEGER, DIMENSION(:), ALLOCATABLE ::  ind_all, nxlf, nxrf, nynf, nysf
62
63    LOGICAL ::  found
64
65!
66!-- Get the number of OpenMP threads
67    !$OMP PARALLEL
68#if defined( __intel_openmp_bug )
69    threads_per_task = omp_get_num_threads()
70#else
71!$  threads_per_task = omp_get_num_threads()
72#endif
73    !$OMP END PARALLEL
74
75
76#if defined( __parallel )
77!
78!-- Determine the processor topology or check it, if prescribed by the user
79    IF ( npex == -1  .AND.  npey == -1 )  THEN
80
81!
82!--    Automatic determination of the topology
83!--    The default on SMP- and cluster-hosts is a 1d-decomposition along x
84       IF ( host(1:3) == 'ibm'  .OR.  host(1:3) == 'nec'  .OR. &
85            host(1:2) == 'lc'   .OR.  host(1:3) == 'dec' )  THEN
86
87          pdims(1) = numprocs
88          pdims(2) = 1
89
90       ELSE
91
92          numproc_sqr = SQRT( REAL( numprocs ) )
93          pdims(1)    = MAX( numproc_sqr , 1 )
94          DO  WHILE ( MOD( numprocs , pdims(1) ) /= 0 )
95             pdims(1) = pdims(1) - 1
96          ENDDO
97          pdims(2) = numprocs / pdims(1)
98
99       ENDIF
100
101    ELSEIF ( npex /= -1  .AND.  npey /= -1 )  THEN
102
103!
104!--    Prescribed by user. Number of processors on the prescribed topology
105!--    must be equal to the number of PEs available to the job
106       IF ( ( npex * npey ) /= numprocs )  THEN
107          PRINT*, '+++ init_pegrid:'
108          PRINT*, '    number of PEs of the prescribed topology (', npex*npey, &
109                      ') does not match the number of PEs available to the ',  &
110                      'job (', numprocs, ')'
111          CALL local_stop
112       ENDIF
113       pdims(1) = npex
114       pdims(2) = npey
115
116    ELSE
117!
118!--    If the processor topology is prescribed by the user, the number of
119!--    PEs must be given in both directions
120       PRINT*, '+++ init_pegrid:'
121       PRINT*, '    if the processor topology is prescribed by the user, ',   &
122                    'both values of "npex" and "npey" must be given in the ', &
123                    'NAMELIST-parameter file'
124       CALL local_stop
125
126    ENDIF
127
128!
129!-- The hybrid solver can only be used in case of a 1d-decomposition along x
130    IF ( pdims(2) /= 1  .AND.  psolver == 'poisfft_hybrid' )  THEN
131       IF ( myid == 0 )  THEN
132          PRINT*, '*** init_pegrid: psolver = "poisfft_hybrid" can only be'
133          PRINT*, '                 used in case of a 1d-decomposition along x'
134       ENDIF
135    ENDIF
136
137!
138!-- If necessary, set horizontal boundary conditions to non-cyclic
139    IF ( bc_lr /= 'cyclic' )  cyclic(1) = .FALSE.
140    IF ( bc_ns /= 'cyclic' )  cyclic(2) = .FALSE.
141
142!
143!-- Create the virtual processor grid
144    CALL MPI_CART_CREATE( comm_palm, ndim, pdims, cyclic, reorder, &
145                          comm2d, ierr )
146    CALL MPI_COMM_RANK( comm2d, myid, ierr )
147    WRITE (myid_char,'(''_'',I4.4)')  myid
148
149    CALL MPI_CART_COORDS( comm2d, myid, ndim, pcoord, ierr )
150    CALL MPI_CART_SHIFT( comm2d, 0, 1, pleft, pright, ierr )
151    CALL MPI_CART_SHIFT( comm2d, 1, 1, psouth, pnorth, ierr )
152
153!
154!-- Determine sub-topologies for transpositions
155!-- Transposition from z to x:
156    remain_dims(1) = .TRUE.
157    remain_dims(2) = .FALSE.
158    CALL MPI_CART_SUB( comm2d, remain_dims, comm1dx, ierr )
159    CALL MPI_COMM_RANK( comm1dx, myidx, ierr )
160!
161!-- Transposition from x to y
162    remain_dims(1) = .FALSE.
163    remain_dims(2) = .TRUE.
164    CALL MPI_CART_SUB( comm2d, remain_dims, comm1dy, ierr )
165    CALL MPI_COMM_RANK( comm1dy, myidy, ierr )
166
167
168!
169!-- Find a grid (used for array d) which will match the transposition demands
170    IF ( grid_matching == 'strict' )  THEN
171
172       nxa = nx;  nya = ny;  nza = nz
173
174    ELSE
175
176       found = .FALSE.
177   xn: DO  nxa = nx, 2*nx
178!
179!--       Meet conditions for nx
180          IF ( MOD( nxa+1, pdims(1) ) /= 0 .OR. &
181               MOD( nxa+1, pdims(2) ) /= 0 )  CYCLE xn
182
183      yn: DO  nya = ny, 2*ny
184!
185!--          Meet conditions for ny
186             IF ( MOD( nya+1, pdims(2) ) /= 0 .OR. &
187                  MOD( nya+1, pdims(1) ) /= 0 )  CYCLE yn
188
189
190         zn: DO  nza = nz, 2*nz
191!
192!--             Meet conditions for nz
193                IF ( ( MOD( nza, pdims(1) ) /= 0  .AND.  pdims(1) /= 1  .AND. &
194                       pdims(2) /= 1 )  .OR.                                  &
195                     ( MOD( nza, pdims(2) ) /= 0  .AND.  dt_dosp /= 9999999.9 &
196                     ) )  THEN
197                   CYCLE zn
198                ELSE
199                   found = .TRUE.
200                   EXIT xn
201                ENDIF
202
203             ENDDO zn
204
205          ENDDO yn
206
207       ENDDO xn
208
209       IF ( .NOT. found )  THEN
210          IF ( myid == 0 )  THEN
211             PRINT*,'+++ init_pegrid: no matching grid for transpositions found'
212          ENDIF
213          CALL local_stop
214       ENDIF
215
216    ENDIF
217
218!
219!-- Calculate array bounds in x-direction for every PE.
220!-- The last PE along x may get less grid points than the others
221    ALLOCATE( nxlf(0:pdims(1)-1), nxrf(0:pdims(1)-1), nynf(0:pdims(2)-1), &
222              nysf(0:pdims(2)-1), nnx_pe(0:pdims(1)-1), nny_pe(0:pdims(2)-1) )
223
224    IF ( MOD( nxa+1 , pdims(1) ) /= 0 )  THEN
225       IF ( myid == 0 )  THEN
226          PRINT*,'+++ x-direction:  gridpoint number (',nx+1,') is not an'
227          PRINT*,'                  integral divisor of the number of proces', &
228                                   &'sors (', pdims(1),')'
229       ENDIF
230       CALL local_stop
231    ELSE
232       nnx  = ( nxa + 1 ) / pdims(1)
233       IF ( nnx*pdims(1) - ( nx + 1) > nnx )  THEN
234          IF ( myid == 0 )  THEN
235             PRINT*,'+++ x-direction: nx does not match the requirements ', &
236                         'given by the number of PEs'
237             PRINT*,'                 used'
238             PRINT*,'    please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
239                         - ( nx + 1 ) ) ), ' instead of nx =', nx
240          ENDIF
241          CALL local_stop
242       ENDIF
243    ENDIF   
244
245!
246!-- Left and right array bounds, number of gridpoints
247    DO  i = 0, pdims(1)-1
248       nxlf(i)   = i * nnx
249       nxrf(i)   = ( i + 1 ) * nnx - 1
250       nnx_pe(i) = MIN( nx, nxrf(i) ) - nxlf(i) + 1
251    ENDDO
252
253!
254!-- Calculate array bounds in y-direction for every PE.
255    IF ( MOD( nya+1 , pdims(2) ) /= 0 )  THEN
256       IF ( myid == 0 )  THEN
257          PRINT*,'+++ y-direction:  gridpoint number (',ny+1,') is not an'
258          PRINT*,'                  integral divisor of the number of proces', &
259                                   &'sors (', pdims(2),')'
260       ENDIF
261       CALL local_stop
262    ELSE
263       nny  = ( nya + 1 ) / pdims(2)
264       IF ( nny*pdims(2) - ( ny + 1) > nny )  THEN
265          IF ( myid == 0 )  THEN
266             PRINT*,'+++ x-direction: nx does not match the requirements ', &
267                         'given by the number of PEs'
268             PRINT*,'                 used'
269             PRINT*,'    please use nx = ', nx - ( pdims(1) - ( nnx*pdims(1) &
270                         - ( nx + 1 ) ) ), ' instead of nx =', nx
271          ENDIF
272          CALL local_stop
273       ENDIF
274    ENDIF   
275
276!
277!-- South and north array bounds
278    DO  j = 0, pdims(2)-1
279       nysf(j)   = j * nny
280       nynf(j)   = ( j + 1 ) * nny - 1
281       nny_pe(j) = MIN( ny, nynf(j) ) - nysf(j) + 1
282    ENDDO
283
284!
285!-- Local array bounds of the respective PEs
286    nxl  = nxlf(pcoord(1))
287    nxra = nxrf(pcoord(1))
288    nxr  = MIN( nx, nxra )
289    nys  = nysf(pcoord(2))
290    nyna = nynf(pcoord(2))
291    nyn  = MIN( ny, nyna )
292    nzb  = 0
293    nzta = nza
294    nzt  = MIN( nz, nzta )
295    nnz  = nza
296
297!
298!-- Calculate array bounds and gridpoint numbers for the transposed arrays
299!-- (needed in the pressure solver)
300!-- For the transposed arrays, cyclic boundaries as well as top and bottom
301!-- boundaries are omitted, because they are obstructive to the transposition
302
303!
304!-- 1. transposition  z --> x
305!-- This transposition is not neccessary in case of a 1d-decomposition along x,
306!-- except that the uptream-spline method is switched on
307    IF ( pdims(2) /= 1  .OR.  momentum_advec == 'ups-scheme'  .OR. &
308         scalar_advec == 'ups-scheme' )  THEN
309
310       IF ( pdims(2) == 1  .AND. ( momentum_advec == 'ups-scheme'  .OR. &
311            scalar_advec == 'ups-scheme' ) )  THEN
312          IF ( myid == 0 )  THEN
313             PRINT*,'+++ WARNING: init_pegrid: 1d-decomposition along x ', &
314                                &'chosen but nz restrictions may occur'
315             PRINT*,'             since ups-scheme is activated'
316          ENDIF
317       ENDIF
318       nys_x  = nys
319       nyn_xa = nyna
320       nyn_x  = nyn
321       nny_x  = nny
322       IF ( MOD( nza , pdims(1) ) /= 0 )  THEN
323          IF ( myid == 0 )  THEN
324             PRINT*,'+++ transposition z --> x:'
325             PRINT*,'    nz=',nz,' is not an integral divisior of pdims(1)=', &
326                    &pdims(1)
327          ENDIF
328          CALL local_stop
329       ENDIF
330       nnz_x  = nza / pdims(1)
331       nzb_x  = 1 + myidx * nnz_x
332       nzt_xa = ( myidx + 1 ) * nnz_x
333       nzt_x  = MIN( nzt, nzt_xa )
334
335       sendrecvcount_zx = nnx * nny * nnz_x
336
337    ENDIF
338
339!
340!-- 2. transposition  x --> y
341    nnz_y  = nnz_x
342    nzb_y  = nzb_x
343    nzt_ya = nzt_xa
344    nzt_y  = nzt_x
345    IF ( MOD( nxa+1 , pdims(2) ) /= 0 )  THEN
346       IF ( myid == 0 )  THEN
347          PRINT*,'+++ transposition x --> y:'
348          PRINT*,'    nx+1=',nx+1,' is not an integral divisor of ',&
349                 &'pdims(2)=',pdims(2)
350       ENDIF
351       CALL local_stop
352    ENDIF
353    nnx_y = (nxa+1) / pdims(2)
354    nxl_y = myidy * nnx_y
355    nxr_ya = ( myidy + 1 ) * nnx_y - 1
356    nxr_y  = MIN( nx, nxr_ya )
357
358    sendrecvcount_xy = nnx_y * nny_x * nnz_y
359
360!
361!-- 3. transposition  y --> z  (ELSE:  x --> y  in case of 1D-decomposition
362!-- along x)
363    IF ( pdims(2) /= 1  .OR.  momentum_advec == 'ups-scheme'  .OR. &
364         scalar_advec == 'ups-scheme' )  THEN
365!
366!--    y --> z
367!--    This transposition is not neccessary in case of a 1d-decomposition
368!--    along x, except that the uptream-spline method is switched on
369       nnx_z  = nnx_y
370       nxl_z  = nxl_y
371       nxr_za = nxr_ya
372       nxr_z  = nxr_y
373       IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
374          IF ( myid == 0 )  THEN
375             PRINT*,'+++ Transposition y --> z:'
376             PRINT*,'    ny+1=',ny+1,' is not an integral divisor of ',&
377                    &'pdims(1)=',pdims(1)
378          ENDIF
379          CALL local_stop
380       ENDIF
381       nny_z  = (nya+1) / pdims(1)
382       nys_z  = myidx * nny_z
383       nyn_za = ( myidx + 1 ) * nny_z - 1
384       nyn_z  = MIN( ny, nyn_za )
385
386       sendrecvcount_yz = nnx_y * nny_z * nnz_y
387
388    ELSE
389!
390!--    x --> y. This condition must be fulfilled for a 1D-decomposition along x
391       IF ( MOD( nya+1 , pdims(1) ) /= 0 )  THEN
392          IF ( myid == 0 )  THEN
393             PRINT*,'+++ Transposition x --> y:'
394             PRINT*,'    ny+1=',ny+1,' is not an integral divisor of ',&
395                    &'pdims(1)=',pdims(1)
396          ENDIF
397          CALL local_stop
398       ENDIF
399
400    ENDIF
401
402!
403!-- Indices for direct transpositions z --> y (used for calculating spectra)
404    IF ( dt_dosp /= 9999999.9 )  THEN
405       IF ( MOD( nza, pdims(2) ) /= 0 )  THEN
406          IF ( myid == 0 )  THEN
407             PRINT*,'+++ Direct transposition z --> y (needed for spectra):'
408             PRINT*,'    nz=',nz,' is not an integral divisor of ',&
409                    &'pdims(2)=',pdims(2)
410          ENDIF
411          CALL local_stop
412       ELSE
413          nxl_yd  = nxl
414          nxr_yda = nxra
415          nxr_yd  = nxr
416          nzb_yd  = 1 + myidy * ( nza / pdims(2) )
417          nzt_yda = ( myidy + 1 ) * ( nza / pdims(2) )
418          nzt_yd  = MIN( nzt, nzt_yda )
419
420          sendrecvcount_zyd = nnx * nny * ( nza / pdims(2) )
421       ENDIF
422    ENDIF
423
424!
425!-- Indices for direct transpositions y --> x (they are only possible in case
426!-- of a 1d-decomposition along x)
427    IF ( pdims(2) == 1 )  THEN
428       nny_x  = nny / pdims(1)
429       nys_x  = myid * nny_x
430       nyn_xa = ( myid + 1 ) * nny_x - 1
431       nyn_x  = MIN( ny, nyn_xa )
432       nzb_x  = 1
433       nzt_xa = nza
434       nzt_x  = nz
435       sendrecvcount_xy = nnx * nny_x * nza
436    ENDIF
437
438!
439!-- Indices for direct transpositions x --> y (they are only possible in case
440!-- of a 1d-decomposition along y)
441    IF ( pdims(1) == 1 )  THEN
442       nnx_y  = nnx / pdims(2)
443       nxl_y  = myid * nnx_y
444       nxr_ya = ( myid + 1 ) * nnx_y - 1
445       nxr_y  = MIN( nx, nxr_ya )
446       nzb_y  = 1
447       nzt_ya = nza
448       nzt_y  = nz
449       sendrecvcount_xy = nnx_y * nny * nza
450    ENDIF
451
452!
453!-- Arrays for storing the array bounds are needed any more
454    DEALLOCATE( nxlf , nxrf , nynf , nysf )
455
456#if defined( __print )
457!
458!-- Control output
459    IF ( myid == 0 )  THEN
460       PRINT*, '*** processor topology ***'
461       PRINT*, ' '
462       PRINT*, 'myid   pcoord    left right  south north  idx idy   nxl: nxr',&
463               &'   nys: nyn'
464       PRINT*, '------------------------------------------------------------',&
465               &'-----------'
466       WRITE (*,1000)  0, pcoord(1), pcoord(2), pleft, pright, psouth, pnorth, &
467                       myidx, myidy, nxl, nxr, nys, nyn
4681000   FORMAT (I4,2X,'(',I3,',',I3,')',3X,I4,2X,I4,3X,I4,2X,I4,2X,I3,1X,I3, &
469               2(2X,I4,':',I4))
470
471!
472!--    Receive data from the other PEs
473       DO  i = 1,numprocs-1
474          CALL MPI_RECV( ibuf, 12, MPI_INTEGER, i, MPI_ANY_TAG, comm2d, status, &
475                         ierr )
476          WRITE (*,1000)  i, ( ibuf(j) , j = 1,12 )
477       ENDDO
478    ELSE
479
480!
481!--    Send data to PE0
482       ibuf(1) = pcoord(1); ibuf(2) = pcoord(2); ibuf(3) = pleft
483       ibuf(4) = pright; ibuf(5) = psouth; ibuf(6) = pnorth; ibuf(7) = myidx
484       ibuf(8) = myidy; ibuf(9) = nxl; ibuf(10) = nxr; ibuf(11) = nys
485       ibuf(12) = nyn
486       CALL MPI_SEND( ibuf, 12, MPI_INTEGER, 0, myid, comm2d, ierr )       
487    ENDIF
488#endif
489
490#if defined( __mpi2 )
491!
492!-- In case of coupled runs, get the port name on PE0 of the atmosphere model
493!-- and pass it to PE0 of the ocean model
494    IF ( myid == 0 )  THEN
495
496       IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
497
498          CALL MPI_OPEN_PORT( MPI_INFO_NULL, port_name, ierr )
499!
500!--       TEST OUTPUT (TO BE REMOVED)
501          WRITE(9,*)  TRIM( coupling_mode ),  &
502               ', ierr after MPI_OPEN_PORT: ', ierr
503          CALL LOCAL_FLUSH( 9 )
504
505          CALL MPI_PUBLISH_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, &
506                                 ierr )
507!
508!--       TEST OUTPUT (TO BE REMOVED)
509          WRITE(9,*)  TRIM( coupling_mode ),  &
510               ', ierr after MPI_PUBLISH_NAME: ', ierr
511          CALL LOCAL_FLUSH( 9 )
512
513!
514!--       Write a flag file for the ocean model and the other atmosphere
515!--       processes.
516!--       There seems to be a bug in MPICH2 which causes hanging processes
517!--       in case that execution of LOOKUP_NAME is continued too early
518!--       (i.e. before the port has been created)
519          OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
520          WRITE ( 90, '(''TRUE'')' )
521          CLOSE ( 90 )
522
523       ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
524
525!
526!--       Continue only if the atmosphere model has created the port.
527!--       There seems to be a bug in MPICH2 which causes hanging processes
528!--       in case that execution of LOOKUP_NAME is continued too early
529!--       (i.e. before the port has been created)
530          INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found )
531          DO WHILE ( .NOT. found )
532             INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found )
533          ENDDO
534
535          CALL MPI_LOOKUP_NAME( 'palm_coupler', MPI_INFO_NULL, port_name, ierr )
536!
537!--       TEST OUTPUT (TO BE REMOVED)
538          WRITE(9,*)  TRIM( coupling_mode ),  &
539               ', ierr after MPI_LOOKUP_NAME: ', ierr
540          CALL LOCAL_FLUSH( 9 )
541
542
543       ENDIF
544
545    ENDIF
546
547!
548!-- In case of coupled runs, establish the connection between the atmosphere
549!-- and the ocean model and define the intercommunicator (comm_inter)
550    CALL MPI_BARRIER( comm2d, ierr )
551    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
552
553       print*, '... before COMM_ACCEPT'
554       CALL MPI_COMM_ACCEPT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
555                             comm_inter, ierr )
556       print*, '--- ierr = ', ierr
557       print*, '--- comm_inter atmosphere = ', comm_inter
558
559       coupling_mode_remote = 'ocean_to_atmosphere'
560
561    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
562
563       IF ( myid == 0 )  PRINT*, '*** read: ', port_name, '  ierr = ', ierr
564       print*, '... before COMM_CONNECT'
565       CALL MPI_COMM_CONNECT( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &
566                              comm_inter, ierr )
567       print*, '--- ierr = ', ierr
568       print*, '--- comm_inter ocean      = ', comm_inter
569
570       coupling_mode_remote = 'atmosphere_to_ocean'
571
572    ENDIF
573
574!
575!-- In case of coupled runs, create a new MPI derived datatype for the
576!-- exchange of surface (xy) data .
577!-- Gridpoint number for the exchange of ghost points (xy-plane)
578    ngp_xy  = ( nxr - nxl + 3 ) * ( nyn - nys + 3 )
579
580!
581!-- Define a new MPI derived datatype for the exchange of ghost points in
582!-- y-direction for 2D-arrays (line)
583    CALL MPI_TYPE_VECTOR( ngp_xy, 1, nzt-nzb+2, MPI_REAL, type_xy, ierr )
584    CALL MPI_TYPE_COMMIT( type_xy, ierr )
585#endif
586
587#else
588
589!
590!-- Array bounds when running on a single PE (respectively a non-parallel
591!-- machine)
592    nxl  = 0
593    nxr  = nx
594    nxra = nx
595    nnx  = nxr - nxl + 1
596    nys  = 0
597    nyn  = ny
598    nyna = ny
599    nny  = nyn - nys + 1
600    nzb  = 0
601    nzt  = nz
602    nzta = nz
603    nnz  = nz
604
605!
606!-- Array bounds for the pressure solver (in the parallel code, these bounds
607!-- are the ones for the transposed arrays)
608    nys_x  = nys
609    nyn_x  = nyn
610    nyn_xa = nyn
611    nzb_x  = nzb + 1
612    nzt_x  = nzt
613    nzt_xa = nzt
614
615    nxl_y  = nxl
616    nxr_y  = nxr
617    nxr_ya = nxr
618    nzb_y  = nzb + 1
619    nzt_y  = nzt
620    nzt_ya = nzt
621
622    nxl_z  = nxl
623    nxr_z  = nxr
624    nxr_za = nxr
625    nys_z  = nys
626    nyn_z  = nyn
627    nyn_za = nyn
628
629#endif
630
631!
632!-- Calculate number of grid levels necessary for the multigrid poisson solver
633!-- as well as the gridpoint indices on each level
634    IF ( psolver == 'multigrid' )  THEN
635
636!
637!--    First calculate number of possible grid levels for the subdomains
638       mg_levels_x = 1
639       mg_levels_y = 1
640       mg_levels_z = 1
641
642       i = nnx
643       DO WHILE ( MOD( i, 2 ) == 0  .AND.  i /= 2 )
644          i = i / 2
645          mg_levels_x = mg_levels_x + 1
646       ENDDO
647
648       j = nny
649       DO WHILE ( MOD( j, 2 ) == 0  .AND.  j /= 2 )
650          j = j / 2
651          mg_levels_y = mg_levels_y + 1
652       ENDDO
653
654       k = nnz
655       DO WHILE ( MOD( k, 2 ) == 0  .AND.  k /= 2 )
656          k = k / 2
657          mg_levels_z = mg_levels_z + 1
658       ENDDO
659
660       maximum_grid_level = MIN( mg_levels_x, mg_levels_y, mg_levels_z )
661
662!
663!--    Find out, if the total domain allows more levels. These additional
664!--    levels are processed on PE0 only.
665       IF ( numprocs > 1 )  THEN
666          IF ( mg_levels_z > MIN( mg_levels_x, mg_levels_y ) )  THEN
667             mg_switch_to_pe0_level_l = maximum_grid_level
668
669             mg_levels_x = 1
670             mg_levels_y = 1
671
672             i = nx+1
673             DO WHILE ( MOD( i, 2 ) == 0  .AND.  i /= 2 )
674                i = i / 2
675                mg_levels_x = mg_levels_x + 1
676             ENDDO
677
678             j = ny+1
679             DO WHILE ( MOD( j, 2 ) == 0  .AND.  j /= 2 )
680                j = j / 2
681                mg_levels_y = mg_levels_y + 1
682             ENDDO
683
684             maximum_grid_level_l = MIN( mg_levels_x, mg_levels_y, mg_levels_z )
685
686             IF ( maximum_grid_level_l > mg_switch_to_pe0_level_l )  THEN
687                mg_switch_to_pe0_level_l = maximum_grid_level_l - &
688                                           mg_switch_to_pe0_level_l + 1
689             ELSE
690                mg_switch_to_pe0_level_l = 0
691             ENDIF
692          ELSE
693             mg_switch_to_pe0_level_l = 0
694             maximum_grid_level_l = maximum_grid_level
695          ENDIF
696
697!
698!--       Use switch level calculated above only if it is not pre-defined
699!--       by user
700          IF ( mg_switch_to_pe0_level == 0 )  THEN
701
702             IF ( mg_switch_to_pe0_level_l /= 0 )  THEN
703                mg_switch_to_pe0_level = mg_switch_to_pe0_level_l
704                maximum_grid_level     = maximum_grid_level_l
705             ENDIF
706
707          ELSE
708!
709!--          Check pre-defined value and reset to default, if neccessary
710             IF ( mg_switch_to_pe0_level < mg_switch_to_pe0_level_l  .OR.  &
711                  mg_switch_to_pe0_level >= maximum_grid_level_l )  THEN
712                IF ( myid == 0 )  THEN
713                   PRINT*, '+++ WARNING init_pegrid: mg_switch_to_pe0_level ', &
714                               'out of range and reset to default (=0)'
715                ENDIF
716                mg_switch_to_pe0_level = 0
717             ELSE
718!
719!--             Use the largest number of possible levels anyway and recalculate
720!--             the switch level to this largest number of possible values
721                maximum_grid_level = maximum_grid_level_l
722
723             ENDIF
724          ENDIF
725
726       ENDIF
727
728       ALLOCATE( grid_level_count(maximum_grid_level),                   &
729                 nxl_mg(maximum_grid_level), nxr_mg(maximum_grid_level), &
730                 nyn_mg(maximum_grid_level), nys_mg(maximum_grid_level), &
731                 nzt_mg(maximum_grid_level) )
732
733       grid_level_count = 0
734       nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzt_l = nzt
735
736       DO  i = maximum_grid_level, 1 , -1
737
738          IF ( i == mg_switch_to_pe0_level )  THEN
739#if defined( __parallel )
740!
741!--          Save the grid size of the subdomain at the switch level, because
742!--          it is needed in poismg.
743!--          Array bounds of the local subdomain grids are gathered on PE0
744             ind(1) = nxl_l; ind(2) = nxr_l
745             ind(3) = nys_l; ind(4) = nyn_l
746             ind(5) = nzt_l
747             ALLOCATE( ind_all(5*numprocs), mg_loc_ind(5,0:numprocs-1) )
748             CALL MPI_ALLGATHER( ind, 5, MPI_INTEGER, ind_all, 5, &
749                                 MPI_INTEGER, comm2d, ierr )
750             DO  j = 0, numprocs-1
751                DO  k = 1, 5
752                   mg_loc_ind(k,j) = ind_all(k+j*5)
753                ENDDO
754             ENDDO
755             DEALLOCATE( ind_all )
756!
757!--          Calculate the grid size of the total domain gathered on PE0
758             nxr_l = ( nxr_l-nxl_l+1 ) * pdims(1) - 1
759             nxl_l = 0
760             nyn_l = ( nyn_l-nys_l+1 ) * pdims(2) - 1
761             nys_l = 0
762!
763!--          The size of this gathered array must not be larger than the
764!--          array tend, which is used in the multigrid scheme as a temporary
765!--          array
766             subdomain_size = ( nxr - nxl + 3 )     * ( nyn - nys + 3 )     * &
767                              ( nzt - nzb + 2 )
768             gathered_size  = ( nxr_l - nxl_l + 3 ) * ( nyn_l - nys_l + 3 ) * &
769                              ( nzt_l - nzb + 2 )
770
771             IF ( gathered_size > subdomain_size )  THEN
772                IF ( myid == 0 )  THEN
773                   PRINT*, '+++ init_pegrid: not enough memory for storing ', &
774                               'gathered multigrid data on PE0'
775                ENDIF
776                CALL local_stop
777             ENDIF
778#else
779             PRINT*, '+++ init_pegrid: multigrid gather/scatter impossible ', &
780                          'in non parallel mode'
781             CALL local_stop
782#endif
783          ENDIF
784
785          nxl_mg(i) = nxl_l
786          nxr_mg(i) = nxr_l
787          nys_mg(i) = nys_l
788          nyn_mg(i) = nyn_l
789          nzt_mg(i) = nzt_l
790
791          nxl_l = nxl_l / 2 
792          nxr_l = nxr_l / 2
793          nys_l = nys_l / 2 
794          nyn_l = nyn_l / 2 
795          nzt_l = nzt_l / 2 
796       ENDDO
797
798    ELSE
799
800       maximum_grid_level = 1
801
802    ENDIF
803
804    grid_level = maximum_grid_level
805
806#if defined( __parallel )
807!
808!-- Gridpoint number for the exchange of ghost points (y-line for 2D-arrays)
809    ngp_y  = nyn - nys + 1
810
811!
812!-- Define a new MPI derived datatype for the exchange of ghost points in
813!-- y-direction for 2D-arrays (line)
814    CALL MPI_TYPE_VECTOR( nxr-nxl+3, 1, ngp_y+2, MPI_REAL, type_x, ierr )
815    CALL MPI_TYPE_COMMIT( type_x, ierr )
816    CALL MPI_TYPE_VECTOR( nxr-nxl+3, 1, ngp_y+2, MPI_INTEGER, type_x_int, ierr )
817    CALL MPI_TYPE_COMMIT( type_x_int, ierr )
818
819!
820!-- Calculate gridpoint numbers for the exchange of ghost points along x
821!-- (yz-plane for 3D-arrays) and define MPI derived data type(s) for the
822!-- exchange of ghost points in y-direction (xz-plane).
823!-- Do these calculations for the model grid and (if necessary) also
824!-- for the coarser grid levels used in the multigrid method
825    ALLOCATE ( ngp_yz(maximum_grid_level), type_xz(maximum_grid_level) )
826
827    nxl_l = nxl; nxr_l = nxr; nys_l = nys; nyn_l = nyn; nzb_l = nzb; nzt_l = nzt
828         
829    DO i = maximum_grid_level, 1 , -1
830       ngp_yz(i) = (nzt_l - nzb_l + 2) * (nyn_l - nys_l + 3)
831
832       CALL MPI_TYPE_VECTOR( nxr_l-nxl_l+3, nzt_l-nzb_l+2, ngp_yz(i), &
833                             MPI_REAL, type_xz(i), ierr )
834       CALL MPI_TYPE_COMMIT( type_xz(i), ierr )
835
836       nxl_l = nxl_l / 2 
837       nxr_l = nxr_l / 2
838       nys_l = nys_l / 2 
839       nyn_l = nyn_l / 2 
840       nzt_l = nzt_l / 2 
841    ENDDO
842#endif
843
844#if defined( __parallel )
845!
846!-- Setting of flags for inflow/outflow conditions in case of non-cyclic
847!-- horizontal boundary conditions.
848    IF ( pleft == MPI_PROC_NULL )  THEN
849       IF ( bc_lr == 'dirichlet/radiation' )  THEN
850          inflow_l  = .TRUE.
851       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
852          outflow_l = .TRUE.
853       ENDIF
854    ENDIF
855
856    IF ( pright == MPI_PROC_NULL )  THEN
857       IF ( bc_lr == 'dirichlet/radiation' )  THEN
858          outflow_r = .TRUE.
859       ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
860          inflow_r  = .TRUE.
861       ENDIF
862    ENDIF
863
864    IF ( psouth == MPI_PROC_NULL )  THEN
865       IF ( bc_ns == 'dirichlet/radiation' )  THEN
866          outflow_s = .TRUE.
867       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
868          inflow_s  = .TRUE.
869       ENDIF
870    ENDIF
871
872    IF ( pnorth == MPI_PROC_NULL )  THEN
873       IF ( bc_ns == 'dirichlet/radiation' )  THEN
874          inflow_n  = .TRUE.
875       ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
876          outflow_n = .TRUE.
877       ENDIF
878    ENDIF
879
880#else
881    IF ( bc_lr == 'dirichlet/radiation' )  THEN
882       inflow_l  = .TRUE.
883       outflow_r = .TRUE.
884    ELSEIF ( bc_lr == 'radiation/dirichlet' )  THEN
885       outflow_l = .TRUE.
886       inflow_r  = .TRUE.
887    ENDIF
888
889    IF ( bc_ns == 'dirichlet/radiation' )  THEN
890       inflow_n  = .TRUE.
891       outflow_s = .TRUE.
892    ELSEIF ( bc_ns == 'radiation/dirichlet' )  THEN
893       outflow_n = .TRUE.
894       inflow_s  = .TRUE.
895    ENDIF
896#endif
897!
898!-- At the outflow, u or v, respectively, have to be calculated for one more
899!-- grid point.
900    IF ( outflow_l )  THEN
901       nxlu = nxl + 1
902    ELSE
903       nxlu = nxl
904    ENDIF
905    IF ( outflow_s )  THEN
906       nysv = nys + 1
907    ELSE
908       nysv = nys
909    ENDIF
910
911    IF ( psolver == 'poisfft_hybrid' )  THEN
912       CALL poisfft_hybrid_ini
913    ELSEIF ( psolver == 'poisfft' )  THEN
914       CALL poisfft_init
915    ENDIF
916
917 END SUBROUTINE init_pegrid
Note: See TracBrowser for help on using the repository browser.