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