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

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

spectrum renamed spactra_par and further modularized, POINTER-attributes added in coupler-routines to avoid gfortran error messages

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