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

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