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

Last change on this file since 1320 was 1320, checked in by raasch, 10 years ago

ONLY-attribute added to USE-statements,
kind-parameters added to all INTEGER and REAL declaration statements,
kinds are defined in new module kinds,
old module precision_kind is removed,
revision history before 2012 removed,
comment fields (!:) to be used for variable explanations added to all variable declaration statements

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