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

Last change on this file since 924 was 850, checked in by raasch, 13 years ago

last commit documented

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