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

Last change on this file since 4631 was 4564, checked in by raasch, 4 years ago

Vertical nesting method of Huq et al. (2019) removed

  • Property svn:keywords set to Id
File size: 4.5 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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! ------------------
26! $Id: init_coupling.f90 4564 2020-06-12 14:03:36Z suehring $
27! Vertical nesting method of Huq et al. (2019) removed
28!
29! 4444 2020-03-05 15:59:50Z raasch
30! bugfix: cpp-directives for serial mode added
31!
32! 4360 2020-01-07 11:25:50Z suehring
33! Corrected "Former revisions" section
34!
35! 3655 2019-01-07 16:51:22Z knoop
36! references to mrun replaced by palmrun, and updated
37!
38! 222 2009-01-12 16:04:16Z letzel
39! Initial revision
40!
41! Description:
42! ------------
43!> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is
44!> called.
45!------------------------------------------------------------------------------!
46  SUBROUTINE init_coupling
47 
48
49    USE control_parameters,                                                    &
50        ONLY:  coupling_char, coupling_mode
51       
52    USE kinds
53   
54    USE pegrid
55
56    IMPLICIT NONE
57
58!
59!-- Local variables
60#if defined( __parallel )
61    INTEGER(iwp) ::  i            !<
62    INTEGER(iwp) ::  inter_color  !<
63#endif
64   
65    INTEGER(iwp), DIMENSION(:) ::  bc_data(0:3) = 0  !<
66
67!
68!-- Get information about the coupling mode from the environment variable
69!-- which has been set by the mpiexec command.
70!-- This method is currently not used because the mpiexec command is not
71!-- available on some machines
72!    CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i )
73!    IF ( i == 0 )  coupling_mode = 'uncoupled'
74!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
75
76!
77!-- Get information about the coupling mode from standard input (PE0 only) and
78!-- distribute it to the other PEs. Distribute PEs to 2 new communicators.
79!-- ATTENTION: numprocs will be reset according to the new communicators
80#if defined ( __parallel )
81
82    IF ( myid == 0 )  THEN
83       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
8410     CONTINUE
85       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
86          i = 1
87       ELSE
88          i = 0
89       ENDIF
90       bc_data(0) = i
91
92!
93!--    Check if '_O' has to be used as file extension in an uncoupled ocean
94!--    run. This is required, if this run shall be continued as a coupled run.
95       IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
96
97    ENDIF
98
99    CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
100    i = bc_data(0)
101
102    IF ( i == 0 )  THEN
103       coupling_mode = 'uncoupled'
104!
105!--    In case of a precursor ocean run, an additional flag file is created.
106!--    This is necessary for data_output_2d_on_each_pe = .T.
107       IF ( bc_data(3) == 1 )  THEN
108          OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' )
109          WRITE ( 90, '(''TRUE'')' )
110          CLOSE ( 90 )
111       ENDIF
112    ELSE
113       comm_inter = MPI_COMM_WORLD
114
115       IF ( myid < bc_data(1) ) THEN
116          inter_color     = 0
117          numprocs        = bc_data(1)
118          coupling_mode   = 'atmosphere_to_ocean'
119       ELSE
120          inter_color     = 1
121          numprocs        = bc_data(2)
122          coupling_mode   = 'ocean_to_atmosphere'
123       ENDIF
124
125       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
126       comm2d = comm_palm
127
128!
129!--    Write a flag file for the ocean model and the other atmosphere
130!--    processes.
131       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
132       WRITE ( 90, '(''TRUE'')' )
133       CLOSE ( 90 )
134    ENDIF
135#endif
136
137!
138!-- In case of a precursor ocean run (followed by a coupled run), or a
139!-- coupled atmosphere-ocean run, set the file extension for the ocean files
140    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
141    THEN
142       coupling_char = '_O'
143    ENDIF
144
145 END SUBROUTINE init_coupling
Note: See TracBrowser for help on using the repository browser.