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

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

preliminary version, several changes to be explained later

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