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

Last change on this file since 183 was 151, checked in by raasch, 17 years ago

preliminary update for the turbulence recycling method

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