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

Last change on this file since 4509 was 4508, checked in by raasch, 4 years ago

salsa decycling replaced by explicit setting of lateral boundary conditions

  • Property svn:keywords set to Id
File size: 73.7 KB
Line 
1!> @file time_integration.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! 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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 4508 2020-04-24 13:32:20Z raasch $
27! salsa decycling replaced by explicit setting of lateral boundary conditions
28!
29! 4502 2020-04-17 16:14:16Z schwenkel
30! Implementation of ice microphysics
31!
32! 4472 2020-03-24 12:21:00Z Giersch
33! OPENACC COPYIN directive for ddx and ddy added
34!
35! 4466 2020-03-20 16:14:41Z suehring
36! Add advection fluxes to ACC copyin
37!
38! 4457 2020-03-11 14:20:43Z raasch
39! use statement for exchange horiz added
40!
41! 4444 2020-03-05 15:59:50Z raasch
42! bugfix: cpp-directives for serial mode added
43!
44! 4420 2020-02-24 14:13:56Z maronga
45! Added output control for wind turbine model
46!
47! 4403 2020-02-12 13:08:46Z banzhafs
48! Allowing both existing and on-demand emission read modes
49!
50! 4360 2020-01-07 11:25:50Z suehring
51! Bugfix, hour_call_emis uninitialized at first call of time_integration
52!
53! 4346 2019-12-18 11:55:56Z motisi
54! Introduction of wall_flags_total_0, which currently sets bits based on static
55! topography information used in wall_flags_static_0
56!
57! 4329 2019-12-10 15:46:36Z motisi
58! Renamed wall_flags_0 to wall_flags_static_0
59!
60! 4281 2019-10-29 15:15:39Z schwenkel
61! Moved boundary conditions to module interface
62!
63! 4276 2019-10-28 16:03:29Z schwenkel
64! Further modularization of lpm code components
65!
66! 4275 2019-10-28 15:34:55Z schwenkel
67! Move call oft lpm to the end of intermediate timestep loop
68!
69! 4268 2019-10-17 11:29:38Z schwenkel
70! Removing module specific boundary conditions an put them into their modules
71!
72! 4227 2019-09-10 18:04:34Z gronemeier
73! implement new palm_date_time_mod
74!
75! 4226 2019-09-10 17:03:24Z suehring
76! Changes in interface for the offline nesting
77!
78! 4182 2019-08-22 15:20:23Z scharf
79! Corrected "Former revisions" section
80!
81! 4170 2019-08-19 17:12:31Z gronemeier
82! copy diss, diss_p, tdiss_m to GPU
83!
84! 4144 2019-08-06 09:11:47Z raasch
85! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.
86!
87! 4126 2019-07-30 11:09:11Z gronemeier
88! renamed routine to calculate uv exposure
89!
90! 4111 2019-07-22 18:16:57Z suehring
91! advc_flags_1 / advc_flags_2 renamed to advc_flags_m / advc_flags_s
92!
93! 4069 2019-07-01 14:05:51Z Giersch
94! Masked output running index mid has been introduced as a local variable to
95! avoid runtime error (Loop variable has been modified) in time_integration
96!
97! 4064 2019-07-01 05:33:33Z gronemeier
98! Moved call to radiation module out of intermediate time loop
99!
100! 4048 2019-06-21 21:00:21Z knoop
101! Moved production_e_init call into turbulence_closure_mod
102!
103! 4047 2019-06-21 18:58:09Z knoop
104! Added remainings of swap_timelevel upon its dissolution
105!
106! 4043 2019-06-18 16:59:00Z schwenkel
107! Further LPM modularization
108!
109! 4039 2019-06-18 10:32:41Z suehring
110! Rename subroutines in module for diagnostic quantities
111!
112! 4029 2019-06-14 14:04:35Z raasch
113! exchange of ghost points and boundary conditions separated for chemical species and SALSA module,
114! bugfix: decycling of chemistry species after nesting data transfer
115!
116! 4022 2019-06-12 11:52:39Z suehring
117! Call synthetic turbulence generator at last RK3 substep right after boundary
118! conditions are updated in offline nesting in order to assure that
119! perturbations are always imposed
120!
121! 4017 2019-06-06 12:16:46Z schwenkel
122! Mass (volume) flux correction included to ensure global mass conservation for child domains.
123!
124! 3994 2019-05-22 18:08:09Z suehring
125! output of turbulence intensity added
126!
127! 3988 2019-05-22 11:32:37Z kanani
128! Implement steerable output interval for virtual measurements
129!
130! 3968 2019-05-13 11:04:01Z suehring
131! replace nspec_out with n_matched_vars
132!
133! 3929 2019-04-24 12:52:08Z banzhafs
134! Reverse changes back from revision 3878: use chem_boundary_conds instead of
135! chem_boundary_conds_decycle
136!
137!
138! 3885 2019-04-11 11:29:34Z kanani
139! Changes related to global restructuring of location messages and introduction
140! of additional debug messages
141!
142! 3879 2019-04-08 20:25:23Z knoop
143! Moved wtm_forces to module_interface_actions
144!
145! 3872 2019-04-08 15:03:06Z knoop
146! Modifications made for salsa:
147! - Call salsa_emission_update at each time step but do the checks within
148!   salsa_emission_update (i.e. skip_time_do_salsa >= time_since_reference_point
149!   and next_aero_emission_update <= time_since_reference_point ).
150! - Renamed nbins --> nbins_aerosol, ncc_tot --> ncomponents_mass and
151!   ngast --> ngases_salsa and loop indices b, c and sg to ib, ic and ig
152! - Apply nesting for salsa variables
153! - Removed cpu_log calls speciffic for salsa.
154!
155! 3833 2019-03-28 15:04:04Z forkel
156! added USE chem_gasphase_mod, replaced nspec by nspec since fixed compounds are not integrated
157!
158! 3820 2019-03-27 11:53:41Z forkel
159! renamed do_emiss to emissions_anthropogenic (ecc)
160!
161!
162! 3774 2019-03-04 10:52:49Z moh.hefny
163! rephrase if statement to avoid unallocated array in case of
164! nesting_offline is false (crashing during debug mode)
165!
166! 3761 2019-02-25 15:31:42Z raasch $
167! module section re-formatted and openacc required variables moved to separate section,
168! re-formatting to 100 char line width
169!
170! 3745 2019-02-15 18:57:56Z suehring
171! Call indoor model after first timestep
172!
173! 3744 2019-02-15 18:38:58Z suehring
174! - Moved call of bio_calculate_thermal_index_maps from biometeorology module to
175! time_integration to make sure averaged input is updated before calculating.
176!
177! 3739 2019-02-13 08:05:17Z dom_dwd_user
178! Removed everything related to "time_bio_results" as this is never used.
179!
180! 3724 2019-02-06 16:28:23Z kanani
181! Correct double-used log_point_s unit
182!
183! 3719 2019-02-06 13:10:18Z kanani
184! - removed wind_turbine cpu measurement, since same time is measured inside
185!   wtm_forces subroutine as special measures
186! - moved the numerous vnest cpulog to special measures
187! - extended radiation cpulog over entire radiation part,
188!   moved radiation_interactions cpulog to special measures
189! - moved some cpu_log calls to this routine for better overview
190!
191! 3705 2019-01-29 19:56:39Z suehring
192! Data output for virtual measurements added
193!
194! 3704 2019-01-29 19:51:41Z suehring
195! Rename subroutines for surface-data output
196!
197! 3647 2019-01-02 14:10:44Z kanani
198! Bugfix: add time_since_reference_point to IF clause for data_output calls
199! (otherwise skip_time_* values don't come into affect with dt_do* = 0.0).
200! Clean up indoor_model and biometeorology model call.
201!
202! Revision 1.1  1997/08/11 06:19:04  raasch
203! Initial revision
204!
205!
206! Description:
207! ------------
208!> Integration in time of the model equations, statistical analysis and graphic
209!> output
210!------------------------------------------------------------------------------!
211 SUBROUTINE time_integration
212
213
214    USE advec_ws,                                                                                  &
215        ONLY:  ws_statistics
216
217    USE arrays_3d,                                                                                 &
218        ONLY:  diss, diss_p, dzu, e_p, nc_p, ni_p, nr_p, prho, pt, pt_p, pt_init, q, qc_p, qr_p,   &
219               q_init, q_p, qi_p, ref_state, rho_ocean, sa_p, s_p, tend, u, u_p, v, vpt, v_p, w_p
220
221#if defined( __parallel )  &&  ! defined( _OPENACC )
222    USE arrays_3d,                                                                                 &
223        ONLY:  e, nc, ni, nr, qc, qi, qr, s, w
224#endif
225
226    USE biometeorology_mod,                                                                        &
227        ONLY:  bio_calculate_thermal_index_maps, thermal_comfort, bio_calculate_uv_exposure,       &
228               uv_exposure
229
230    USE bulk_cloud_model_mod,                                                                      &
231        ONLY: bulk_cloud_model, calc_liquid_water_content, collision_turbulence,                   &
232              microphysics_ice_extension, microphysics_morrison, microphysics_seifert
233
234    USE calc_mean_profile_mod,                                                                     &
235        ONLY:  calc_mean_profile
236
237    USE chem_emissions_mod,                                                                        &
238        ONLY:  chem_emissions_setup, chem_emissions_update_on_demand
239
240    USE chem_gasphase_mod,                                                                         &
241        ONLY:  nvar
242
243    USE chem_modules,                                                                              &
244        ONLY:  bc_cs_t_val, chem_species, emissions_anthropogenic, emiss_read_legacy_mode,         &
245               n_matched_vars
246
247#if defined( __parallel )
248    USE chem_modules,                                                                              &
249        ONLY:  cs_name
250#endif
251
252    USE chemistry_model_mod,                                                                       &
253        ONLY:  chem_boundary_conds
254
255    USE control_parameters,                                                                        &
256        ONLY:  advected_distance_x, advected_distance_y, air_chemistry, average_count_3d,          &
257               averaging_interval, averaging_interval_pr, bc_lr_cyc, bc_ns_cyc, bc_pt_t_val,       &
258               bc_q_t_val, biometeorology, call_psolver_at_all_substeps,  child_domain,            &
259               constant_flux_layer, constant_heatflux, create_disturbances,        &
260               dopr_n, constant_diffusion, coupling_mode, coupling_start_time,                     &
261               current_timestep_number, disturbance_created, disturbance_energy_limit, dist_range, &
262               do_sum, dt_3d, dt_averaging_input, dt_averaging_input_pr, dt_coupling,              &
263               dt_data_output_av, dt_disturb, dt_do2d_xy, dt_do2d_xz, dt_do2d_yz, dt_do3d,         &
264               dt_domask,dt_dopts, dt_dopr, dt_dopr_listing, dt_dots, dt_run_control,              &
265               end_time, first_call_lpm, first_call_mas, galilei_transformation, humidity,         &
266               indoor_model, intermediate_timestep_count, intermediate_timestep_count_max,         &
267               land_surface, large_scale_forcing, loop_optimization, lsf_surf, lsf_vert, masks,    &
268               multi_agent_system_end, multi_agent_system_start, nesting_offline, neutral,         &
269               nr_timesteps_this_run, nudging, ocean_mode, passive_scalar, pt_reference,           &
270               pt_slope_offset, random_heatflux, rans_tke_e, run_coupled, salsa,                   &
271               simulated_time, simulated_time_chr, skip_time_do2d_xy, skip_time_do2d_xz,           &
272               skip_time_do2d_yz, skip_time_do3d, skip_time_domask, skip_time_dopr,                &
273               skip_time_data_output_av, sloping_surface, stop_dt, surface_output,                 &
274               terminate_coupled, terminate_run, timestep_scheme, time_coupling, time_do2d_xy,     &
275               time_do2d_xz, time_do2d_yz, time_do3d, time_domask, time_dopr, time_dopr_av,        &
276               time_dopr_listing, time_dopts, time_dosp, time_dosp_av, time_dots, time_do_av,      &
277               time_do_sla, time_disturb, time_run_control, time_since_reference_point,            &
278               timestep_count, turbulent_inflow, turbulent_outflow, urban_surface,                 &
279               use_initial_profile_as_reference, use_single_reference_value, u_gtrans, v_gtrans,   &
280               virtual_flight, virtual_measurement, ws_scheme_mom, ws_scheme_sca
281
282#if defined( __parallel )
283    USE control_parameters,                                                                        &
284        ONLY:  rans_mode
285#endif
286
287    USE cpulog,                                                                                    &
288        ONLY:  cpu_log, log_point, log_point_s
289
290    USE diagnostic_output_quantities_mod,                                                          &
291        ONLY:  doq_calculate,                                                                      &
292               timestep_number_at_prev_calc
293
294    USE exchange_horiz_mod,                                                                        &
295        ONLY:  exchange_horiz
296
297    USE flight_mod,                                                                                &
298        ONLY:  flight_measurement
299
300    USE grid_variables,                                                                            &
301        ONLY:  ddx, ddy
302
303    USE indices,                                                                                   &
304        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nzb, nzt
305
306    USE indoor_model_mod,                                                                          &
307        ONLY:  dt_indoor, im_main_heatcool, time_indoor
308
309    USE interfaces
310
311    USE kinds
312
313    USE land_surface_model_mod,                                                                    &
314        ONLY:  lsm_boundary_condition, lsm_energy_balance, lsm_soil_model, skip_time_do_lsm
315
316    USE lagrangian_particle_model_mod,                                                             &
317        ONLY:  lpm_data_output_ptseries
318
319    USE lsf_nudging_mod,                                                                           &
320        ONLY:  calc_tnudge, ls_forcing_surf, ls_forcing_vert, nudge_ref
321
322    USE module_interface,                                                                          &
323        ONLY:  module_interface_actions, module_interface_swap_timelevel,                          &
324               module_interface_boundary_conditions
325
326    USE multi_agent_system_mod,                                                                    &
327        ONLY:  agents_active, multi_agent_system
328
329    USE nesting_offl_mod,                                                                          &
330        ONLY:  nesting_offl_bc,                                                                    &
331               nesting_offl_geostrophic_wind,                                                      &
332               nesting_offl_input,                                                                 &
333               nesting_offl_interpolation_factor,                                                  &
334               nesting_offl_mass_conservation
335
336    USE netcdf_data_input_mod,                                                                     &
337        ONLY:  chem_emis, chem_emis_att
338
339    USE ocean_mod,                                                                                 &
340        ONLY:  prho_reference
341
342    USE palm_date_time_mod,                                                                        &
343        ONLY:  get_date_time
344
345    USE particle_attributes,                                                                       &
346        ONLY:  particle_advection, particle_advection_start, use_sgs_for_particles, wang_kernel
347
348    USE pegrid
349
350#if defined( __parallel )
351    USE pmc_interface,                                                                             &
352        ONLY:  nested_run, nesting_mode, pmci_boundary_conds, pmci_datatrans, pmci_synchronize,    &
353        pmci_ensure_nest_mass_conservation, pmci_ensure_nest_mass_conservation_vertical,           &
354        pmci_set_swaplevel
355#endif
356
357    USE progress_bar,                                                                              &
358        ONLY:  finish_progress_bar, output_progress_bar
359
360    USE prognostic_equations_mod,                                                                  &
361        ONLY:  prognostic_equations_cache, prognostic_equations_vector
362
363    USE radiation_model_mod,                                                                       &
364        ONLY: dt_radiation, force_radiation_call, radiation, radiation_control,                    &
365              radiation_interaction, radiation_interactions, skip_time_do_radiation, time_radiation
366
367    USE salsa_mod,                                                                                 &
368        ONLY: aerosol_number, aerosol_mass, bc_am_t_val, bc_an_t_val, bc_gt_t_val,                 &
369              communicator_salsa, nbins_aerosol, ncomponents_mass, ngases_salsa,                   &
370              salsa_boundary_conditions, salsa_emission_update, salsa_gas, salsa_gases_from_chem,  &
371              skip_time_do_salsa
372
373    USE spectra_mod,                                                                               &
374        ONLY: average_count_sp, averaging_interval_sp, calc_spectra, dt_dosp, skip_time_dosp
375
376    USE statistics,                                                                                &
377        ONLY:  flow_statistics_called, hom, pr_palm, sums_ls_l
378
379
380    USE surface_layer_fluxes_mod,                                                                  &
381        ONLY:  surface_layer_fluxes
382
383    USE surface_data_output_mod,                                                                   &
384        ONLY:  average_count_surf, averaging_interval_surf, dt_dosurf, dt_dosurf_av,               &
385               surface_data_output, surface_data_output_averaging, skip_time_dosurf,               &
386               skip_time_dosurf_av, time_dosurf, time_dosurf_av
387
388    USE surface_mod,                                                                               &
389        ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
390
391    USE synthetic_turbulence_generator_mod,                                                        &
392        ONLY:  dt_stg_call, dt_stg_adjust, parametrize_inflow_turbulence, stg_adjust, stg_main,    &
393               time_stg_adjust, time_stg_call, use_syn_turb_gen
394
395    USE turbulence_closure_mod,                                                                    &
396        ONLY:  tcm_diffusivities
397
398    USE urban_surface_mod,                                                                         &
399        ONLY:  usm_boundary_condition, usm_material_heat_model, usm_material_model,                &
400               usm_surface_energy_balance, usm_green_heat_model
401
402    USE vertical_nesting_mod,                                                                      &
403        ONLY:  vnested, vnest_init
404
405#if defined( __parallel )
406    USE vertical_nesting_mod,                                                                      &
407        ONLY:  vnest_anterpolate, vnest_anterpolate_e, vnest_boundary_conds,                       &
408               vnest_boundary_conds_khkm, vnest_deallocate, vnest_init_fine, vnest_start_time
409#endif
410
411    USE virtual_measurement_mod,                                                                   &
412        ONLY:  dt_virtual_measurement,                                                             &
413               time_virtual_measurement,                                                           &
414               vm_data_output,                                                                     &
415               vm_sampling,                                                                        &
416               vm_time_start
417
418
419    USE wind_turbine_model_mod,                                                                    &
420        ONLY:  dt_data_output_wtm, time_wtm, wind_turbine, wtm_data_output
421
422#if defined( _OPENACC )
423    USE arrays_3d,                                                                                 &
424        ONLY:  d, dd2zu, ddzu, ddzw,                                                               &
425               diss_l_u,                                                                           &
426               diss_l_v,                                                                           &
427               diss_l_w,                                                                           &
428               diss_s_u,                                                                           &
429               diss_s_v,                                                                           &
430               diss_s_w,                                                                           &
431               drho_air, drho_air_zw, dzw, e,                                                      &
432               flux_l_u,                                                                           &
433               flux_l_v,                                                                           &
434               flux_l_w,                                                                           &
435               flux_s_u,                                                                           &
436               flux_s_v,                                                                           &
437               flux_s_w,                                                                           &
438               heatflux_output_conversion,                                                         &
439               kh, km, momentumflux_output_conversion, nc, ni, nr, p, ptdf_x, ptdf_y, qc, qi, qr, rdf,     &
440               rdf_sc, rho_air, rho_air_zw, s, tdiss_m, te_m, tpt_m, tu_m, tv_m, tw_m, ug, u_init, &
441               u_stokes_zu, vg, v_init, v_stokes_zu, w, zu
442
443    USE control_parameters,                                                                        &
444        ONLY:  tsc
445
446    USE indices,                                                                                   &
447        ONLY:  advc_flags_m, advc_flags_s, nyn, nyng, nys, nysg, nz, nzb_max, wall_flags_total_0
448
449    USE statistics,                                                                                &
450        ONLY:  rmask, statistic_regions, sums_l, sums_l_l, sums_us2_ws_l,                          &
451               sums_wsus_ws_l, sums_vs2_ws_l, sums_wsvs_ws_l, sums_ws2_ws_l, sums_wspts_ws_l,      &
452               sums_wsqs_ws_l, sums_wssas_ws_l, sums_wsqcs_ws_l, sums_wsqrs_ws_l, sums_wsncs_ws_l, &
453               sums_wsnrs_ws_l, sums_wsss_ws_l, weight_substep, sums_salsa_ws_l, sums_wsqis_ws_l,  &
454               sums_wsnis_ws_l
455
456    USE surface_mod,                                                                               &
457        ONLY:  bc_h, enter_surface_arrays, exit_surface_arrays
458#endif
459
460
461    IMPLICIT NONE
462
463    CHARACTER (LEN=9) ::  time_to_string   !<
464
465    INTEGER(iwp) ::  hour                !< hour of current time
466    INTEGER(iwp) ::  hour_call_emis = -1 !< last hour where emission was called
467    INTEGER(iwp) ::  ib                  !< index for aerosol size bins
468    INTEGER(iwp) ::  ic                  !< index for aerosol mass bins
469    INTEGER(iwp) ::  icc                 !< additional index for aerosol mass bins
470    INTEGER(iwp) ::  ig                  !< index for salsa gases
471    INTEGER(iwp) ::  lsp                 !<
472    INTEGER(iwp) ::  mid                 !< masked output running index
473#if defined( __parallel )
474    INTEGER(iwp) ::  lsp_usr             !<
475    INTEGER(iwp) ::  n                   !< loop counter for chemistry species
476#endif
477
478    REAL(wp) ::  dt_3d_old  !< temporary storage of timestep to be used for
479                            !< steering of run control output interval
480    REAL(wp) ::  time_since_reference_point_save  !< original value of
481                                                  !< time_since_reference_point
482
483
484!
485!-- Copy data from arrays_3d
486!$ACC DATA &
487!$ACC COPY(d(nzb+1:nzt,nys:nyn,nxl:nxr)) &
488!$ACC COPY(diss(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
489!$ACC COPY(e(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
490!$ACC COPY(u(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
491!$ACC COPY(v(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
492!$ACC COPY(w(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
493!$ACC COPY(kh(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
494!$ACC COPY(km(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
495!$ACC COPY(p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
496!$ACC COPY(pt(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
497
498!$ACC DATA &
499!$ACC COPYIN(diss_l_u(0:nz+1,nys:nyn,0), flux_l_u(0:nz+1,nys:nyn,0)) &
500!$ACC COPYIN(diss_l_v(0:nz+1,nys:nyn,0), flux_l_v(0:nz+1,nys:nyn,0)) &
501!$ACC COPYIN(diss_l_w(0:nz+1,nys:nyn,0), flux_l_w(0:nz+1,nys:nyn,0)) &
502!$ACC COPYIN(diss_s_u(0:nz+1,0), flux_s_u(0:nz+1,0)) &
503!$ACC COPYIN(diss_s_v(0:nz+1,0), flux_s_v(0:nz+1,0)) &
504!$ACC COPYIN(diss_s_w(0:nz+1,0), flux_s_w(0:nz+1,0)) &
505!$ACC COPY(diss_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
506!$ACC COPY(e_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
507!$ACC COPY(u_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
508!$ACC COPY(v_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
509!$ACC COPY(w_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
510!$ACC COPY(pt_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
511!$ACC COPY(tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
512!$ACC COPY(tdiss_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
513!$ACC COPY(te_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
514!$ACC COPY(tu_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
515!$ACC COPY(tv_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
516!$ACC COPY(tw_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
517!$ACC COPY(tpt_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
518
519!$ACC DATA &
520!$ACC COPYIN(rho_air(nzb:nzt+1), drho_air(nzb:nzt+1)) &
521!$ACC COPYIN(rho_air_zw(nzb:nzt+1), drho_air_zw(nzb:nzt+1)) &
522!$ACC COPYIN(zu(nzb:nzt+1)) &
523!$ACC COPYIN(dzu(1:nzt+1), dzw(1:nzt+1)) &
524!$ACC COPYIN(ddzu(1:nzt+1), dd2zu(1:nzt)) &
525!$ACC COPYIN(ddzw(1:nzt+1)) &
526!$ACC COPYIN(heatflux_output_conversion(nzb:nzt+1)) &
527!$ACC COPYIN(momentumflux_output_conversion(nzb:nzt+1)) &
528!$ACC COPYIN(rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt)) &
529!$ACC COPYIN(ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng)) &
530!$ACC COPYIN(ref_state(0:nz+1)) &
531!$ACC COPYIN(u_init(0:nz+1), v_init(0:nz+1)) &
532!$ACC COPYIN(u_stokes_zu(nzb:nzt+1), v_stokes_zu(nzb:nzt+1)) &
533!$ACC COPYIN(pt_init(0:nz+1)) &
534!$ACC COPYIN(ug(0:nz+1), vg(0:nz+1))
535
536!
537!-- Copy data from control_parameters
538!$ACC DATA &
539!$ACC COPYIN(tsc(1:5))
540
541!
542!-- Copy data from grid_variables
543!$ACC DATA &
544!$ACC COPYIN(ddx, ddy)
545
546!
547!-- Copy data from indices
548!$ACC DATA &
549!$ACC COPYIN(advc_flags_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
550!$ACC COPYIN(advc_flags_s(nzb:nzt+1,nysg:nyng,nxlg:nxrg)) &
551!$ACC COPYIN(wall_flags_total_0(nzb:nzt+1,nysg:nyng,nxlg:nxrg))
552
553!
554!-- Copy data from surface_mod
555!$ACC DATA &
556!$ACC COPYIN(bc_h(0:1)) &
557!$ACC COPYIN(bc_h(0)%i(1:bc_h(0)%ns)) &
558!$ACC COPYIN(bc_h(0)%j(1:bc_h(0)%ns)) &
559!$ACC COPYIN(bc_h(0)%k(1:bc_h(0)%ns)) &
560!$ACC COPYIN(bc_h(1)%i(1:bc_h(1)%ns)) &
561!$ACC COPYIN(bc_h(1)%j(1:bc_h(1)%ns)) &
562!$ACC COPYIN(bc_h(1)%k(1:bc_h(1)%ns))
563
564!
565!-- Copy data from statistics
566!$ACC DATA &
567!$ACC COPYIN(hom(0:nz+1,1:2,1:4,0)) &
568!$ACC COPYIN(rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions)) &
569!$ACC COPYIN(weight_substep(1:intermediate_timestep_count_max)) &
570!$ACC COPY(sums_l(nzb:nzt+1,1:pr_palm,0)) &
571!$ACC COPY(sums_l_l(nzb:nzt+1,0:statistic_regions,0)) &
572!$ACC COPY(sums_us2_ws_l(nzb:nzt+1,0)) &
573!$ACC COPY(sums_wsus_ws_l(nzb:nzt+1,0)) &
574!$ACC COPY(sums_vs2_ws_l(nzb:nzt+1,0)) &
575!$ACC COPY(sums_wsvs_ws_l(nzb:nzt+1,0)) &
576!$ACC COPY(sums_ws2_ws_l(nzb:nzt+1,0)) &
577!$ACC COPY(sums_wspts_ws_l(nzb:nzt+1,0)) &
578!$ACC COPY(sums_wssas_ws_l(nzb:nzt+1,0)) &
579!$ACC COPY(sums_wsqs_ws_l(nzb:nzt+1,0)) &
580!$ACC COPY(sums_wsqcs_ws_l(nzb:nzt+1,0)) &
581!$ACC COPY(sums_wsqis_ws_l(nzb:nzt+1,0)) &
582!$ACC COPY(sums_wsqrs_ws_l(nzb:nzt+1,0)) &
583!$ACC COPY(sums_wsncs_ws_l(nzb:nzt+1,0)) &
584!$ACC COPY(sums_wsnis_ws_l(nzb:nzt+1,0)) &
585!$ACC COPY(sums_wsnrs_ws_l(nzb:nzt+1,0)) &
586!$ACC COPY(sums_wsss_ws_l(nzb:nzt+1,0)) &
587!$ACC COPY(sums_salsa_ws_l(nzb:nzt+1,0))
588
589!
590!-- Next statement is to avoid compiler warnings about unused variables. Please
591!-- remove in case that you are using them. ddx and ddy need to be defined in
592!-- time_integration because of ACC COPYIN directive.
593    ddx = ddx
594    ddy = ddy
595
596#if defined( _OPENACC )
597    CALL enter_surface_arrays
598#endif
599
600!
601!-- At beginning determine the first time step
602    CALL timestep
603
604#if defined( __parallel )
605!
606!-- Synchronize the timestep in case of nested run.
607    IF ( nested_run )  THEN
608!
609!--    Synchronization by unifying the time step.
610!--    Global minimum of all time-steps is used for all.
611       CALL pmci_synchronize
612    ENDIF
613#endif
614
615!
616!-- Determine and print out the run control quantities before the first time
617!-- step of this run. For the initial run, some statistics (e.g. divergence)
618!-- need to be determined first --> CALL flow_statistics at the beginning of
619!-- run_control
620    CALL run_control
621!
622!-- Data exchange between coupled models in case that a call has been omitted
623!-- at the end of the previous run of a job chain.
624    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled  .AND. .NOT. vnested )  THEN
625!
626!--    In case of model termination initiated by the local model the coupler
627!--    must not be called because this would again cause an MPI hang.
628       DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
629          CALL surface_coupler
630          time_coupling = time_coupling - dt_coupling
631       ENDDO
632       IF (time_coupling == 0.0_wp  .AND.  time_since_reference_point < dt_coupling )  THEN
633          time_coupling = time_since_reference_point
634       ENDIF
635    ENDIF
636
637    CALL location_message( 'atmosphere (and/or ocean) time-stepping', 'start' )
638
639!
640!-- Start of the time loop
641    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. .NOT. terminate_run )
642
643       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
644
645#if defined( __parallel )
646!
647!--    Vertical nesting: initialize fine grid
648       IF ( vnested ) THEN
649          IF ( .NOT. vnest_init  .AND.  simulated_time >= vnest_start_time )  THEN
650             CALL cpu_log( log_point_s(22), 'vnest_init', 'start' )
651             CALL vnest_init_fine
652             vnest_init = .TRUE.
653             CALL cpu_log( log_point_s(22), 'vnest_init', 'stop' )
654          ENDIF
655       ENDIF
656#endif
657
658!
659!--    Determine ug, vg and w_subs in dependence on data from external file
660!--    LSF_DATA
661       IF ( large_scale_forcing .AND. lsf_vert )  THEN
662           CALL ls_forcing_vert ( simulated_time )
663           sums_ls_l = 0.0_wp
664       ENDIF
665
666!
667!--    Set pt_init and q_init to the current profiles taken from
668!--    NUDGING_DATA
669       IF ( nudging )  THEN
670           CALL nudge_ref ( simulated_time )
671!
672!--        Store temperature gradient at the top boundary for possible Neumann
673!--        boundary condition
674           bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
675           bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
676           IF ( air_chemistry )  THEN
677              DO  lsp = 1, nvar
678                 bc_cs_t_val = (  chem_species(lsp)%conc_pr_init(nzt+1)                            &
679                                - chem_species(lsp)%conc_pr_init(nzt) )                            &
680                               / dzu(nzt+1)
681              ENDDO
682           ENDIF
683           IF ( salsa  .AND.  time_since_reference_point >= skip_time_do_salsa )  THEN
684              DO  ib = 1, nbins_aerosol
685                 bc_an_t_val = ( aerosol_number(ib)%init(nzt+1) - aerosol_number(ib)%init(nzt) ) / &
686                               dzu(nzt+1)
687                 DO  ic = 1, ncomponents_mass
688                    icc = ( ic - 1 ) * nbins_aerosol + ib
689                    bc_am_t_val = ( aerosol_mass(icc)%init(nzt+1) - aerosol_mass(icc)%init(nzt) ) /&
690                                  dzu(nzt+1)
691                 ENDDO
692              ENDDO
693              IF ( .NOT. salsa_gases_from_chem )  THEN
694                 DO  ig = 1, ngases_salsa
695                    bc_gt_t_val = ( salsa_gas(ig)%init(nzt+1) - salsa_gas(ig)%init(nzt) ) /        &
696                                  dzu(nzt+1)
697                 ENDDO
698              ENDIF
699           ENDIF
700       ENDIF
701!
702!--    Input of boundary data.
703       IF ( nesting_offline )  CALL nesting_offl_input
704!
705!--    Execute all other module actions routines
706       CALL module_interface_actions( 'before_timestep' )
707
708!
709!--    Start of intermediate step loop
710       intermediate_timestep_count = 0
711       DO  WHILE ( intermediate_timestep_count < intermediate_timestep_count_max )
712
713          intermediate_timestep_count = intermediate_timestep_count + 1
714
715!
716!--       Set the steering factors for the prognostic equations which depend
717!--       on the timestep scheme
718          CALL timestep_scheme_steering
719
720!
721!--       Calculate those variables needed in the tendency terms which need
722!--       global communication
723          IF ( .NOT. use_single_reference_value  .AND.  .NOT. use_initial_profile_as_reference )   &
724          THEN
725!
726!--          Horizontally averaged profiles to be used as reference state in
727!--          buoyancy terms (WARNING: only the respective last call of
728!--          calc_mean_profile defines the reference state!)
729             IF ( .NOT. neutral )  THEN
730                CALL calc_mean_profile( pt, 4 )
731                ref_state(:)  = hom(:,1,4,0) ! this is used in the buoyancy term
732             ENDIF
733             IF ( ocean_mode )  THEN
734                CALL calc_mean_profile( rho_ocean, 64 )
735                ref_state(:)  = hom(:,1,64,0)
736             ENDIF
737             IF ( humidity )  THEN
738                CALL calc_mean_profile( vpt, 44 )
739                ref_state(:)  = hom(:,1,44,0)
740             ENDIF
741!
742!--          Assure that ref_state does not become zero at any level
743!--          ( might be the case if a vertical level is completely occupied
744!--            with topography ).
745             ref_state = MERGE( MAXVAL(ref_state), ref_state, ref_state == 0.0_wp )
746          ENDIF
747
748          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  intermediate_timestep_count == 1 )     &
749          THEN
750             CALL ws_statistics
751          ENDIF
752!
753!--       In case of nudging calculate current nudging time scale and horizontal
754!--       means of u, v, pt and q
755          IF ( nudging )  THEN
756             CALL calc_tnudge( simulated_time )
757             CALL calc_mean_profile( u, 1 )
758             CALL calc_mean_profile( v, 2 )
759             CALL calc_mean_profile( pt, 4 )
760             CALL calc_mean_profile( q, 41 )
761          ENDIF
762!
763!--       Execute all other module actions routunes
764          CALL module_interface_actions( 'before_prognostic_equations' )
765!
766!--       Solve the prognostic equations. A fast cache optimized version with
767!--       only one single loop is used in case of Piascek-Williams advection
768!--       scheme. NEC vector machines use a different version, because
769!--       in the other versions a good vectorization is prohibited due to
770!--       inlining problems.
771          IF ( loop_optimization == 'cache' )  THEN
772             CALL prognostic_equations_cache
773          ELSEIF ( loop_optimization == 'vector' )  THEN
774             CALL prognostic_equations_vector
775          ENDIF
776
777!
778!--       Movement of agents in multi agent system
779          IF ( agents_active  .AND.  time_since_reference_point >= multi_agent_system_start  .AND. &
780               time_since_reference_point <= multi_agent_system_end  .AND.                         &
781               intermediate_timestep_count == 1 )                                                  &
782          THEN
783             CALL multi_agent_system
784             first_call_mas = .FALSE.
785          ENDIF
786
787!
788!--       Exchange of ghost points (lateral boundary conditions)
789          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
790
791          CALL exchange_horiz( u_p, nbgp )
792          CALL exchange_horiz( v_p, nbgp )
793          CALL exchange_horiz( w_p, nbgp )
794          CALL exchange_horiz( pt_p, nbgp )
795          IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
796          IF ( rans_tke_e  .OR.  wang_kernel  .OR.  collision_turbulence                           &
797               .OR.  use_sgs_for_particles )  THEN
798             IF ( rans_tke_e )  THEN
799                CALL exchange_horiz( diss_p, nbgp )
800             ELSE
801                CALL exchange_horiz( diss, nbgp )
802             ENDIF
803          ENDIF
804          IF ( ocean_mode )  THEN
805             CALL exchange_horiz( sa_p, nbgp )
806             CALL exchange_horiz( rho_ocean, nbgp )
807             CALL exchange_horiz( prho, nbgp )
808          ENDIF
809          IF ( humidity )  THEN
810             CALL exchange_horiz( q_p, nbgp )
811             IF ( bulk_cloud_model .AND. microphysics_morrison )  THEN
812                CALL exchange_horiz( qc_p, nbgp )
813                CALL exchange_horiz( nc_p, nbgp )
814             ENDIF
815             IF ( bulk_cloud_model .AND. microphysics_seifert )  THEN
816                CALL exchange_horiz( qr_p, nbgp )
817                CALL exchange_horiz( nr_p, nbgp )
818             ENDIF
819             IF ( bulk_cloud_model .AND. microphysics_ice_extension )  THEN
820                CALL exchange_horiz( qi_p, nbgp )
821                CALL exchange_horiz( ni_p, nbgp )
822             ENDIF
823          ENDIF
824          IF ( passive_scalar )  CALL exchange_horiz( s_p, nbgp )
825          IF ( air_chemistry )  THEN
826             DO  lsp = 1, nvar
827                CALL exchange_horiz( chem_species(lsp)%conc_p, nbgp )
828             ENDDO
829          ENDIF
830
831          IF ( salsa  .AND.  time_since_reference_point >= skip_time_do_salsa )  THEN
832             DO  ib = 1, nbins_aerosol
833                CALL exchange_horiz( aerosol_number(ib)%conc_p, nbgp,                              &
834                                     alternative_communicator = communicator_salsa )
835                DO  ic = 1, ncomponents_mass
836                   icc = ( ic - 1 ) * nbins_aerosol + ib
837                   CALL exchange_horiz( aerosol_mass(icc)%conc_p, nbgp,                            &
838                                        alternative_communicator = communicator_salsa )
839                ENDDO
840             ENDDO
841             IF ( .NOT. salsa_gases_from_chem )  THEN
842                DO  ig = 1, ngases_salsa
843                   CALL exchange_horiz( salsa_gas(ig)%conc_p, nbgp,                                &
844                                        alternative_communicator = communicator_salsa )
845                ENDDO
846             ENDIF
847          ENDIF
848
849          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
850
851!
852!--       Boundary conditions for the prognostic quantities (except of the
853!--       velocities at the outflow in case of a non-cyclic lateral wall) and
854!--       boundary conditions for module-specific variables
855          CALL module_interface_boundary_conditions
856
857!
858!--       Incrementing timestep counter
859          timestep_count = timestep_count + 1
860
861          CALL cpu_log( log_point(28), 'swap_timelevel', 'start' )
862!
863!--       Set the swap level for all modules
864          CALL module_interface_swap_timelevel( MOD( timestep_count, 2) )
865
866#if defined( __parallel )
867!
868!--       Set the swap level for steering the pmc data transfer
869          IF ( nested_run )  CALL pmci_set_swaplevel( MOD( timestep_count, 2) + 1 )  !> @todo: why the +1 ?
870#endif
871
872          CALL cpu_log( log_point(28), 'swap_timelevel', 'stop' )
873
874#if defined( __parallel )
875!
876!--       Vertical nesting: Interpolate fine grid data to the coarse grid
877          IF ( vnest_init ) THEN
878             CALL cpu_log( log_point_s(37), 'vnest_anterpolate', 'start' )
879             CALL vnest_anterpolate
880             CALL cpu_log( log_point_s(37), 'vnest_anterpolate', 'stop' )
881          ENDIF
882
883          IF ( nested_run )  THEN
884
885             CALL cpu_log( log_point(60), 'nesting', 'start' )
886!
887!--          Domain nesting. The data transfer subroutines pmci_parent_datatrans
888!--          and pmci_child_datatrans are called inside the wrapper
889!--          subroutine pmci_datatrans according to the control parameters
890!--          nesting_mode and nesting_datatransfer_mode.
891!--          TO_DO: why is nesting_mode given as a parameter here?
892             CALL pmci_datatrans( nesting_mode )
893
894             IF ( TRIM( nesting_mode ) == 'two-way' .OR.  nesting_mode == 'vertical' )  THEN
895
896                CALL cpu_log( log_point_s(92), 'exchange-horiz-nest', 'start' )
897!
898!--             Exchange_horiz is needed for all parent-domains after the
899!--             anterpolation
900                CALL exchange_horiz( u, nbgp )
901                CALL exchange_horiz( v, nbgp )
902                CALL exchange_horiz( w, nbgp )
903                IF ( .NOT. neutral )  CALL exchange_horiz( pt, nbgp )
904
905                IF ( humidity )  THEN
906
907                   CALL exchange_horiz( q, nbgp )
908
909                   IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
910                       CALL exchange_horiz( qc, nbgp )
911                       CALL exchange_horiz( nc, nbgp )
912                   ENDIF
913                   IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
914                       CALL exchange_horiz( qr, nbgp )
915                       CALL exchange_horiz( nr, nbgp )
916                   ENDIF
917                   IF ( bulk_cloud_model  .AND.  microphysics_ice_extension )  THEN
918                      CALL exchange_horiz( qi, nbgp )
919                      CALL exchange_horiz( ni, nbgp )
920                   ENDIF
921
922                ENDIF
923
924                IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
925
926                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
927
928                IF ( .NOT. constant_diffusion  .AND.  rans_mode  .AND.  rans_tke_e )  THEN
929                   CALL exchange_horiz( diss, nbgp )
930                ENDIF
931
932                IF ( air_chemistry )  THEN
933                   DO  n = 1, nvar
934                      CALL exchange_horiz( chem_species(n)%conc, nbgp )
935                   ENDDO
936                ENDIF
937
938                IF ( salsa  .AND. time_since_reference_point >= skip_time_do_salsa )  THEN
939                   DO  ib = 1, nbins_aerosol
940                      CALL exchange_horiz( aerosol_number(ib)%conc, nbgp,                          &
941                                           alternative_communicator = communicator_salsa )
942                      DO  ic = 1, ncomponents_mass
943                         icc = ( ic - 1 ) * nbins_aerosol + ib
944                         CALL exchange_horiz( aerosol_mass(icc)%conc, nbgp,                        &
945                                              alternative_communicator = communicator_salsa )
946                      ENDDO
947                   ENDDO
948                   IF ( .NOT. salsa_gases_from_chem )  THEN
949                      DO  ig = 1, ngases_salsa
950                         CALL exchange_horiz( salsa_gas(ig)%conc, nbgp,                            &
951                                              alternative_communicator = communicator_salsa )
952                      ENDDO
953                   ENDIF
954                ENDIF
955                CALL cpu_log( log_point_s(92), 'exchange-horiz-nest', 'stop' )
956
957             ENDIF
958
959!
960!--          Set boundary conditions again after interpolation and anterpolation.
961             CALL pmci_boundary_conds
962
963!
964!--          Set chemistry boundary conditions (decycling)
965             IF ( air_chemistry )  THEN
966                DO  lsp = 1, nvar
967                   lsp_usr = 1
968                   DO WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )
969                      IF ( TRIM( chem_species(lsp)%name ) == TRIM( cs_name(lsp_usr) ) )  THEN
970                         CALL chem_boundary_conds( chem_species(lsp)%conc,                         &
971                                                   chem_species(lsp)%conc_pr_init )
972                      ENDIF
973                      lsp_usr = lsp_usr + 1
974                   ENDDO
975                ENDDO
976             ENDIF
977
978             CALL cpu_log( log_point(60), 'nesting', 'stop' )
979
980          ENDIF
981#endif
982
983!
984!--       Temperature offset must be imposed at cyclic boundaries in x-direction
985!--       when a sloping surface is used
986          IF ( sloping_surface )  THEN
987             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - pt_slope_offset
988             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + pt_slope_offset
989          ENDIF
990
991!
992!--       Impose a turbulent inflow using the recycling method
993          IF ( turbulent_inflow )  CALL inflow_turbulence
994
995!
996!--       Set values at outflow boundary using the special outflow condition
997          IF ( turbulent_outflow )  CALL outflow_turbulence
998
999!
1000!--       Impose a random perturbation on the horizontal velocity field
1001          IF ( create_disturbances  .AND.  ( call_psolver_at_all_substeps  .AND.                   &
1002               intermediate_timestep_count == intermediate_timestep_count_max )                    &
1003               .OR. ( .NOT. call_psolver_at_all_substeps  .AND.  intermediate_timestep_count == 1 ) ) &
1004          THEN
1005             time_disturb = time_disturb + dt_3d
1006             IF ( time_disturb >= dt_disturb )  THEN
1007                IF ( disturbance_energy_limit /= 0.0_wp  .AND.                                     &
1008                     hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
1009                   CALL disturb_field( 'u', tend, u )
1010                   CALL disturb_field( 'v', tend, v )
1011                ELSEIF ( ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )                                &
1012                         .AND. .NOT. child_domain  .AND.  .NOT.  nesting_offline )                 &
1013                THEN
1014!
1015!--                Runs with a non-cyclic lateral wall need perturbations
1016!--                near the inflow throughout the whole simulation
1017                   dist_range = 1
1018                   CALL disturb_field( 'u', tend, u )
1019                   CALL disturb_field( 'v', tend, v )
1020                   dist_range = 0
1021                ENDIF
1022                time_disturb = time_disturb - dt_disturb
1023             ENDIF
1024          ENDIF
1025
1026!
1027!--       Map forcing data derived from larger scale model onto domain
1028!--       boundaries. Further, update geostrophic wind components.
1029          IF ( nesting_offline  .AND.  intermediate_timestep_count ==                              &
1030                                       intermediate_timestep_count_max  )  THEN
1031!--          Determine interpolation factor before boundary conditions and geostrophic wind
1032!--          is updated.
1033             CALL nesting_offl_interpolation_factor
1034             CALL nesting_offl_bc
1035             CALL nesting_offl_geostrophic_wind
1036          ENDIF
1037!
1038!--       Impose a turbulent inflow using synthetic generated turbulence.
1039          IF ( use_syn_turb_gen  .AND.                                                             &
1040               intermediate_timestep_count == intermediate_timestep_count_max )  THEN
1041             CALL cpu_log( log_point(57), 'synthetic_turbulence_gen', 'start' )
1042             CALL stg_main
1043             CALL cpu_log( log_point(57), 'synthetic_turbulence_gen', 'stop' )
1044          ENDIF
1045!
1046!--       Ensure mass conservation. This need to be done after imposing
1047!--       synthetic turbulence and top boundary condition for pressure is set to
1048!--       Neumann conditions.
1049!--       Is this also required in case of Dirichlet?
1050          IF ( nesting_offline )  CALL nesting_offl_mass_conservation
1051!
1052!--       Reduce the velocity divergence via the equation for perturbation
1053!--       pressure.
1054          IF ( intermediate_timestep_count == 1  .OR. &
1055                call_psolver_at_all_substeps )  THEN
1056
1057             IF (  vnest_init ) THEN
1058#if defined( __parallel )
1059!
1060!--             Compute pressure in the CG, interpolate top boundary conditions
1061!--             to the FG and then compute pressure in the FG
1062                IF ( coupling_mode == 'vnested_crse' )  CALL pres
1063
1064                CALL cpu_log( log_point_s(30), 'vnest_bc', 'start' )
1065                CALL vnest_boundary_conds
1066                CALL cpu_log( log_point_s(30), 'vnest_bc', 'stop' )
1067
1068                IF ( coupling_mode == 'vnested_fine' )  CALL pres
1069
1070!--             Anterpolate TKE, satisfy Germano Identity
1071                CALL cpu_log( log_point_s(28), 'vnest_anter_e', 'start' )
1072                CALL vnest_anterpolate_e
1073                CALL cpu_log( log_point_s(28), 'vnest_anter_e', 'stop' )
1074#else
1075                CONTINUE
1076#endif
1077
1078             ELSE
1079#if defined( __parallel )
1080!
1081!--             Mass (volume) flux correction to ensure global mass conservation for child domains.
1082                IF ( child_domain )  THEN
1083                   IF ( nesting_mode == 'vertical' )  THEN
1084                      CALL pmci_ensure_nest_mass_conservation_vertical
1085                   ELSE
1086                      CALL pmci_ensure_nest_mass_conservation
1087                   ENDIF
1088                ENDIF
1089#endif
1090                CALL pres
1091
1092             ENDIF
1093
1094          ENDIF
1095!
1096!--       Particle transport/physics with the Lagrangian particle model
1097!--       (only once during intermediate steps, because it uses an Euler-step)
1098!--       ### particle model should be moved before prognostic_equations, in order
1099!--       to regard droplet interactions directly
1100
1101          CALL module_interface_actions( 'after_pressure_solver' )
1102!
1103!--       Interaction of droplets with temperature and mixing ratio.
1104!--       Droplet condensation and evaporation is calculated within
1105!--       advec_particles.
1106!
1107!--       If required, compute liquid water content
1108          IF ( bulk_cloud_model )  THEN
1109             CALL calc_liquid_water_content
1110          ENDIF
1111!
1112!--       If required, compute virtual potential temperature
1113          IF ( humidity )  THEN
1114             CALL compute_vpt
1115          ENDIF
1116
1117!
1118!--       Compute the diffusion quantities
1119          IF ( .NOT. constant_diffusion )  THEN
1120
1121!
1122!--          Determine surface fluxes shf and qsws and surface values
1123!--          pt_surface and q_surface in dependence on data from external
1124!--          file LSF_DATA respectively
1125             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND.                                     &
1126                 intermediate_timestep_count == intermediate_timestep_count_max )                  &
1127             THEN
1128                CALL ls_forcing_surf( simulated_time )
1129             ENDIF
1130
1131!
1132!--          First the vertical (and horizontal) fluxes in the surface
1133!--          (constant flux) layer are computed
1134             IF ( constant_flux_layer )  THEN
1135                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'start' )
1136                CALL surface_layer_fluxes
1137                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'stop' )
1138             ENDIF
1139!
1140!--          If required, solve the energy balance for the surface and run soil
1141!--          model. Call for horizontal as well as vertical surfaces
1142             IF ( land_surface .AND. time_since_reference_point >= skip_time_do_lsm)  THEN
1143
1144                CALL cpu_log( log_point(54), 'land_surface', 'start' )
1145!
1146!--             Call for horizontal upward-facing surfaces
1147                CALL lsm_energy_balance( .TRUE., -1 )
1148                CALL lsm_soil_model( .TRUE., -1, .TRUE. )
1149!
1150!--             Call for northward-facing surfaces
1151                CALL lsm_energy_balance( .FALSE., 0 )
1152                CALL lsm_soil_model( .FALSE., 0, .TRUE. )
1153!
1154!--             Call for southward-facing surfaces
1155                CALL lsm_energy_balance( .FALSE., 1 )
1156                CALL lsm_soil_model( .FALSE., 1, .TRUE. )
1157!
1158!--             Call for eastward-facing surfaces
1159                CALL lsm_energy_balance( .FALSE., 2 )
1160                CALL lsm_soil_model( .FALSE., 2, .TRUE. )
1161!
1162!--             Call for westward-facing surfaces
1163                CALL lsm_energy_balance( .FALSE., 3 )
1164                CALL lsm_soil_model( .FALSE., 3, .TRUE. )
1165
1166!
1167!--             At the end, set boundary conditons for potential temperature
1168!--             and humidity after running the land-surface model. This
1169!--             might be important for the nesting, where arrays are transfered.
1170                CALL lsm_boundary_condition
1171
1172
1173                CALL cpu_log( log_point(54), 'land_surface', 'stop' )
1174             ENDIF
1175!
1176!--          If required, solve the energy balance for urban surfaces and run
1177!--          the material heat model
1178             IF (urban_surface) THEN
1179                CALL cpu_log( log_point(74), 'urban_surface', 'start' )
1180
1181                CALL usm_surface_energy_balance( .FALSE. )
1182                IF ( usm_material_model )  THEN
1183                   CALL usm_green_heat_model
1184                   CALL usm_material_heat_model ( .FALSE. )
1185                ENDIF
1186
1187!
1188!--             At the end, set boundary conditons for potential temperature
1189!--             and humidity after running the urban-surface model. This
1190!--             might be important for the nesting, where arrays are transfered.
1191                CALL usm_boundary_condition
1192
1193                CALL cpu_log( log_point(74), 'urban_surface', 'stop' )
1194             ENDIF
1195!
1196!--          Compute the diffusion coefficients
1197             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
1198             IF ( .NOT. humidity ) THEN
1199                IF ( ocean_mode )  THEN
1200                   CALL tcm_diffusivities( prho, prho_reference )
1201                ELSE
1202                   CALL tcm_diffusivities( pt, pt_reference )
1203                ENDIF
1204             ELSE
1205                CALL tcm_diffusivities( vpt, pt_reference )
1206             ENDIF
1207             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
1208
1209#if defined( __parallel )
1210!
1211!--          Vertical nesting: set fine grid eddy viscosity top boundary condition
1212             IF ( vnest_init )  CALL vnest_boundary_conds_khkm
1213#endif
1214
1215          ENDIF
1216
1217       ENDDO   ! Intermediate step loop
1218
1219!
1220!--    Will be used at some point by flow_statistics.
1221       !$ACC UPDATE &
1222       !$ACC HOST(sums_l_l(nzb:nzt+1,0:statistic_regions,0)) &
1223       !$ACC HOST(sums_us2_ws_l(nzb:nzt+1,0)) &
1224       !$ACC HOST(sums_wsus_ws_l(nzb:nzt+1,0)) &
1225       !$ACC HOST(sums_vs2_ws_l(nzb:nzt+1,0)) &
1226       !$ACC HOST(sums_wsvs_ws_l(nzb:nzt+1,0)) &
1227       !$ACC HOST(sums_ws2_ws_l(nzb:nzt+1,0)) &
1228       !$ACC HOST(sums_wspts_ws_l(nzb:nzt+1,0)) &
1229       !$ACC HOST(sums_wssas_ws_l(nzb:nzt+1,0)) &
1230       !$ACC HOST(sums_wsqs_ws_l(nzb:nzt+1,0)) &
1231       !$ACC HOST(sums_wsqcs_ws_l(nzb:nzt+1,0)) &
1232       !$ACC HOST(sums_wsqis_ws_l(nzb:nzt+1,0)) &
1233       !$ACC HOST(sums_wsqrs_ws_l(nzb:nzt+1,0)) &
1234       !$ACC HOST(sums_wsncs_ws_l(nzb:nzt+1,0)) &
1235       !$ACC HOST(sums_wsnis_ws_l(nzb:nzt+1,0)) &
1236       !$ACC HOST(sums_wsnrs_ws_l(nzb:nzt+1,0)) &
1237       !$ACC HOST(sums_wsss_ws_l(nzb:nzt+1,0)) &
1238       !$ACC HOST(sums_salsa_ws_l(nzb:nzt+1,0))
1239
1240!
1241!--    If required, calculate radiative fluxes and heating rates
1242       IF ( radiation  .AND.  time_since_reference_point > skip_time_do_radiation )  THEN
1243
1244          time_radiation = time_radiation + dt_3d
1245
1246          IF ( time_radiation >= dt_radiation  .OR.  force_radiation_call )  THEN
1247
1248             CALL cpu_log( log_point(50), 'radiation', 'start' )
1249
1250             IF ( .NOT. force_radiation_call )  THEN
1251                time_radiation = time_radiation - dt_radiation
1252             ENDIF
1253
1254!
1255!--          Adjust the current time to the time step of the radiation model.
1256!--          Needed since radiation is pre-calculated and stored only on apparent
1257!--          solar positions
1258             time_since_reference_point_save = time_since_reference_point
1259             time_since_reference_point = REAL( FLOOR( time_since_reference_point /             &
1260                                                       dt_radiation ), wp ) * dt_radiation
1261
1262             CALL radiation_control
1263
1264             IF ( ( urban_surface  .OR.  land_surface )  .AND.  radiation_interactions )  THEN
1265                CALL cpu_log( log_point_s(46), 'radiation_interaction', 'start' )
1266                CALL radiation_interaction
1267                CALL cpu_log( log_point_s(46), 'radiation_interaction', 'stop' )
1268             ENDIF
1269
1270!
1271!--          Return the current time to its original value
1272             time_since_reference_point = time_since_reference_point_save
1273
1274             CALL cpu_log( log_point(50), 'radiation', 'stop' )
1275
1276          ENDIF
1277       ENDIF
1278
1279
1280!
1281!-- 20200203 (ECC)
1282!-- allows for emission update mode in legacy mode as well as on-demand mode
1283!-- note that under on-demand mode emission update is no longer restricted to
1284!-- an hourly frequency, but whenever the simulation time corresponds to an
1285!-- inrement in emission timestamp value
1286
1287!
1288!-- If required, consider chemical emissions
1289
1290       IF  ( air_chemistry .AND. emissions_anthropogenic )  THEN
1291
1292          IF  ( emiss_read_legacy_mode )  THEN
1293!
1294!-- get hourly index and updates emission data when the hour is passed
1295
1296             CALL get_date_time( time_since_reference_point, hour=hour )
1297
1298             IF  ( hour_call_emis /= hour )   THEN
1299
1300                CALL chem_emissions_setup( chem_emis_att, chem_emis, n_matched_vars )
1301                hour_call_emis = hour
1302
1303             ENDIF
1304
1305          ELSE
1306
1307             CALL chem_emissions_update_on_demand
1308
1309          ENDIF
1310
1311       ENDIF
1312
1313
1314!
1315!--    If required, consider aerosol emissions for the salsa model
1316       IF ( salsa )  THEN
1317!
1318!--       Call emission routine to update emissions if needed
1319          CALL salsa_emission_update
1320
1321       ENDIF
1322!
1323!--    If required, calculate indoor temperature, waste heat, heat flux
1324!--    through wall, etc.
1325!--    dt_indoor steers the frequency of the indoor model calculations.
1326!--    Note, at first timestep indoor model is called, in order to provide
1327!--    a waste heat flux.
1328       IF ( indoor_model )  THEN
1329
1330          time_indoor = time_indoor + dt_3d
1331
1332          IF ( time_indoor >= dt_indoor  .OR.  current_timestep_number == 0 )  THEN
1333
1334             time_indoor = time_indoor - dt_indoor
1335
1336             CALL cpu_log( log_point(76), 'indoor_model', 'start' )
1337             CALL im_main_heatcool
1338             CALL cpu_log( log_point(76), 'indoor_model', 'stop' )
1339
1340          ENDIF
1341       ENDIF
1342!
1343!--    Increase simulation time and output times
1344       nr_timesteps_this_run      = nr_timesteps_this_run + 1
1345       current_timestep_number    = current_timestep_number + 1
1346       simulated_time             = simulated_time   + dt_3d
1347       time_since_reference_point = simulated_time - coupling_start_time
1348       simulated_time_chr         = time_to_string( time_since_reference_point )
1349
1350
1351       IF ( time_since_reference_point >= skip_time_data_output_av )  THEN
1352          time_do_av         = time_do_av       + dt_3d
1353       ENDIF
1354       IF ( time_since_reference_point >= skip_time_do2d_xy )  THEN
1355          time_do2d_xy       = time_do2d_xy     + dt_3d
1356       ENDIF
1357       IF ( time_since_reference_point >= skip_time_do2d_xz )  THEN
1358          time_do2d_xz       = time_do2d_xz     + dt_3d
1359       ENDIF
1360       IF ( time_since_reference_point >= skip_time_do2d_yz )  THEN
1361          time_do2d_yz       = time_do2d_yz     + dt_3d
1362       ENDIF
1363       IF ( time_since_reference_point >= skip_time_do3d    )  THEN
1364          time_do3d          = time_do3d        + dt_3d
1365       ENDIF
1366       DO  mid = 1, masks
1367          IF ( time_since_reference_point >= skip_time_domask(mid) )  THEN
1368             time_domask(mid)= time_domask(mid) + dt_3d
1369          ENDIF
1370       ENDDO
1371       IF ( time_since_reference_point >= skip_time_dosp )  THEN
1372          time_dosp       = time_dosp        + dt_3d
1373       ENDIF
1374       time_dots          = time_dots        + dt_3d
1375       IF ( .NOT. first_call_lpm )  THEN
1376          time_dopts      = time_dopts       + dt_3d
1377       ENDIF
1378       IF ( time_since_reference_point >= skip_time_dopr )  THEN
1379          time_dopr       = time_dopr        + dt_3d
1380       ENDIF
1381       time_dopr_listing  = time_dopr_listing + dt_3d
1382       time_run_control   = time_run_control + dt_3d
1383!
1384!--    Increment time-counter for surface output
1385       IF ( surface_output )  THEN
1386          IF ( time_since_reference_point >= skip_time_dosurf )  THEN
1387             time_dosurf    = time_dosurf + dt_3d
1388          ENDIF
1389          IF ( time_since_reference_point >= skip_time_dosurf_av )  THEN
1390             time_dosurf_av = time_dosurf_av + dt_3d
1391          ENDIF
1392       ENDIF
1393!
1394!--    Increment time-counter for virtual measurements
1395       IF ( virtual_measurement  .AND.  vm_time_start <= time_since_reference_point )  THEN
1396          time_virtual_measurement = time_virtual_measurement + dt_3d
1397       ENDIF
1398
1399!
1400!--    Increment time-counter for wind turbine data output
1401       IF ( wind_turbine )  THEN
1402          time_wtm = time_wtm + dt_3d
1403       ENDIF
1404
1405!
1406!--    In case of synthetic turbulence generation and parametrized turbulence
1407!--    information, update the time counter and if required, adjust the
1408!--    STG to new atmospheric conditions.
1409       IF ( use_syn_turb_gen  )  THEN
1410          IF ( parametrize_inflow_turbulence )  THEN
1411             time_stg_adjust = time_stg_adjust + dt_3d
1412             IF ( time_stg_adjust >= dt_stg_adjust )  THEN
1413                CALL cpu_log( log_point(57), 'synthetic_turbulence_gen', 'start' )
1414                CALL stg_adjust
1415                CALL cpu_log( log_point(57), 'synthetic_turbulence_gen', 'stop' )
1416             ENDIF
1417          ENDIF
1418          time_stg_call = time_stg_call + dt_3d
1419       ENDIF
1420
1421!
1422!--    Data exchange between coupled models
1423       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled  .AND.  .NOT. vnested )  THEN
1424          time_coupling = time_coupling + dt_3d
1425
1426!
1427!--       In case of model termination initiated by the local model
1428!--       (terminate_coupled > 0), the coupler must be skipped because it would
1429!--       cause an MPI intercomminucation hang.
1430!--       If necessary, the coupler will be called at the beginning of the
1431!--       next restart run.
1432          DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
1433             CALL surface_coupler
1434             time_coupling = time_coupling - dt_coupling
1435          ENDDO
1436       ENDIF
1437
1438!
1439!--    Biometeorology calculation of stationary thermal indices
1440!--    Todo (kanani): biometeorology needs own time_... treatment.
1441!--                   It might be that time_do2d_xy differs from time_do3d,
1442!--                   and then we might get trouble with the biomet output,
1443!--                   because we can have 2d and/or 3d biomet output!!
1444       IF ( biometeorology                                                                         &
1445            .AND. ( ( time_do3d >= dt_do3d  .AND.  time_since_reference_point >= skip_time_do3d )  &
1446                  .OR.                                                                             &
1447            ( time_do2d_xy >= dt_do2d_xy  .AND.  time_since_reference_point >= skip_time_do2d_xy ) &
1448                    ) )  THEN
1449!
1450!--       If required, do thermal comfort calculations
1451          IF ( thermal_comfort )  THEN
1452             CALL bio_calculate_thermal_index_maps ( .FALSE. )
1453          ENDIF
1454!
1455!--       If required, do UV exposure calculations
1456          IF ( uv_exposure )  THEN
1457             CALL bio_calculate_uv_exposure
1458          ENDIF
1459       ENDIF
1460
1461!
1462!--    Execute alle other module actions routunes
1463       CALL module_interface_actions( 'after_integration' )
1464
1465!
1466!--    If Galilei transformation is used, determine the distance that the
1467!--    model has moved so far
1468       IF ( galilei_transformation )  THEN
1469          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
1470          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
1471       ENDIF
1472
1473!
1474!--    Check, if restart is necessary (because cpu-time is expiring or
1475!--    because it is forced by user) and set stop flag
1476!--    This call is skipped if the remote model has already initiated a restart.
1477       IF ( .NOT. terminate_run )  CALL check_for_restart
1478
1479!
1480!--    Carry out statistical analysis and output at the requested output times.
1481!--    The MOD function is used for calculating the output time counters (like
1482!--    time_dopr) in order to regard a possible decrease of the output time
1483!--    interval in case of restart runs
1484
1485!
1486!--    Set a flag indicating that so far no statistics have been created
1487!--    for this time step
1488       flow_statistics_called = .FALSE.
1489
1490!
1491!--    If required, call flow_statistics for averaging in time
1492       IF ( averaging_interval_pr /= 0.0_wp  .AND.                                                 &
1493            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.                                &
1494            time_since_reference_point >= skip_time_dopr )  THEN
1495          time_dopr_av = time_dopr_av + dt_3d
1496          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
1497             do_sum = .TRUE.
1498             time_dopr_av = MOD( time_dopr_av, MAX( dt_averaging_input_pr, dt_3d ) )
1499          ENDIF
1500       ENDIF
1501       IF ( do_sum )  CALL flow_statistics
1502
1503!
1504!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
1505       IF ( averaging_interval /= 0.0_wp  .AND.                                                    &
1506            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND.                        &
1507            time_since_reference_point >= skip_time_data_output_av )                               &
1508       THEN
1509          time_do_sla = time_do_sla + dt_3d
1510          IF ( time_do_sla >= dt_averaging_input )  THEN
1511             IF ( current_timestep_number > timestep_number_at_prev_calc )                         &
1512                CALL doq_calculate
1513
1514             CALL sum_up_3d_data
1515             average_count_3d = average_count_3d + 1
1516             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
1517          ENDIF
1518       ENDIF
1519!
1520!--    Average surface data
1521       IF ( surface_output )  THEN
1522          IF ( averaging_interval_surf /= 0.0_wp                                                   &
1523                .AND.  ( dt_dosurf_av - time_dosurf_av ) <= averaging_interval_surf                &
1524                .AND.  time_since_reference_point >= skip_time_dosurf_av )  THEN
1525             IF ( time_dosurf_av >= dt_averaging_input )  THEN
1526                CALL surface_data_output_averaging
1527                average_count_surf = average_count_surf + 1
1528             ENDIF
1529          ENDIF
1530       ENDIF
1531
1532!
1533!--    Calculate spectra for time averaging
1534       IF ( averaging_interval_sp /= 0.0_wp  .AND. ( dt_dosp - time_dosp ) <= averaging_interval_sp&
1535            .AND.  time_since_reference_point >= skip_time_dosp )  THEN
1536          time_dosp_av = time_dosp_av + dt_3d
1537          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
1538             CALL calc_spectra
1539             time_dosp_av = MOD( time_dosp_av, MAX( dt_averaging_input_pr, dt_3d ) )
1540          ENDIF
1541       ENDIF
1542
1543!
1544!--    Call flight module and output data
1545       IF ( virtual_flight )  THEN
1546          CALL flight_measurement
1547          CALL data_output_flight
1548       ENDIF
1549!
1550!--    Take virtual measurements
1551       IF ( virtual_measurement  .AND.  time_virtual_measurement >= dt_virtual_measurement         &
1552                                 .AND.  vm_time_start <= time_since_reference_point )  THEN
1553          CALL vm_sampling
1554          CALL vm_data_output
1555          time_virtual_measurement = MOD(      time_virtual_measurement,                           &
1556                                          MAX( dt_virtual_measurement, dt_3d ) )
1557       ENDIF
1558
1559!
1560!--    Output wind turbine data
1561       IF ( wind_turbine  .AND.  time_wtm >= dt_data_output_wtm )  THEN
1562          CALL wtm_data_output
1563          time_wtm = MOD( time_wtm, MAX( dt_data_output_wtm, dt_3d ) )
1564       ENDIF
1565
1566!
1567!--    Profile output (ASCII) on file
1568       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
1569          CALL print_1d
1570          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, dt_3d ) )
1571       ENDIF
1572
1573!
1574!--    Graphic output for PROFIL
1575       IF ( time_dopr >= dt_dopr  .AND.  time_since_reference_point >= skip_time_dopr )  THEN
1576          IF ( dopr_n /= 0 )  CALL data_output_profiles
1577          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
1578          time_dopr_av = 0.0_wp    ! due to averaging (see above)
1579       ENDIF
1580
1581!
1582!--    Graphic output for time series
1583       IF ( time_dots >= dt_dots )  THEN
1584          CALL data_output_tseries
1585          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
1586       ENDIF
1587
1588!
1589!--    Output of spectra (formatted for use with PROFIL), in case of no
1590!--    time averaging, spectra has to be calculated before
1591       IF ( time_dosp >= dt_dosp  .AND.  time_since_reference_point >= skip_time_dosp )  THEN
1592          IF ( average_count_sp == 0 )  CALL calc_spectra
1593          CALL data_output_spectra
1594          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
1595       ENDIF
1596
1597!
1598!--    2d-data output (cross-sections)
1599       IF ( time_do2d_xy >= dt_do2d_xy  .AND.  time_since_reference_point >= skip_time_do2d_xy )  THEN
1600          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
1601             CALL doq_calculate
1602
1603          CALL data_output_2d( 'xy', 0 )
1604          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
1605       ENDIF
1606       IF ( time_do2d_xz >= dt_do2d_xz  .AND.  time_since_reference_point >= skip_time_do2d_xz )  THEN
1607          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
1608
1609             CALL doq_calculate
1610          CALL data_output_2d( 'xz', 0 )
1611          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
1612       ENDIF
1613       IF ( time_do2d_yz >= dt_do2d_yz  .AND.  time_since_reference_point >= skip_time_do2d_yz )  THEN
1614          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
1615             CALL doq_calculate
1616
1617          CALL data_output_2d( 'yz', 0 )
1618          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
1619       ENDIF
1620
1621!
1622!--    3d-data output (volume data)
1623       IF ( time_do3d >= dt_do3d  .AND.  time_since_reference_point >= skip_time_do3d )  THEN
1624          IF ( current_timestep_number > timestep_number_at_prev_calc )                            &
1625             CALL doq_calculate
1626
1627          CALL data_output_3d( 0 )
1628          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
1629       ENDIF
1630
1631!
1632!--    Masked data output
1633       DO  mid = 1, masks
1634          IF ( time_domask(mid) >= dt_domask(mid)                                                  &
1635               .AND.  time_since_reference_point >= skip_time_domask(mid) )  THEN
1636             IF ( current_timestep_number > timestep_number_at_prev_calc )                         &
1637                CALL doq_calculate
1638
1639             CALL data_output_mask( 0, mid )
1640             time_domask(mid) = MOD( time_domask(mid), MAX( dt_domask(mid), dt_3d ) )
1641          ENDIF
1642       ENDDO
1643
1644!
1645!--    Output of time-averaged 2d/3d/masked data
1646       IF ( time_do_av >= dt_data_output_av                                                        &
1647            .AND.  time_since_reference_point >= skip_time_data_output_av )  THEN
1648          CALL average_3d_data
1649!
1650!--       Udate thermal comfort indices based on updated averaged input
1651          IF ( biometeorology  .AND.  thermal_comfort )  THEN
1652             CALL bio_calculate_thermal_index_maps ( .TRUE. )
1653          ENDIF
1654          CALL data_output_2d( 'xy', 1 )
1655          CALL data_output_2d( 'xz', 1 )
1656          CALL data_output_2d( 'yz', 1 )
1657          CALL data_output_3d( 1 )
1658          DO  mid = 1, masks
1659             CALL data_output_mask( 1, mid )
1660          ENDDO
1661          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
1662       ENDIF
1663!
1664!--    Output of surface data, instantaneous and averaged data
1665       IF ( surface_output )  THEN
1666          IF ( time_dosurf >= dt_dosurf  .AND.  time_since_reference_point >= skip_time_dosurf )  THEN
1667             CALL surface_data_output( 0 )
1668             time_dosurf = MOD( time_dosurf, MAX( dt_dosurf, dt_3d ) )
1669          ENDIF
1670          IF ( time_dosurf_av >= dt_dosurf_av  .AND.  time_since_reference_point >= skip_time_dosurf_av )  THEN
1671             CALL surface_data_output( 1 )
1672             time_dosurf_av = MOD( time_dosurf_av, MAX( dt_dosurf_av, dt_3d ) )
1673          ENDIF
1674       ENDIF
1675
1676!
1677!--    Output of particle time series
1678       IF ( particle_advection )  THEN
1679          IF ( time_dopts >= dt_dopts  .OR.                                                        &
1680               ( time_since_reference_point >= particle_advection_start  .AND.                     &
1681                 first_call_lpm ) )  THEN
1682             CALL lpm_data_output_ptseries
1683             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
1684          ENDIF
1685       ENDIF
1686
1687!
1688!--    If required, set the heat flux for the next time step to a random value
1689       IF ( constant_heatflux  .AND.  random_heatflux )  THEN
1690          IF ( surf_def_h(0)%ns >= 1 )  THEN
1691             CALL cpu_log( log_point(23), 'disturb_heatflux', 'start' )
1692             CALL disturb_heatflux( surf_def_h(0) )
1693             CALL cpu_log( log_point(23), 'disturb_heatflux', 'stop' )
1694          ENDIF
1695          IF ( surf_lsm_h%ns    >= 1 )  THEN
1696             CALL cpu_log( log_point(23), 'disturb_heatflux', 'start' )
1697             CALL disturb_heatflux( surf_lsm_h    )
1698             CALL cpu_log( log_point(23), 'disturb_heatflux', 'stop' )
1699          ENDIF
1700          IF ( surf_usm_h%ns    >= 1 )  THEN
1701             CALL cpu_log( log_point(23), 'disturb_heatflux', 'start' )
1702             CALL disturb_heatflux( surf_usm_h    )
1703             CALL cpu_log( log_point(23), 'disturb_heatflux', 'stop' )
1704          ENDIF
1705       ENDIF
1706
1707!
1708!--    Execute alle other module actions routunes
1709       CALL module_interface_actions( 'after_timestep' )
1710
1711!
1712!--    Determine size of next time step. Save timestep dt_3d because it is
1713!--    newly calculated in routine timestep, but required further below for
1714!--    steering the run control output interval
1715       dt_3d_old = dt_3d
1716       CALL timestep
1717
1718#if defined( __parallel )
1719!
1720!--    Synchronize the timestep in case of nested run.
1721       IF ( nested_run )  THEN
1722!
1723!--       Synchronize by unifying the time step.
1724!--       Global minimum of all time-steps is used for all.
1725          CALL pmci_synchronize
1726       ENDIF
1727#endif
1728
1729!
1730!--    Computation and output of run control parameters.
1731!--    This is also done whenever perturbations have been imposed
1732       IF ( time_run_control >= dt_run_control  .OR.                                               &
1733            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created )                           &
1734       THEN
1735          CALL run_control
1736          IF ( time_run_control >= dt_run_control )  THEN
1737             time_run_control = MOD( time_run_control, MAX( dt_run_control, dt_3d_old ) )
1738          ENDIF
1739       ENDIF
1740
1741!
1742!--    Output elapsed simulated time in form of a progress bar on stdout
1743       IF ( myid == 0 )  CALL output_progress_bar
1744
1745       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
1746
1747
1748    ENDDO   ! time loop
1749
1750#if defined( _OPENACC )
1751    CALL exit_surface_arrays
1752#endif
1753!$ACC END DATA
1754!$ACC END DATA
1755!$ACC END DATA
1756!$ACC END DATA
1757!$ACC END DATA
1758!$ACC END DATA
1759!$ACC END DATA
1760!$ACC END DATA
1761
1762#if defined( __parallel )
1763!
1764!-- Vertical nesting: Deallocate variables initialized for vertical nesting
1765    IF ( vnest_init )  CALL vnest_deallocate
1766#endif
1767
1768    IF ( myid == 0 )  CALL finish_progress_bar
1769
1770    CALL location_message( 'atmosphere (and/or ocean) time-stepping', 'finished' )
1771
1772 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.