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