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

Last change on this file since 2032 was 2032, checked in by knoop, 8 years ago

last commit documented

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