source: palm/trunk/SOURCE/init_3d_model.f90 @ 3049

Last change on this file since 3049 was 3049, checked in by Giersch, 6 years ago

Revision history corrected

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to False
    /palm/branches/forwind/SOURCE/init_3d_model.f901564-1913
    /palm/branches/palm4u/SOURCE/init_3d_model.f902540-2692
File size: 98.7 KB
RevLine 
[1682]1!> @file init_3d_model.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[254]20! Current revisions:
[732]21! ------------------
[2233]22!
[3049]23!
[2233]24! Former revisions:
25! -----------------
26! $Id: init_3d_model.f90 3049 2018-05-29 13:52:36Z Giersch $
[3045]27! Error messages revised
28!
[3049]29! 3045 2018-05-28 07:55:41Z Giersch
30! Error messages revised
31!
[3045]32! 3042 2018-05-25 10:44:37Z schwenkel
[3042]33! Changed the name specific humidity to mixing ratio
34!
35! 3040 2018-05-25 10:22:08Z schwenkel
[3035]36! Add option to initialize warm air bubble close to surface
37!
38! 3014 2018-05-09 08:42:38Z maronga
[3014]39! Bugfix: initialization of ts_value missing
40!
41! 3011 2018-05-07 14:38:42Z schwenkel
[3011]42! removed redundant if statement
43!
44! 3004 2018-04-27 12:33:25Z Giersch
[3004]45! precipitation_rate removed
46!
47! 2995 2018-04-19 12:13:16Z Giersch
[2995]48! CALL radiation_control is not necessary during initialization because
49! calculation of radiative fluxes at model start is done in radiation_init
50! in any case
51!
52! 2977 2018-04-17 10:27:57Z kanani
[2977]53! Implement changes from branch radiation (r2948-2971) with minor modifications
54! (moh.hefny):
55! - set radiation_interactions according to the existence of urban/land vertical
56!   surfaces and trees to activiate RTM
57! - set average_radiation to TRUE if RTM is activiated
58!
59! 2938 2018-03-27 15:52:42Z suehring
[2938]60! - Revise Inifor initialization for geostrophic wind components
61! - Initialize synthetic turbulence generator in case of Inifor initialization 
62!
63! 2936 2018-03-27 14:49:27Z suehring
[2934]64! Synchronize parent and child models after initialization.
65! Remove obsolete masking of topography grid points for Runge-Kutta weighted
66! tendency arrays.
67!
68! 2920 2018-03-22 11:22:01Z kanani
[2920]69! Add call for precalculating apparent solar positions (moh.hefny)
70!
71! 2906 2018-03-19 08:56:40Z Giersch
[2906]72! The variables read/write_svf_on_init have been removed. Instead ENVIRONMENT
73! variables read/write_svf have been introduced. Location_message has been
74! added.
75!
76! 2894 2018-03-15 09:17:58Z Giersch
[2894]77! Renamed routines with respect to reading restart data, file 13 is closed in
78! rrd_read_parts_of_global now
79!
80! 2867 2018-03-09 09:40:23Z suehring
[2867]81! Further bugfix concerning call of user_init.
82!
83! 2864 2018-03-08 11:57:45Z suehring
[2864]84! Bugfix, move call of user_init in front of initialization of grid-point
85! arrays
86!
87! 2817 2018-02-19 16:32:21Z knoop
[2817]88! Preliminary gust module interface implemented
89!
90! 2776 2018-01-31 10:44:42Z Giersch
[2776]91! Variable use_synthetic_turbulence_generator has been abbreviated
92!
93! 2766 2018-01-22 17:17:47Z kanani
[2766]94! Removed preprocessor directive __chem
95!
96! 2758 2018-01-17 12:55:21Z suehring
[2758]97! In case of spinup of land- and urban-surface model, do not mask wind velocity
98! at first computational grid level
99!
100! 2746 2018-01-15 12:06:04Z suehring
[2746]101! Move flag plant canopy to modules
102!
103! 2718 2018-01-02 08:49:38Z maronga
[2716]104! Corrected "Former revisions" section
105!
106! 2705 2017-12-18 11:26:23Z maronga
[2705]107! Bugfix for reading initial profiles from ls/nuding file
[2716]108!
109! 2701 2017-12-15 15:40:50Z suehring
110! Changes from last commit documented
[2705]111!
[2716]112! 2700 2017-12-15 14:12:35Z suehring
[2701]113! Bugfix, missing initialization of surface attributes in case of
114! inifor-initialization branch
[2716]115!
116! 2698 2017-12-14 18:46:24Z suehring
117! Bugfix in get_topography_top_index
118!
119! 2696 2017-12-14 17:12:51Z kanani
120! Change in file header (GPL part)
[2696]121! Implementation of uv exposure model (FK)
122! Moved initialisation of diss, e, kh, km to turbulence_closure_mod (TG)
123! Added chemical emissions (FK)
124! Initialize masking arrays and number-of-grid-points arrays before initialize
125! LSM, USM and radiation module
126! Initialization with inifor (MS)
127!
128! 2618 2017-11-16 15:37:30Z suehring
[2618]129! Reorder calls of init_surfaces.
130!
131! 2564 2017-10-19 15:56:56Z Giersch
[2564]132! Variable wind_turbine was added to control_parameters.
133!
134! 2550 2017-10-16 17:12:01Z boeske
[2550]135! Modifications to cyclic fill method and turbulence recycling method in case of
136! complex terrain simulations
137!
138! 2513 2017-10-04 09:24:39Z kanani
[2513]139! Bugfix in storing initial scalar profile (wrong index)
140!
141! 2350 2017-08-15 11:48:26Z kanani
[2350]142! Bugfix in nopointer version
143!
144! 2339 2017-08-07 13:55:26Z gronemeier
[2339]145! corrected timestamp in header
146!
147! 2338 2017-08-07 12:15:38Z gronemeier
[2338]148! Modularize 1D model
149!
[2339]150! 2329 2017-08-03 14:24:56Z knoop
[2329]151! Removed temporary bugfix (r2327) as bug is properly resolved by this revision
152!
153! 2327 2017-08-02 07:40:57Z maronga
[2327]154! Temporary bugfix
155!
156! 2320 2017-07-21 12:47:43Z suehring
[2320]157! Modularize large-scale forcing and nudging
158!
159! 2292 2017-06-20 09:51:42Z schwenkel
[2292]160! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
161! includes two more prognostic equations for cloud drop concentration (nc) 
162! and cloud water content (qc).
163!
164! 2277 2017-06-12 10:47:51Z kanani
[2277]165! Removed unused variable sums_up_fraction_l
166!
167! 2270 2017-06-09 12:18:47Z maronga
[2270]168! dots_num must be increased when LSM and/or radiation is used
169!
170! 2259 2017-06-08 09:09:11Z gronemeier
[2259]171! Implemented synthetic turbulence generator
172!
173! 2252 2017-06-07 09:35:37Z knoop
[2252]174! rho_air now depending on surface_pressure even in Boussinesq mode
175!
176! 2233 2017-05-30 18:08:54Z suehring
[2233]177!
178! 2232 2017-05-30 17:47:52Z suehring
[2232]179! Adjustments to new topography and surface concept:
180!   - Modify passed parameters for disturb_field
181!   - Topography representation via flags
182!   - Remove unused arrays.
183!   - Move initialization of surface-related quantities to surface_mod
[1961]184!
[2173]185! 2172 2017-03-08 15:55:25Z knoop
186! Bugfix: moved parallel random generator initialization into its module
187!
[2119]188! 2118 2017-01-17 16:38:49Z raasch
189! OpenACC directives removed
190!
[2038]191! 2037 2016-10-26 11:15:40Z knoop
192! Anelastic approximation implemented
193!
[2032]194! 2031 2016-10-21 15:11:58Z knoop
195! renamed variable rho to rho_ocean
196!
[2012]197! 2011 2016-09-19 17:29:57Z kanani
198! Flag urban_surface is now defined in module control_parameters.
199!
[2008]200! 2007 2016-08-24 15:47:17Z kanani
201! Added support for urban surface model,
202! adjusted location_message in case of plant_canopy
203!
[2001]204! 2000 2016-08-20 18:09:15Z knoop
205! Forced header and separation lines into 80 columns
206!
[1993]207! 1992 2016-08-12 15:14:59Z suehring
208! Initializaton of scalarflux at model top
209! Bugfixes in initialization of surface and top salinity flux, top scalar and
210! humidity fluxes
211!
[1961]212! 1960 2016-07-12 16:34:24Z suehring
[1960]213! Separate humidity and passive scalar
214! Increase dimension for mean_inflow_profiles
215! Remove inadvertent write-statement
216! Bugfix, large-scale forcing is still not implemented for passive scalars
[1919]217!
[1958]218! 1957 2016-07-07 10:43:48Z suehring
219! flight module added
220!
[1921]221! 1920 2016-05-30 10:50:15Z suehring
222! Initialize us with very small number to avoid segmentation fault during
223! calculation of Obukhov length
224!
[1919]225! 1918 2016-05-27 14:35:57Z raasch
226! intermediate_timestep_count is set 0 instead 1 for first call of pres,
227! bugfix: initialization of local sum arrays are moved to the beginning of the
228!         routine because otherwise results from pres are overwritten
229!
[1917]230! 1914 2016-05-26 14:44:07Z witha
231! Added initialization of the wind turbine model
232!
[1879]233! 1878 2016-04-19 12:30:36Z hellstea
234! The zeroth element of weight_pres removed as unnecessary
235!
[1851]236! 1849 2016-04-08 11:33:18Z hoffmann
[1849]237! Adapted for modularization of microphysics.
238! precipitation_amount, precipitation_rate, prr moved to arrays_3d.
[1852]239! Initialization of nc_1d, nr_1d, pt_1d, qc_1d, qr_1d, q_1d moved to
[1849]240! microphysics_init.
241!
[1846]242! 1845 2016-04-08 08:29:13Z raasch
243! nzb_2d replaced by nzb_u|v_inner
[1914]244!
[1834]245! 1833 2016-04-07 14:23:03Z raasch
246! initialization of spectra quantities moved to spectra_mod
247!
[1832]248! 1831 2016-04-07 13:15:51Z hoffmann
249! turbulence renamed collision_turbulence
250!
[1827]251! 1826 2016-04-07 12:01:39Z maronga
252! Renamed radiation calls.
253! Renamed canopy model calls.
254!
[1823]255! 1822 2016-04-07 07:49:42Z hoffmann
256! icloud_scheme replaced by microphysics_*
[1914]257!
[1818]258! 1817 2016-04-06 15:44:20Z maronga
259! Renamed lsm calls.
260!
[1816]261! 1815 2016-04-06 13:49:59Z raasch
262! zero-settings for velocities inside topography re-activated (was deactivated
263! in r1762)
264!
[1789]265! 1788 2016-03-10 11:01:04Z maronga
266! Added z0q.
267! Syntax layout improved.
268!
[1784]269! 1783 2016-03-06 18:36:17Z raasch
270! netcdf module name changed + related changes
271!
[1765]272! 1764 2016-02-28 12:45:19Z raasch
273! bugfix: increase size of volume_flow_area_l and volume_flow_initial_l by 1
274!
[1763]275! 1762 2016-02-25 12:31:13Z hellstea
276! Introduction of nested domain feature
277!
[1739]278! 1738 2015-12-18 13:56:05Z raasch
279! calculate mean surface level height for each statistic region
280!
[1735]281! 1734 2015-12-02 12:17:12Z raasch
282! no initial disturbances in case that the disturbance energy limit has been
283! set zero
284!
[1708]285! 1707 2015-11-02 15:24:52Z maronga
286! Bugfix: transfer of Richardson number from 1D model to Obukhov length caused
287! devision by zero in neutral stratification
288!
[1692]289! 1691 2015-10-26 16:17:44Z maronga
290! Call to init_surface_layer added. rif is replaced by ol and zeta.
291!
[1683]292! 1682 2015-10-07 23:56:08Z knoop
293! Code annotations made doxygen readable
294!
[1616]295! 1615 2015-07-08 18:49:19Z suehring
296! Enable turbulent inflow for passive_scalar and humidity
297!
[1586]298! 1585 2015-04-30 07:05:52Z maronga
299! Initialization of radiation code is now done after LSM initializtion
300!
[1576]301! 1575 2015-03-27 09:56:27Z raasch
302! adjustments for psolver-queries
303!
[1552]304! 1551 2015-03-03 14:18:16Z maronga
[1817]305! Allocation of land surface arrays is now done in the subroutine lsm_init_arrays,
[1552]306! which is part of land_surface_model.
307!
[1508]308! 1507 2014-12-10 12:14:18Z suehring
309! Bugfix: set horizontal velocity components to zero inside topography
310!
[1497]311! 1496 2014-12-02 17:25:50Z maronga
312! Added initialization of the land surface and radiation schemes
313!
[1485]314! 1484 2014-10-21 10:53:05Z kanani
[1484]315! Changes due to new module structure of the plant canopy model:
[1508]316! canopy-related initialization (e.g. lad and canopy_heat_flux) moved to new
317! subroutine init_plant_canopy within the module plant_canopy_model_mod,
318! call of subroutine init_plant_canopy added.
[1341]319!
[1432]320! 1431 2014-07-15 14:47:17Z suehring
321! var_d added, in order to normalize spectra.
322!
[1430]323! 1429 2014-07-15 12:53:45Z knoop
324! Ensemble run capability added to parallel random number generator
325!
[1412]326! 1411 2014-05-16 18:01:51Z suehring
327! Initial horizontal velocity profiles were not set to zero at the first vertical
328! grid level in case of non-cyclic lateral boundary conditions.
329!
[1407]330! 1406 2014-05-16 13:47:01Z raasch
331! bugfix: setting of initial velocities at k=1 to zero not in case of a
332! no-slip boundary condition for uv
333!
[1403]334! 1402 2014-05-09 14:25:13Z raasch
335! location messages modified
336!
[1401]337! 1400 2014-05-09 14:03:54Z knoop
338! Parallel random number generator added
339!
[1385]340! 1384 2014-05-02 14:31:06Z raasch
341! location messages added
342!
[1362]343! 1361 2014-04-16 15:17:48Z hoffmann
344! tend_* removed
345! Bugfix: w_subs is not allocated anymore if it is already allocated
346!
[1360]347! 1359 2014-04-11 17:15:14Z hoffmann
348! module lpm_init_mod added to use statements, because lpm_init has become a
349! module
350!
[1354]351! 1353 2014-04-08 15:21:23Z heinze
352! REAL constants provided with KIND-attribute
353!
[1341]354! 1340 2014-03-25 19:45:13Z kanani
355! REAL constants defined as wp-kind
356!
[1323]357! 1322 2014-03-20 16:38:49Z raasch
358! REAL constants defined as wp-kind
359! module interfaces removed
360!
[1321]361! 1320 2014-03-20 08:40:49Z raasch
362! ONLY-attribute added to USE-statements,
363! kind-parameters added to all INTEGER and REAL declaration statements,
364! kinds are defined in new module kinds,
365! revision history before 2012 removed,
366! comment fields (!:) to be used for variable explanations added to
367! all variable declaration statements
368!
[1317]369! 1316 2014-03-17 07:44:59Z heinze
370! Bugfix: allocation of w_subs
371!
[1300]372! 1299 2014-03-06 13:15:21Z heinze
373! Allocate w_subs due to extension of large scale subsidence in combination
374! with large scale forcing data (LSF_DATA)
375!
[1242]376! 1241 2013-10-30 11:36:58Z heinze
377! Overwrite initial profiles in case of nudging
378! Inititialize shf and qsws in case of large_scale_forcing
379!
[1222]380! 1221 2013-09-10 08:59:13Z raasch
381! +rflags_s_inner in copyin statement, use copyin for most arrays instead of
382! copy
383!
[1213]384! 1212 2013-08-15 08:46:27Z raasch
385! array tri is allocated and included in data copy statement
386!
[1196]387! 1195 2013-07-01 12:27:57Z heinze
388! Bugfix: move allocation of ref_state to parin.f90 and read_var_list.f90
389!
[1182]390! 1179 2013-06-14 05:57:58Z raasch
391! allocate and set ref_state to be used in buoyancy terms
392!
[1172]393! 1171 2013-05-30 11:27:45Z raasch
394! diss array is allocated with full size if accelerator boards are used
395!
[1160]396! 1159 2013-05-21 11:58:22Z fricke
397! -bc_lr_dirneu, bc_lr_neudir, bc_ns_dirneu, bc_ns_neudir
398!
[1154]399! 1153 2013-05-10 14:33:08Z raasch
400! diss array is allocated with dummy elements even if it is not needed
[1171]401! (required by PGI 13.4 / CUDA 5.0)
[1154]402!
[1116]403! 1115 2013-03-26 18:16:16Z hoffmann
404! unused variables removed
405!
[1114]406! 1113 2013-03-10 02:48:14Z raasch
407! openACC directive modified
408!
[1112]409! 1111 2013-03-08 23:54:10Z raasch
410! openACC directives added for pres
411! array diss allocated only if required
412!
[1093]413! 1092 2013-02-02 11:24:22Z raasch
414! unused variables removed
415!
[1066]416! 1065 2012-11-22 17:42:36Z hoffmann
417! allocation of diss (dissipation rate) in case of turbulence = .TRUE. added
418!
[1054]419! 1053 2012-11-13 17:11:03Z hoffmann
[1053]420! allocation and initialisation of necessary data arrays for the two-moment
421! cloud physics scheme the two new prognostic equations (nr, qr):
422! +dr, lambda_r, mu_r, sed_*, xr, *s, *sws, *swst, *, *_p, t*_m, *_1, *_2, *_3,
423! +tend_*, prr
[979]424!
[1037]425! 1036 2012-10-22 13:43:42Z raasch
426! code put under GPL (PALM 3.9)
427!
[1033]428! 1032 2012-10-21 13:03:21Z letzel
429! save memory by not allocating pt_2 in case of neutral = .T.
430!
[1026]431! 1025 2012-10-07 16:04:41Z letzel
432! bugfix: swap indices of mask for ghost boundaries
433!
[1017]434! 1015 2012-09-27 09:23:24Z raasch
435! mask is set to zero for ghost boundaries
436!
[1011]437! 1010 2012-09-20 07:59:54Z raasch
438! cpp switch __nopointer added for pointer free version
439!
[1004]440! 1003 2012-09-14 14:35:53Z raasch
441! nxra,nyna, nzta replaced ny nxr, nyn, nzt
442!
[1002]443! 1001 2012-09-13 14:08:46Z raasch
444! all actions concerning leapfrog scheme removed
445!
[997]446! 996 2012-09-07 10:41:47Z raasch
447! little reformatting
448!
[979]449! 978 2012-08-09 08:28:32Z fricke
[978]450! outflow damping layer removed
451! roughness length for scalar quantites z0h added
452! damping zone for the potential temperatur in case of non-cyclic lateral
453! boundaries added
454! initialization of ptdf_x, ptdf_y
455! initialization of c_u_m, c_u_m_l, c_v_m, c_v_m_l, c_w_m, c_w_m_l
[708]456!
[850]457! 849 2012-03-15 10:35:09Z raasch
458! init_particles renamed lpm_init
459!
[826]460! 825 2012-02-19 03:03:44Z raasch
461! wang_collision_kernel renamed wang_kernel
462!
[1]463! Revision 1.1  1998/03/09 16:22:22  raasch
464! Initial revision
465!
466!
467! Description:
468! ------------
[1682]469!> Allocation of arrays and initialization of the 3D model via
470!> a) pre-run the 1D model
471!> or
472!> b) pre-set constant linear profiles
473!> or
474!> c) read values of a previous run
[1]475!------------------------------------------------------------------------------!
[1682]476 SUBROUTINE init_3d_model
477 
[1]478
[667]479    USE advec_ws
[1320]480
[1]481    USE arrays_3d
[1849]482
[2696]483    USE chemistry_model_mod,                                                   &
484        ONLY:  chem_emissions
485
[2037]486    USE cloud_parameters,                                                      &
487        ONLY:  cp, l_v, r_d
488
[1320]489    USE constants,                                                             &
490        ONLY:  pi
491   
[1]492    USE control_parameters
[1320]493   
[1957]494    USE flight_mod,                                                            &
495        ONLY:  flight_init
496   
[1320]497    USE grid_variables,                                                        &
[2037]498        ONLY:  dx, dy, ddx2_mg, ddy2_mg
[2817]499
500    USE gust_mod,                                                              &
501        ONLY:  gust_init, gust_init_arrays, gust_module_enabled
[1320]502   
[1]503    USE indices
[1359]504
[1429]505    USE lpm_init_mod,                                                          &
[1359]506        ONLY:  lpm_init
[1320]507   
508    USE kinds
[1496]509
510    USE land_surface_model_mod,                                                &
[2232]511        ONLY:  lsm_init, lsm_init_arrays
[1496]512 
[2320]513    USE lsf_nudging_mod,                                                       &
[2696]514        ONLY:  lsf_init, ls_forcing_surf, nudge_init
[1849]515
516    USE microphysics_mod,                                                      &
517        ONLY:  collision_turbulence, microphysics_init
518
[2338]519    USE model_1d_mod,                                                          &
520        ONLY:  e1d, init_1d_model, kh1d, km1d, l1d, rif1d, u1d, us1d, usws1d,  &
521               v1d, vsws1d 
522
[1783]523    USE netcdf_interface,                                                      &
[2817]524        ONLY:  dots_max, dots_num, dots_unit, dots_label
[2696]525
[2906]526    USE netcdf_data_input_mod,                                                 &
[2696]527        ONLY:  init_3d, netcdf_data_input_interpolate, netcdf_data_input_init_3d
[1320]528   
529    USE particle_attributes,                                                   &
530        ONLY:  particle_advection, use_sgs_for_particles, wang_kernel
531   
[1]532    USE pegrid
[1320]533   
[1484]534    USE plant_canopy_model_mod,                                                &
[2746]535        ONLY:  pcm_init
[1496]536
[2934]537    USE pmc_interface,                                                         &
538        ONLY:  nested_run
539
[1496]540    USE radiation_model_mod,                                                   &
[2977]541        ONLY:  average_radiation,                                              &
[2995]542               radiation_init, radiation, radiation_scheme,                    &
[2906]543               radiation_calc_svf, radiation_write_svf,                        &
[2696]544               radiation_interaction, radiation_interactions,                  &
[2920]545               radiation_interaction_init, radiation_read_svf,                 &
[2977]546               radiation_presimulate_solar_pos, radiation_interactions_on
[1484]547   
[1320]548    USE random_function_mod 
549   
[1400]550    USE random_generator_parallel,                                             &
[2172]551        ONLY:  init_parallel_random_generator
[2894]552
553    USE read_restart_data_mod,                                                 &
554        ONLY:  rrd_read_parts_of_global, rrd_local                                     
[1400]555   
[1320]556    USE statistics,                                                            &
[1738]557        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask,        &
[1833]558               statistic_regions, sums, sums_divnew_l, sums_divold_l, sums_l,  &
[2277]559               sums_l_l, sums_wsts_bc_l, ts_value,                             &
[1833]560               weight_pres, weight_substep
[2259]561
562    USE synthetic_turbulence_generator_mod,                                    &
[2776]563        ONLY:  stg_init, use_syn_turb_gen
[2259]564
[1691]565    USE surface_layer_fluxes_mod,                                              &
566        ONLY:  init_surface_layer_fluxes
[2232]567
568    USE surface_mod,                                                           &
569        ONLY :  init_surface_arrays, init_surfaces, surf_def_h, surf_lsm_h,    &
[2977]570                surf_usm_h, get_topography_top_index_ji, vertical_surfaces_exist
[1691]571   
[2007]572    USE transpose_indices
[1]573
[2696]574    USE turbulence_closure_mod,                                                &
575        ONLY:  tcm_init_arrays, tcm_init
576
[2007]577    USE urban_surface_mod,                                                     &
[2696]578        ONLY:  usm_init_urban_surface, usm_allocate_surface
[2007]579
[2696]580    USE uv_exposure_model_mod,                                                 &
581        ONLY:  uvem_init, uvem_init_arrays
582
[1914]583    USE wind_turbine_model_mod,                                                &
[2564]584        ONLY:  wtm_init, wtm_init_arrays
[1914]585
[1]586    IMPLICIT NONE
587
[1682]588    INTEGER(iwp) ::  i             !<
589    INTEGER(iwp) ::  ind_array(1)  !<
590    INTEGER(iwp) ::  j             !<
591    INTEGER(iwp) ::  k             !<
[2232]592    INTEGER(iwp) ::  k_surf        !< surface level index
593    INTEGER(iwp) ::  m             !< index of surface element in surface data type
594    INTEGER(iwp) ::  sr            !< index of statistic region
[1]595
[1682]596    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !<
[1]597
[1682]598    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !<
599    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !<
[1]600
[2037]601    REAL(wp)     ::  t_surface !< air temperature at the surface
602
603    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic !< hydrostatic pressure
604
605    INTEGER(iwp) ::  l       !< loop variable
606    INTEGER(iwp) ::  nzt_l   !< index of top PE boundary for multigrid level
607    REAL(wp) ::  dx_l !< grid spacing along x on different multigrid level
608    REAL(wp) ::  dy_l !< grid spacing along y on different multigrid level
609
[1764]610    REAL(wp), DIMENSION(1:3) ::  volume_flow_area_l     !<
611    REAL(wp), DIMENSION(1:3) ::  volume_flow_initial_l  !<
[1]612
[1738]613    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l    !<
[1682]614    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l    !<
615    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp  !<
[1]616
[2550]617    INTEGER(iwp) ::  nz_u_shift   !<
618    INTEGER(iwp) ::  nz_v_shift   !<
619    INTEGER(iwp) ::  nz_w_shift   !<
620    INTEGER(iwp) ::  nz_s_shift   !<
621    INTEGER(iwp) ::  nz_u_shift_l !<
622    INTEGER(iwp) ::  nz_v_shift_l !<
623    INTEGER(iwp) ::  nz_w_shift_l !<
624    INTEGER(iwp) ::  nz_s_shift_l !<
[485]625
[1402]626    CALL location_message( 'allocating arrays', .FALSE. )
[1]627!
628!-- Allocate arrays
[1788]629    ALLOCATE( mean_surface_level_height(0:statistic_regions),                  &
630              mean_surface_level_height_l(0:statistic_regions),                &
631              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),    &
632              ngp_3d(0:statistic_regions),                                     &
633              ngp_3d_inner(0:statistic_regions),                               &
634              ngp_3d_inner_l(0:statistic_regions),                             &
635              ngp_3d_inner_tmp(0:statistic_regions),                           &
636              sums_divnew_l(0:statistic_regions),                              &
[1]637              sums_divold_l(0:statistic_regions) )
[1195]638    ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
[1788]639    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                    &
640              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                  &
641              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                  &
642              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                &
643              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                  &
644              sums(nzb:nzt+1,pr_palm+max_pr_user),                             &
645              sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1),      &
646              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),    &
647              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions),                   &
[394]648              ts_value(dots_max,0:statistic_regions) )
[978]649    ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) )
[1]650
[1788]651    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                    &
652              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
[1010]653              tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
654
655#if defined( __nopointer )
[2696]656    ALLOCATE( pt(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                               &
[1788]657              pt_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
658              u(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
659              u_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
660              v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
661              v_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
662              w(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
663              w_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
664              tpt_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
665              tu_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
666              tv_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
[1010]667              tw_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
668#else
[2696]669    ALLOCATE( pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
[1788]670              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
671              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
672              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
673              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
674              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
675              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
676              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
677              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
678              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
[667]679              w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1788]680    IF (  .NOT.  neutral )  THEN
[1032]681       ALLOCATE( pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
682    ENDIF
[1010]683#endif
684
[673]685!
[707]686!-- Following array is required for perturbation pressure within the iterative
687!-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds
688!-- the weighted average of the substeps and cannot be used in the Poisson
689!-- solver.
690    IF ( psolver == 'sor' )  THEN
691       ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1575]692    ELSEIF ( psolver(1:9) == 'multigrid' )  THEN
[707]693!
694!--    For performance reasons, multigrid is using one ghost layer only
695       ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
[673]696    ENDIF
[1]697
[1111]698!
699!-- Array for storing constant coeffficients of the tridiagonal solver
700    IF ( psolver == 'poisfft' )  THEN
[1212]701       ALLOCATE( tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,2) )
[1111]702       ALLOCATE( tric(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) )
703    ENDIF
704
[1960]705    IF ( humidity )  THEN
[1]706!
[1960]707!--    3D-humidity
[1010]708#if defined( __nopointer )
[1788]709       ALLOCATE( q(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
710                 q_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[3011]711                 tq_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
712                 vpt(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]713#else
[1788]714       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
715                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[3011]716                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
717                 vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) 
[1010]718#endif
[1]719
[3011]720       IF ( cloud_physics )  THEN
[1]721!
722!--          Liquid water content
[1010]723#if defined( __nopointer )
[3011]724          ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]725#else
[3011]726          ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]727#endif
[1053]728
729!
[3011]730!--       3D-cloud water content
731          IF ( .NOT. microphysics_morrison )  THEN
[1053]732#if defined( __nopointer )
[3011]733             ALLOCATE( qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]734#else
[3011]735             ALLOCATE( qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]736#endif
[3011]737          ENDIF
[1822]738!
[3011]739!--       Precipitation amount and rate (only needed if output is switched)
740          ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg) )
[2292]741
742!
[3011]743!--       3d-precipitation rate
744          ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]745
[3011]746          IF ( microphysics_morrison )  THEN
[2292]747!
[3011]748!--          3D-cloud drop water content, cloud drop concentration arrays
[2292]749#if defined( __nopointer )
[3011]750             ALLOCATE( nc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
751                       nc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
752                       qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
753                       qc_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
754                       tnc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   & 
755                       tqc_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[2292]756#else
[3011]757             ALLOCATE( nc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
758                       nc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
759                       nc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
760                       qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
761                       qc_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
762                       qc_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[2292]763#endif
[3011]764          ENDIF
[2292]765
[3011]766          IF ( microphysics_seifert )  THEN
[1053]767!
[3011]768!--          3D-rain water content, rain drop concentration arrays
[1115]769#if defined( __nopointer )
[3011]770             ALLOCATE( nr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
771                       nr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
772                       qr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
773                       qr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
774                       tnr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
775                       tqr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]776#else
[3011]777             ALLOCATE( nr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
778                       nr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
779                       nr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
780                       qr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
781                       qr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                    &
782                       qr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]783#endif
[1]784          ENDIF
785
[3011]786       ENDIF
787
788       IF ( cloud_droplets )  THEN
[1]789!
[3011]790!--       Liquid water content, change in liquid water content
[1010]791#if defined( __nopointer )
[3011]792          ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
793                     ql_c(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]794#else
[3011]795          ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
796                     ql_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]797#endif
798!
[3011]799!--       Real volume of particles (with weighting), volume of particles
800          ALLOCATE ( ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                      &
801                     ql_vp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]802       ENDIF
803
[3011]804    ENDIF   
[1960]805   
806    IF ( passive_scalar )  THEN
[1]807
[1960]808!
809!--    3D scalar arrays
810#if defined( __nopointer )
811       ALLOCATE( s(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
812                 s_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
813                 ts_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
814#else
815       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
816                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
817                 s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
818#endif
819    ENDIF
820
[94]821    IF ( ocean )  THEN
[1010]822#if defined( __nopointer )
[1788]823       ALLOCATE( prho(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[2031]824                 rho_ocean(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[1788]825                 sa(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
826                 sa_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[1010]827                 tsa_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
828#else
[1788]829       ALLOCATE( prho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
830                 rho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                         &
831                 sa_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
832                 sa_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[667]833                 sa_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[388]834       prho => prho_1
[2031]835       rho_ocean  => rho_1  ! routines calc_mean_profile and diffusion_e require
[388]836                      ! density to be apointer
[1010]837#endif
[94]838    ENDIF
839
[1]840!
[2037]841!-- Allocation of anelastic and Boussinesq approximation specific arrays
842    ALLOCATE( p_hydrostatic(nzb:nzt+1) )
843    ALLOCATE( rho_air(nzb:nzt+1) )
844    ALLOCATE( rho_air_zw(nzb:nzt+1) )
845    ALLOCATE( drho_air(nzb:nzt+1) )
846    ALLOCATE( drho_air_zw(nzb:nzt+1) )
847
848!
849!-- Density profile calculation for anelastic approximation
[2252]850    t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**( r_d / cp )
[2037]851    IF ( TRIM( approximation ) == 'anelastic' ) THEN
852       DO  k = nzb, nzt+1
853          p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
854                                ( 1 - ( g * zu(k) ) / ( cp * t_surface )       &
855                                )**( cp / r_d )
856          rho_air(k)          = ( p_hydrostatic(k) *                           &
857                                  ( 100000.0_wp / p_hydrostatic(k)             &
858                                  )**( r_d / cp )                              &
859                                ) / ( r_d * pt_init(k) )
860       ENDDO
861       DO  k = nzb, nzt
862          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
863       ENDDO
864       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
865                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
866    ELSE
[2252]867       DO  k = nzb, nzt+1
868          p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
869                                ( 1 - ( g * zu(nzb) ) / ( cp * t_surface )       &
870                                )**( cp / r_d )
871          rho_air(k)          = ( p_hydrostatic(k) *                           &
872                                  ( 100000.0_wp / p_hydrostatic(k)             &
873                                  )**( r_d / cp )                              &
874                                ) / ( r_d * pt_init(nzb) )
875       ENDDO
876       DO  k = nzb, nzt
877          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
878       ENDDO
879       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
880                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
[2037]881    ENDIF
[2696]882!
[2037]883!-- compute the inverse density array in order to avoid expencive divisions
884    drho_air    = 1.0_wp / rho_air
885    drho_air_zw = 1.0_wp / rho_air_zw
886
887!
888!-- Allocation of flux conversion arrays
889    ALLOCATE( heatflux_input_conversion(nzb:nzt+1) )
890    ALLOCATE( waterflux_input_conversion(nzb:nzt+1) )
891    ALLOCATE( momentumflux_input_conversion(nzb:nzt+1) )
892    ALLOCATE( heatflux_output_conversion(nzb:nzt+1) )
893    ALLOCATE( waterflux_output_conversion(nzb:nzt+1) )
894    ALLOCATE( momentumflux_output_conversion(nzb:nzt+1) )
895
896!
897!-- calculate flux conversion factors according to approximation and in-/output mode
898    DO  k = nzb, nzt+1
899
900        IF ( TRIM( flux_input_mode ) == 'kinematic' )  THEN
901            heatflux_input_conversion(k)      = rho_air_zw(k)
902            waterflux_input_conversion(k)     = rho_air_zw(k)
903            momentumflux_input_conversion(k)  = rho_air_zw(k)
904        ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN
905            heatflux_input_conversion(k)      = 1.0_wp / cp
906            waterflux_input_conversion(k)     = 1.0_wp / l_v
907            momentumflux_input_conversion(k)  = 1.0_wp
908        ENDIF
909
910        IF ( TRIM( flux_output_mode ) == 'kinematic' )  THEN
911            heatflux_output_conversion(k)     = drho_air_zw(k)
912            waterflux_output_conversion(k)    = drho_air_zw(k)
913            momentumflux_output_conversion(k) = drho_air_zw(k)
914        ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN
915            heatflux_output_conversion(k)     = cp
916            waterflux_output_conversion(k)    = l_v
917            momentumflux_output_conversion(k) = 1.0_wp
918        ENDIF
919
920        IF ( .NOT. humidity ) THEN
921            waterflux_input_conversion(k)  = 1.0_wp
922            waterflux_output_conversion(k) = 1.0_wp
923        ENDIF
924
925    ENDDO
926
927!
928!-- In case of multigrid method, compute grid lengths and grid factors for the
929!-- grid levels with respective density on each grid
930    IF ( psolver(1:9) == 'multigrid' )  THEN
931
932       ALLOCATE( ddx2_mg(maximum_grid_level) )
933       ALLOCATE( ddy2_mg(maximum_grid_level) )
934       ALLOCATE( dzu_mg(nzb+1:nzt+1,maximum_grid_level) )
935       ALLOCATE( dzw_mg(nzb+1:nzt+1,maximum_grid_level) )
936       ALLOCATE( f1_mg(nzb+1:nzt,maximum_grid_level) )
937       ALLOCATE( f2_mg(nzb+1:nzt,maximum_grid_level) )
938       ALLOCATE( f3_mg(nzb+1:nzt,maximum_grid_level) )
939       ALLOCATE( rho_air_mg(nzb:nzt+1,maximum_grid_level) )
940       ALLOCATE( rho_air_zw_mg(nzb:nzt+1,maximum_grid_level) )
941
942       dzu_mg(:,maximum_grid_level) = dzu
943       rho_air_mg(:,maximum_grid_level) = rho_air
944!       
945!--    Next line to ensure an equally spaced grid.
946       dzu_mg(1,maximum_grid_level) = dzu(2)
947       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) +                     &
948                                             (rho_air(nzb) - rho_air(nzb+1))
949
950       dzw_mg(:,maximum_grid_level) = dzw
951       rho_air_zw_mg(:,maximum_grid_level) = rho_air_zw
952       nzt_l = nzt
953       DO  l = maximum_grid_level-1, 1, -1
954           dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1)
955           dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1)
956           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1) + (rho_air_mg(nzb,l+1) - rho_air_mg(nzb+1,l+1))
957           rho_air_zw_mg(nzb,l) = rho_air_zw_mg(nzb,l+1) + (rho_air_zw_mg(nzb,l+1) - rho_air_zw_mg(nzb+1,l+1))
958           rho_air_mg(nzb+1,l)    = rho_air_mg(nzb+1,l+1)
959           rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1)
960           nzt_l = nzt_l / 2
961           DO  k = 2, nzt_l+1
962              dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1)
963              dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1)
964              rho_air_mg(k,l)    = rho_air_mg(2*k-1,l+1)
965              rho_air_zw_mg(k,l) = rho_air_zw_mg(2*k-1,l+1)
966           ENDDO
967       ENDDO
968
969       nzt_l = nzt
970       dx_l  = dx
971       dy_l  = dy
972       DO  l = maximum_grid_level, 1, -1
973          ddx2_mg(l) = 1.0_wp / dx_l**2
974          ddy2_mg(l) = 1.0_wp / dy_l**2
975          DO  k = nzb+1, nzt_l
976             f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) )
977             f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l)   * dzw_mg(k,l) )
978             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) ) &
979                          * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l)
980          ENDDO
981          nzt_l = nzt_l / 2
982          dx_l  = dx_l * 2.0_wp
983          dy_l  = dy_l * 2.0_wp
984       ENDDO
985
986    ENDIF
987
988!
[1299]989!-- 1D-array for large scale subsidence velocity
[1361]990    IF ( .NOT. ALLOCATED( w_subs ) )  THEN
991       ALLOCATE ( w_subs(nzb:nzt+1) )
992       w_subs = 0.0_wp
993    ENDIF
[1299]994
995!
[106]996!-- Arrays to store velocity data from t-dt and the phase speeds which
997!-- are needed for radiation boundary conditions
[73]998    IF ( outflow_l )  THEN
[1788]999       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2),                               &
1000                 v_m_l(nzb:nzt+1,nysg:nyng,0:1),                               &
[667]1001                 w_m_l(nzb:nzt+1,nysg:nyng,0:1) )
[73]1002    ENDIF
1003    IF ( outflow_r )  THEN
[1788]1004       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
1005                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
[667]1006                 w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) )
[73]1007    ENDIF
[106]1008    IF ( outflow_l  .OR.  outflow_r )  THEN
[1788]1009       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng),           &
[667]1010                 c_w(nzb:nzt+1,nysg:nyng) )
[106]1011    ENDIF
[73]1012    IF ( outflow_s )  THEN
[1788]1013       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg),                               &
1014                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg),                               &
[667]1015                 w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) )
[73]1016    ENDIF
1017    IF ( outflow_n )  THEN
[1788]1018       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
1019                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
[667]1020                 w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) )
[73]1021    ENDIF
[106]1022    IF ( outflow_s  .OR.  outflow_n )  THEN
[1788]1023       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg),           &
[667]1024                 c_w(nzb:nzt+1,nxlg:nxrg) )
[106]1025    ENDIF
[996]1026    IF ( outflow_l  .OR.  outflow_r  .OR.  outflow_s  .OR.  outflow_n )  THEN
[978]1027       ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) )                   
1028       ALLOCATE( c_u_m(nzb:nzt+1), c_v_m(nzb:nzt+1), c_w_m(nzb:nzt+1) )
1029    ENDIF
[73]1030
[978]1031
[1010]1032#if ! defined( __nopointer )
[73]1033!
[1]1034!-- Initial assignment of the pointers
[1032]1035    IF ( .NOT. neutral )  THEN
1036       pt => pt_1;  pt_p => pt_2;  tpt_m => pt_3
1037    ELSE
1038       pt => pt_1;  pt_p => pt_1;  tpt_m => pt_3
1039    ENDIF
[1001]1040    u  => u_1;   u_p  => u_2;   tu_m  => u_3
1041    v  => v_1;   v_p  => v_2;   tv_m  => v_3
1042    w  => w_1;   w_p  => w_2;   tw_m  => w_3
[1]1043
[1960]1044    IF ( humidity )  THEN
[1001]1045       q => q_1;  q_p => q_2;  tq_m => q_3
[1053]1046       IF ( humidity )  THEN
1047          vpt  => vpt_1   
1048          IF ( cloud_physics )  THEN
1049             ql => ql_1
[2292]1050             IF ( .NOT. microphysics_morrison )  THEN
1051                qc => qc_1
1052             ENDIF
1053             IF ( microphysics_morrison )  THEN
1054                qc => qc_1;  qc_p  => qc_2;  tqc_m  => qc_3
1055                nc => nc_1;  nc_p  => nc_2;  tnc_m  => nc_3
1056             ENDIF
[1822]1057             IF ( microphysics_seifert )  THEN
1058                qr => qr_1;  qr_p  => qr_2;  tqr_m  => qr_3
1059                nr => nr_1;  nr_p  => nr_2;  tnr_m  => nr_3
[1053]1060             ENDIF
1061          ENDIF
1062       ENDIF
[1001]1063       IF ( cloud_droplets )  THEN
1064          ql   => ql_1
1065          ql_c => ql_2
[1]1066       ENDIF
[1001]1067    ENDIF
[1960]1068   
1069    IF ( passive_scalar )  THEN
1070       s => s_1;  s_p => s_2;  ts_m => s_3
1071    ENDIF   
[1]1072
[1001]1073    IF ( ocean )  THEN
1074       sa => sa_1;  sa_p => sa_2;  tsa_m => sa_3
1075    ENDIF
[1010]1076#endif
[1]1077!
[2696]1078!-- Initialize arrays for turbulence closure
1079    CALL tcm_init_arrays
1080!
1081!-- Initialize surface arrays
[2232]1082    CALL init_surface_arrays
1083!
[1551]1084!-- Allocate land surface model arrays
1085    IF ( land_surface )  THEN
[1817]1086       CALL lsm_init_arrays
[1551]1087    ENDIF
1088
1089!
[1914]1090!-- Allocate wind turbine model arrays
1091    IF ( wind_turbine )  THEN
1092       CALL wtm_init_arrays
1093    ENDIF
[1957]1094!
[2817]1095!-- Allocate gust module arrays
1096    IF ( gust_module_enabled )  THEN
1097       CALL gust_init_arrays
1098    ENDIF
1099
1100!
[1957]1101!-- Initialize virtual flight measurements
1102    IF ( virtual_flight )  THEN
1103       CALL flight_init
1104    ENDIF
[1914]1105
1106!
[2696]1107!-- Read uv exposure input data
1108    IF ( uv_exposure )  THEN
1109       CALL uvem_init
[2320]1110    ENDIF
1111!
[2696]1112!-- Allocate uv exposure arrays
1113    IF ( uv_exposure )  THEN
1114       CALL uvem_init_arrays
[2320]1115    ENDIF
1116
1117!
[2705]1118!-- Initialize nudging if required
1119    IF ( nudging )  THEN
1120       CALL nudge_init
1121    ENDIF
1122
1123!
1124!-- Initialize reading of large scale forcing from external file - if required
1125    IF ( large_scale_forcing  .OR.  forcing )  THEN
1126       CALL lsf_init
1127    ENDIF
1128
1129!
[709]1130!-- Allocate arrays containing the RK coefficient for calculation of
1131!-- perturbation pressure and turbulent fluxes. At this point values are
1132!-- set for pressure calculation during initialization (where no timestep
1133!-- is done). Further below the values needed within the timestep scheme
1134!-- will be set.
[1788]1135    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),               &
[1878]1136              weight_pres(1:intermediate_timestep_count_max) )
[1340]1137    weight_substep = 1.0_wp
1138    weight_pres    = 1.0_wp
[1918]1139    intermediate_timestep_count = 0  ! needed when simulated_time = 0.0
[673]1140       
[1402]1141    CALL location_message( 'finished', .TRUE. )
[1918]1142
[673]1143!
[3014]1144!-- Initialize time series
1145    ts_value = 0.0_wp
1146
1147!
[1918]1148!-- Initialize local summation arrays for routine flow_statistics.
1149!-- This is necessary because they may not yet have been initialized when they
1150!-- are called from flow_statistics (or - depending on the chosen model run -
1151!-- are never initialized)
1152    sums_divnew_l      = 0.0_wp
1153    sums_divold_l      = 0.0_wp
1154    sums_l_l           = 0.0_wp
1155    sums_wsts_bc_l     = 0.0_wp
1156
[2696]1157
1158
[1918]1159!
[1]1160!-- Initialize model variables
[1788]1161    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[328]1162         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[1]1163!
[2696]1164!--    Initialization with provided input data derived from larger-scale model
1165       IF ( INDEX( initializing_actions, 'inifor' ) /= 0 )  THEN
1166          CALL location_message( 'initializing with INIFOR', .FALSE. )
1167!
1168!--       Read initial 1D profiles from NetCDF file if available.
1169!--       At the moment, only u, v, w, pt and q are provided.
1170          CALL netcdf_data_input_init_3d
1171!
1172!--       Please note, at the moment INIFOR assumes only an equidistant vertical
1173!--       grid. In case of vertical grid stretching, input of inital data
1174!--       need to be inter- and/or extrapolated.
1175!--       Therefore, check if zu grid on file is identical to numeric zw grid.
1176!--       Please note 
1177          IF ( ANY( zu(1:nzt+1) /= init_3d%zu_atmos(1:init_3d%nzu) ) )  THEN
[1384]1178
[2696]1179             CALL netcdf_data_input_interpolate( init_3d%u_init(nzb+1:nzt+1),  &
1180                                                 zu(nzb+1:nzt+1),              &
1181                                                 init_3d%zu_atmos )
1182             CALL netcdf_data_input_interpolate( init_3d%v_init(nzb+1:nzt+1),  &
1183                                                 zu(nzb+1:nzt+1),              &
1184                                                 init_3d%zu_atmos )
1185!              CALL netcdf_data_input_interpolate( init_3d%w_init(nzb+1:nzt),    &
1186!                                                  zw(nzb+1:nzt),                &
1187!                                                  init_3d%zw_atmos )
1188             IF ( .NOT. neutral )                                              &
1189                CALL netcdf_data_input_interpolate(                            &
1190                                             init_3d%pt_init(nzb+1:nzt+1),     &
1191                                             zu(nzb+1:nzt+1),                  &
1192                                             init_3d%zu_atmos )
1193             IF ( humidity )                                                   &
1194                CALL netcdf_data_input_interpolate(                            &
1195                                             init_3d%q_init(nzb+1:nzt+1),      &
1196                                             zu(nzb+1:nzt+1),                  &
1197                                             init_3d%zu_atmos )
1198          ENDIF
1199
1200          u_init = init_3d%u_init
1201          v_init = init_3d%v_init   
1202          IF( .NOT. neutral )  pt_init = init_3d%pt_init
1203          IF( humidity      )  q_init  = init_3d%q_init
1204
1205!
1206!--       Please note, Inifor provides data from nzb+1 to nzt+1.
1207!--       Initialize pt and q with Neumann condition at nzb.
1208          IF( .NOT. neutral )  pt_init(nzb) = pt_init(nzb+1)
1209          IF( humidity      )  q_init(nzb)  = q_init(nzb+1)
1210          DO  i = nxlg, nxrg
1211             DO  j = nysg, nyng
1212                u(:,j,i) = u_init(:)
1213                v(:,j,i) = v_init(:)
1214                IF( .NOT. neutral )  pt(:,j,i) = pt_init(:)
1215                IF( humidity      )  q(:,j,i)  = q_init(:)
1216             ENDDO
1217          ENDDO
1218!
1219!--       MS: What about the geostrophic wind profiles? Actually these
1220!--           are not identical to the initial wind profiles in this case.
1221!--           This need to be further revised.
[2938]1222          IF ( init_3d%from_file_ug )  THEN
1223             ug(:) = init_3d%ug_init(:)
1224          ENDIF
1225          IF ( init_3d%from_file_vg )  THEN
1226             vg(:) = init_3d%vg_init(:)
1227          ENDIF
1228
1229          ug(nzt+1) = ug(nzt)
1230          vg(nzt+1) = vg(nzt)
1231
[2696]1232!
1233!--       Set inital w to 0
1234          w = 0.0_wp
1235!
1236!--       Initialize the remaining quantities
1237          IF ( humidity )  THEN
1238             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1239                DO  i = nxlg, nxrg
1240                   DO  j = nysg, nyng
1241                      qc(:,j,i) = 0.0_wp
1242                      nc(:,j,i) = 0.0_wp
1243                   ENDDO
1244                ENDDO
1245             ENDIF
1246
1247             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
1248                DO  i = nxlg, nxrg
1249                   DO  j = nysg, nyng
1250                      qr(:,j,i) = 0.0_wp
1251                      nr(:,j,i) = 0.0_wp
1252                   ENDDO
1253                ENDDO
1254             ENDIF
1255
1256          ENDIF
1257
1258          IF ( passive_scalar )  THEN
1259             DO  i = nxlg, nxrg
1260                DO  j = nysg, nyng
1261                   s(:,j,i) = s_init
1262                ENDDO
1263             ENDDO
1264          ENDIF
1265
1266          IF ( ocean )  THEN
1267             DO  i = nxlg, nxrg
1268                DO  j = nysg, nyng
1269                   sa(:,j,i) = sa_init
1270                ENDDO
1271             ENDDO
1272          ENDIF
1273
1274!
1275!--       Set velocity components at non-atmospheric / oceanic grid points to
1276!--       zero.
1277          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1278          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )
1279          w = MERGE( w, 0.0_wp, BTEST( wall_flags_0, 3 ) )
[2700]1280!
1281!--       Initialize surface variables, e.g. friction velocity, momentum
1282!--       fluxes, etc.
1283          CALL init_surfaces
[2938]1284!
1285!--       Initialize turbulence generator
1286          IF( use_syn_turb_gen )  CALL stg_init
[2696]1287
1288          CALL location_message( 'finished', .TRUE. )
1289!
1290!--    Initialization via computed 1D-model profiles
1291       ELSEIF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
1292
[1402]1293          CALL location_message( 'initializing with 1D model profiles', .FALSE. )
[1]1294!
1295!--       Use solutions of the 1D model as initial profiles,
1296!--       start 1D model
1297          CALL init_1d_model
1298!
1299!--       Transfer initial profiles to the arrays of the 3D model
[667]1300          DO  i = nxlg, nxrg
1301             DO  j = nysg, nyng
[1]1302                pt(:,j,i) = pt_init
1303                u(:,j,i)  = u1d
1304                v(:,j,i)  = v1d
1305             ENDDO
1306          ENDDO
1307
[1960]1308          IF ( humidity )  THEN
[667]1309             DO  i = nxlg, nxrg
1310                DO  j = nysg, nyng
[1]1311                   q(:,j,i) = q_init
1312                ENDDO
1313             ENDDO
[2292]1314             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1315                DO  i = nxlg, nxrg
1316                   DO  j = nysg, nyng
1317                      qc(:,j,i) = 0.0_wp
1318                      nc(:,j,i) = 0.0_wp
1319                   ENDDO
1320                ENDDO
1321             ENDIF
[1822]1322             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]1323                DO  i = nxlg, nxrg
1324                   DO  j = nysg, nyng
[1340]1325                      qr(:,j,i) = 0.0_wp
1326                      nr(:,j,i) = 0.0_wp
[1053]1327                   ENDDO
1328                ENDDO
1329             ENDIF
[1]1330          ENDIF
[2292]1331
[1960]1332          IF ( passive_scalar )  THEN
1333             DO  i = nxlg, nxrg
1334                DO  j = nysg, nyng
1335                   s(:,j,i) = s_init
1336                ENDDO
1337             ENDDO   
1338          ENDIF
[1]1339!
1340!--          Store initial profiles for output purposes etc.
[2696]1341          IF ( .NOT. constant_diffusion )  THEN
[1]1342             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
1343          ENDIF
1344!
[2696]1345!--       Set velocities back to zero
[2758]1346          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1347          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )         
[1]1348!
[2696]1349!--       WARNING: The extra boundary conditions set after running the
1350!--       -------  1D model impose an error on the divergence one layer
1351!--                below the topography; need to correct later
1352!--       ATTENTION: Provisional correction for Piacsek & Williams
1353!--       ---------  advection scheme: keep u and v zero one layer below
1354!--                  the topography.
1355          IF ( ibc_uv_b == 1 )  THEN
[667]1356!
[2696]1357!--          Neumann condition
1358             DO  i = nxl-1, nxr+1
1359                DO  j = nys-1, nyn+1
1360                   u(nzb,j,i) = u(nzb+1,j,i)
1361                   v(nzb,j,i) = v(nzb+1,j,i)
[1]1362                ENDDO
[2696]1363             ENDDO
[1]1364
1365          ENDIF
[2618]1366!
1367!--       Initialize surface variables, e.g. friction velocity, momentum
1368!--       fluxes, etc.
1369          CALL init_surfaces
[1]1370
[1402]1371          CALL location_message( 'finished', .TRUE. )
[1384]1372
[1788]1373       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )    &
[1]1374       THEN
[1241]1375
[1402]1376          CALL location_message( 'initializing with constant profiles', .FALSE. )
[1]1377!
[2259]1378!--       Overwrite initial profiles in case of synthetic turbulence generator
[2938]1379          IF( use_syn_turb_gen )  CALL stg_init
[2259]1380
1381!
[1]1382!--       Use constructed initial profiles (velocity constant with height,
1383!--       temperature profile with constant gradient)
[667]1384          DO  i = nxlg, nxrg
1385             DO  j = nysg, nyng
[1]1386                pt(:,j,i) = pt_init
1387                u(:,j,i)  = u_init
1388                v(:,j,i)  = v_init
1389             ENDDO
1390          ENDDO
1391!
[2758]1392!--       Mask topography
1393          u = MERGE( u, 0.0_wp, BTEST( wall_flags_0, 1 ) )
1394          v = MERGE( v, 0.0_wp, BTEST( wall_flags_0, 2 ) )
1395!
[292]1396!--       Set initial horizontal velocities at the lowest computational grid
1397!--       levels to zero in order to avoid too small time steps caused by the
1398!--       diffusion limit in the initial phase of a run (at k=1, dz/2 occurs
[2758]1399!--       in the limiting formula!).
1400!--       Please note, in case land- or urban-surface model is used and a
1401!--       spinup is applied, masking the lowest computational level is not
1402!--       possible as MOST as well as energy-balance parametrizations will not
1403!--       work with zero wind velocity.
1404          IF ( ibc_uv_b /= 1  .AND.  .NOT.  spinup )  THEN
[1815]1405             DO  i = nxlg, nxrg
1406                DO  j = nysg, nyng
[2232]1407                   DO  k = nzb, nzt
1408                      u(k,j,i) = MERGE( u(k,j,i), 0.0_wp,                      &
1409                                        BTEST( wall_flags_0(k,j,i), 20 ) )
1410                      v(k,j,i) = MERGE( v(k,j,i), 0.0_wp,                      &
1411                                        BTEST( wall_flags_0(k,j,i), 21 ) )
1412                   ENDDO
[1815]1413                ENDDO
1414             ENDDO
1415          ENDIF
[1]1416
[1960]1417          IF ( humidity )  THEN
[667]1418             DO  i = nxlg, nxrg
1419                DO  j = nysg, nyng
[1]1420                   q(:,j,i) = q_init
1421                ENDDO
1422             ENDDO
[2292]1423             IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1424                DO  i = nxlg, nxrg
1425                   DO  j = nysg, nyng
1426                      qc(:,j,i) = 0.0_wp
1427                      nc(:,j,i) = 0.0_wp
1428                   ENDDO
1429                ENDDO
1430             ENDIF
1431
[1822]1432             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
1433                DO  i = nxlg, nxrg
1434                   DO  j = nysg, nyng
1435                      qr(:,j,i) = 0.0_wp
1436                      nr(:,j,i) = 0.0_wp
[1053]1437                   ENDDO
[1822]1438                ENDDO
[2292]1439             ENDIF
[1115]1440
[1]1441          ENDIF
[1960]1442         
1443          IF ( passive_scalar )  THEN
1444             DO  i = nxlg, nxrg
1445                DO  j = nysg, nyng
1446                   s(:,j,i) = s_init
1447                ENDDO
1448             ENDDO
1449          ENDIF
[1]1450
[94]1451          IF ( ocean )  THEN
[667]1452             DO  i = nxlg, nxrg
1453                DO  j = nysg, nyng
[94]1454                   sa(:,j,i) = sa_init
1455                ENDDO
1456             ENDDO
1457          ENDIF
[1920]1458!
[1]1459!--       Compute initial temperature field and other constants used in case
1460!--       of a sloping surface
1461          IF ( sloping_surface )  CALL init_slope
[2618]1462!
1463!--       Initialize surface variables, e.g. friction velocity, momentum
1464!--       fluxes, etc.
1465          CALL init_surfaces
[1]1466
[1402]1467          CALL location_message( 'finished', .TRUE. )
[1384]1468
[1788]1469       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )                  &
[46]1470       THEN
[1384]1471
[1402]1472          CALL location_message( 'initializing by user', .FALSE. )
[46]1473!
[2618]1474!--       Pre-initialize surface variables, i.e. setting start- and end-indices
1475!--       at each (j,i)-location. Please note, this does not supersede
1476!--       user-defined initialization of surface quantities.
1477          CALL init_surfaces
1478!
[46]1479!--       Initialization will completely be done by the user
1480          CALL user_init_3d_model
1481
[1402]1482          CALL location_message( 'finished', .TRUE. )
[1384]1483
[1]1484       ENDIF
[1384]1485
[1402]1486       CALL location_message( 'initializing statistics, boundary conditions, etc.', &
1487                              .FALSE. )
[1384]1488
[667]1489!
1490!--    Bottom boundary
1491       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2  )  THEN
[1340]1492          u(nzb,:,:) = 0.0_wp
1493          v(nzb,:,:) = 0.0_wp
[667]1494       ENDIF
[1]1495
1496!
[151]1497!--    Apply channel flow boundary condition
[132]1498       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
[1340]1499          u(nzt+1,:,:) = 0.0_wp
1500          v(nzt+1,:,:) = 0.0_wp
[132]1501       ENDIF
1502
1503!
[1]1504!--    Calculate virtual potential temperature
[1960]1505       IF ( humidity )  vpt = pt * ( 1.0_wp + 0.61_wp * q )
[1]1506
1507!
[2696]1508!--    Store initial profiles for output purposes etc.. Please note, in case of
1509!--    initialization of u, v, w, pt, and q via output data derived from larger
1510!--    scale models, data will not be horizontally homogeneous. Actually, a mean
1511!--    profile should be calculated before.   
[1]1512       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
1513       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
[667]1514       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2)  THEN
[1340]1515          hom(nzb,1,5,:) = 0.0_wp
1516          hom(nzb,1,6,:) = 0.0_wp
[1]1517       ENDIF
1518       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1519
[2696]1520
1521!
1522!--    Store initial salinity profile
[97]1523       IF ( ocean )  THEN
1524          hom(:,1,26,:)  = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 )
1525       ENDIF
[1]1526
[75]1527       IF ( humidity )  THEN
[1]1528!
1529!--       Store initial profile of total water content, virtual potential
1530!--       temperature
1531          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
1532          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
[2696]1533!
[3040]1534!--       Store initial profile of mixing ratio and potential
[2696]1535!--       temperature
[1]1536          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
1537             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
1538             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1539          ENDIF
1540       ENDIF
1541
[2696]1542!
1543!--    Store initial scalar profile
[1]1544       IF ( passive_scalar )  THEN
[2513]1545          hom(:,1,121,:) = SPREAD(  s(:,nys,nxl), 2, statistic_regions+1 )
[1]1546       ENDIF
1547
1548!
[1400]1549!--    Initialize the random number generators (from numerical recipes)
1550       CALL random_function_ini
[1429]1551       
[1400]1552       IF ( random_generator == 'random-parallel' )  THEN
[2172]1553          CALL init_parallel_random_generator(nx, ny, nys, nyn, nxl, nxr)
[1400]1554       ENDIF
1555!
[1179]1556!--    Set the reference state to be used in the buoyancy terms (for ocean runs
1557!--    the reference state will be set (overwritten) in init_ocean)
1558       IF ( use_single_reference_value )  THEN
[1788]1559          IF (  .NOT.  humidity )  THEN
[1179]1560             ref_state(:) = pt_reference
1561          ELSE
1562             ref_state(:) = vpt_reference
1563          ENDIF
1564       ELSE
[1788]1565          IF (  .NOT.  humidity )  THEN
[1179]1566             ref_state(:) = pt_init(:)
1567          ELSE
1568             ref_state(:) = vpt(:,nys,nxl)
1569          ENDIF
1570       ENDIF
[152]1571
1572!
[707]1573!--    For the moment, vertical velocity is zero
[1340]1574       w = 0.0_wp
[1]1575
1576!
1577!--    Initialize array sums (must be defined in first call of pres)
[1340]1578       sums = 0.0_wp
[1]1579
1580!
[707]1581!--    In case of iterative solvers, p must get an initial value
[1575]1582       IF ( psolver(1:9) == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0_wp
[707]1583
1584!
[72]1585!--    Treating cloud physics, liquid water content and precipitation amount
1586!--    are zero at beginning of the simulation
1587       IF ( cloud_physics )  THEN
[1340]1588          ql = 0.0_wp
[1822]1589          qc = 0.0_wp
1590
1591          precipitation_amount = 0.0_wp
[72]1592       ENDIF
[673]1593!
[1]1594!--    Impose vortex with vertical axis on the initial velocity profile
1595       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
1596          CALL init_rankine
1597       ENDIF
1598
1599!
[3035]1600!--    Impose temperature anomaly (advection test only) or warm air bubble
1601!--    close to surface
1602       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0  .OR.  &
1603            INDEX( initializing_actions, 'initialize_bubble' ) /= 0  )  THEN
[1]1604          CALL init_pt_anomaly
1605       ENDIF
[3035]1606       
[1]1607!
1608!--    If required, change the surface temperature at the start of the 3D run
[1340]1609       IF ( pt_surface_initial_change /= 0.0_wp )  THEN
[1]1610          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
1611       ENDIF
1612
1613!
1614!--    If required, change the surface humidity/scalar at the start of the 3D
1615!--    run
[1960]1616       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )              &
[1]1617          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
[1960]1618         
1619       IF ( passive_scalar .AND.  s_surface_initial_change /= 0.0_wp )         &
1620          s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change
1621       
[1]1622
1623!
1624!--    Initialize old and new time levels.
[2696]1625       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
1626       pt_p = pt; u_p = u; v_p = v; w_p = w
[1]1627
[1960]1628       IF ( humidity  )  THEN
[1340]1629          tq_m = 0.0_wp
[1]1630          q_p = q
[2292]1631          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1632             tqc_m = 0.0_wp
1633             qc_p  = qc
1634             tnc_m = 0.0_wp
1635             nc_p  = nc
1636          ENDIF
[1822]1637          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1638             tqr_m = 0.0_wp
[1822]1639             qr_p  = qr
[1340]1640             tnr_m = 0.0_wp
[1822]1641             nr_p  = nr
[1053]1642          ENDIF
[1]1643       ENDIF
[1960]1644       
1645       IF ( passive_scalar )  THEN
1646          ts_m = 0.0_wp
1647          s_p  = s
1648       ENDIF       
[1]1649
[94]1650       IF ( ocean )  THEN
[1340]1651          tsa_m = 0.0_wp
[94]1652          sa_p  = sa
1653       ENDIF
[667]1654       
[1402]1655       CALL location_message( 'finished', .TRUE. )
[94]1656
[1788]1657    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
[2232]1658             TRIM( initializing_actions ) == 'cyclic_fill' )                   &
[1]1659    THEN
[1384]1660
[1402]1661       CALL location_message( 'initializing in case of restart / cyclic_fill', &
1662                              .FALSE. )
[1]1663!
[2232]1664!--    Initialize surface elements and its attributes, e.g. heat- and
1665!--    momentumfluxes, roughness, scaling parameters. As number of surface
1666!--    elements might be different between runs, e.g. in case of cyclic fill,
1667!--    and not all surface elements are read, surface elements need to be
1668!--    initialized before.     
1669       CALL init_surfaces
1670!
[767]1671!--    When reading data for cyclic fill of 3D prerun data files, read
1672!--    some of the global variables from the restart file which are required
1673!--    for initializing the inflow
[328]1674       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
[559]1675
[759]1676          DO  i = 0, io_blocks-1
1677             IF ( i == io_group )  THEN
[2894]1678                CALL rrd_read_parts_of_global
[759]1679             ENDIF
1680#if defined( __parallel )
1681             CALL MPI_BARRIER( comm2d, ierr )
1682#endif
1683          ENDDO
[328]1684
[767]1685       ENDIF
1686
[151]1687!
[2894]1688!--    Read processor specific binary data from restart file
[767]1689       DO  i = 0, io_blocks-1
1690          IF ( i == io_group )  THEN
[2894]1691             CALL rrd_local
[767]1692          ENDIF
1693#if defined( __parallel )
1694          CALL MPI_BARRIER( comm2d, ierr )
1695#endif
1696       ENDDO
1697
[328]1698!
[2550]1699!--    In case of complex terrain and cyclic fill method as initialization,
1700!--    shift initial data in the vertical direction for each point in the
1701!--    x-y-plane depending on local surface height
1702       IF ( complex_terrain  .AND.                                             &
1703            TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1704          DO  i = nxlg, nxrg
1705             DO  j = nysg, nyng
[2698]1706                nz_u_shift = get_topography_top_index_ji( j, i, 'u' )
1707                nz_v_shift = get_topography_top_index_ji( j, i, 'v' )
1708                nz_w_shift = get_topography_top_index_ji( j, i, 'w' )
1709                nz_s_shift = get_topography_top_index_ji( j, i, 's' )
[2550]1710
1711                u(nz_u_shift:nzt+1,j,i)  = u(0:nzt+1-nz_u_shift,j,i)               
1712
1713                v(nz_v_shift:nzt+1,j,i)  = v(0:nzt+1-nz_v_shift,j,i)
1714
1715                w(nz_w_shift:nzt+1,j,i)  = w(0:nzt+1-nz_w_shift,j,i)
1716
1717                p(nz_s_shift:nzt+1,j,i)  =  p(0:nzt+1-nz_s_shift,j,i)
1718                pt(nz_s_shift:nzt+1,j,i) = pt(0:nzt+1-nz_s_shift,j,i)
1719             ENDDO
1720          ENDDO
1721       ENDIF
1722
1723!
[767]1724!--    Initialization of the turbulence recycling method
[1788]1725       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.               &
[767]1726            turbulent_inflow )  THEN
1727!
1728!--       First store the profiles to be used at the inflow.
1729!--       These profiles are the (temporally) and horizontally averaged vertical
1730!--       profiles from the prerun. Alternatively, prescribed profiles
1731!--       for u,v-components can be used.
[1960]1732          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,7) )
[151]1733
[767]1734          IF ( use_prescribed_profile_data )  THEN
1735             mean_inflow_profiles(:,1) = u_init            ! u
1736             mean_inflow_profiles(:,2) = v_init            ! v
1737          ELSE
[328]1738             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
1739             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
[767]1740          ENDIF
1741          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
[1960]1742          IF ( humidity )                                                      &
1743             mean_inflow_profiles(:,6) = hom_sum(:,41,0)   ! q
1744          IF ( passive_scalar )                                                &
1745             mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
[2550]1746!
1747!--       In case of complex terrain, determine vertical displacement at inflow
1748!--       boundary and adjust mean inflow profiles
1749          IF ( complex_terrain )  THEN
1750             IF ( nxlg <= 0 .AND. nxrg >= 0 .AND. nysg <= 0 .AND. nyng >= 0 )  THEN
[2698]1751                nz_u_shift_l = get_topography_top_index_ji( 0, 0, 'u' )
1752                nz_v_shift_l = get_topography_top_index_ji( 0, 0, 'v' )
1753                nz_w_shift_l = get_topography_top_index_ji( 0, 0, 'w' )
1754                nz_s_shift_l = get_topography_top_index_ji( 0, 0, 's' )
[2550]1755             ELSE
1756                nz_u_shift_l = 0
1757                nz_v_shift_l = 0
1758                nz_w_shift_l = 0
1759                nz_s_shift_l = 0
1760             ENDIF
[151]1761
[2550]1762#if defined( __parallel )
1763             CALL MPI_ALLREDUCE(nz_u_shift_l, nz_u_shift, 1, MPI_INTEGER,      &
1764                                MPI_MAX, comm2d, ierr)
1765             CALL MPI_ALLREDUCE(nz_v_shift_l, nz_v_shift, 1, MPI_INTEGER,      &
1766                                MPI_MAX, comm2d, ierr)
1767             CALL MPI_ALLREDUCE(nz_w_shift_l, nz_w_shift, 1, MPI_INTEGER,      & 
1768                                MPI_MAX, comm2d, ierr)
1769             CALL MPI_ALLREDUCE(nz_s_shift_l, nz_s_shift, 1, MPI_INTEGER,      &
1770                                MPI_MAX, comm2d, ierr)
1771#else
1772             nz_u_shift = nz_u_shift_l
1773             nz_v_shift = nz_v_shift_l
1774             nz_w_shift = nz_w_shift_l
1775             nz_s_shift = nz_s_shift_l
1776#endif
1777
1778             mean_inflow_profiles(:,1) = 0.0_wp
1779             mean_inflow_profiles(nz_u_shift:nzt+1,1) = hom_sum(0:nzt+1-nz_u_shift,1,0)  ! u
1780
1781             mean_inflow_profiles(:,2) = 0.0_wp
1782             mean_inflow_profiles(nz_v_shift:nzt+1,2) = hom_sum(0:nzt+1-nz_v_shift,2,0)  ! v
1783
1784             mean_inflow_profiles(nz_s_shift:nzt+1,4) = hom_sum(0:nzt+1-nz_s_shift,4,0)  ! pt
1785
1786          ENDIF
1787
[151]1788!
[767]1789!--       If necessary, adjust the horizontal flow field to the prescribed
1790!--       profiles
1791          IF ( use_prescribed_profile_data )  THEN
1792             DO  i = nxlg, nxrg
[667]1793                DO  j = nysg, nyng
[328]1794                   DO  k = nzb, nzt+1
[767]1795                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
1796                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
[328]1797                   ENDDO
[151]1798                ENDDO
[767]1799             ENDDO
1800          ENDIF
[151]1801
1802!
[767]1803!--       Use these mean profiles at the inflow (provided that Dirichlet
1804!--       conditions are used)
1805          IF ( inflow_l )  THEN
1806             DO  j = nysg, nyng
1807                DO  k = nzb, nzt+1
1808                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
1809                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
[1340]1810                   w(k,j,nxlg:-1)  = 0.0_wp
[767]1811                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
[1960]1812                   IF ( humidity )                                             &
[1615]1813                      q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
[1960]1814                   IF ( passive_scalar )                                       &
1815                      s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)                     
[767]1816                ENDDO
1817             ENDDO
1818          ENDIF
1819
[151]1820!
[767]1821!--       Calculate the damping factors to be used at the inflow. For a
1822!--       turbulent inflow the turbulent fluctuations have to be limited
1823!--       vertically because otherwise the turbulent inflow layer will grow
1824!--       in time.
[1340]1825          IF ( inflow_damping_height == 9999999.9_wp )  THEN
[767]1826!
1827!--          Default: use the inversion height calculated by the prerun; if
1828!--          this is zero, inflow_damping_height must be explicitly
1829!--          specified.
[1340]1830             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp )  THEN
[767]1831                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
1832             ELSE
[1788]1833                WRITE( message_string, * ) 'inflow_damping_height must be ',   &
1834                     'explicitly specified because&the inversion height ',     &
[767]1835                     'calculated by the prerun is zero.'
1836                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
[292]1837             ENDIF
[151]1838
[767]1839          ENDIF
1840
[1340]1841          IF ( inflow_damping_width == 9999999.9_wp )  THEN
[151]1842!
[767]1843!--          Default for the transition range: one tenth of the undamped
1844!--          layer
[1340]1845             inflow_damping_width = 0.1_wp * inflow_damping_height
[151]1846
[767]1847          ENDIF
[151]1848
[767]1849          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
[151]1850
[767]1851          DO  k = nzb, nzt+1
[151]1852
[767]1853             IF ( zu(k) <= inflow_damping_height )  THEN
[1340]1854                inflow_damping_factor(k) = 1.0_wp
[996]1855             ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) )  THEN
[1340]1856                inflow_damping_factor(k) = 1.0_wp -                            &
[996]1857                                           ( zu(k) - inflow_damping_height ) / &
1858                                           inflow_damping_width
[767]1859             ELSE
[1340]1860                inflow_damping_factor(k) = 0.0_wp
[767]1861             ENDIF
[151]1862
[767]1863          ENDDO
[151]1864
[147]1865       ENDIF
1866
[152]1867!
[2696]1868!--    Inside buildings set velocities back to zero
[1788]1869       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.                &
[359]1870            topography /= 'flat' )  THEN
1871!
[2696]1872!--       Inside buildings set velocities back to zero.
1873!--       Other scalars (pt, q, s, p, sa, ...) are ignored at present,
[359]1874!--       maybe revise later.
[1001]1875          DO  i = nxlg, nxrg
1876             DO  j = nysg, nyng
[2232]1877                DO  k = nzb, nzt
1878                   u(k,j,i)     = MERGE( u(k,j,i), 0.0_wp,                     &
1879                                         BTEST( wall_flags_0(k,j,i), 1 ) )
1880                   v(k,j,i)     = MERGE( v(k,j,i), 0.0_wp,                     &
1881                                         BTEST( wall_flags_0(k,j,i), 2 ) )
1882                   w(k,j,i)     = MERGE( w(k,j,i), 0.0_wp,                     &
1883                                         BTEST( wall_flags_0(k,j,i), 3 ) )
1884                ENDDO
[359]1885             ENDDO
[1001]1886          ENDDO
[359]1887
1888       ENDIF
1889
1890!
[1]1891!--    Calculate initial temperature field and other constants used in case
1892!--    of a sloping surface
1893       IF ( sloping_surface )  CALL init_slope
1894
1895!
1896!--    Initialize new time levels (only done in order to set boundary values
1897!--    including ghost points)
[2696]1898       pt_p = pt; u_p = u; v_p = v; w_p = w
[1960]1899       IF ( humidity )  THEN
[1053]1900          q_p = q
[2292]1901          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1902             qc_p = qc
1903             nc_p = nc
1904          ENDIF
[1822]1905          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]1906             qr_p = qr
1907             nr_p = nr
1908          ENDIF
1909       ENDIF
[1960]1910       IF ( passive_scalar )  s_p  = s
1911       IF ( ocean          )  sa_p = sa
[1]1912
[181]1913!
1914!--    Allthough tendency arrays are set in prognostic_equations, they have
1915!--    have to be predefined here because they are used (but multiplied with 0)
1916!--    there before they are set.
[2696]1917       tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
[1960]1918       IF ( humidity )  THEN
[1340]1919          tq_m = 0.0_wp
[2292]1920          IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
1921             tqc_m = 0.0_wp
1922             tnc_m = 0.0_wp
1923          ENDIF
[1822]1924          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1925             tqr_m = 0.0_wp
1926             tnr_m = 0.0_wp
[1053]1927          ENDIF
1928       ENDIF
[1960]1929       IF ( passive_scalar )  ts_m  = 0.0_wp
1930       IF ( ocean          )  tsa_m = 0.0_wp
[2259]1931!
1932!--    Initialize synthetic turbulence generator in case of restart.
1933       IF ( TRIM( initializing_actions ) == 'read_restart_data'  .AND.         &
[2776]1934            use_syn_turb_gen )  CALL stg_init
[181]1935
[1402]1936       CALL location_message( 'finished', .TRUE. )
[1384]1937
[1]1938    ELSE
1939!
1940!--    Actually this part of the programm should not be reached
[254]1941       message_string = 'unknown initializing problem'
1942       CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 )
[1]1943    ENDIF
1944
[2696]1945!
1946!-- Initialize TKE, Kh and Km
1947    CALL tcm_init
[151]1948
[2696]1949
[151]1950    IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
[1]1951!
[151]1952!--    Initialize old timelevels needed for radiation boundary conditions
1953       IF ( outflow_l )  THEN
1954          u_m_l(:,:,:) = u(:,:,1:2)
1955          v_m_l(:,:,:) = v(:,:,0:1)
1956          w_m_l(:,:,:) = w(:,:,0:1)
1957       ENDIF
1958       IF ( outflow_r )  THEN
1959          u_m_r(:,:,:) = u(:,:,nx-1:nx)
1960          v_m_r(:,:,:) = v(:,:,nx-1:nx)
1961          w_m_r(:,:,:) = w(:,:,nx-1:nx)
1962       ENDIF
1963       IF ( outflow_s )  THEN
1964          u_m_s(:,:,:) = u(:,0:1,:)
1965          v_m_s(:,:,:) = v(:,1:2,:)
1966          w_m_s(:,:,:) = w(:,0:1,:)
1967       ENDIF
1968       IF ( outflow_n )  THEN
1969          u_m_n(:,:,:) = u(:,ny-1:ny,:)
1970          v_m_n(:,:,:) = v(:,ny-1:ny,:)
1971          w_m_n(:,:,:) = w(:,ny-1:ny,:)
1972       ENDIF
[667]1973       
[151]1974    ENDIF
[680]1975
[667]1976!
1977!-- Calculate the initial volume flow at the right and north boundary
[709]1978    IF ( conserve_volume_flow )  THEN
[151]1979
[767]1980       IF ( use_prescribed_profile_data )  THEN
[667]1981
[1340]1982          volume_flow_initial_l = 0.0_wp
1983          volume_flow_area_l    = 0.0_wp
[732]1984
[667]1985          IF ( nxr == nx )  THEN
1986             DO  j = nys, nyn
[2232]1987                DO  k = nzb+1, nzt
[1788]1988                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[2232]1989                                              u_init(k) * dzw(k)               &
1990                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1991                                              BTEST( wall_flags_0(k,j,nxr), 1 )&
1992                                            )
1993
1994                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
1995                                     * MERGE( 1.0_wp, 0.0_wp,                  &
1996                                              BTEST( wall_flags_0(k,j,nxr), 1 )&
1997                                            )
[767]1998                ENDDO
1999             ENDDO
2000          ENDIF
2001         
2002          IF ( nyn == ny )  THEN
2003             DO  i = nxl, nxr
[2232]2004                DO  k = nzb+1, nzt
2005                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
2006                                              v_init(k) * dzw(k)               &       
2007                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2008                                              BTEST( wall_flags_0(k,nyn,i), 2 )&
2009                                            )
2010                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
2011                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2012                                              BTEST( wall_flags_0(k,nyn,i), 2 )&
2013                                            )
[767]2014                ENDDO
2015             ENDDO
2016          ENDIF
2017
2018#if defined( __parallel )
2019          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
2020                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2021          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
2022                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2023
2024#else
2025          volume_flow_initial = volume_flow_initial_l
2026          volume_flow_area    = volume_flow_area_l
2027#endif 
2028
2029       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
2030
[1340]2031          volume_flow_initial_l = 0.0_wp
2032          volume_flow_area_l    = 0.0_wp
[767]2033
2034          IF ( nxr == nx )  THEN
2035             DO  j = nys, nyn
[2232]2036                DO  k = nzb+1, nzt
[1788]2037                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[2232]2038                                              hom_sum(k,1,0) * dzw(k)          &
2039                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2040                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2041                                            )
2042                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
2043                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2044                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2045                                            )
[667]2046                ENDDO
2047             ENDDO
2048          ENDIF
2049         
2050          IF ( nyn == ny )  THEN
2051             DO  i = nxl, nxr
[2232]2052                DO  k = nzb+1, nzt
[1788]2053                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[2232]2054                                              hom_sum(k,2,0) * dzw(k)          &       
2055                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2056                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2057                                            )
2058                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
2059                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2060                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2061                                            )
[667]2062                ENDDO
2063             ENDDO
2064          ENDIF
2065
[732]2066#if defined( __parallel )
2067          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
2068                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2069          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
2070                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2071
2072#else
2073          volume_flow_initial = volume_flow_initial_l
2074          volume_flow_area    = volume_flow_area_l
2075#endif 
2076
[667]2077       ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
2078
[1340]2079          volume_flow_initial_l = 0.0_wp
2080          volume_flow_area_l    = 0.0_wp
[732]2081
[667]2082          IF ( nxr == nx )  THEN
2083             DO  j = nys, nyn
[2232]2084                DO  k = nzb+1, nzt
2085                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
2086                                              u(k,j,nx) * dzw(k)               &
2087                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2088                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2089                                            )
2090                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)   &
2091                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2092                                              BTEST( wall_flags_0(k,j,nx), 1 ) &
2093                                            )
[667]2094                ENDDO
2095             ENDDO
2096          ENDIF
2097         
2098          IF ( nyn == ny )  THEN
2099             DO  i = nxl, nxr
[2232]2100                DO  k = nzb+1, nzt
[1788]2101                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[2232]2102                                              v(k,ny,i) * dzw(k)               &       
2103                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2104                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2105                                            )
2106                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)   &       
2107                                     * MERGE( 1.0_wp, 0.0_wp,                  &
2108                                              BTEST( wall_flags_0(k,ny,i), 2 ) &
2109                                            )
[667]2110                ENDDO
2111             ENDDO
2112          ENDIF
2113
2114#if defined( __parallel )
[732]2115          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
2116                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
2117          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
2118                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
[667]2119
2120#else
[732]2121          volume_flow_initial = volume_flow_initial_l
2122          volume_flow_area    = volume_flow_area_l
[667]2123#endif 
2124
[732]2125       ENDIF
2126
[151]2127!
[709]2128!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated
2129!--    from u|v_bulk instead
[680]2130       IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
2131          volume_flow_initial(1) = u_bulk * volume_flow_area(1)
2132          volume_flow_initial(2) = v_bulk * volume_flow_area(2)
2133       ENDIF
[667]2134
[680]2135    ENDIF
[2232]2136!
[2618]2137!-- Finally, if random_heatflux is set, disturb shf at horizontal
2138!-- surfaces. Actually, this should be done in surface_mod, where all other
2139!-- initializations of surface quantities are done. However, this
2140!-- would create a ring dependency, hence, it is done here. Maybe delete
2141!-- disturb_heatflux and tranfer the respective code directly into the
2142!-- initialization in surface_mod.         
[2232]2143    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
2144         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[2618]2145 
[2232]2146       IF ( use_surface_fluxes  .AND.  constant_heatflux  .AND.                &
2147            random_heatflux )  THEN
2148          IF ( surf_def_h(0)%ns >= 1 )  CALL disturb_heatflux( surf_def_h(0) )
2149          IF ( surf_lsm_h%ns    >= 1 )  CALL disturb_heatflux( surf_lsm_h    )
2150          IF ( surf_usm_h%ns    >= 1 )  CALL disturb_heatflux( surf_usm_h    )
2151       ENDIF
2152    ENDIF
[680]2153
[787]2154!
[2696]2155!-- Before initializing further modules, compute total sum of active mask
2156!-- grid points and the mean surface level height for each statistic region.
2157!-- ngp_2dh: number of grid points of a horizontal cross section through the
2158!--          total domain
2159!-- ngp_3d:  number of grid points of the total domain
2160    ngp_2dh_outer_l   = 0
2161    ngp_2dh_outer     = 0
2162    ngp_2dh_s_inner_l = 0
2163    ngp_2dh_s_inner   = 0
2164    ngp_2dh_l         = 0
2165    ngp_2dh           = 0
2166    ngp_3d_inner_l    = 0.0_wp
2167    ngp_3d_inner      = 0
2168    ngp_3d            = 0
2169    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
2170
2171    mean_surface_level_height   = 0.0_wp
2172    mean_surface_level_height_l = 0.0_wp
2173!
2174!-- Pre-set masks for regional statistics. Default is the total model domain.
2175!-- Ghost points are excluded because counting values at the ghost boundaries
2176!-- would bias the statistics
2177    rmask = 1.0_wp
2178    rmask(:,nxlg:nxl-1,:) = 0.0_wp;  rmask(:,nxr+1:nxrg,:) = 0.0_wp
2179    rmask(nysg:nys-1,:,:) = 0.0_wp;  rmask(nyn+1:nyng,:,:) = 0.0_wp
2180!
[2867]2181!-- User-defined initializing actions
2182    CALL user_init
2183!
[2696]2184!-- To do: New concept for these non-topography grid points!
2185    DO  sr = 0, statistic_regions
2186       DO  i = nxl, nxr
2187          DO  j = nys, nyn
2188             IF ( rmask(j,i,sr) == 1.0_wp )  THEN
2189!
2190!--             All xy-grid points
2191                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
2192!
2193!--             Determine mean surface-level height. In case of downward-
2194!--             facing walls are present, more than one surface level exist.
2195!--             In this case, use the lowest surface-level height.
2196                IF ( surf_def_h(0)%start_index(j,i) <=                         &
2197                     surf_def_h(0)%end_index(j,i) )  THEN
2198                   m = surf_def_h(0)%start_index(j,i)
2199                   k = surf_def_h(0)%k(m)
2200                   mean_surface_level_height_l(sr) =                           &
2201                                       mean_surface_level_height_l(sr) + zw(k-1)
2202                ENDIF
2203                IF ( surf_lsm_h%start_index(j,i) <=                            &
2204                     surf_lsm_h%end_index(j,i) )  THEN
2205                   m = surf_lsm_h%start_index(j,i)
2206                   k = surf_lsm_h%k(m)
2207                   mean_surface_level_height_l(sr) =                           &
2208                                       mean_surface_level_height_l(sr) + zw(k-1)
2209                ENDIF
2210                IF ( surf_usm_h%start_index(j,i) <=                            &
2211                     surf_usm_h%end_index(j,i) )  THEN
2212                   m = surf_usm_h%start_index(j,i)
2213                   k = surf_usm_h%k(m)
2214                   mean_surface_level_height_l(sr) =                           &
2215                                       mean_surface_level_height_l(sr) + zw(k-1)
2216                ENDIF
2217
2218                k_surf = k - 1
2219
2220                DO  k = nzb, nzt+1
2221!
2222!--                xy-grid points above topography
2223                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr)     +         &
2224                                  MERGE( 1, 0, BTEST( wall_flags_0(k,j,i), 24 ) )
2225
2226                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) +         &
2227                                  MERGE( 1, 0, BTEST( wall_flags_0(k,j,i), 22 ) )
2228
2229                ENDDO
2230!
2231!--             All grid points of the total domain above topography
2232                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + ( nz - k_surf + 2 )
2233
2234
2235
2236             ENDIF
2237          ENDDO
2238       ENDDO
2239    ENDDO
[2864]2240!
2241!-- Initialize arrays encompassing number of grid-points in inner and outer
2242!-- domains, statistic regions, etc. Mainly used for horizontal averaging
2243!-- of turbulence statistics. Please note, user_init must be called before
2244!-- doing this.   
[2696]2245    sr = statistic_regions + 1
2246#if defined( __parallel )
2247    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2248    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,    &
2249                        comm2d, ierr )
2250    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2251    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr,   &
2252                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
2253    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2254    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),          &
2255                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
2256    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2257    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL,  &
2258                        MPI_SUM, comm2d, ierr )
2259    ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
2260    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
2261    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0),                        &
2262                        mean_surface_level_height(0), sr, MPI_REAL,            &
2263                        MPI_SUM, comm2d, ierr )
2264    mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh )
2265#else
2266    ngp_2dh         = ngp_2dh_l
2267    ngp_2dh_outer   = ngp_2dh_outer_l
2268    ngp_2dh_s_inner = ngp_2dh_s_inner_l
2269    ngp_3d_inner    = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) )
2270    mean_surface_level_height = mean_surface_level_height_l / REAL( ngp_2dh_l )
2271#endif
2272
2273    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * &
2274             INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
2275
2276!
2277!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
2278!-- buoyancy, etc. A zero value will occur for cases where all grid points of
2279!-- the respective subdomain lie below the surface topography
2280    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   ) 
2281    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )),             &
2282                           ngp_3d_inner(:) )
2283    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) 
2284
2285    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l,       &
2286                ngp_3d_inner_l, ngp_3d_inner_tmp )
2287
2288!
[2232]2289!-- Initialize surface forcing corresponding to large-scale forcing. Therein,
2290!-- initialize heat-fluxes, etc. via datatype. Revise it later!
2291    IF ( large_scale_forcing .AND. lsf_surf )  THEN
2292       IF ( use_surface_fluxes  .AND.  constant_heatflux )  THEN
2293          CALL ls_forcing_surf ( simulated_time )
2294       ENDIF
2295    ENDIF
2296!
[787]2297!-- Initialize quantities for special advections schemes
2298    CALL init_advec
[680]2299
[667]2300!
[680]2301!-- Impose random perturbation on the horizontal velocity field and then
2302!-- remove the divergences from the velocity field at the initial stage
[1788]2303    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND. &
2304         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[680]2305         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
2306
[1402]2307       CALL location_message( 'creating initial disturbances', .FALSE. )
[2232]2308       CALL disturb_field( 'u', tend, u )
2309       CALL disturb_field( 'v', tend, v )
[1402]2310       CALL location_message( 'finished', .TRUE. )
[1384]2311
[1402]2312       CALL location_message( 'calling pressure solver', .FALSE. )
[680]2313       n_sor = nsor_ini
2314       CALL pres
2315       n_sor = nsor
[1402]2316       CALL location_message( 'finished', .TRUE. )
[1384]2317
[680]2318    ENDIF
2319
2320!
[1484]2321!-- If required, initialize quantities needed for the plant canopy model
[2007]2322    IF ( plant_canopy )  THEN
2323       CALL location_message( 'initializing plant canopy model', .FALSE. )   
2324       CALL pcm_init
2325       CALL location_message( 'finished', .TRUE. )
2326    ENDIF
[138]2327
2328!
[1]2329!-- If required, initialize dvrp-software
[1340]2330    IF ( dt_dvrp /= 9999999.9_wp )  CALL init_dvrp
[1]2331
[96]2332    IF ( ocean )  THEN
[1]2333!
[96]2334!--    Initialize quantities needed for the ocean model
2335       CALL init_ocean
[388]2336
[96]2337    ELSE
2338!
2339!--    Initialize quantities for handling cloud physics
[849]2340!--    This routine must be called before lpm_init, because
[96]2341!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
[849]2342!--    lpm_init) is not defined.
[96]2343       CALL init_cloud_physics
[1849]2344!
2345!--    Initialize bulk cloud microphysics
2346       CALL microphysics_init
[96]2347    ENDIF
[1]2348
2349!
2350!-- If required, initialize particles
[849]2351    IF ( particle_advection )  CALL lpm_init
[1]2352
[1585]2353!
2354!-- If required, initialize quantities needed for the LSM
2355    IF ( land_surface )  THEN
2356       CALL location_message( 'initializing land surface model', .FALSE. )
[1817]2357       CALL lsm_init
[1585]2358       CALL location_message( 'finished', .TRUE. )
2359    ENDIF
[1496]2360
[1]2361!
[2696]2362!-- If required, allocate USM and LSM surfaces
2363    IF ( urban_surface )  THEN
2364       CALL location_message( 'initializing and allocating urban surfaces', .FALSE. )
2365       CALL usm_allocate_surface
2366       CALL location_message( 'finished', .TRUE. )
2367    ENDIF
2368!
2369!-- If required, initialize urban surface model
2370    IF ( urban_surface )  THEN
2371       CALL location_message( 'initializing urban surface model', .FALSE. )
2372       CALL usm_init_urban_surface
2373       CALL location_message( 'finished', .TRUE. )
2374    ENDIF
2375
2376!
[1691]2377!-- Initialize surface layer (done after LSM as roughness length are required
2378!-- for initialization
2379    IF ( constant_flux_layer )  THEN
2380       CALL location_message( 'initializing surface layer', .FALSE. )
2381       CALL init_surface_layer_fluxes
2382       CALL location_message( 'finished', .TRUE. )
2383    ENDIF
2384
2385!
[2696]2386!-- If required, set chemical emissions
2387!-- (todo(FK): This should later on be CALLed time-dependently in init_3d_model)
[2977]2388    IF ( air_chemistry )  THEN
[2696]2389       CALL chem_emissions
2390    ENDIF
2391
2392!
2393!-- Initialize radiation processes
[1496]2394    IF ( radiation )  THEN
[2696]2395!
[2977]2396!--    Activate radiation_interactions according to the existence of vertical surfaces and/or trees.
2397!--    The namelist parameter radiation_interactions_on can override this behavior.
2398!--    (This check cannot be performed in check_parameters, because vertical_surfaces_exist is first set in
2399!--    init_surface_arrays.)
2400       IF ( radiation_interactions_on )  THEN
2401          IF ( vertical_surfaces_exist  .OR.  plant_canopy )  THEN
2402             radiation_interactions    = .TRUE.
2403             average_radiation         = .TRUE.
2404          ELSE
2405             radiation_interactions_on = .FALSE.   !< reset namelist parameter: no interactions
2406                                                   !< calculations necessary in case of flat surface
2407          ENDIF
2408       ELSEIF ( vertical_surfaces_exist  .OR.  plant_canopy )  THEN
2409          message_string = 'radiation_interactions_on is set to .FALSE. although '     // &
2410                           'vertical surfaces and/or trees exist. The model will run ' // &
2411                           'without RTM (no shadows, no radiation reflections)'
2412          CALL message( 'init_3d_model', 'PA0348', 0, 1, 0, 6, 0 )
2413       ENDIF
2414!
[2696]2415!--    If required, initialize radiation interactions between surfaces
[2920]2416!--    via sky-view factors. This must be done before radiation is initialized.
[2696]2417       IF ( radiation_interactions )  CALL radiation_interaction_init
2418
2419!
2420!--    Initialize radiation model
[1585]2421       CALL location_message( 'initializing radiation model', .FALSE. )
[1826]2422       CALL radiation_init
[1585]2423       CALL location_message( 'finished', .TRUE. )
[2696]2424
2425!
[2920]2426!--    Find all discretized apparent solar positions for radiation interaction.
2427!--    This must be done after radiation_init.
2428       IF ( radiation_interactions )  CALL radiation_presimulate_solar_pos
2429
2430!
[2696]2431!--    If required, read or calculate and write out the SVF
[2906]2432       IF ( radiation_interactions .AND. read_svf)  THEN
[2696]2433!
2434!--       Read sky-view factors and further required data from file
2435          CALL location_message( '    Start reading SVF from file', .FALSE. )
2436          CALL radiation_read_svf()
2437          CALL location_message( '    Reading SVF from file has finished', .TRUE. )
2438
[2906]2439       ELSEIF ( radiation_interactions .AND. .NOT. read_svf)  THEN
[2696]2440!
2441!--       calculate SFV and CSF
2442          CALL location_message( '    Start calculation of SVF', .FALSE. )
2443          CALL radiation_calc_svf()
2444          CALL location_message( '    Calculation of SVF has finished', .TRUE. )
2445       ENDIF
2446
[2906]2447       IF ( radiation_interactions .AND. write_svf)  THEN
[2696]2448!
2449!--       Write svf, csf svfsurf and csfsurf data to file
[2906]2450          CALL location_message( '    Start writing SVF in file', .FALSE. )
[2696]2451          CALL radiation_write_svf()
[2906]2452          CALL location_message( '    Writing SVF in file has finished', .TRUE. )
[2696]2453       ENDIF
2454
2455!
2456!--    Adjust radiative fluxes. In case of urban and land surfaces, also
2457!--    call an initial interaction.
2458       IF ( radiation_interactions )  THEN
2459          CALL radiation_interaction
2460       ENDIF
[1496]2461    ENDIF
[2995]2462
[1914]2463!
[2270]2464!-- Temporary solution to add LSM and radiation time series to the default
2465!-- output
2466    IF ( land_surface  .OR.  radiation )  THEN
2467       IF ( TRIM( radiation_scheme ) == 'rrtmg' )  THEN
2468          dots_num = dots_num + 15
2469       ELSE
2470          dots_num = dots_num + 11
2471       ENDIF
2472    ENDIF
2473   
[2007]2474
[2696]2475
[2007]2476!
[1914]2477!-- If required, initialize quantities needed for the wind turbine model
2478    IF ( wind_turbine )  THEN
2479       CALL location_message( 'initializing wind turbine model', .FALSE. )
2480       CALL wtm_init
2481       CALL location_message( 'finished', .TRUE. )
2482    ENDIF
[1496]2483
[2817]2484!
2485!-- If required, initialize quantities needed for the gust module
2486    IF ( gust_module_enabled )  THEN
2487       CALL gust_init( dots_label, dots_unit, dots_num, dots_max )
2488    ENDIF
[1914]2489
[1496]2490!
[673]2491!-- Initialize the ws-scheme.   
2492    IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init       
[1]2493
2494!
[709]2495!-- Setting weighting factors for calculation of perturbation pressure
[1762]2496!-- and turbulent quantities from the RK substeps
[709]2497    IF ( TRIM(timestep_scheme) == 'runge-kutta-3' )  THEN      ! for RK3-method
2498
[1322]2499       weight_substep(1) = 1._wp/6._wp
2500       weight_substep(2) = 3._wp/10._wp
2501       weight_substep(3) = 8._wp/15._wp
[709]2502
[1322]2503       weight_pres(1)    = 1._wp/3._wp
2504       weight_pres(2)    = 5._wp/12._wp
2505       weight_pres(3)    = 1._wp/4._wp
[709]2506
2507    ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' )  THEN  ! for RK2-method
2508
[1322]2509       weight_substep(1) = 1._wp/2._wp
2510       weight_substep(2) = 1._wp/2._wp
[673]2511         
[1322]2512       weight_pres(1)    = 1._wp/2._wp
2513       weight_pres(2)    = 1._wp/2._wp       
[709]2514
[1001]2515    ELSE                                     ! for Euler-method
[709]2516
[1340]2517       weight_substep(1) = 1.0_wp     
2518       weight_pres(1)    = 1.0_wp                   
[709]2519
[673]2520    ENDIF
2521
2522!
[1]2523!-- Initialize Rayleigh damping factors
[1340]2524    rdf    = 0.0_wp
2525    rdf_sc = 0.0_wp
2526    IF ( rayleigh_damping_factor /= 0.0_wp )  THEN
[1788]2527       IF (  .NOT.  ocean )  THEN
[108]2528          DO  k = nzb+1, nzt
2529             IF ( zu(k) >= rayleigh_damping_height )  THEN
[1788]2530                rdf(k) = rayleigh_damping_factor *                             &
[1340]2531                      ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height ) &
[1788]2532                             / ( zu(nzt) - rayleigh_damping_height ) )         &
[1]2533                      )**2
[108]2534             ENDIF
2535          ENDDO
2536       ELSE
2537          DO  k = nzt, nzb+1, -1
2538             IF ( zu(k) <= rayleigh_damping_height )  THEN
[1788]2539                rdf(k) = rayleigh_damping_factor *                             &
[1340]2540                      ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) ) &
[1788]2541                             / ( rayleigh_damping_height - zu(nzb+1) ) )       &
[108]2542                      )**2
2543             ENDIF
2544          ENDDO
2545       ENDIF
[1]2546    ENDIF
[785]2547    IF ( scalar_rayleigh_damping )  rdf_sc = rdf
[1]2548
2549!
[240]2550!-- Initialize the starting level and the vertical smoothing factor used for
2551!-- the external pressure gradient
[1340]2552    dp_smooth_factor = 1.0_wp
[240]2553    IF ( dp_external )  THEN
2554!
2555!--    Set the starting level dp_level_ind_b only if it has not been set before
2556!--    (e.g. in init_grid).
2557       IF ( dp_level_ind_b == 0 )  THEN
2558          ind_array = MINLOC( ABS( dp_level_b - zu ) )
2559          dp_level_ind_b = ind_array(1) - 1 + nzb 
2560                                        ! MINLOC uses lower array bound 1
2561       ENDIF
2562       IF ( dp_smooth )  THEN
[1340]2563          dp_smooth_factor(:dp_level_ind_b) = 0.0_wp
[240]2564          DO  k = dp_level_ind_b+1, nzt
[1340]2565             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *               &
2566                        ( REAL( k - dp_level_ind_b, KIND=wp ) /                &
2567                          REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
[240]2568          ENDDO
2569       ENDIF
2570    ENDIF
2571
2572!
[978]2573!-- Initialize damping zone for the potential temperature in case of
2574!-- non-cyclic lateral boundaries. The damping zone has the maximum value
2575!-- at the inflow boundary and decreases to zero at pt_damping_width.
[1340]2576    ptdf_x = 0.0_wp
2577    ptdf_y = 0.0_wp
[1159]2578    IF ( bc_lr_dirrad )  THEN
[996]2579       DO  i = nxl, nxr
[978]2580          IF ( ( i * dx ) < pt_damping_width )  THEN
[1340]2581             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *              &
2582                            REAL( pt_damping_width - i * dx, KIND=wp ) / (     &
[1788]2583                            REAL( pt_damping_width, KIND=wp ) ) ) )**2 
[73]2584          ENDIF
2585       ENDDO
[1159]2586    ELSEIF ( bc_lr_raddir )  THEN
[996]2587       DO  i = nxl, nxr
[978]2588          IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) )  THEN
[1322]2589             ptdf_x(i) = pt_damping_factor *                                   &
[1340]2590                         SIN( pi * 0.5_wp *                                    &
2591                                 ( ( i - nx ) * dx + pt_damping_width ) /      &
2592                                 REAL( pt_damping_width, KIND=wp ) )**2
[73]2593          ENDIF
[978]2594       ENDDO 
[1159]2595    ELSEIF ( bc_ns_dirrad )  THEN
[996]2596       DO  j = nys, nyn
[978]2597          IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) )  THEN
[1322]2598             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2599                         SIN( pi * 0.5_wp *                                    &
2600                                 ( ( j - ny ) * dy + pt_damping_width ) /      &
2601                                 REAL( pt_damping_width, KIND=wp ) )**2
[1]2602          ENDIF
[978]2603       ENDDO 
[1159]2604    ELSEIF ( bc_ns_raddir )  THEN
[996]2605       DO  j = nys, nyn
[978]2606          IF ( ( j * dy ) < pt_damping_width )  THEN
[1322]2607             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2608                         SIN( pi * 0.5_wp *                                    &
2609                                ( pt_damping_width - j * dy ) /                &
2610                                REAL( pt_damping_width, KIND=wp ) )**2
[1]2611          ENDIF
[73]2612       ENDDO
[1]2613    ENDIF
2614!
[2864]2615!-- Check if maximum number of allowed timeseries is exceeded
[51]2616    IF ( dots_num > dots_max )  THEN
[1788]2617       WRITE( message_string, * ) 'number of time series quantities exceeds',  &
2618                                  ' its maximum of dots_max = ', dots_max,     &
[3046]2619                                  '&Please increase dots_max in modules.f90.'
[254]2620       CALL message( 'init_3d_model', 'PA0194', 1, 2, 0, 6, 0 )   
[51]2621    ENDIF
2622
[1]2623!
2624!-- Input binary data file is not needed anymore. This line must be placed
2625!-- after call of user_init!
2626    CALL close_file( 13 )
[2934]2627!
2628!-- In case of nesting, put an barrier to assure that all parent and child
2629!-- domains finished initialization.
2630#if defined( __parallel )
2631    IF ( nested_run )  CALL MPI_BARRIER( MPI_COMM_WORLD, ierr )
2632#endif
[1]2633
[2934]2634
[1402]2635    CALL location_message( 'leaving init_3d_model', .TRUE. )
[1]2636
2637 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.