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

Last change on this file since 1691 was 1691, checked in by maronga, 9 years ago

various bugfixes and modifications of the atmosphere-land-surface-radiation interaction. Completely re-written routine to calculate surface fluxes (surface_layer_fluxes.f90) that replaces prandtl_fluxes. Minor formatting corrections and renamings

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