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

Last change on this file since 3609 was 3609, checked in by suehring, 5 years ago

Further correction in initialization of surfaces in cyclic-fill case

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