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

Last change on this file since 1402 was 1402, checked in by raasch, 10 years ago

output of location messages complemented, output of location bar added
(Makefile, check_parameters, cpulog, init_pegrid, init_3d_model, message, palm, parin, time_integration, new: progress_bar)
preprocessor switch intel_compiler added, -r8 compiler options removed
(.mrun.config.default, .mrun.config.imuk, .mrun.config.kiaps)

batch_job added to envpar-NAMELIST
(mrun, parin)

  • Property svn:keywords set to Id
File size: 37.7 KB
Line 
1 SUBROUTINE time_integration
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! location messages modified
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 1402 2014-05-09 14:25:13Z raasch $
27!
28! 1384 2014-05-02 14:31:06Z raasch
29! location messages added
30!
31! 1380 2014-04-28 12:40:45Z heinze
32! CALL of nudge_ref added
33! bc_pt_t_val and bc_q_t_val are updated in case nudging is used
34!
35! 1365 2014-04-22 15:03:56Z boeske
36! Reset sums_ls_l to zero at each timestep
37! +sums_ls_l
38! Calculation of reference state (previously in subroutine calc_mean_profile)
39
40! 1342 2014-03-26 17:04:47Z kanani
41! REAL constants defined as wp-kind
42!
43! 1320 2014-03-20 08:40:49Z raasch
44! ONLY-attribute added to USE-statements,
45! kind-parameters added to all INTEGER and REAL declaration statements,
46! kinds are defined in new module kinds,
47! old module precision_kind is removed,
48! revision history before 2012 removed,
49! comment fields (!:) to be used for variable explanations added to
50! all variable declaration statements
51! 1318 2014-03-17 13:35:16Z raasch
52! module interfaces removed
53!
54! 1308 2014-03-13 14:58:42Z fricke
55! +netcdf_data_format_save
56! For masked data, parallel netcdf output is not tested so far, hence
57! netcdf_data_format is switched back to non-paralell output.
58!
59! 1276 2014-01-15 13:40:41Z heinze
60! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
61!
62! 1257 2013-11-08 15:18:40Z raasch
63! acc-update-host directive for timestep removed
64!
65! 1241 2013-10-30 11:36:58Z heinze
66! Generalize calc_mean_profile for wider use
67! Determine shf and qsws in dependence on data from LSF_DATA
68! Determine ug and vg in dependence on data from LSF_DATA
69! 1221 2013-09-10 08:59:13Z raasch
70! host update of arrays before timestep is called
71!
72! 1179 2013-06-14 05:57:58Z raasch
73! mean profiles for reference state are only calculated if required,
74! small bugfix for background communication
75!
76! 1171 2013-05-30 11:27:45Z raasch
77! split of prognostic_equations deactivated (comment lines), for the time being
78!
79! 1128 2013-04-12 06:19:32Z raasch
80! asynchronous transfer of ghost point data realized for acc-optimized version:
81! prognostic_equations are first called two times for those points required for
82! the left-right and north-south exchange, respectively, and then for the
83! remaining points,
84! those parts requiring global communication moved from prognostic_equations to
85! here
86!
87! 1115 2013-03-26 18:16:16Z hoffmann
88! calculation of qr and nr is restricted to precipitation
89!
90! 1113 2013-03-10 02:48:14Z raasch
91! GPU-porting of boundary conditions,
92! openACC directives updated
93! formal parameter removed from routine boundary_conds
94!
95! 1111 2013-03-08 23:54:10Z raasch
96! +internal timestep counter for cpu statistics added,
97! openACC directives updated
98!
99! 1092 2013-02-02 11:24:22Z raasch
100! unused variables removed
101!
102! 1065 2012-11-22 17:42:36Z hoffmann
103! exchange of diss (dissipation rate) in case of turbulence = .TRUE. added
104!
105! 1053 2012-11-13 17:11:03Z hoffmann
106! exchange of ghost points for nr, qr added
107!
108! 1036 2012-10-22 13:43:42Z raasch
109! code put under GPL (PALM 3.9)
110!
111! 1019 2012-09-28 06:46:45Z raasch
112! non-optimized version of prognostic_equations removed
113!
114! 1015 2012-09-27 09:23:24Z raasch
115! +call of prognostic_equations_acc
116!
117! 1001 2012-09-13 14:08:46Z raasch
118! all actions concerning leapfrog- and upstream-spline-scheme removed
119!
120! 849 2012-03-15 10:35:09Z raasch
121! advec_particles renamed lpm, first_call_advec_particles renamed first_call_lpm
122!
123! 825 2012-02-19 03:03:44Z raasch
124! wang_collision_kernel renamed wang_kernel
125!
126! Revision 1.1  1997/08/11 06:19:04  raasch
127! Initial revision
128!
129!
130! Description:
131! ------------
132! Integration in time of the model equations, statistical analysis and graphic
133! output
134!------------------------------------------------------------------------------!
135
136    USE advec_ws,                                                              &
137        ONLY:  ws_statistics
138
139    USE arrays_3d,                                                             &
140        ONLY:  diss, dzu, e_p, nr_p, prho, pt, pt_p, pt_init, q_init, q, ql,   &
141               ql_c, ql_v, ql_vp, qr_p, q_p, ref_state, rho, sa_p, tend, u,    &
142               u_p, v, vpt, v_p, w_p
143
144    USE calc_mean_profile_mod,                                                 &
145        ONLY:  calc_mean_profile
146
147    USE control_parameters,                                                    &
148        ONLY:  advected_distance_x, advected_distance_y, average_count_3d,     &
149               average_count_sp, averaging_interval, averaging_interval_pr,    &
150               averaging_interval_sp, bc_lr_cyc, bc_ns_cyc, bc_pt_t_val,       &
151               bc_q_t_val, call_psolver_at_all_substeps, cloud_droplets,       &
152               cloud_physics, constant_heatflux, create_disturbances, dopr_n,  &
153               constant_diffusion, coupling_mode, coupling_start_time,         &
154               current_timestep_number, disturbance_created,                   &
155               disturbance_energy_limit, dist_range, do_sum, dt_3d,            &
156               dt_averaging_input, dt_averaging_input_pr, dt_coupling,         &
157               dt_data_output_av, dt_disturb, dt_do2d_xy, dt_do2d_xz,          &
158               dt_do2d_yz, dt_do3d, dt_domask,dt_dopts, dt_dopr,               &
159               dt_dopr_listing, dt_dosp, dt_dots, dt_dvrp, dt_run_control,     &
160               end_time, first_call_lpm, galilei_transformation, humidity,     &
161               icloud_scheme, intermediate_timestep_count,                     &
162               intermediate_timestep_count_max, large_scale_forcing,           &
163               loop_optimization, lsf_surf, lsf_vert, masks, mid,              &
164               netcdf_data_format, neutral, nr_timesteps_this_run, nudging,    &
165               ocean, on_device, passive_scalar, prandtl_layer, precipitation, &
166               prho_reference, pt_reference, pt_slope_offset, random_heatflux, &
167               run_coupled, simulated_time, simulated_time_chr,                &
168               skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz,        &
169               skip_time_do3d, skip_time_domask, skip_time_dopr,               &
170               skip_time_dosp, skip_time_data_output_av, sloping_surface,      &
171               stop_dt, terminate_coupled, terminate_run, timestep_scheme,     &
172               time_coupling, time_do2d_xy, time_do2d_xz, time_do2d_yz,        &
173               time_do3d, time_domask, time_dopr, time_dopr_av,                &
174               time_dopr_listing, time_dopts, time_dosp, time_dosp_av,         &
175               time_dots, time_do_av, time_do_sla, time_disturb, time_dvrp,    &
176               time_run_control, time_since_reference_point, turbulence,       &
177               turbulent_inflow, use_initial_profile_as_reference,             &
178               use_single_reference_value, u_gtrans, v_gtrans, ws_scheme_mom,  &
179               ws_scheme_sca
180
181    USE cpulog,                                                                &
182        ONLY:  cpu_log, log_point, log_point_s
183
184    USE indices,                                                               &
185        ONLY:  i_left, i_right, j_north, j_south, nbgp, nx, nxl, nxlg, nxr,    &
186               nxrg, nyn, nys, nzb, nzt, nzb_u_inner, nzb_v_inner 
187
188    USE interaction_droplets_ptq_mod,                                          &
189        ONLY:  interaction_droplets_ptq
190
191    USE kinds
192
193    USE ls_forcing_mod,                                                        &
194        ONLY:  ls_forcing_surf, ls_forcing_vert
195
196    USE nudge_mod,                                                             &
197        ONLY:  calc_tnudge, nudge_ref
198
199    USE particle_attributes,                                                   &
200        ONLY:  particle_advection, particle_advection_start, wang_kernel
201
202    USE pegrid
203
204    USE production_e_mod,                                                      &
205        ONLY:  production_e_init
206
207    USE progress_bar,                                                          &
208        ONLY:  finish_progress_bar, output_progress_bar
209
210    USE prognostic_equations_mod,                                              &
211        ONLY:  prognostic_equations_acc, prognostic_equations_cache,           &
212               prognostic_equations_vector
213
214    USE statistics,                                                            &
215        ONLY:  flow_statistics_called, hom, pr_palm, sums_ls_l
216
217    USE user_actions_mod,                                                      &
218        ONLY:  user_actions
219
220    IMPLICIT NONE
221
222    CHARACTER (LEN=9) ::  time_to_string          !:
223
224    INTEGER(iwp)      ::  netcdf_data_format_save !:
225
226!
227!-- At the beginning of a simulation determine the time step as well as
228!-- determine and print out the run control parameters
229    IF ( simulated_time == 0.0_wp )  CALL timestep
230
231    CALL run_control
232
233
234!
235!-- Data exchange between coupled models in case that a call has been omitted
236!-- at the end of the previous run of a job chain.
237    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
238!
239!--    In case of model termination initiated by the local model the coupler
240!--    must not be called because this would again cause an MPI hang.
241       DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
242          CALL surface_coupler
243          time_coupling = time_coupling - dt_coupling
244       ENDDO
245       IF (time_coupling == 0.0_wp .AND. time_since_reference_point < dt_coupling)&
246       THEN
247          time_coupling = time_since_reference_point
248       ENDIF
249    ENDIF
250
251
252#if defined( __dvrp_graphics )
253!
254!-- Time measurement with dvrp software 
255    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
256#endif
257
258    CALL location_message( 'start with time-stepping', .TRUE. )
259!
260!-- Start of the time loop
261    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
262                .NOT. terminate_run )
263
264       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
265
266!
267!--    Determine size of next time step
268       IF ( simulated_time /= 0.0_wp )  THEN
269          CALL timestep
270       ENDIF
271
272!
273!--    Determine ug, vg and w_subs in dependence on data from external file
274!--    LSF_DATA
275       IF ( large_scale_forcing .AND. lsf_vert )  THEN
276           CALL ls_forcing_vert ( simulated_time )
277           sums_ls_l = 0.0_wp
278       ENDIF
279
280!
281!--    Set pt_init and q_init to the current profiles taken from
282!--    NUDGING_DATA
283       IF ( nudging )  THEN
284           CALL nudge_ref ( simulated_time )
285!
286!--        Store temperature gradient at the top boundary for possible Neumann
287!--        boundary condition
288           bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
289           bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
290       ENDIF
291
292!
293!--    Execute the user-defined actions
294       CALL user_actions( 'before_timestep' )
295
296!
297!--    Start of intermediate step loop
298       intermediate_timestep_count = 0
299       DO  WHILE ( intermediate_timestep_count < &
300                   intermediate_timestep_count_max )
301
302          intermediate_timestep_count = intermediate_timestep_count + 1
303
304!
305!--       Set the steering factors for the prognostic equations which depend
306!--       on the timestep scheme
307          CALL timestep_scheme_steering
308
309!
310!--       Calculate those variables needed in the tendency terms which need
311!--       global communication
312          IF ( .NOT. use_single_reference_value  .AND. &
313               .NOT. use_initial_profile_as_reference )  THEN
314!
315!--          Horizontally averaged profiles to be used as reference state in
316!--          buoyancy terms (WARNING: only the respective last call of
317!--          calc_mean_profile defines the reference state!)
318             IF ( .NOT. neutral )  THEN
319                CALL calc_mean_profile( pt, 4 )
320                ref_state(:)  = hom(:,1,4,0) ! this is used in the buoyancy term
321             ENDIF
322             IF ( ocean )  THEN
323                CALL calc_mean_profile( rho, 64 )
324                ref_state(:)  = hom(:,1,64,0)
325             ENDIF
326             IF ( humidity )  THEN
327                CALL calc_mean_profile( vpt, 44 )
328                ref_state(:)  = hom(:,1,44,0)
329             ENDIF
330
331          ENDIF
332
333          IF ( .NOT. constant_diffusion )  CALL production_e_init
334          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  &
335               intermediate_timestep_count == 1 )  CALL ws_statistics
336!
337!--       In case of nudging calculate current nudging time scale and horizontal
338!--       means of u, v, pt and q
339          IF ( nudging )  THEN
340             CALL calc_tnudge( simulated_time )
341             CALL calc_mean_profile( u, 1 )
342             CALL calc_mean_profile( v, 2 )
343             CALL calc_mean_profile( pt, 4 )
344             CALL calc_mean_profile( q, 41 )
345          ENDIF
346
347!
348!--       Solve the prognostic equations. A fast cache optimized version with
349!--       only one single loop is used in case of Piascek-Williams advection
350!--       scheme. NEC vector machines use a different version, because
351!--       in the other versions a good vectorization is prohibited due to
352!--       inlining problems.
353          IF ( loop_optimization == 'cache' )  THEN
354             CALL prognostic_equations_cache
355          ELSEIF ( loop_optimization == 'vector' )  THEN
356             CALL prognostic_equations_vector
357          ELSEIF ( loop_optimization == 'acc' )  THEN
358             i_left  = nxl;         i_right = nxr
359             j_south = nys;         j_north = nyn
360             CALL prognostic_equations_acc
361
362!             i_left  = nxl;         i_right = nxl+nbgp-1
363!             j_south = nys;         j_north = nyn
364!             CALL prognostic_equations_acc
365!             i_left  = nxr-nbgp+1;  i_right = nxr
366!             j_south = nys;         j_north = nyn
367!             CALL prognostic_equations_acc
368
369!
370!--          Exchange of ghost points (lateral boundary conditions)
371             IF ( background_communication )  THEN
372
373                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
374               
375                send_receive = 'lr'
376                sendrecv_in_background = .TRUE.
377                req          = 0
378                req_count    = 0
379
380                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
381                   on_device = .TRUE.         ! to be removed after complete porting
382                ELSE                          ! of ghost point exchange
383                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
384                ENDIF
385
386                CALL exchange_horiz( u_p, nbgp )
387                CALL exchange_horiz( v_p, nbgp )
388                CALL exchange_horiz( w_p, nbgp )
389                CALL exchange_horiz( pt_p, nbgp )
390                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
391                IF ( ocean )  THEN
392                   CALL exchange_horiz( sa_p, nbgp )
393                   CALL exchange_horiz( rho, nbgp )
394                  CALL exchange_horiz( prho, nbgp )
395                ENDIF
396                IF (humidity  .OR.  passive_scalar)  THEN
397                   CALL exchange_horiz( q_p, nbgp )
398                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
399                      CALL exchange_horiz( qr_p, nbgp )
400                      CALL exchange_horiz( nr_p, nbgp )
401                   ENDIF
402                ENDIF
403                IF ( cloud_droplets )  THEN
404                   CALL exchange_horiz( ql, nbgp )
405                   CALL exchange_horiz( ql_c, nbgp )
406                   CALL exchange_horiz( ql_v, nbgp )
407                   CALL exchange_horiz( ql_vp, nbgp )
408                ENDIF
409                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
410
411                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
412                   on_device = .FALSE.        ! to be removed after complete porting
413                ELSE                          ! of ghost point exchange
414                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
415                ENDIF
416
417                sendrecv_in_background = .FALSE.
418
419                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'pause' )
420
421             ENDIF
422
423!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
424!             j_south = nys;         j_north = nys+nbgp-1
425!             CALL prognostic_equations_acc
426!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
427!             j_south = nyn-nbgp+1;  j_north = nyn
428!             CALL prognostic_equations_acc
429
430             IF ( background_communication )  THEN
431                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'start' )
432#if defined( __parallel )
433                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
434#endif
435                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'pause' )
436
437                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'continue' )
438
439                send_receive = 'ns'
440                sendrecv_in_background = .TRUE.
441                req          = 0
442                req_count    = 0
443
444                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
445                   on_device = .TRUE.         ! to be removed after complete porting
446                ELSE                          ! of ghost point exchange
447                   !$acc update host( e_p, pt_p, u_p, v_p, w_p )
448                ENDIF
449
450                CALL exchange_horiz( u_p, nbgp )
451                CALL exchange_horiz( v_p, nbgp )
452                CALL exchange_horiz( w_p, nbgp )
453                CALL exchange_horiz( pt_p, nbgp )
454                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
455                IF ( ocean )  THEN
456                   CALL exchange_horiz( sa_p, nbgp )
457                   CALL exchange_horiz( rho, nbgp )
458                  CALL exchange_horiz( prho, nbgp )
459                ENDIF
460                IF (humidity  .OR.  passive_scalar)  THEN
461                   CALL exchange_horiz( q_p, nbgp )
462                   IF ( cloud_physics .AND. icloud_scheme == 0 )  THEN
463                      CALL exchange_horiz( qr_p, nbgp )
464                      CALL exchange_horiz( nr_p, nbgp )
465                   ENDIF
466                ENDIF
467                IF ( cloud_droplets )  THEN
468                   CALL exchange_horiz( ql, nbgp )
469                   CALL exchange_horiz( ql_c, nbgp )
470                   CALL exchange_horiz( ql_v, nbgp )
471                   CALL exchange_horiz( ql_vp, nbgp )
472                ENDIF
473                IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
474
475                IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
476                   on_device = .FALSE.        ! to be removed after complete porting
477                ELSE                          ! of ghost point exchange
478                   !$acc update device( e_p, pt_p, u_p, v_p, w_p )
479                ENDIF
480
481                sendrecv_in_background = .FALSE.
482
483                CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
484
485             ENDIF
486
487!             i_left  = nxl+nbgp;    i_right = nxr-nbgp
488!             j_south = nys+nbgp;    j_north = nyn-nbgp
489!             CALL prognostic_equations_acc
490
491             IF ( background_communication )  THEN
492                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'continue' )
493#if defined( __parallel )
494                CALL MPI_WAITALL( req_count, req, wait_stat, ierr )
495#endif
496                send_receive = 'al'
497                CALL cpu_log( log_point(41), 'exchange-horiz-wait', 'stop' )
498             ENDIF
499
500          ENDIF
501
502!
503!--       Particle transport/physics with the Lagrangian particle model
504!--       (only once during intermediate steps, because it uses an Euler-step)
505!--       ### particle model should be moved before prognostic_equations, in order
506!--       to regard droplet interactions directly
507          IF ( particle_advection  .AND.                         &
508               simulated_time >= particle_advection_start  .AND. &
509               intermediate_timestep_count == 1 )  THEN
510             CALL lpm
511             first_call_lpm = .FALSE.
512          ENDIF
513
514!
515!--       Interaction of droplets with temperature and specific humidity.
516!--       Droplet condensation and evaporation is calculated within
517!--       advec_particles.
518          IF ( cloud_droplets  .AND.  &
519               intermediate_timestep_count == intermediate_timestep_count_max )&
520          THEN
521             CALL interaction_droplets_ptq
522          ENDIF
523
524!
525!--       Exchange of ghost points (lateral boundary conditions)
526          IF ( .NOT. background_communication )  THEN
527
528             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
529
530             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
531                on_device = .TRUE.         ! to be removed after complete porting
532             ELSE                          ! of ghost point exchange
533                !$acc update host( e_p, pt_p, u_p, v_p, w_p )
534             ENDIF
535
536             CALL exchange_horiz( u_p, nbgp )
537             CALL exchange_horiz( v_p, nbgp )
538             CALL exchange_horiz( w_p, nbgp )
539             CALL exchange_horiz( pt_p, nbgp )
540             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
541             IF ( ocean )  THEN
542                CALL exchange_horiz( sa_p, nbgp )
543                CALL exchange_horiz( rho, nbgp )
544                CALL exchange_horiz( prho, nbgp )
545             ENDIF
546             IF (humidity  .OR.  passive_scalar)  THEN
547                CALL exchange_horiz( q_p, nbgp )
548                IF ( cloud_physics .AND. icloud_scheme == 0  .AND.  &
549                     precipitation )  THEN
550                   CALL exchange_horiz( qr_p, nbgp )
551                   CALL exchange_horiz( nr_p, nbgp )
552                ENDIF
553             ENDIF
554             IF ( cloud_droplets )  THEN
555                CALL exchange_horiz( ql, nbgp )
556                CALL exchange_horiz( ql_c, nbgp )
557                CALL exchange_horiz( ql_v, nbgp )
558                CALL exchange_horiz( ql_vp, nbgp )
559             ENDIF
560             IF ( wang_kernel  .OR.  turbulence )  CALL exchange_horiz( diss, nbgp )
561
562             IF ( numprocs == 1 )  THEN    ! workaround for single-core GPU runs
563                on_device = .FALSE.        ! to be removed after complete porting
564             ELSE                          ! of ghost point exchange
565                !$acc update device( e_p, pt_p, u_p, v_p, w_p )
566             ENDIF
567
568             CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
569
570          ENDIF
571
572!
573!--       Boundary conditions for the prognostic quantities (except of the
574!--       velocities at the outflow in case of a non-cyclic lateral wall)
575          CALL boundary_conds
576
577!
578!--       Swap the time levels in preparation for the next time step.
579          CALL swap_timelevel
580
581!
582!--       Temperature offset must be imposed at cyclic boundaries in x-direction
583!--       when a sloping surface is used
584          IF ( sloping_surface )  THEN
585             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - &
586                                                    pt_slope_offset
587             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + &
588                                                    pt_slope_offset
589          ENDIF
590
591!
592!--       Impose a turbulent inflow using the recycling method
593          IF ( turbulent_inflow )  CALL  inflow_turbulence
594
595!
596!--       Impose a random perturbation on the horizontal velocity field
597          IF ( create_disturbances  .AND.                                      &
598               ( call_psolver_at_all_substeps  .AND.                           &
599               intermediate_timestep_count == intermediate_timestep_count_max )&
600          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
601               intermediate_timestep_count == 1 ) )                            &
602          THEN
603             time_disturb = time_disturb + dt_3d
604             IF ( time_disturb >= dt_disturb )  THEN
605                !$acc update host( u, v )
606                IF ( numprocs == 1 )  on_device = .FALSE.  ! workaround, remove later
607                IF ( hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
608                   CALL disturb_field( nzb_u_inner, tend, u )
609                   CALL disturb_field( nzb_v_inner, tend, v )
610                ELSEIF ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )  THEN
611!
612!--                Runs with a non-cyclic lateral wall need perturbations
613!--                near the inflow throughout the whole simulation
614                   dist_range = 1
615                   CALL disturb_field( nzb_u_inner, tend, u )
616                   CALL disturb_field( nzb_v_inner, tend, v )
617                   dist_range = 0
618                ENDIF
619                IF ( numprocs == 1 )  on_device = .TRUE.  ! workaround, remove later
620                !$acc update device( u, v )
621                time_disturb = time_disturb - dt_disturb
622             ENDIF
623          ENDIF
624
625!
626!--       Reduce the velocity divergence via the equation for perturbation
627!--       pressure.
628          IF ( intermediate_timestep_count == 1  .OR. &
629                call_psolver_at_all_substeps )  THEN
630             CALL pres
631          ENDIF
632
633!
634!--       If required, compute liquid water content
635          IF ( cloud_physics )  THEN
636             CALL calc_liquid_water_content
637             !$acc update device( ql )
638          ENDIF
639!
640!--       If required, compute virtual potential temperature
641          IF ( humidity )  THEN
642             CALL compute_vpt 
643             !$acc update device( vpt )
644          ENDIF 
645!
646!--       Compute the diffusion quantities
647          IF ( .NOT. constant_diffusion )  THEN
648
649!
650!--          Determine surface fluxes shf and qsws and surface values
651!--          pt_surface and q_surface in dependence on data from external
652!--          file LSF_DATA respectively
653             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
654                 intermediate_timestep_count == intermediate_timestep_count_max )&
655             THEN
656                CALL ls_forcing_surf ( simulated_time )
657             ENDIF
658
659!
660!--          First the vertical fluxes in the Prandtl layer are being computed
661             IF ( prandtl_layer )  THEN
662                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'start' )
663                CALL prandtl_fluxes
664                CALL cpu_log( log_point(19), 'prandtl_fluxes', 'stop' )
665             ENDIF
666
667!
668!--          Compute the diffusion coefficients
669             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
670             IF ( .NOT. humidity ) THEN
671                IF ( ocean )  THEN
672                   CALL diffusivities( prho, prho_reference )
673                ELSE
674                   CALL diffusivities( pt, pt_reference )
675                ENDIF
676             ELSE
677                CALL diffusivities( vpt, pt_reference )
678             ENDIF
679             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
680
681          ENDIF
682
683       ENDDO   ! Intermediate step loop
684
685!
686!--    Increase simulation time and output times
687       nr_timesteps_this_run      = nr_timesteps_this_run + 1
688       current_timestep_number    = current_timestep_number + 1
689       simulated_time             = simulated_time   + dt_3d
690       simulated_time_chr         = time_to_string( simulated_time )
691       time_since_reference_point = simulated_time - coupling_start_time
692
693       IF ( simulated_time >= skip_time_data_output_av )  THEN
694          time_do_av         = time_do_av       + dt_3d
695       ENDIF
696       IF ( simulated_time >= skip_time_do2d_xy )  THEN
697          time_do2d_xy       = time_do2d_xy     + dt_3d
698       ENDIF
699       IF ( simulated_time >= skip_time_do2d_xz )  THEN
700          time_do2d_xz       = time_do2d_xz     + dt_3d
701       ENDIF
702       IF ( simulated_time >= skip_time_do2d_yz )  THEN
703          time_do2d_yz       = time_do2d_yz     + dt_3d
704       ENDIF
705       IF ( simulated_time >= skip_time_do3d    )  THEN
706          time_do3d          = time_do3d        + dt_3d
707       ENDIF
708       DO  mid = 1, masks
709          IF ( simulated_time >= skip_time_domask(mid) )  THEN
710             time_domask(mid)= time_domask(mid) + dt_3d
711          ENDIF
712       ENDDO
713       time_dvrp          = time_dvrp        + dt_3d
714       IF ( simulated_time >= skip_time_dosp )  THEN
715          time_dosp       = time_dosp        + dt_3d
716       ENDIF
717       time_dots          = time_dots        + dt_3d
718       IF ( .NOT. first_call_lpm )  THEN
719          time_dopts      = time_dopts       + dt_3d
720       ENDIF
721       IF ( simulated_time >= skip_time_dopr )  THEN
722          time_dopr       = time_dopr        + dt_3d
723       ENDIF
724       time_dopr_listing          = time_dopr_listing        + dt_3d
725       time_run_control   = time_run_control + dt_3d
726
727!
728!--    Data exchange between coupled models
729       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled )  THEN
730          time_coupling = time_coupling + dt_3d
731
732!
733!--       In case of model termination initiated by the local model
734!--       (terminate_coupled > 0), the coupler must be skipped because it would
735!--       cause an MPI intercomminucation hang.
736!--       If necessary, the coupler will be called at the beginning of the
737!--       next restart run.
738          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
739             CALL surface_coupler
740             time_coupling = time_coupling - dt_coupling
741          ENDDO
742       ENDIF
743
744!
745!--    Execute user-defined actions
746       CALL user_actions( 'after_integration' )
747
748!
749!--    If Galilei transformation is used, determine the distance that the
750!--    model has moved so far
751       IF ( galilei_transformation )  THEN
752          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
753          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
754       ENDIF
755
756!
757!--    Check, if restart is necessary (because cpu-time is expiring or
758!--    because it is forced by user) and set stop flag
759!--    This call is skipped if the remote model has already initiated a restart.
760       IF ( .NOT. terminate_run )  CALL check_for_restart
761
762!
763!--    Carry out statistical analysis and output at the requested output times.
764!--    The MOD function is used for calculating the output time counters (like
765!--    time_dopr) in order to regard a possible decrease of the output time
766!--    interval in case of restart runs
767
768!
769!--    Set a flag indicating that so far no statistics have been created
770!--    for this time step
771       flow_statistics_called = .FALSE.
772
773!
774!--    If required, call flow_statistics for averaging in time
775       IF ( averaging_interval_pr /= 0.0_wp  .AND.  &
776            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
777            simulated_time >= skip_time_dopr )  THEN
778          time_dopr_av = time_dopr_av + dt_3d
779          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
780             do_sum = .TRUE.
781             time_dopr_av = MOD( time_dopr_av, &
782                                    MAX( dt_averaging_input_pr, dt_3d ) )
783          ENDIF
784       ENDIF
785       IF ( do_sum )  CALL flow_statistics
786
787!
788!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
789       IF ( averaging_interval /= 0.0_wp  .AND.                                &
790            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
791            simulated_time >= skip_time_data_output_av )                    &
792       THEN
793          time_do_sla = time_do_sla + dt_3d
794          IF ( time_do_sla >= dt_averaging_input )  THEN
795             CALL sum_up_3d_data
796             average_count_3d = average_count_3d + 1
797             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
798          ENDIF
799       ENDIF
800
801!
802!--    Calculate spectra for time averaging
803       IF ( averaging_interval_sp /= 0.0_wp  .AND.  &
804            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
805            simulated_time >= skip_time_dosp )  THEN
806          time_dosp_av = time_dosp_av + dt_3d
807          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
808             CALL calc_spectra
809             time_dosp_av = MOD( time_dosp_av, &
810                                 MAX( dt_averaging_input_pr, dt_3d ) )
811          ENDIF
812       ENDIF
813
814!
815!--    Computation and output of run control parameters.
816!--    This is also done whenever perturbations have been imposed
817       IF ( time_run_control >= dt_run_control  .OR.                     &
818            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created ) &
819       THEN
820          CALL run_control
821          IF ( time_run_control >= dt_run_control )  THEN
822             time_run_control = MOD( time_run_control, &
823                                     MAX( dt_run_control, dt_3d ) )
824          ENDIF
825       ENDIF
826
827!
828!--    Profile output (ASCII) on file
829       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
830          CALL print_1d
831          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
832                                                           dt_3d ) )
833       ENDIF
834
835!
836!--    Graphic output for PROFIL
837       IF ( time_dopr >= dt_dopr )  THEN
838          IF ( dopr_n /= 0 )  CALL data_output_profiles
839          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
840          time_dopr_av = 0.0_wp    ! due to averaging (see above)
841       ENDIF
842
843!
844!--    Graphic output for time series
845       IF ( time_dots >= dt_dots )  THEN
846          CALL data_output_tseries
847          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
848       ENDIF
849
850!
851!--    Output of spectra (formatted for use with PROFIL), in case of no
852!--    time averaging, spectra has to be calculated before
853       IF ( time_dosp >= dt_dosp )  THEN
854          IF ( average_count_sp == 0 )  CALL calc_spectra
855          CALL data_output_spectra
856          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
857       ENDIF
858
859!
860!--    2d-data output (cross-sections)
861       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
862          CALL data_output_2d( 'xy', 0 )
863          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
864       ENDIF
865       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
866          CALL data_output_2d( 'xz', 0 )
867          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
868       ENDIF
869       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
870          CALL data_output_2d( 'yz', 0 )
871          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
872       ENDIF
873
874!
875!--    3d-data output (volume data)
876       IF ( time_do3d >= dt_do3d )  THEN
877          CALL data_output_3d( 0 )
878          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
879       ENDIF
880
881!
882!--    masked data output
883!--    Parallel netcdf output is not tested so far for masked data, hence
884!--    netcdf_data_format is switched back to non-paralell output.
885       netcdf_data_format_save = netcdf_data_format
886       IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
887       IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
888       DO  mid = 1, masks
889          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
890             CALL data_output_mask( 0 )
891             time_domask(mid) = MOD( time_domask(mid),  &
892                                     MAX( dt_domask(mid), dt_3d ) )
893          ENDIF
894       ENDDO
895       netcdf_data_format = netcdf_data_format_save
896
897!
898!--    Output of time-averaged 2d/3d/masked data
899       IF ( time_do_av >= dt_data_output_av )  THEN
900          CALL average_3d_data
901          CALL data_output_2d( 'xy', 1 )
902          CALL data_output_2d( 'xz', 1 )
903          CALL data_output_2d( 'yz', 1 )
904          CALL data_output_3d( 1 )
905!--       Parallel netcdf output is not tested so far for masked data, hence
906!--       netcdf_data_format is switched back to non-paralell output.
907          netcdf_data_format_save = netcdf_data_format
908          IF ( netcdf_data_format == 5 ) netcdf_data_format = 3
909          IF ( netcdf_data_format == 6 ) netcdf_data_format = 4
910          DO  mid = 1, masks
911             CALL data_output_mask( 1 )
912          ENDDO
913          netcdf_data_format = netcdf_data_format_save
914          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
915       ENDIF
916
917!
918!--    Output of particle time series
919       IF ( particle_advection )  THEN
920          IF ( time_dopts >= dt_dopts  .OR. &
921               ( simulated_time >= particle_advection_start  .AND. &
922                 first_call_lpm ) )  THEN
923             CALL data_output_ptseries
924             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
925          ENDIF
926       ENDIF
927
928!
929!--    Output of dvrp-graphics (isosurface, particles, slicer)
930#if defined( __dvrp_graphics )
931       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
932#endif
933       IF ( time_dvrp >= dt_dvrp )  THEN
934          CALL data_output_dvrp
935          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
936       ENDIF
937#if defined( __dvrp_graphics )
938       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
939#endif
940
941!
942!--    If required, set the heat flux for the next time step at a random value
943       IF ( constant_heatflux  .AND.  random_heatflux )  CALL disturb_heatflux
944
945!
946!--    Execute user-defined actions
947       CALL user_actions( 'after_timestep' )
948
949!
950!--    Output elapsed simulated time in form of a progress bar on stdout
951       IF ( myid == 0 )  CALL output_progress_bar
952
953       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
954
955
956    ENDDO   ! time loop
957
958    IF ( myid == 0 )  CALL finish_progress_bar
959
960#if defined( __dvrp_graphics )
961    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
962#endif
963
964    CALL location_message( 'finished time-stepping', .TRUE. )
965
966 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.