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

Last change on this file since 3352 was 3347, checked in by suehring, 6 years ago

Offline nesting revised and separated from large_scale_forcing_mod; Time-dependent synthetic turbulence generator; bugfixes in USM/LSM radiation model and init_pegrid

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