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

Last change on this file since 4180 was 4180, checked in by scharf, 22 months ago

removed comments in 'Former revisions' section that are older than 01.01.2019

  • Property svn:keywords set to Id
File size: 5.3 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 4180 2019-08-21 14:37:54Z scharf $
27! references to mrun replaced by palmrun, and updated
28!
29!
30! Description:
31! ------------
32!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
33!> called.
34!------------------------------------------------------------------------------!
35  SUBROUTINE init_coupling
36 
37
38    USE control_parameters,                                                    &
39        ONLY:  coupling_char, coupling_mode
40       
41    USE kinds
42   
43    USE pegrid
44
45    USE vertical_nesting_mod
46
47    IMPLICIT NONE
48
49!
50!-- Local variables
51    INTEGER(iwp) ::  i            !<
52    INTEGER(iwp) ::  inter_color  !<
53   
54    INTEGER(iwp), DIMENSION(:) ::  bc_data(0:3) = 0  !<
55
56!
57!-- Get information about the coupling mode from the environment variable
58!-- which has been set by the mpiexec command.
59!-- This method is currently not used because the mpiexec command is not
60!-- available on some machines
61!    CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i )
62!    IF ( i == 0 )  coupling_mode = 'uncoupled'
63!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
64
65!
66!-- Get information about the coupling mode from standard input (PE0 only) and
67!-- distribute it to the other PEs. Distribute PEs to 2 new communicators.
68!-- ATTENTION: numprocs will be reset according to the new communicators
69#if defined ( __parallel )
70
71    IF ( myid == 0 )  THEN
72       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
7310     CONTINUE
74       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
75          i = 1
76       ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' )  THEN
77          i = 9
78       ELSE
79          i = 0
80       ENDIF
81       bc_data(0) = i
82
83!
84!--    Check if '_O' has to be used as file extension in an uncoupled ocean
85!--    run. This is required, if this run shall be continued as a coupled run.
86       IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
87
88    ENDIF
89
90    CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
91    i = bc_data(0)
92
93    IF ( i == 0 )  THEN
94       coupling_mode = 'uncoupled'
95!
96!--    In case of a precursor ocean run, an additional flag file is created.
97!--    This is necessary for data_output_2d_on_each_pe = .T.
98       IF ( bc_data(3) == 1 )  THEN
99          OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' )
100          WRITE ( 90, '(''TRUE'')' )
101          CLOSE ( 90 )
102       ENDIF
103    ELSEIF ( i == 9 )  THEN
104
105!
106!--    Set a flag to identify runs with vertical nesting
107       vnested = .TRUE.
108       
109       comm_inter = MPI_COMM_WORLD
110       
111!
112!--    Split the total available PE's into two groups
113!--    numprocs for coarse and fine grid are read from stdin (see above, and
114!--    execution command in the palmrun script, numprocs are provided via
115!--    palmrun option -Y)
116       IF ( myid < bc_data(1) )  THEN
117          inter_color     = 0
118          numprocs        = bc_data(1)
119          coupling_mode   = 'vnested_crse'
120       ELSE
121          inter_color     = 1
122          numprocs        = bc_data(2)
123          coupling_mode   = 'vnested_fine'
124       ENDIF
125       
126       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
127       comm2d = comm_palm
128       
129       OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' )
130       WRITE ( 90, '(''TRUE'')' )
131       CLOSE ( 90 )
132     
133    ELSE
134       comm_inter = MPI_COMM_WORLD
135
136       IF ( myid < bc_data(1) ) THEN
137          inter_color     = 0
138          numprocs        = bc_data(1)
139          coupling_mode   = 'atmosphere_to_ocean'
140       ELSE
141          inter_color     = 1
142          numprocs        = bc_data(2)
143          coupling_mode   = 'ocean_to_atmosphere'
144       ENDIF
145
146       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
147       comm2d = comm_palm
148
149!
150!--    Write a flag file for the ocean model and the other atmosphere
151!--    processes.
152       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
153       WRITE ( 90, '(''TRUE'')' )
154       CLOSE ( 90 )
155    ENDIF
156#endif
157
158!
159!-- In case of a precursor ocean run (followed by a coupled run), or a
160!-- coupled atmosphere-ocean run, set the file extension for the ocean files
161    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
162    THEN
163       coupling_char = '_O'
164    ENDIF
165
166    IF (  TRIM( coupling_mode ) == 'vnested_fine' )  THEN
167!
168!-- Set file extension for vertical nesting
169       coupling_char = '_NV'
170    ENDIF
171
172 END SUBROUTINE init_coupling
Note: See TracBrowser for help on using the repository browser.