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

Last change on this file since 3413 was 3378, checked in by kanani, 6 years ago

merge fixes of radiation branch (r3362) to trunk

  • Property svn:keywords set to Id
File size: 57.6 KB
Line 
1!> @file time_integration.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: time_integration.f90 3378 2018-10-19 12:34:59Z suehring $
27! merge from radiation branch (r3362) into trunk
28! (moh.hefny):
29! Bugfix in the if statement to call radiation_interaction
30!
31! 3347 2018-10-15 14:21:08Z suehring
32! - offline nesting separated from large-scale forcing module
33! - changes for synthetic turbulence generator
34!
35! 3343 2018-10-15 10:38:52Z suehring
36! - Formatting, clean-up, comments (kanani)
37! - Added CALL to chem_emissions_setup (Russo)
38! - Code added for decycling chemistry (basit)
39!
40! 3294 2018-10-01 02:37:10Z raasch
41! changes concerning modularization of ocean option
42!
43! 3274 2018-09-24 15:42:55Z knoop
44! Modularization of all bulk cloud physics code components
45!
46! 3241 2018-09-12 15:02:00Z raasch
47! unused variables removed
48!
49! 3198 2018-08-15 09:23:10Z sward
50! Added multi_agent_system_end; defined start time for MAS relative to
51! time_since_reference_point
52!
53! 3183 2018-07-27 14:25:55Z suehring
54! Replace simulated_time by time_since_reference_point in COSMO nesting mode.
55! Rename subroutines and variables in COSMO nesting mode
56!
57! 3182 2018-07-27 13:36:03Z suehring
58! Added multi agent system
59!
60! 3042 2018-05-25 10:44:37Z schwenkel
61! Changed the name specific humidity to mixing ratio
62!
63! 3040 2018-05-25 10:22:08Z schwenkel
64! Fixed bug in IF statement
65! Ensure that the time when calling the radiation to be the time step of the
66! pre-calculated time when first calculate the positions of the sun
67!
68! 3004 2018-04-27 12:33:25Z Giersch
69! First call of flow_statistics has been removed. It is already called in
70! run_control itself
71!
72! 2984 2018-04-18 11:51:30Z hellstea
73! CALL pmci_ensure_nest_mass_conservation is removed (so far only commented out)
74! as seemingly unnecessary.
75!
76! 2941 2018-04-03 11:54:58Z kanani
77! Deduct spinup_time from RUN_CONTROL output of main 3d run
78! (use time_since_reference_point instead of simulated_time)
79!
80! 2938 2018-03-27 15:52:42Z suehring
81! Nesting of dissipation rate in case of RANS mode and TKE-e closure is applied
82!
83! 2936 2018-03-27 14:49:27Z suehring
84! Little formatting adjustment.
85!
86! 2817 2018-02-19 16:32:21Z knoop
87! Preliminary gust module interface implemented
88!
89! 2801 2018-02-14 16:01:55Z thiele
90! Changed lpm from subroutine to module.
91! Introduce particle transfer in nested models.
92!
93! 2776 2018-01-31 10:44:42Z Giersch
94! Variable use_synthetic_turbulence_generator has been abbreviated
95!
96! 2773 2018-01-30 14:12:54Z suehring
97! - Nesting for chemical species
98!
99! 2766 2018-01-22 17:17:47Z kanani
100! Removed preprocessor directive __chem
101!
102! 2718 2018-01-02 08:49:38Z maronga
103! Corrected "Former revisions" section
104!
105! 2696 2017-12-14 17:12:51Z kanani
106! - Change in file header (GPL part)
107! - Implementation of uv exposure model (FK)
108! - Moved vnest_boundary_conds_khkm from tcm_diffusivities to here (TG)
109! - renamed diffusivities to tcm_diffusivities (TG)
110! - implement prognostic equation for diss (TG)
111! - Moved/commented CALL to chem_emissions (FK)
112! - Added CALL to chem_emissions (FK)
113! - Implementation of chemistry module (FK)
114! - Calls for setting boundary conditions in USM and LSM (MS)
115! - Large-scale forcing with larger-scale models implemented (MS)
116! - Rename usm_radiation into radiation_interactions; merge with branch
117!   radiation (MS)
118! - added call for usm_green_heat_model for green building surfaces (RvT)
119! - added call for usm_temperature_near_surface for use in indoor model (RvT)
120!
121! 2617 2017-11-16 12:47:24Z suehring
122! Bugfix, assure that the reference state does not become zero.
123!
124! 2563 2017-10-19 15:36:10Z Giersch
125! Variable wind_turbine moved to module control_parameters
126!
127! 2365 2017-08-21 14:59:59Z kanani
128! Vertical grid nesting implemented (SadiqHuq)
129!
130! 2320 2017-07-21 12:47:43Z suehring
131! Set bottom boundary conditions after nesting interpolation and anterpolation
132!
133! 2299 2017-06-29 10:14:38Z maronga
134! Call of soil model adjusted
135!
136! 2292 2017-06-20 09:51:42Z schwenkel
137! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
138! includes two more prognostic equations for cloud drop concentration (nc) 
139! and cloud water content (qc).
140!
141! 2271 2017-06-09 12:34:55Z sward
142! Start timestep message changed
143!
144! 2259 2017-06-08 09:09:11Z gronemeier
145! Implemented synthetic turbulence generator
146!
147! 2233 2017-05-30 18:08:54Z suehring
148!
149! 2232 2017-05-30 17:47:52Z suehring
150! Adjustments to new topography and surface concept
151! Modify passed parameters for disturb_field
152!
153! 2178 2017-03-17 11:07:39Z hellstea
154! Setting perturbations at all times near inflow boundary is removed
155! in case of nested boundaries
156!
157! 2174 2017-03-13 08:18:57Z maronga
158! Added support for nesting with cloud microphysics
159!
160! 2118 2017-01-17 16:38:49Z raasch
161! OpenACC directives and related code removed
162!
163! 2050 2016-11-08 15:00:55Z gronemeier
164! Implement turbulent outflow condition
165!
166! 2031 2016-10-21 15:11:58Z knoop
167! renamed variable rho to rho_ocean
168!
169! 2011 2016-09-19 17:29:57Z kanani
170! Flag urban_surface is now defined in module control_parameters,
171! removed commented CALLs of global_min_max.
172!
173! 2007 2016-08-24 15:47:17Z kanani
174! Added CALLs for new urban surface model
175!
176! 2000 2016-08-20 18:09:15Z knoop
177! Forced header and separation lines into 80 columns
178!
179! 1976 2016-07-27 13:28:04Z maronga
180! Simplified calls to radiation model
181!
182! 1960 2016-07-12 16:34:24Z suehring
183! Separate humidity and passive scalar
184!
185! 1957 2016-07-07 10:43:48Z suehring
186! flight module added
187!
188! 1919 2016-05-27 14:51:23Z raasch
189! Initial version of purely vertical nesting introduced.
190!
191! 1918 2016-05-27 14:35:57Z raasch
192! determination of time step moved to the end of the time step loop,
193! the first time step is now always calculated before the time step loop (i.e.
194! also in case of restart runs)
195!
196! 1914 2016-05-26 14:44:07Z witha
197! Added call for wind turbine model
198!
199! 1878 2016-04-19 12:30:36Z hellstea
200! Synchronization for nested runs rewritten
201!
202! 1853 2016-04-11 09:00:35Z maronga
203! Adjusted for use with radiation_scheme = constant
204!
205! 1849 2016-04-08 11:33:18Z hoffmann
206! Adapted for modularization of microphysics
207!
208! 1833 2016-04-07 14:23:03Z raasch
209! spectrum renamed spectra_mod, spectra related variables moved to spectra_mod
210!
211! 1831 2016-04-07 13:15:51Z hoffmann
212! turbulence renamed collision_turbulence
213!
214! 1822 2016-04-07 07:49:42Z hoffmann
215! icloud_scheme replaced by microphysics_*
216!
217! 1808 2016-04-05 19:44:00Z raasch
218! output message in case unscheduled radiation calls removed
219!
220! 1797 2016-03-21 16:50:28Z raasch
221! introduction of different datatransfer modes
222!
223! 1791 2016-03-11 10:41:25Z raasch
224! call of pmci_update_new removed
225!
226! 1786 2016-03-08 05:49:27Z raasch
227! +module spectrum
228!
229! 1783 2016-03-06 18:36:17Z raasch
230! switch back of netcdf data format for mask output moved to the mask output
231! routine
232!
233! 1781 2016-03-03 15:12:23Z raasch
234! some pmc calls removed at the beginning (before timeloop),
235! pmc initialization moved to the main program
236!
237! 1764 2016-02-28 12:45:19Z raasch
238! PMC_ACTIVE flags removed,
239! bugfix: nest synchronization after first call of timestep
240!
241! 1762 2016-02-25 12:31:13Z hellstea
242! Introduction of nested domain feature
243!
244! 1736 2015-12-04 08:56:33Z raasch
245! no perturbations added to total domain if energy limit has been set zero
246!
247! 1691 2015-10-26 16:17:44Z maronga
248! Added option for spin-ups without land surface and radiation models. Moved calls
249! for radiation and lan surface schemes.
250!
251! 1682 2015-10-07 23:56:08Z knoop
252! Code annotations made doxygen readable
253!
254! 1671 2015-09-25 03:29:37Z raasch
255! bugfix: ghostpoint exchange for array diss in case that sgs velocities are used
256! for particles
257!
258! 1585 2015-04-30 07:05:52Z maronga
259! Moved call of radiation scheme. Added support for RRTM
260!
261! 1551 2015-03-03 14:18:16Z maronga
262! Added interface for different radiation schemes.
263!
264! 1496 2014-12-02 17:25:50Z maronga
265! Added calls for the land surface model and radiation scheme
266!
267! 1402 2014-05-09 14:25:13Z raasch
268! location messages modified
269!
270! 1384 2014-05-02 14:31:06Z raasch
271! location messages added
272!
273! 1380 2014-04-28 12:40:45Z heinze
274! CALL of nudge_ref added
275! bc_pt_t_val and bc_q_t_val are updated in case nudging is used
276!
277! 1365 2014-04-22 15:03:56Z boeske
278! Reset sums_ls_l to zero at each timestep
279! +sums_ls_l
280! Calculation of reference state (previously in subroutine calc_mean_profile)
281
282! 1342 2014-03-26 17:04:47Z kanani
283! REAL constants defined as wp-kind
284!
285! 1320 2014-03-20 08:40:49Z raasch
286! ONLY-attribute added to USE-statements,
287! kind-parameters added to all INTEGER and REAL declaration statements,
288! kinds are defined in new module kinds,
289! old module precision_kind is removed,
290! revision history before 2012 removed,
291! comment fields (!:) to be used for variable explanations added to
292! all variable declaration statements
293! 1318 2014-03-17 13:35:16Z raasch
294! module interfaces removed
295!
296! 1308 2014-03-13 14:58:42Z fricke
297! +netcdf_data_format_save
298! For masked data, parallel netcdf output is not tested so far, hence
299! netcdf_data_format is switched back to non-paralell output.
300!
301! 1276 2014-01-15 13:40:41Z heinze
302! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
303!
304! 1257 2013-11-08 15:18:40Z raasch
305! acc-update-host directive for timestep removed
306!
307! 1241 2013-10-30 11:36:58Z heinze
308! Generalize calc_mean_profile for wider use
309! Determine shf and qsws in dependence on data from LSF_DATA
310! Determine ug and vg in dependence on data from LSF_DATA
311! 1221 2013-09-10 08:59:13Z raasch
312! host update of arrays before timestep is called
313!
314! 1179 2013-06-14 05:57:58Z raasch
315! mean profiles for reference state are only calculated if required,
316! small bugfix for background communication
317!
318! 1171 2013-05-30 11:27:45Z raasch
319! split of prognostic_equations deactivated (comment lines), for the time being
320!
321! 1128 2013-04-12 06:19:32Z raasch
322! asynchronous transfer of ghost point data realized for acc-optimized version:
323! prognostic_equations are first called two times for those points required for
324! the left-right and north-south exchange, respectively, and then for the
325! remaining points,
326! those parts requiring global communication moved from prognostic_equations to
327! here
328!
329! 1115 2013-03-26 18:16:16Z hoffmann
330! calculation of qr and nr is restricted to precipitation
331!
332! 1113 2013-03-10 02:48:14Z raasch
333! GPU-porting of boundary conditions,
334! openACC directives updated
335! formal parameter removed from routine boundary_conds
336!
337! 1111 2013-03-08 23:54:10Z raasch
338! +internal timestep counter for cpu statistics added,
339! openACC directives updated
340!
341! 1092 2013-02-02 11:24:22Z raasch
342! unused variables removed
343!
344! 1065 2012-11-22 17:42:36Z hoffmann
345! exchange of diss (dissipation rate) in case of turbulence = .TRUE. added
346!
347! 1053 2012-11-13 17:11:03Z hoffmann
348! exchange of ghost points for nr, qr added
349!
350! 1036 2012-10-22 13:43:42Z raasch
351! code put under GPL (PALM 3.9)
352!
353! 1019 2012-09-28 06:46:45Z raasch
354! non-optimized version of prognostic_equations removed
355!
356! 1015 2012-09-27 09:23:24Z raasch
357! +call of prognostic_equations_acc
358!
359! 1001 2012-09-13 14:08:46Z raasch
360! all actions concerning leapfrog- and upstream-spline-scheme removed
361!
362! 849 2012-03-15 10:35:09Z raasch
363! advec_particles renamed lpm, first_call_advec_particles renamed first_call_lpm
364!
365! 825 2012-02-19 03:03:44Z raasch
366! wang_collision_kernel renamed wang_kernel
367!
368! Revision 1.1  1997/08/11 06:19:04  raasch
369! Initial revision
370!
371!
372! Description:
373! ------------
374!> Integration in time of the model equations, statistical analysis and graphic
375!> output
376!------------------------------------------------------------------------------!
377 SUBROUTINE time_integration
378 
379
380    USE advec_ws,                                                              &
381        ONLY:  ws_statistics
382
383    USE arrays_3d,                                                             &
384        ONLY:  diss, diss_p, dzu, e, e_p, nc, nc_p, nr, nr_p, prho, pt, pt_p, pt_init, &
385               q_init, q, qc, qc_p, ql, ql_c, ql_v, ql_vp, qr, qr_p, q_p,      &
386               ref_state, rho_ocean, s, s_p, sa_p, tend, u, u_p, v, vpt,       &
387               v_p, w, w_p
388
389    USE bulk_cloud_model_mod,                                                  &
390        ONLY: bulk_cloud_model, calc_liquid_water_content,                     &
391              collision_turbulence, microphysics_morrison, microphysics_seifert
392
393    USE calc_mean_profile_mod,                                                 &
394        ONLY:  calc_mean_profile
395
396    USE chem_emissions_mod,                                                    &
397        ONLY:  chem_emissions_setup
398
399    USE chem_modules,                                                          &
400        ONLY:  bc_cs_t_val, call_chem_at_all_substeps, cs_name,                &
401               constant_csflux, do_emis, nspec, nspec_out
402
403    USE chemistry_model_mod,                                                   &
404        ONLY:  chem_boundary_conds, chem_species
405
406    USE control_parameters,                                                    &
407        ONLY:  advected_distance_x, advected_distance_y, air_chemistry,        &
408               average_count_3d, averaging_interval, averaging_interval_pr,    &
409               bc_lr_cyc, bc_ns_cyc, bc_pt_t_val, bc_q_t_val,                  &
410               call_psolver_at_all_substeps,  child_domain, cloud_droplets,    &
411               constant_flux_layer, constant_heatflux,                         &
412               create_disturbances, dopr_n, constant_diffusion, coupling_mode, &
413               coupling_start_time, current_timestep_number,                   &
414               disturbance_created, disturbance_energy_limit, dist_range,      &
415               do_sum, dt_3d, dt_averaging_input, dt_averaging_input_pr,       &
416               dt_coupling, dt_data_output_av, dt_disturb, dt_do2d_xy,         &
417               dt_do2d_xz, dt_do2d_yz, dt_do3d, dt_domask,dt_dopts, dt_dopr,   &
418               dt_dopr_listing, dt_dots, dt_dvrp, dt_run_control, end_time,    &
419               first_call_lpm, first_call_mas, galilei_transformation,         &
420               humidity, intermediate_timestep_count,                          &
421               intermediate_timestep_count_max,                                &
422               land_surface, large_scale_forcing,                              &
423               loop_optimization, lsf_surf, lsf_vert, masks, mid,              &
424               multi_agent_system_end, multi_agent_system_start,               &
425               nesting_offline, neutral, nr_timesteps_this_run, nudging,       &
426               ocean_mode, passive_scalar, pt_reference,                       &
427               pt_slope_offset, random_heatflux, rans_mode,                    &
428               rans_tke_e, run_coupled, simulated_time, simulated_time_chr,    &
429               skip_time_do2d_xy, skip_time_do2d_xz, skip_time_do2d_yz,        &
430               skip_time_do3d, skip_time_domask, skip_time_dopr,               &
431               skip_time_data_output_av, sloping_surface,                      &
432               stop_dt, terminate_coupled, terminate_run, timestep_scheme,     &
433               time_coupling, time_do2d_xy, time_do2d_xz, time_do2d_yz,        &
434               time_do3d, time_domask, time_dopr, time_dopr_av,                &
435               time_dopr_listing, time_dopts, time_dosp, time_dosp_av,         &
436               time_dots, time_do_av, time_do_sla, time_disturb, time_dvrp,    &
437               time_run_control, time_since_reference_point,                   &
438               turbulent_inflow, turbulent_outflow, urban_surface,             &
439               use_initial_profile_as_reference,                               &
440               use_single_reference_value, uv_exposure, u_gtrans, v_gtrans,    &
441               virtual_flight, wind_turbine, ws_scheme_mom, ws_scheme_sca
442
443    USE cpulog,                                                                &
444        ONLY:  cpu_log, log_point, log_point_s
445
446    USE date_and_time_mod,                                                     &
447        ONLY:  calc_date_and_time, hour_call_emis, hour_of_year
448
449    USE flight_mod,                                                            &
450        ONLY:  flight_measurement
451
452    USE gust_mod,                                                              &
453        ONLY:  gust_actions, gust_module_enabled
454
455    USE indices,                                                               &
456        ONLY:  nbgp, nx, nxl, nxlg, nxr, nxrg, nzb, nzt
457
458    USE interaction_droplets_ptq_mod,                                          &
459        ONLY:  interaction_droplets_ptq
460
461    USE interfaces
462
463    USE kinds
464
465    USE land_surface_model_mod,                                                &
466        ONLY:  lsm_boundary_condition, lsm_energy_balance, lsm_soil_model,     &
467               skip_time_do_lsm
468
469    USE lsf_nudging_mod,                                                       &
470        ONLY:  calc_tnudge, ls_forcing_surf, ls_forcing_vert, nudge_ref
471
472    USE multi_agent_system_mod,                                                &
473        ONLY:  agents_active, multi_agent_system
474       
475    USE nesting_offl_mod,                                                      &
476        ONLY:  nesting_offl_bc, nesting_offl_mass_conservation
477       
478    USE netcdf_data_input_mod,                                                 &
479        ONLY:  chem_emis, chem_emis_att, nest_offl,                            &
480               netcdf_data_input_offline_nesting
481
482    USE ocean_mod,                                                             &
483        ONLY:  prho_reference
484
485    USE particle_attributes,                                                   &
486        ONLY:  particle_advection, particle_advection_start,                   &
487               use_sgs_for_particles, wang_kernel
488
489    USE pegrid
490
491    USE pmc_interface,                                                         &
492        ONLY:  nested_run, nesting_mode, pmci_boundary_conds, pmci_datatrans,  &
493               pmci_ensure_nest_mass_conservation, pmci_synchronize
494
495    USE progress_bar,                                                          &
496        ONLY:  finish_progress_bar, output_progress_bar
497
498    USE prognostic_equations_mod,                                              &
499        ONLY:  prognostic_equations_cache, prognostic_equations_vector
500
501    USE radiation_model_mod,                                                   &
502        ONLY: dt_radiation, force_radiation_call, radiation, radiation_control,&
503              radiation_interaction, radiation_interactions,                   &
504              skip_time_do_radiation, time_radiation
505
506    USE spectra_mod,                                                           &
507        ONLY: average_count_sp, averaging_interval_sp, calc_spectra, dt_dosp,  &
508              skip_time_dosp
509
510    USE statistics,                                                            &
511        ONLY:  flow_statistics_called, hom, pr_palm, sums_ls_l
512
513    USE surface_layer_fluxes_mod,                                              &
514        ONLY:  surface_layer_fluxes
515
516    USE surface_mod,                                                           &
517        ONLY:  surf_def_h, surf_lsm_h, surf_usm_h
518
519    USE turbulence_closure_mod,                                                &
520        ONLY:  tcm_diffusivities, production_e_init
521
522    USE urban_surface_mod,                                                     &
523        ONLY:  usm_boundary_condition, usm_material_heat_model,                &
524               usm_material_model,                                             &
525               usm_surface_energy_balance, usm_green_heat_model,               &
526               usm_temperature_near_surface
527
528    USE synthetic_turbulence_generator_mod,                                    &
529        ONLY:  dt_stg_call, dt_stg_adjust, parametrize_inflow_turbulence,      &
530               stg_adjust, stg_main, time_stg_adjust, time_stg_call,           &
531               use_syn_turb_gen
532
533    USE user_actions_mod,                                                      &
534        ONLY:  user_actions
535
536    USE uv_exposure_model_mod,                                                 &
537        ONLY:  uvem_calc_exposure
538
539    USE wind_turbine_model_mod,                                                &
540        ONLY:  wtm_forces
541
542    USE lpm_mod,                                                               &
543        ONLY:  lpm
544
545    USE vertical_nesting_mod,                                                  &
546        ONLY:  vnested, vnest_anterpolate, vnest_anterpolate_e,                &
547               vnest_boundary_conds, vnest_boundary_conds_khkm,                & 
548               vnest_deallocate, vnest_init, vnest_init_fine,                  &
549               vnest_start_time
550
551    IMPLICIT NONE
552
553    CHARACTER (LEN=9) ::  time_to_string   !<
554
555    INTEGER(iwp)      ::  lsp       !<
556    INTEGER(iwp)      ::  lsp_usr   !<
557    INTEGER(iwp)      ::  n         !< loop counter for chemistry species
558
559    REAL(wp) ::  dt_3d_old  !< temporary storage of timestep to be used for
560                            !< steering of run control output interval
561    REAL(wp) ::  time_since_reference_point_save  !< original value of
562                                                  !< time_since_reference_point
563
564!
565!-- At beginning determine the first time step
566    CALL timestep
567!
568!-- Synchronize the timestep in case of nested run.
569    IF ( nested_run )  THEN
570!
571!--    Synchronization by unifying the time step.
572!--    Global minimum of all time-steps is used for all.
573       CALL pmci_synchronize
574    ENDIF
575
576!
577!-- Determine and print out the run control quantities before the first time
578!-- step of this run. For the initial run, some statistics (e.g. divergence)
579!-- need to be determined first --> CALL flow_statistics at the beginning of
580!-- run_control
581    CALL run_control
582!
583!-- Data exchange between coupled models in case that a call has been omitted
584!-- at the end of the previous run of a job chain.
585    IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled .AND. .NOT. vnested)  THEN
586!
587!--    In case of model termination initiated by the local model the coupler
588!--    must not be called because this would again cause an MPI hang.
589       DO WHILE ( time_coupling >= dt_coupling  .AND.  terminate_coupled == 0 )
590          CALL surface_coupler
591          time_coupling = time_coupling - dt_coupling
592       ENDDO
593       IF (time_coupling == 0.0_wp  .AND.                                      &
594           time_since_reference_point < dt_coupling )                          &
595       THEN
596          time_coupling = time_since_reference_point
597       ENDIF
598    ENDIF
599
600#if defined( __dvrp_graphics )
601!
602!-- Time measurement with dvrp software 
603    CALL DVRP_LOG_EVENT( 2, current_timestep_number )
604#endif
605
606    CALL location_message( 'starting timestep-sequence', .TRUE. )
607!
608!-- Start of the time loop
609    DO  WHILE ( simulated_time < end_time  .AND.  .NOT. stop_dt  .AND. &
610                .NOT. terminate_run )
611
612       CALL cpu_log( log_point_s(10), 'timesteps', 'start' )
613!
614!--    Vertical nesting: initialize fine grid
615       IF ( vnested ) THEN
616          IF ( .NOT. vnest_init  .AND.  simulated_time >= vnest_start_time )  THEN
617             CALL cpu_log( log_point(80), 'vnest_init', 'start' )
618             CALL vnest_init_fine
619             vnest_init = .TRUE.
620             CALL cpu_log( log_point(80), 'vnest_init', 'stop' )
621          ENDIF
622       ENDIF
623!
624!--    Determine ug, vg and w_subs in dependence on data from external file
625!--    LSF_DATA
626       IF ( large_scale_forcing .AND. lsf_vert )  THEN
627           CALL ls_forcing_vert ( simulated_time )
628           sums_ls_l = 0.0_wp
629       ENDIF
630
631!
632!--    Set pt_init and q_init to the current profiles taken from
633!--    NUDGING_DATA
634       IF ( nudging )  THEN
635           CALL nudge_ref ( simulated_time )
636!
637!--        Store temperature gradient at the top boundary for possible Neumann
638!--        boundary condition
639           bc_pt_t_val = ( pt_init(nzt+1) - pt_init(nzt) ) / dzu(nzt+1)
640           bc_q_t_val  = ( q_init(nzt+1) - q_init(nzt) ) / dzu(nzt+1)
641           IF ( air_chemistry )  THEN
642              DO  lsp = 1, nspec
643                 bc_cs_t_val = (  chem_species(lsp)%conc_pr_init(nzt+1)       &
644                                - chem_species(lsp)%conc_pr_init(nzt) )       &
645                               / dzu(nzt+1)
646              ENDDO
647           ENDIF
648       ENDIF
649!
650!--    If forcing by larger-scale models is applied, check if new data
651!--    at domain boundaries need to be read.
652       IF ( nesting_offline )  THEN
653          IF ( nest_offl%time(nest_offl%tind_p) <= time_since_reference_point )&
654             CALL netcdf_data_input_offline_nesting
655       ENDIF
656
657!
658!--    Execute the gust module actions
659       IF ( gust_module_enabled )  THEN
660          CALL gust_actions( 'before_timestep' )
661       ENDIF
662
663!
664!--    Execute the user-defined actions
665       CALL user_actions( 'before_timestep' )
666
667!
668!--    Calculate forces by wind turbines
669       IF ( wind_turbine )  THEN
670
671          CALL cpu_log( log_point(55), 'wind_turbine', 'start' )
672
673          CALL wtm_forces
674
675          CALL cpu_log( log_point(55), 'wind_turbine', 'stop' )
676
677       ENDIF       
678       
679!
680!--    Start of intermediate step loop
681       intermediate_timestep_count = 0
682       DO  WHILE ( intermediate_timestep_count < &
683                   intermediate_timestep_count_max )
684
685          intermediate_timestep_count = intermediate_timestep_count + 1
686
687!
688!--       Set the steering factors for the prognostic equations which depend
689!--       on the timestep scheme
690          CALL timestep_scheme_steering
691
692!
693!--       Calculate those variables needed in the tendency terms which need
694!--       global communication
695          IF ( .NOT. use_single_reference_value  .AND. &
696               .NOT. use_initial_profile_as_reference )  THEN
697!
698!--          Horizontally averaged profiles to be used as reference state in
699!--          buoyancy terms (WARNING: only the respective last call of
700!--          calc_mean_profile defines the reference state!)
701             IF ( .NOT. neutral )  THEN
702                CALL calc_mean_profile( pt, 4 )
703                ref_state(:)  = hom(:,1,4,0) ! this is used in the buoyancy term
704             ENDIF
705             IF ( ocean_mode )  THEN
706                CALL calc_mean_profile( rho_ocean, 64 )
707                ref_state(:)  = hom(:,1,64,0)
708             ENDIF
709             IF ( humidity )  THEN
710                CALL calc_mean_profile( vpt, 44 )
711                ref_state(:)  = hom(:,1,44,0)
712             ENDIF
713!
714!--          Assure that ref_state does not become zero at any level
715!--          ( might be the case if a vertical level is completely occupied
716!--            with topography ).
717             ref_state = MERGE( MAXVAL(ref_state), ref_state,                  &
718                                ref_state == 0.0_wp )
719          ENDIF
720
721          IF ( .NOT. constant_diffusion )  CALL production_e_init
722          IF ( ( ws_scheme_mom .OR. ws_scheme_sca )  .AND.  &
723               intermediate_timestep_count == 1 )  CALL ws_statistics
724!
725!--       In case of nudging calculate current nudging time scale and horizontal
726!--       means of u, v, pt and q
727          IF ( nudging )  THEN
728             CALL calc_tnudge( simulated_time )
729             CALL calc_mean_profile( u, 1 )
730             CALL calc_mean_profile( v, 2 )
731             CALL calc_mean_profile( pt, 4 )
732             CALL calc_mean_profile( q, 41 )
733          ENDIF
734
735!
736!--       Solve the prognostic equations. A fast cache optimized version with
737!--       only one single loop is used in case of Piascek-Williams advection
738!--       scheme. NEC vector machines use a different version, because
739!--       in the other versions a good vectorization is prohibited due to
740!--       inlining problems.
741          IF ( loop_optimization == 'cache' )  THEN
742             CALL prognostic_equations_cache
743          ELSEIF ( loop_optimization == 'vector' )  THEN
744             CALL prognostic_equations_vector
745          ENDIF
746
747!
748!--       Particle transport/physics with the Lagrangian particle model
749!--       (only once during intermediate steps, because it uses an Euler-step)
750!--       ### particle model should be moved before prognostic_equations, in order
751!--       to regard droplet interactions directly
752          IF ( particle_advection  .AND.                         &
753               simulated_time >= particle_advection_start  .AND. &
754               intermediate_timestep_count == 1 )  THEN
755             CALL lpm
756             first_call_lpm = .FALSE.
757          ENDIF
758
759!
760!--       Interaction of droplets with temperature and mixing ratio.
761!--       Droplet condensation and evaporation is calculated within
762!--       advec_particles.
763          IF ( cloud_droplets  .AND.  &
764               intermediate_timestep_count == intermediate_timestep_count_max )&
765          THEN
766             CALL interaction_droplets_ptq
767          ENDIF
768
769!
770!--       Movement of agents in multi agent system
771          IF ( agents_active  .AND.                                            &
772               time_since_reference_point >= multi_agent_system_start  .AND.   &
773               time_since_reference_point <= multi_agent_system_end    .AND.   &
774               intermediate_timestep_count == 1 )  THEN
775             CALL multi_agent_system
776             first_call_mas = .FALSE.
777          ENDIF
778
779!
780!--       Exchange of ghost points (lateral boundary conditions)
781          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'start' )
782
783          CALL exchange_horiz( u_p, nbgp )
784          CALL exchange_horiz( v_p, nbgp )
785          CALL exchange_horiz( w_p, nbgp )
786          CALL exchange_horiz( pt_p, nbgp )
787          IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e_p, nbgp )
788          IF ( rans_tke_e  .OR.  wang_kernel  .OR.  collision_turbulence       &
789               .OR.  use_sgs_for_particles )  THEN
790             IF ( rans_tke_e )  THEN
791                CALL exchange_horiz( diss_p, nbgp )
792             ELSE
793                CALL exchange_horiz( diss, nbgp )
794             ENDIF
795          ENDIF
796          IF ( ocean_mode )  THEN
797             CALL exchange_horiz( sa_p, nbgp )
798             CALL exchange_horiz( rho_ocean, nbgp )
799             CALL exchange_horiz( prho, nbgp )
800          ENDIF
801          IF ( humidity )  THEN
802             CALL exchange_horiz( q_p, nbgp )
803             IF ( bulk_cloud_model .AND. microphysics_morrison )  THEN
804                CALL exchange_horiz( qc_p, nbgp )
805                CALL exchange_horiz( nc_p, nbgp )
806             ENDIF
807             IF ( bulk_cloud_model .AND. microphysics_seifert )  THEN
808                CALL exchange_horiz( qr_p, nbgp )
809                CALL exchange_horiz( nr_p, nbgp )
810             ENDIF
811          ENDIF
812          IF ( cloud_droplets )  THEN
813             CALL exchange_horiz( ql, nbgp )
814             CALL exchange_horiz( ql_c, nbgp )
815             CALL exchange_horiz( ql_v, nbgp )
816             CALL exchange_horiz( ql_vp, nbgp )
817          ENDIF
818          IF ( passive_scalar )  CALL exchange_horiz( s_p, nbgp )
819          IF ( air_chemistry )  THEN
820             DO  lsp = 1, nspec
821                CALL exchange_horiz( chem_species(lsp)%conc_p, nbgp )
822!
823!--             kanani: Push chem_boundary_conds after CALL boundary_conds
824                lsp_usr = 1
825                DO WHILE ( TRIM( cs_name( lsp_usr ) ) /= 'novalue' )
826                   IF ( TRIM(chem_species(lsp)%name) == TRIM(cs_name(lsp_usr)) )  THEN
827                      CALL chem_boundary_conds( chem_species(lsp)%conc_p,              &
828                                                chem_species(lsp)%conc_pr_init )
829                   ENDIF
830                   lsp_usr = lsp_usr + 1
831                ENDDO
832             ENDDO
833          ENDIF
834
835          CALL cpu_log( log_point(26), 'exchange-horiz-progn', 'stop' )
836
837!
838!--       Boundary conditions for the prognostic quantities (except of the
839!--       velocities at the outflow in case of a non-cyclic lateral wall)
840          CALL boundary_conds
841!
842!--       Swap the time levels in preparation for the next time step.
843          CALL swap_timelevel
844
845!
846!--       Vertical nesting: Interpolate fine grid data to the coarse grid
847          IF ( vnest_init ) THEN
848             CALL cpu_log( log_point(81), 'vnest_anterpolate', 'start' )
849             CALL vnest_anterpolate
850             CALL cpu_log( log_point(81), 'vnest_anterpolate', 'stop' )
851          ENDIF
852
853          IF ( nested_run )  THEN
854
855             CALL cpu_log( log_point(60), 'nesting', 'start' )
856!
857!--          Domain nesting. The data transfer subroutines pmci_parent_datatrans
858!--          and pmci_child_datatrans are called inside the wrapper
859!--          subroutine pmci_datatrans according to the control parameters
860!--          nesting_mode and nesting_datatransfer_mode.
861!--          TO_DO: why is nesting_mode given as a parameter here?
862             CALL pmci_datatrans( nesting_mode )
863
864             IF ( TRIM( nesting_mode ) == 'two-way' .OR.                       &
865                  nesting_mode == 'vertical' )  THEN
866!
867!--             Exchange_horiz is needed for all parent-domains after the
868!--             anterpolation
869                CALL exchange_horiz( u, nbgp )
870                CALL exchange_horiz( v, nbgp )
871                CALL exchange_horiz( w, nbgp )
872                IF ( .NOT. neutral )  CALL exchange_horiz( pt, nbgp )
873
874                IF ( humidity )  THEN
875
876                   CALL exchange_horiz( q, nbgp )
877
878                   IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
879                       CALL exchange_horiz( qc, nbgp )
880                       CALL exchange_horiz( nc, nbgp )
881                   ENDIF
882                   IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
883                       CALL exchange_horiz( qr, nbgp )
884                       CALL exchange_horiz( nr, nbgp )
885                   ENDIF
886
887                ENDIF
888
889                IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
890                IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
891
892                IF ( .NOT. constant_diffusion  .AND.  rans_mode  .AND.         &
893                                                      rans_tke_e )             &
894                   CALL exchange_horiz( diss, nbgp )
895
896                IF ( air_chemistry )  THEN
897                   DO  n = 1, nspec     
898                      CALL exchange_horiz( chem_species(n)%conc, nbgp ) 
899                   ENDDO
900                ENDIF
901
902             ENDIF
903!
904!--          Set boundary conditions again after interpolation and anterpolation.
905             CALL pmci_boundary_conds
906!
907!--          Correct the w top-BC in nest domains to ensure mass conservation.
908!--          This action must never be done for the root domain. Vertical
909!--          nesting implies mass conservation.
910!--          Commented out April 18, 2018 as seemingly unnecessary.
911!--          Will later be completely removed.
912!--             IF ( child_domain )  THEN
913!--                CALL pmci_ensure_nest_mass_conservation
914!--             ENDIF
915
916
917             CALL cpu_log( log_point(60), 'nesting', 'stop' )
918
919          ENDIF
920
921!
922!--       Temperature offset must be imposed at cyclic boundaries in x-direction
923!--       when a sloping surface is used
924          IF ( sloping_surface )  THEN
925             IF ( nxl ==  0 )  pt(:,:,nxlg:nxl-1) = pt(:,:,nxlg:nxl-1) - &
926                                                    pt_slope_offset
927             IF ( nxr == nx )  pt(:,:,nxr+1:nxrg) = pt(:,:,nxr+1:nxrg) + &
928                                                    pt_slope_offset
929          ENDIF
930
931!
932!--       Impose a turbulent inflow using the recycling method
933          IF ( turbulent_inflow )  CALL  inflow_turbulence
934
935!
936!--       Set values at outflow boundary using the special outflow condition
937          IF ( turbulent_outflow )  CALL  outflow_turbulence
938
939!
940!--       Impose a random perturbation on the horizontal velocity field
941          IF ( create_disturbances  .AND.                                      &
942               ( call_psolver_at_all_substeps  .AND.                           &
943               intermediate_timestep_count == intermediate_timestep_count_max )&
944          .OR. ( .NOT. call_psolver_at_all_substeps  .AND.                     &
945               intermediate_timestep_count == 1 ) )                            &
946          THEN
947             time_disturb = time_disturb + dt_3d
948             IF ( time_disturb >= dt_disturb )  THEN
949                IF ( disturbance_energy_limit /= 0.0_wp  .AND.                 &
950                     hom(nzb+5,1,pr_palm,0) < disturbance_energy_limit )  THEN
951                   CALL disturb_field( 'u', tend, u )
952                   CALL disturb_field( 'v', tend, v )
953                ELSEIF ( ( .NOT. bc_lr_cyc  .OR.  .NOT. bc_ns_cyc )            &
954                     .AND. .NOT. child_domain  .AND.  .NOT.  nesting_offline )  &
955                THEN
956!
957!--                Runs with a non-cyclic lateral wall need perturbations
958!--                near the inflow throughout the whole simulation
959                   dist_range = 1
960                   CALL disturb_field( 'u', tend, u )
961                   CALL disturb_field( 'v', tend, v )
962                   dist_range = 0
963                ENDIF
964                time_disturb = time_disturb - dt_disturb
965             ENDIF
966          ENDIF
967
968!
969!--       Map forcing data derived from larger scale model onto domain
970!--       boundaries.
971          IF ( nesting_offline  .AND.  intermediate_timestep_count ==          &
972                                       intermediate_timestep_count_max  )      &
973             CALL nesting_offl_bc
974!
975!--       Impose a turbulent inflow using synthetic generated turbulence,
976!--       only once per time step.
977          IF ( use_syn_turb_gen  .AND.  time_stg_call >= dt_stg_call  .AND.    &
978             intermediate_timestep_count == intermediate_timestep_count_max )  THEN! &
979             CALL stg_main
980          ENDIF
981!
982!--       Ensure mass conservation. This need to be done after imposing
983!--       synthetic turbulence and top boundary condition for pressure is set to
984!--       Neumann conditions.
985!--       Is this also required in case of Dirichlet?
986          IF ( nesting_offline )  CALL nesting_offl_mass_conservation
987!
988!--       Reduce the velocity divergence via the equation for perturbation
989!--       pressure.
990          IF ( intermediate_timestep_count == 1  .OR. &
991                call_psolver_at_all_substeps )  THEN
992
993             IF (  vnest_init ) THEN
994!
995!--             Compute pressure in the CG, interpolate top boundary conditions
996!--             to the FG and then compute pressure in the FG
997                IF ( coupling_mode == 'vnested_crse' )  CALL pres
998
999                CALL cpu_log( log_point(82), 'vnest_bc', 'start' )
1000                CALL vnest_boundary_conds
1001                CALL cpu_log( log_point(82), 'vnest_bc', 'stop' )
1002 
1003                IF ( coupling_mode == 'vnested_fine' )  CALL pres
1004
1005!--             Anterpolate TKE, satisfy Germano Identity
1006                CALL cpu_log( log_point(83), 'vnest_anter_e', 'start' )
1007                CALL vnest_anterpolate_e
1008                CALL cpu_log( log_point(83), 'vnest_anter_e', 'stop' )
1009
1010             ELSE
1011
1012                CALL pres
1013
1014             ENDIF
1015
1016          ENDIF
1017
1018!
1019!--       If required, compute liquid water content
1020          IF ( bulk_cloud_model )  THEN
1021             CALL calc_liquid_water_content
1022          ENDIF
1023!
1024!--       If required, compute virtual potential temperature
1025          IF ( humidity )  THEN
1026             CALL compute_vpt 
1027          ENDIF 
1028
1029!
1030!--       Compute the diffusion quantities
1031          IF ( .NOT. constant_diffusion )  THEN
1032
1033!
1034!--          Determine surface fluxes shf and qsws and surface values
1035!--          pt_surface and q_surface in dependence on data from external
1036!--          file LSF_DATA respectively
1037             IF ( ( large_scale_forcing .AND. lsf_surf ) .AND. &
1038                 intermediate_timestep_count == intermediate_timestep_count_max )&
1039             THEN
1040                CALL ls_forcing_surf( simulated_time )
1041             ENDIF
1042
1043!
1044!--          First the vertical (and horizontal) fluxes in the surface
1045!--          (constant flux) layer are computed
1046             IF ( constant_flux_layer )  THEN
1047                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'start' )
1048                CALL surface_layer_fluxes
1049                CALL cpu_log( log_point(19), 'surface_layer_fluxes', 'stop' )
1050             ENDIF
1051!
1052!--          If required, solve the energy balance for the surface and run soil
1053!--          model. Call for horizontal as well as vertical surfaces
1054             IF ( land_surface .AND. time_since_reference_point >= skip_time_do_lsm)  THEN
1055
1056                CALL cpu_log( log_point(54), 'land_surface', 'start' )
1057!
1058!--             Call for horizontal upward-facing surfaces
1059                CALL lsm_energy_balance( .TRUE., -1 )
1060                CALL lsm_soil_model( .TRUE., -1, .TRUE. )
1061!
1062!--             Call for northward-facing surfaces
1063                CALL lsm_energy_balance( .FALSE., 0 )
1064                CALL lsm_soil_model( .FALSE., 0, .TRUE. )
1065!
1066!--             Call for southward-facing surfaces
1067                CALL lsm_energy_balance( .FALSE., 1 )
1068                CALL lsm_soil_model( .FALSE., 1, .TRUE. )
1069!
1070!--             Call for eastward-facing surfaces
1071                CALL lsm_energy_balance( .FALSE., 2 )
1072                CALL lsm_soil_model( .FALSE., 2, .TRUE. )
1073!
1074!--             Call for westward-facing surfaces
1075                CALL lsm_energy_balance( .FALSE., 3 )
1076                CALL lsm_soil_model( .FALSE., 3, .TRUE. )
1077!
1078!--             At the end, set boundary conditons for potential temperature
1079!--             and humidity after running the land-surface model. This
1080!--             might be important for the nesting, where arrays are transfered.
1081                CALL lsm_boundary_condition
1082
1083                CALL cpu_log( log_point(54), 'land_surface', 'stop' )
1084             ENDIF
1085!
1086!--          If required, solve the energy balance for urban surfaces and run
1087!--          the material heat model
1088             IF (urban_surface) THEN
1089                CALL cpu_log( log_point(74), 'urban_surface', 'start' )
1090               
1091                CALL usm_surface_energy_balance
1092                IF ( usm_material_model )  THEN
1093                   CALL usm_green_heat_model
1094                   CALL usm_material_heat_model
1095                ENDIF
1096
1097                CALL usm_temperature_near_surface
1098!
1099!--             At the end, set boundary conditons for potential temperature
1100!--             and humidity after running the urban-surface model. This
1101!--             might be important for the nesting, where arrays are transfered.
1102                CALL usm_boundary_condition
1103
1104                CALL cpu_log( log_point(74), 'urban_surface', 'stop' )
1105             ENDIF
1106!
1107!--          Compute the diffusion coefficients
1108             CALL cpu_log( log_point(17), 'diffusivities', 'start' )
1109             IF ( .NOT. humidity ) THEN
1110                IF ( ocean_mode )  THEN
1111                   CALL tcm_diffusivities( prho, prho_reference )
1112                ELSE
1113                   CALL tcm_diffusivities( pt, pt_reference )
1114                ENDIF
1115             ELSE
1116                CALL tcm_diffusivities( vpt, pt_reference )
1117             ENDIF
1118             CALL cpu_log( log_point(17), 'diffusivities', 'stop' )
1119!
1120!--          Vertical nesting: set fine grid eddy viscosity top boundary condition
1121             IF ( vnest_init )  CALL vnest_boundary_conds_khkm
1122
1123          ENDIF
1124
1125!
1126!--       If required, calculate radiative fluxes and heating rates
1127          IF ( radiation .AND. intermediate_timestep_count                     &
1128               == intermediate_timestep_count_max .AND. time_since_reference_point >    &
1129               skip_time_do_radiation )  THEN
1130
1131               time_radiation = time_radiation + dt_3d
1132
1133             IF ( time_radiation >= dt_radiation .OR. force_radiation_call )   &
1134             THEN
1135
1136                CALL cpu_log( log_point(50), 'radiation', 'start' )
1137
1138                IF ( .NOT. force_radiation_call )  THEN
1139                   time_radiation = time_radiation - dt_radiation
1140                ENDIF
1141
1142!
1143!--             Adjust the current time to the time step of the radiation model.
1144!--             Needed since radiation is pre-calculated and stored only on apparent
1145!--             solar positions
1146                time_since_reference_point_save = time_since_reference_point
1147                time_since_reference_point =                                   &
1148                                    REAL( FLOOR( time_since_reference_point /  &
1149                                                 dt_radiation), wp )           &
1150                                             * dt_radiation
1151
1152                CALL radiation_control
1153
1154                CALL cpu_log( log_point(50), 'radiation', 'stop' )
1155
1156                IF ( ( urban_surface  .OR.  land_surface )  .AND.               &
1157                     radiation_interactions )  THEN
1158                   CALL cpu_log( log_point(75), 'radiation_interaction', 'start' )
1159                   CALL radiation_interaction
1160                   CALL cpu_log( log_point(75), 'radiation_interaction', 'stop' )
1161                ENDIF
1162   
1163!
1164!--             Return the current time to its original value
1165                time_since_reference_point = time_since_reference_point_save
1166
1167             ENDIF
1168          ENDIF
1169
1170       ENDDO   ! Intermediate step loop
1171!
1172!--    If required, consider chemical emissions
1173       IF ( air_chemistry  .AND.  do_emis )  THEN
1174!
1175!--       Update the time --> kanani: revise location of this CALL
1176          CALL calc_date_and_time
1177!
1178!--       Call emission routine only once an hour
1179          IF (hour_of_year  .GT.  hour_call_emis )  THEN
1180             CALL chem_emissions_setup( chem_emis_att, chem_emis, nspec_out )
1181             hour_call_emis = hour_of_year
1182          ENDIF
1183       ENDIF
1184!
1185!--    If required, do UV exposure calculations
1186       IF ( uv_exposure )  THEN
1187          CALL uvem_calc_exposure
1188       ENDIF
1189!
1190!--    Increase simulation time and output times
1191       nr_timesteps_this_run      = nr_timesteps_this_run + 1
1192       current_timestep_number    = current_timestep_number + 1
1193       simulated_time             = simulated_time   + dt_3d
1194       time_since_reference_point = simulated_time - coupling_start_time
1195       simulated_time_chr         = time_to_string( time_since_reference_point )
1196
1197
1198
1199
1200       IF ( simulated_time >= skip_time_data_output_av )  THEN
1201          time_do_av         = time_do_av       + dt_3d
1202       ENDIF
1203       IF ( simulated_time >= skip_time_do2d_xy )  THEN
1204          time_do2d_xy       = time_do2d_xy     + dt_3d
1205       ENDIF
1206       IF ( simulated_time >= skip_time_do2d_xz )  THEN
1207          time_do2d_xz       = time_do2d_xz     + dt_3d
1208       ENDIF
1209       IF ( simulated_time >= skip_time_do2d_yz )  THEN
1210          time_do2d_yz       = time_do2d_yz     + dt_3d
1211       ENDIF
1212       IF ( simulated_time >= skip_time_do3d    )  THEN
1213          time_do3d          = time_do3d        + dt_3d
1214       ENDIF
1215       DO  mid = 1, masks
1216          IF ( simulated_time >= skip_time_domask(mid) )  THEN
1217             time_domask(mid)= time_domask(mid) + dt_3d
1218          ENDIF
1219       ENDDO
1220       time_dvrp          = time_dvrp        + dt_3d
1221       IF ( simulated_time >= skip_time_dosp )  THEN
1222          time_dosp       = time_dosp        + dt_3d
1223       ENDIF
1224       time_dots          = time_dots        + dt_3d
1225       IF ( .NOT. first_call_lpm )  THEN
1226          time_dopts      = time_dopts       + dt_3d
1227       ENDIF
1228       IF ( simulated_time >= skip_time_dopr )  THEN
1229          time_dopr       = time_dopr        + dt_3d
1230       ENDIF
1231       time_dopr_listing          = time_dopr_listing        + dt_3d
1232       time_run_control   = time_run_control + dt_3d
1233!
1234!--    In case of synthetic turbulence generation and parametrized turbulence
1235!--    information, update the time counter and if required, adjust the
1236!--    STG to new atmospheric conditions.
1237       IF ( use_syn_turb_gen  )  THEN
1238          IF ( parametrize_inflow_turbulence )  THEN
1239             time_stg_adjust = time_stg_adjust + dt_3d
1240             IF ( time_stg_adjust >= dt_stg_adjust )  CALL stg_adjust
1241          ENDIF
1242          time_stg_call = time_stg_call + dt_3d
1243       ENDIF
1244
1245!
1246!--    Data exchange between coupled models
1247       IF ( coupling_mode /= 'uncoupled'  .AND.  run_coupled                   &
1248                                          .AND. .NOT. vnested )  THEN
1249          time_coupling = time_coupling + dt_3d
1250
1251!
1252!--       In case of model termination initiated by the local model
1253!--       (terminate_coupled > 0), the coupler must be skipped because it would
1254!--       cause an MPI intercomminucation hang.
1255!--       If necessary, the coupler will be called at the beginning of the
1256!--       next restart run.
1257          DO WHILE ( time_coupling >= dt_coupling .AND. terminate_coupled == 0 )
1258             CALL surface_coupler
1259             time_coupling = time_coupling - dt_coupling
1260          ENDDO
1261       ENDIF
1262
1263!
1264!--    Execute the gust module actions
1265       IF ( gust_module_enabled )  THEN
1266          CALL gust_actions( 'after_integration' )
1267       ENDIF
1268
1269!
1270!--    Execute user-defined actions
1271       CALL user_actions( 'after_integration' )
1272
1273!
1274!--    If Galilei transformation is used, determine the distance that the
1275!--    model has moved so far
1276       IF ( galilei_transformation )  THEN
1277          advected_distance_x = advected_distance_x + u_gtrans * dt_3d
1278          advected_distance_y = advected_distance_y + v_gtrans * dt_3d
1279       ENDIF
1280
1281!
1282!--    Check, if restart is necessary (because cpu-time is expiring or
1283!--    because it is forced by user) and set stop flag
1284!--    This call is skipped if the remote model has already initiated a restart.
1285       IF ( .NOT. terminate_run )  CALL check_for_restart
1286
1287!
1288!--    Carry out statistical analysis and output at the requested output times.
1289!--    The MOD function is used for calculating the output time counters (like
1290!--    time_dopr) in order to regard a possible decrease of the output time
1291!--    interval in case of restart runs
1292
1293!
1294!--    Set a flag indicating that so far no statistics have been created
1295!--    for this time step
1296       flow_statistics_called = .FALSE.
1297
1298!
1299!--    If required, call flow_statistics for averaging in time
1300       IF ( averaging_interval_pr /= 0.0_wp  .AND.  &
1301            ( dt_dopr - time_dopr ) <= averaging_interval_pr  .AND.  &
1302            simulated_time >= skip_time_dopr )  THEN
1303          time_dopr_av = time_dopr_av + dt_3d
1304          IF ( time_dopr_av >= dt_averaging_input_pr )  THEN
1305             do_sum = .TRUE.
1306             time_dopr_av = MOD( time_dopr_av, &
1307                                    MAX( dt_averaging_input_pr, dt_3d ) )
1308          ENDIF
1309       ENDIF
1310       IF ( do_sum )  CALL flow_statistics
1311
1312!
1313!--    Sum-up 3d-arrays for later output of time-averaged 2d/3d/masked data
1314       IF ( averaging_interval /= 0.0_wp  .AND.                                &
1315            ( dt_data_output_av - time_do_av ) <= averaging_interval  .AND. &
1316            simulated_time >= skip_time_data_output_av )                    &
1317       THEN
1318          time_do_sla = time_do_sla + dt_3d
1319          IF ( time_do_sla >= dt_averaging_input )  THEN
1320             CALL sum_up_3d_data
1321             average_count_3d = average_count_3d + 1
1322             time_do_sla = MOD( time_do_sla, MAX( dt_averaging_input, dt_3d ) )
1323          ENDIF
1324       ENDIF
1325
1326!
1327!--    Calculate spectra for time averaging
1328       IF ( averaging_interval_sp /= 0.0_wp  .AND.  &
1329            ( dt_dosp - time_dosp ) <= averaging_interval_sp  .AND.  &
1330            simulated_time >= skip_time_dosp )  THEN
1331          time_dosp_av = time_dosp_av + dt_3d
1332          IF ( time_dosp_av >= dt_averaging_input_pr )  THEN
1333             CALL calc_spectra
1334             time_dosp_av = MOD( time_dosp_av, &
1335                                 MAX( dt_averaging_input_pr, dt_3d ) )
1336          ENDIF
1337       ENDIF
1338
1339!
1340!--    Call flight module and output data
1341       IF ( virtual_flight )  THEN
1342          CALL flight_measurement
1343          CALL data_output_flight
1344       ENDIF
1345
1346!
1347!--    Profile output (ASCII) on file
1348       IF ( time_dopr_listing >= dt_dopr_listing )  THEN
1349          CALL print_1d
1350          time_dopr_listing = MOD( time_dopr_listing, MAX( dt_dopr_listing, &
1351                                                           dt_3d ) )
1352       ENDIF
1353
1354!
1355!--    Graphic output for PROFIL
1356       IF ( time_dopr >= dt_dopr )  THEN
1357          IF ( dopr_n /= 0 )  CALL data_output_profiles
1358          time_dopr = MOD( time_dopr, MAX( dt_dopr, dt_3d ) )
1359          time_dopr_av = 0.0_wp    ! due to averaging (see above)
1360       ENDIF
1361
1362!
1363!--    Graphic output for time series
1364       IF ( time_dots >= dt_dots )  THEN
1365          CALL data_output_tseries
1366          time_dots = MOD( time_dots, MAX( dt_dots, dt_3d ) )
1367       ENDIF
1368
1369!
1370!--    Output of spectra (formatted for use with PROFIL), in case of no
1371!--    time averaging, spectra has to be calculated before
1372       IF ( time_dosp >= dt_dosp )  THEN
1373          IF ( average_count_sp == 0 )  CALL calc_spectra
1374          CALL data_output_spectra
1375          time_dosp = MOD( time_dosp, MAX( dt_dosp, dt_3d ) )
1376       ENDIF
1377
1378!
1379!--    2d-data output (cross-sections)
1380       IF ( time_do2d_xy >= dt_do2d_xy )  THEN
1381          CALL data_output_2d( 'xy', 0 )
1382          time_do2d_xy = MOD( time_do2d_xy, MAX( dt_do2d_xy, dt_3d ) )
1383       ENDIF
1384       IF ( time_do2d_xz >= dt_do2d_xz )  THEN
1385          CALL data_output_2d( 'xz', 0 )
1386          time_do2d_xz = MOD( time_do2d_xz, MAX( dt_do2d_xz, dt_3d ) )
1387       ENDIF
1388       IF ( time_do2d_yz >= dt_do2d_yz )  THEN
1389          CALL data_output_2d( 'yz', 0 )
1390          time_do2d_yz = MOD( time_do2d_yz, MAX( dt_do2d_yz, dt_3d ) )
1391       ENDIF
1392
1393!
1394!--    3d-data output (volume data)
1395       IF ( time_do3d >= dt_do3d )  THEN
1396          CALL data_output_3d( 0 )
1397          time_do3d = MOD( time_do3d, MAX( dt_do3d, dt_3d ) )
1398       ENDIF
1399
1400!
1401!--    Masked data output
1402       DO  mid = 1, masks
1403          IF ( time_domask(mid) >= dt_domask(mid) )  THEN
1404             CALL data_output_mask( 0 )
1405             time_domask(mid) = MOD( time_domask(mid),  &
1406                                     MAX( dt_domask(mid), dt_3d ) )
1407          ENDIF
1408       ENDDO
1409
1410!
1411!--    Output of time-averaged 2d/3d/masked data
1412       IF ( time_do_av >= dt_data_output_av )  THEN
1413          CALL average_3d_data
1414          CALL data_output_2d( 'xy', 1 )
1415          CALL data_output_2d( 'xz', 1 )
1416          CALL data_output_2d( 'yz', 1 )
1417          CALL data_output_3d( 1 )
1418          DO  mid = 1, masks
1419             CALL data_output_mask( 1 )
1420          ENDDO
1421          time_do_av = MOD( time_do_av, MAX( dt_data_output_av, dt_3d ) )
1422       ENDIF
1423
1424!
1425!--    Output of particle time series
1426       IF ( particle_advection )  THEN
1427          IF ( time_dopts >= dt_dopts  .OR. &
1428               ( simulated_time >= particle_advection_start  .AND. &
1429                 first_call_lpm ) )  THEN
1430             CALL data_output_ptseries
1431             time_dopts = MOD( time_dopts, MAX( dt_dopts, dt_3d ) )
1432          ENDIF
1433       ENDIF
1434
1435!
1436!--    Output of dvrp-graphics (isosurface, particles, slicer)
1437#if defined( __dvrp_graphics )
1438       CALL DVRP_LOG_EVENT( -2, current_timestep_number-1 )
1439#endif
1440       IF ( time_dvrp >= dt_dvrp )  THEN
1441          CALL data_output_dvrp
1442          time_dvrp = MOD( time_dvrp, MAX( dt_dvrp, dt_3d ) )
1443       ENDIF
1444#if defined( __dvrp_graphics )
1445       CALL DVRP_LOG_EVENT( 2, current_timestep_number )
1446#endif
1447
1448!
1449!--    If required, set the heat flux for the next time step at a random value
1450       IF ( constant_heatflux  .AND.  random_heatflux )  THEN
1451          IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
1452          IF ( surf_lsm_h%ns    >= 1 )  CALL disturb_heatflux( surf_lsm_h    )
1453          IF ( surf_usm_h%ns    >= 1 )  CALL disturb_heatflux( surf_usm_h    )
1454       ENDIF
1455
1456!
1457!--    Execute the gust module actions
1458       IF ( gust_module_enabled )  THEN
1459          CALL gust_actions( 'after_timestep' )
1460       ENDIF
1461
1462!
1463!--    Execute user-defined actions
1464       CALL user_actions( 'after_timestep' )
1465
1466!
1467!--    Determine size of next time step. Save timestep dt_3d because it is
1468!--    newly calculated in routine timestep, but required further below for
1469!--    steering the run control output interval
1470       dt_3d_old = dt_3d
1471       CALL timestep
1472
1473!
1474!--    Synchronize the timestep in case of nested run.
1475       IF ( nested_run )  THEN
1476!
1477!--       Synchronize by unifying the time step.
1478!--       Global minimum of all time-steps is used for all.
1479          CALL pmci_synchronize
1480       ENDIF
1481
1482!
1483!--    Computation and output of run control parameters.
1484!--    This is also done whenever perturbations have been imposed
1485       IF ( time_run_control >= dt_run_control  .OR.                     &
1486            timestep_scheme(1:5) /= 'runge'  .OR.  disturbance_created ) &
1487       THEN
1488          CALL run_control
1489          IF ( time_run_control >= dt_run_control )  THEN
1490             time_run_control = MOD( time_run_control, &
1491                                     MAX( dt_run_control, dt_3d_old ) )
1492          ENDIF
1493       ENDIF
1494
1495!
1496!--    Output elapsed simulated time in form of a progress bar on stdout
1497       IF ( myid == 0 )  CALL output_progress_bar
1498
1499       CALL cpu_log( log_point_s(10), 'timesteps', 'stop' )
1500
1501
1502    ENDDO   ! time loop
1503   
1504!
1505!-- Vertical nesting: Deallocate variables initialized for vertical nesting   
1506    IF ( vnest_init )  CALL vnest_deallocate
1507
1508    IF ( myid == 0 )  CALL finish_progress_bar
1509
1510#if defined( __dvrp_graphics )
1511    CALL DVRP_LOG_EVENT( -2, current_timestep_number )
1512#endif
1513
1514    CALL location_message( 'finished time-stepping', .TRUE. )
1515
1516 END SUBROUTINE time_integration
Note: See TracBrowser for help on using the repository browser.