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

Last change on this file since 1737 was 1737, checked in by raasch, 6 years ago

last commit documented

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