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

Last change on this file since 1817 was 1817, checked in by maronga, 9 years ago

further modularization of land surface model

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