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

Last change on this file since 1114 was 1114, checked in by raasch, 11 years ago

last commit documented

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