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

Last change on this file since 3472 was 3472, checked in by suehring, 7 years ago

module for virtual measurements added (in a preliminary state); new public routines to input NetCDF data directly from modules

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