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

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

Added support for RRTMG radiation code

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