source: palm/trunk/SOURCE/init_coupling.f90 @ 4330

Last change on this file since 4330 was 4182, checked in by scharf, 5 years ago
  • corrected "Former revisions" section
  • minor formatting in "Former revisions" section
  • added "Author" section
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1!> @file init_coupling.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! ------------------
26! $Id: init_coupling.f90 4182 2019-08-22 15:20:23Z knoop $
27! Corrected "Former revisions" section
28!
29! 3655 2019-01-07 16:51:22Z knoop
30! references to mrun replaced by palmrun, and updated
31!
32! 222 2009-01-12 16:04:16Z letzel
33! Initial revision
34!
35! Description:
36! ------------
37!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
38!> called.
39!------------------------------------------------------------------------------!
40  SUBROUTINE init_coupling
41 
42
43    USE control_parameters,                                                    &
44        ONLY:  coupling_char, coupling_mode
45       
46    USE kinds
47   
48    USE pegrid
49
50    USE vertical_nesting_mod
51
52    IMPLICIT NONE
53
54!
55!-- Local variables
56    INTEGER(iwp) ::  i            !<
57    INTEGER(iwp) ::  inter_color  !<
58   
59    INTEGER(iwp), DIMENSION(:) ::  bc_data(0:3) = 0  !<
60
61!
62!-- Get information about the coupling mode from the environment variable
63!-- which has been set by the mpiexec command.
64!-- This method is currently not used because the mpiexec command is not
65!-- available on some machines
66!    CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i )
67!    IF ( i == 0 )  coupling_mode = 'uncoupled'
68!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
69
70!
71!-- Get information about the coupling mode from standard input (PE0 only) and
72!-- distribute it to the other PEs. Distribute PEs to 2 new communicators.
73!-- ATTENTION: numprocs will be reset according to the new communicators
74#if defined ( __parallel )
75
76    IF ( myid == 0 )  THEN
77       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
7810     CONTINUE
79       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
80          i = 1
81       ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' )  THEN
82          i = 9
83       ELSE
84          i = 0
85       ENDIF
86       bc_data(0) = i
87
88!
89!--    Check if '_O' has to be used as file extension in an uncoupled ocean
90!--    run. This is required, if this run shall be continued as a coupled run.
91       IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
92
93    ENDIF
94
95    CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
96    i = bc_data(0)
97
98    IF ( i == 0 )  THEN
99       coupling_mode = 'uncoupled'
100!
101!--    In case of a precursor ocean run, an additional flag file is created.
102!--    This is necessary for data_output_2d_on_each_pe = .T.
103       IF ( bc_data(3) == 1 )  THEN
104          OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' )
105          WRITE ( 90, '(''TRUE'')' )
106          CLOSE ( 90 )
107       ENDIF
108    ELSEIF ( i == 9 )  THEN
109
110!
111!--    Set a flag to identify runs with vertical nesting
112       vnested = .TRUE.
113       
114       comm_inter = MPI_COMM_WORLD
115       
116!
117!--    Split the total available PE's into two groups
118!--    numprocs for coarse and fine grid are read from stdin (see above, and
119!--    execution command in the palmrun script, numprocs are provided via
120!--    palmrun option -Y)
121       IF ( myid < bc_data(1) )  THEN
122          inter_color     = 0
123          numprocs        = bc_data(1)
124          coupling_mode   = 'vnested_crse'
125       ELSE
126          inter_color     = 1
127          numprocs        = bc_data(2)
128          coupling_mode   = 'vnested_fine'
129       ENDIF
130       
131       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
132       comm2d = comm_palm
133       
134       OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' )
135       WRITE ( 90, '(''TRUE'')' )
136       CLOSE ( 90 )
137     
138    ELSE
139       comm_inter = MPI_COMM_WORLD
140
141       IF ( myid < bc_data(1) ) THEN
142          inter_color     = 0
143          numprocs        = bc_data(1)
144          coupling_mode   = 'atmosphere_to_ocean'
145       ELSE
146          inter_color     = 1
147          numprocs        = bc_data(2)
148          coupling_mode   = 'ocean_to_atmosphere'
149       ENDIF
150
151       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
152       comm2d = comm_palm
153
154!
155!--    Write a flag file for the ocean model and the other atmosphere
156!--    processes.
157       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
158       WRITE ( 90, '(''TRUE'')' )
159       CLOSE ( 90 )
160    ENDIF
161#endif
162
163!
164!-- In case of a precursor ocean run (followed by a coupled run), or a
165!-- coupled atmosphere-ocean run, set the file extension for the ocean files
166    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
167    THEN
168       coupling_char = '_O'
169    ENDIF
170
171    IF (  TRIM( coupling_mode ) == 'vnested_fine' )  THEN
172!
173!-- Set file extension for vertical nesting
174       coupling_char = '_NV'
175    ENDIF
176
177 END SUBROUTINE init_coupling
Note: See TracBrowser for help on using the repository browser.