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

Last change on this file since 1683 was 1683, checked in by knoop, 9 years ago

last commit documented

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