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

Last change on this file since 3418 was 3418, checked in by kanani, 5 years ago

Add green facades, update building data base, fix for thin walls in spinup

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