1 | !> @file surface_coupler.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: surface_coupler.f90 4429 2020-02-27 15:24:30Z raasch $ |
---|
27 | ! bugfix: preprocessor directives rearranged for serial mode |
---|
28 | ! |
---|
29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
30 | ! Corrected "Former revisions" section |
---|
31 | ! |
---|
32 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
33 | ! Modularization of all bulk cloud physics code components |
---|
34 | ! |
---|
35 | ! 109 2007-08-28 15:26:47Z letzel |
---|
36 | ! Initial revision |
---|
37 | ! |
---|
38 | ! Description: |
---|
39 | ! ------------ |
---|
40 | !> Data exchange at the interface between coupled models |
---|
41 | !------------------------------------------------------------------------------! |
---|
42 | SUBROUTINE surface_coupler |
---|
43 | #if defined( __parallel ) |
---|
44 | |
---|
45 | |
---|
46 | USE arrays_3d, & |
---|
47 | ONLY: pt, rho_ocean, sa, total_2d_a, total_2d_o, u, v |
---|
48 | |
---|
49 | USE basic_constants_and_equations_mod, & |
---|
50 | ONLY: c_p, l_v |
---|
51 | |
---|
52 | USE control_parameters, & |
---|
53 | ONLY: coupling_mode, coupling_mode_remote, coupling_topology, & |
---|
54 | humidity, humidity_remote, land_surface, message_string, & |
---|
55 | terminate_coupled, terminate_coupled_remote, & |
---|
56 | time_since_reference_point, urban_surface |
---|
57 | |
---|
58 | USE cpulog, & |
---|
59 | ONLY: cpu_log, log_point |
---|
60 | |
---|
61 | USE indices, & |
---|
62 | ONLY: nbgp, nx, nxl, nxlg, nxr, nxrg, nx_a, nx_o, ny, nyn, nyng, nys, & |
---|
63 | nysg, ny_a, ny_o, nzt |
---|
64 | |
---|
65 | USE kinds |
---|
66 | |
---|
67 | USE pegrid |
---|
68 | |
---|
69 | USE surface_mod, & |
---|
70 | ONLY : surf_def_h, surf_lsm_h, surf_type, surf_usm_h |
---|
71 | |
---|
72 | IMPLICIT NONE |
---|
73 | |
---|
74 | INTEGER(iwp) :: i !< index variable x-direction |
---|
75 | INTEGER(iwp) :: j !< index variable y-direction |
---|
76 | INTEGER(iwp) :: m !< running index for surface elements |
---|
77 | |
---|
78 | REAL(wp) :: cpw = 4218.0_wp !< heat capacity of water at constant pressure |
---|
79 | REAL(wp) :: time_since_reference_point_rem !< |
---|
80 | REAL(wp) :: total_2d(-nbgp:ny+nbgp,-nbgp:nx+nbgp) !< |
---|
81 | |
---|
82 | REAL(wp), DIMENSION(nysg:nyng,nxlg:nxrg) :: surface_flux !< dummy array for surface fluxes on 2D grid |
---|
83 | |
---|
84 | |
---|
85 | CALL cpu_log( log_point(39), 'surface_coupler', 'start' ) |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | ! |
---|
90 | !-- In case of model termination initiated by the remote model |
---|
91 | !-- (terminate_coupled_remote > 0), initiate termination of the local model. |
---|
92 | !-- The rest of the coupler must then be skipped because it would cause an MPI |
---|
93 | !-- intercomminucation hang. |
---|
94 | !-- If necessary, the coupler will be called at the beginning of the next |
---|
95 | !-- restart run. |
---|
96 | |
---|
97 | IF ( coupling_topology == 0 ) THEN |
---|
98 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, target_id, & |
---|
99 | 0, & |
---|
100 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, & |
---|
101 | 0, comm_inter, status, ierr ) |
---|
102 | ELSE |
---|
103 | IF ( myid == 0) THEN |
---|
104 | CALL MPI_SENDRECV( terminate_coupled, 1, MPI_INTEGER, & |
---|
105 | target_id, 0, & |
---|
106 | terminate_coupled_remote, 1, MPI_INTEGER, & |
---|
107 | target_id, 0, & |
---|
108 | comm_inter, status, ierr ) |
---|
109 | ENDIF |
---|
110 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, & |
---|
111 | ierr ) |
---|
112 | |
---|
113 | ALLOCATE( total_2d_a(-nbgp:ny_a+nbgp,-nbgp:nx_a+nbgp), & |
---|
114 | total_2d_o(-nbgp:ny_o+nbgp,-nbgp:nx_o+nbgp) ) |
---|
115 | |
---|
116 | ENDIF |
---|
117 | |
---|
118 | IF ( terminate_coupled_remote > 0 ) THEN |
---|
119 | WRITE( message_string, * ) 'remote model "', & |
---|
120 | TRIM( coupling_mode_remote ), & |
---|
121 | '" terminated', & |
---|
122 | '&with terminate_coupled_remote = ', & |
---|
123 | terminate_coupled_remote, & |
---|
124 | '&local model "', TRIM( coupling_mode ), & |
---|
125 | '" has', & |
---|
126 | '&terminate_coupled = ', & |
---|
127 | terminate_coupled |
---|
128 | CALL message( 'surface_coupler', 'PA0310', 1, 2, 0, 6, 0 ) |
---|
129 | RETURN |
---|
130 | ENDIF |
---|
131 | |
---|
132 | |
---|
133 | ! |
---|
134 | !-- Exchange the current simulated time between the models, |
---|
135 | !-- currently just for total_2d |
---|
136 | IF ( coupling_topology == 0 ) THEN |
---|
137 | |
---|
138 | CALL MPI_SEND( time_since_reference_point, 1, MPI_REAL, target_id, 11, & |
---|
139 | comm_inter, ierr ) |
---|
140 | CALL MPI_RECV( time_since_reference_point_rem, 1, MPI_REAL, target_id, & |
---|
141 | 11, comm_inter, status, ierr ) |
---|
142 | ELSE |
---|
143 | |
---|
144 | IF ( myid == 0 ) THEN |
---|
145 | |
---|
146 | CALL MPI_SEND( time_since_reference_point, 1, MPI_REAL, target_id, & |
---|
147 | 11, comm_inter, ierr ) |
---|
148 | CALL MPI_RECV( time_since_reference_point_rem, 1, MPI_REAL, & |
---|
149 | target_id, 11, comm_inter, status, ierr ) |
---|
150 | |
---|
151 | ENDIF |
---|
152 | |
---|
153 | CALL MPI_BCAST( time_since_reference_point_rem, 1, MPI_REAL, 0, comm2d, & |
---|
154 | ierr ) |
---|
155 | |
---|
156 | ENDIF |
---|
157 | |
---|
158 | ! |
---|
159 | !-- Exchange the interface data |
---|
160 | IF ( coupling_mode == 'atmosphere_to_ocean' ) THEN |
---|
161 | |
---|
162 | ! |
---|
163 | !-- Horizontal grid size and number of processors is equal in ocean and |
---|
164 | !-- atmosphere |
---|
165 | IF ( coupling_topology == 0 ) THEN |
---|
166 | |
---|
167 | ! |
---|
168 | !-- Send heat flux at bottom surface to the ocean. First, transfer from |
---|
169 | !-- 1D surface type to 2D grid. |
---|
170 | CALL transfer_1D_to_2D_equal( surf_def_h(0)%shf, surf_lsm_h%shf, & |
---|
171 | surf_usm_h%shf ) |
---|
172 | CALL MPI_SEND( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, & |
---|
173 | 12, comm_inter, ierr ) |
---|
174 | ! |
---|
175 | !-- Send humidity flux at bottom surface to the ocean. First, transfer |
---|
176 | !-- from 1D surface type to 2D grid. |
---|
177 | CALL transfer_1D_to_2D_equal( surf_def_h(0)%qsws, surf_lsm_h%qsws, & |
---|
178 | surf_usm_h%qsws ) |
---|
179 | IF ( humidity ) THEN |
---|
180 | CALL MPI_SEND( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, & |
---|
181 | target_id, 13, comm_inter, ierr ) |
---|
182 | ENDIF |
---|
183 | ! |
---|
184 | !-- Receive temperature at the bottom surface from the ocean |
---|
185 | CALL MPI_RECV( pt(0,nysg,nxlg), 1, type_xy, target_id, 14, & |
---|
186 | comm_inter, status, ierr ) |
---|
187 | ! |
---|
188 | !-- Send the momentum flux (u) at bottom surface to the ocean. First, |
---|
189 | !-- transfer from 1D surface type to 2D grid. |
---|
190 | CALL transfer_1D_to_2D_equal( surf_def_h(0)%usws, surf_lsm_h%usws, & |
---|
191 | surf_usm_h%usws ) |
---|
192 | CALL MPI_SEND( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, & |
---|
193 | 15, comm_inter, ierr ) |
---|
194 | ! |
---|
195 | !-- Send the momentum flux (v) at bottom surface to the ocean. First, |
---|
196 | !-- transfer from 1D surface type to 2D grid. |
---|
197 | CALL transfer_1D_to_2D_equal( surf_def_h(0)%vsws, surf_lsm_h%vsws, & |
---|
198 | surf_usm_h%vsws ) |
---|
199 | CALL MPI_SEND( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, & |
---|
200 | 16, comm_inter, ierr ) |
---|
201 | ! |
---|
202 | !-- Receive u at the bottom surface from the ocean |
---|
203 | CALL MPI_RECV( u(0,nysg,nxlg), 1, type_xy, target_id, 17, & |
---|
204 | comm_inter, status, ierr ) |
---|
205 | ! |
---|
206 | !-- Receive v at the bottom surface from the ocean |
---|
207 | CALL MPI_RECV( v(0,nysg,nxlg), 1, type_xy, target_id, 18, & |
---|
208 | comm_inter, status, ierr ) |
---|
209 | ! |
---|
210 | !-- Horizontal grid size or number of processors differs between |
---|
211 | !-- ocean and atmosphere |
---|
212 | ELSE |
---|
213 | |
---|
214 | ! |
---|
215 | !-- Send heat flux at bottom surface to the ocean |
---|
216 | total_2d_a = 0.0_wp |
---|
217 | total_2d = 0.0_wp |
---|
218 | ! |
---|
219 | !-- Transfer from 1D surface type to 2D grid. |
---|
220 | CALL transfer_1D_to_2D_unequal( surf_def_h(0)%shf, surf_lsm_h%shf, & |
---|
221 | surf_usm_h%shf ) |
---|
222 | |
---|
223 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
224 | comm2d, ierr ) |
---|
225 | CALL interpolate_to_ocean( 12 ) |
---|
226 | ! |
---|
227 | !-- Send humidity flux at bottom surface to the ocean |
---|
228 | IF ( humidity ) THEN |
---|
229 | total_2d_a = 0.0_wp |
---|
230 | total_2d = 0.0_wp |
---|
231 | ! |
---|
232 | !-- Transfer from 1D surface type to 2D grid. |
---|
233 | CALL transfer_1D_to_2D_unequal( surf_def_h(0)%qsws, & |
---|
234 | surf_lsm_h%qsws, & |
---|
235 | surf_usm_h%qsws ) |
---|
236 | |
---|
237 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, & |
---|
238 | 0, comm2d, ierr ) |
---|
239 | CALL interpolate_to_ocean( 13 ) |
---|
240 | ENDIF |
---|
241 | ! |
---|
242 | !-- Receive temperature at the bottom surface from the ocean |
---|
243 | IF ( myid == 0 ) THEN |
---|
244 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
245 | target_id, 14, comm_inter, status, ierr ) |
---|
246 | ENDIF |
---|
247 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
248 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
249 | ierr ) |
---|
250 | pt(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
251 | ! |
---|
252 | !-- Send momentum flux (u) at bottom surface to the ocean |
---|
253 | total_2d_a = 0.0_wp |
---|
254 | total_2d = 0.0_wp |
---|
255 | ! |
---|
256 | !-- Transfer from 1D surface type to 2D grid. |
---|
257 | CALL transfer_1D_to_2D_unequal( surf_def_h(0)%usws, surf_lsm_h%usws, & |
---|
258 | surf_usm_h%usws ) |
---|
259 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
260 | comm2d, ierr ) |
---|
261 | CALL interpolate_to_ocean( 15 ) |
---|
262 | ! |
---|
263 | !-- Send momentum flux (v) at bottom surface to the ocean |
---|
264 | total_2d_a = 0.0_wp |
---|
265 | total_2d = 0.0_wp |
---|
266 | ! |
---|
267 | !-- Transfer from 1D surface type to 2D grid. |
---|
268 | CALL transfer_1D_to_2D_unequal( surf_def_h(0)%usws, surf_lsm_h%usws, & |
---|
269 | surf_usm_h%usws ) |
---|
270 | CALL MPI_REDUCE( total_2d, total_2d_a, ngp_a, MPI_REAL, MPI_SUM, 0, & |
---|
271 | comm2d, ierr ) |
---|
272 | CALL interpolate_to_ocean( 16 ) |
---|
273 | ! |
---|
274 | !-- Receive u at the bottom surface from the ocean |
---|
275 | IF ( myid == 0 ) THEN |
---|
276 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
277 | target_id, 17, comm_inter, status, ierr ) |
---|
278 | ENDIF |
---|
279 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
280 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
281 | ierr ) |
---|
282 | u(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
283 | ! |
---|
284 | !-- Receive v at the bottom surface from the ocean |
---|
285 | IF ( myid == 0 ) THEN |
---|
286 | CALL MPI_RECV( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, & |
---|
287 | target_id, 18, comm_inter, status, ierr ) |
---|
288 | ENDIF |
---|
289 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
290 | CALL MPI_BCAST( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, 0, comm2d, & |
---|
291 | ierr ) |
---|
292 | v(0,nysg:nyng,nxlg:nxrg) = total_2d_a(nysg:nyng,nxlg:nxrg) |
---|
293 | |
---|
294 | ENDIF |
---|
295 | |
---|
296 | ELSEIF ( coupling_mode == 'ocean_to_atmosphere' ) THEN |
---|
297 | |
---|
298 | ! |
---|
299 | !-- Horizontal grid size and number of processors is equal |
---|
300 | !-- in ocean and atmosphere |
---|
301 | IF ( coupling_topology == 0 ) THEN |
---|
302 | ! |
---|
303 | !-- Receive heat flux at the sea surface (top) from the atmosphere |
---|
304 | CALL MPI_RECV( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 12, & |
---|
305 | comm_inter, status, ierr ) |
---|
306 | CALL transfer_2D_to_1D_equal( surf_def_h(2)%shf ) |
---|
307 | ! |
---|
308 | !-- Receive humidity flux from the atmosphere (bottom) |
---|
309 | !-- and add it to the heat flux at the sea surface (top)... |
---|
310 | IF ( humidity_remote ) THEN |
---|
311 | CALL MPI_RECV( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, & |
---|
312 | target_id, 13, comm_inter, status, ierr ) |
---|
313 | CALL transfer_2D_to_1D_equal( surf_def_h(2)%qsws ) |
---|
314 | ENDIF |
---|
315 | ! |
---|
316 | !-- Send sea surface temperature to the atmosphere model |
---|
317 | CALL MPI_SEND( pt(nzt,nysg,nxlg), 1, type_xy, target_id, 14, & |
---|
318 | comm_inter, ierr ) |
---|
319 | ! |
---|
320 | !-- Receive momentum flux (u) at the sea surface (top) from the atmosphere |
---|
321 | CALL MPI_RECV( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 15, & |
---|
322 | comm_inter, status, ierr ) |
---|
323 | CALL transfer_2D_to_1D_equal( surf_def_h(2)%usws ) |
---|
324 | ! |
---|
325 | !-- Receive momentum flux (v) at the sea surface (top) from the atmosphere |
---|
326 | CALL MPI_RECV( surface_flux(nysg,nxlg), ngp_xy, MPI_REAL, target_id, 16, & |
---|
327 | comm_inter, status, ierr ) |
---|
328 | CALL transfer_2D_to_1D_equal( surf_def_h(2)%vsws ) |
---|
329 | ! |
---|
330 | !-- Send u to the atmosphere |
---|
331 | CALL MPI_SEND( u(nzt,nysg,nxlg), 1, type_xy, target_id, 17, & |
---|
332 | comm_inter, ierr ) |
---|
333 | ! |
---|
334 | !-- Send v to the atmosphere |
---|
335 | CALL MPI_SEND( v(nzt,nysg,nxlg), 1, type_xy, target_id, 18, & |
---|
336 | comm_inter, ierr ) |
---|
337 | ! |
---|
338 | !-- Horizontal gridsize or number of processors differs between |
---|
339 | !-- ocean and atmosphere |
---|
340 | ELSE |
---|
341 | ! |
---|
342 | !-- Receive heat flux at the sea surface (top) from the atmosphere |
---|
343 | IF ( myid == 0 ) THEN |
---|
344 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
345 | target_id, 12, comm_inter, status, ierr ) |
---|
346 | ENDIF |
---|
347 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
348 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, comm2d, & |
---|
349 | ierr ) |
---|
350 | CALL transfer_2D_to_1D_unequal( surf_def_h(2)%shf ) |
---|
351 | ! |
---|
352 | !-- Receive humidity flux at the sea surface (top) from the atmosphere |
---|
353 | IF ( humidity_remote ) THEN |
---|
354 | IF ( myid == 0 ) THEN |
---|
355 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
356 | target_id, 13, comm_inter, status, ierr ) |
---|
357 | ENDIF |
---|
358 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
359 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, & |
---|
360 | comm2d, ierr) |
---|
361 | CALL transfer_2D_to_1D_unequal( surf_def_h(2)%qsws ) |
---|
362 | ENDIF |
---|
363 | ! |
---|
364 | !-- Send surface temperature to atmosphere |
---|
365 | total_2d_o = 0.0_wp |
---|
366 | total_2d = 0.0_wp |
---|
367 | total_2d(nys:nyn,nxl:nxr) = pt(nzt,nys:nyn,nxl:nxr) |
---|
368 | |
---|
369 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
370 | comm2d, ierr) |
---|
371 | CALL interpolate_to_atmos( 14 ) |
---|
372 | ! |
---|
373 | !-- Receive momentum flux (u) at the sea surface (top) from the atmosphere |
---|
374 | IF ( myid == 0 ) THEN |
---|
375 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
376 | target_id, 15, comm_inter, status, ierr ) |
---|
377 | ENDIF |
---|
378 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
379 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
380 | 0, comm2d, ierr ) |
---|
381 | CALL transfer_2D_to_1D_unequal( surf_def_h(2)%usws ) |
---|
382 | ! |
---|
383 | !-- Receive momentum flux (v) at the sea surface (top) from the atmosphere |
---|
384 | IF ( myid == 0 ) THEN |
---|
385 | CALL MPI_RECV( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
386 | target_id, 16, comm_inter, status, ierr ) |
---|
387 | ENDIF |
---|
388 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
389 | CALL MPI_BCAST( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, 0, comm2d, & |
---|
390 | ierr ) |
---|
391 | CALL transfer_2D_to_1D_unequal( surf_def_h(2)%vsws ) |
---|
392 | ! |
---|
393 | !-- Send u to atmosphere |
---|
394 | total_2d_o = 0.0_wp |
---|
395 | total_2d = 0.0_wp |
---|
396 | total_2d(nys:nyn,nxl:nxr) = u(nzt,nys:nyn,nxl:nxr) |
---|
397 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
398 | comm2d, ierr ) |
---|
399 | CALL interpolate_to_atmos( 17 ) |
---|
400 | ! |
---|
401 | !-- Send v to atmosphere |
---|
402 | total_2d_o = 0.0_wp |
---|
403 | total_2d = 0.0_wp |
---|
404 | total_2d(nys:nyn,nxl:nxr) = v(nzt,nys:nyn,nxl:nxr) |
---|
405 | CALL MPI_REDUCE( total_2d, total_2d_o, ngp_o, MPI_REAL, MPI_SUM, 0, & |
---|
406 | comm2d, ierr ) |
---|
407 | CALL interpolate_to_atmos( 18 ) |
---|
408 | |
---|
409 | ENDIF |
---|
410 | |
---|
411 | ! |
---|
412 | !-- Conversions of fluxes received from atmosphere |
---|
413 | IF ( humidity_remote ) THEN |
---|
414 | ! |
---|
415 | !-- Here top heat flux is still the sum of atmospheric bottom heat fluxes, |
---|
416 | !-- * latent heat of vaporization in m2/s2, or 540 cal/g, or 40.65 kJ/mol |
---|
417 | !-- /(rho_atm(=1.0)*c_p) |
---|
418 | DO m = 1, surf_def_h(2)%ns |
---|
419 | i = surf_def_h(2)%i(m) |
---|
420 | j = surf_def_h(2)%j(m) |
---|
421 | |
---|
422 | surf_def_h(2)%shf(m) = surf_def_h(2)%shf(m) + & |
---|
423 | surf_def_h(2)%qsws(m) * l_v / c_p |
---|
424 | ! |
---|
425 | !-- ...and convert it to a salinity flux at the sea surface (top) |
---|
426 | !-- following Steinhorn (1991), JPO 21, pp. 1681-1683: |
---|
427 | !-- S'w' = -S * evaporation / ( rho_water * ( 1 - S ) ) |
---|
428 | surf_def_h(2)%sasws(m) = -1.0_wp * sa(nzt,j,i) * 0.001_wp * & |
---|
429 | surf_def_h(2)%qsws(m) / & |
---|
430 | ( rho_ocean(nzt,j,i) * & |
---|
431 | ( 1.0_wp - sa(nzt,j,i) * 0.001_wp ) & |
---|
432 | ) |
---|
433 | ENDDO |
---|
434 | ENDIF |
---|
435 | |
---|
436 | ! |
---|
437 | !-- Adjust the kinematic heat flux with respect to ocean density |
---|
438 | !-- (constants are the specific heat capacities for air and water), as well |
---|
439 | !-- as momentum fluxes |
---|
440 | DO m = 1, surf_def_h(2)%ns |
---|
441 | i = surf_def_h(2)%i(m) |
---|
442 | j = surf_def_h(2)%j(m) |
---|
443 | surf_def_h(2)%shf(m) = surf_def_h(2)%shf(m) / rho_ocean(nzt,j,i) * & |
---|
444 | c_p / cpw |
---|
445 | |
---|
446 | surf_def_h(2)%usws(m) = surf_def_h(2)%usws(m) / rho_ocean(nzt,j,i) |
---|
447 | surf_def_h(2)%vsws(m) = surf_def_h(2)%vsws(m) / rho_ocean(nzt,j,i) |
---|
448 | ENDDO |
---|
449 | |
---|
450 | ENDIF |
---|
451 | |
---|
452 | IF ( coupling_topology == 1 ) THEN |
---|
453 | DEALLOCATE( total_2d_o, total_2d_a ) |
---|
454 | ENDIF |
---|
455 | |
---|
456 | CALL cpu_log( log_point(39), 'surface_coupler', 'stop' ) |
---|
457 | |
---|
458 | |
---|
459 | CONTAINS |
---|
460 | |
---|
461 | ! Description: |
---|
462 | !------------------------------------------------------------------------------! |
---|
463 | !> Data transfer from 1D surface-data type to 2D dummy array for equal |
---|
464 | !> grids in atmosphere and ocean. |
---|
465 | !------------------------------------------------------------------------------! |
---|
466 | SUBROUTINE transfer_1D_to_2D_equal( def_1d, lsm_1d, usm_1d ) |
---|
467 | |
---|
468 | IMPLICIT NONE |
---|
469 | |
---|
470 | INTEGER(iwp) :: i !< running index x |
---|
471 | INTEGER(iwp) :: j !< running index y |
---|
472 | INTEGER(iwp) :: m !< running index surface type |
---|
473 | |
---|
474 | REAL(wp), DIMENSION(1:surf_def_h(0)%ns) :: def_1d !< 1D surface flux, default surfaces |
---|
475 | REAL(wp), DIMENSION(1:surf_lsm_h%ns) :: lsm_1d !< 1D surface flux, natural surfaces |
---|
476 | REAL(wp), DIMENSION(1:surf_usm_h%ns) :: usm_1d !< 1D surface flux, urban surfaces |
---|
477 | ! |
---|
478 | !-- Transfer surface flux at default surfaces to 2D grid |
---|
479 | DO m = 1, surf_def_h(0)%ns |
---|
480 | i = surf_def_h(0)%i(m) |
---|
481 | j = surf_def_h(0)%j(m) |
---|
482 | surface_flux(j,i) = def_1d(m) |
---|
483 | ENDDO |
---|
484 | ! |
---|
485 | !-- Transfer surface flux at natural surfaces to 2D grid |
---|
486 | IF ( land_surface ) THEN |
---|
487 | DO m = 1, SIZE(lsm_1d) |
---|
488 | i = surf_lsm_h%i(m) |
---|
489 | j = surf_lsm_h%j(m) |
---|
490 | surface_flux(j,i) = lsm_1d(m) |
---|
491 | ENDDO |
---|
492 | ENDIF |
---|
493 | ! |
---|
494 | !-- Transfer surface flux at natural surfaces to 2D grid |
---|
495 | IF ( urban_surface ) THEN |
---|
496 | DO m = 1, SIZE(usm_1d) |
---|
497 | i = surf_usm_h%i(m) |
---|
498 | j = surf_usm_h%j(m) |
---|
499 | surface_flux(j,i) = usm_1d(m) |
---|
500 | ENDDO |
---|
501 | ENDIF |
---|
502 | |
---|
503 | END SUBROUTINE transfer_1D_to_2D_equal |
---|
504 | |
---|
505 | ! Description: |
---|
506 | !------------------------------------------------------------------------------! |
---|
507 | !> Data transfer from 2D array for equal grids onto 1D surface-data type |
---|
508 | !> array. |
---|
509 | !------------------------------------------------------------------------------! |
---|
510 | SUBROUTINE transfer_2D_to_1D_equal( def_1d ) |
---|
511 | |
---|
512 | IMPLICIT NONE |
---|
513 | |
---|
514 | INTEGER(iwp) :: i !< running index x |
---|
515 | INTEGER(iwp) :: j !< running index y |
---|
516 | INTEGER(iwp) :: m !< running index surface type |
---|
517 | |
---|
518 | REAL(wp), DIMENSION(1:surf_def_h(2)%ns) :: def_1d !< 1D surface flux, default surfaces |
---|
519 | ! |
---|
520 | !-- Transfer surface flux to 1D surface type, only for default surfaces |
---|
521 | DO m = 1, surf_def_h(2)%ns |
---|
522 | i = surf_def_h(2)%i(m) |
---|
523 | j = surf_def_h(2)%j(m) |
---|
524 | def_1d(m) = surface_flux(j,i) |
---|
525 | ENDDO |
---|
526 | |
---|
527 | END SUBROUTINE transfer_2D_to_1D_equal |
---|
528 | |
---|
529 | ! Description: |
---|
530 | !------------------------------------------------------------------------------! |
---|
531 | !> Data transfer from 1D surface-data type to 2D dummy array from unequal |
---|
532 | !> grids in atmosphere and ocean. |
---|
533 | !------------------------------------------------------------------------------! |
---|
534 | SUBROUTINE transfer_1D_to_2D_unequal( def_1d, lsm_1d, usm_1d ) |
---|
535 | |
---|
536 | IMPLICIT NONE |
---|
537 | |
---|
538 | INTEGER(iwp) :: i !< running index x |
---|
539 | INTEGER(iwp) :: j !< running index y |
---|
540 | INTEGER(iwp) :: m !< running index surface type |
---|
541 | |
---|
542 | REAL(wp), DIMENSION(1:surf_def_h(0)%ns) :: def_1d !< 1D surface flux, default surfaces |
---|
543 | REAL(wp), DIMENSION(1:surf_lsm_h%ns) :: lsm_1d !< 1D surface flux, natural surfaces |
---|
544 | REAL(wp), DIMENSION(1:surf_usm_h%ns) :: usm_1d !< 1D surface flux, urban surfaces |
---|
545 | ! |
---|
546 | !-- Transfer surface flux at default surfaces to 2D grid. Transfer no |
---|
547 | !-- ghost-grid points since total_2d is a global array. |
---|
548 | DO m = 1, SIZE(def_1d) |
---|
549 | i = surf_def_h(0)%i(m) |
---|
550 | j = surf_def_h(0)%j(m) |
---|
551 | |
---|
552 | IF ( i >= nxl .AND. i <= nxr .AND. & |
---|
553 | j >= nys .AND. j <= nyn ) THEN |
---|
554 | total_2d(j,i) = def_1d(m) |
---|
555 | ENDIF |
---|
556 | ENDDO |
---|
557 | ! |
---|
558 | !-- Transfer surface flux at natural surfaces to 2D grid |
---|
559 | IF ( land_surface ) THEN |
---|
560 | DO m = 1, SIZE(lsm_1d) |
---|
561 | i = surf_lsm_h%i(m) |
---|
562 | j = surf_lsm_h%j(m) |
---|
563 | |
---|
564 | IF ( i >= nxl .AND. i <= nxr .AND. & |
---|
565 | j >= nys .AND. j <= nyn ) THEN |
---|
566 | total_2d(j,i) = lsm_1d(m) |
---|
567 | ENDIF |
---|
568 | ENDDO |
---|
569 | ENDIF |
---|
570 | ! |
---|
571 | !-- Transfer surface flux at natural surfaces to 2D grid |
---|
572 | IF ( urban_surface ) THEN |
---|
573 | DO m = 1, SIZE(usm_1d) |
---|
574 | i = surf_usm_h%i(m) |
---|
575 | j = surf_usm_h%j(m) |
---|
576 | |
---|
577 | IF ( i >= nxl .AND. i <= nxr .AND. & |
---|
578 | j >= nys .AND. j <= nyn ) THEN |
---|
579 | total_2d(j,i) = usm_1d(m) |
---|
580 | ENDIF |
---|
581 | ENDDO |
---|
582 | ENDIF |
---|
583 | |
---|
584 | END SUBROUTINE transfer_1D_to_2D_unequal |
---|
585 | |
---|
586 | ! Description: |
---|
587 | !------------------------------------------------------------------------------! |
---|
588 | !> Data transfer from 2D dummy array from unequal grids to 1D surface-data |
---|
589 | !> type. |
---|
590 | !------------------------------------------------------------------------------! |
---|
591 | SUBROUTINE transfer_2D_to_1D_unequal( def_1d ) |
---|
592 | |
---|
593 | IMPLICIT NONE |
---|
594 | |
---|
595 | INTEGER(iwp) :: i !< running index x |
---|
596 | INTEGER(iwp) :: j !< running index y |
---|
597 | INTEGER(iwp) :: m !< running index surface type |
---|
598 | |
---|
599 | REAL(wp), DIMENSION(1:surf_def_h(2)%ns) :: def_1d !< 1D surface flux, default surfaces |
---|
600 | ! |
---|
601 | !-- Transfer 2D surface flux to default surfaces data type. Transfer no |
---|
602 | !-- ghost-grid points since total_2d is a global array. |
---|
603 | DO m = 1, SIZE(def_1d) |
---|
604 | i = surf_def_h(2)%i(m) |
---|
605 | j = surf_def_h(2)%j(m) |
---|
606 | |
---|
607 | IF ( i >= nxl .AND. i <= nxr .AND. & |
---|
608 | j >= nys .AND. j <= nyn ) THEN |
---|
609 | def_1d(m) = total_2d_o(j,i) |
---|
610 | ENDIF |
---|
611 | ENDDO |
---|
612 | |
---|
613 | |
---|
614 | END SUBROUTINE transfer_2D_to_1D_unequal |
---|
615 | |
---|
616 | #endif |
---|
617 | END SUBROUTINE surface_coupler |
---|
618 | |
---|
619 | |
---|
620 | |
---|
621 | !------------------------------------------------------------------------------! |
---|
622 | ! Description: |
---|
623 | ! ------------ |
---|
624 | !> @todo Missing subroutine description. |
---|
625 | !------------------------------------------------------------------------------! |
---|
626 | #if defined( __parallel ) |
---|
627 | |
---|
628 | SUBROUTINE interpolate_to_atmos( tag ) |
---|
629 | |
---|
630 | USE arrays_3d, & |
---|
631 | ONLY: total_2d_a, total_2d_o |
---|
632 | |
---|
633 | USE indices, & |
---|
634 | ONLY: nbgp, nx, nx_a, nx_o, ny, ny_a, ny_o |
---|
635 | |
---|
636 | USE kinds |
---|
637 | |
---|
638 | USE pegrid |
---|
639 | |
---|
640 | IMPLICIT NONE |
---|
641 | |
---|
642 | INTEGER(iwp) :: dnx !< |
---|
643 | INTEGER(iwp) :: dnx2 !< |
---|
644 | INTEGER(iwp) :: dny !< |
---|
645 | INTEGER(iwp) :: dny2 !< |
---|
646 | INTEGER(iwp) :: i !< |
---|
647 | INTEGER(iwp) :: ii !< |
---|
648 | INTEGER(iwp) :: j !< |
---|
649 | INTEGER(iwp) :: jj !< |
---|
650 | |
---|
651 | INTEGER(iwp), intent(in) :: tag !< |
---|
652 | |
---|
653 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
654 | |
---|
655 | IF ( myid == 0 ) THEN |
---|
656 | ! |
---|
657 | !-- Cyclic boundary conditions for the total 2D-grid |
---|
658 | total_2d_o(-nbgp:-1,:) = total_2d_o(ny+1-nbgp:ny,:) |
---|
659 | total_2d_o(:,-nbgp:-1) = total_2d_o(:,nx+1-nbgp:nx) |
---|
660 | |
---|
661 | total_2d_o(ny+1:ny+nbgp,:) = total_2d_o(0:nbgp-1,:) |
---|
662 | total_2d_o(:,nx+1:nx+nbgp) = total_2d_o(:,0:nbgp-1) |
---|
663 | |
---|
664 | ! |
---|
665 | !-- Number of gridpoints of the fine grid within one mesh of the coarse grid |
---|
666 | dnx = (nx_o+1) / (nx_a+1) |
---|
667 | dny = (ny_o+1) / (ny_a+1) |
---|
668 | |
---|
669 | ! |
---|
670 | !-- Distance for interpolation around coarse grid points within the fine |
---|
671 | !-- grid (note: 2*dnx2 must not be equal with dnx) |
---|
672 | dnx2 = 2 * ( dnx / 2 ) |
---|
673 | dny2 = 2 * ( dny / 2 ) |
---|
674 | |
---|
675 | total_2d_a = 0.0_wp |
---|
676 | ! |
---|
677 | !-- Interpolation from ocean-grid-layer to atmosphere-grid-layer |
---|
678 | DO j = 0, ny_a |
---|
679 | DO i = 0, nx_a |
---|
680 | DO jj = 0, dny2 |
---|
681 | DO ii = 0, dnx2 |
---|
682 | total_2d_a(j,i) = total_2d_a(j,i) & |
---|
683 | + total_2d_o(j*dny+jj,i*dnx+ii) |
---|
684 | ENDDO |
---|
685 | ENDDO |
---|
686 | total_2d_a(j,i) = total_2d_a(j,i) / ( ( dnx2 + 1 ) * ( dny2 + 1 ) ) |
---|
687 | ENDDO |
---|
688 | ENDDO |
---|
689 | ! |
---|
690 | !-- Cyclic boundary conditions for atmosphere grid |
---|
691 | total_2d_a(-nbgp:-1,:) = total_2d_a(ny_a+1-nbgp:ny_a,:) |
---|
692 | total_2d_a(:,-nbgp:-1) = total_2d_a(:,nx_a+1-nbgp:nx_a) |
---|
693 | |
---|
694 | total_2d_a(ny_a+1:ny_a+nbgp,:) = total_2d_a(0:nbgp-1,:) |
---|
695 | total_2d_a(:,nx_a+1:nx_a+nbgp) = total_2d_a(:,0:nbgp-1) |
---|
696 | ! |
---|
697 | !-- Transfer of the atmosphere-grid-layer to the atmosphere |
---|
698 | CALL MPI_SEND( total_2d_a(-nbgp,-nbgp), ngp_a, MPI_REAL, target_id, & |
---|
699 | tag, comm_inter, ierr ) |
---|
700 | |
---|
701 | ENDIF |
---|
702 | |
---|
703 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
704 | |
---|
705 | END SUBROUTINE interpolate_to_atmos |
---|
706 | |
---|
707 | #endif |
---|
708 | |
---|
709 | |
---|
710 | !------------------------------------------------------------------------------! |
---|
711 | ! Description: |
---|
712 | ! ------------ |
---|
713 | !> @todo Missing subroutine description. |
---|
714 | !------------------------------------------------------------------------------! |
---|
715 | #if defined( __parallel ) |
---|
716 | |
---|
717 | SUBROUTINE interpolate_to_ocean( tag ) |
---|
718 | |
---|
719 | USE arrays_3d, & |
---|
720 | ONLY: total_2d_a, total_2d_o |
---|
721 | |
---|
722 | USE indices, & |
---|
723 | ONLY: nbgp, nx, nx_a, nx_o, ny, ny_a, ny_o |
---|
724 | |
---|
725 | USE kinds |
---|
726 | |
---|
727 | USE pegrid |
---|
728 | |
---|
729 | IMPLICIT NONE |
---|
730 | |
---|
731 | INTEGER(iwp) :: dnx !< |
---|
732 | INTEGER(iwp) :: dny !< |
---|
733 | INTEGER(iwp) :: i !< |
---|
734 | INTEGER(iwp) :: ii !< |
---|
735 | INTEGER(iwp) :: j !< |
---|
736 | INTEGER(iwp) :: jj !< |
---|
737 | INTEGER(iwp), intent(in) :: tag !< |
---|
738 | |
---|
739 | REAL(wp) :: fl !< |
---|
740 | REAL(wp) :: fr !< |
---|
741 | REAL(wp) :: myl !< |
---|
742 | REAL(wp) :: myr !< |
---|
743 | |
---|
744 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
745 | |
---|
746 | IF ( myid == 0 ) THEN |
---|
747 | |
---|
748 | ! |
---|
749 | !-- Number of gridpoints of the fine grid within one mesh of the coarse grid |
---|
750 | dnx = ( nx_o + 1 ) / ( nx_a + 1 ) |
---|
751 | dny = ( ny_o + 1 ) / ( ny_a + 1 ) |
---|
752 | |
---|
753 | ! |
---|
754 | !-- Cyclic boundary conditions for atmosphere grid |
---|
755 | total_2d_a(-nbgp:-1,:) = total_2d_a(ny+1-nbgp:ny,:) |
---|
756 | total_2d_a(:,-nbgp:-1) = total_2d_a(:,nx+1-nbgp:nx) |
---|
757 | |
---|
758 | total_2d_a(ny+1:ny+nbgp,:) = total_2d_a(0:nbgp-1,:) |
---|
759 | total_2d_a(:,nx+1:nx+nbgp) = total_2d_a(:,0:nbgp-1) |
---|
760 | ! |
---|
761 | !-- Bilinear Interpolation from atmosphere grid-layer to ocean grid-layer |
---|
762 | DO j = 0, ny |
---|
763 | DO i = 0, nx |
---|
764 | myl = ( total_2d_a(j+1,i) - total_2d_a(j,i) ) / dny |
---|
765 | myr = ( total_2d_a(j+1,i+1) - total_2d_a(j,i+1) ) / dny |
---|
766 | DO jj = 0, dny-1 |
---|
767 | fl = myl*jj + total_2d_a(j,i) |
---|
768 | fr = myr*jj + total_2d_a(j,i+1) |
---|
769 | DO ii = 0, dnx-1 |
---|
770 | total_2d_o(j*dny+jj,i*dnx+ii) = ( fr - fl ) / dnx * ii + fl |
---|
771 | ENDDO |
---|
772 | ENDDO |
---|
773 | ENDDO |
---|
774 | ENDDO |
---|
775 | ! |
---|
776 | !-- Cyclic boundary conditions for ocean grid |
---|
777 | total_2d_o(-nbgp:-1,:) = total_2d_o(ny_o+1-nbgp:ny_o,:) |
---|
778 | total_2d_o(:,-nbgp:-1) = total_2d_o(:,nx_o+1-nbgp:nx_o) |
---|
779 | |
---|
780 | total_2d_o(ny_o+1:ny_o+nbgp,:) = total_2d_o(0:nbgp-1,:) |
---|
781 | total_2d_o(:,nx_o+1:nx_o+nbgp) = total_2d_o(:,0:nbgp-1) |
---|
782 | |
---|
783 | CALL MPI_SEND( total_2d_o(-nbgp,-nbgp), ngp_o, MPI_REAL, & |
---|
784 | target_id, tag, comm_inter, ierr ) |
---|
785 | |
---|
786 | ENDIF |
---|
787 | |
---|
788 | CALL MPI_BARRIER( comm2d, ierr ) |
---|
789 | |
---|
790 | END SUBROUTINE interpolate_to_ocean |
---|
791 | |
---|
792 | #endif |
---|