source: palm/trunk/SOURCE/timestep.f90 @ 1092

Last change on this file since 1092 was 1092, checked in by raasch, 11 years ago

unused variables remove from several routines

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