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

Last change on this file since 3231 was 3198, checked in by sward, 6 years ago

Added MAS end time, used time_since_reference_point, corrected tolerance_dp in nav_mesh

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