source: palm/trunk/SOURCE/time_integration.f90 @ 221

Last change on this file since 221 was 198, checked in by raasch, 16 years ago

file headers updated for the next release 3.5

  • Property svn:keywords set to Id
File size: 18.6 KB
Line 
1 SUBROUTINE time_integration
2
3!------------------------------------------------------------------------------!
4! Actual revisions:
5! -----------------
6!
7!
8! Former revisions:
9! -----------------
10! $Id: time_integration.f90 198 2008-09-17 08:55:28Z raasch $
11!
12! 151 2008-03-07 13:42:18Z raasch
13! inflow turbulence is imposed by calling new routine inflow_turbulence
14!
15! 108 2007-08-24 15:10:38Z letzel
16! Call of new routine surface_coupler,
17! presure solver is called after the first Runge-Kutta substep instead of the
18! last in case that call_psolver_at_all_substeps = .F.; for this case, the
19! random perturbation has to be added to the velocity fields also after the
20! first substep
21!
22! 97 2007-06-21 08:23:15Z raasch
23! diffusivities is called with argument rho in case of ocean runs,
24! new argument pt_/prho_reference in calls of diffusivities,
25! ghostpoint exchange for salinity and density
26!
27! 87 2007-05-22 15:46:47Z raasch
28! var_hom renamed pr_palm
29!
30! 75 2007-03-22 09:54:05Z raasch
31! Move call of user_actions( 'after_integration' ) below increment of times
32! and counters,
33! calls of prognostic_equations_.. changed to .._noopt, .._cache, and
34! .._vector, these calls are now controlled by switch loop_optimization,
35! uxrp, vynp eliminated, 2nd+3rd argument removed from exchange horiz,
36! moisture renamed humidity
37!
38! RCS Log replace by Id keyword, revision history cleaned up
39!
40! Revision 1.8  2006/08/22 14:16:05  raasch
41! Disturbances are imposed only for the last Runge-Kutta-substep
42!
43! Revision 1.2  2004/04/30 13:03:40  raasch
44! decalpha-specific warning removed, routine name changed to time_integration,
45! particle advection is carried out only once during the intermediate steps,
46! impulse_advec renamed momentum_advec
47!
48! Revision 1.1  1997/08/11 06:19:04  raasch
49! Initial revision
50!
51!
52! Description:
53! ------------
54! Integration in time of the model equations, statistical analysis and graphic
55! output
56!------------------------------------------------------------------------------!
57
58    USE arrays_3d
59    USE averaging
60    USE control_parameters
61    USE cpulog
62#if defined( __dvrp_graphics )
63    USE DVRP
64#endif
65    USE grid_variables
66    USE indices
67    USE interaction_droplets_ptq_mod
68    USE interfaces
69    USE particle_attributes
70    USE pegrid
71    USE prognostic_equations_mod
72    USE statistics
73    USE user_actions_mod
74
75    IMPLICIT NONE
76
77    CHARACTER (LEN=9) ::  time_to_string
78    INTEGER ::  i, j, k
79
80!
81!-- At the beginning of a simulation determine the time step as well as
82!-- determine and print out the run control parameters
83    IF ( simulated_time == 0.0 )  CALL timestep
84    CALL run_control
85
86!
87!-- Data exchange between coupled models in case that a call has been omitted
88!-- at the end of the previous run of a job chain.
89    IF ( coupling_mode /= 'uncoupled' )  THEN
90!
91!--    In case of model termination initiated by the local model the coupler
92!--    must not be called because this would again cause an MPI hang.
93       DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
94          CALL surface_coupler
95          time_coupling = time_coupling - dt_coupling
96       ENDDO
97    ENDIF
98
99
100#if defined( __dvrp_graphics )
101!
102!-- Time measurement with dvrp software 
103    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
104#endif
105
106!
107!-- Start of the time loop
108    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
109                .NOT. terminate_run )
110
111       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
112
113!
114!--    Determine size of next time step
115       IF ( simulated_time /= 0.0 )  CALL timestep
116
117!
118!--    Execute the user-defined actions
119       CALL user_actions( 'before_timestep' )
120
121!
122!--    Start of intermediate step loop
123       intermediate_timestep_count = 0
124       DO  WHILE ( intermediate_timestep_count < &
125                   intermediate_timestep_count_max )
126
127          intermediate_timestep_count = intermediate_timestep_count + 1
128
129!
130!--       Set the steering factors for the prognostic equations which depend
131!--       on the timestep scheme
132          CALL timestep_scheme_steering
133
134!
135!--       Solve the prognostic equations. A fast cache optimized version with
136!--       only one single loop is used in case of Piascek-Williams advection
137!--       scheme. NEC vector machines use a different version, because
138!--       in the other versions a good vectorization is prohibited due to
139!--       inlining problems.
140          IF ( loop_optimization == 'vector' )  THEN
141             CALL prognostic_equations_vector
142          ELSE
143             IF ( momentum_advec == 'ups-scheme'  .OR.  &
144                  scalar_advec == 'ups-scheme'   .OR.  &
145                  scalar_advec == 'bc-scheme' )        &
146             THEN
147                CALL prognostic_equations_noopt
148             ELSE
149                CALL prognostic_equations_cache
150             ENDIF
151          ENDIF
152
153!
154!--       Particle advection (only once during intermediate steps, because
155!--       it uses an Euler-step)
156          IF ( particle_advection  .AND.                         &
157               simulated_time >= particle_advection_start  .AND. &
158               intermediate_timestep_count == 1 )  THEN
159             CALL advec_particles
160             first_call_advec_particles = .FALSE.
161          ENDIF
162
163!
164!--       Interaction of droplets with temperature and specific humidity.
165!--       Droplet condensation and evaporation is calculated within
166!--       advec_particles.
167          IF ( cloud_droplets  .AND.  &
168               intermediate_timestep_count == intermediate_timestep_count_max )&
169          THEN
170             CALL interaction_droplets_ptq
171          ENDIF
172
173!
174!--       Exchange of ghost points (lateral boundary conditions)
175          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
176          CALL exchange_horiz( u_p )
177          CALL exchange_horiz( v_p )
178          CALL exchange_horiz( w_p )
179          CALL exchange_horiz( pt_p )
180          IF ( .NOT. constant_diffusion       )  CALL exchange_horiz( e_p )
181          IF ( ocean )  THEN
182             CALL exchange_horiz( sa_p )
183             CALL exchange_horiz( rho )
184          ENDIF
185          IF ( humidity  .OR.  passive_scalar )  CALL exchange_horiz( q_p )
186          IF ( cloud_droplets )  THEN
187             CALL exchange_horiz( ql )
188             CALL exchange_horiz( ql_c )
189             CALL exchange_horiz( ql_v )
190             CALL exchange_horiz( ql_vp )
191          ENDIF
192
193          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
194
195!
196!--       Apply time filter in case of leap-frog timestep
197          IF ( tsc(2) == 2.0  .AND.  timestep_scheme(1:8) == 'leapfrog' )  THEN
198             CALL asselin_filter
199          ENDIF
200
201!
202!--       Boundary conditions for the prognostic quantities (except of the
203!--       velocities at the outflow in case of a non-cyclic lateral wall)
204          CALL boundary_conds( 'main' )
205
206!
207!--       Swap the time levels in preparation for the next time step.
208          CALL swap_timelevel
209
210!
211!--       Temperature offset must be imposed at cyclic boundaries in x-direction
212!--       when a sloping surface is used
213          IF ( sloping_surface )  THEN
214             IF ( nxl ==  0 )  pt(:,:,nxl-1) = pt(:,:,nxl-1) - pt_slope_offset
215             IF ( nxr == nx )  pt(:,:,nxr+1) = pt(:,:,nxr+1) + pt_slope_offset
216          ENDIF
217
218!
219!--       Impose a turbulent inflow using the recycling method
220          IF ( turbulent_inflow )  CALL  inflow_turbulence
221
222!
223!--       Impose a random perturbation on the horizontal velocity field
224          IF ( create_disturbances  .AND.                                      &
225               ( call_psolver_at_all_substeps  .AND.                           &
226               intermediate_timestep_count == intermediate_timestep_count_max )&
227          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
228               intermediate_timestep_count == 1 ) )                            &
229          THEN
230             time_disturb = time_disturb + dt_3d
231             IF ( time_disturb >= dt_disturb )  THEN
232                IF ( hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
233                   CALL disturb_field( nzb_u_inner, tend, u )
234                   CALL disturb_field( nzb_v_inner, tend, v )
235                ELSEIF ( bc_lr /= 'cyclic'  .OR.  bc_ns /= 'cyclic' )  THEN
236!
237!--                Runs with a non-cyclic lateral wall need perturbations
238!--                near the inflow throughout the whole simulation
239                   dist_range = 1
240                   CALL disturb_field( nzb_u_inner, tend, u )
241                   CALL disturb_field( nzb_v_inner, tend, v )
242                   dist_range = 0
243                ENDIF
244                time_disturb = time_disturb - dt_disturb
245             ENDIF
246          ENDIF
247
248!
249!--       Reduce the velocity divergence via the equation for perturbation
250!--       pressure.
251          IF ( intermediate_timestep_count == 1  .OR. &
252                call_psolver_at_all_substeps )  THEN
253             CALL pres
254          ENDIF
255
256!
257!--       If required, compute virtuell potential temperature
258          IF ( humidity ) CALL compute_vpt
259
260!
261!--       If required, compute liquid water content
262          IF ( cloud_physics ) CALL calc_liquid_water_content
263
264!
265!--       Compute the diffusion quantities
266          IF ( .NOT. constant_diffusion )  THEN
267
268!
269!--          First the vertical fluxes in the Prandtl layer are being computed
270             IF ( prandtl_layer )  THEN
271                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'start' )
272                CALL prandtl_fluxes
273                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'stop' )
274             ENDIF
275
276!
277!--          Compute the diffusion coefficients
278             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
279             IF ( .NOT. humidity ) THEN
280                IF ( ocean )  THEN
281                   CALL diffusivities( rho, prho_reference )
282                ELSE
283                   CALL diffusivities( pt, pt_reference )
284                ENDIF
285             ELSE
286                CALL diffusivities( vpt, pt_reference )
287             ENDIF
288             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
289
290          ENDIF
291
292       ENDDO   ! Intermediate step loop
293
294!
295!--    Increase simulation time and output times
296       current_timestep_number = current_timestep_number + 1
297       simulated_time     = simulated_time   + dt_3d
298       simulated_time_chr = time_to_string( simulated_time )
299       IF ( simulated_time >= skip_time_data_output_av )  THEN
300          time_do_av         = time_do_av       + dt_3d
301       ENDIF
302       IF ( simulated_time >= skip_time_do2d_xy )  THEN
303          time_do2d_xy       = time_do2d_xy     + dt_3d
304       ENDIF
305       IF ( simulated_time >= skip_time_do2d_xz )  THEN
306          time_do2d_xz       = time_do2d_xz     + dt_3d
307       ENDIF
308       IF ( simulated_time >= skip_time_do2d_yz )  THEN
309          time_do2d_yz       = time_do2d_yz     + dt_3d
310       ENDIF
311       IF ( simulated_time >= skip_time_do3d    )  THEN
312          time_do3d          = time_do3d        + dt_3d
313       ENDIF
314       time_dvrp          = time_dvrp        + dt_3d
315       IF ( simulated_time >= skip_time_dosp )  THEN
316          time_dosp       = time_dosp        + dt_3d
317       ENDIF
318       time_dots          = time_dots        + dt_3d
319       IF ( .NOT. first_call_advec_particles )  THEN
320          time_dopts      = time_dopts       + dt_3d
321       ENDIF
322       IF ( simulated_time >= skip_time_dopr )  THEN
323          time_dopr       = time_dopr        + dt_3d
324       ENDIF
325       time_dopr_listing          = time_dopr_listing        + dt_3d
326       time_run_control   = time_run_control + dt_3d
327
328!
329!--    Data exchange between coupled models
330       IF ( coupling_mode /= 'uncoupled' )  THEN
331          time_coupling = time_coupling + dt_3d
332!
333!--       In case of model termination initiated by the local model
334!--       (terminate_coupled > 0), the coupler must be skipped because it would
335!--       cause an MPI intercomminucation hang.
336!--       If necessary, the coupler will be called at the beginning of the
337!--       next restart run.
338          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
339             CALL surface_coupler
340             time_coupling = time_coupling - dt_coupling
341          ENDDO
342       ENDIF
343
344!
345!--    Execute user-defined actions
346       CALL user_actions( 'after_integration' )
347
348!
349!--    If Galilei transformation is used, determine the distance that the
350!--    model has moved so far
351       IF ( galilei_transformation )  THEN
352          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
353          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
354       ENDIF
355
356!
357!--    Check, if restart is necessary (because cpu-time is expiring or
358!--    because it is forced by user) and set stop flag
359!--    This call is skipped if the remote model has already initiated a restart.
360       IF ( .NOT. terminate_run )  CALL check_for_restart
361
362!
363!--    Carry out statistical analysis and output at the requested output times.
364!--    The MOD function is used for calculating the output time counters (like
365!--    time_dopr) in order to regard a possible decrease of the output time
366!--    interval in case of restart runs
367
368!
369!--    Set a flag indicating that so far no statistics have been created
370!--    for this time step
371       flow_statistics_called = .FALSE.
372
373!
374!--    If required, call flow_statistics for averaging in time
375       IF ( averaging_interval_pr /= 0.0  .AND.  &
376            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
377            simulated_time >= skip_time_dopr )  THEN
378          time_dopr_av = time_dopr_av + dt_3d
379          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
380             do_sum = .TRUE.
381             time_dopr_av = MOD( time_dopr_av, &
382                                    MAX( dt_averaging_input_pr, dt_3d ) )
383          ENDIF
384       ENDIF
385       IF ( do_sum )  CALL flow_statistics
386
387!
388!--    Sum-up 3d-arrays for later output of time-averaged data
389       IF ( averaging_interval /= 0.0  .AND.                                &
390            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
391            simulated_time >= skip_time_data_output_av )                    &
392       THEN
393          time_do_sla = time_do_sla + dt_3d
394          IF ( time_do_sla >= dt_averaging_input )  THEN
395             CALL sum_up_3d_data
396             average_count_3d = average_count_3d + 1
397             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
398          ENDIF
399       ENDIF
400
401!
402!--    Calculate spectra for time averaging
403       IF ( averaging_interval_sp /= 0.0  .AND.  &
404            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
405            simulated_time >= skip_time_dosp )  THEN
406          time_dosp_av = time_dosp_av + dt_3d
407          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
408             CALL calc_spectra
409             time_dosp_av = MOD( time_dosp_av, &
410                                 MAX( dt_averaging_input_pr, dt_3d ) )
411          ENDIF
412       ENDIF
413
414!
415!--    Computation and output of run control parameters.
416!--    This is also done whenever the time step has changed or perturbations
417!--    have been imposed
418       IF ( time_run_control >= dt_run_control  .OR.                     &
419            ( dt_changed  .AND.  timestep_scheme(1:5) /= 'runge' )  .OR. &
420            disturbance_created )                                        &
421       THEN
422          CALL run_control
423          IF ( time_run_control >= dt_run_control )  THEN
424             time_run_control = MOD( time_run_control, &
425                                     MAX( dt_run_control, dt_3d ) )
426          ENDIF
427       ENDIF
428
429!
430!--    Profile output (ASCII) on file
431       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
432          CALL print_1d
433          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
434                                                           dt_3d ) )
435       ENDIF
436
437!
438!--    Graphic output for PROFIL
439       IF ( time_dopr >= dt_dopr )  THEN
440          IF ( dopr_n /= 0 )  CALL data_output_profiles
441          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
442          time_dopr_av = 0.0    ! due to averaging (see above)
443       ENDIF
444
445!
446!--    Graphic output for time series
447       IF ( time_dots >= dt_dots )  THEN
448          CALL data_output_tseries
449          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
450       ENDIF
451
452!
453!--    Output of spectra (formatted for use with PROFIL), in case of no
454!--    time averaging, spectra has to be calculated before
455       IF ( time_dosp >= dt_dosp )  THEN
456          IF ( average_count_sp == 0 )  CALL calc_spectra
457          CALL data_output_spectra
458          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
459       ENDIF
460
461!
462!--    2d-data output (cross-sections)
463       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
464          CALL data_output_2d( 'xy', 0 )
465          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
466       ENDIF
467       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
468          CALL data_output_2d( 'xz', 0 )
469          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
470       ENDIF
471       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
472          CALL data_output_2d( 'yz', 0 )
473          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
474       ENDIF
475
476!
477!--    3d-data output (volume data)
478       IF ( time_do3d >= dt_do3d )  THEN
479          CALL data_output_3d( 0 )
480          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
481       ENDIF
482
483!
484!--    Output of time-averaged 2d/3d-data
485       IF ( time_do_av >= dt_data_output_av )  THEN
486          CALL average_3d_data
487          CALL data_output_2d( 'xy', 1 )
488          CALL data_output_2d( 'xz', 1 )
489          CALL data_output_2d( 'yz', 1 )
490          CALL data_output_3d( 1 )
491          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
492       ENDIF
493
494!
495!--    Output of particle time series
496       IF ( time_dopts >= dt_dopts  .OR. &
497            ( simulated_time >= particle_advection_start  .AND. &
498              first_call_advec_particles ) )  THEN
499          CALL data_output_ptseries
500          time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
501       ENDIF
502
503!
504!--    Output of dvrp-graphics (isosurface, particles, slicer)
505#if defined( __dvrp_graphics )
506       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
507#endif
508       IF ( time_dvrp >= dt_dvrp )  THEN
509          CALL data_output_dvrp
510          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
511       ENDIF
512#if defined( __dvrp_graphics )
513       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
514#endif
515
516!
517!--    If required, set the heat flux for the next time step at a random value
518       IF ( constant_heatflux  .AND.  random_heatflux )  CALL disturb_heatflux
519
520!
521!--    Execute user-defined actions
522       CALL user_actions( 'after_timestep' )
523
524       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
525
526    ENDDO   ! time loop
527
528#if defined( __dvrp_graphics )
529    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
530#endif
531
532 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.