[1] | 1 | SUBROUTINE pres |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[484] | 4 | ! Current revisions: |
---|
[1] | 5 | ! ----------------- |
---|
[708] | 6 | ! |
---|
| 7 | ! |
---|
| 8 | ! Former revisions: |
---|
| 9 | ! ----------------- |
---|
| 10 | ! $Id: pres.f90 708 2011-03-29 12:34:54Z raasch $ |
---|
| 11 | ! |
---|
| 12 | ! 707 2011-03-29 11:39:40Z raasch |
---|
[707] | 13 | ! Calculation of weighted average of p is now handled in the same way |
---|
| 14 | ! regardless of the number of ghost layers (advection scheme), |
---|
| 15 | ! multigrid and sor method are using p_loc for iterative advancements of |
---|
| 16 | ! pressure, |
---|
| 17 | ! localsum calculation modified for proper OpenMP reduction, |
---|
| 18 | ! bc_lr/ns replaced by bc_lr/ns_cyc |
---|
[674] | 19 | ! |
---|
[694] | 20 | ! 693 2011-03-08 09:..:..Z raasch |
---|
[695] | 21 | ! bugfix: weighting coefficient added to ibm branch |
---|
[694] | 22 | ! |
---|
| 23 | ! 680 2011-02-04 23:16:06Z gryschka |
---|
[681] | 24 | ! bugfix: collective_wait |
---|
[668] | 25 | ! |
---|
[676] | 26 | ! 675 2011-01-19 10:56:55Z suehring |
---|
| 27 | ! Removed bugfix while copying tend. |
---|
| 28 | ! |
---|
[674] | 29 | ! 673 2011-01-18 16:19:48Z suehring |
---|
| 30 | ! Weighting coefficients added for right computation of the pressure during |
---|
| 31 | ! Runge-Kutta substeps. |
---|
| 32 | ! |
---|
[668] | 33 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
[667] | 34 | ! New allocation of tend when ws-scheme and multigrid is used. This is due to |
---|
| 35 | ! reasons of perforance of the data_exchange. The same is done with p after |
---|
| 36 | ! poismg is called. |
---|
| 37 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng when no |
---|
| 38 | ! multigrid is used. Calls of exchange_horiz are modified. |
---|
| 39 | ! bugfix: After pressure correction no volume flow correction in case of |
---|
| 40 | ! non-cyclic boundary conditions |
---|
| 41 | ! (has to be done only before pressure correction) |
---|
| 42 | ! Call of SOR routine is referenced with ddzu_pres. |
---|
| 43 | ! |
---|
[623] | 44 | ! 622 2010-12-10 08:08:13Z raasch |
---|
| 45 | ! optional barriers included in order to speed up collective operations |
---|
| 46 | ! |
---|
[198] | 47 | ! 151 2008-03-07 13:42:18Z raasch |
---|
| 48 | ! Bugfix in volume flow control for non-cyclic boundary conditions |
---|
| 49 | ! |
---|
[110] | 50 | ! 106 2007-08-16 14:30:26Z raasch |
---|
| 51 | ! Volume flow conservation added for the remaining three outflow boundaries |
---|
| 52 | ! |
---|
[90] | 53 | ! 85 2007-05-11 09:35:14Z raasch |
---|
| 54 | ! Division through dt_3d replaced by multiplication of the inverse. |
---|
| 55 | ! For performance optimisation, this is done in the loop calculating the |
---|
| 56 | ! divergence instead of using a seperate loop. |
---|
| 57 | ! |
---|
[77] | 58 | ! 75 2007-03-22 09:54:05Z raasch |
---|
[75] | 59 | ! Volume flow control for non-cyclic boundary conditions added (currently only |
---|
[76] | 60 | ! for the north boundary!!), 2nd+3rd argument removed from exchange horiz, |
---|
| 61 | ! mean vertical velocity is removed in case of Neumann boundary conditions |
---|
| 62 | ! both at the bottom and the top |
---|
[1] | 63 | ! |
---|
[3] | 64 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 65 | ! |
---|
[1] | 66 | ! Revision 1.25 2006/04/26 13:26:12 raasch |
---|
| 67 | ! OpenMP optimization (+localsum, threadsum) |
---|
| 68 | ! |
---|
| 69 | ! Revision 1.1 1997/07/24 11:24:44 raasch |
---|
| 70 | ! Initial revision |
---|
| 71 | ! |
---|
| 72 | ! |
---|
| 73 | ! Description: |
---|
| 74 | ! ------------ |
---|
| 75 | ! Compute the divergence of the provisional velocity field. Solve the Poisson |
---|
| 76 | ! equation for the perturbation pressure. Compute the final velocities using |
---|
| 77 | ! this perturbation pressure. Compute the remaining divergence. |
---|
| 78 | !------------------------------------------------------------------------------! |
---|
| 79 | |
---|
| 80 | USE arrays_3d |
---|
| 81 | USE constants |
---|
| 82 | USE control_parameters |
---|
| 83 | USE cpulog |
---|
| 84 | USE grid_variables |
---|
| 85 | USE indices |
---|
| 86 | USE interfaces |
---|
| 87 | USE pegrid |
---|
| 88 | USE poisfft_mod |
---|
| 89 | USE poisfft_hybrid_mod |
---|
| 90 | USE statistics |
---|
| 91 | |
---|
| 92 | IMPLICIT NONE |
---|
| 93 | |
---|
| 94 | INTEGER :: i, j, k, sr |
---|
| 95 | |
---|
[673] | 96 | REAL :: ddt_3d, localsum, threadsum, d_weight_pres |
---|
[1] | 97 | |
---|
| 98 | REAL, DIMENSION(1:2) :: volume_flow_l, volume_flow_offset |
---|
[76] | 99 | REAL, DIMENSION(1:nzt) :: w_l, w_l_l |
---|
[1] | 100 | |
---|
| 101 | |
---|
| 102 | CALL cpu_log( log_point(8), 'pres', 'start' ) |
---|
| 103 | |
---|
[85] | 104 | |
---|
| 105 | ddt_3d = 1.0 / dt_3d |
---|
[673] | 106 | d_weight_pres = 1. / weight_pres(intermediate_timestep_count) |
---|
[85] | 107 | |
---|
[1] | 108 | ! |
---|
[707] | 109 | !-- Multigrid method expects array d to have one ghost layer. |
---|
| 110 | !-- |
---|
[1] | 111 | IF ( psolver == 'multigrid' ) THEN |
---|
[667] | 112 | |
---|
[1] | 113 | DEALLOCATE( d ) |
---|
[667] | 114 | ALLOCATE( d(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) |
---|
[707] | 115 | |
---|
| 116 | ! |
---|
| 117 | !-- Since p is later used to hold the weighted average of the substeps, it |
---|
| 118 | !-- cannot be used in the iterative solver. Therefore, its initial value is |
---|
| 119 | !-- stored on p_loc, which is then iteratively advanced in every substep. |
---|
| 120 | IF ( intermediate_timestep_count == 1 ) THEN |
---|
| 121 | DO i = nxl-1, nxr+1 |
---|
| 122 | DO j = nys-1, nyn+1 |
---|
| 123 | DO k = nzb, nzt+1 |
---|
| 124 | p_loc(k,j,i) = p(k,j,i) |
---|
| 125 | ENDDO |
---|
| 126 | ENDDO |
---|
| 127 | ENDDO |
---|
[667] | 128 | ENDIF |
---|
| 129 | |
---|
[707] | 130 | ELSEIF ( psolver == 'sor' .AND. intermediate_timestep_count == 1 ) THEN |
---|
| 131 | |
---|
| 132 | ! |
---|
| 133 | !-- Since p is later used to hold the weighted average of the substeps, it |
---|
| 134 | !-- cannot be used in the iterative solver. Therefore, its initial value is |
---|
| 135 | !-- stored on p_loc, which is then iteratively advanced in every substep. |
---|
| 136 | p_loc = p |
---|
| 137 | |
---|
[1] | 138 | ENDIF |
---|
| 139 | |
---|
| 140 | ! |
---|
[75] | 141 | !-- Conserve the volume flow at the outflow in case of non-cyclic lateral |
---|
| 142 | !-- boundary conditions |
---|
[106] | 143 | !-- WARNING: so far, this conservation does not work at the left/south |
---|
| 144 | !-- boundary if the topography at the inflow differs from that at the |
---|
| 145 | !-- outflow! For this case, volume_flow_area needs adjustment! |
---|
| 146 | ! |
---|
| 147 | !-- Left/right |
---|
[680] | 148 | |
---|
[106] | 149 | IF ( conserve_volume_flow .AND. ( outflow_l .OR. outflow_r ) ) THEN |
---|
[75] | 150 | |
---|
[106] | 151 | volume_flow(1) = 0.0 |
---|
| 152 | volume_flow_l(1) = 0.0 |
---|
| 153 | |
---|
| 154 | IF ( outflow_l ) THEN |
---|
| 155 | i = 0 |
---|
| 156 | ELSEIF ( outflow_r ) THEN |
---|
| 157 | i = nx+1 |
---|
| 158 | ENDIF |
---|
| 159 | |
---|
| 160 | DO j = nys, nyn |
---|
| 161 | ! |
---|
| 162 | !-- Sum up the volume flow through the south/north boundary |
---|
| 163 | DO k = nzb_2d(j,i) + 1, nzt |
---|
[667] | 164 | volume_flow_l(1) = volume_flow_l(1) + u(k,j,i) * dzw(k) |
---|
[106] | 165 | ENDDO |
---|
| 166 | ENDDO |
---|
| 167 | |
---|
| 168 | #if defined( __parallel ) |
---|
[680] | 169 | IF ( collective_wait ) CALL MPI_BARRIER( comm1dy, ierr ) |
---|
[106] | 170 | CALL MPI_ALLREDUCE( volume_flow_l(1), volume_flow(1), 1, MPI_REAL, & |
---|
| 171 | MPI_SUM, comm1dy, ierr ) |
---|
| 172 | #else |
---|
| 173 | volume_flow = volume_flow_l |
---|
| 174 | #endif |
---|
| 175 | volume_flow_offset(1) = ( volume_flow_initial(1) - volume_flow(1) ) & |
---|
| 176 | / volume_flow_area(1) |
---|
| 177 | |
---|
[667] | 178 | DO j = nysg, nyng |
---|
| 179 | DO k = nzb_2d(j,i) + 1, nzt |
---|
[106] | 180 | u(k,j,i) = u(k,j,i) + volume_flow_offset(1) |
---|
| 181 | ENDDO |
---|
| 182 | ENDDO |
---|
| 183 | |
---|
| 184 | ENDIF |
---|
| 185 | |
---|
| 186 | ! |
---|
| 187 | !-- South/north |
---|
| 188 | IF ( conserve_volume_flow .AND. ( outflow_n .OR. outflow_s ) ) THEN |
---|
| 189 | |
---|
[75] | 190 | volume_flow(2) = 0.0 |
---|
| 191 | volume_flow_l(2) = 0.0 |
---|
| 192 | |
---|
[106] | 193 | IF ( outflow_s ) THEN |
---|
| 194 | j = 0 |
---|
| 195 | ELSEIF ( outflow_n ) THEN |
---|
[75] | 196 | j = ny+1 |
---|
[106] | 197 | ENDIF |
---|
| 198 | |
---|
| 199 | DO i = nxl, nxr |
---|
[75] | 200 | ! |
---|
[106] | 201 | !-- Sum up the volume flow through the south/north boundary |
---|
| 202 | DO k = nzb_2d(j,i) + 1, nzt |
---|
[667] | 203 | volume_flow_l(2) = volume_flow_l(2) + v(k,j,i) * dzw(k) |
---|
[75] | 204 | ENDDO |
---|
[106] | 205 | ENDDO |
---|
| 206 | |
---|
[75] | 207 | #if defined( __parallel ) |
---|
[680] | 208 | IF ( collective_wait ) CALL MPI_BARRIER( comm1dx, ierr ) |
---|
[75] | 209 | CALL MPI_ALLREDUCE( volume_flow_l(2), volume_flow(2), 1, MPI_REAL, & |
---|
| 210 | MPI_SUM, comm1dx, ierr ) |
---|
| 211 | #else |
---|
| 212 | volume_flow = volume_flow_l |
---|
| 213 | #endif |
---|
| 214 | volume_flow_offset(2) = ( volume_flow_initial(2) - volume_flow(2) ) & |
---|
[106] | 215 | / volume_flow_area(2) |
---|
[75] | 216 | |
---|
[667] | 217 | DO i = nxlg, nxrg |
---|
[106] | 218 | DO k = nzb_v_inner(j,i) + 1, nzt |
---|
| 219 | v(k,j,i) = v(k,j,i) + volume_flow_offset(2) |
---|
[75] | 220 | ENDDO |
---|
[106] | 221 | ENDDO |
---|
[75] | 222 | |
---|
| 223 | ENDIF |
---|
| 224 | |
---|
[76] | 225 | ! |
---|
| 226 | !-- Remove mean vertical velocity |
---|
| 227 | IF ( ibc_p_b == 1 .AND. ibc_p_t == 1 ) THEN |
---|
| 228 | IF ( simulated_time > 0.0 ) THEN ! otherwise nzb_w_inner is not yet known |
---|
| 229 | w_l = 0.0; w_l_l = 0.0 |
---|
| 230 | DO i = nxl, nxr |
---|
| 231 | DO j = nys, nyn |
---|
| 232 | DO k = nzb_w_inner(j,i)+1, nzt |
---|
| 233 | w_l_l(k) = w_l_l(k) + w(k,j,i) |
---|
| 234 | ENDDO |
---|
| 235 | ENDDO |
---|
| 236 | ENDDO |
---|
| 237 | #if defined( __parallel ) |
---|
[622] | 238 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[76] | 239 | CALL MPI_ALLREDUCE( w_l_l(1), w_l(1), nzt, MPI_REAL, MPI_SUM, comm2d, & |
---|
| 240 | ierr ) |
---|
| 241 | #else |
---|
| 242 | w_l = w_l_l |
---|
| 243 | #endif |
---|
| 244 | DO k = 1, nzt |
---|
| 245 | w_l(k) = w_l(k) / ngp_2dh_outer(k,0) |
---|
| 246 | ENDDO |
---|
[667] | 247 | DO i = nxlg, nxrg |
---|
| 248 | DO j = nysg, nyng |
---|
[76] | 249 | DO k = nzb_w_inner(j,i)+1, nzt |
---|
| 250 | w(k,j,i) = w(k,j,i) - w_l(k) |
---|
| 251 | ENDDO |
---|
| 252 | ENDDO |
---|
| 253 | ENDDO |
---|
| 254 | ENDIF |
---|
| 255 | ENDIF |
---|
[75] | 256 | |
---|
| 257 | ! |
---|
[1] | 258 | !-- Compute the divergence of the provisional velocity field. |
---|
| 259 | CALL cpu_log( log_point_s(1), 'divergence', 'start' ) |
---|
| 260 | |
---|
| 261 | IF ( psolver == 'multigrid' ) THEN |
---|
| 262 | !$OMP PARALLEL DO SCHEDULE( STATIC ) |
---|
| 263 | DO i = nxl-1, nxr+1 |
---|
| 264 | DO j = nys-1, nyn+1 |
---|
| 265 | DO k = nzb, nzt+1 |
---|
| 266 | d(k,j,i) = 0.0 |
---|
| 267 | ENDDO |
---|
| 268 | ENDDO |
---|
| 269 | ENDDO |
---|
| 270 | ELSE |
---|
| 271 | !$OMP PARALLEL DO SCHEDULE( STATIC ) |
---|
| 272 | DO i = nxl, nxra |
---|
| 273 | DO j = nys, nyna |
---|
| 274 | DO k = nzb+1, nzta |
---|
| 275 | d(k,j,i) = 0.0 |
---|
| 276 | ENDDO |
---|
| 277 | ENDDO |
---|
| 278 | ENDDO |
---|
| 279 | ENDIF |
---|
| 280 | |
---|
| 281 | localsum = 0.0 |
---|
| 282 | threadsum = 0.0 |
---|
| 283 | |
---|
| 284 | #if defined( __ibm ) |
---|
| 285 | !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum) |
---|
| 286 | !$OMP DO SCHEDULE( STATIC ) |
---|
| 287 | DO i = nxl, nxr |
---|
| 288 | DO j = nys, nyn |
---|
| 289 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
[85] | 290 | d(k,j,i) = ( ( u(k,j,i+1) - u(k,j,i) ) * ddx + & |
---|
| 291 | ( v(k,j+1,i) - v(k,j,i) ) * ddy + & |
---|
[673] | 292 | ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) ) * ddt_3d & |
---|
| 293 | * d_weight_pres |
---|
[1] | 294 | ENDDO |
---|
| 295 | ! |
---|
| 296 | !-- Additional pressure boundary condition at the bottom boundary for |
---|
| 297 | !-- inhomogeneous Prandtl layer heat fluxes and temperatures, respectively |
---|
| 298 | !-- dp/dz = -(dtau13/dx + dtau23/dy) + g*pt'/pt0. |
---|
| 299 | !-- This condition must not be applied at the start of a run, because then |
---|
| 300 | !-- flow_statistics has not yet been called and thus sums = 0. |
---|
| 301 | IF ( ibc_p_b == 2 .AND. sums(nzb+1,4) /= 0.0 ) THEN |
---|
| 302 | k = nzb_s_inner(j,i) |
---|
| 303 | d(k+1,j,i) = d(k+1,j,i) + ( & |
---|
| 304 | ( usws(j,i+1) - usws(j,i) ) * ddx & |
---|
| 305 | + ( vsws(j+1,i) - vsws(j,i) ) * ddy & |
---|
| 306 | - g * ( pt(k+1,j,i) - sums(k+1,4) ) / & |
---|
| 307 | sums(k+1,4) & |
---|
[673] | 308 | ) * ddzw(k+1) * ddt_3d * d_weight_pres |
---|
[1] | 309 | ENDIF |
---|
| 310 | |
---|
| 311 | ! |
---|
| 312 | !-- Compute possible PE-sum of divergences for flow_statistics |
---|
| 313 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
| 314 | threadsum = threadsum + ABS( d(k,j,i) ) |
---|
| 315 | ENDDO |
---|
| 316 | |
---|
| 317 | ENDDO |
---|
| 318 | ENDDO |
---|
| 319 | |
---|
[707] | 320 | localsum = localsum + threadsum * dt_3d * & |
---|
| 321 | weight_pres(intermediate_timestep_count) |
---|
[693] | 322 | |
---|
[1] | 323 | !$OMP END PARALLEL |
---|
| 324 | #else |
---|
| 325 | IF ( ibc_p_b == 2 .AND. sums(nzb+1,4) /= 0.0 ) THEN |
---|
| 326 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 327 | !$OMP DO SCHEDULE( STATIC ) |
---|
| 328 | DO i = nxl, nxr |
---|
| 329 | DO j = nys, nyn |
---|
| 330 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
[667] | 331 | d(k,j,i) = ( ( u(k,j,i+1) - u(k,j,i) ) * ddx + & |
---|
| 332 | ( v(k,j+1,i) - v(k,j,i) ) * ddy + & |
---|
[673] | 333 | ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) ) * ddt_3d & |
---|
| 334 | * d_weight_pres |
---|
[1] | 335 | ENDDO |
---|
| 336 | ENDDO |
---|
| 337 | ! |
---|
| 338 | !-- Additional pressure boundary condition at the bottom boundary for |
---|
| 339 | !-- inhomogeneous Prandtl layer heat fluxes and temperatures, respectively |
---|
| 340 | !-- dp/dz = -(dtau13/dx + dtau23/dy) + g*pt'/pt0. |
---|
| 341 | !-- This condition must not be applied at the start of a run, because then |
---|
| 342 | !-- flow_statistics has not yet been called and thus sums = 0. |
---|
| 343 | DO j = nys, nyn |
---|
| 344 | k = nzb_s_inner(j,i) |
---|
| 345 | d(k+1,j,i) = d(k+1,j,i) + ( & |
---|
| 346 | ( usws(j,i+1) - usws(j,i) ) * ddx & |
---|
| 347 | + ( vsws(j+1,i) - vsws(j,i) ) * ddy & |
---|
| 348 | - g * ( pt(k+1,j,i) - sums(k+1,4) ) / & |
---|
| 349 | sums(k+1,4) & |
---|
[673] | 350 | ) * ddzw(k+1) * ddt_3d & |
---|
| 351 | * d_weight_pres |
---|
[1] | 352 | ENDDO |
---|
| 353 | ENDDO |
---|
| 354 | !$OMP END PARALLEL |
---|
| 355 | |
---|
| 356 | ELSE |
---|
| 357 | |
---|
| 358 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 359 | !$OMP DO SCHEDULE( STATIC ) |
---|
| 360 | DO i = nxl, nxr |
---|
| 361 | DO j = nys, nyn |
---|
| 362 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
[85] | 363 | d(k,j,i) = ( ( u(k,j,i+1) - u(k,j,i) ) * ddx + & |
---|
[667] | 364 | ( v(k,j+1,i) - v(k,j,i) ) * ddy + & |
---|
[673] | 365 | ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) ) * ddt_3d & |
---|
| 366 | * d_weight_pres |
---|
[1] | 367 | ENDDO |
---|
| 368 | ENDDO |
---|
| 369 | ENDDO |
---|
| 370 | !$OMP END PARALLEL |
---|
| 371 | |
---|
| 372 | ENDIF |
---|
| 373 | |
---|
| 374 | ! |
---|
| 375 | !-- Compute possible PE-sum of divergences for flow_statistics |
---|
| 376 | !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum) |
---|
| 377 | !$OMP DO SCHEDULE( STATIC ) |
---|
| 378 | DO i = nxl, nxr |
---|
| 379 | DO j = nys, nyn |
---|
| 380 | DO k = nzb+1, nzt |
---|
| 381 | threadsum = threadsum + ABS( d(k,j,i) ) |
---|
| 382 | ENDDO |
---|
| 383 | ENDDO |
---|
| 384 | ENDDO |
---|
[707] | 385 | localsum = localsum + threadsum * dt_3d * & |
---|
| 386 | weight_pres(intermediate_timestep_count) |
---|
[1] | 387 | !$OMP END PARALLEL |
---|
| 388 | #endif |
---|
| 389 | |
---|
| 390 | ! |
---|
| 391 | !-- For completeness, set the divergence sum of all statistic regions to those |
---|
| 392 | !-- of the total domain |
---|
| 393 | sums_divold_l(0:statistic_regions) = localsum |
---|
| 394 | |
---|
| 395 | CALL cpu_log( log_point_s(1), 'divergence', 'stop' ) |
---|
| 396 | |
---|
| 397 | ! |
---|
| 398 | !-- Compute the pressure perturbation solving the Poisson equation |
---|
| 399 | IF ( psolver(1:7) == 'poisfft' ) THEN |
---|
| 400 | |
---|
| 401 | ! |
---|
| 402 | !-- Enlarge the size of tend, used as a working array for the transpositions |
---|
| 403 | IF ( nxra > nxr .OR. nyna > nyn .OR. nza > nz ) THEN |
---|
| 404 | DEALLOCATE( tend ) |
---|
| 405 | ALLOCATE( tend(1:nza,nys:nyna,nxl:nxra) ) |
---|
| 406 | ENDIF |
---|
| 407 | |
---|
| 408 | ! |
---|
| 409 | !-- Solve Poisson equation via FFT and solution of tridiagonal matrices |
---|
| 410 | IF ( psolver == 'poisfft' ) THEN |
---|
| 411 | ! |
---|
| 412 | !-- Solver for 2d-decomposition |
---|
| 413 | CALL poisfft( d, tend ) |
---|
| 414 | ELSEIF ( psolver == 'poisfft_hybrid' ) THEN |
---|
| 415 | ! |
---|
| 416 | !-- Solver for 1d-decomposition (using MPI and OpenMP). |
---|
| 417 | !-- The old hybrid-solver is still included here, as long as there |
---|
| 418 | !-- are some optimization problems in poisfft |
---|
| 419 | CALL poisfft_hybrid( d ) |
---|
| 420 | ENDIF |
---|
| 421 | |
---|
| 422 | ! |
---|
| 423 | !-- Resize tend to its normal size |
---|
| 424 | IF ( nxra > nxr .OR. nyna > nyn .OR. nza > nz ) THEN |
---|
| 425 | DEALLOCATE( tend ) |
---|
[667] | 426 | ALLOCATE( tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1] | 427 | ENDIF |
---|
| 428 | |
---|
| 429 | ! |
---|
| 430 | !-- Store computed perturbation pressure and set boundary condition in |
---|
| 431 | !-- z-direction |
---|
| 432 | !$OMP PARALLEL DO |
---|
| 433 | DO i = nxl, nxr |
---|
| 434 | DO j = nys, nyn |
---|
| 435 | DO k = nzb+1, nzt |
---|
| 436 | tend(k,j,i) = d(k,j,i) |
---|
| 437 | ENDDO |
---|
| 438 | ENDDO |
---|
| 439 | ENDDO |
---|
| 440 | |
---|
| 441 | ! |
---|
| 442 | !-- Bottom boundary: |
---|
| 443 | !-- This condition is only required for internal output. The pressure |
---|
| 444 | !-- gradient (dp(nzb+1)-dp(nzb))/dz is not used anywhere else. |
---|
| 445 | IF ( ibc_p_b == 1 ) THEN |
---|
| 446 | ! |
---|
| 447 | !-- Neumann (dp/dz = 0) |
---|
| 448 | !$OMP PARALLEL DO |
---|
[667] | 449 | DO i = nxlg, nxrg |
---|
| 450 | DO j = nysg, nyng |
---|
[1] | 451 | tend(nzb_s_inner(j,i),j,i) = tend(nzb_s_inner(j,i)+1,j,i) |
---|
| 452 | ENDDO |
---|
| 453 | ENDDO |
---|
| 454 | |
---|
| 455 | ELSEIF ( ibc_p_b == 2 ) THEN |
---|
| 456 | ! |
---|
| 457 | !-- Neumann condition for inhomogeneous surfaces, |
---|
| 458 | !-- here currently still in the form of a zero gradient. Actually |
---|
| 459 | !-- dp/dz = -(dtau13/dx + dtau23/dy) + g*pt'/pt0 would have to be used for |
---|
| 460 | !-- the computation (cf. above: computation of divergences). |
---|
| 461 | !$OMP PARALLEL DO |
---|
[667] | 462 | DO i = nxlg, nxrg |
---|
| 463 | DO j = nysg, nyng |
---|
[1] | 464 | tend(nzb_s_inner(j,i),j,i) = tend(nzb_s_inner(j,i)+1,j,i) |
---|
| 465 | ENDDO |
---|
| 466 | ENDDO |
---|
| 467 | |
---|
| 468 | ELSE |
---|
| 469 | ! |
---|
| 470 | !-- Dirichlet |
---|
| 471 | !$OMP PARALLEL DO |
---|
[667] | 472 | DO i = nxlg, nxrg |
---|
| 473 | DO j = nysg, nyng |
---|
[1] | 474 | tend(nzb_s_inner(j,i),j,i) = 0.0 |
---|
| 475 | ENDDO |
---|
| 476 | ENDDO |
---|
| 477 | |
---|
| 478 | ENDIF |
---|
| 479 | |
---|
| 480 | ! |
---|
| 481 | !-- Top boundary |
---|
| 482 | IF ( ibc_p_t == 1 ) THEN |
---|
| 483 | ! |
---|
| 484 | !-- Neumann |
---|
| 485 | !$OMP PARALLEL DO |
---|
[667] | 486 | DO i = nxlg, nxrg |
---|
| 487 | DO j = nysg, nyng |
---|
[1] | 488 | tend(nzt+1,j,i) = tend(nzt,j,i) |
---|
| 489 | ENDDO |
---|
| 490 | ENDDO |
---|
| 491 | |
---|
| 492 | ELSE |
---|
| 493 | ! |
---|
| 494 | !-- Dirichlet |
---|
| 495 | !$OMP PARALLEL DO |
---|
[667] | 496 | DO i = nxlg, nxrg |
---|
| 497 | DO j = nysg, nyng |
---|
[1] | 498 | tend(nzt+1,j,i) = 0.0 |
---|
| 499 | ENDDO |
---|
| 500 | ENDDO |
---|
| 501 | |
---|
| 502 | ENDIF |
---|
| 503 | |
---|
| 504 | ! |
---|
| 505 | !-- Exchange boundaries for p |
---|
[667] | 506 | CALL exchange_horiz( tend, nbgp ) |
---|
[1] | 507 | |
---|
| 508 | ELSEIF ( psolver == 'sor' ) THEN |
---|
| 509 | |
---|
| 510 | ! |
---|
| 511 | !-- Solve Poisson equation for perturbation pressure using SOR-Red/Black |
---|
| 512 | !-- scheme |
---|
[707] | 513 | CALL sor( d, ddzu_pres, ddzw, p_loc ) |
---|
| 514 | tend = p_loc |
---|
[1] | 515 | |
---|
| 516 | ELSEIF ( psolver == 'multigrid' ) THEN |
---|
| 517 | |
---|
| 518 | ! |
---|
| 519 | !-- Solve Poisson equation for perturbation pressure using Multigrid scheme, |
---|
[667] | 520 | !-- array tend is used to store the residuals, logical exchange_mg is used |
---|
| 521 | !-- to discern data exchange in multigrid ( 1 ghostpoint ) and normal grid |
---|
| 522 | !-- ( nbgp ghost points ). |
---|
[1] | 523 | CALL poismg( tend ) |
---|
[707] | 524 | |
---|
[1] | 525 | ! |
---|
| 526 | !-- Restore perturbation pressure on tend because this array is used |
---|
| 527 | !-- further below to correct the velocity fields |
---|
[707] | 528 | DO i = nxl-1, nxr+1 |
---|
| 529 | DO j = nys-1, nyn+1 |
---|
| 530 | DO k = nzb, nzt+1 |
---|
| 531 | tend(k,j,i) = p_loc(k,j,i) |
---|
| 532 | ENDDO |
---|
| 533 | ENDDO |
---|
| 534 | ENDDO |
---|
[667] | 535 | |
---|
[1] | 536 | ENDIF |
---|
| 537 | |
---|
| 538 | ! |
---|
[707] | 539 | !-- Store perturbation pressure on array p, used for pressure data output. |
---|
| 540 | !-- Ghost layers are added in the output routines (except sor-method: see below) |
---|
| 541 | IF ( intermediate_timestep_count == 1 ) THEN |
---|
| 542 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 543 | !$OMP DO |
---|
| 544 | DO i = nxl-1, nxr+1 |
---|
| 545 | DO j = nys-1, nyn+1 |
---|
| 546 | DO k = nzb, nzt+1 |
---|
| 547 | p(k,j,i) = tend(k,j,i) * & |
---|
| 548 | weight_substep(intermediate_timestep_count) |
---|
[673] | 549 | ENDDO |
---|
[1] | 550 | ENDDO |
---|
[707] | 551 | ENDDO |
---|
| 552 | !$OMP END PARALLEL |
---|
| 553 | |
---|
| 554 | ELSE |
---|
| 555 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 556 | !$OMP DO |
---|
| 557 | DO i = nxl-1, nxr+1 |
---|
| 558 | DO j = nys-1, nyn+1 |
---|
| 559 | DO k = nzb, nzt+1 |
---|
| 560 | p(k,j,i) = p(k,j,i) + tend(k,j,i) * & |
---|
| 561 | weight_substep(intermediate_timestep_count) |
---|
[673] | 562 | ENDDO |
---|
| 563 | ENDDO |
---|
[707] | 564 | ENDDO |
---|
| 565 | !$OMP END PARALLEL |
---|
| 566 | |
---|
| 567 | ENDIF |
---|
[673] | 568 | |
---|
[707] | 569 | ! |
---|
| 570 | !-- SOR-method needs ghost layers for the next timestep |
---|
| 571 | IF ( psolver == 'sor' ) CALL exchange_horiz( p, nbgp ) |
---|
[682] | 572 | |
---|
[1] | 573 | ! |
---|
| 574 | !-- Correction of the provisional velocities with the current perturbation |
---|
| 575 | !-- pressure just computed |
---|
[707] | 576 | IF ( conserve_volume_flow .AND. ( bc_lr_cyc .OR. bc_ns_cyc ) ) THEN |
---|
[1] | 577 | volume_flow_l(1) = 0.0 |
---|
| 578 | volume_flow_l(2) = 0.0 |
---|
| 579 | ENDIF |
---|
[707] | 580 | |
---|
[1] | 581 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 582 | !$OMP DO |
---|
[673] | 583 | DO i = nxl, nxr |
---|
[1] | 584 | DO j = nys, nyn |
---|
| 585 | DO k = nzb_w_inner(j,i)+1, nzt |
---|
[707] | 586 | w(k,j,i) = w(k,j,i) - dt_3d * & |
---|
| 587 | ( tend(k+1,j,i) - tend(k,j,i) ) * ddzu(k+1) * & |
---|
| 588 | weight_pres(intermediate_timestep_count) |
---|
[1] | 589 | ENDDO |
---|
| 590 | DO k = nzb_u_inner(j,i)+1, nzt |
---|
[673] | 591 | u(k,j,i) = u(k,j,i) - dt_3d * & |
---|
[707] | 592 | ( tend(k,j,i) - tend(k,j,i-1) ) * ddx * & |
---|
| 593 | weight_pres(intermediate_timestep_count) |
---|
[1] | 594 | ENDDO |
---|
| 595 | DO k = nzb_v_inner(j,i)+1, nzt |
---|
[673] | 596 | v(k,j,i) = v(k,j,i) - dt_3d * & |
---|
[707] | 597 | ( tend(k,j,i) - tend(k,j-1,i) ) * ddy * & |
---|
| 598 | weight_pres(intermediate_timestep_count) |
---|
[673] | 599 | ENDDO |
---|
[1] | 600 | ! |
---|
| 601 | !-- Sum up the volume flow through the right and north boundary |
---|
[707] | 602 | IF ( conserve_volume_flow .AND. bc_lr_cyc .AND. bc_ns_cyc .AND. & |
---|
| 603 | i == nx ) THEN |
---|
[1] | 604 | !$OMP CRITICAL |
---|
| 605 | DO k = nzb_2d(j,i) + 1, nzt |
---|
[667] | 606 | volume_flow_l(1) = volume_flow_l(1) + u(k,j,i) * dzw(k) |
---|
[1] | 607 | ENDDO |
---|
| 608 | !$OMP END CRITICAL |
---|
| 609 | ENDIF |
---|
[707] | 610 | IF ( conserve_volume_flow .AND. bc_ns_cyc .AND. bc_lr_cyc .AND. & |
---|
| 611 | j == ny ) THEN |
---|
[1] | 612 | !$OMP CRITICAL |
---|
| 613 | DO k = nzb_2d(j,i) + 1, nzt |
---|
[667] | 614 | volume_flow_l(2) = volume_flow_l(2) + v(k,j,i) * dzw(k) |
---|
[1] | 615 | ENDDO |
---|
| 616 | !$OMP END CRITICAL |
---|
| 617 | ENDIF |
---|
| 618 | |
---|
| 619 | ENDDO |
---|
| 620 | ENDDO |
---|
| 621 | !$OMP END PARALLEL |
---|
[673] | 622 | |
---|
[1] | 623 | ! |
---|
| 624 | !-- Conserve the volume flow |
---|
[707] | 625 | IF ( conserve_volume_flow .AND. ( bc_lr_cyc .AND. bc_ns_cyc ) ) THEN |
---|
[1] | 626 | |
---|
| 627 | #if defined( __parallel ) |
---|
[622] | 628 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 629 | CALL MPI_ALLREDUCE( volume_flow_l(1), volume_flow(1), 2, MPI_REAL, & |
---|
| 630 | MPI_SUM, comm2d, ierr ) |
---|
| 631 | #else |
---|
| 632 | volume_flow = volume_flow_l |
---|
| 633 | #endif |
---|
| 634 | |
---|
| 635 | volume_flow_offset = ( volume_flow_initial - volume_flow ) / & |
---|
| 636 | volume_flow_area |
---|
| 637 | |
---|
| 638 | !$OMP PARALLEL PRIVATE (i,j,k) |
---|
| 639 | !$OMP DO |
---|
| 640 | DO i = nxl, nxr |
---|
| 641 | DO j = nys, nyn |
---|
[667] | 642 | DO k = nzb_u_inner(j,i) + 1, nzt |
---|
| 643 | u(k,j,i) = u(k,j,i) + volume_flow_offset(1) |
---|
| 644 | v(k,j,i) = v(k,j,i) + volume_flow_offset(2) |
---|
| 645 | ENDDO |
---|
[1] | 646 | ENDDO |
---|
| 647 | ENDDO |
---|
[667] | 648 | |
---|
[1] | 649 | !$OMP END PARALLEL |
---|
| 650 | |
---|
| 651 | ENDIF |
---|
| 652 | |
---|
| 653 | ! |
---|
| 654 | !-- Exchange of boundaries for the velocities |
---|
[667] | 655 | CALL exchange_horiz( u, nbgp ) |
---|
| 656 | CALL exchange_horiz( v, nbgp ) |
---|
| 657 | CALL exchange_horiz( w, nbgp ) |
---|
[1] | 658 | |
---|
| 659 | ! |
---|
| 660 | !-- Compute the divergence of the corrected velocity field, |
---|
| 661 | !-- a possible PE-sum is computed in flow_statistics |
---|
| 662 | CALL cpu_log( log_point_s(1), 'divergence', 'start' ) |
---|
| 663 | sums_divnew_l = 0.0 |
---|
| 664 | |
---|
| 665 | ! |
---|
| 666 | !-- d must be reset to zero because it can contain nonzero values below the |
---|
| 667 | !-- topography |
---|
| 668 | IF ( topography /= 'flat' ) d = 0.0 |
---|
| 669 | |
---|
| 670 | localsum = 0.0 |
---|
| 671 | threadsum = 0.0 |
---|
| 672 | |
---|
| 673 | !$OMP PARALLEL PRIVATE (i,j,k) FIRSTPRIVATE(threadsum) REDUCTION(+:localsum) |
---|
| 674 | !$OMP DO SCHEDULE( STATIC ) |
---|
| 675 | #if defined( __ibm ) |
---|
| 676 | DO i = nxl, nxr |
---|
| 677 | DO j = nys, nyn |
---|
| 678 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
| 679 | d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx + & |
---|
| 680 | ( v(k,j+1,i) - v(k,j,i) ) * ddy + & |
---|
| 681 | ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) |
---|
| 682 | ENDDO |
---|
| 683 | DO k = nzb+1, nzt |
---|
| 684 | threadsum = threadsum + ABS( d(k,j,i) ) |
---|
| 685 | ENDDO |
---|
| 686 | ENDDO |
---|
| 687 | ENDDO |
---|
| 688 | #else |
---|
| 689 | DO i = nxl, nxr |
---|
| 690 | DO j = nys, nyn |
---|
| 691 | DO k = nzb_s_inner(j,i)+1, nzt |
---|
| 692 | d(k,j,i) = ( u(k,j,i+1) - u(k,j,i) ) * ddx + & |
---|
| 693 | ( v(k,j+1,i) - v(k,j,i) ) * ddy + & |
---|
| 694 | ( w(k,j,i) - w(k-1,j,i) ) * ddzw(k) |
---|
| 695 | threadsum = threadsum + ABS( d(k,j,i) ) |
---|
| 696 | ENDDO |
---|
| 697 | ENDDO |
---|
| 698 | ENDDO |
---|
| 699 | #endif |
---|
[667] | 700 | |
---|
[1] | 701 | localsum = localsum + threadsum |
---|
| 702 | !$OMP END PARALLEL |
---|
| 703 | |
---|
| 704 | ! |
---|
| 705 | !-- For completeness, set the divergence sum of all statistic regions to those |
---|
| 706 | !-- of the total domain |
---|
| 707 | sums_divnew_l(0:statistic_regions) = localsum |
---|
| 708 | |
---|
| 709 | CALL cpu_log( log_point_s(1), 'divergence', 'stop' ) |
---|
| 710 | |
---|
| 711 | CALL cpu_log( log_point(8), 'pres', 'stop' ) |
---|
[667] | 712 | |
---|
[1] | 713 | |
---|
| 714 | |
---|
| 715 | END SUBROUTINE pres |
---|