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

Last change on this file since 4802 was 4802, checked in by suehring, 3 years ago

Bugfix in time-control of indoor model in case of restarts and at the very first time step

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