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

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

Branch salsa @3446 re-integrated into trunk

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