1 | SUBROUTINE surface_coupler |
---|
2 | |
---|
3 | !--------------------------------------------------------------------------------! |
---|
4 | ! This file is part of PALM. |
---|
5 | ! |
---|
6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | ! either version 3 of the License, or (at your option) any later 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-2012 Leibniz University Hannover |
---|
18 | !--------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ------------------ |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: surface_coupler.f90 1093 2013-02-02 12:58:49Z moh.hefny $ |
---|
27 | ! |
---|
28 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
29 | ! unused variables removed |
---|
30 | ! |
---|
31 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
32 | ! code put under GPL (PALM 3.9) |
---|
33 | ! |
---|
34 | ! 880 2012-04-13 06:28:59Z raasch |
---|
35 | ! Bugfix: preprocessor statements for parallel execution added |
---|
36 | ! |
---|
37 | ! 709 2011-03-30 09:31:40Z raasch |
---|
38 | ! formatting adjustments |
---|
39 | ! |
---|
40 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
41 | ! Additional case for nonequivalent processor and grid topopolgy in ocean and |
---|
42 | ! atmosphere added (coupling_topology = 1). |
---|
43 | ! Added exchange of u and v from Ocean to Atmosphere |
---|
44 | ! |
---|
45 | ! 291 2009-04-16 12:07:26Z raasch |
---|
46 | ! Coupling with independent precursor runs. |
---|
47 | ! Output of messages replaced by message handling routine. |
---|
48 | ! |
---|
49 | ! 206 2008-10-13 14:59:11Z raasch |
---|
50 | ! Implementation of a MPI-1 Coupling: replaced myid with target_id, |
---|
51 | ! deleted __mpi2 directives |
---|
52 | ! |
---|
53 | ! 109 2007-08-28 15:26:47Z letzel |
---|
54 | ! Initial revision |
---|
55 | ! |
---|
56 | ! Description: |
---|
57 | ! ------------ |
---|
58 | ! Data exchange at the interface between coupled models |
---|
59 | !------------------------------------------------------------------------------! |
---|
60 | |
---|
61 | USE arrays_3d |
---|
62 | USE control_parameters |
---|
63 | USE cpulog |
---|
64 | USE grid_variables |
---|
65 | USE indices |
---|
66 | USE interfaces |
---|
67 | USE pegrid |
---|
68 | |
---|
69 | IMPLICIT NONE |
---|
70 | |
---|
71 | REAL :: time_since_reference_point_rem |
---|
72 | REAL :: total_2d(-nbgp:ny+nbgp,-nbgp:nx+nbgp) |
---|
73 | |
---|
74 | #if defined( __parallel ) |
---|
75 | |
---|
76 | CALL cpu_log( log_point(39), 'surface_coupler', 'start' ) |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | ! |
---|
81 | !-- In case of model termination initiated by the remote model |
---|
82 | !-- (terminate_coupled_remote > 0), initiate termination of the local model. |
---|
83 | !-- The rest of the coupler must then be skipped because it would cause an MPI |
---|
84 | !-- intercomminucation hang. |
---|
85 | !-- If necessary, the coupler will be called at the beginning of the next |
---|
86 | !-- restart run. |
---|
87 | |
---|
88 | IF ( coupling_topology == 0 ) THEN |
---|
89 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, target_id, & |
---|
90 | 0, & |
---|
91 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, & |
---|
92 | 0, comm_inter, status, ierr ) |
---|
93 | ELSE |
---|
94 | IF ( myid == 0) THEN |
---|
95 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
96 | target_id, 0, & |
---|
97 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
98 | target_id, 0, & |
---|
99 | comm_inter, status, ierr ) |
---|
100 | ENDIF |
---|
101 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
102 | ierr ) |
---|
103 | |
---|
104 | ALLOCATE( total_2d_a(-nbgp:ny_a+nbgp,-nbgp:nx_a+nbgp), & |
---|
105 | total_2d_o(-nbgp:ny_o+nbgp,-nbgp:nx_o+nbgp) ) |
---|
106 | |
---|
107 | ENDIF |
---|
108 | |
---|
109 | IF ( terminate_coupled_remote > 0 ) THEN |
---|
110 | WRITE( message_string, * ) 'remote model "', & |
---|
111 | TRIM( coupling_mode_remote ), & |
---|
112 | '" terminated', & |
---|
113 | '&with terminate_coupled_remote = ', & |
---|
114 | terminate_coupled_remote, & |
---|
115 | '&local model "', TRIM( coupling_mode ), & |
---|
116 | '" has', & |
---|
117 | '&terminate_coupled = ', & |
---|
118 | terminate_coupled |
---|
119 | CALL message( 'surface_coupler', 'PA0310', 1, 2, 0, 6, 0 ) |
---|
120 | RETURN |
---|
121 | ENDIF |
---|
122 | |
---|
123 | |
---|
124 | ! |
---|
125 | !-- Exchange the current simulated time between the models, |
---|
126 | !-- currently just for total_2ding |
---|
127 | IF ( coupling_topology == 0 ) THEN |
---|
128 | |
---|
129 | CALL MPI_SEND( time_since_reference_point, 1, MPI_REAL, target_id, 11, & |
---|
130 | comm_inter, ierr ) |
---|
131 | CALL MPI_RECV( time_since_reference_point_rem, 1, MPI_REAL, target_id, & |
---|
132 | 11, comm_inter, status, ierr ) |
---|
133 | ELSE |
---|
134 | |
---|
135 | IF ( myid == 0 ) THEN |
---|
136 | |
---|
137 | CALL MPI_SEND( time_since_reference_point, 1, MPI_REAL, target_id, & |
---|
138 | 11, comm_inter, ierr ) |
---|
139 | CALL MPI_RECV( time_since_reference_point_rem, 1, MPI_REAL, & |
---|
140 | target_id, 11, comm_inter, status, ierr ) |
---|
141 | |
---|
142 | ENDIF |
---|
143 | |
---|
144 | CALL MPI_BCAST( time_since_reference_point_rem, 1, MPI_REAL, 0, comm2d, & |
---|
145 | ierr ) |
---|
146 | |
---|
147 | ENDIF |
---|
148 | |
---|
149 | ! |
---|
150 | !-- Exchange the interface data |
---|
151 | IF ( coupling_mode == 'atmosphere_to_ocean' ) THEN |
---|
152 | |
---|
153 | ! |
---|
154 | !-- Horizontal grid size and number of processors is equal in ocean and |
---|
155 | !-- atmosphere |
---|
156 | IF ( coupling_topology == 0 ) THEN |
---|
157 | |
---|
158 | ! |
---|
159 | !-- Send heat flux at bottom surface to the ocean |
---|
160 | CALL MPI_SEND( shf(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 12, & |
---|
161 | comm_inter, ierr ) |
---|
162 | ! |
---|
163 | !-- Send humidity flux at bottom surface to the ocean |
---|
164 | IF ( humidity ) THEN |
---|
165 | CALL MPI_SEND( qsws(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 13, & |
---|
166 | comm_inter, ierr ) |
---|
167 | ENDIF |
---|
168 | ! |
---|
169 | !-- Receive temperature at the bottom surface from the ocean |
---|
170 | CALL MPI_RECV( pt(0,nysg,nxlg), 1, type_xy, target_id, 14, & |
---|
171 | comm_inter, status, ierr ) |
---|
172 | ! |
---|
173 | !-- Send the momentum flux (u) at bottom surface to the ocean |
---|
174 | CALL MPI_SEND( usws(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 15, & |
---|
175 | comm_inter, ierr ) |
---|
176 | ! |
---|
177 | !-- Send the momentum flux (v) at bottom surface to the ocean |
---|
178 | CALL MPI_SEND( vsws(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 16, & |
---|
179 | comm_inter, ierr ) |
---|
180 | ! |
---|
181 | !-- Receive u at the bottom surface from the ocean |
---|
182 | CALL MPI_RECV( u(0,nysg,nxlg), 1, type_xy, target_id, 17, & |
---|
183 | comm_inter, status, ierr ) |
---|
184 | ! |
---|
185 | !-- Receive v at the bottom surface from the ocean |
---|
186 | CALL MPI_RECV( v(0,nysg,nxlg), 1, type_xy, target_id, 18, & |
---|
187 | comm_inter, status, ierr ) |
---|
188 | ! |
---|
189 | !-- Horizontal grid size or number of processors differs between |
---|
190 | !-- ocean and atmosphere |
---|
191 | ELSE |
---|
192 | |
---|
193 | ! |
---|
194 | !-- Send heat flux at bottom surface to the ocean |
---|
195 | total_2d_a = 0.0 |
---|
196 | total_2d = 0.0 |
---|
197 | total_2d(nys:nyn,nxl:nxr) = shf(nys:nyn,nxl:nxr) |
---|
198 | |
---|
199 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
200 | comm2d, ierr ) |
---|
201 | CALL interpolate_to_ocean( 12 ) |
---|
202 | ! |
---|
203 | !-- Send humidity flux at bottom surface to the ocean |
---|
204 | IF ( humidity ) THEN |
---|
205 | total_2d_a = 0.0 |
---|
206 | total_2d = 0.0 |
---|
207 | total_2d(nys:nyn,nxl:nxr) = qsws(nys:nyn,nxl:nxr) |
---|
208 | |
---|
209 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, & |
---|
210 | 0, comm2d, ierr ) |
---|
211 | CALL interpolate_to_ocean( 13 ) |
---|
212 | ENDIF |
---|
213 | ! |
---|
214 | !-- Receive temperature at the bottom surface from the ocean |
---|
215 | IF ( myid == 0 ) THEN |
---|
216 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
217 | target_id, 14, comm_inter, status, ierr ) |
---|
218 | ENDIF |
---|
219 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
220 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
221 | ierr ) |
---|
222 | pt(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
223 | ! |
---|
224 | !-- Send momentum flux (u) at bottom surface to the ocean |
---|
225 | total_2d_a = 0.0 |
---|
226 | total_2d = 0.0 |
---|
227 | total_2d(nys:nyn,nxl:nxr) = usws(nys:nyn,nxl:nxr) |
---|
228 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
229 | comm2d, ierr ) |
---|
230 | CALL interpolate_to_ocean( 15 ) |
---|
231 | ! |
---|
232 | !-- Send momentum flux (v) at bottom surface to the ocean |
---|
233 | total_2d_a = 0.0 |
---|
234 | total_2d = 0.0 |
---|
235 | total_2d(nys:nyn,nxl:nxr) = vsws(nys:nyn,nxl:nxr) |
---|
236 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
237 | comm2d, ierr ) |
---|
238 | CALL interpolate_to_ocean( 16 ) |
---|
239 | ! |
---|
240 | !-- Receive u at the bottom surface from the ocean |
---|
241 | IF ( myid == 0 ) THEN |
---|
242 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
243 | target_id, 17, comm_inter, status, ierr ) |
---|
244 | ENDIF |
---|
245 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
246 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
247 | ierr ) |
---|
248 | u(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
249 | ! |
---|
250 | !-- Receive v at the bottom surface from the ocean |
---|
251 | IF ( myid == 0 ) THEN |
---|
252 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
253 | target_id, 18, comm_inter, status, ierr ) |
---|
254 | ENDIF |
---|
255 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
256 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
257 | ierr ) |
---|
258 | v(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
259 | |
---|
260 | ENDIF |
---|
261 | |
---|
262 | ELSEIF ( coupling_mode == 'ocean_to_atmosphere' ) THEN |
---|
263 | |
---|
264 | ! |
---|
265 | !-- Horizontal grid size and number of processors is equal |
---|
266 | !-- in ocean and atmosphere |
---|
267 | IF ( coupling_topology == 0 ) THEN |
---|
268 | ! |
---|
269 | !-- Receive heat flux at the sea surface (top) from the atmosphere |
---|
270 | CALL MPI_RECV( tswst(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 12, & |
---|
271 | comm_inter, status, ierr ) |
---|
272 | ! |
---|
273 | !-- Receive humidity flux from the atmosphere (bottom) |
---|
274 | !-- and add it to the heat flux at the sea surface (top)... |
---|
275 | IF ( humidity_remote ) THEN |
---|
276 | CALL MPI_RECV( qswst_remote(nysg,nxlg), ngp_xy, MPI_REAL, & |
---|
277 | target_id, 13, comm_inter, status, ierr ) |
---|
278 | ENDIF |
---|
279 | ! |
---|
280 | !-- Send sea surface temperature to the atmosphere model |
---|
281 | CALL MPI_SEND( pt(nzt,nysg,nxlg), 1, type_xy, target_id, 14, & |
---|
282 | comm_inter, ierr ) |
---|
283 | ! |
---|
284 | !-- Receive momentum flux (u) at the sea surface (top) from the atmosphere |
---|
285 | CALL MPI_RECV( uswst(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 15, & |
---|
286 | comm_inter, status, ierr ) |
---|
287 | ! |
---|
288 | !-- Receive momentum flux (v) at the sea surface (top) from the atmosphere |
---|
289 | CALL MPI_RECV( vswst(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 16, & |
---|
290 | comm_inter, status, ierr ) |
---|
291 | ! |
---|
292 | !-- Send u to the atmosphere |
---|
293 | CALL MPI_SEND( u(nzt,nysg,nxlg), 1, type_xy, target_id, 17, & |
---|
294 | comm_inter, ierr ) |
---|
295 | ! |
---|
296 | !-- Send v to the atmosphere |
---|
297 | CALL MPI_SEND( v(nzt,nysg,nxlg), 1, type_xy, target_id, 18, & |
---|
298 | comm_inter, ierr ) |
---|
299 | ! |
---|
300 | !-- Horizontal gridsize or number of processors differs between |
---|
301 | !-- ocean and atmosphere |
---|
302 | ELSE |
---|
303 | ! |
---|
304 | !-- Receive heat flux at the sea surface (top) from the atmosphere |
---|
305 | IF ( myid == 0 ) THEN |
---|
306 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
307 | target_id, 12, comm_inter, status, ierr ) |
---|
308 | ENDIF |
---|
309 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
310 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, comm2d, & |
---|
311 | ierr ) |
---|
312 | tswst(nysg:nyng,nxlg:nxrg) = total_2d_o(nysg:nyng,nxlg:nxrg) |
---|
313 | ! |
---|
314 | !-- Receive humidity flux at the sea surface (top) from the atmosphere |
---|
315 | IF ( humidity_remote ) THEN |
---|
316 | IF ( myid == 0 ) THEN |
---|
317 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
318 | target_id, 13, comm_inter, status, ierr ) |
---|
319 | ENDIF |
---|
320 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
321 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, & |
---|
322 | comm2d, ierr) |
---|
323 | qswst_remote(nysg:nyng,nxlg:nxrg) = total_2d_o(nysg:nyng,nxlg:nxrg) |
---|
324 | ENDIF |
---|
325 | ! |
---|
326 | !-- Send surface temperature to atmosphere |
---|
327 | total_2d_o = 0.0 |
---|
328 | total_2d = 0.0 |
---|
329 | total_2d(nys:nyn,nxl:nxr) = pt(nzt,nys:nyn,nxl:nxr) |
---|
330 | |
---|
331 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
332 | comm2d, ierr) |
---|
333 | CALL interpolate_to_atmos( 14 ) |
---|
334 | ! |
---|
335 | !-- Receive momentum flux (u) at the sea surface (top) from the atmosphere |
---|
336 | IF ( myid == 0 ) THEN |
---|
337 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
338 | target_id, 15, comm_inter, status, ierr ) |
---|
339 | ENDIF |
---|
340 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
341 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
342 | 0, comm2d, ierr ) |
---|
343 | uswst(nysg:nyng,nxlg:nxrg) = total_2d_o(nysg:nyng,nxlg:nxrg) |
---|
344 | ! |
---|
345 | !-- Receive momentum flux (v) at the sea surface (top) from the atmosphere |
---|
346 | IF ( myid == 0 ) THEN |
---|
347 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
348 | target_id, 16, comm_inter, status, ierr ) |
---|
349 | ENDIF |
---|
350 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
351 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, comm2d, & |
---|
352 | ierr ) |
---|
353 | vswst(nysg:nyng,nxlg:nxrg) = total_2d_o(nysg:nyng,nxlg:nxrg) |
---|
354 | ! |
---|
355 | !-- Send u to atmosphere |
---|
356 | total_2d_o = 0.0 |
---|
357 | total_2d = 0.0 |
---|
358 | total_2d(nys:nyn,nxl:nxr) = u(nzt,nys:nyn,nxl:nxr) |
---|
359 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
360 | comm2d, ierr ) |
---|
361 | CALL interpolate_to_atmos( 17 ) |
---|
362 | ! |
---|
363 | !-- Send v to atmosphere |
---|
364 | total_2d_o = 0.0 |
---|
365 | total_2d = 0.0 |
---|
366 | total_2d(nys:nyn,nxl:nxr) = v(nzt,nys:nyn,nxl:nxr) |
---|
367 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
368 | comm2d, ierr ) |
---|
369 | CALL interpolate_to_atmos( 18 ) |
---|
370 | |
---|
371 | ENDIF |
---|
372 | |
---|
373 | ! |
---|
374 | !-- Conversions of fluxes received from atmosphere |
---|
375 | IF ( humidity_remote ) THEN |
---|
376 | ! |
---|
377 | !-- Here tswst is still the sum of atmospheric bottom heat fluxes, |
---|
378 | !-- * latent heat of vaporization in m2/s2, or 540 cal/g, or 40.65 kJ/mol |
---|
379 | !-- /(rho_atm(=1.0)*c_p) |
---|
380 | tswst = tswst + qswst_remote * 2.2626108E6 / 1005.0 |
---|
381 | ! |
---|
382 | !-- ...and convert it to a salinity flux at the sea surface (top) |
---|
383 | !-- following Steinhorn (1991), JPO 21, pp. 1681-1683: |
---|
384 | !-- S'w' = -S * evaporation / ( rho_water * ( 1 - S ) ) |
---|
385 | saswst = -1.0 * sa(nzt,:,:) * qswst_remote / & |
---|
386 | ( rho(nzt,:,:) * ( 1.0 - sa(nzt,:,:) ) ) |
---|
387 | ENDIF |
---|
388 | |
---|
389 | ! |
---|
390 | !-- Adjust the kinematic heat flux with respect to ocean density |
---|
391 | !-- (constants are the specific heat capacities for air and water) |
---|
392 | !-- now tswst is the ocean top heat flux |
---|
393 | tswst = tswst / rho(nzt,:,:) * 1005.0 / 4218.0 |
---|
394 | |
---|
395 | ! |
---|
396 | !-- Adjust the momentum fluxes with respect to ocean density |
---|
397 | uswst = uswst / rho(nzt,:,:) |
---|
398 | vswst = vswst / rho(nzt,:,:) |
---|
399 | |
---|
400 | ENDIF |
---|
401 | |
---|
402 | IF ( coupling_topology == 1 ) THEN |
---|
403 | DEALLOCATE( total_2d_o, total_2d_a ) |
---|
404 | ENDIF |
---|
405 | |
---|
406 | CALL cpu_log( log_point(39), 'surface_coupler', 'stop' ) |
---|
407 | |
---|
408 | #endif |
---|
409 | |
---|
410 | END SUBROUTINE surface_coupler |
---|
411 | |
---|
412 | |
---|
413 | |
---|
414 | SUBROUTINE interpolate_to_atmos( tag ) |
---|
415 | |
---|
416 | #if defined( __parallel ) |
---|
417 | |
---|
418 | USE arrays_3d |
---|
419 | USE control_parameters |
---|
420 | USE grid_variables |
---|
421 | USE indices |
---|
422 | USE pegrid |
---|
423 | |
---|
424 | IMPLICIT NONE |
---|
425 | |
---|
426 | INTEGER :: dnx, dnx2, dny, dny2, i, ii, j, jj |
---|
427 | INTEGER, intent(in) :: tag |
---|
428 | |
---|
429 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
430 | |
---|
431 | IF ( myid == 0 ) THEN |
---|
432 | ! |
---|
433 | !-- Cyclic boundary conditions for the total 2D-grid |
---|
434 | total_2d_o(-nbgp:-1,:) = total_2d_o(ny+1-nbgp:ny,:) |
---|
435 | total_2d_o(:,-nbgp:-1) = total_2d_o(:,nx+1-nbgp:nx) |
---|
436 | |
---|
437 | total_2d_o(ny+1:ny+nbgp,:) = total_2d_o(0:nbgp-1,:) |
---|
438 | total_2d_o(:,nx+1:nx+nbgp) = total_2d_o(:,0:nbgp-1) |
---|
439 | |
---|
440 | ! |
---|
441 | !-- Number of gridpoints of the fine grid within one mesh of the coarse grid |
---|
442 | dnx = (nx_o+1) / (nx_a+1) |
---|
443 | dny = (ny_o+1) / (ny_a+1) |
---|
444 | |
---|
445 | ! |
---|
446 | !-- Distance for interpolation around coarse grid points within the fine |
---|
447 | !-- grid (note: 2*dnx2 must not be equal with dnx) |
---|
448 | dnx2 = 2 * ( dnx / 2 ) |
---|
449 | dny2 = 2 * ( dny / 2 ) |
---|
450 | |
---|
451 | total_2d_a = 0.0 |
---|
452 | ! |
---|
453 | !-- Interpolation from ocean-grid-layer to atmosphere-grid-layer |
---|
454 | DO j = 0, ny_a |
---|
455 | DO i = 0, nx_a |
---|
456 | DO jj = 0, dny2 |
---|
457 | DO ii = 0, dnx2 |
---|
458 | total_2d_a(j,i) = total_2d_a(j,i) & |
---|
459 | + total_2d_o(j*dny+jj,i*dnx+ii) |
---|
460 | ENDDO |
---|
461 | ENDDO |
---|
462 | total_2d_a(j,i) = total_2d_a(j,i) / ( ( dnx2 + 1 ) * ( dny2 + 1 ) ) |
---|
463 | ENDDO |
---|
464 | ENDDO |
---|
465 | ! |
---|
466 | !-- Cyclic boundary conditions for atmosphere grid |
---|
467 | total_2d_a(-nbgp:-1,:) = total_2d_a(ny_a+1-nbgp:ny_a,:) |
---|
468 | total_2d_a(:,-nbgp:-1) = total_2d_a(:,nx_a+1-nbgp:nx_a) |
---|
469 | |
---|
470 | total_2d_a(ny_a+1:ny_a+nbgp,:) = total_2d_a(0:nbgp-1,:) |
---|
471 | total_2d_a(:,nx_a+1:nx_a+nbgp) = total_2d_a(:,0:nbgp-1) |
---|
472 | ! |
---|
473 | !-- Transfer of the atmosphere-grid-layer to the atmosphere |
---|
474 | CALL MPI_SEND( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, target_id, & |
---|
475 | tag, comm_inter, ierr ) |
---|
476 | |
---|
477 | ENDIF |
---|
478 | |
---|
479 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
480 | |
---|
481 | #endif |
---|
482 | |
---|
483 | END SUBROUTINE interpolate_to_atmos |
---|
484 | |
---|
485 | |
---|
486 | SUBROUTINE interpolate_to_ocean( tag ) |
---|
487 | |
---|
488 | #if defined( __parallel ) |
---|
489 | |
---|
490 | USE arrays_3d |
---|
491 | USE control_parameters |
---|
492 | USE grid_variables |
---|
493 | USE indices |
---|
494 | USE pegrid |
---|
495 | |
---|
496 | IMPLICIT NONE |
---|
497 | |
---|
498 | INTEGER :: dnx, dny, i, ii, j, jj |
---|
499 | INTEGER, intent(in) :: tag |
---|
500 | REAL :: fl, fr, myl, myr |
---|
501 | |
---|
502 | |
---|
503 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
504 | |
---|
505 | IF ( myid == 0 ) THEN |
---|
506 | |
---|
507 | ! |
---|
508 | !-- Number of gridpoints of the fine grid within one mesh of the coarse grid |
---|
509 | dnx = ( nx_o + 1 ) / ( nx_a + 1 ) |
---|
510 | dny = ( ny_o + 1 ) / ( ny_a + 1 ) |
---|
511 | |
---|
512 | ! |
---|
513 | !-- Cyclic boundary conditions for atmosphere grid |
---|
514 | total_2d_a(-nbgp:-1,:) = total_2d_a(ny+1-nbgp:ny,:) |
---|
515 | total_2d_a(:,-nbgp:-1) = total_2d_a(:,nx+1-nbgp:nx) |
---|
516 | |
---|
517 | total_2d_a(ny+1:ny+nbgp,:) = total_2d_a(0:nbgp-1,:) |
---|
518 | total_2d_a(:,nx+1:nx+nbgp) = total_2d_a(:,0:nbgp-1) |
---|
519 | ! |
---|
520 | !-- Bilinear Interpolation from atmosphere grid-layer to ocean grid-layer |
---|
521 | DO j = 0, ny |
---|
522 | DO i = 0, nx |
---|
523 | myl = ( total_2d_a(j+1,i) - total_2d_a(j,i) ) / dny |
---|
524 | myr = ( total_2d_a(j+1,i+1) - total_2d_a(j,i+1) ) / dny |
---|
525 | DO jj = 0, dny-1 |
---|
526 | fl = myl*jj + total_2d_a(j,i) |
---|
527 | fr = myr*jj + total_2d_a(j,i+1) |
---|
528 | DO ii = 0, dnx-1 |
---|
529 | total_2d_o(j*dny+jj,i*dnx+ii) = ( fr - fl ) / dnx * ii + fl |
---|
530 | ENDDO |
---|
531 | ENDDO |
---|
532 | ENDDO |
---|
533 | ENDDO |
---|
534 | ! |
---|
535 | !-- Cyclic boundary conditions for ocean grid |
---|
536 | total_2d_o(-nbgp:-1,:) = total_2d_o(ny_o+1-nbgp:ny_o,:) |
---|
537 | total_2d_o(:,-nbgp:-1) = total_2d_o(:,nx_o+1-nbgp:nx_o) |
---|
538 | |
---|
539 | total_2d_o(ny_o+1:ny_o+nbgp,:) = total_2d_o(0:nbgp-1,:) |
---|
540 | total_2d_o(:,nx_o+1:nx_o+nbgp) = total_2d_o(:,0:nbgp-1) |
---|
541 | |
---|
542 | CALL MPI_SEND( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
543 | target_id, tag, comm_inter, ierr ) |
---|
544 | |
---|
545 | ENDIF |
---|
546 | |
---|
547 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
548 | |
---|
549 | #endif |
---|
550 | |
---|
551 | END SUBROUTINE interpolate_to_ocean |
---|