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

Last change on this file since 1672 was 1672, checked in by raasch, 9 years ago

last commit documented

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