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

Last change on this file since 2172 was 2172, checked in by knoop, 7 years ago

Bugfix: parallel random number generator

  • Property svn:keywords set to Id
  • Property svn:mergeinfo set to False
    /palm/branches/forwind/SOURCE/init_3d_model.f901564-1913
File size: 80.4 KB
RevLine 
[1682]1!> @file init_3d_model.f90
[2000]2!------------------------------------------------------------------------------!
[1036]3! This file is part of PALM.
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!
[2101]17! Copyright 1997-2017 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[254]20! Current revisions:
[732]21! ------------------
[2172]22! Bugfix: moved parallel random generator initialization into its module
[1961]23!
24! Former revisions:
25! -----------------
26! $Id: init_3d_model.f90 2172 2017-03-08 15:55:25Z knoop $
27!
[2119]28! 2118 2017-01-17 16:38:49Z raasch
29! OpenACC directives removed
30!
[2038]31! 2037 2016-10-26 11:15:40Z knoop
32! Anelastic approximation implemented
33!
[2032]34! 2031 2016-10-21 15:11:58Z knoop
35! renamed variable rho to rho_ocean
36!
[2012]37! 2011 2016-09-19 17:29:57Z kanani
38! Flag urban_surface is now defined in module control_parameters.
39!
[2008]40! 2007 2016-08-24 15:47:17Z kanani
41! Added support for urban surface model,
42! adjusted location_message in case of plant_canopy
43!
[2001]44! 2000 2016-08-20 18:09:15Z knoop
45! Forced header and separation lines into 80 columns
46!
[1993]47! 1992 2016-08-12 15:14:59Z suehring
48! Initializaton of scalarflux at model top
49! Bugfixes in initialization of surface and top salinity flux, top scalar and
50! humidity fluxes
51!
[1961]52! 1960 2016-07-12 16:34:24Z suehring
[1960]53! Separate humidity and passive scalar
54! Increase dimension for mean_inflow_profiles
55! Remove inadvertent write-statement
56! Bugfix, large-scale forcing is still not implemented for passive scalars
[1919]57!
[1958]58! 1957 2016-07-07 10:43:48Z suehring
59! flight module added
60!
[1921]61! 1920 2016-05-30 10:50:15Z suehring
62! Initialize us with very small number to avoid segmentation fault during
63! calculation of Obukhov length
64!
[1919]65! 1918 2016-05-27 14:35:57Z raasch
66! intermediate_timestep_count is set 0 instead 1 for first call of pres,
67! bugfix: initialization of local sum arrays are moved to the beginning of the
68!         routine because otherwise results from pres are overwritten
69!
[1917]70! 1914 2016-05-26 14:44:07Z witha
71! Added initialization of the wind turbine model
72!
[1879]73! 1878 2016-04-19 12:30:36Z hellstea
74! The zeroth element of weight_pres removed as unnecessary
75!
[1851]76! 1849 2016-04-08 11:33:18Z hoffmann
[1849]77! Adapted for modularization of microphysics.
78! precipitation_amount, precipitation_rate, prr moved to arrays_3d.
[1852]79! Initialization of nc_1d, nr_1d, pt_1d, qc_1d, qr_1d, q_1d moved to
[1849]80! microphysics_init.
81!
[1846]82! 1845 2016-04-08 08:29:13Z raasch
83! nzb_2d replaced by nzb_u|v_inner
[1914]84!
[1834]85! 1833 2016-04-07 14:23:03Z raasch
86! initialization of spectra quantities moved to spectra_mod
87!
[1832]88! 1831 2016-04-07 13:15:51Z hoffmann
89! turbulence renamed collision_turbulence
90!
[1827]91! 1826 2016-04-07 12:01:39Z maronga
92! Renamed radiation calls.
93! Renamed canopy model calls.
94!
[1823]95! 1822 2016-04-07 07:49:42Z hoffmann
96! icloud_scheme replaced by microphysics_*
[1914]97!
[1818]98! 1817 2016-04-06 15:44:20Z maronga
99! Renamed lsm calls.
100!
[1816]101! 1815 2016-04-06 13:49:59Z raasch
102! zero-settings for velocities inside topography re-activated (was deactivated
103! in r1762)
104!
[1789]105! 1788 2016-03-10 11:01:04Z maronga
106! Added z0q.
107! Syntax layout improved.
108!
[1784]109! 1783 2016-03-06 18:36:17Z raasch
110! netcdf module name changed + related changes
111!
[1765]112! 1764 2016-02-28 12:45:19Z raasch
113! bugfix: increase size of volume_flow_area_l and volume_flow_initial_l by 1
114!
[1763]115! 1762 2016-02-25 12:31:13Z hellstea
116! Introduction of nested domain feature
117!
[1739]118! 1738 2015-12-18 13:56:05Z raasch
119! calculate mean surface level height for each statistic region
120!
[1735]121! 1734 2015-12-02 12:17:12Z raasch
122! no initial disturbances in case that the disturbance energy limit has been
123! set zero
124!
[1708]125! 1707 2015-11-02 15:24:52Z maronga
126! Bugfix: transfer of Richardson number from 1D model to Obukhov length caused
127! devision by zero in neutral stratification
128!
[1692]129! 1691 2015-10-26 16:17:44Z maronga
130! Call to init_surface_layer added. rif is replaced by ol and zeta.
131!
[1683]132! 1682 2015-10-07 23:56:08Z knoop
133! Code annotations made doxygen readable
134!
[1616]135! 1615 2015-07-08 18:49:19Z suehring
136! Enable turbulent inflow for passive_scalar and humidity
137!
[1586]138! 1585 2015-04-30 07:05:52Z maronga
139! Initialization of radiation code is now done after LSM initializtion
140!
[1576]141! 1575 2015-03-27 09:56:27Z raasch
142! adjustments for psolver-queries
143!
[1552]144! 1551 2015-03-03 14:18:16Z maronga
[1817]145! Allocation of land surface arrays is now done in the subroutine lsm_init_arrays,
[1552]146! which is part of land_surface_model.
147!
[1508]148! 1507 2014-12-10 12:14:18Z suehring
149! Bugfix: set horizontal velocity components to zero inside topography
150!
[1497]151! 1496 2014-12-02 17:25:50Z maronga
152! Added initialization of the land surface and radiation schemes
153!
[1485]154! 1484 2014-10-21 10:53:05Z kanani
[1484]155! Changes due to new module structure of the plant canopy model:
[1508]156! canopy-related initialization (e.g. lad and canopy_heat_flux) moved to new
157! subroutine init_plant_canopy within the module plant_canopy_model_mod,
158! call of subroutine init_plant_canopy added.
[1341]159!
[1432]160! 1431 2014-07-15 14:47:17Z suehring
161! var_d added, in order to normalize spectra.
162!
[1430]163! 1429 2014-07-15 12:53:45Z knoop
164! Ensemble run capability added to parallel random number generator
165!
[1412]166! 1411 2014-05-16 18:01:51Z suehring
167! Initial horizontal velocity profiles were not set to zero at the first vertical
168! grid level in case of non-cyclic lateral boundary conditions.
169!
[1407]170! 1406 2014-05-16 13:47:01Z raasch
171! bugfix: setting of initial velocities at k=1 to zero not in case of a
172! no-slip boundary condition for uv
173!
[1403]174! 1402 2014-05-09 14:25:13Z raasch
175! location messages modified
176!
[1401]177! 1400 2014-05-09 14:03:54Z knoop
178! Parallel random number generator added
179!
[1385]180! 1384 2014-05-02 14:31:06Z raasch
181! location messages added
182!
[1362]183! 1361 2014-04-16 15:17:48Z hoffmann
184! tend_* removed
185! Bugfix: w_subs is not allocated anymore if it is already allocated
186!
[1360]187! 1359 2014-04-11 17:15:14Z hoffmann
188! module lpm_init_mod added to use statements, because lpm_init has become a
189! module
190!
[1354]191! 1353 2014-04-08 15:21:23Z heinze
192! REAL constants provided with KIND-attribute
193!
[1341]194! 1340 2014-03-25 19:45:13Z kanani
195! REAL constants defined as wp-kind
196!
[1323]197! 1322 2014-03-20 16:38:49Z raasch
198! REAL constants defined as wp-kind
199! module interfaces removed
200!
[1321]201! 1320 2014-03-20 08:40:49Z raasch
202! ONLY-attribute added to USE-statements,
203! kind-parameters added to all INTEGER and REAL declaration statements,
204! kinds are defined in new module kinds,
205! revision history before 2012 removed,
206! comment fields (!:) to be used for variable explanations added to
207! all variable declaration statements
208!
[1317]209! 1316 2014-03-17 07:44:59Z heinze
210! Bugfix: allocation of w_subs
211!
[1300]212! 1299 2014-03-06 13:15:21Z heinze
213! Allocate w_subs due to extension of large scale subsidence in combination
214! with large scale forcing data (LSF_DATA)
215!
[1242]216! 1241 2013-10-30 11:36:58Z heinze
217! Overwrite initial profiles in case of nudging
218! Inititialize shf and qsws in case of large_scale_forcing
219!
[1222]220! 1221 2013-09-10 08:59:13Z raasch
221! +rflags_s_inner in copyin statement, use copyin for most arrays instead of
222! copy
223!
[1213]224! 1212 2013-08-15 08:46:27Z raasch
225! array tri is allocated and included in data copy statement
226!
[1196]227! 1195 2013-07-01 12:27:57Z heinze
228! Bugfix: move allocation of ref_state to parin.f90 and read_var_list.f90
229!
[1182]230! 1179 2013-06-14 05:57:58Z raasch
231! allocate and set ref_state to be used in buoyancy terms
232!
[1172]233! 1171 2013-05-30 11:27:45Z raasch
234! diss array is allocated with full size if accelerator boards are used
235!
[1160]236! 1159 2013-05-21 11:58:22Z fricke
237! -bc_lr_dirneu, bc_lr_neudir, bc_ns_dirneu, bc_ns_neudir
238!
[1154]239! 1153 2013-05-10 14:33:08Z raasch
240! diss array is allocated with dummy elements even if it is not needed
[1171]241! (required by PGI 13.4 / CUDA 5.0)
[1154]242!
[1116]243! 1115 2013-03-26 18:16:16Z hoffmann
244! unused variables removed
245!
[1114]246! 1113 2013-03-10 02:48:14Z raasch
247! openACC directive modified
248!
[1112]249! 1111 2013-03-08 23:54:10Z raasch
250! openACC directives added for pres
251! array diss allocated only if required
252!
[1093]253! 1092 2013-02-02 11:24:22Z raasch
254! unused variables removed
255!
[1066]256! 1065 2012-11-22 17:42:36Z hoffmann
257! allocation of diss (dissipation rate) in case of turbulence = .TRUE. added
258!
[1054]259! 1053 2012-11-13 17:11:03Z hoffmann
[1053]260! allocation and initialisation of necessary data arrays for the two-moment
261! cloud physics scheme the two new prognostic equations (nr, qr):
262! +dr, lambda_r, mu_r, sed_*, xr, *s, *sws, *swst, *, *_p, t*_m, *_1, *_2, *_3,
263! +tend_*, prr
[979]264!
[1037]265! 1036 2012-10-22 13:43:42Z raasch
266! code put under GPL (PALM 3.9)
267!
[1033]268! 1032 2012-10-21 13:03:21Z letzel
269! save memory by not allocating pt_2 in case of neutral = .T.
270!
[1026]271! 1025 2012-10-07 16:04:41Z letzel
272! bugfix: swap indices of mask for ghost boundaries
273!
[1017]274! 1015 2012-09-27 09:23:24Z raasch
275! mask is set to zero for ghost boundaries
276!
[1011]277! 1010 2012-09-20 07:59:54Z raasch
278! cpp switch __nopointer added for pointer free version
279!
[1004]280! 1003 2012-09-14 14:35:53Z raasch
281! nxra,nyna, nzta replaced ny nxr, nyn, nzt
282!
[1002]283! 1001 2012-09-13 14:08:46Z raasch
284! all actions concerning leapfrog scheme removed
285!
[997]286! 996 2012-09-07 10:41:47Z raasch
287! little reformatting
288!
[979]289! 978 2012-08-09 08:28:32Z fricke
[978]290! outflow damping layer removed
291! roughness length for scalar quantites z0h added
292! damping zone for the potential temperatur in case of non-cyclic lateral
293! boundaries added
294! initialization of ptdf_x, ptdf_y
295! initialization of c_u_m, c_u_m_l, c_v_m, c_v_m_l, c_w_m, c_w_m_l
[708]296!
[850]297! 849 2012-03-15 10:35:09Z raasch
298! init_particles renamed lpm_init
299!
[826]300! 825 2012-02-19 03:03:44Z raasch
301! wang_collision_kernel renamed wang_kernel
302!
[1]303! Revision 1.1  1998/03/09 16:22:22  raasch
304! Initial revision
305!
306!
307! Description:
308! ------------
[1682]309!> Allocation of arrays and initialization of the 3D model via
310!> a) pre-run the 1D model
311!> or
312!> b) pre-set constant linear profiles
313!> or
314!> c) read values of a previous run
[1]315!------------------------------------------------------------------------------!
[1682]316 SUBROUTINE init_3d_model
317 
[1]318
[667]319    USE advec_ws
[1320]320
[1]321    USE arrays_3d
[1849]322
[2037]323    USE cloud_parameters,                                                      &
324        ONLY:  cp, l_v, r_d
325
[1320]326    USE constants,                                                             &
327        ONLY:  pi
328   
[1]329    USE control_parameters
[1320]330   
[1957]331    USE flight_mod,                                                            &
332        ONLY:  flight_init
333   
[1320]334    USE grid_variables,                                                        &
[2037]335        ONLY:  dx, dy, ddx2_mg, ddy2_mg
[1320]336   
[1]337    USE indices
[1359]338
[1429]339    USE lpm_init_mod,                                                          &
[1359]340        ONLY:  lpm_init
[1320]341   
342    USE kinds
[1496]343
344    USE land_surface_model_mod,                                                &
[1817]345        ONLY:  lsm_init, lsm_init_arrays, land_surface
[1496]346 
[1241]347    USE ls_forcing_mod
[1849]348
349    USE microphysics_mod,                                                      &
350        ONLY:  collision_turbulence, microphysics_init
351
[1320]352    USE model_1d,                                                              &
353        ONLY:  e1d, kh1d, km1d, l1d, rif1d, u1d, us1d, usws1d, v1d, vsws1d 
354   
[1783]355    USE netcdf_interface,                                                      &
356        ONLY:  dots_max, dots_num
[1320]357   
358    USE particle_attributes,                                                   &
359        ONLY:  particle_advection, use_sgs_for_particles, wang_kernel
360   
[1]361    USE pegrid
[1320]362   
[1484]363    USE plant_canopy_model_mod,                                                &
[1826]364        ONLY:  pcm_init, plant_canopy
[1496]365
366    USE radiation_model_mod,                                                   &
[1826]367        ONLY:  radiation_init, radiation
[1484]368   
[1320]369    USE random_function_mod 
370   
[1400]371    USE random_generator_parallel,                                             &
[2172]372        ONLY:  init_parallel_random_generator
[1400]373   
[1320]374    USE statistics,                                                            &
[1738]375        ONLY:  hom, hom_sum, mean_surface_level_height, pr_palm, rmask,        &
[1833]376               statistic_regions, sums, sums_divnew_l, sums_divold_l, sums_l,  &
377               sums_l_l, sums_up_fraction_l, sums_wsts_bc_l, ts_value,         &
378               weight_pres, weight_substep
[1691]379 
380    USE surface_layer_fluxes_mod,                                              &
381        ONLY:  init_surface_layer_fluxes
382   
[2007]383    USE transpose_indices
[1]384
[2007]385    USE urban_surface_mod,                                                     &
[2011]386        ONLY:  usm_init_urban_surface
[2007]387
[1914]388    USE wind_turbine_model_mod,                                                &
389        ONLY:  wtm_init, wtm_init_arrays, wind_turbine
390
[1]391    IMPLICIT NONE
392
[1682]393    INTEGER(iwp) ::  i             !<
394    INTEGER(iwp) ::  ind_array(1)  !<
395    INTEGER(iwp) ::  j             !<
396    INTEGER(iwp) ::  k             !<
397    INTEGER(iwp) ::  sr            !<
[1]398
[1682]399    INTEGER(iwp), DIMENSION(:), ALLOCATABLE   ::  ngp_2dh_l  !<
[1]400
[1682]401    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_outer_l    !<
402    INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  ngp_2dh_s_inner_l  !<
[1]403
[2037]404    REAL(wp)     ::  t_surface !< air temperature at the surface
405
406    REAL(wp), DIMENSION(:), ALLOCATABLE ::  p_hydrostatic !< hydrostatic pressure
407
408    INTEGER(iwp) ::  l       !< loop variable
409    INTEGER(iwp) ::  nzt_l   !< index of top PE boundary for multigrid level
410    REAL(wp) ::  dx_l !< grid spacing along x on different multigrid level
411    REAL(wp) ::  dy_l !< grid spacing along y on different multigrid level
412
[1764]413    REAL(wp), DIMENSION(1:3) ::  volume_flow_area_l     !<
414    REAL(wp), DIMENSION(1:3) ::  volume_flow_initial_l  !<
[1]415
[1738]416    REAL(wp), DIMENSION(:), ALLOCATABLE ::  mean_surface_level_height_l    !<
[1682]417    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_l    !<
418    REAL(wp), DIMENSION(:), ALLOCATABLE ::  ngp_3d_inner_tmp  !<
[1]419
[485]420
[1402]421    CALL location_message( 'allocating arrays', .FALSE. )
[1]422!
423!-- Allocate arrays
[1788]424    ALLOCATE( mean_surface_level_height(0:statistic_regions),                  &
425              mean_surface_level_height_l(0:statistic_regions),                &
426              ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions),    &
427              ngp_3d(0:statistic_regions),                                     &
428              ngp_3d_inner(0:statistic_regions),                               &
429              ngp_3d_inner_l(0:statistic_regions),                             &
430              ngp_3d_inner_tmp(0:statistic_regions),                           &
431              sums_divnew_l(0:statistic_regions),                              &
[1]432              sums_divold_l(0:statistic_regions) )
[1195]433    ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt), rdf_sc(nzb+1:nzt) )
[1788]434    ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions),                    &
435              ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions),                  &
436              ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions),                  &
437              ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions),                &
438              rmask(nysg:nyng,nxlg:nxrg,0:statistic_regions),                  &
439              sums(nzb:nzt+1,pr_palm+max_pr_user),                             &
440              sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1),      &
441              sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1),    &
442              sums_up_fraction_l(10,3,0:statistic_regions),                    &
443              sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions),                   &
[394]444              ts_value(dots_max,0:statistic_regions) )
[978]445    ALLOCATE( ptdf_x(nxlg:nxrg), ptdf_y(nysg:nyng) )
[1]446
[1788]447    ALLOCATE( ol(nysg:nyng,nxlg:nxrg), shf(nysg:nyng,nxlg:nxrg),               &
448              ts(nysg:nyng,nxlg:nxrg), tswst(nysg:nyng,nxlg:nxrg),             &
449              us(nysg:nyng,nxlg:nxrg), usws(nysg:nyng,nxlg:nxrg),              &
450              uswst(nysg:nyng,nxlg:nxrg), vsws(nysg:nyng,nxlg:nxrg),           &
451              vswst(nysg:nyng,nxlg:nxrg), z0(nysg:nyng,nxlg:nxrg),             &
452              z0h(nysg:nyng,nxlg:nxrg), z0q(nysg:nyng,nxlg:nxrg) )
[1]453
[1788]454    ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr),                                    &
455              kh(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                               &
456              km(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                               &
457              p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
[1010]458              tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
459
460#if defined( __nopointer )
[1788]461    ALLOCATE( e(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
462              e_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
463              pt(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                               &
464              pt_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
465              u(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
466              u_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
467              v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
468              v_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
469              w(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                                &
470              w_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
471              te_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
472              tpt_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
473              tu_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
474              tv_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
[1010]475              tw_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
476#else
[1788]477    ALLOCATE( e_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
478              e_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
479              e_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
480              pt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
481              pt_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
482              u_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
483              u_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
484              u_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
485              v_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
486              v_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
487              v_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
488              w_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
489              w_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                              &
[667]490              w_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1788]491    IF (  .NOT.  neutral )  THEN
[1032]492       ALLOCATE( pt_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
493    ENDIF
[1010]494#endif
495
[673]496!
[707]497!-- Following array is required for perturbation pressure within the iterative
498!-- pressure solvers. For the multistep schemes (Runge-Kutta), array p holds
499!-- the weighted average of the substeps and cannot be used in the Poisson
500!-- solver.
501    IF ( psolver == 'sor' )  THEN
502       ALLOCATE( p_loc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1575]503    ELSEIF ( psolver(1:9) == 'multigrid' )  THEN
[707]504!
505!--    For performance reasons, multigrid is using one ghost layer only
506       ALLOCATE( p_loc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) )
[673]507    ENDIF
[1]508
[1111]509!
510!-- Array for storing constant coeffficients of the tridiagonal solver
511    IF ( psolver == 'poisfft' )  THEN
[1212]512       ALLOCATE( tri(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1,2) )
[1111]513       ALLOCATE( tric(nxl_z:nxr_z,nys_z:nyn_z,0:nz-1) )
514    ENDIF
515
[1960]516    IF ( humidity )  THEN
[1]517!
[1960]518!--    2D-humidity
[1788]519       ALLOCATE ( qs(nysg:nyng,nxlg:nxrg),                                     &
520                  qsws(nysg:nyng,nxlg:nxrg),                                   &
[1001]521                  qswst(nysg:nyng,nxlg:nxrg) )
[1]522
523!
[1960]524!--    3D-humidity
[1010]525#if defined( __nopointer )
[1788]526       ALLOCATE( q(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
527                 q_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[1010]528                 tq_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
529#else
[1788]530       ALLOCATE( q_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
531                 q_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[667]532                 q_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]533#endif
[1]534
535!
[1960]536!--    3D-arrays needed for humidity
[75]537       IF ( humidity )  THEN
[1010]538#if defined( __nopointer )
539          ALLOCATE( vpt(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
540#else
[667]541          ALLOCATE( vpt_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]542#endif
[1]543
[1788]544          IF ( cloud_physics )  THEN
[1053]545
[1]546!
547!--          Liquid water content
[1010]548#if defined( __nopointer )
549             ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
550#else
[667]551             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1010]552#endif
[72]553!
554!--          Precipitation amount and rate (only needed if output is switched)
[1788]555             ALLOCATE( precipitation_amount(nysg:nyng,nxlg:nxrg),              &
[667]556                       precipitation_rate(nysg:nyng,nxlg:nxrg) )
[1053]557
558!
[1822]559!--          3D-cloud water content
[1053]560#if defined( __nopointer )
[1822]561             ALLOCATE( qc(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]562#else
[1822]563             ALLOCATE( qc_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1053]564#endif
[1822]565!
566!--          3d-precipitation rate
567             ALLOCATE( prr(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]568
[1822]569             IF ( microphysics_seifert )  THEN
[1053]570!
[1822]571!--             2D-rain water content and rain drop concentration arrays
572                ALLOCATE ( qrs(nysg:nyng,nxlg:nxrg),                        &
573                           qrsws(nysg:nyng,nxlg:nxrg),                      &
574                           qrswst(nysg:nyng,nxlg:nxrg),                     &
575                           nrs(nysg:nyng,nxlg:nxrg),                        &
576                           nrsws(nysg:nyng,nxlg:nxrg),                      &
577                           nrswst(nysg:nyng,nxlg:nxrg) )
[1115]578!
[1822]579!--             3D-rain water content, rain drop concentration arrays
[1115]580#if defined( __nopointer )
[1822]581                ALLOCATE( nr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
582                          nr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
583                          qr(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                &
584                          qr_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
585                          tnr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg),             &
586                          tqr_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]587#else
[1822]588                ALLOCATE( nr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
589                          nr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
590                          nr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
591                          qr_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
592                          qr_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),              &
593                          qr_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1115]594#endif
[1822]595             ENDIF
[1053]596
[1]597          ENDIF
598
599          IF ( cloud_droplets )  THEN
600!
[1010]601!--          Liquid water content, change in liquid water content
602#if defined( __nopointer )
[1788]603             ALLOCATE ( ql(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                     &
[1010]604                        ql_c(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
605#else
[1788]606             ALLOCATE ( ql_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
[1010]607                        ql_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
608#endif
609!
610!--          Real volume of particles (with weighting), volume of particles
[1788]611             ALLOCATE ( ql_v(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                   &
[667]612                        ql_vp(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]613          ENDIF
614
615       ENDIF
616
617    ENDIF
[1960]618   
619   
620    IF ( passive_scalar )  THEN
621!
622!--    2D-scalar arrays
623       ALLOCATE ( ss(nysg:nyng,nxlg:nxrg),                                     &
624                  ssws(nysg:nyng,nxlg:nxrg),                                   &
625                  sswst(nysg:nyng,nxlg:nxrg) )
[1]626
[1960]627!
628!--    3D scalar arrays
629#if defined( __nopointer )
630       ALLOCATE( s(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                             &
631                 s_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
632                 ts_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
633#else
634       ALLOCATE( s_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
635                 s_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
636                 s_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
637#endif
638    ENDIF
639
[94]640    IF ( ocean )  THEN
[1788]641       ALLOCATE( saswsb(nysg:nyng,nxlg:nxrg),                                  &
[1001]642                 saswst(nysg:nyng,nxlg:nxrg) )
[1010]643#if defined( __nopointer )
[1788]644       ALLOCATE( prho(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[2031]645                 rho_ocean(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                           &
[1788]646                 sa(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                            &
647                 sa_p(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[1010]648                 tsa_m(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
649#else
[1788]650       ALLOCATE( prho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
651                 rho_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                         &
652                 sa_1(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
653                 sa_2(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                          &
[667]654                 sa_3(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[388]655       prho => prho_1
[2031]656       rho_ocean  => rho_1  ! routines calc_mean_profile and diffusion_e require
[388]657                      ! density to be apointer
[1010]658#endif
[108]659       IF ( humidity_remote )  THEN
[667]660          ALLOCATE( qswst_remote(nysg:nyng,nxlg:nxrg))
[1340]661          qswst_remote = 0.0_wp
[108]662       ENDIF
[94]663    ENDIF
664
[1]665!
[2037]666!-- Allocation of anelastic and Boussinesq approximation specific arrays
667    ALLOCATE( p_hydrostatic(nzb:nzt+1) )
668    ALLOCATE( rho_air(nzb:nzt+1) )
669    ALLOCATE( rho_air_zw(nzb:nzt+1) )
670    ALLOCATE( drho_air(nzb:nzt+1) )
671    ALLOCATE( drho_air_zw(nzb:nzt+1) )
672
673!
674!-- Density profile calculation for anelastic approximation
675    IF ( TRIM( approximation ) == 'anelastic' ) THEN
676       t_surface = pt_surface * ( surface_pressure / 1000.0_wp )**( r_d / cp )
677       DO  k = nzb, nzt+1
678          p_hydrostatic(k)    = surface_pressure * 100.0_wp *                  &
679                                ( 1 - ( g * zu(k) ) / ( cp * t_surface )       &
680                                )**( cp / r_d )
681          rho_air(k)          = ( p_hydrostatic(k) *                           &
682                                  ( 100000.0_wp / p_hydrostatic(k)             &
683                                  )**( r_d / cp )                              &
684                                ) / ( r_d * pt_init(k) )
685       ENDDO
686       DO  k = nzb, nzt
687          rho_air_zw(k) = 0.5_wp * ( rho_air(k) + rho_air(k+1) )
688       ENDDO
689       rho_air_zw(nzt+1)  = rho_air_zw(nzt)                                    &
690                            + 2.0_wp * ( rho_air(nzt+1) - rho_air_zw(nzt)  )
691    ELSE
692       rho_air     = 1.0_wp
693       rho_air_zw  = 1.0_wp
694    ENDIF
695
696!-- compute the inverse density array in order to avoid expencive divisions
697    drho_air    = 1.0_wp / rho_air
698    drho_air_zw = 1.0_wp / rho_air_zw
699
700!
701!-- Allocation of flux conversion arrays
702    ALLOCATE( heatflux_input_conversion(nzb:nzt+1) )
703    ALLOCATE( waterflux_input_conversion(nzb:nzt+1) )
704    ALLOCATE( momentumflux_input_conversion(nzb:nzt+1) )
705    ALLOCATE( heatflux_output_conversion(nzb:nzt+1) )
706    ALLOCATE( waterflux_output_conversion(nzb:nzt+1) )
707    ALLOCATE( momentumflux_output_conversion(nzb:nzt+1) )
708
709!
710!-- calculate flux conversion factors according to approximation and in-/output mode
711    DO  k = nzb, nzt+1
712
713        IF ( TRIM( flux_input_mode ) == 'kinematic' )  THEN
714            heatflux_input_conversion(k)      = rho_air_zw(k)
715            waterflux_input_conversion(k)     = rho_air_zw(k)
716            momentumflux_input_conversion(k)  = rho_air_zw(k)
717        ELSEIF ( TRIM( flux_input_mode ) == 'dynamic' ) THEN
718            heatflux_input_conversion(k)      = 1.0_wp / cp
719            waterflux_input_conversion(k)     = 1.0_wp / l_v
720            momentumflux_input_conversion(k)  = 1.0_wp
721        ENDIF
722
723        IF ( TRIM( flux_output_mode ) == 'kinematic' )  THEN
724            heatflux_output_conversion(k)     = drho_air_zw(k)
725            waterflux_output_conversion(k)    = drho_air_zw(k)
726            momentumflux_output_conversion(k) = drho_air_zw(k)
727        ELSEIF ( TRIM( flux_output_mode ) == 'dynamic' ) THEN
728            heatflux_output_conversion(k)     = cp
729            waterflux_output_conversion(k)    = l_v
730            momentumflux_output_conversion(k) = 1.0_wp
731        ENDIF
732
733        IF ( .NOT. humidity ) THEN
734            waterflux_input_conversion(k)  = 1.0_wp
735            waterflux_output_conversion(k) = 1.0_wp
736        ENDIF
737
738    ENDDO
739
740!
741!-- In case of multigrid method, compute grid lengths and grid factors for the
742!-- grid levels with respective density on each grid
743    IF ( psolver(1:9) == 'multigrid' )  THEN
744
745       ALLOCATE( ddx2_mg(maximum_grid_level) )
746       ALLOCATE( ddy2_mg(maximum_grid_level) )
747       ALLOCATE( dzu_mg(nzb+1:nzt+1,maximum_grid_level) )
748       ALLOCATE( dzw_mg(nzb+1:nzt+1,maximum_grid_level) )
749       ALLOCATE( f1_mg(nzb+1:nzt,maximum_grid_level) )
750       ALLOCATE( f2_mg(nzb+1:nzt,maximum_grid_level) )
751       ALLOCATE( f3_mg(nzb+1:nzt,maximum_grid_level) )
752       ALLOCATE( rho_air_mg(nzb:nzt+1,maximum_grid_level) )
753       ALLOCATE( rho_air_zw_mg(nzb:nzt+1,maximum_grid_level) )
754
755       dzu_mg(:,maximum_grid_level) = dzu
756       rho_air_mg(:,maximum_grid_level) = rho_air
757!       
758!--    Next line to ensure an equally spaced grid.
759       dzu_mg(1,maximum_grid_level) = dzu(2)
760       rho_air_mg(nzb,maximum_grid_level) = rho_air(nzb) +                     &
761                                             (rho_air(nzb) - rho_air(nzb+1))
762
763       dzw_mg(:,maximum_grid_level) = dzw
764       rho_air_zw_mg(:,maximum_grid_level) = rho_air_zw
765       nzt_l = nzt
766       DO  l = maximum_grid_level-1, 1, -1
767           dzu_mg(nzb+1,l) = 2.0_wp * dzu_mg(nzb+1,l+1)
768           dzw_mg(nzb+1,l) = 2.0_wp * dzw_mg(nzb+1,l+1)
769           rho_air_mg(nzb,l)    = rho_air_mg(nzb,l+1) + (rho_air_mg(nzb,l+1) - rho_air_mg(nzb+1,l+1))
770           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))
771           rho_air_mg(nzb+1,l)    = rho_air_mg(nzb+1,l+1)
772           rho_air_zw_mg(nzb+1,l) = rho_air_zw_mg(nzb+1,l+1)
773           nzt_l = nzt_l / 2
774           DO  k = 2, nzt_l+1
775              dzu_mg(k,l) = dzu_mg(2*k-2,l+1) + dzu_mg(2*k-1,l+1)
776              dzw_mg(k,l) = dzw_mg(2*k-2,l+1) + dzw_mg(2*k-1,l+1)
777              rho_air_mg(k,l)    = rho_air_mg(2*k-1,l+1)
778              rho_air_zw_mg(k,l) = rho_air_zw_mg(2*k-1,l+1)
779           ENDDO
780       ENDDO
781
782       nzt_l = nzt
783       dx_l  = dx
784       dy_l  = dy
785       DO  l = maximum_grid_level, 1, -1
786          ddx2_mg(l) = 1.0_wp / dx_l**2
787          ddy2_mg(l) = 1.0_wp / dy_l**2
788          DO  k = nzb+1, nzt_l
789             f2_mg(k,l) = rho_air_zw_mg(k,l) / ( dzu_mg(k+1,l) * dzw_mg(k,l) )
790             f3_mg(k,l) = rho_air_zw_mg(k-1,l) / ( dzu_mg(k,l)   * dzw_mg(k,l) )
791             f1_mg(k,l) = 2.0_wp * ( ddx2_mg(l) + ddy2_mg(l) ) &
792                          * rho_air_mg(k,l) + f2_mg(k,l) + f3_mg(k,l)
793          ENDDO
794          nzt_l = nzt_l / 2
795          dx_l  = dx_l * 2.0_wp
796          dy_l  = dy_l * 2.0_wp
797       ENDDO
798
799    ENDIF
800
801!
[1]802!-- 3D-array for storing the dissipation, needed for calculating the sgs
803!-- particle velocities
[2118]804    IF ( use_sgs_for_particles  .OR.  wang_kernel  .OR.  collision_turbulence )&
805    THEN
[1153]806       ALLOCATE( diss(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
[1]807    ENDIF
808
809!
[1299]810!-- 1D-array for large scale subsidence velocity
[1361]811    IF ( .NOT. ALLOCATED( w_subs ) )  THEN
812       ALLOCATE ( w_subs(nzb:nzt+1) )
813       w_subs = 0.0_wp
814    ENDIF
[1299]815
816!
[51]817!-- 4D-array for storing the Rif-values at vertical walls
818    IF ( topography /= 'flat' )  THEN
[667]819       ALLOCATE( rif_wall(nzb:nzt+1,nysg:nyng,nxlg:nxrg,1:4) )
[1340]820       rif_wall = 0.0_wp
[51]821    ENDIF
822
823!
[106]824!-- Arrays to store velocity data from t-dt and the phase speeds which
825!-- are needed for radiation boundary conditions
[73]826    IF ( outflow_l )  THEN
[1788]827       ALLOCATE( u_m_l(nzb:nzt+1,nysg:nyng,1:2),                               &
828                 v_m_l(nzb:nzt+1,nysg:nyng,0:1),                               &
[667]829                 w_m_l(nzb:nzt+1,nysg:nyng,0:1) )
[73]830    ENDIF
831    IF ( outflow_r )  THEN
[1788]832       ALLOCATE( u_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
833                 v_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx),                           &
[667]834                 w_m_r(nzb:nzt+1,nysg:nyng,nx-1:nx) )
[73]835    ENDIF
[106]836    IF ( outflow_l  .OR.  outflow_r )  THEN
[1788]837       ALLOCATE( c_u(nzb:nzt+1,nysg:nyng), c_v(nzb:nzt+1,nysg:nyng),           &
[667]838                 c_w(nzb:nzt+1,nysg:nyng) )
[106]839    ENDIF
[73]840    IF ( outflow_s )  THEN
[1788]841       ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxlg:nxrg),                               &
842                 v_m_s(nzb:nzt+1,1:2,nxlg:nxrg),                               &
[667]843                 w_m_s(nzb:nzt+1,0:1,nxlg:nxrg) )
[73]844    ENDIF
845    IF ( outflow_n )  THEN
[1788]846       ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
847                 v_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg),                           &
[667]848                 w_m_n(nzb:nzt+1,ny-1:ny,nxlg:nxrg) )
[73]849    ENDIF
[106]850    IF ( outflow_s  .OR.  outflow_n )  THEN
[1788]851       ALLOCATE( c_u(nzb:nzt+1,nxlg:nxrg), c_v(nzb:nzt+1,nxlg:nxrg),           &
[667]852                 c_w(nzb:nzt+1,nxlg:nxrg) )
[106]853    ENDIF
[996]854    IF ( outflow_l  .OR.  outflow_r  .OR.  outflow_s  .OR.  outflow_n )  THEN
[978]855       ALLOCATE( c_u_m_l(nzb:nzt+1), c_v_m_l(nzb:nzt+1), c_w_m_l(nzb:nzt+1) )                   
856       ALLOCATE( c_u_m(nzb:nzt+1), c_v_m(nzb:nzt+1), c_w_m(nzb:nzt+1) )
857    ENDIF
[73]858
[978]859
[1010]860#if ! defined( __nopointer )
[73]861!
[1]862!-- Initial assignment of the pointers
[1001]863    e  => e_1;   e_p  => e_2;   te_m  => e_3
[1032]864    IF ( .NOT. neutral )  THEN
865       pt => pt_1;  pt_p => pt_2;  tpt_m => pt_3
866    ELSE
867       pt => pt_1;  pt_p => pt_1;  tpt_m => pt_3
868    ENDIF
[1001]869    u  => u_1;   u_p  => u_2;   tu_m  => u_3
870    v  => v_1;   v_p  => v_2;   tv_m  => v_3
871    w  => w_1;   w_p  => w_2;   tw_m  => w_3
[1]872
[1960]873    IF ( humidity )  THEN
[1001]874       q => q_1;  q_p => q_2;  tq_m => q_3
[1053]875       IF ( humidity )  THEN
876          vpt  => vpt_1   
877          IF ( cloud_physics )  THEN
878             ql => ql_1
[1822]879             qc => qc_1
880             IF ( microphysics_seifert )  THEN
881                qr => qr_1;  qr_p  => qr_2;  tqr_m  => qr_3
882                nr => nr_1;  nr_p  => nr_2;  tnr_m  => nr_3
[1053]883             ENDIF
884          ENDIF
885       ENDIF
[1001]886       IF ( cloud_droplets )  THEN
887          ql   => ql_1
888          ql_c => ql_2
[1]889       ENDIF
[1001]890    ENDIF
[1960]891   
892    IF ( passive_scalar )  THEN
893       s => s_1;  s_p => s_2;  ts_m => s_3
894    ENDIF   
[1]895
[1001]896    IF ( ocean )  THEN
897       sa => sa_1;  sa_p => sa_2;  tsa_m => sa_3
898    ENDIF
[1010]899#endif
[1]900
901!
[1551]902!-- Allocate land surface model arrays
903    IF ( land_surface )  THEN
[1817]904       CALL lsm_init_arrays
[1551]905    ENDIF
906
907!
[1914]908!-- Allocate wind turbine model arrays
909    IF ( wind_turbine )  THEN
910       CALL wtm_init_arrays
911    ENDIF
[1957]912   
913!
914!-- Initialize virtual flight measurements
915    IF ( virtual_flight )  THEN
916       CALL flight_init
917    ENDIF
[1914]918
919!
[709]920!-- Allocate arrays containing the RK coefficient for calculation of
921!-- perturbation pressure and turbulent fluxes. At this point values are
922!-- set for pressure calculation during initialization (where no timestep
923!-- is done). Further below the values needed within the timestep scheme
924!-- will be set.
[1788]925    ALLOCATE( weight_substep(1:intermediate_timestep_count_max),               &
[1878]926              weight_pres(1:intermediate_timestep_count_max) )
[1340]927    weight_substep = 1.0_wp
928    weight_pres    = 1.0_wp
[1918]929    intermediate_timestep_count = 0  ! needed when simulated_time = 0.0
[673]930       
[1402]931    CALL location_message( 'finished', .TRUE. )
[1918]932
[673]933!
[1918]934!-- Initialize local summation arrays for routine flow_statistics.
935!-- This is necessary because they may not yet have been initialized when they
936!-- are called from flow_statistics (or - depending on the chosen model run -
937!-- are never initialized)
938    sums_divnew_l      = 0.0_wp
939    sums_divold_l      = 0.0_wp
940    sums_l_l           = 0.0_wp
941    sums_up_fraction_l = 0.0_wp
942    sums_wsts_bc_l     = 0.0_wp
943
944
945!
[1]946!-- Initialize model variables
[1788]947    IF ( TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[328]948         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
[1]949!
950!--    First model run of a possible job queue.
951!--    Initial profiles of the variables must be computes.
952       IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 )  THEN
[1384]953
[1402]954          CALL location_message( 'initializing with 1D model profiles', .FALSE. )
[1]955!
956!--       Use solutions of the 1D model as initial profiles,
957!--       start 1D model
958          CALL init_1d_model
959!
960!--       Transfer initial profiles to the arrays of the 3D model
[667]961          DO  i = nxlg, nxrg
962             DO  j = nysg, nyng
[1]963                e(:,j,i)  = e1d
964                kh(:,j,i) = kh1d
965                km(:,j,i) = km1d
966                pt(:,j,i) = pt_init
967                u(:,j,i)  = u1d
968                v(:,j,i)  = v1d
969             ENDDO
970          ENDDO
971
[1960]972          IF ( humidity )  THEN
[667]973             DO  i = nxlg, nxrg
974                DO  j = nysg, nyng
[1]975                   q(:,j,i) = q_init
976                ENDDO
977             ENDDO
[1822]978             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]979                DO  i = nxlg, nxrg
980                   DO  j = nysg, nyng
[1340]981                      qr(:,j,i) = 0.0_wp
982                      nr(:,j,i) = 0.0_wp
[1053]983                   ENDDO
984                ENDDO
[1115]985
[1053]986             ENDIF
[1]987          ENDIF
[1960]988          IF ( passive_scalar )  THEN
989             DO  i = nxlg, nxrg
990                DO  j = nysg, nyng
991                   s(:,j,i) = s_init
992                ENDDO
993             ENDDO   
994          ENDIF
[1]995
996          IF ( .NOT. constant_diffusion )  THEN
[667]997             DO  i = nxlg, nxrg
998                DO  j = nysg, nyng
[1]999                   e(:,j,i)  = e1d
1000                ENDDO
1001             ENDDO
1002!
1003!--          Store initial profiles for output purposes etc.
1004             hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 )
1005
[1691]1006             IF ( constant_flux_layer )  THEN
[1707]1007                ol   = ( zu(nzb+1) - zw(nzb) ) / ( rif1d(nzb+1) + 1.0E-20_wp )
[1340]1008                ts   = 0.0_wp  ! could actually be computed more accurately in the
1009                               ! 1D model. Update when opportunity arises.
[1]1010                us   = us1d
1011                usws = usws1d
1012                vsws = vsws1d
1013             ELSE
[1340]1014                ts   = 0.0_wp  ! must be set, because used in
[1691]1015                ol   = ( zu(nzb+1) - zw(nzb) ) / zeta_min  ! flowste
[1340]1016                us   = 0.0_wp
1017                usws = 0.0_wp
1018                vsws = 0.0_wp
[1]1019             ENDIF
1020
1021          ELSE
[1340]1022             e    = 0.0_wp  ! must be set, because used in
[1691]1023             ol   = ( zu(nzb+1) - zw(nzb) ) / zeta_min  ! flowste
[1340]1024             ts   = 0.0_wp
1025             us   = 0.0_wp
1026             usws = 0.0_wp
1027             vsws = 0.0_wp
[1]1028          ENDIF
[2037]1029          uswst = top_momentumflux_u * momentumflux_input_conversion(nzt+1)
1030          vswst = top_momentumflux_v * momentumflux_input_conversion(nzt+1)
[1]1031
1032!
1033!--       In every case qs = 0.0 (see also pt)
1034!--       This could actually be computed more accurately in the 1D model.
1035!--       Update when opportunity arises!
[1960]1036          IF ( humidity )  THEN
[1340]1037             qs = 0.0_wp
[1822]1038             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1039                qrs = 0.0_wp
1040                nrs = 0.0_wp
[1053]1041             ENDIF
1042          ENDIF
[1960]1043!
1044!--       Initialize scaling parameter for passive scalar
1045          IF ( passive_scalar ) ss = 0.0_wp         
[1]1046
1047!
[1762]1048!--       Inside buildings set velocities back to zero
[1]1049          IF ( topography /= 'flat' )  THEN
[1762]1050             DO  i = nxlg, nxrg
1051                DO  j = nysg, nyng
[1340]1052                   u(nzb:nzb_u_inner(j,i),j,i) = 0.0_wp
1053                   v(nzb:nzb_v_inner(j,i),j,i) = 0.0_wp
[1]1054                ENDDO
1055             ENDDO
[667]1056             
[1]1057!
1058!--          WARNING: The extra boundary conditions set after running the
1059!--          -------  1D model impose an error on the divergence one layer
1060!--                   below the topography; need to correct later
1061!--          ATTENTION: Provisional correction for Piacsek & Williams
1062!--          ---------  advection scheme: keep u and v zero one layer below
1063!--                     the topography.
[667]1064             IF ( ibc_uv_b == 1 )  THEN
1065!
[1]1066!--             Neumann condition
1067                DO  i = nxl-1, nxr+1
1068                   DO  j = nys-1, nyn+1
1069                      IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = u(1,j,i)
1070                      IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = v(1,j,i)
1071                   ENDDO
1072                ENDDO
1073
1074             ENDIF
1075
1076          ENDIF
1077
[1402]1078          CALL location_message( 'finished', .TRUE. )
[1384]1079
[1788]1080       ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 )    &
[1]1081       THEN
[1241]1082
[1402]1083          CALL location_message( 'initializing with constant profiles', .FALSE. )
[1]1084!
[1241]1085!--       Overwrite initial profiles in case of nudging
[1788]1086          IF ( nudging )  THEN
[1241]1087             pt_init = ptnudge(:,1)
1088             u_init  = unudge(:,1)
1089             v_init  = vnudge(:,1)
[1960]1090             IF ( humidity  )  THEN ! is passive_scalar correct???
[1241]1091                q_init = qnudge(:,1)
1092             ENDIF
1093
[1788]1094             WRITE( message_string, * ) 'Initial profiles of u, v and ',       &
[1241]1095                 'scalars from NUDGING_DATA are used.'
1096             CALL message( 'init_3d_model', 'PA0370', 0, 0, 0, 6, 0 )
1097          ENDIF
1098
1099!
[1]1100!--       Use constructed initial profiles (velocity constant with height,
1101!--       temperature profile with constant gradient)
[667]1102          DO  i = nxlg, nxrg
1103             DO  j = nysg, nyng
[1]1104                pt(:,j,i) = pt_init
1105                u(:,j,i)  = u_init
1106                v(:,j,i)  = v_init
1107             ENDDO
1108          ENDDO
[75]1109
[1]1110!
[292]1111!--       Set initial horizontal velocities at the lowest computational grid
1112!--       levels to zero in order to avoid too small time steps caused by the
1113!--       diffusion limit in the initial phase of a run (at k=1, dz/2 occurs
[1815]1114!--       in the limiting formula!).
1115          IF ( ibc_uv_b /= 1 )  THEN
1116             DO  i = nxlg, nxrg
1117                DO  j = nysg, nyng
1118                   u(nzb:nzb_u_inner(j,i)+1,j,i) = 0.0_wp
1119                   v(nzb:nzb_v_inner(j,i)+1,j,i) = 0.0_wp
1120                ENDDO
1121             ENDDO
1122          ENDIF
[1]1123
[1960]1124          IF ( humidity )  THEN
[667]1125             DO  i = nxlg, nxrg
1126                DO  j = nysg, nyng
[1]1127                   q(:,j,i) = q_init
1128                ENDDO
1129             ENDDO
[1822]1130             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1115]1131
[1822]1132                DO  i = nxlg, nxrg
1133                   DO  j = nysg, nyng
1134                      qr(:,j,i) = 0.0_wp
1135                      nr(:,j,i) = 0.0_wp
[1053]1136                   ENDDO
[1822]1137                ENDDO
[1115]1138
[1053]1139             ENDIF
[1]1140          ENDIF
[1960]1141         
1142          IF ( passive_scalar )  THEN
1143             DO  i = nxlg, nxrg
1144                DO  j = nysg, nyng
1145                   s(:,j,i) = s_init
1146                ENDDO
1147             ENDDO
1148          ENDIF
[1]1149
[94]1150          IF ( ocean )  THEN
[667]1151             DO  i = nxlg, nxrg
1152                DO  j = nysg, nyng
[94]1153                   sa(:,j,i) = sa_init
1154                ENDDO
1155             ENDDO
1156          ENDIF
[1]1157         
1158          IF ( constant_diffusion )  THEN
1159             km   = km_constant
1160             kh   = km / prandtl_number
[1340]1161             e    = 0.0_wp
1162          ELSEIF ( e_init > 0.0_wp )  THEN
[108]1163             DO  k = nzb+1, nzt
[1340]1164                km(k,:,:) = 0.1_wp * l_grid(k) * SQRT( e_init )
[108]1165             ENDDO
1166             km(nzb,:,:)   = km(nzb+1,:,:)
1167             km(nzt+1,:,:) = km(nzt,:,:)
1168             kh   = km / prandtl_number
1169             e    = e_init
[1]1170          ELSE
[108]1171             IF ( .NOT. ocean )  THEN
[1340]1172                kh   = 0.01_wp   ! there must exist an initial diffusion, because
1173                km   = 0.01_wp   ! otherwise no TKE would be produced by the
[108]1174                              ! production terms, as long as not yet
1175                              ! e = (u*/cm)**2 at k=nzb+1
1176             ELSE
[1340]1177                kh   = 0.00001_wp
1178                km   = 0.00001_wp
[108]1179             ENDIF
[1340]1180             e    = 0.0_wp
[1]1181          ENDIF
[1691]1182          ol    = ( zu(nzb+1) - zw(nzb) ) / zeta_min
[1340]1183          ts    = 0.0_wp
[1920]1184!
1185!--       Very small number is required for calculation of Obukhov length
1186!--       at first timestep     
1187          us    = 1E-30_wp 
[1340]1188          usws  = 0.0_wp
[2037]1189          uswst = top_momentumflux_u * momentumflux_input_conversion(nzt+1)
[1340]1190          vsws  = 0.0_wp
[2037]1191          vswst = top_momentumflux_v * momentumflux_input_conversion(nzt+1)
[1960]1192          IF ( humidity )       qs = 0.0_wp
1193          IF ( passive_scalar ) ss = 0.0_wp
[1]1194
1195!
1196!--       Compute initial temperature field and other constants used in case
1197!--       of a sloping surface
1198          IF ( sloping_surface )  CALL init_slope
1199
[1402]1200          CALL location_message( 'finished', .TRUE. )
[1384]1201
[1788]1202       ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 )                  &
[46]1203       THEN
[1384]1204
[1402]1205          CALL location_message( 'initializing by user', .FALSE. )
[46]1206!
1207!--       Initialization will completely be done by the user
1208          CALL user_init_3d_model
1209
[1402]1210          CALL location_message( 'finished', .TRUE. )
[1384]1211
[1]1212       ENDIF
[1384]1213
[1402]1214       CALL location_message( 'initializing statistics, boundary conditions, etc.', &
1215                              .FALSE. )
[1384]1216
[667]1217!
1218!--    Bottom boundary
1219       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2  )  THEN
[1340]1220          u(nzb,:,:) = 0.0_wp
1221          v(nzb,:,:) = 0.0_wp
[667]1222       ENDIF
[1]1223
1224!
[151]1225!--    Apply channel flow boundary condition
[132]1226       IF ( TRIM( bc_uv_t ) == 'dirichlet_0' )  THEN
[1340]1227          u(nzt+1,:,:) = 0.0_wp
1228          v(nzt+1,:,:) = 0.0_wp
[132]1229       ENDIF
1230
1231!
[1]1232!--    Calculate virtual potential temperature
[1960]1233       IF ( humidity )  vpt = pt * ( 1.0_wp + 0.61_wp * q )
[1]1234
1235!
1236!--    Store initial profiles for output purposes etc.
1237       hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 )
1238       hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 )
[667]1239       IF ( ibc_uv_b == 0 .OR. ibc_uv_b == 2)  THEN
[1340]1240          hom(nzb,1,5,:) = 0.0_wp
1241          hom(nzb,1,6,:) = 0.0_wp
[1]1242       ENDIF
1243       hom(:,1,7,:)  = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1244       hom(:,1,23,:) = SPREAD( km(:,nys,nxl), 2, statistic_regions+1 )
1245       hom(:,1,24,:) = SPREAD( kh(:,nys,nxl), 2, statistic_regions+1 )
1246
[97]1247       IF ( ocean )  THEN
1248!
1249!--       Store initial salinity profile
1250          hom(:,1,26,:)  = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 )
1251       ENDIF
[1]1252
[75]1253       IF ( humidity )  THEN
[1]1254!
1255!--       Store initial profile of total water content, virtual potential
1256!--       temperature
1257          hom(:,1,26,:) = SPREAD(   q(:,nys,nxl), 2, statistic_regions+1 )
1258          hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 )
1259          IF ( cloud_physics  .OR.  cloud_droplets ) THEN
1260!
1261!--          Store initial profile of specific humidity and potential
1262!--          temperature
1263             hom(:,1,27,:) = SPREAD(  q(:,nys,nxl), 2, statistic_regions+1 )
1264             hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 )
1265          ENDIF
1266       ENDIF
1267
1268       IF ( passive_scalar )  THEN
1269!
1270!--       Store initial scalar profile
[1960]1271          hom(:,1,115,:) = SPREAD(  s(:,nys,nxl), 2, statistic_regions+1 )
[1]1272       ENDIF
1273
1274!
[1400]1275!--    Initialize the random number generators (from numerical recipes)
1276       CALL random_function_ini
[1429]1277       
[1400]1278       IF ( random_generator == 'random-parallel' )  THEN
[2172]1279          CALL init_parallel_random_generator(nx, ny, nys, nyn, nxl, nxr)
[1400]1280       ENDIF
1281
1282!
[19]1283!--    Initialize fluxes at bottom surface
[1]1284       IF ( use_surface_fluxes )  THEN
1285
1286          IF ( constant_heatflux )  THEN
1287!
1288!--          Heat flux is prescribed
1289             IF ( random_heatflux )  THEN
1290                CALL disturb_heatflux
1291             ELSE
[2037]1292                shf = surface_heatflux * heatflux_input_conversion(nzb)
[1]1293!
[1241]1294!--             Initialize shf with data from external file LSF_DATA
[1788]1295                IF ( large_scale_forcing .AND. lsf_surf )  THEN
[1241]1296                   CALL ls_forcing_surf ( simulated_time )
1297                ENDIF
1298
1299!
[1]1300!--             Over topography surface_heatflux is replaced by wall_heatflux(0)
1301                IF ( TRIM( topography ) /= 'flat' )  THEN
[667]1302                   DO  i = nxlg, nxrg
1303                      DO  j = nysg, nyng
[1]1304                         IF ( nzb_s_inner(j,i) /= 0 )  THEN
[2037]1305                            shf(j,i) = wall_heatflux(0)                        &
1306                                  * heatflux_input_conversion(nzb_s_inner(j,i))
[1]1307                         ENDIF
1308                      ENDDO
1309                   ENDDO
1310                ENDIF
1311             ENDIF
1312          ENDIF
1313
1314!
1315!--       Determine the near-surface water flux
[1960]1316          IF ( humidity )  THEN
[1822]1317             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1318                qrsws = 0.0_wp
1319                nrsws = 0.0_wp
[1053]1320             ENDIF
[1]1321             IF ( constant_waterflux )  THEN
[2037]1322                qsws   = surface_waterflux * waterflux_input_conversion(nzb)
[407]1323!
1324!--             Over topography surface_waterflux is replaced by
1325!--             wall_humidityflux(0)
1326                IF ( TRIM( topography ) /= 'flat' )  THEN
1327                   wall_qflux = wall_humidityflux
[667]1328                   DO  i = nxlg, nxrg
1329                      DO  j = nysg, nyng
[407]1330                         IF ( nzb_s_inner(j,i) /= 0 )  THEN
[2037]1331                            qsws(j,i) = wall_qflux(0)                          &
1332                                 * waterflux_input_conversion(nzb_s_inner(j,i))
[407]1333                         ENDIF
1334                      ENDDO
1335                   ENDDO
1336                ENDIF
[1]1337             ENDIF
1338          ENDIF
[1960]1339!
1340!--       Initialize the near-surface scalar flux
1341          IF ( passive_scalar )  THEN
1342             IF ( constant_scalarflux )  THEN
1343                ssws   = surface_scalarflux
1344!
1345!--             Over topography surface_scalarflux is replaced by
1346!--             wall_scalarflux(0)
1347                IF ( TRIM( topography ) /= 'flat' )  THEN
1348                   wall_sflux = wall_scalarflux
1349                   DO  i = nxlg, nxrg
1350                      DO  j = nysg, nyng
1351                         IF ( nzb_s_inner(j,i) /= 0 )  ssws(j,i) = wall_sflux(0)
1352                      ENDDO
1353                   ENDDO
1354                ENDIF
1355             ENDIF
[1992]1356          ENDIF   
1357!
1358!--       Initialize near-surface salinity flux
1359          IF ( ocean )  saswsb = bottom_salinityflux
[1]1360
1361       ENDIF
1362
1363!
[19]1364!--    Initialize fluxes at top surface
[94]1365!--    Currently, only the heatflux and salinity flux can be prescribed.
1366!--    The latent flux is zero in this case!
[19]1367       IF ( use_top_fluxes )  THEN
1368!
[1992]1369!--       Prescribe to heat flux
[2037]1370          IF ( constant_top_heatflux )  tswst = top_heatflux                   &
1371                                             * heatflux_input_conversion(nzt+1)
[1992]1372!
1373!--       Prescribe zero latent flux at the top     
1374          IF ( humidity )  THEN
1375             qswst = 0.0_wp
1376             IF ( cloud_physics  .AND.  microphysics_seifert ) THEN
1377                nrswst = 0.0_wp
1378                qrswst = 0.0_wp
[1053]1379             ENDIF
[102]1380          ENDIF
1381!
[1992]1382!--       Prescribe top scalar flux
1383          IF ( passive_scalar .AND. constant_top_scalarflux )                  &
1384             sswst = top_scalarflux
1385!
1386!--       Prescribe top salinity flux
1387          IF ( ocean .AND. constant_top_salinityflux)                          &
1388             saswst = top_salinityflux
1389!
[102]1390!--       Initialization in case of a coupled model run
1391          IF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
[1340]1392             tswst = 0.0_wp
[102]1393          ENDIF
1394
[19]1395       ENDIF
1396
1397!
[1]1398!--    Initialize Prandtl layer quantities
[1691]1399       IF ( constant_flux_layer )  THEN
[1]1400
1401          z0 = roughness_length
[978]1402          z0h = z0h_factor * z0
[1788]1403          z0q = z0h_factor * z0
[1]1404
1405          IF ( .NOT. constant_heatflux )  THEN 
1406!
1407!--          Surface temperature is prescribed. Here the heat flux cannot be
[1691]1408!--          simply estimated, because therefore ol, u* and theta* would have
[1]1409!--          to be computed by iteration. This is why the heat flux is assumed
1410!--          to be zero before the first time step. It approaches its correct
1411!--          value in the course of the first few time steps.
[1340]1412             shf   = 0.0_wp
[1]1413          ENDIF
1414
[1960]1415          IF ( humidity  )  THEN
[1788]1416             IF (  .NOT.  constant_waterflux )  qsws   = 0.0_wp
[1822]1417             IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1418                qrsws = 0.0_wp
1419                nrsws = 0.0_wp
[1053]1420             ENDIF
[1]1421          ENDIF
[1960]1422          IF ( passive_scalar  .AND.  .NOT.  constant_scalarflux )  ssws = 0.0_wp
[1]1423
1424       ENDIF
1425
[1179]1426!
1427!--    Set the reference state to be used in the buoyancy terms (for ocean runs
1428!--    the reference state will be set (overwritten) in init_ocean)
1429       IF ( use_single_reference_value )  THEN
[1788]1430          IF (  .NOT.  humidity )  THEN
[1179]1431             ref_state(:) = pt_reference
1432          ELSE
1433             ref_state(:) = vpt_reference
1434          ENDIF
1435       ELSE
[1788]1436          IF (  .NOT.  humidity )  THEN
[1179]1437             ref_state(:) = pt_init(:)
1438          ELSE
1439             ref_state(:) = vpt(:,nys,nxl)
1440          ENDIF
1441       ENDIF
[152]1442
1443!
[707]1444!--    For the moment, vertical velocity is zero
[1340]1445       w = 0.0_wp
[1]1446
1447!
1448!--    Initialize array sums (must be defined in first call of pres)
[1340]1449       sums = 0.0_wp
[1]1450
1451!
[707]1452!--    In case of iterative solvers, p must get an initial value
[1575]1453       IF ( psolver(1:9) == 'multigrid'  .OR.  psolver == 'sor' )  p = 0.0_wp
[707]1454
1455!
[72]1456!--    Treating cloud physics, liquid water content and precipitation amount
1457!--    are zero at beginning of the simulation
1458       IF ( cloud_physics )  THEN
[1340]1459          ql = 0.0_wp
[1822]1460          qc = 0.0_wp
1461
1462          precipitation_amount = 0.0_wp
[72]1463       ENDIF
[673]1464!
[1]1465!--    Impose vortex with vertical axis on the initial velocity profile
1466       IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 )  THEN
1467          CALL init_rankine
1468       ENDIF
1469
1470!
1471!--    Impose temperature anomaly (advection test only)
1472       IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 )  THEN
1473          CALL init_pt_anomaly
1474       ENDIF
1475
1476!
1477!--    If required, change the surface temperature at the start of the 3D run
[1340]1478       IF ( pt_surface_initial_change /= 0.0_wp )  THEN
[1]1479          pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change
1480       ENDIF
1481
1482!
1483!--    If required, change the surface humidity/scalar at the start of the 3D
1484!--    run
[1960]1485       IF ( humidity  .AND.  q_surface_initial_change /= 0.0_wp )              &
[1]1486          q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change
[1960]1487         
1488       IF ( passive_scalar .AND.  s_surface_initial_change /= 0.0_wp )         &
1489          s(nzb,:,:) = s(nzb,:,:) + s_surface_initial_change
1490       
[1]1491
1492!
1493!--    Initialize old and new time levels.
[1340]1494       te_m = 0.0_wp; tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
[1]1495       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
1496
[1960]1497       IF ( humidity  )  THEN
[1340]1498          tq_m = 0.0_wp
[1]1499          q_p = q
[1822]1500          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1501             tqr_m = 0.0_wp
[1822]1502             qr_p  = qr
[1340]1503             tnr_m = 0.0_wp
[1822]1504             nr_p  = nr
[1053]1505          ENDIF
[1]1506       ENDIF
[1960]1507       
1508       IF ( passive_scalar )  THEN
1509          ts_m = 0.0_wp
1510          s_p  = s
1511       ENDIF       
[1]1512
[94]1513       IF ( ocean )  THEN
[1340]1514          tsa_m = 0.0_wp
[94]1515          sa_p  = sa
1516       ENDIF
[667]1517       
[1402]1518       CALL location_message( 'finished', .TRUE. )
[94]1519
[1788]1520    ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data'  .OR.         &
1521         TRIM( initializing_actions ) == 'cyclic_fill' )                       &
[1]1522    THEN
[1384]1523
[1402]1524       CALL location_message( 'initializing in case of restart / cyclic_fill', &
1525                              .FALSE. )
[1]1526!
[767]1527!--    When reading data for cyclic fill of 3D prerun data files, read
1528!--    some of the global variables from the restart file which are required
1529!--    for initializing the inflow
[328]1530       IF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
[559]1531
[759]1532          DO  i = 0, io_blocks-1
1533             IF ( i == io_group )  THEN
1534                CALL read_parts_of_var_list
1535                CALL close_file( 13 )
1536             ENDIF
1537#if defined( __parallel )
1538             CALL MPI_BARRIER( comm2d, ierr )
1539#endif
1540          ENDDO
[328]1541
[767]1542       ENDIF
1543
[151]1544!
[767]1545!--    Read binary data from restart file
1546       DO  i = 0, io_blocks-1
1547          IF ( i == io_group )  THEN
1548             CALL read_3d_binary
1549          ENDIF
1550#if defined( __parallel )
1551          CALL MPI_BARRIER( comm2d, ierr )
1552#endif
1553       ENDDO
1554
[328]1555!
[767]1556!--    Initialization of the turbulence recycling method
[1788]1557       IF ( TRIM( initializing_actions ) == 'cyclic_fill'  .AND.               &
[767]1558            turbulent_inflow )  THEN
1559!
1560!--       First store the profiles to be used at the inflow.
1561!--       These profiles are the (temporally) and horizontally averaged vertical
1562!--       profiles from the prerun. Alternatively, prescribed profiles
1563!--       for u,v-components can be used.
[1960]1564          ALLOCATE( mean_inflow_profiles(nzb:nzt+1,7) )
[151]1565
[767]1566          IF ( use_prescribed_profile_data )  THEN
1567             mean_inflow_profiles(:,1) = u_init            ! u
1568             mean_inflow_profiles(:,2) = v_init            ! v
1569          ELSE
[328]1570             mean_inflow_profiles(:,1) = hom_sum(:,1,0)    ! u
1571             mean_inflow_profiles(:,2) = hom_sum(:,2,0)    ! v
[767]1572          ENDIF
1573          mean_inflow_profiles(:,4) = hom_sum(:,4,0)       ! pt
1574          mean_inflow_profiles(:,5) = hom_sum(:,8,0)       ! e
[1960]1575          IF ( humidity )                                                      &
1576             mean_inflow_profiles(:,6) = hom_sum(:,41,0)   ! q
1577          IF ( passive_scalar )                                                &
1578             mean_inflow_profiles(:,7) = hom_sum(:,115,0)   ! s
[151]1579
1580!
[767]1581!--       If necessary, adjust the horizontal flow field to the prescribed
1582!--       profiles
1583          IF ( use_prescribed_profile_data )  THEN
1584             DO  i = nxlg, nxrg
[667]1585                DO  j = nysg, nyng
[328]1586                   DO  k = nzb, nzt+1
[767]1587                      u(k,j,i) = u(k,j,i) - hom_sum(k,1,0) + u_init(k)
1588                      v(k,j,i) = v(k,j,i) - hom_sum(k,2,0) + v_init(k)
[328]1589                   ENDDO
[151]1590                ENDDO
[767]1591             ENDDO
1592          ENDIF
[151]1593
1594!
[767]1595!--       Use these mean profiles at the inflow (provided that Dirichlet
1596!--       conditions are used)
1597          IF ( inflow_l )  THEN
1598             DO  j = nysg, nyng
1599                DO  k = nzb, nzt+1
1600                   u(k,j,nxlg:-1)  = mean_inflow_profiles(k,1)
1601                   v(k,j,nxlg:-1)  = mean_inflow_profiles(k,2)
[1340]1602                   w(k,j,nxlg:-1)  = 0.0_wp
[767]1603                   pt(k,j,nxlg:-1) = mean_inflow_profiles(k,4)
1604                   e(k,j,nxlg:-1)  = mean_inflow_profiles(k,5)
[1960]1605                   IF ( humidity )                                             &
[1615]1606                      q(k,j,nxlg:-1)  = mean_inflow_profiles(k,6)
[1960]1607                   IF ( passive_scalar )                                       &
1608                      s(k,j,nxlg:-1)  = mean_inflow_profiles(k,7)                     
[767]1609                ENDDO
1610             ENDDO
1611          ENDIF
1612
[151]1613!
[767]1614!--       Calculate the damping factors to be used at the inflow. For a
1615!--       turbulent inflow the turbulent fluctuations have to be limited
1616!--       vertically because otherwise the turbulent inflow layer will grow
1617!--       in time.
[1340]1618          IF ( inflow_damping_height == 9999999.9_wp )  THEN
[767]1619!
1620!--          Default: use the inversion height calculated by the prerun; if
1621!--          this is zero, inflow_damping_height must be explicitly
1622!--          specified.
[1340]1623             IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0_wp )  THEN
[767]1624                inflow_damping_height = hom_sum(nzb+6,pr_palm,0)
1625             ELSE
[1788]1626                WRITE( message_string, * ) 'inflow_damping_height must be ',   &
1627                     'explicitly specified because&the inversion height ',     &
[767]1628                     'calculated by the prerun is zero.'
1629                CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 )
[292]1630             ENDIF
[151]1631
[767]1632          ENDIF
1633
[1340]1634          IF ( inflow_damping_width == 9999999.9_wp )  THEN
[151]1635!
[767]1636!--          Default for the transition range: one tenth of the undamped
1637!--          layer
[1340]1638             inflow_damping_width = 0.1_wp * inflow_damping_height
[151]1639
[767]1640          ENDIF
[151]1641
[767]1642          ALLOCATE( inflow_damping_factor(nzb:nzt+1) )
[151]1643
[767]1644          DO  k = nzb, nzt+1
[151]1645
[767]1646             IF ( zu(k) <= inflow_damping_height )  THEN
[1340]1647                inflow_damping_factor(k) = 1.0_wp
[996]1648             ELSEIF ( zu(k) <= ( inflow_damping_height + inflow_damping_width ) )  THEN
[1340]1649                inflow_damping_factor(k) = 1.0_wp -                            &
[996]1650                                           ( zu(k) - inflow_damping_height ) / &
1651                                           inflow_damping_width
[767]1652             ELSE
[1340]1653                inflow_damping_factor(k) = 0.0_wp
[767]1654             ENDIF
[151]1655
[767]1656          ENDDO
[151]1657
[147]1658       ENDIF
1659
[152]1660!
[359]1661!--    Inside buildings set velocities and TKE back to zero
[1788]1662       IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND.                &
[359]1663            topography /= 'flat' )  THEN
1664!
1665!--       Inside buildings set velocities and TKE back to zero.
1666!--       Other scalars (pt, q, s, km, kh, p, sa, ...) are ignored at present,
1667!--       maybe revise later.
[1001]1668          DO  i = nxlg, nxrg
1669             DO  j = nysg, nyng
[1340]1670                u  (nzb:nzb_u_inner(j,i),j,i)   = 0.0_wp
1671                v  (nzb:nzb_v_inner(j,i),j,i)   = 0.0_wp
1672                w  (nzb:nzb_w_inner(j,i),j,i)   = 0.0_wp
1673                e  (nzb:nzb_w_inner(j,i),j,i)   = 0.0_wp
1674                tu_m(nzb:nzb_u_inner(j,i),j,i)  = 0.0_wp
1675                tv_m(nzb:nzb_v_inner(j,i),j,i)  = 0.0_wp
1676                tw_m(nzb:nzb_w_inner(j,i),j,i)  = 0.0_wp
1677                te_m(nzb:nzb_w_inner(j,i),j,i)  = 0.0_wp
1678                tpt_m(nzb:nzb_w_inner(j,i),j,i) = 0.0_wp
[359]1679             ENDDO
[1001]1680          ENDDO
[359]1681
1682       ENDIF
1683
1684!
[1]1685!--    Calculate initial temperature field and other constants used in case
1686!--    of a sloping surface
1687       IF ( sloping_surface )  CALL init_slope
1688
1689!
1690!--    Initialize new time levels (only done in order to set boundary values
1691!--    including ghost points)
1692       e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w
[1960]1693       IF ( humidity )  THEN
[1053]1694          q_p = q
[1822]1695          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1053]1696             qr_p = qr
1697             nr_p = nr
1698          ENDIF
1699       ENDIF
[1960]1700       IF ( passive_scalar )  s_p  = s
1701       IF ( ocean          )  sa_p = sa
[1]1702
[181]1703!
1704!--    Allthough tendency arrays are set in prognostic_equations, they have
1705!--    have to be predefined here because they are used (but multiplied with 0)
1706!--    there before they are set.
[1340]1707       te_m = 0.0_wp; tpt_m = 0.0_wp; tu_m = 0.0_wp; tv_m = 0.0_wp; tw_m = 0.0_wp
[1960]1708       IF ( humidity )  THEN
[1340]1709          tq_m = 0.0_wp
[1822]1710          IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
[1340]1711             tqr_m = 0.0_wp
1712             tnr_m = 0.0_wp
[1053]1713          ENDIF
1714       ENDIF
[1960]1715       IF ( passive_scalar )  ts_m  = 0.0_wp
1716       IF ( ocean          )  tsa_m = 0.0_wp
[181]1717
[1402]1718       CALL location_message( 'finished', .TRUE. )
[1384]1719
[1]1720    ELSE
1721!
1722!--    Actually this part of the programm should not be reached
[254]1723       message_string = 'unknown initializing problem'
1724       CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 )
[1]1725    ENDIF
1726
[151]1727
1728    IF (  TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
[1]1729!
[151]1730!--    Initialize old timelevels needed for radiation boundary conditions
1731       IF ( outflow_l )  THEN
1732          u_m_l(:,:,:) = u(:,:,1:2)
1733          v_m_l(:,:,:) = v(:,:,0:1)
1734          w_m_l(:,:,:) = w(:,:,0:1)
1735       ENDIF
1736       IF ( outflow_r )  THEN
1737          u_m_r(:,:,:) = u(:,:,nx-1:nx)
1738          v_m_r(:,:,:) = v(:,:,nx-1:nx)
1739          w_m_r(:,:,:) = w(:,:,nx-1:nx)
1740       ENDIF
1741       IF ( outflow_s )  THEN
1742          u_m_s(:,:,:) = u(:,0:1,:)
1743          v_m_s(:,:,:) = v(:,1:2,:)
1744          w_m_s(:,:,:) = w(:,0:1,:)
1745       ENDIF
1746       IF ( outflow_n )  THEN
1747          u_m_n(:,:,:) = u(:,ny-1:ny,:)
1748          v_m_n(:,:,:) = v(:,ny-1:ny,:)
1749          w_m_n(:,:,:) = w(:,ny-1:ny,:)
1750       ENDIF
[667]1751       
[151]1752    ENDIF
[680]1753
[667]1754!
1755!-- Calculate the initial volume flow at the right and north boundary
[709]1756    IF ( conserve_volume_flow )  THEN
[151]1757
[767]1758       IF ( use_prescribed_profile_data )  THEN
[667]1759
[1340]1760          volume_flow_initial_l = 0.0_wp
1761          volume_flow_area_l    = 0.0_wp
[732]1762
[667]1763          IF ( nxr == nx )  THEN
1764             DO  j = nys, nyn
[1845]1765                DO  k = nzb_u_inner(j,nx)+1, nzt
[1788]1766                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[767]1767                                              u_init(k) * dzw(k)
1768                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1769                ENDDO
1770             ENDDO
1771          ENDIF
1772         
1773          IF ( nyn == ny )  THEN
1774             DO  i = nxl, nxr
[1845]1775                DO  k = nzb_v_inner(ny,i)+1, nzt
[767]1776                   volume_flow_initial_l(2) = volume_flow_initial_l(2) + &
1777                                              v_init(k) * dzw(k)
1778                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1779                ENDDO
1780             ENDDO
1781          ENDIF
1782
1783#if defined( __parallel )
1784          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1785                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1786          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1787                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1788
1789#else
1790          volume_flow_initial = volume_flow_initial_l
1791          volume_flow_area    = volume_flow_area_l
1792#endif 
1793
1794       ELSEIF ( TRIM( initializing_actions ) == 'cyclic_fill' )  THEN
1795
[1340]1796          volume_flow_initial_l = 0.0_wp
1797          volume_flow_area_l    = 0.0_wp
[767]1798
1799          IF ( nxr == nx )  THEN
1800             DO  j = nys, nyn
[1845]1801                DO  k = nzb_u_inner(j,nx)+1, nzt
[1788]1802                   volume_flow_initial_l(1) = volume_flow_initial_l(1) +       &
[667]1803                                              hom_sum(k,1,0) * dzw(k)
1804                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1805                ENDDO
1806             ENDDO
1807          ENDIF
1808         
1809          IF ( nyn == ny )  THEN
1810             DO  i = nxl, nxr
[1845]1811                DO  k = nzb_v_inner(ny,i)+1, nzt
[1788]1812                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[709]1813                                              hom_sum(k,2,0) * dzw(k)
[667]1814                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1815                ENDDO
1816             ENDDO
1817          ENDIF
1818
[732]1819#if defined( __parallel )
1820          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1821                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1822          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1823                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1824
1825#else
1826          volume_flow_initial = volume_flow_initial_l
1827          volume_flow_area    = volume_flow_area_l
1828#endif 
1829
[667]1830       ELSEIF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
1831
[1340]1832          volume_flow_initial_l = 0.0_wp
1833          volume_flow_area_l    = 0.0_wp
[732]1834
[667]1835          IF ( nxr == nx )  THEN
1836             DO  j = nys, nyn
[1845]1837                DO  k = nzb_u_inner(j,nx)+1, nzt
[667]1838                   volume_flow_initial_l(1) = volume_flow_initial_l(1) + &
[709]1839                                              u(k,j,nx) * dzw(k)
[667]1840                   volume_flow_area_l(1)    = volume_flow_area_l(1) + dzw(k)
1841                ENDDO
1842             ENDDO
1843          ENDIF
1844         
1845          IF ( nyn == ny )  THEN
1846             DO  i = nxl, nxr
[1845]1847                DO  k = nzb_v_inner(ny,i)+1, nzt
[1788]1848                   volume_flow_initial_l(2) = volume_flow_initial_l(2) +       &
[667]1849                                              v(k,ny,i) * dzw(k)
1850                   volume_flow_area_l(2)    = volume_flow_area_l(2) + dzw(k)
1851                ENDDO
1852             ENDDO
1853          ENDIF
1854
1855#if defined( __parallel )
[732]1856          CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),&
1857                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
1858          CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1),      &
1859                              2, MPI_REAL, MPI_SUM, comm2d, ierr )
[667]1860
1861#else
[732]1862          volume_flow_initial = volume_flow_initial_l
1863          volume_flow_area    = volume_flow_area_l
[667]1864#endif 
1865
[732]1866       ENDIF
1867
[151]1868!
[709]1869!--    In case of 'bulk_velocity' mode, volume_flow_initial is calculated
1870!--    from u|v_bulk instead
[680]1871       IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' )  THEN
1872          volume_flow_initial(1) = u_bulk * volume_flow_area(1)
1873          volume_flow_initial(2) = v_bulk * volume_flow_area(2)
1874       ENDIF
[667]1875
[680]1876    ENDIF
1877
[787]1878!
1879!-- Initialize quantities for special advections schemes
1880    CALL init_advec
[680]1881
[667]1882!
[680]1883!-- Impose random perturbation on the horizontal velocity field and then
1884!-- remove the divergences from the velocity field at the initial stage
[1788]1885    IF ( create_disturbances  .AND.  disturbance_energy_limit /= 0.0_wp  .AND. &
1886         TRIM( initializing_actions ) /= 'read_restart_data'  .AND.            &
[680]1887         TRIM( initializing_actions ) /= 'cyclic_fill' )  THEN
1888
[1402]1889       CALL location_message( 'creating initial disturbances', .FALSE. )
[680]1890       CALL disturb_field( nzb_u_inner, tend, u )
1891       CALL disturb_field( nzb_v_inner, tend, v )
[1402]1892       CALL location_message( 'finished', .TRUE. )
[1384]1893
[1402]1894       CALL location_message( 'calling pressure solver', .FALSE. )
[680]1895       n_sor = nsor_ini
1896       CALL pres
1897       n_sor = nsor
[1402]1898       CALL location_message( 'finished', .TRUE. )
[1384]1899
[680]1900    ENDIF
1901
1902!
[1484]1903!-- If required, initialize quantities needed for the plant canopy model
[2007]1904    IF ( plant_canopy )  THEN
1905       CALL location_message( 'initializing plant canopy model', .FALSE. )   
1906       CALL pcm_init
1907       CALL location_message( 'finished', .TRUE. )
1908    ENDIF
[138]1909
1910!
[1]1911!-- If required, initialize dvrp-software
[1340]1912    IF ( dt_dvrp /= 9999999.9_wp )  CALL init_dvrp
[1]1913
[96]1914    IF ( ocean )  THEN
[1]1915!
[96]1916!--    Initialize quantities needed for the ocean model
1917       CALL init_ocean
[388]1918
[96]1919    ELSE
1920!
1921!--    Initialize quantities for handling cloud physics
[849]1922!--    This routine must be called before lpm_init, because
[96]1923!--    otherwise, array pt_d_t, needed in data_output_dvrp (called by
[849]1924!--    lpm_init) is not defined.
[96]1925       CALL init_cloud_physics
[1849]1926!
1927!--    Initialize bulk cloud microphysics
1928       CALL microphysics_init
[96]1929    ENDIF
[1]1930
1931!
1932!-- If required, initialize particles
[849]1933    IF ( particle_advection )  CALL lpm_init
[1]1934
[1585]1935!
1936!-- If required, initialize quantities needed for the LSM
1937    IF ( land_surface )  THEN
1938       CALL location_message( 'initializing land surface model', .FALSE. )
[1817]1939       CALL lsm_init
[1585]1940       CALL location_message( 'finished', .TRUE. )
1941    ENDIF
[1496]1942
[1]1943!
[1691]1944!-- Initialize surface layer (done after LSM as roughness length are required
1945!-- for initialization
1946    IF ( constant_flux_layer )  THEN
1947       CALL location_message( 'initializing surface layer', .FALSE. )
1948       CALL init_surface_layer_fluxes
1949       CALL location_message( 'finished', .TRUE. )
1950    ENDIF
1951
1952!
[1496]1953!-- If required, initialize radiation model
1954    IF ( radiation )  THEN
[1585]1955       CALL location_message( 'initializing radiation model', .FALSE. )
[1826]1956       CALL radiation_init
[1585]1957       CALL location_message( 'finished', .TRUE. )
[1496]1958    ENDIF
[2007]1959
[1914]1960!
[2007]1961!-- If required, initialize urban surface model
1962    IF ( urban_surface )  THEN
1963       CALL location_message( 'initializing urban surface model', .FALSE. )
1964       CALL usm_init_urban_surface
1965       CALL location_message( 'finished', .TRUE. )
1966    ENDIF
1967
1968!
[1914]1969!-- If required, initialize quantities needed for the wind turbine model
1970    IF ( wind_turbine )  THEN
1971       CALL location_message( 'initializing wind turbine model', .FALSE. )
1972       CALL wtm_init
1973       CALL location_message( 'finished', .TRUE. )
1974    ENDIF
[1496]1975
[1914]1976
[1496]1977!
[673]1978!-- Initialize the ws-scheme.   
1979    IF ( ws_scheme_sca .OR. ws_scheme_mom )  CALL ws_init       
[1]1980
1981!
[709]1982!-- Setting weighting factors for calculation of perturbation pressure
[1762]1983!-- and turbulent quantities from the RK substeps
[709]1984    IF ( TRIM(timestep_scheme) == 'runge-kutta-3' )  THEN      ! for RK3-method
1985
[1322]1986       weight_substep(1) = 1._wp/6._wp
1987       weight_substep(2) = 3._wp/10._wp
1988       weight_substep(3) = 8._wp/15._wp
[709]1989
[1322]1990       weight_pres(1)    = 1._wp/3._wp
1991       weight_pres(2)    = 5._wp/12._wp
1992       weight_pres(3)    = 1._wp/4._wp
[709]1993
1994    ELSEIF ( TRIM(timestep_scheme) == 'runge-kutta-2' )  THEN  ! for RK2-method
1995
[1322]1996       weight_substep(1) = 1._wp/2._wp
1997       weight_substep(2) = 1._wp/2._wp
[673]1998         
[1322]1999       weight_pres(1)    = 1._wp/2._wp
2000       weight_pres(2)    = 1._wp/2._wp       
[709]2001
[1001]2002    ELSE                                     ! for Euler-method
[709]2003
[1340]2004       weight_substep(1) = 1.0_wp     
2005       weight_pres(1)    = 1.0_wp                   
[709]2006
[673]2007    ENDIF
2008
2009!
[1]2010!-- Initialize Rayleigh damping factors
[1340]2011    rdf    = 0.0_wp
2012    rdf_sc = 0.0_wp
2013    IF ( rayleigh_damping_factor /= 0.0_wp )  THEN
[1788]2014       IF (  .NOT.  ocean )  THEN
[108]2015          DO  k = nzb+1, nzt
2016             IF ( zu(k) >= rayleigh_damping_height )  THEN
[1788]2017                rdf(k) = rayleigh_damping_factor *                             &
[1340]2018                      ( SIN( pi * 0.5_wp * ( zu(k) - rayleigh_damping_height ) &
[1788]2019                             / ( zu(nzt) - rayleigh_damping_height ) )         &
[1]2020                      )**2
[108]2021             ENDIF
2022          ENDDO
2023       ELSE
2024          DO  k = nzt, nzb+1, -1
2025             IF ( zu(k) <= rayleigh_damping_height )  THEN
[1788]2026                rdf(k) = rayleigh_damping_factor *                             &
[1340]2027                      ( SIN( pi * 0.5_wp * ( rayleigh_damping_height - zu(k) ) &
[1788]2028                             / ( rayleigh_damping_height - zu(nzb+1) ) )       &
[108]2029                      )**2
2030             ENDIF
2031          ENDDO
2032       ENDIF
[1]2033    ENDIF
[785]2034    IF ( scalar_rayleigh_damping )  rdf_sc = rdf
[1]2035
2036!
[240]2037!-- Initialize the starting level and the vertical smoothing factor used for
2038!-- the external pressure gradient
[1340]2039    dp_smooth_factor = 1.0_wp
[240]2040    IF ( dp_external )  THEN
2041!
2042!--    Set the starting level dp_level_ind_b only if it has not been set before
2043!--    (e.g. in init_grid).
2044       IF ( dp_level_ind_b == 0 )  THEN
2045          ind_array = MINLOC( ABS( dp_level_b - zu ) )
2046          dp_level_ind_b = ind_array(1) - 1 + nzb 
2047                                        ! MINLOC uses lower array bound 1
2048       ENDIF
2049       IF ( dp_smooth )  THEN
[1340]2050          dp_smooth_factor(:dp_level_ind_b) = 0.0_wp
[240]2051          DO  k = dp_level_ind_b+1, nzt
[1340]2052             dp_smooth_factor(k) = 0.5_wp * ( 1.0_wp + SIN( pi *               &
2053                        ( REAL( k - dp_level_ind_b, KIND=wp ) /                &
2054                          REAL( nzt - dp_level_ind_b, KIND=wp ) - 0.5_wp ) ) )
[240]2055          ENDDO
2056       ENDIF
2057    ENDIF
2058
2059!
[978]2060!-- Initialize damping zone for the potential temperature in case of
2061!-- non-cyclic lateral boundaries. The damping zone has the maximum value
2062!-- at the inflow boundary and decreases to zero at pt_damping_width.
[1340]2063    ptdf_x = 0.0_wp
2064    ptdf_y = 0.0_wp
[1159]2065    IF ( bc_lr_dirrad )  THEN
[996]2066       DO  i = nxl, nxr
[978]2067          IF ( ( i * dx ) < pt_damping_width )  THEN
[1340]2068             ptdf_x(i) = pt_damping_factor * ( SIN( pi * 0.5_wp *              &
2069                            REAL( pt_damping_width - i * dx, KIND=wp ) / (     &
[1788]2070                            REAL( pt_damping_width, KIND=wp ) ) ) )**2 
[73]2071          ENDIF
2072       ENDDO
[1159]2073    ELSEIF ( bc_lr_raddir )  THEN
[996]2074       DO  i = nxl, nxr
[978]2075          IF ( ( i * dx ) > ( nx * dx - pt_damping_width ) )  THEN
[1322]2076             ptdf_x(i) = pt_damping_factor *                                   &
[1340]2077                         SIN( pi * 0.5_wp *                                    &
2078                                 ( ( i - nx ) * dx + pt_damping_width ) /      &
2079                                 REAL( pt_damping_width, KIND=wp ) )**2
[73]2080          ENDIF
[978]2081       ENDDO 
[1159]2082    ELSEIF ( bc_ns_dirrad )  THEN
[996]2083       DO  j = nys, nyn
[978]2084          IF ( ( j * dy ) > ( ny * dy - pt_damping_width ) )  THEN
[1322]2085             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2086                         SIN( pi * 0.5_wp *                                    &
2087                                 ( ( j - ny ) * dy + pt_damping_width ) /      &
2088                                 REAL( pt_damping_width, KIND=wp ) )**2
[1]2089          ENDIF
[978]2090       ENDDO 
[1159]2091    ELSEIF ( bc_ns_raddir )  THEN
[996]2092       DO  j = nys, nyn
[978]2093          IF ( ( j * dy ) < pt_damping_width )  THEN
[1322]2094             ptdf_y(j) = pt_damping_factor *                                   &
[1340]2095                         SIN( pi * 0.5_wp *                                    &
2096                                ( pt_damping_width - j * dy ) /                &
2097                                REAL( pt_damping_width, KIND=wp ) )**2
[1]2098          ENDIF
[73]2099       ENDDO
[1]2100    ENDIF
2101
2102!
2103!-- Pre-set masks for regional statistics. Default is the total model domain.
[1015]2104!-- Ghost points are excluded because counting values at the ghost boundaries
2105!-- would bias the statistics
[1340]2106    rmask = 1.0_wp
2107    rmask(:,nxlg:nxl-1,:) = 0.0_wp;  rmask(:,nxr+1:nxrg,:) = 0.0_wp
2108    rmask(nysg:nys-1,:,:) = 0.0_wp;  rmask(nyn+1:nyng,:,:) = 0.0_wp
[1]2109
2110!
[51]2111!-- User-defined initializing actions. Check afterwards, if maximum number
[709]2112!-- of allowed timeseries is exceeded
[1]2113    CALL user_init
2114
[51]2115    IF ( dots_num > dots_max )  THEN
[1788]2116       WRITE( message_string, * ) 'number of time series quantities exceeds',  &
2117                                  ' its maximum of dots_max = ', dots_max,     &
[254]2118                                  ' &Please increase dots_max in modules.f90.'
2119       CALL message( 'init_3d_model', 'PA0194', 1, 2, 0, 6, 0 )   
[51]2120    ENDIF
2121
[1]2122!
2123!-- Input binary data file is not needed anymore. This line must be placed
2124!-- after call of user_init!
2125    CALL close_file( 13 )
2126
2127!
2128!-- Compute total sum of active mask grid points
[1738]2129!-- and the mean surface level height for each statistic region
[1]2130!-- ngp_2dh: number of grid points of a horizontal cross section through the
2131!--          total domain
2132!-- ngp_3d:  number of grid points of the total domain
[132]2133    ngp_2dh_outer_l   = 0
2134    ngp_2dh_outer     = 0
2135    ngp_2dh_s_inner_l = 0
2136    ngp_2dh_s_inner   = 0
2137    ngp_2dh_l         = 0
2138    ngp_2dh           = 0
[1340]2139    ngp_3d_inner_l    = 0.0_wp
[132]2140    ngp_3d_inner      = 0
2141    ngp_3d            = 0
2142    ngp_sums          = ( nz + 2 ) * ( pr_palm + max_pr_user )
[1]2143
[1738]2144    mean_surface_level_height   = 0.0_wp
2145    mean_surface_level_height_l = 0.0_wp
2146
[1]2147    DO  sr = 0, statistic_regions
2148       DO  i = nxl, nxr
2149          DO  j = nys, nyn
[1340]2150             IF ( rmask(j,i,sr) == 1.0_wp )  THEN
[1]2151!
2152!--             All xy-grid points
2153                ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1
[1788]2154                mean_surface_level_height_l(sr) = mean_surface_level_height_l(sr) &
2155                                                  + zw(nzb_s_inner(j,i))
[1]2156!
2157!--             xy-grid points above topography
2158                DO  k = nzb_s_outer(j,i), nz + 1
2159                   ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr) + 1
2160                ENDDO
[132]2161                DO  k = nzb_s_inner(j,i), nz + 1
2162                   ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) + 1
2163                ENDDO
[1]2164!
2165!--             All grid points of the total domain above topography
[1788]2166                ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr)                        &
2167                                     + ( nz - nzb_s_inner(j,i) + 2 )
[1]2168             ENDIF
2169          ENDDO
2170       ENDDO
2171    ENDDO
2172
2173    sr = statistic_regions + 1
2174#if defined( __parallel )
[622]2175    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1788]2176    CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM,    &
[1]2177                        comm2d, ierr )
[622]2178    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1788]2179    CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr,   &
[1]2180                        MPI_INTEGER, MPI_SUM, comm2d, ierr )
[622]2181    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1788]2182    CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0),          &
[132]2183                        (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr )
[622]2184    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1788]2185    CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner_tmp(0), sr, MPI_REAL,  &
[1]2186                        MPI_SUM, comm2d, ierr )
[485]2187    ngp_3d_inner = INT( ngp_3d_inner_tmp, KIND = SELECTED_INT_KIND( 18 ) )
[1738]2188    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1788]2189    CALL MPI_ALLREDUCE( mean_surface_level_height_l(0),                        &
2190                        mean_surface_level_height(0), sr, MPI_REAL,            &
[1738]2191                        MPI_SUM, comm2d, ierr )
2192    mean_surface_level_height = mean_surface_level_height / REAL( ngp_2dh )
[1]2193#else
[132]2194    ngp_2dh         = ngp_2dh_l
2195    ngp_2dh_outer   = ngp_2dh_outer_l
2196    ngp_2dh_s_inner = ngp_2dh_s_inner_l
[485]2197    ngp_3d_inner    = INT( ngp_3d_inner_l, KIND = SELECTED_INT_KIND( 18 ) )
[1738]2198    mean_surface_level_height = mean_surface_level_height_l / REAL( ngp_2dh_l )
[1]2199#endif
2200
[560]2201    ngp_3d = INT ( ngp_2dh, KIND = SELECTED_INT_KIND( 18 ) ) * &
2202             INT ( (nz + 2 ), KIND = SELECTED_INT_KIND( 18 ) )
[1]2203
2204!
2205!-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics,
2206!-- buoyancy, etc. A zero value will occur for cases where all grid points of
2207!-- the respective subdomain lie below the surface topography
[667]2208    ngp_2dh_outer   = MAX( 1, ngp_2dh_outer(:,:)   ) 
[1788]2209    ngp_3d_inner    = MAX( INT(1, KIND = SELECTED_INT_KIND( 18 )),             &
[631]2210                           ngp_3d_inner(:) )
[667]2211    ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) 
[1]2212
[1788]2213    DEALLOCATE( mean_surface_level_height_l, ngp_2dh_l, ngp_2dh_outer_l,       &
[1738]2214                ngp_3d_inner_l, ngp_3d_inner_tmp )
[1]2215
[1402]2216    CALL location_message( 'leaving init_3d_model', .TRUE. )
[1]2217
2218 END SUBROUTINE init_3d_model
Note: See TracBrowser for help on using the repository browser.