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

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

Forced header and separation lines into 80 columns

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