[1] | 1 | SUBROUTINE timestep |
---|
| 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 | ! |
---|
| 17 | ! Copyright 1997-2012 Leibniz University Hannover |
---|
| 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[258] | 20 | ! Current revisions: |
---|
[866] | 21 | ! ------------------ |
---|
[316] | 22 | ! |
---|
[1258] | 23 | ! |
---|
[1] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
[3] | 26 | ! $Id: timestep.f90 1258 2013-11-08 16:09:09Z heinze $ |
---|
[110] | 27 | ! |
---|
[1258] | 28 | ! 1257 2013-11-08 15:18:40Z raasch |
---|
| 29 | ! openacc porting |
---|
| 30 | ! bugfix for calculation of advective timestep in case of vertically stretched |
---|
| 31 | ! grids |
---|
| 32 | ! |
---|
[1093] | 33 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 34 | ! unused variables removed |
---|
| 35 | ! |
---|
[1054] | 36 | ! 1053 2012-11-13 17:11:03Z hoffmann |
---|
| 37 | ! timestep is reduced in two-moment cloud scheme according to the maximum |
---|
| 38 | ! terminal velocity of rain drops |
---|
| 39 | ! |
---|
[1037] | 40 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 41 | ! code put under GPL (PALM 3.9) |
---|
| 42 | ! |
---|
[1002] | 43 | ! 1001 2012-09-13 14:08:46Z raasch |
---|
| 44 | ! all actions concerning leapfrog scheme removed |
---|
| 45 | ! |
---|
[979] | 46 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 47 | ! restriction of the outflow damping layer in the diffusion criterion removed |
---|
| 48 | ! |
---|
[867] | 49 | ! 866 2012-03-28 06:44:41Z raasch |
---|
| 50 | ! bugfix for timestep calculation in case of Galilei transformation, |
---|
| 51 | ! special treatment in case of mirror velocity boundary condition removed |
---|
| 52 | ! |
---|
[708] | 53 | ! 707 2011-03-29 11:39:40Z raasch |
---|
| 54 | ! bc_lr/ns replaced by bc_lr/ns_cyc |
---|
| 55 | ! |
---|
[668] | 56 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 57 | ! Exchange of terminate_coupled between ocean and atmosphere via PE0 |
---|
| 58 | ! Minimum grid spacing dxyz2_min(k) is now calculated using dzw instead of dzu |
---|
| 59 | ! |
---|
[623] | 60 | ! 622 2010-12-10 08:08:13Z raasch |
---|
| 61 | ! optional barriers included in order to speed up collective operations |
---|
| 62 | ! |
---|
[392] | 63 | ! 343 2009-06-24 12:59:09Z maronga |
---|
| 64 | ! Additional timestep criterion in case of simulations with plant canopy |
---|
| 65 | ! Output of messages replaced by message handling routine. |
---|
| 66 | ! |
---|
[226] | 67 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 68 | ! Implementation of a MPI-1 Coupling: replaced myid with target_id |
---|
| 69 | ! Bugfix for nonparallel execution |
---|
| 70 | ! |
---|
[110] | 71 | ! 108 2007-08-24 15:10:38Z letzel |
---|
| 72 | ! modifications to terminate coupled runs |
---|
| 73 | ! |
---|
[3] | 74 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 75 | ! |
---|
[1] | 76 | ! Revision 1.21 2006/02/23 12:59:44 raasch |
---|
| 77 | ! nt_anz renamed current_timestep_number |
---|
| 78 | ! |
---|
| 79 | ! Revision 1.1 1997/08/11 06:26:19 raasch |
---|
| 80 | ! Initial revision |
---|
| 81 | ! |
---|
| 82 | ! |
---|
| 83 | ! Description: |
---|
| 84 | ! ------------ |
---|
| 85 | ! Compute the time step under consideration of the FCL and diffusion criterion. |
---|
| 86 | !------------------------------------------------------------------------------! |
---|
| 87 | |
---|
| 88 | USE arrays_3d |
---|
[1053] | 89 | USE cloud_parameters |
---|
[1] | 90 | USE control_parameters |
---|
| 91 | USE cpulog |
---|
| 92 | USE grid_variables |
---|
| 93 | USE indices |
---|
| 94 | USE interfaces |
---|
| 95 | USE pegrid |
---|
| 96 | USE statistics |
---|
| 97 | |
---|
| 98 | IMPLICIT NONE |
---|
| 99 | |
---|
[1257] | 100 | INTEGER :: i, j, k |
---|
[1] | 101 | |
---|
[1257] | 102 | REAL :: div, dt_diff, dt_diff_l, dt_plant_canopy, dt_plant_canopy_l, & |
---|
| 103 | dt_plant_canopy_u, dt_plant_canopy_v, dt_plant_canopy_w, & |
---|
| 104 | dt_u, dt_u_l, dt_v, dt_v_l, dt_w, dt_w_l, u_gtrans_l, u_max_l, & |
---|
| 105 | u_min_l, value, v_gtrans_l, v_max_l, v_min_l, w_max_l, w_min_l |
---|
[1] | 106 | |
---|
| 107 | REAL, DIMENSION(2) :: uv_gtrans, uv_gtrans_l |
---|
[1257] | 108 | REAL, DIMENSION(3) :: reduce, reduce_l |
---|
[1] | 109 | REAL, DIMENSION(nzb+1:nzt) :: dxyz2_min |
---|
| 110 | |
---|
[667] | 111 | |
---|
| 112 | |
---|
[1] | 113 | CALL cpu_log( log_point(12), 'calculate_timestep', 'start' ) |
---|
| 114 | |
---|
| 115 | ! |
---|
| 116 | !-- In case of Galilei-transform not using the geostrophic wind as translation |
---|
| 117 | !-- velocity, compute the volume-averaged horizontal velocity components, which |
---|
| 118 | !-- will then be subtracted from the horizontal wind for the time step and |
---|
| 119 | !-- horizontal advection routines. |
---|
| 120 | IF ( galilei_transformation .AND. .NOT. use_ug_for_galilei_tr ) THEN |
---|
| 121 | IF ( flow_statistics_called ) THEN |
---|
| 122 | ! |
---|
| 123 | !-- Horizontal averages already existent, just need to average them |
---|
| 124 | !-- vertically. |
---|
| 125 | u_gtrans = 0.0 |
---|
| 126 | v_gtrans = 0.0 |
---|
| 127 | DO k = nzb+1, nzt |
---|
| 128 | u_gtrans = u_gtrans + hom(k,1,1,0) |
---|
| 129 | v_gtrans = v_gtrans + hom(k,1,2,0) |
---|
| 130 | ENDDO |
---|
| 131 | u_gtrans = u_gtrans / REAL( nzt - nzb ) |
---|
| 132 | v_gtrans = v_gtrans / REAL( nzt - nzb ) |
---|
| 133 | ELSE |
---|
| 134 | ! |
---|
| 135 | !-- Averaging over the entire model domain. |
---|
[1257] | 136 | u_gtrans_l = 0.0 |
---|
| 137 | v_gtrans_l = 0.0 |
---|
| 138 | !$acc parallel present( u, v ) |
---|
[1] | 139 | DO i = nxl, nxr |
---|
| 140 | DO j = nys, nyn |
---|
| 141 | DO k = nzb+1, nzt |
---|
[1257] | 142 | u_gtrans_l = u_gtrans_l + u(k,j,i) |
---|
| 143 | v_gtrans_l = v_gtrans_l + v(k,j,i) |
---|
[1] | 144 | ENDDO |
---|
| 145 | ENDDO |
---|
| 146 | ENDDO |
---|
[1257] | 147 | !$acc end parallel |
---|
| 148 | uv_gtrans_l(1) = u_gtrans_l / REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb) ) |
---|
| 149 | uv_gtrans_l(2) = v_gtrans_l / REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb) ) |
---|
[1] | 150 | #if defined( __parallel ) |
---|
[622] | 151 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 152 | CALL MPI_ALLREDUCE( uv_gtrans_l, uv_gtrans, 2, MPI_REAL, MPI_SUM, & |
---|
| 153 | comm2d, ierr ) |
---|
| 154 | u_gtrans = uv_gtrans(1) / REAL( numprocs ) |
---|
| 155 | v_gtrans = uv_gtrans(2) / REAL( numprocs ) |
---|
| 156 | #else |
---|
| 157 | u_gtrans = uv_gtrans_l(1) |
---|
| 158 | v_gtrans = uv_gtrans_l(2) |
---|
| 159 | #endif |
---|
| 160 | ENDIF |
---|
| 161 | ENDIF |
---|
| 162 | |
---|
[866] | 163 | ! |
---|
[1257] | 164 | !-- Determine the maxima of the velocity components, including their |
---|
| 165 | !-- grid index positions. |
---|
| 166 | #if defined( __openacc ) |
---|
| 167 | IF ( dt_fixed ) THEN ! otherwise do it further below for better cache usage |
---|
| 168 | u_max_l = -999999.9 |
---|
| 169 | u_min_l = 999999.9 |
---|
| 170 | v_max_l = -999999.9 |
---|
| 171 | v_min_l = 999999.9 |
---|
| 172 | w_max_l = -999999.9 |
---|
| 173 | w_min_l = 999999.9 |
---|
| 174 | !$acc parallel present( u, v, w ) |
---|
| 175 | DO i = nxl, nxr |
---|
| 176 | DO j = nys, nyn |
---|
| 177 | DO k = nzb+1, nzt |
---|
| 178 | u_max_l = MAX( u_max_l, u(k,j,i) ) |
---|
| 179 | u_min_l = MIN( u_min_l, u(k,j,i) ) |
---|
| 180 | v_max_l = MAX( v_max_l, v(k,j,i) ) |
---|
| 181 | v_min_l = MIN( v_min_l, v(k,j,i) ) |
---|
| 182 | w_max_l = MAX( w_max_l, w(k,j,i) ) |
---|
| 183 | w_min_l = MIN( w_min_l, w(k,j,i) ) |
---|
| 184 | ENDDO |
---|
| 185 | ENDDO |
---|
| 186 | ENDDO |
---|
| 187 | !$acc end parallel |
---|
| 188 | #if defined( __parallel ) |
---|
| 189 | reduce_l(1) = u_max_l |
---|
| 190 | reduce_l(2) = v_max_l |
---|
| 191 | reduce_l(3) = w_max_l |
---|
| 192 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 193 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MAX, comm2d, ierr ) |
---|
| 194 | u_max = reduce(1) |
---|
| 195 | v_max = reduce(2) |
---|
| 196 | w_max = reduce(3) |
---|
| 197 | reduce_l(1) = u_min_l |
---|
| 198 | reduce_l(2) = v_min_l |
---|
| 199 | reduce_l(3) = w_min_l |
---|
| 200 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 201 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MIN, comm2d, ierr ) |
---|
| 202 | IF ( ABS( reduce(1) ) > u_max ) u_max = reduce(1) |
---|
| 203 | IF ( ABS( reduce(2) ) > v_max ) v_max = reduce(2) |
---|
| 204 | IF ( ABS( reduce(3) ) > w_max ) w_max = reduce(3) |
---|
| 205 | #else |
---|
| 206 | IF ( ABS( u_min_l ) > u_max_l ) THEN |
---|
| 207 | u_max = u_min_l |
---|
| 208 | ELSE |
---|
| 209 | u_max = u_max_l |
---|
| 210 | ENDIF |
---|
| 211 | IF ( ABS( v_min_l ) > v_max_l ) THEN |
---|
| 212 | v_max = v_min_l |
---|
| 213 | ELSE |
---|
| 214 | v_max = v_max_l |
---|
| 215 | ENDIF |
---|
| 216 | IF ( ABS( w_min_l ) > w_max_l ) THEN |
---|
| 217 | w_max = w_min_l |
---|
| 218 | ELSE |
---|
| 219 | w_max = w_max_l |
---|
| 220 | ENDIF |
---|
| 221 | #endif |
---|
| 222 | ENDIF |
---|
| 223 | #else |
---|
[866] | 224 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, u, 'abs', 0.0, & |
---|
| 225 | u_max, u_max_ijk ) |
---|
| 226 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, v, 'abs', 0.0, & |
---|
| 227 | v_max, v_max_ijk ) |
---|
| 228 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, w, 'abs', 0.0, & |
---|
| 229 | w_max, w_max_ijk ) |
---|
[1257] | 230 | #endif |
---|
[866] | 231 | |
---|
[1257] | 232 | IF ( .NOT. dt_fixed ) THEN |
---|
| 233 | #if defined( __openacc ) |
---|
[866] | 234 | ! |
---|
[1257] | 235 | !-- Variable time step: |
---|
| 236 | !-- Calculate the maximum time step according to the CFL-criterion, |
---|
| 237 | !-- individually for each velocity component |
---|
| 238 | dt_u_l = 999999.9 |
---|
| 239 | dt_v_l = 999999.9 |
---|
| 240 | dt_w_l = 999999.9 |
---|
| 241 | u_max_l = -999999.9 |
---|
| 242 | u_min_l = 999999.9 |
---|
| 243 | v_max_l = -999999.9 |
---|
| 244 | v_min_l = 999999.9 |
---|
| 245 | w_max_l = -999999.9 |
---|
| 246 | w_min_l = 999999.9 |
---|
| 247 | !$acc parallel loop collapse(3) present( u, v, w ) |
---|
| 248 | DO i = nxl, nxr |
---|
| 249 | DO j = nys, nyn |
---|
| 250 | DO k = nzb+1, nzt |
---|
| 251 | dt_u_l = MIN( dt_u_l, ( dx / ( ABS( u(k,j,i) - u_gtrans ) + 1.0E-10 ) ) ) |
---|
| 252 | dt_v_l = MIN( dt_v_l, ( dy / ( ABS( v(k,j,i) - v_gtrans ) + 1.0E-10 ) ) ) |
---|
| 253 | dt_w_l = MIN( dt_w_l, ( dzu(k) / ( ABS( w(k,j,i) ) + 1.0E-10 ) ) ) |
---|
| 254 | u_max_l = MAX( u_max_l, u(k,j,i) ) |
---|
| 255 | u_min_l = MIN( u_min_l, u(k,j,i) ) |
---|
| 256 | v_max_l = MAX( v_max_l, v(k,j,i) ) |
---|
| 257 | v_min_l = MIN( v_min_l, v(k,j,i) ) |
---|
| 258 | w_max_l = MAX( w_max_l, w(k,j,i) ) |
---|
| 259 | w_min_l = MIN( w_min_l, w(k,j,i) ) |
---|
| 260 | ENDDO |
---|
| 261 | ENDDO |
---|
| 262 | ENDDO |
---|
| 263 | !$acc end parallel |
---|
[866] | 264 | |
---|
[1257] | 265 | #if defined( __parallel ) |
---|
| 266 | reduce_l(1) = dt_u_l |
---|
| 267 | reduce_l(2) = dt_v_l |
---|
| 268 | reduce_l(3) = dt_w_l |
---|
| 269 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 270 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MIN, comm2d, ierr ) |
---|
| 271 | dt_u = reduce(1) |
---|
| 272 | dt_v = reduce(2) |
---|
| 273 | dt_w = reduce(3) |
---|
[866] | 274 | |
---|
[1257] | 275 | reduce_l(1) = u_max_l |
---|
| 276 | reduce_l(2) = v_max_l |
---|
| 277 | reduce_l(3) = w_max_l |
---|
| 278 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 279 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MAX, comm2d, ierr ) |
---|
| 280 | u_max = reduce(1) |
---|
| 281 | v_max = reduce(2) |
---|
| 282 | w_max = reduce(3) |
---|
| 283 | reduce_l(1) = u_min_l |
---|
| 284 | reduce_l(2) = v_min_l |
---|
| 285 | reduce_l(3) = w_min_l |
---|
| 286 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 287 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MIN, comm2d, ierr ) |
---|
| 288 | IF ( ABS( reduce(1) ) > u_max ) u_max = reduce(1) |
---|
| 289 | IF ( ABS( reduce(2) ) > v_max ) v_max = reduce(2) |
---|
| 290 | IF ( ABS( reduce(3) ) > w_max ) w_max = reduce(3) |
---|
| 291 | #else |
---|
| 292 | dt_u = dt_u_l |
---|
| 293 | dt_v = dt_v_l |
---|
| 294 | dt_w = dt_w_l |
---|
| 295 | |
---|
| 296 | IF ( ABS( u_min_l ) > u_max_l ) THEN |
---|
| 297 | u_max = u_min_l |
---|
| 298 | ELSE |
---|
| 299 | u_max = u_max_l |
---|
| 300 | ENDIF |
---|
| 301 | IF ( ABS( v_min_l ) > v_max_l ) THEN |
---|
| 302 | v_max = v_min_l |
---|
| 303 | ELSE |
---|
| 304 | v_max = v_max_l |
---|
| 305 | ENDIF |
---|
| 306 | IF ( ABS( w_min_l ) > w_max_l ) THEN |
---|
| 307 | w_max = w_min_l |
---|
| 308 | ELSE |
---|
| 309 | w_max = w_max_l |
---|
| 310 | ENDIF |
---|
| 311 | #endif |
---|
| 312 | |
---|
| 313 | #else |
---|
[1] | 314 | ! |
---|
| 315 | !-- Variable time step: |
---|
[1257] | 316 | !-- Calculate the maximum time step according to the CFL-criterion, |
---|
| 317 | !-- individually for each velocity component |
---|
| 318 | dt_u_l = 999999.9 |
---|
| 319 | dt_v_l = 999999.9 |
---|
| 320 | dt_w_l = 999999.9 |
---|
| 321 | DO i = nxl, nxr |
---|
| 322 | DO j = nys, nyn |
---|
| 323 | DO k = nzb+1, nzt |
---|
| 324 | dt_u_l = MIN( dt_u_l, ( dx / ( ABS( u(k,j,i) - u_gtrans ) + 1.0E-10 ) ) ) |
---|
| 325 | dt_v_l = MIN( dt_v_l, ( dy / ( ABS( v(k,j,i) - v_gtrans ) + 1.0E-10 ) ) ) |
---|
| 326 | dt_w_l = MIN( dt_w_l, ( dzu(k) / ( ABS( w(k,j,i) ) + 1.0E-10 ) ) ) |
---|
| 327 | ENDDO |
---|
| 328 | ENDDO |
---|
| 329 | ENDDO |
---|
[1] | 330 | |
---|
[1257] | 331 | #if defined( __parallel ) |
---|
| 332 | reduce_l(1) = dt_u_l |
---|
| 333 | reduce_l(2) = dt_v_l |
---|
| 334 | reduce_l(3) = dt_w_l |
---|
| 335 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 336 | CALL MPI_ALLREDUCE( reduce_l, reduce, 3, MPI_REAL, MPI_MIN, comm2d, ierr ) |
---|
| 337 | dt_u = reduce(1) |
---|
| 338 | dt_v = reduce(2) |
---|
| 339 | dt_w = reduce(3) |
---|
| 340 | #else |
---|
| 341 | dt_u = dt_u_l |
---|
| 342 | dt_v = dt_v_l |
---|
| 343 | dt_w = dt_w_l |
---|
| 344 | #endif |
---|
| 345 | |
---|
| 346 | #endif |
---|
| 347 | |
---|
[1] | 348 | ! |
---|
| 349 | !-- Compute time step according to the diffusion criterion. |
---|
| 350 | !-- First calculate minimum grid spacing which only depends on index k |
---|
| 351 | !-- Note: also at k=nzb+1 a full grid length is being assumed, although |
---|
| 352 | !-- in the Prandtl-layer friction term only dz/2 is used. |
---|
| 353 | !-- Experience from the old model seems to justify this. |
---|
| 354 | dt_diff_l = 999999.0 |
---|
| 355 | |
---|
| 356 | DO k = nzb+1, nzt |
---|
[667] | 357 | dxyz2_min(k) = MIN( dx2, dy2, dzw(k)*dzw(k) ) * 0.125 |
---|
[1] | 358 | ENDDO |
---|
| 359 | |
---|
| 360 | !$OMP PARALLEL private(i,j,k,value) reduction(MIN: dt_diff_l) |
---|
| 361 | !$OMP DO |
---|
[1257] | 362 | !$acc parallel loop collapse(3) present( kh, km ) |
---|
[1] | 363 | DO i = nxl, nxr |
---|
| 364 | DO j = nys, nyn |
---|
| 365 | DO k = nzb+1, nzt |
---|
[1257] | 366 | dt_diff_l = MIN( dt_diff_l, dxyz2_min(k) / & |
---|
| 367 | ( MAX( kh(k,j,i), km(k,j,i) ) + 1E-20 ) ) |
---|
[1] | 368 | ENDDO |
---|
| 369 | ENDDO |
---|
| 370 | ENDDO |
---|
[1257] | 371 | !$acc end parallel |
---|
[1] | 372 | !$OMP END PARALLEL |
---|
| 373 | #if defined( __parallel ) |
---|
[622] | 374 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 375 | CALL MPI_ALLREDUCE( dt_diff_l, dt_diff, 1, MPI_REAL, MPI_MIN, comm2d, & |
---|
| 376 | ierr ) |
---|
| 377 | #else |
---|
| 378 | dt_diff = dt_diff_l |
---|
| 379 | #endif |
---|
| 380 | |
---|
| 381 | ! |
---|
[316] | 382 | !-- Additional timestep criterion with plant canopies: |
---|
| 383 | !-- it is not allowed to extract more than the available momentum |
---|
| 384 | IF ( plant_canopy ) THEN |
---|
[318] | 385 | |
---|
| 386 | dt_plant_canopy_l = 0.0 |
---|
| 387 | DO i = nxl, nxr |
---|
| 388 | DO j = nys, nyn |
---|
| 389 | DO k = nzb+1, nzt |
---|
| 390 | dt_plant_canopy_u = cdc(k,j,i) * lad_u(k,j,i) * & |
---|
| 391 | SQRT( u(k,j,i)**2 + & |
---|
| 392 | ( ( v(k,j,i-1) + & |
---|
| 393 | v(k,j,i) + & |
---|
| 394 | v(k,j+1,i) + & |
---|
| 395 | v(k,j+1,i-1) ) & |
---|
| 396 | / 4.0 )**2 + & |
---|
| 397 | ( ( w(k-1,j,i-1) + & |
---|
| 398 | w(k-1,j,i) + & |
---|
| 399 | w(k,j,i-1) + & |
---|
| 400 | w(k,j,i) ) & |
---|
| 401 | / 4.0 )**2 ) |
---|
| 402 | IF ( dt_plant_canopy_u > dt_plant_canopy_l ) THEN |
---|
| 403 | dt_plant_canopy_l = dt_plant_canopy_u |
---|
| 404 | ENDIF |
---|
| 405 | dt_plant_canopy_v = cdc(k,j,i) * lad_v(k,j,i) * & |
---|
| 406 | SQRT( ( ( u(k,j-1,i) + & |
---|
| 407 | u(k,j-1,i+1) + & |
---|
| 408 | u(k,j,i) + & |
---|
| 409 | u(k,j,i+1) ) & |
---|
| 410 | / 4.0 )**2 + & |
---|
| 411 | v(k,j,i)**2 + & |
---|
| 412 | ( ( w(k-1,j-1,i) + & |
---|
| 413 | w(k-1,j,i) + & |
---|
| 414 | w(k,j-1,i) + & |
---|
| 415 | w(k,j,i) ) & |
---|
| 416 | / 4.0 )**2 ) |
---|
| 417 | IF ( dt_plant_canopy_v > dt_plant_canopy_l ) THEN |
---|
| 418 | dt_plant_canopy_l = dt_plant_canopy_v |
---|
| 419 | ENDIF |
---|
| 420 | dt_plant_canopy_w = cdc(k,j,i) * lad_w(k,j,i) * & |
---|
| 421 | SQRT( ( ( u(k,j,i) + & |
---|
| 422 | u(k,j,i+1) + & |
---|
| 423 | u(k+1,j,i) + & |
---|
| 424 | u(k+1,j,i+1) ) & |
---|
| 425 | / 4.0 )**2 + & |
---|
| 426 | ( ( v(k,j,i) + & |
---|
| 427 | v(k,j+1,i) + & |
---|
| 428 | v(k+1,j,i) + & |
---|
| 429 | v(k+1,j+1,i) ) & |
---|
| 430 | / 4.0 )**2 + & |
---|
| 431 | w(k,j,i)**2 ) |
---|
| 432 | IF ( dt_plant_canopy_w > dt_plant_canopy_l ) THEN |
---|
| 433 | dt_plant_canopy_l = dt_plant_canopy_w |
---|
| 434 | ENDIF |
---|
| 435 | ENDDO |
---|
| 436 | ENDDO |
---|
| 437 | ENDDO |
---|
| 438 | |
---|
| 439 | IF ( dt_plant_canopy_l > 0.0 ) THEN |
---|
[320] | 440 | ! |
---|
| 441 | !-- Invert dt_plant_canopy_l and apply a security timestep factor 0.1 |
---|
[318] | 442 | dt_plant_canopy_l = 0.1 / dt_plant_canopy_l |
---|
[320] | 443 | ELSE |
---|
| 444 | ! |
---|
| 445 | !-- In case of inhomogeneous plant canopy, some processors may have no |
---|
| 446 | !-- canopy at all. Then use dt_max as dummy instead. |
---|
| 447 | dt_plant_canopy_l = dt_max |
---|
[318] | 448 | ENDIF |
---|
[320] | 449 | |
---|
[316] | 450 | ! |
---|
[318] | 451 | !-- Determine the global minumum |
---|
| 452 | #if defined( __parallel ) |
---|
[622] | 453 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[866] | 454 | CALL MPI_ALLREDUCE( dt_plant_canopy_l, dt_plant_canopy, 1, MPI_REAL, & |
---|
[318] | 455 | MPI_MIN, comm2d, ierr ) |
---|
| 456 | #else |
---|
| 457 | dt_plant_canopy = dt_plant_canopy_l |
---|
| 458 | #endif |
---|
[316] | 459 | |
---|
| 460 | ELSE |
---|
| 461 | ! |
---|
| 462 | !-- Use dt_diff as dummy value to avoid extra IF branches further below |
---|
| 463 | dt_plant_canopy = dt_diff |
---|
| 464 | |
---|
| 465 | ENDIF |
---|
| 466 | |
---|
| 467 | ! |
---|
| 468 | !-- The time step is the minimum of the 3-4 components and the diffusion time |
---|
[1001] | 469 | !-- step minus a reduction (cfl_factor) to be on the safe side. |
---|
[1] | 470 | !-- The time step must not exceed the maximum allowed value. |
---|
[1053] | 471 | dt_3d = cfl_factor * MIN( dt_diff, dt_plant_canopy, dt_u, dt_v, dt_w, & |
---|
| 472 | dt_precipitation ) |
---|
[1] | 473 | dt_3d = MIN( dt_3d, dt_max ) |
---|
| 474 | |
---|
| 475 | ! |
---|
| 476 | !-- Remember the restricting time step criterion for later output. |
---|
[316] | 477 | IF ( MIN( dt_u, dt_v, dt_w ) < MIN( dt_diff, dt_plant_canopy ) ) THEN |
---|
[1] | 478 | timestep_reason = 'A' |
---|
[316] | 479 | ELSEIF ( dt_plant_canopy < dt_diff ) THEN |
---|
| 480 | timestep_reason = 'C' |
---|
[1] | 481 | ELSE |
---|
| 482 | timestep_reason = 'D' |
---|
| 483 | ENDIF |
---|
| 484 | |
---|
| 485 | ! |
---|
| 486 | !-- Set flag if the time step becomes too small. |
---|
| 487 | IF ( dt_3d < ( 0.00001 * dt_max ) ) THEN |
---|
| 488 | stop_dt = .TRUE. |
---|
[108] | 489 | |
---|
[320] | 490 | WRITE( message_string, * ) 'Time step has reached minimum limit.', & |
---|
| 491 | '&dt = ', dt_3d, ' s Simulation is terminated.', & |
---|
| 492 | '&old_dt = ', old_dt, ' s', & |
---|
| 493 | '&dt_u = ', dt_u, ' s', & |
---|
| 494 | '&dt_v = ', dt_v, ' s', & |
---|
| 495 | '&dt_w = ', dt_w, ' s', & |
---|
| 496 | '&dt_diff = ', dt_diff, ' s', & |
---|
| 497 | '&dt_plant_canopy = ', dt_plant_canopy, ' s', & |
---|
[1257] | 498 | '&u_max = ', u_max, ' m/s k=', u_max_ijk(1), & |
---|
[320] | 499 | ' j=', u_max_ijk(2), ' i=', u_max_ijk(3), & |
---|
[1257] | 500 | '&v_max = ', v_max, ' m/s k=', v_max_ijk(1), & |
---|
[320] | 501 | ' j=', v_max_ijk(2), ' i=', v_max_ijk(3), & |
---|
[1257] | 502 | '&w_max = ', w_max, ' m/s k=', w_max_ijk(1), & |
---|
[320] | 503 | ' j=', w_max_ijk(2), ' i=', w_max_ijk(3) |
---|
[258] | 504 | CALL message( 'timestep', 'PA0312', 0, 1, 0, 6, 0 ) |
---|
[108] | 505 | ! |
---|
| 506 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 507 | !-- and its reason, provided the remote model has not already been |
---|
| 508 | !-- informed of another termination reason (terminate_coupled > 0) before. |
---|
[222] | 509 | #if defined( __parallel ) |
---|
[108] | 510 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 ) THEN |
---|
| 511 | terminate_coupled = 2 |
---|
[667] | 512 | IF ( myid == 0 ) THEN |
---|
| 513 | CALL MPI_SENDRECV( & |
---|
| 514 | terminate_coupled, 1, MPI_INTEGER, target_id, 0, & |
---|
| 515 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, 0, & |
---|
| 516 | comm_inter, status, ierr ) |
---|
| 517 | ENDIF |
---|
| 518 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, ierr) |
---|
[108] | 519 | ENDIF |
---|
[222] | 520 | #endif |
---|
[1] | 521 | ENDIF |
---|
| 522 | |
---|
| 523 | ! |
---|
[1001] | 524 | !-- Ensure a smooth value (two significant digits) of the timestep. |
---|
| 525 | div = 1000.0 |
---|
| 526 | DO WHILE ( dt_3d < div ) |
---|
| 527 | div = div / 10.0 |
---|
| 528 | ENDDO |
---|
| 529 | dt_3d = NINT( dt_3d * 100.0 / div ) * div / 100.0 |
---|
[1] | 530 | |
---|
| 531 | ! |
---|
[1001] | 532 | !-- Adjust the time step |
---|
| 533 | old_dt = dt_3d |
---|
[1] | 534 | |
---|
[1001] | 535 | ENDIF |
---|
[1] | 536 | |
---|
| 537 | CALL cpu_log( log_point(12), 'calculate_timestep', 'stop' ) |
---|
| 538 | |
---|
| 539 | END SUBROUTINE timestep |
---|