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

Last change on this file since 1053 was 1053, checked in by hoffmann, 12 years ago

two-moment cloud physics implemented

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