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

Last change on this file since 3636 was 3636, checked in by raasch, 5 years ago

nopointer option removed

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