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

Last change on this file since 1394 was 1385, checked in by raasch, 10 years ago

last commit documented

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