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

Last change on this file since 1210 was 1196, checked in by heinze, 11 years ago

last commit documented

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