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

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

salsa decycling replaced by explicit setting of lateral boundary conditions

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