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

Last change on this file since 1018 was 1017, checked in by raasch, 12 years ago

last commit documented

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