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

Last change on this file since 1834 was 1834, checked in by raasch, 5 years ago

last commit documented

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