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