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