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

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

branch revision comments from Marcus (rev 410) replaced by normal revision comments

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