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

Last change on this file since 1853 was 1853, checked in by maronga, 8 years ago

bugfix: radiation_scheme = constant caused model crash when used in combination with land surface model

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