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