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

Last change on this file since 3887 was 3655, checked in by knoop, 5 years ago

Bugfix: made "unit" and "found" intend INOUT in module interface subroutines + automatic copyright update

  • Property svn:keywords set to Id
File size: 6.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 3655 2019-01-07 16:51:22Z schwenkel $
27! references to mrun replaced by palmrun, and updated
28!
29! 2718 2018-01-02 08:49:38Z maronga
30! Corrected "Former revisions" section
31!
32! 2696 2017-12-14 17:12:51Z kanani
33! Change in file header (GPL part)
34!
35! 2669 2017-12-06 16:03:27Z raasch
36! file extension for vertical nesting changed to "_NV"
37!
38! 2365 2017-08-21 14:59:59Z kanani
39! Vertical nesting implemented (SadiqHuq)
40!
41! 2298 2017-06-29 09:28:18Z raasch
42! MPI2 coupling removed
43!
44! 2101 2017-01-05 16:42:31Z suehring
45!
46! 2000 2016-08-20 18:09:15Z knoop
47! Forced header and separation lines into 80 columns
48!
49! 1808 2016-04-05 19:44:00Z raasch
50! routine local_getenv replaced by standard FORTRAN routine
51!
52! 1682 2015-10-07 23:56:08Z knoop
53! Code annotations made doxygen readable
54!
55! 1320 2014-03-20 08:40:49Z raasch
56! ONLY-attribute added to USE-statements,
57! kind-parameters added to all INTEGER and REAL declaration statements,
58! kinds are defined in new module kinds,
59! revision history before 2012 removed,
60! comment fields (!:) to be used for variable explanations added to
61! all variable declaration statements
62!
63! 1036 2012-10-22 13:43:42Z raasch
64! code put under GPL (PALM 3.9)
65!
66! 222 2009-01-12 16:04:16Z letzel
67! Initial revision
68!
69! Description:
70! ------------
71!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
72!> called.
73!------------------------------------------------------------------------------!
74  SUBROUTINE init_coupling
75 
76
77    USE control_parameters,                                                    &
78        ONLY:  coupling_char, coupling_mode
79       
80    USE kinds
81   
82    USE pegrid
83
84    USE vertical_nesting_mod
85
86    IMPLICIT NONE
87
88!
89!-- Local variables
90    INTEGER(iwp) ::  i            !<
91    INTEGER(iwp) ::  inter_color  !<
92   
93    INTEGER(iwp), DIMENSION(:) ::  bc_data(0:3) = 0  !<
94
95!
96!-- Get information about the coupling mode from the environment variable
97!-- which has been set by the mpiexec command.
98!-- This method is currently not used because the mpiexec command is not
99!-- available on some machines
100!    CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i )
101!    IF ( i == 0 )  coupling_mode = 'uncoupled'
102!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
103
104!
105!-- Get information about the coupling mode from standard input (PE0 only) and
106!-- distribute it to the other PEs. Distribute PEs to 2 new communicators.
107!-- ATTENTION: numprocs will be reset according to the new communicators
108#if defined ( __parallel )
109
110    IF ( myid == 0 )  THEN
111       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
11210     CONTINUE
113       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
114          i = 1
115       ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' )  THEN
116          i = 9
117       ELSE
118          i = 0
119       ENDIF
120       bc_data(0) = i
121
122!
123!--    Check if '_O' has to be used as file extension in an uncoupled ocean
124!--    run. This is required, if this run shall be continued as a coupled run.
125       IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
126
127    ENDIF
128
129    CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
130    i = bc_data(0)
131
132    IF ( i == 0 )  THEN
133       coupling_mode = 'uncoupled'
134!
135!--    In case of a precursor ocean run, an additional flag file is created.
136!--    This is necessary for data_output_2d_on_each_pe = .T.
137       IF ( bc_data(3) == 1 )  THEN
138          OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' )
139          WRITE ( 90, '(''TRUE'')' )
140          CLOSE ( 90 )
141       ENDIF
142    ELSEIF ( i == 9 )  THEN
143
144!
145!--    Set a flag to identify runs with vertical nesting
146       vnested = .TRUE.
147       
148       comm_inter = MPI_COMM_WORLD
149       
150!
151!--    Split the total available PE's into two groups
152!--    numprocs for coarse and fine grid are read from stdin (see above, and
153!--    execution command in the palmrun script, numprocs are provided via
154!--    palmrun option -Y)
155       IF ( myid < bc_data(1) )  THEN
156          inter_color     = 0
157          numprocs        = bc_data(1)
158          coupling_mode   = 'vnested_crse'
159       ELSE
160          inter_color     = 1
161          numprocs        = bc_data(2)
162          coupling_mode   = 'vnested_fine'
163       ENDIF
164       
165       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
166       comm2d = comm_palm
167       
168       OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' )
169       WRITE ( 90, '(''TRUE'')' )
170       CLOSE ( 90 )
171     
172    ELSE
173       comm_inter = MPI_COMM_WORLD
174
175       IF ( myid < bc_data(1) ) THEN
176          inter_color     = 0
177          numprocs        = bc_data(1)
178          coupling_mode   = 'atmosphere_to_ocean'
179       ELSE
180          inter_color     = 1
181          numprocs        = bc_data(2)
182          coupling_mode   = 'ocean_to_atmosphere'
183       ENDIF
184
185       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
186       comm2d = comm_palm
187
188!
189!--    Write a flag file for the ocean model and the other atmosphere
190!--    processes.
191       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
192       WRITE ( 90, '(''TRUE'')' )
193       CLOSE ( 90 )
194    ENDIF
195#endif
196
197!
198!-- In case of a precursor ocean run (followed by a coupled run), or a
199!-- coupled atmosphere-ocean run, set the file extension for the ocean files
200    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
201    THEN
202       coupling_char = '_O'
203    ENDIF
204
205    IF (  TRIM( coupling_mode ) == 'vnested_fine' )  THEN
206!
207!-- Set file extension for vertical nesting
208       coupling_char = '_NV'
209    ENDIF
210
211 END SUBROUTINE init_coupling
Note: See TracBrowser for help on using the repository browser.