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

Last change on this file since 1346 was 1343, checked in by kanani, 10 years ago

last commit documented

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