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

Last change on this file since 1365 was 1365, checked in by boeske, 10 years ago

large scale forcing enabled

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