[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 | ! |
---|
[1] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
[3] | 25 | ! $Id: timestep.f90 1054 2012-11-13 17:30:09Z raasch $ |
---|
[110] | 26 | ! |
---|
[1054] | 27 | ! 1053 2012-11-13 17:11:03Z hoffmann |
---|
| 28 | ! timestep is reduced in two-moment cloud scheme according to the maximum |
---|
| 29 | ! terminal velocity of rain drops |
---|
| 30 | ! |
---|
[1037] | 31 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 32 | ! code put under GPL (PALM 3.9) |
---|
| 33 | ! |
---|
[1002] | 34 | ! 1001 2012-09-13 14:08:46Z raasch |
---|
| 35 | ! all actions concerning leapfrog scheme removed |
---|
| 36 | ! |
---|
[979] | 37 | ! 978 2012-08-09 08:28:32Z fricke |
---|
| 38 | ! restriction of the outflow damping layer in the diffusion criterion removed |
---|
| 39 | ! |
---|
[867] | 40 | ! 866 2012-03-28 06:44:41Z raasch |
---|
| 41 | ! bugfix for timestep calculation in case of Galilei transformation, |
---|
| 42 | ! special treatment in case of mirror velocity boundary condition removed |
---|
| 43 | ! |
---|
[708] | 44 | ! 707 2011-03-29 11:39:40Z raasch |
---|
| 45 | ! bc_lr/ns replaced by bc_lr/ns_cyc |
---|
| 46 | ! |
---|
[668] | 47 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 48 | ! Exchange of terminate_coupled between ocean and atmosphere via PE0 |
---|
| 49 | ! Minimum grid spacing dxyz2_min(k) is now calculated using dzw instead of dzu |
---|
| 50 | ! |
---|
[623] | 51 | ! 622 2010-12-10 08:08:13Z raasch |
---|
| 52 | ! optional barriers included in order to speed up collective operations |
---|
| 53 | ! |
---|
[392] | 54 | ! 343 2009-06-24 12:59:09Z maronga |
---|
| 55 | ! Additional timestep criterion in case of simulations with plant canopy |
---|
| 56 | ! Output of messages replaced by message handling routine. |
---|
| 57 | ! |
---|
[226] | 58 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 59 | ! Implementation of a MPI-1 Coupling: replaced myid with target_id |
---|
| 60 | ! Bugfix for nonparallel execution |
---|
| 61 | ! |
---|
[110] | 62 | ! 108 2007-08-24 15:10:38Z letzel |
---|
| 63 | ! modifications to terminate coupled runs |
---|
| 64 | ! |
---|
[3] | 65 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 66 | ! |
---|
[1] | 67 | ! Revision 1.21 2006/02/23 12:59:44 raasch |
---|
| 68 | ! nt_anz renamed current_timestep_number |
---|
| 69 | ! |
---|
| 70 | ! Revision 1.1 1997/08/11 06:26:19 raasch |
---|
| 71 | ! Initial revision |
---|
| 72 | ! |
---|
| 73 | ! |
---|
| 74 | ! Description: |
---|
| 75 | ! ------------ |
---|
| 76 | ! Compute the time step under consideration of the FCL and diffusion criterion. |
---|
| 77 | !------------------------------------------------------------------------------! |
---|
| 78 | |
---|
| 79 | USE arrays_3d |
---|
[1053] | 80 | USE cloud_parameters |
---|
[1] | 81 | USE control_parameters |
---|
| 82 | USE cpulog |
---|
| 83 | USE grid_variables |
---|
| 84 | USE indices |
---|
| 85 | USE interfaces |
---|
| 86 | USE pegrid |
---|
| 87 | USE statistics |
---|
| 88 | |
---|
| 89 | IMPLICIT NONE |
---|
| 90 | |
---|
[866] | 91 | INTEGER :: i, j, k, u_max_cfl_ijk(3), v_max_cfl_ijk(3) |
---|
[1] | 92 | |
---|
[318] | 93 | REAL :: div, dt_diff, dt_diff_l, dt_plant_canopy, & |
---|
| 94 | dt_plant_canopy_l, & |
---|
| 95 | dt_plant_canopy_u, dt_plant_canopy_v, dt_plant_canopy_w, & |
---|
[1001] | 96 | dt_u, dt_v, dt_w, lad_max, & |
---|
[866] | 97 | u_gtrans_l, u_max_cfl, vabs_max, value, v_gtrans_l, v_max_cfl |
---|
[1] | 98 | |
---|
| 99 | REAL, DIMENSION(2) :: uv_gtrans, uv_gtrans_l |
---|
| 100 | REAL, DIMENSION(nzb+1:nzt) :: dxyz2_min |
---|
| 101 | |
---|
[667] | 102 | |
---|
| 103 | |
---|
[1] | 104 | CALL cpu_log( log_point(12), 'calculate_timestep', 'start' ) |
---|
| 105 | |
---|
| 106 | ! |
---|
| 107 | !-- In case of Galilei-transform not using the geostrophic wind as translation |
---|
| 108 | !-- velocity, compute the volume-averaged horizontal velocity components, which |
---|
| 109 | !-- will then be subtracted from the horizontal wind for the time step and |
---|
| 110 | !-- horizontal advection routines. |
---|
| 111 | IF ( galilei_transformation .AND. .NOT. use_ug_for_galilei_tr ) THEN |
---|
| 112 | IF ( flow_statistics_called ) THEN |
---|
| 113 | ! |
---|
| 114 | !-- Horizontal averages already existent, just need to average them |
---|
| 115 | !-- vertically. |
---|
| 116 | u_gtrans = 0.0 |
---|
| 117 | v_gtrans = 0.0 |
---|
| 118 | DO k = nzb+1, nzt |
---|
| 119 | u_gtrans = u_gtrans + hom(k,1,1,0) |
---|
| 120 | v_gtrans = v_gtrans + hom(k,1,2,0) |
---|
| 121 | ENDDO |
---|
| 122 | u_gtrans = u_gtrans / REAL( nzt - nzb ) |
---|
| 123 | v_gtrans = v_gtrans / REAL( nzt - nzb ) |
---|
| 124 | ELSE |
---|
| 125 | ! |
---|
| 126 | !-- Averaging over the entire model domain. |
---|
| 127 | uv_gtrans_l = 0.0 |
---|
| 128 | DO i = nxl, nxr |
---|
| 129 | DO j = nys, nyn |
---|
| 130 | DO k = nzb+1, nzt |
---|
| 131 | uv_gtrans_l(1) = uv_gtrans_l(1) + u(k,j,i) |
---|
| 132 | uv_gtrans_l(2) = uv_gtrans_l(2) + v(k,j,i) |
---|
| 133 | ENDDO |
---|
| 134 | ENDDO |
---|
| 135 | ENDDO |
---|
| 136 | uv_gtrans_l = uv_gtrans_l / REAL( (nxr-nxl+1)*(nyn-nys+1)*(nzt-nzb) ) |
---|
| 137 | #if defined( __parallel ) |
---|
[622] | 138 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 139 | CALL MPI_ALLREDUCE( uv_gtrans_l, uv_gtrans, 2, MPI_REAL, MPI_SUM, & |
---|
| 140 | comm2d, ierr ) |
---|
| 141 | u_gtrans = uv_gtrans(1) / REAL( numprocs ) |
---|
| 142 | v_gtrans = uv_gtrans(2) / REAL( numprocs ) |
---|
| 143 | #else |
---|
| 144 | u_gtrans = uv_gtrans_l(1) |
---|
| 145 | v_gtrans = uv_gtrans_l(2) |
---|
| 146 | #endif |
---|
| 147 | ENDIF |
---|
| 148 | ENDIF |
---|
| 149 | |
---|
[866] | 150 | ! |
---|
| 151 | !-- Determine the maxima of the velocity components. |
---|
| 152 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, u, 'abs', 0.0, & |
---|
| 153 | u_max, u_max_ijk ) |
---|
| 154 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, v, 'abs', 0.0, & |
---|
| 155 | v_max, v_max_ijk ) |
---|
| 156 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, w, 'abs', 0.0, & |
---|
| 157 | w_max, w_max_ijk ) |
---|
| 158 | |
---|
| 159 | ! |
---|
| 160 | !-- In case of Galilei transformation, the horizontal velocity maxima have |
---|
| 161 | !-- to be calculated from the transformed horizontal velocities |
---|
| 162 | IF ( galilei_transformation ) THEN |
---|
| 163 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, u, 'absoff', & |
---|
| 164 | u_gtrans, u_max_cfl, u_max_cfl_ijk ) |
---|
| 165 | CALL global_min_max( nzb, nzt+1, nysg, nyng, nxlg, nxrg, v, 'absoff', & |
---|
| 166 | v_gtrans, v_max_cfl, v_max_cfl_ijk ) |
---|
| 167 | ELSE |
---|
| 168 | u_max_cfl = u_max |
---|
| 169 | v_max_cfl = v_max |
---|
| 170 | u_max_cfl_ijk = u_max_ijk |
---|
| 171 | v_max_cfl_ijk = v_max_ijk |
---|
| 172 | ENDIF |
---|
| 173 | |
---|
| 174 | |
---|
[1] | 175 | IF ( .NOT. dt_fixed ) THEN |
---|
| 176 | ! |
---|
| 177 | !-- Variable time step: |
---|
| 178 | ! |
---|
| 179 | !-- For each component, compute the maximum time step according to the |
---|
[866] | 180 | !-- CFL-criterion. |
---|
| 181 | dt_u = dx / ( ABS( u_max_cfl ) + 1.0E-10 ) |
---|
| 182 | dt_v = dy / ( ABS( v_max_cfl ) + 1.0E-10 ) |
---|
[1] | 183 | dt_w = dzu(MAX( 1, w_max_ijk(1) )) / ( ABS( w_max ) + 1.0E-10 ) |
---|
| 184 | |
---|
| 185 | ! |
---|
| 186 | !-- Compute time step according to the diffusion criterion. |
---|
| 187 | !-- First calculate minimum grid spacing which only depends on index k |
---|
| 188 | !-- Note: also at k=nzb+1 a full grid length is being assumed, although |
---|
| 189 | !-- in the Prandtl-layer friction term only dz/2 is used. |
---|
| 190 | !-- Experience from the old model seems to justify this. |
---|
| 191 | dt_diff_l = 999999.0 |
---|
| 192 | |
---|
| 193 | DO k = nzb+1, nzt |
---|
[667] | 194 | dxyz2_min(k) = MIN( dx2, dy2, dzw(k)*dzw(k) ) * 0.125 |
---|
[1] | 195 | ENDDO |
---|
| 196 | |
---|
| 197 | !$OMP PARALLEL private(i,j,k,value) reduction(MIN: dt_diff_l) |
---|
| 198 | !$OMP DO |
---|
| 199 | DO i = nxl, nxr |
---|
| 200 | DO j = nys, nyn |
---|
| 201 | DO k = nzb+1, nzt |
---|
| 202 | value = dxyz2_min(k) / ( MAX( kh(k,j,i), km(k,j,i) ) + 1E-20 ) |
---|
| 203 | |
---|
| 204 | dt_diff_l = MIN( value, dt_diff_l ) |
---|
| 205 | ENDDO |
---|
| 206 | ENDDO |
---|
| 207 | ENDDO |
---|
| 208 | !$OMP END PARALLEL |
---|
| 209 | #if defined( __parallel ) |
---|
[622] | 210 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 211 | CALL MPI_ALLREDUCE( dt_diff_l, dt_diff, 1, MPI_REAL, MPI_MIN, comm2d, & |
---|
| 212 | ierr ) |
---|
| 213 | #else |
---|
| 214 | dt_diff = dt_diff_l |
---|
| 215 | #endif |
---|
| 216 | |
---|
| 217 | ! |
---|
[316] | 218 | !-- Additional timestep criterion with plant canopies: |
---|
| 219 | !-- it is not allowed to extract more than the available momentum |
---|
| 220 | IF ( plant_canopy ) THEN |
---|
[318] | 221 | |
---|
| 222 | dt_plant_canopy_l = 0.0 |
---|
| 223 | DO i = nxl, nxr |
---|
| 224 | DO j = nys, nyn |
---|
| 225 | DO k = nzb+1, nzt |
---|
| 226 | dt_plant_canopy_u = cdc(k,j,i) * lad_u(k,j,i) * & |
---|
| 227 | SQRT( u(k,j,i)**2 + & |
---|
| 228 | ( ( v(k,j,i-1) + & |
---|
| 229 | v(k,j,i) + & |
---|
| 230 | v(k,j+1,i) + & |
---|
| 231 | v(k,j+1,i-1) ) & |
---|
| 232 | / 4.0 )**2 + & |
---|
| 233 | ( ( w(k-1,j,i-1) + & |
---|
| 234 | w(k-1,j,i) + & |
---|
| 235 | w(k,j,i-1) + & |
---|
| 236 | w(k,j,i) ) & |
---|
| 237 | / 4.0 )**2 ) |
---|
| 238 | IF ( dt_plant_canopy_u > dt_plant_canopy_l ) THEN |
---|
| 239 | dt_plant_canopy_l = dt_plant_canopy_u |
---|
| 240 | ENDIF |
---|
| 241 | dt_plant_canopy_v = cdc(k,j,i) * lad_v(k,j,i) * & |
---|
| 242 | SQRT( ( ( u(k,j-1,i) + & |
---|
| 243 | u(k,j-1,i+1) + & |
---|
| 244 | u(k,j,i) + & |
---|
| 245 | u(k,j,i+1) ) & |
---|
| 246 | / 4.0 )**2 + & |
---|
| 247 | v(k,j,i)**2 + & |
---|
| 248 | ( ( w(k-1,j-1,i) + & |
---|
| 249 | w(k-1,j,i) + & |
---|
| 250 | w(k,j-1,i) + & |
---|
| 251 | w(k,j,i) ) & |
---|
| 252 | / 4.0 )**2 ) |
---|
| 253 | IF ( dt_plant_canopy_v > dt_plant_canopy_l ) THEN |
---|
| 254 | dt_plant_canopy_l = dt_plant_canopy_v |
---|
| 255 | ENDIF |
---|
| 256 | dt_plant_canopy_w = cdc(k,j,i) * lad_w(k,j,i) * & |
---|
| 257 | SQRT( ( ( u(k,j,i) + & |
---|
| 258 | u(k,j,i+1) + & |
---|
| 259 | u(k+1,j,i) + & |
---|
| 260 | u(k+1,j,i+1) ) & |
---|
| 261 | / 4.0 )**2 + & |
---|
| 262 | ( ( v(k,j,i) + & |
---|
| 263 | v(k,j+1,i) + & |
---|
| 264 | v(k+1,j,i) + & |
---|
| 265 | v(k+1,j+1,i) ) & |
---|
| 266 | / 4.0 )**2 + & |
---|
| 267 | w(k,j,i)**2 ) |
---|
| 268 | IF ( dt_plant_canopy_w > dt_plant_canopy_l ) THEN |
---|
| 269 | dt_plant_canopy_l = dt_plant_canopy_w |
---|
| 270 | ENDIF |
---|
| 271 | ENDDO |
---|
| 272 | ENDDO |
---|
| 273 | ENDDO |
---|
| 274 | |
---|
| 275 | IF ( dt_plant_canopy_l > 0.0 ) THEN |
---|
[320] | 276 | ! |
---|
| 277 | !-- Invert dt_plant_canopy_l and apply a security timestep factor 0.1 |
---|
[318] | 278 | dt_plant_canopy_l = 0.1 / dt_plant_canopy_l |
---|
[320] | 279 | ELSE |
---|
| 280 | ! |
---|
| 281 | !-- In case of inhomogeneous plant canopy, some processors may have no |
---|
| 282 | !-- canopy at all. Then use dt_max as dummy instead. |
---|
| 283 | dt_plant_canopy_l = dt_max |
---|
[318] | 284 | ENDIF |
---|
[320] | 285 | |
---|
[316] | 286 | ! |
---|
[318] | 287 | !-- Determine the global minumum |
---|
| 288 | #if defined( __parallel ) |
---|
[622] | 289 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[866] | 290 | CALL MPI_ALLREDUCE( dt_plant_canopy_l, dt_plant_canopy, 1, MPI_REAL, & |
---|
[318] | 291 | MPI_MIN, comm2d, ierr ) |
---|
| 292 | #else |
---|
| 293 | dt_plant_canopy = dt_plant_canopy_l |
---|
| 294 | #endif |
---|
[316] | 295 | |
---|
| 296 | ELSE |
---|
| 297 | ! |
---|
| 298 | !-- Use dt_diff as dummy value to avoid extra IF branches further below |
---|
| 299 | dt_plant_canopy = dt_diff |
---|
| 300 | |
---|
| 301 | ENDIF |
---|
| 302 | |
---|
| 303 | ! |
---|
| 304 | !-- The time step is the minimum of the 3-4 components and the diffusion time |
---|
[1001] | 305 | !-- step minus a reduction (cfl_factor) to be on the safe side. |
---|
[1] | 306 | !-- The time step must not exceed the maximum allowed value. |
---|
[1053] | 307 | dt_3d = cfl_factor * MIN( dt_diff, dt_plant_canopy, dt_u, dt_v, dt_w, & |
---|
| 308 | dt_precipitation ) |
---|
[1] | 309 | dt_3d = MIN( dt_3d, dt_max ) |
---|
| 310 | |
---|
| 311 | ! |
---|
| 312 | !-- Remember the restricting time step criterion for later output. |
---|
[316] | 313 | IF ( MIN( dt_u, dt_v, dt_w ) < MIN( dt_diff, dt_plant_canopy ) ) THEN |
---|
[1] | 314 | timestep_reason = 'A' |
---|
[316] | 315 | ELSEIF ( dt_plant_canopy < dt_diff ) THEN |
---|
| 316 | timestep_reason = 'C' |
---|
[1] | 317 | ELSE |
---|
| 318 | timestep_reason = 'D' |
---|
| 319 | ENDIF |
---|
| 320 | |
---|
| 321 | ! |
---|
| 322 | !-- Set flag if the time step becomes too small. |
---|
| 323 | IF ( dt_3d < ( 0.00001 * dt_max ) ) THEN |
---|
| 324 | stop_dt = .TRUE. |
---|
[108] | 325 | |
---|
[320] | 326 | WRITE( message_string, * ) 'Time step has reached minimum limit.', & |
---|
| 327 | '&dt = ', dt_3d, ' s Simulation is terminated.', & |
---|
| 328 | '&old_dt = ', old_dt, ' s', & |
---|
| 329 | '&dt_u = ', dt_u, ' s', & |
---|
| 330 | '&dt_v = ', dt_v, ' s', & |
---|
| 331 | '&dt_w = ', dt_w, ' s', & |
---|
| 332 | '&dt_diff = ', dt_diff, ' s', & |
---|
| 333 | '&dt_plant_canopy = ', dt_plant_canopy, ' s', & |
---|
[866] | 334 | '&u_max_cfl = ', u_max_cfl, ' m/s k=', u_max_cfl_ijk(1), & |
---|
[320] | 335 | ' j=', u_max_ijk(2), ' i=', u_max_ijk(3), & |
---|
[866] | 336 | '&v_max_cfl = ', v_max_cfl, ' m/s k=', v_max_cfl_ijk(1), & |
---|
[320] | 337 | ' j=', v_max_ijk(2), ' i=', v_max_ijk(3), & |
---|
[866] | 338 | '&w_max = ', w_max, ' m/s k=', w_max_ijk(1), & |
---|
[320] | 339 | ' j=', w_max_ijk(2), ' i=', w_max_ijk(3) |
---|
[258] | 340 | CALL message( 'timestep', 'PA0312', 0, 1, 0, 6, 0 ) |
---|
[108] | 341 | ! |
---|
| 342 | !-- In case of coupled runs inform the remote model of the termination |
---|
| 343 | !-- and its reason, provided the remote model has not already been |
---|
| 344 | !-- informed of another termination reason (terminate_coupled > 0) before. |
---|
[222] | 345 | #if defined( __parallel ) |
---|
[108] | 346 | IF ( coupling_mode /= 'uncoupled' .AND. terminate_coupled == 0 ) THEN |
---|
| 347 | terminate_coupled = 2 |
---|
[667] | 348 | IF ( myid == 0 ) THEN |
---|
| 349 | CALL MPI_SENDRECV( & |
---|
| 350 | terminate_coupled, 1, MPI_INTEGER, target_id, 0, & |
---|
| 351 | terminate_coupled_remote, 1, MPI_INTEGER, target_id, 0, & |
---|
| 352 | comm_inter, status, ierr ) |
---|
| 353 | ENDIF |
---|
| 354 | CALL MPI_BCAST( terminate_coupled_remote, 1, MPI_INTEGER, 0, comm2d, ierr) |
---|
[108] | 355 | ENDIF |
---|
[222] | 356 | #endif |
---|
[1] | 357 | ENDIF |
---|
| 358 | |
---|
| 359 | ! |
---|
[1001] | 360 | !-- Ensure a smooth value (two significant digits) of the timestep. |
---|
| 361 | div = 1000.0 |
---|
| 362 | DO WHILE ( dt_3d < div ) |
---|
| 363 | div = div / 10.0 |
---|
| 364 | ENDDO |
---|
| 365 | dt_3d = NINT( dt_3d * 100.0 / div ) * div / 100.0 |
---|
[1] | 366 | |
---|
| 367 | ! |
---|
[1001] | 368 | !-- Adjust the time step |
---|
| 369 | old_dt = dt_3d |
---|
[1] | 370 | |
---|
[1001] | 371 | ENDIF |
---|
[1] | 372 | |
---|
| 373 | CALL cpu_log( log_point(12), 'calculate_timestep', 'stop' ) |
---|
| 374 | |
---|
| 375 | END SUBROUTINE timestep |
---|