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

Last change on this file since 4668 was 4668, checked in by pavelkrc, 4 years ago

Document changes (forgotten)

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