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

Last change on this file since 388 was 388, checked in by raasch, 15 years ago

in-situ AND potential density are calculated and used in the ocean version

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