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

Last change on this file since 1380 was 1380, checked in by heinze, 10 years ago

Upper boundary conditions for pt and q in case of nudging adjusted

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