source: palm/trunk/SOURCE/surface_coupler.f90 @ 268

Last change on this file since 268 was 258, checked in by heinze, 16 years ago

Output of messages replaced by message handling routine.

  • Property svn:keywords set to Id
File size: 6.7 KB
RevLine 
[102]1 SUBROUTINE surface_coupler
2
3!------------------------------------------------------------------------------!
[258]4! Current revisions:
[102]5! -----------------
[258]6! Output of messages replaced by message handling routine.
[102]7!
[258]8!
[102]9! Former revisions:
10! ------------------
11! $Id: surface_coupler.f90 258 2009-03-13 12:36:03Z letzel $
12!
[226]13! 206 2008-10-13 14:59:11Z raasch
14! Implementation of a MPI-1 Coupling: replaced myid with target_id,
15! deleted __mpi2 directives
16!
[110]17! 109 2007-08-28 15:26:47Z letzel
[102]18! Initial revision
19!
20! Description:
21! ------------
22! Data exchange at the interface between coupled models
23!------------------------------------------------------------------------------!
24
25    USE arrays_3d
26    USE control_parameters
27    USE cpulog
28    USE grid_variables
29    USE indices
30    USE interfaces
31    USE pegrid
32
33    IMPLICIT NONE
34
[108]35    INTEGER ::  i, j, k
[102]36
37    REAL    ::  simulated_time_remote
38
[206]39#if defined( __parallel )
[102]40
[206]41       CALL cpu_log( log_point(39), 'surface_coupler', 'start' )
[102]42
43!
[108]44!-- In case of model termination initiated by the remote model
45!-- (terminate_coupled_remote > 0), initiate termination of the local model.
46!-- The rest of the coupler must then be skipped because it would cause an MPI
47!-- intercomminucation hang.
48!-- If necessary, the coupler will be called at the beginning of the next
49!-- restart run.
[206]50    CALL MPI_SENDRECV( terminate_coupled,        1, MPI_INTEGER, target_id,  &
51                       0, &
52                       terminate_coupled_remote, 1, MPI_INTEGER, target_id,  &
53                       0, comm_inter, status, ierr )
[108]54    IF ( terminate_coupled_remote > 0 )  THEN
[258]55       WRITE( message_string, * ) 'remote model "', TRIM( coupling_mode_remote ), &
56                                  '" terminated',                                 &
57                                  '&with terminate_coupled_remote = ',            &
58                                  terminate_coupled_remote,                       &
59                                  '&local model  "', TRIM( coupling_mode ),       &
60                                  '" has',                                        &
61                                  '&terminate_coupled = ',                        &
62                                  terminate_coupled
63       CALL message( 'surface_coupler', 'PA0310', 1, 2, 0, 6, 0 )
[108]64       RETURN
65    ENDIF
66!
67!-- Exchange the current simulated time between the models,
[102]68!-- currently just for testing
[206]69    CALL MPI_SEND( simulated_time, 1, MPI_REAL, target_id, 11, &
70                   comm_inter, ierr )
71    CALL MPI_RECV( simulated_time_remote, 1, MPI_REAL, target_id, 11, &
[102]72                   comm_inter, status, ierr )
73    WRITE ( 9, * )  simulated_time, ' remote: ', simulated_time_remote
74    CALL local_flush( 9 )
75
76!
77!-- Exchange the interface data
78    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
79
80!
81!--    Send heat flux at bottom surface to the ocean model
82       WRITE ( 9, * )  '*** send shf to ocean'
83       CALL local_flush( 9 )
[206]84       CALL MPI_SEND( shf(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 12, &
[102]85                      comm_inter, ierr )
86
87!
[108]88!--    Send humidity flux at bottom surface to the ocean model
89       IF ( humidity )  THEN
90          WRITE ( 9, * )  '*** send qsws to ocean'
91          CALL local_flush( 9 )
[206]92          CALL MPI_SEND( qsws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 13, &
[108]93               comm_inter, ierr )
94       ENDIF
95
96!
[102]97!--    Receive temperature at the bottom surface from the ocean model
98       WRITE ( 9, * )  '*** receive pt from ocean'
99       CALL local_flush( 9 )
[206]100       CALL MPI_RECV( pt(0,nys-1,nxl-1), 1, type_xy, target_id, 14, &
101                      comm_inter, status, ierr )
[102]102
103!
104!--    Send the momentum flux (u) at bottom surface to the ocean model
105       WRITE ( 9, * )  '*** send usws to ocean'
106       CALL local_flush( 9 )
[206]107       CALL MPI_SEND( usws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 15, &
[102]108                      comm_inter, ierr )
109
110!
111!--    Send the momentum flux (v) at bottom surface to the ocean model
112       WRITE ( 9, * )  '*** send vsws to ocean'
113       CALL local_flush( 9 )
[206]114       CALL MPI_SEND( vsws(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 16, &
[102]115                      comm_inter, ierr )
116
117    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
118
119!
120!--    Receive heat flux at the sea surface (top) from the atmosphere model
121       WRITE ( 9, * )  '*** receive tswst from atmosphere'
122       CALL local_flush( 9 )
[206]123       CALL MPI_RECV( tswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 12, &
[102]124                      comm_inter, status, ierr )
125
126!
[108]127!--    Receive humidity flux from the atmosphere model (bottom)
128!--    and add it to the heat flux at the sea surface (top)...
129       IF ( humidity_remote )  THEN
130          WRITE ( 9, * )  '*** receive qswst_remote from atmosphere'
131          CALL local_flush( 9 )
[206]132          CALL MPI_RECV( qswst_remote(nys-1,nxl-1), ngp_xy, MPI_REAL, &
133                         target_id, 13, comm_inter, status, ierr )
[108]134
[109]135          !here tswst is still the sum of atmospheric bottom heat fluxes
136          tswst = tswst + qswst_remote * 2.2626108e6 / 1005.0
137          !*latent heat of vaporization in m2/s2, or 540 cal/g, or 40.65 kJ/mol
138          !/(rho_atm(=1.0)*c_p)
[108]139!
140!--    ...and convert it to a salinity flux at the sea surface (top)
141!--       following Steinhorn (1991), JPO 21, pp. 1681-1683:
142!--       S'w' = -S * evaporation / ( rho_water * ( 1 - S ) )
143          saswst = -1.0 * sa(nzt,:,:) * qswst_remote /  &
144               ( rho(nzt,:,:) * ( 1.0 - sa(nzt,:,:) ) )
145       ENDIF
146
147!
[102]148!--    Adjust the kinematic heat flux with respect to ocean density
149!--    (constants are the specific heat capacities for air and water)
[109]150       !now tswst is the ocean top heat flux
[108]151       tswst = tswst / rho(nzt,:,:) * 1005.0 / 4218.0
[102]152
153!
154!--    Send sea surface temperature to the atmosphere model
155       WRITE ( 9, * )  '*** send pt to atmosphere'
156       CALL local_flush( 9 )
[206]157       CALL MPI_SEND( pt(nzt,nys-1,nxl-1), 1, type_xy, target_id, 14, &
158                      comm_inter, ierr )
[102]159
160!
161!--    Receive momentum flux (u) at the sea surface (top) from the atmosphere
162!--    model
163       WRITE ( 9, * )  '*** receive uswst from atmosphere'
164       CALL local_flush( 9 )
[206]165       CALL MPI_RECV( uswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 15, &
[102]166                      comm_inter, status, ierr )
167
168!
169!--    Receive momentum flux (v) at the sea surface (top) from the atmosphere
170!--    model
171       WRITE ( 9, * )  '*** receive vswst from atmosphere'
172       CALL local_flush( 9 )
[206]173       CALL MPI_RECV( vswst(nys-1,nxl-1), ngp_xy, MPI_REAL, target_id, 16, &
[102]174                      comm_inter, status, ierr )
175
176!
177!--    Adjust the momentum fluxes with respect to ocean density
[108]178       uswst = uswst / rho(nzt,:,:)
179       vswst = vswst / rho(nzt,:,:)
[102]180
181    ENDIF
182
183    CALL cpu_log( log_point(39), 'surface_coupler', 'stop' )
184
185#endif
186
187 END SUBROUTINE surface_coupler
Note: See TracBrowser for help on using the repository browser.