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

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

Rename surface_output_mod into surface_data_output_mod, same with all corresponding subroutines

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