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

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

added beta version of a land surface model and a simple radiation model for clear sky conditions

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