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

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

preliminary update for changes concerning non-cyclic boundary conditions

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