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

Last change on this file since 1736 was 1736, checked in by raasch, 8 years ago

no perturbations added to total domain if energy limit has been set zero

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